git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@90 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2007-11-14 16:32:41 +00:00
parent e776216d02
commit 890c5532da
19 changed files with 106 additions and 51 deletions

View File

@ -93,9 +93,13 @@ AOPT =
TOPT = -mthumb -D THUMB TOPT = -mthumb -D THUMB
# Common options here # Common options here
# NOTE: -ffixed-r7 is only needed if you enabled CH_CURRP_REGISTER_CACHE in chconf.h. # NOTE: -ffixed-r7 is only needed if you enabled CH_CURRP_REGISTER_CACHE in
# chconf.h.
# NOTE: -falign-functions=16 may improve the performance, not always, but
# increases the code size.
OPT = -O2 -ggdb -fomit-frame-pointer -fno-strict-aliasing OPT = -O2 -ggdb -fomit-frame-pointer -fno-strict-aliasing
#OPT += -ffixed-r7 #OPT += -ffixed-r7
#OPT += -falign-functions=16
# Define warning options here # Define warning options here
WARN = -Wall -Wstrict-prototypes WARN = -Wall -Wstrict-prototypes

View File

@ -119,8 +119,14 @@ static t_msg Thread3(void *arg) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
chSysInit(); chSysInit();
chThdCreate(NORMALPRIO, 0, waThread1, sizeof(waThread1), Thread1, NULL); /*
chThdCreate(NORMALPRIO, 0, waThread2, sizeof(waThread2), Thread2, NULL); * If a button is pressed during the reset then the blinking leds are not
* started in order to make accurate benchmarks.
*/
if ((IO0PIN & 0x00018000) == 0x00018000) {
chThdCreate(NORMALPRIO, 0, waThread1, sizeof(waThread1), Thread1, NULL);
chThdCreate(NORMALPRIO, 0, waThread2, sizeof(waThread2), Thread2, NULL);
}
chThdCreate(NORMALPRIO, 0, waThread3, sizeof(waThread3), Thread3, NULL); chThdCreate(NORMALPRIO, 0, waThread3, sizeof(waThread3), Thread3, NULL);
chSysPause(); chSysPause();
return 0; return 0;

View File

@ -157,6 +157,12 @@
*/ */
//#define CH_CURRP_REGISTER_CACHE "reg" //#define CH_CURRP_REGISTER_CACHE "reg"
/** Configuration option: Includes basic debug support to the kernel.
* @note the debug support is port-dependent, it may be not present on some
* targets. In that case stub functions will be included.
*/
//#define CH_USE_DEBUG
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -101,6 +101,7 @@ typedef struct {
#define chSysLock() asm("cli") #define chSysLock() asm("cli")
#define chSysUnlock() asm("sei") #define chSysUnlock() asm("sei")
#define chSysPuts(msg) {}
void chSysHalt(void) __attribute__((noreturn)) ; void chSysHalt(void) __attribute__((noreturn)) ;
void chSysPause(void) __attribute__((noreturn)) ; void chSysPause(void) __attribute__((noreturn)) ;

View File

@ -34,6 +34,7 @@
typedef BYTE8 t_tmode; typedef BYTE8 t_tmode;
typedef BYTE8 t_tstate; typedef BYTE8 t_tstate;
typedef BYTE8 t_tid;
typedef BYTE8 t_prio; typedef BYTE8 t_prio;
typedef WORD16 t_msg; typedef WORD16 t_msg;
typedef BYTE8 t_eventid; typedef BYTE8 t_eventid;

View File

@ -141,6 +141,9 @@
<Filter <Filter
Name="src" Name="src"
Filter=""> Filter="">
<File
RelativePath="..\..\src\chdebug.c">
</File>
<File <File
RelativePath="..\..\src\chdelta.c"> RelativePath="..\..\src\chdelta.c">
</File> </File>
@ -209,6 +212,9 @@
<File <File
RelativePath="..\..\src\include\ch.h"> RelativePath="..\..\src\include\ch.h">
</File> </File>
<File
RelativePath="..\..\src\include\debug.h">
</File>
<File <File
RelativePath="..\..\src\include\delta.h"> RelativePath="..\..\src\include\delta.h">
</File> </File>

View File

@ -161,6 +161,12 @@
*/ */
//#define CH_CURRP_REGISTER_CACHE "reg" //#define CH_CURRP_REGISTER_CACHE "reg"
/** Configuration option: Includes basic debug support to the kernel.
* @note the debug support is port-dependent, it may be not present on some
* targets. In that case stub functions will be included.
*/
//#define CH_USE_DEBUG
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -47,7 +47,7 @@ void InitCore(void) {
/* /*
* Interrupt simulation. * Interrupt simulation.
*/ */
static void ChkIntSources(void) { void ChkIntSources(void) {
LARGE_INTEGER n; LARGE_INTEGER n;
if (Com1InInterruptSimCom() || Com2InInterruptSimCom() || if (Com1InInterruptSimCom() || Com2InInterruptSimCom() ||

View File

@ -58,8 +58,8 @@ typedef struct {
} }
#define chSysLock() #define chSysLock()
#define chSysUnlock() #define chSysUnlock()
#define chSysPuts(msg) {}
#define INT_REQUIRED_STACK 0x0 #define INT_REQUIRED_STACK 0x0

View File

@ -33,6 +33,7 @@
typedef BYTE8 t_tmode; typedef BYTE8 t_tmode;
typedef BYTE8 t_tstate; typedef BYTE8 t_tstate;
typedef UWORD16 t_tid;
typedef ULONG32 t_prio; typedef ULONG32 t_prio;
typedef LONG32 t_msg; typedef LONG32 t_msg;
typedef LONG32 t_eventid; typedef LONG32 t_eventid;

View File

@ -161,6 +161,12 @@
*/ */
//#define CH_CURRP_REGISTER_CACHE "reg" //#define CH_CURRP_REGISTER_CACHE "reg"
/** Configuration option: Includes basic debug support to the kernel.
* @note the debug support is port-dependent, it may be not present on some
* targets. In that case stub functions will be included.
*/
//#define CH_USE_DEBUG
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -70,7 +70,7 @@ void InitCore(void) {
/* /*
* Interrupt simulation. * Interrupt simulation.
*/ */
static void ChkIntSources(void) { void ChkIntSources(void) {
LARGE_INTEGER n; LARGE_INTEGER n;
if (Com1InInterruptSimCom() || Com2InInterruptSimCom() || if (Com1InInterruptSimCom() || Com2InInterruptSimCom() ||

View File

@ -58,8 +58,8 @@ typedef struct {
} }
#define chSysLock() #define chSysLock()
#define chSysUnlock() #define chSysUnlock()
#define chSysPuts(msg) {}
#define INT_REQUIRED_STACK 0x0 #define INT_REQUIRED_STACK 0x0

View File

@ -33,6 +33,7 @@
typedef BYTE8 t_tmode; typedef BYTE8 t_tmode;
typedef BYTE8 t_tstate; typedef BYTE8 t_tstate;
typedef UWORD16 t_tid;
typedef ULONG32 t_prio; typedef ULONG32 t_prio;
typedef LONG32 t_msg; typedef LONG32 t_msg;
typedef LONG32 t_eventid; typedef LONG32 t_eventid;

View File

@ -48,6 +48,7 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet.
using the CH_USE_DEBUG in chconf.h. using the CH_USE_DEBUG in chconf.h.
The trace buffer is meant to be fetched and decoded by an external tool The trace buffer is meant to be fetched and decoded by an external tool
(coming soon, it can be accessed using JTAG in the meanwhile). (coming soon, it can be accessed using JTAG in the meanwhile).
- Added new API chThdGetPriority() as a macro.
- Implemented panic messages when CH_USE_DEBUG is enabled. - Implemented panic messages when CH_USE_DEBUG is enabled.
- Added a thread identifier field to the Thread structure, it is used only - Added a thread identifier field to the Thread structure, it is used only
for debug. for debug.

View File

@ -153,7 +153,7 @@ t_msg chMsgWait(void) {
* @return the pointer to the message structure. Note, it is always the * @return the pointer to the message structure. Note, it is always the
* message associated to the thread on the top of the messages queue. * message associated to the thread on the top of the messages queue.
* If the queue is empty then \p NULL is returned. * If the queue is empty then \p NULL is returned.
* @note You can assume that the data contained in the message is stable until * @note You can assume that the data pointed by the message is stable until
* you invoke \p chMsgRelease() because the sending thread is * you invoke \p chMsgRelease() because the sending thread is
* suspended until then. Always remember that the message data is not * suspended until then. Always remember that the message data is not
* copied between the sender and the receiver, just a pointer is passed. * copied between the sender and the receiver, just a pointer is passed.

View File

@ -81,7 +81,11 @@ Thread *chSchReadyI(Thread *tp) {
* Switches to the next thread in the ready list, the ready list is assumed * Switches to the next thread in the ready list, the ready list is assumed
* to contain at least a thread. * to contain at least a thread.
*/ */
#ifdef CH_OPTIMIZE_SPEED
static INLINE void nextready(void) {
#else
static void nextready(void) { static void nextready(void) {
#endif
Thread *otp = currp; Thread *otp = currp;
(currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR;
@ -111,27 +115,27 @@ void chSchGoSleepS(t_tstate newstate) {
* Wakeups a thread, the thread is inserted into the ready list or made * Wakeups a thread, the thread is inserted into the ready list or made
* running directly depending on its relative priority compared to the current * running directly depending on its relative priority compared to the current
* thread. * thread.
* @param tp the Thread to be made ready * @param ntp the Thread to be made ready
* @param msg wakeup message to the awakened thread * @param msg wakeup message to the awakened thread
* @note The function must be called in the system mutex zone. * @note The function must be called in the system mutex zone.
* @note The function is not meant to be used in the user code directly. * @note The function is not meant to be used in the user code directly.
* @note It is equivalent to a \p chSchReadyI() followed by a * @note It is equivalent to a \p chSchReadyI() followed by a
* \p chSchRescheduleI() but much more efficient. * \p chSchRescheduleI() but much more efficient.
*/ */
void chSchWakeupS(Thread *tp, t_msg msg) { void chSchWakeupS(Thread *ntp, t_msg msg) {
Thread *ctp = currp;
if (tp->p_prio <= ctp->p_prio) if (ntp->p_prio <= currp->p_prio)
chSchReadyI(tp)->p_rdymsg = msg; chSchReadyI(ntp)->p_rdymsg = msg;
else { else {
chSchReadyI(ctp); Thread *otp = currp;
(currp = tp)->p_state = PRCURR; chSchReadyI(otp);
tp->p_rdymsg = msg; (currp = ntp)->p_state = PRCURR;
ntp->p_rdymsg = msg;
preempt = CH_TIME_QUANTUM; preempt = CH_TIME_QUANTUM;
#ifdef CH_USE_DEBUG #ifdef CH_USE_DEBUG
chDbgTrace(ctp, tp); chDbgTrace(otp, ntp);
#endif #endif
chSysSwitchI(&ctp->p_ctx, &tp->p_ctx); chSysSwitchI(&otp->p_ctx, &ntp->p_ctx);
} }
} }

View File

@ -178,6 +178,9 @@ extern "C" {
/** Returns the pointer to the \p Thread currently in execution.*/ /** Returns the pointer to the \p Thread currently in execution.*/
#define chThdSelf() currp #define chThdSelf() currp
/** Returns the thread priority.*/
#define chThdGetPriority() (currp->p_prio)
/** Returns the pointer to the \p Thread local storage area, if any.*/ /** Returns the pointer to the \p Thread local storage area, if any.*/
#define chThdLS() (void *)(currp + 1) #define chThdLS() (void *)(currp + 1)

View File

@ -19,6 +19,8 @@
#include <ch.h> #include <ch.h>
void ChkIntSources(void);
#if defined(WIN32) && defined(_DEBUG) #if defined(WIN32) && defined(_DEBUG)
static BYTE8 wsT1[UserStackSize(512)]; static BYTE8 wsT1[UserStackSize(512)];
static BYTE8 wsT2[UserStackSize(512)]; static BYTE8 wsT2[UserStackSize(512)];
@ -126,6 +128,7 @@ t_msg Thread6(void *p) {
t_msg TestThread(void *p) { t_msg TestThread(void *p) {
t_msg msg; t_msg msg;
unsigned int i; unsigned int i;
t_time time;
comp = p; comp = p;
println("*****************************"); println("*****************************");
@ -137,19 +140,19 @@ t_msg TestThread(void *p) {
* Ready list ordering test. * Ready list ordering test.
*/ */
println("*** Ready List, priority enqueuing test #1, you should read ABCDE:"); println("*** Ready List, priority enqueuing test #1, you should read ABCDE:");
t5 = chThdCreate(NORMALPRIO-5, 0, wsT5, sizeof(wsT5), Thread1, "E"); t5 = chThdCreate(chThdGetPriority()-5, 0, wsT5, sizeof(wsT5), Thread1, "E");
t4 = chThdCreate(NORMALPRIO-4, 0, wsT4, sizeof(wsT4), Thread1, "D"); t4 = chThdCreate(chThdGetPriority()-4, 0, wsT4, sizeof(wsT4), Thread1, "D");
t3 = chThdCreate(NORMALPRIO-3, 0, wsT3, sizeof(wsT3), Thread1, "C"); t3 = chThdCreate(chThdGetPriority()-3, 0, wsT3, sizeof(wsT3), Thread1, "C");
t2 = chThdCreate(NORMALPRIO-2, 0, wsT2, sizeof(wsT2), Thread1, "B"); t2 = chThdCreate(chThdGetPriority()-2, 0, wsT2, sizeof(wsT2), Thread1, "B");
t1 = chThdCreate(NORMALPRIO-1, 0, wsT1, sizeof(wsT1), Thread1, "A"); t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread1, "A");
wait(); wait();
println(""); println("");
println("*** Ready List, priority enqueuing test #2, you should read ABCDE:"); println("*** Ready List, priority enqueuing test #2, you should read ABCDE:");
t4 = chThdCreate(NORMALPRIO-4, 0, wsT4, sizeof(wsT4), Thread1, "D"); t4 = chThdCreate(chThdGetPriority()-4, 0, wsT4, sizeof(wsT4), Thread1, "D");
t5 = chThdCreate(NORMALPRIO-5, 0, wsT5, sizeof(wsT5), Thread1, "E"); t5 = chThdCreate(chThdGetPriority()-5, 0, wsT5, sizeof(wsT5), Thread1, "E");
t1 = chThdCreate(NORMALPRIO-1, 0, wsT1, sizeof(wsT1), Thread1, "A"); t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread1, "A");
t2 = chThdCreate(NORMALPRIO-2, 0, wsT2, sizeof(wsT2), Thread1, "B"); t2 = chThdCreate(chThdGetPriority()-2, 0, wsT2, sizeof(wsT2), Thread1, "B");
t3 = chThdCreate(NORMALPRIO-3, 0, wsT3, sizeof(wsT3), Thread1, "C"); t3 = chThdCreate(chThdGetPriority()-3, 0, wsT3, sizeof(wsT3), Thread1, "C");
wait(); wait();
println(""); println("");
@ -158,11 +161,11 @@ t_msg TestThread(void *p) {
*/ */
chSemInit(&sem1, 0); chSemInit(&sem1, 0);
println("*** Semaphores, FIFO enqueuing test, you should read ABCDE:"); println("*** Semaphores, FIFO enqueuing test, you should read ABCDE:");
t1 = chThdCreate(NORMALPRIO+5, 0, wsT1, sizeof(wsT1), Thread2, "A"); t1 = chThdCreate(chThdGetPriority()+5, 0, wsT1, sizeof(wsT1), Thread2, "A");
t2 = chThdCreate(NORMALPRIO+1, 0, wsT2, sizeof(wsT2), Thread2, "B"); t2 = chThdCreate(chThdGetPriority()+1, 0, wsT2, sizeof(wsT2), Thread2, "B");
t3 = chThdCreate(NORMALPRIO+3, 0, wsT3, sizeof(wsT3), Thread2, "C"); t3 = chThdCreate(chThdGetPriority()+3, 0, wsT3, sizeof(wsT3), Thread2, "C");
t4 = chThdCreate(NORMALPRIO+4, 0, wsT4, sizeof(wsT4), Thread2, "D"); t4 = chThdCreate(chThdGetPriority()+4, 0, wsT4, sizeof(wsT4), Thread2, "D");
t5 = chThdCreate(NORMALPRIO+2, 0, wsT5, sizeof(wsT5), Thread2, "E"); t5 = chThdCreate(chThdGetPriority()+2, 0, wsT5, sizeof(wsT5), Thread2, "E");
chSemSignal(&sem1); chSemSignal(&sem1);
chSemSignal(&sem1); chSemSignal(&sem1);
chSemSignal(&sem1); chSemSignal(&sem1);
@ -172,11 +175,11 @@ t_msg TestThread(void *p) {
println(""); println("");
println("*** Semaphores, priority enqueuing test #1, you should read ABCDE:"); println("*** Semaphores, priority enqueuing test #1, you should read ABCDE:");
chSemInit(&sem1, 0); chSemInit(&sem1, 0);
t5 = chThdCreate(NORMALPRIO+1, 0, wsT5, sizeof(wsT5), Thread3, "E"); t5 = chThdCreate(chThdGetPriority()+1, 0, wsT5, sizeof(wsT5), Thread3, "E");
t4 = chThdCreate(NORMALPRIO+2, 0, wsT4, sizeof(wsT4), Thread3, "D"); t4 = chThdCreate(chThdGetPriority()+2, 0, wsT4, sizeof(wsT4), Thread3, "D");
t3 = chThdCreate(NORMALPRIO+3, 0, wsT3, sizeof(wsT3), Thread3, "C"); t3 = chThdCreate(chThdGetPriority()+3, 0, wsT3, sizeof(wsT3), Thread3, "C");
t2 = chThdCreate(NORMALPRIO+4, 0, wsT2, sizeof(wsT2), Thread3, "B"); t2 = chThdCreate(chThdGetPriority()+4, 0, wsT2, sizeof(wsT2), Thread3, "B");
t1 = chThdCreate(NORMALPRIO+5, 0, wsT1, sizeof(wsT1), Thread3, "A"); t1 = chThdCreate(chThdGetPriority()+5, 0, wsT1, sizeof(wsT1), Thread3, "A");
chSemLowerPrioSignal(&sem1); chSemLowerPrioSignal(&sem1);
chSemLowerPrioSignal(&sem1); chSemLowerPrioSignal(&sem1);
chSemLowerPrioSignal(&sem1); chSemLowerPrioSignal(&sem1);
@ -186,11 +189,11 @@ t_msg TestThread(void *p) {
println(""); println("");
println("*** Semaphores, priority enqueuing test #2, you should read ABCDE:"); println("*** Semaphores, priority enqueuing test #2, you should read ABCDE:");
chSemInit(&sem1, 0); chSemInit(&sem1, 0);
t4 = chThdCreate(NORMALPRIO+2, 0, wsT4, sizeof(wsT4), Thread3, "D"); t4 = chThdCreate(chThdGetPriority()+2, 0, wsT4, sizeof(wsT4), Thread3, "D");
t5 = chThdCreate(NORMALPRIO+1, 0, wsT5, sizeof(wsT5), Thread3, "E"); t5 = chThdCreate(chThdGetPriority()+1, 0, wsT5, sizeof(wsT5), Thread3, "E");
t1 = chThdCreate(NORMALPRIO+5, 0, wsT1, sizeof(wsT1), Thread3, "A"); t1 = chThdCreate(chThdGetPriority()+5, 0, wsT1, sizeof(wsT1), Thread3, "A");
t2 = chThdCreate(NORMALPRIO+4, 0, wsT2, sizeof(wsT2), Thread3, "B"); t2 = chThdCreate(chThdGetPriority()+4, 0, wsT2, sizeof(wsT2), Thread3, "B");
t3 = chThdCreate(NORMALPRIO+3, 0, wsT3, sizeof(wsT3), Thread3, "C"); t3 = chThdCreate(chThdGetPriority()+3, 0, wsT3, sizeof(wsT3), Thread3, "C");
chSemLowerPrioSignal(&sem1); chSemLowerPrioSignal(&sem1);
chSemLowerPrioSignal(&sem1); chSemLowerPrioSignal(&sem1);
chSemLowerPrioSignal(&sem1); chSemLowerPrioSignal(&sem1);
@ -210,7 +213,7 @@ t_msg TestThread(void *p) {
* Messages test. * Messages test.
*/ */
println("*** Messages, dispatch test, you should read AABBCCDDEE:"); println("*** Messages, dispatch test, you should read AABBCCDDEE:");
t1 = chThdCreate(NORMALPRIO-1, 0, wsT1, sizeof(wsT1), Thread4, chThdSelf()); t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread4, chThdSelf());
do { do {
chMsgRelease(msg = chMsgWait()); chMsgRelease(msg = chMsgWait());
if (msg) if (msg)
@ -219,7 +222,7 @@ t_msg TestThread(void *p) {
chThdWait(t1); chThdWait(t1);
println(""); println("");
println("*** Messages, timeout test, you should read ABCDE (slowly):"); println("*** Messages, timeout test, you should read ABCDE (slowly):");
t1 = chThdCreate(NORMALPRIO-1, 0, wsT1, sizeof(wsT1), Thread5, chThdSelf()); t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread5, chThdSelf());
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
chFDDPut(comp, 'A'+i); chFDDPut(comp, 'A'+i);
chMsgSendTimeout(t1, 'A'+i, 500); chMsgSendTimeout(t1, 'A'+i, 500);
@ -232,16 +235,22 @@ t_msg TestThread(void *p) {
* Kernel benchmarks. * Kernel benchmarks.
*/ */
println("*** Kernel Benchmark, context switch stress test:"); println("*** Kernel Benchmark, context switch stress test:");
t_time time = chSysGetTime() + 1; time = chSysGetTime() + 1;
while (chSysGetTime() < time) while (chSysGetTime() < time) {
; #if defined(WIN32)
ChkIntSources();
#endif
}
time += 1000; time += 1000;
i = 0; i = 0;
t1 = chThdCreate(NORMALPRIO+1, 0, wsT1, sizeof(wsT1), Thread6, chThdSelf()); t1 = chThdCreate(chThdGetPriority()-1, 0, wsT1, sizeof(wsT1), Thread6, chThdSelf());
while (chSysGetTime() < time) while (chSysGetTime() < time) {
i = chMsgSend(t1, i); i = chMsgSend(t1, i);
#if defined(WIN32)
ChkIntSources();
#endif
}
chThdTerminate(t1); chThdTerminate(t1);
chMsgSend(t1, 0); /* Lets the thread check the termination flag.*/
chThdWait(t1); chThdWait(t1);
print("Messages throughput = "); print("Messages throughput = ");
printn(i); printn(i);