From 73642ca0cce31ed6982813a90b89e4de05da76cb Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 13 Oct 2007 06:59:54 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@48 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/Win32-MSVS/chcore.c | 3 ++- demos/Win32-MinGW/chcore.c | 3 ++- readme.txt | 10 +++++++++- src/chdelta.c | 27 +++++++++++++++------------ src/chevents.c | 8 ++++---- src/chmsg.c | 10 +++++----- src/chqueues.c | 14 ++++---------- src/chschd.c | 6 +++--- src/chsem.c | 33 +++++++++++++++++---------------- src/chsleep.c | 4 ++-- src/chthreads.c | 10 +++++----- src/include/delta.h | 3 +++ src/include/scheduler.h | 6 +++--- 13 files changed, 74 insertions(+), 63 deletions(-) diff --git a/demos/Win32-MSVS/chcore.c b/demos/Win32-MSVS/chcore.c index 80fd11424..01619f9cd 100644 --- a/demos/Win32-MSVS/chcore.c +++ b/demos/Win32-MSVS/chcore.c @@ -53,7 +53,8 @@ static void ChkIntSources(void) { if (Com1InInterruptSimCom() || Com2InInterruptSimCom() || Com1OutInterruptSimCom() || Com2OutInterruptSimCom() || Com1ConnInterruptSimCom() || Com2ConnInterruptSimCom()) { - chSchRescheduleI(); + if (chSchRescRequiredI()) + chSchDoRescheduleI(); return; } diff --git a/demos/Win32-MinGW/chcore.c b/demos/Win32-MinGW/chcore.c index 4f677b929..ee04147e9 100644 --- a/demos/Win32-MinGW/chcore.c +++ b/demos/Win32-MinGW/chcore.c @@ -76,7 +76,8 @@ static void ChkIntSources(void) { if (Com1InInterruptSimCom() || Com2InInterruptSimCom() || Com1OutInterruptSimCom() || Com2OutInterruptSimCom() || Com1ConnInterruptSimCom() || Com2ConnInterruptSimCom()) { - chSchRescheduleI(); + if (chSchRescRequiredI()) + chSchDoRescheduleI(); return; } diff --git a/readme.txt b/readme.txt index 8392f96e2..a044cc0df 100644 --- a/readme.txt +++ b/readme.txt @@ -38,13 +38,21 @@ AVR-AT90CANx-GCC - Port on AVER AT90CAN128, not complete yet. *** Releases *** ***************************************************************************** +*** 0.3.3 *** +- Modified the chVTSetI(), now for the "time" parameter can have value zero + with meaning "infinite". + This allows all the APIs with timeout parameters to be invoked + with timeout=0 and work with no timeout. +- Fixes in the documentation. +- Renamed some APIs in the "Sch" group to have an S suffix instead of I. + *** 0.3.2 *** - Modified the chSysInit() to give the idle thread absolute priority, the priority is then lowered to the minimum value into the chSysPause(). This is done in order to ensure that the initializations performed into the main() procedure are performed before any thread starts. - Added chThdSetPriority() new API. -- Added a generic events generator timer to the library code. +- Added a generic events generator timer modulee to the library code. - Modified the ARM7-LPC214x-GCC demo to show the use of the event timer. - Added the "#ifdef __cplusplus" stuff to the header files. - Removed an obsolete definition in ./src/templates/chtypes.h. diff --git a/src/chdelta.c b/src/chdelta.c index e627cbf19..f87aec5a9 100644 --- a/src/chdelta.c +++ b/src/chdelta.c @@ -39,7 +39,8 @@ void chVTInit(void) { /** * Enables a virtual timer. * @param vtp the \p VirtualTimer structure pointer - * @param time the number of time ticks + * @param time the number of time ticks, the value zero is allowed with + * meaning "infinite". * @param vtfunc the timer callback function. After invoking the callback * the timer is disabled and the structure can be disposed or * reused. @@ -48,21 +49,23 @@ void chVTInit(void) { * @note The associated function is invoked by an interrupt handler. */ void chVTSetI(VirtualTimer *vtp, t_time time, t_vtfunc vtfunc, void *par) { - VirtualTimer *p; vtp->vt_func = vtfunc; vtp->vt_par = par; - p = dlist.dl_next; - while (p->vt_dtime < time) { - time -= p->vt_dtime; - p = p->vt_next; - } - vtp->vt_prev = (vtp->vt_next = p)->vt_prev; - vtp->vt_prev->vt_next = p->vt_prev = vtp; - vtp->vt_dtime = time; - if (p != (VirtualTimer *)&dlist) - p->vt_dtime -= time; + if (time) { + VirtualTimer *p = dlist.dl_next; + while (p->vt_dtime < time) { + time -= p->vt_dtime; + p = p->vt_next; + } + + vtp->vt_prev = (vtp->vt_next = p)->vt_prev; + vtp->vt_prev->vt_next = p->vt_prev = vtp; + vtp->vt_dtime = time; + if (p != (VirtualTimer *)&dlist) + p->vt_dtime -= time; + } } /** diff --git a/src/chevents.c b/src/chevents.c index 9094f45cd..a38975216 100644 --- a/src/chevents.c +++ b/src/chevents.c @@ -104,7 +104,7 @@ void chEvtSend(EventSource *esp) { chSchReadyI(tp); elp = elp->el_next; } - chSchRescheduleI(); + chSchRescheduleS(); chSysUnlock(); } @@ -112,7 +112,7 @@ void chEvtSend(EventSource *esp) { /** * Signals all the Event Listeners registered on the specified Event Source. * @param esp pointer to the \p EventSource structure - * @note This function must be called with interrupts disabled. + * @note This function does not reschedule. */ void chEvtSendI(EventSource *esp) { EventListener *elp; @@ -153,7 +153,7 @@ t_eventid chEvtWait(t_eventmask ewmask, if ((currp->p_epending & ewmask) == 0) { currp->p_ewmask = ewmask; - chSchGoSleepI(PRWTEVENT); + chSchGoSleepS(PRWTEVENT); } i = 0, m = 1; while ((currp->p_epending & ewmask & m) == 0) @@ -219,7 +219,7 @@ t_eventid chEvtWaitTimeout(t_eventmask ewmask, chVTSetI(&vt, time, unwait, currp); currp->p_ewmask = ewmask; - chSchGoSleepI(PRWTEVENT); + chSchGoSleepS(PRWTEVENT); if (!vt.vt_func) { chSysUnlock(); diff --git a/src/chmsg.c b/src/chmsg.c index 7a25502b0..4140e3165 100644 --- a/src/chmsg.c +++ b/src/chmsg.c @@ -40,7 +40,7 @@ t_msg chMsgSend(Thread *tp, t_msg msg) { if (tp->p_state == PRWTMSG) chSchReadyI(tp); currp->p_msg = msg; - chSchGoSleepI(PRSNDMSG); + chSchGoSleepS(PRSNDMSG); msg = currp->p_rdymsg; chSysUnlock(); @@ -71,7 +71,7 @@ t_msg chMsgSendWithEvent(Thread *tp, t_msg msg, EventSource *esp) { // chSchReadyI(tp); chEvtSendI(esp); currp->p_msg = msg; - chSchGoSleepI(PRSNDMSG); + chSchGoSleepS(PRSNDMSG); msg = currp->p_rdymsg; chSysUnlock(); @@ -113,7 +113,7 @@ t_msg chMsgSendTimeout(Thread *tp, t_msg msg, t_time time) { if (tp->p_state == PRWTMSG) chSchReadyI(tp); currp->p_msg = msg; - chSchGoSleepI(PRSNDMSG); + chSchGoSleepS(PRSNDMSG); msg = currp->p_rdymsg; if (vt.vt_func) chVTResetI(&vt); @@ -138,7 +138,7 @@ t_msg chMsgWait(void) { chSysLock(); if (!chMsgIsPendingI(currp)) - chSchGoSleepI(PRWTMSG); + chSchGoSleepS(PRWTMSG); msg = chMsgGetI(currp); chSysUnlock(); @@ -183,7 +183,7 @@ void chMsgRelease(t_msg msg) { chSysLock(); // if (!chMsgIsPendingI(currp) - chSchWakeupI(fifo_remove(&currp->p_msgqueue), msg); + chSchWakeupS(fifo_remove(&currp->p_msgqueue), msg); chSysUnlock(); } diff --git a/src/chqueues.c b/src/chqueues.c index 225492e60..88eac2184 100644 --- a/src/chqueues.c +++ b/src/chqueues.c @@ -145,10 +145,10 @@ t_msg chIQGetTimeout(Queue *qp, t_time time) { * is non-blocking and can return zero if the queue is empty. * @param qp pointer to a \p Queue structure * @param buffer the data buffer - * @param n the maxium amount of data to be read + * @param n the maximum amount of data to be read * @return the number of bytes read * @note This function is the upper side endpoint of the input queue. - * @note The function is not atomical, if you need atomicity it is suggested + * @note The function is not atomic, if you need atomicity it is suggested * to use a semaphore for mutual exclusion. */ t_size chIQRead(Queue *qp, BYTE8 *buffer, t_size n) { @@ -167,9 +167,6 @@ t_size chIQRead(Queue *qp, BYTE8 *buffer, t_size n) { if (qp->q_rdptr >= qp->q_top) qp->q_rdptr = qp->q_buffer; -// if (qp->q_notify) -// qp->q_notify(); - chSysUnlock(); r++; } @@ -264,9 +261,9 @@ t_msg chOQGetI(Queue *qp) { * is non-blocking and can return zero if the queue is full. * @param qp pointer to a \p Queue structure * @param buffer the data buffer - * @param n the maxium amount of data to be written + * @param n the maximum amount of data to be written * @note This function is the upper side endpoint of the output queue. - * @note The function is not atomical, if you need atomicity it is suggested + * @note The function is not atomic, if you need atomicity it is suggested * to use a semaphore for mutual exclusion. */ t_size chOQWrite(Queue *qp, BYTE8 *buffer, t_size n) { @@ -285,9 +282,6 @@ t_size chOQWrite(Queue *qp, BYTE8 *buffer, t_size n) { if (qp->q_wrptr >= qp->q_top) qp->q_wrptr = qp->q_buffer; -// if (qp->q_notify) -// qp->q_notify(); - chSysUnlock(); w++; } diff --git a/src/chschd.c b/src/chschd.c index 254f87937..c95c0cd0e 100644 --- a/src/chschd.c +++ b/src/chschd.c @@ -98,7 +98,7 @@ static void nextready(void) { * @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. */ -void chSchGoSleepI(t_tstate newstate) { +void chSchGoSleepS(t_tstate newstate) { currp->p_state = newstate; nextready(); @@ -115,7 +115,7 @@ void chSchGoSleepI(t_tstate newstate) { * @note It is equivalent to a \p chSchReadyI() followed by a * \p chSchRescheduleI() but much more efficient. */ -void chSchWakeupI(Thread *tp, t_msg msg) { +void chSchWakeupS(Thread *tp, t_msg msg) { Thread *ctp = currp; if (tp->p_prio <= ctp->p_prio) @@ -134,7 +134,7 @@ void chSchWakeupI(Thread *tp, t_msg msg) { * ready list then it becomes running. * @note The function must be called in the system mutex zone. */ -void chSchRescheduleI(void) { +void chSchRescheduleS(void) { if (isempty(&rlist.r_queue) || firstprio(&rlist.r_queue) <= currp->p_prio) return; diff --git a/src/chsem.c b/src/chsem.c index 70741c4f0..a58ee71b1 100644 --- a/src/chsem.c +++ b/src/chsem.c @@ -55,7 +55,7 @@ void chSemReset(Semaphore *sp, t_cnt n) { if (cnt < 0) { while (cnt++) chSchReadyI(fifo_remove(&sp->s_queue))->p_rdymsg = RDY_RESET; - chSchRescheduleI(); + chSchRescheduleS(); } chSysUnlock(); @@ -68,7 +68,7 @@ void chSemReset(Semaphore *sp, t_cnt n) { * @note The released threads can recognize they were waked up by a reset * instead than a signal because the \p p_rdymsg field is set to * \p RDY_RESET. - * @note This function must be called with interrupts disabled. + * @note This function does not reschedule. */ void chSemResetI(Semaphore *sp, t_cnt n) { t_cnt cnt; @@ -90,7 +90,7 @@ void chSemWait(Semaphore *sp) { if (--sp->s_cnt < 0) { fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); } chSysUnlock(); @@ -107,7 +107,7 @@ void chSemWaitS(Semaphore *sp) { if (--sp->s_cnt < 0) { fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); } } @@ -137,7 +137,7 @@ t_msg chSemWaitTimeout(Semaphore *sp, t_time time) { chVTSetI(&vt, time, unwait, currp); fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); msg = currp->p_rdymsg; if (vt.vt_func) chVTResetI(&vt); @@ -168,7 +168,7 @@ t_msg chSemWaitTimeoutS(Semaphore *sp, t_time time) { chVTSetI(&vt, time, unwait, currp); fifo_insert(currp, &sp->s_queue); currp->p_semp = sp; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); if (vt.vt_func) chVTResetI(&vt); return currp->p_rdymsg; @@ -188,7 +188,7 @@ void chSemSignal(Semaphore *sp) { chSysLock(); if (sp->s_cnt++ < 0) - chSchWakeupI(fifo_remove(&sp->s_queue), RDY_OK); + chSchWakeupS(fifo_remove(&sp->s_queue), RDY_OK); chSysUnlock(); } @@ -199,6 +199,7 @@ void chSemSignal(Semaphore *sp) { * @note This function must be called with interrupts disabled. * @note The function is available only if the \p CH_USE_SEMAPHORES * option is enabled in \p chconf.h. + * @note This function does not reschedule. */ void chSemSignalI(Semaphore *sp) { @@ -224,10 +225,10 @@ void chSemSignalWait(Semaphore *sps, Semaphore *spw) { if (--spw->s_cnt < 0) { fifo_insert(currp, &spw->s_queue); currp->p_semp = spw; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); } else - chSchRescheduleI(); + chSchRescheduleS(); chSysUnlock(); } @@ -265,7 +266,7 @@ void chSemRaisePrioWait(Semaphore *sp) { if (--sp->s_cnt < 0) { prioenq(currp, &sp->s_queue); currp->p_semp = sp; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); } if (!currp->p_rtcnt++) @@ -288,10 +289,10 @@ void chSemLowerPrioSignal(Semaphore *sp) { currp->p_prio -= MEPRIO; if (sp->s_cnt++ < 0) chSchReadyI(fifo_remove(&sp->s_queue)); - chSchRescheduleI(); + chSchRescheduleS(); } else if (sp->s_cnt++ < 0) - chSchWakeupI(fifo_remove(&sp->s_queue), RDY_OK); + chSchWakeupS(fifo_remove(&sp->s_queue), RDY_OK); chSysUnlock(); } @@ -315,7 +316,7 @@ void chSemRaisePrioSignalWait(Semaphore *sps, Semaphore *spw) { if (--spw->s_cnt < 0) { prioenq(currp, &spw->s_queue); currp->p_semp = spw; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); if (!currp->p_rtcnt++) currp->p_prio += MEPRIO; @@ -324,7 +325,7 @@ void chSemRaisePrioSignalWait(Semaphore *sps, Semaphore *spw) { if (!currp->p_rtcnt++) currp->p_prio += MEPRIO; - chSchRescheduleI(); // Really needed ? + chSchRescheduleS(); // Really needed ? } chSysUnlock(); @@ -351,10 +352,10 @@ void chSemLowerPrioSignalWait(Semaphore *sps, Semaphore *spw) { if (--spw->s_cnt < 0) { fifo_insert(currp, &spw->s_queue); // fifo_insert() because the spw is a normal sem. currp->p_semp = spw; - chSchGoSleepI(PRWTSEM); + chSchGoSleepS(PRWTSEM); } else - chSchRescheduleI(); + chSchRescheduleS(); chSysUnlock(); } diff --git a/src/chsleep.c b/src/chsleep.c index 5814410f3..6c8cfc3c3 100644 --- a/src/chsleep.c +++ b/src/chsleep.c @@ -35,7 +35,7 @@ void chThdSleep(t_time time) { chSysLock(); chVTSetI(&vt, time, (t_vtfunc)chSchReadyI, currp); - chSchGoSleepI(PRSLEEP); + chSchGoSleepS(PRSLEEP); chSysUnlock(); } @@ -67,7 +67,7 @@ void chThdSleepUntil(t_time time) { chSysLock(); chVTSetI(&vt, (t_time)(time - stime), (t_vtfunc)chSchReadyI, currp); - chSchGoSleepI(PRSLEEP); + chSchGoSleepS(PRSLEEP); chSysUnlock(); } diff --git a/src/chthreads.c b/src/chthreads.c index 28b276db5..00ae04778 100644 --- a/src/chthreads.c +++ b/src/chthreads.c @@ -91,7 +91,7 @@ Thread *chThdCreate(t_prio prio, t_tmode mode, void *workspace, #endif chSysLock(); - chSchWakeupI(tp, RDY_OK); + chSchWakeupS(tp, RDY_OK); chSysUnlock(); #ifdef CH_USE_RESUME @@ -116,7 +116,7 @@ void chThdSetPriority(t_prio newprio) { #else currp->p_prio = newprio; #endif - chSchRescheduleI(); + chSchRescheduleS(); chSysUnlock(); } @@ -135,7 +135,7 @@ void chThdResume(Thread *tp) { chSysLock(); if (tp->p_state == PRSUSPENDED) - chSchWakeupI(tp, RDY_OK); + chSchWakeupS(tp, RDY_OK); chSysUnlock(); } @@ -176,7 +176,7 @@ void chThdExit(t_msg msg) { #ifdef CH_USE_EXIT_EVENT chEvtSendI(&currp->p_exitesource); #endif - chSchGoSleepI(PREXIT); + chSchGoSleepS(PREXIT); chSysUnlock(); /* Never executed. */ } @@ -196,7 +196,7 @@ t_msg chThdWait(Thread *tp) { if (tp->p_state != PREXIT) { list_insert(currp, &tp->p_waiting); - chSchGoSleepI(PRWAIT); + chSchGoSleepS(PRWAIT); } chSysUnlock(); diff --git a/src/include/delta.h b/src/include/delta.h index 46fd3b883..1af774959 100644 --- a/src/include/delta.h +++ b/src/include/delta.h @@ -81,6 +81,9 @@ extern DeltaList dlist; } \ } +/** Infinite time specification.*/ +#define TIME_INFINITE 0 + /* * Virtual Timers APIs. */ diff --git a/src/include/scheduler.h b/src/include/scheduler.h index 884b3936c..fccbfb446 100644 --- a/src/include/scheduler.h +++ b/src/include/scheduler.h @@ -50,9 +50,9 @@ extern "C" { #endif void chSchInit(void); Thread *chSchReadyI(Thread *tp); - void chSchGoSleepI(t_tstate newstate); - void chSchWakeupI(Thread *tp, t_msg msg); - void chSchRescheduleI(void); + void chSchGoSleepS(t_tstate newstate); + void chSchWakeupS(Thread *tp, t_msg msg); + void chSchRescheduleS(void); void chSchDoRescheduleI(void); BOOL chSchRescRequiredI(void); void chSchTimerHandlerI(void);