From a62cb84475bb6212554b847751a409a6183f05a0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 26 Nov 2007 16:00:25 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@114 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chevents.c | 52 ++++++++++++++++++++++++++++++---------------------- src/chinit.c | 6 ++---- src/chmsg.c | 10 ++++++---- src/chsem.c | 19 +++---------------- src/chsleep.c | 2 +- src/chthreads.c | 4 ++++ 6 files changed, 46 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/chevents.c b/src/chevents.c index 13f20310d..f8d7d971f 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -119,6 +119,7 @@ void chEvtSendI(EventSource *esp) { } } +#ifdef CH_USE_EVENTS_TIMEOUT /** * The function waits for an event and returns the event identifier, if an * event handler is specified then the handler is executed before returning. @@ -137,33 +138,14 @@ void chEvtSendI(EventSource *esp) { */ t_eventid chEvtWait(t_eventmask ewmask, const t_evhandler handlers[]) { - t_eventid i; - t_eventmask m; - chSysLock(); - - if ((currp->p_epending & ewmask) == 0) { - currp->p_ewmask = ewmask; - chSchGoSleepS(PRWTEVENT); - } - i = 0, m = 1; - while ((currp->p_epending & ewmask & m) == 0) - i += 1, m <<= 1; - currp->p_epending &= ~m; - - chSysUnlock(); - - if (handlers && handlers[i]) - handlers[i](i); - - return i; + return chEvtWaitTimeout(ewmask, handlers, TIME_INFINITE); } -#ifdef CH_USE_EVENTS_TIMEOUT static void wakeup(void *p) { #ifdef CH_USE_DEBUG if (((Thread *)p)->p_state != PRWTEVENT) - chDbgPanic("chevents.c, wakeup()\r\n"); + chDbgPanic("chevents.c, wakeup()"); #endif chSchReadyI(p, RDY_TIMEOUT); } @@ -223,7 +205,33 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask, return i; } -#endif /*CH_USE_EVENTS_TIMEOUT */ + +#else /* !CH_USE_EVENTS_TIMEOUT */ +t_eventid chEvtWait(t_eventmask ewmask, + const t_evhandler handlers[]) { + t_eventid i; + t_eventmask m; + + chSysLock(); + + if ((currp->p_epending & ewmask) == 0) { + currp->p_ewmask = ewmask; + chSchGoSleepS(PRWTEVENT); + } + i = 0, m = 1; + while ((currp->p_epending & ewmask & m) == 0) + i += 1, m <<= 1; + currp->p_epending &= ~m; + + chSysUnlock(); + + if (handlers && handlers[i]) + handlers[i](i); + + return i; +} + +#endif /* CH_USE_EVENTS_TIMEOUT */ #endif /* CH_USE_EVENTS */ diff --git a/src/chinit.c b/src/chinit.c index 918da1796..b1b6bd7d1 100644 --- a/src/chinit.c +++ b/src/chinit.c @@ -53,10 +53,8 @@ void chSysInit(void) { /* * The idle thread is created using the port-provided implementation. * This thread has the lowest priority in the system, its role is just to - * execute the chSysPause() and serve interrupts in its context. - * In ChibiOS/RT at least one thread in the system *must* execute - * chThdPause(), it can be done in a dedicated thread or in the main() - * function (that would never exit the call). + * serve interrupts in its context while keeping the lowest energy saving + * mode compatible with the system status. */ chThdCreate(IDLEPRIO, 0, waIdleThread, sizeof(waIdleThread), (t_tfunc)_IdleThread, NULL); } diff --git a/src/chmsg.c b/src/chmsg.c index 51675e0fe..844628d75 100644 --- a/src/chmsg.c +++ b/src/chmsg.c @@ -67,8 +67,10 @@ t_msg chMsgSendWithEvent(Thread *tp, t_msg msg, EventSource *esp) { chSysLock(); fifo_insert(currp, &tp->p_msgqueue); -// if (tp->p_state == PRWTMSG) -// chSchReadyI(tp, RDY_OK); +#ifdef CH_USE_DEBUG + if (tp->p_state == PRWTMSG) + chDbgPanic("chmsg.c, chMsgSendWithEvent()"); +#endif chEvtSendI(esp); currp->p_msg = msg; chSchGoSleepS(PRSNDMSG); @@ -84,7 +86,7 @@ static void wakeup(void *p) { #ifdef CH_USE_DEBUG if (((Thread *)p)->p_state != PRSNDMSG) - chDbgPanic("chmsg.c, wakeup()\r\n"); + chDbgPanic("chmsg.c, wakeup()"); #endif chSchReadyI(dequeue(p), RDY_TIMEOUT); } @@ -186,7 +188,7 @@ void chMsgRelease(t_msg msg) { #ifdef CH_USE_DEBUG if (!chMsgIsPendingI(currp)) - chDbgPanic("chmsg.c, chMsgRelease()\r\n"); + chDbgPanic("chmsg.c, chMsgRelease()"); #endif chSchWakeupS(fifo_remove(&currp->p_msgqueue), msg); diff --git a/src/chsem.c b/src/chsem.c index df783dc7a..61fff37a1 100644 --- a/src/chsem.c +++ b/src/chsem.c @@ -116,7 +116,7 @@ static void wakeup(void *p) { #ifdef CH_USE_DEBUG if (((Thread *)p)->p_state != PRWTSEM) - chDbgPanic("chsem.c, wakeup()\r\n"); + chDbgPanic("chsem.c, wakeup()"); #endif chSemFastSignalI(((Thread *)p)->p_semp); chSchReadyI(dequeue(p), RDY_TIMEOUT); @@ -133,23 +133,10 @@ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) { chSysLock(); - if (--sp->s_cnt < 0) { - VirtualTimer vt; - - chVTSetI(&vt, time, wakeup, currp); - fifo_insert(currp, &sp->s_queue); - currp->p_semp = sp; - chSchGoSleepS(PRWTSEM); - msg = currp->p_rdymsg; - if (chVTIsArmedI(&vt)) - chVTResetI(&vt); - - chSysUnlock(); - return msg; - } + msg = chSemWaitTimeoutS(sp, time); chSysUnlock(); - return RDY_OK; + return msg; } /** diff --git a/src/chsleep.c b/src/chsleep.c index ae6e394b8..3abf22cd2 100644 --- a/src/chsleep.c +++ b/src/chsleep.c @@ -29,7 +29,7 @@ static void wakeup(void *p) { #ifdef CH_USE_DEBUG if (((Thread *)p)->p_state != PRSLEEP) - chDbgPanic("chsleep.c, wakeup()\r\n"); + chDbgPanic("chsleep.c, wakeup()"); #endif chSchReadyI(p, RDY_OK); } diff --git a/src/chthreads.c b/src/chthreads.c index a0729311f..041690af9 100644 --- a/src/chthreads.c +++ b/src/chthreads.c @@ -139,6 +139,10 @@ void chThdSuspend(Thread **tpp) { chSysLock(); +#ifdef CH_USE_DEBUG + if (*tpp) + chDbgPanic("chthreads.c, chThdSuspend()"); +#endif *tpp = currp; chSchGoSleepS(PRSUSPENDED); *tpp = NULL; -- cgit v1.2.3