From f2ced068fb80aa38326e1ef75eafdd5834e9017a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 23 Nov 2007 13:53:53 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@107 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARM7-LPC214x-GCC/main.c | 10 +++++----- readme.txt | 1 + src/chschd.c | 10 ++-------- src/chsem.c | 1 + src/chsleep.c | 13 +++++++++++-- src/include/scheduler.h | 3 +++ src/include/sleep.h | 3 +-- src/lib/evtimer.h | 10 ---------- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/demos/ARM7-LPC214x-GCC/main.c b/demos/ARM7-LPC214x-GCC/main.c index 71fba60a8..b98747d20 100644 --- a/demos/ARM7-LPC214x-GCC/main.c +++ b/demos/ARM7-LPC214x-GCC/main.c @@ -139,13 +139,13 @@ int main(int argc, char **argv) { * Normal main() activity, in this demo it serves events generated by * various sources. */ - evtInit(&evt, 500); /* Initializes an event timer object. */ - evtRegister(&evt, &el0, 0); /* Registers on the timer event source. */ - evtStart(&evt); /* Starts the event timer. */ - mmcStartPolling(); /* Starts the MMC connector polling. */ + evtInit(&evt, 500); /* Initializes an event timer object. */ + evtStart(&evt); /* Starts the event timer. */ + chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */ + mmcStartPolling(); /* Starts the MMC connector polling. */ chEvtRegister(&MMCInsertEventSource, &el1, 1); chEvtRegister(&MMCRemoveEventSource, &el2, 2); - while (TRUE) /* Just serve events. */ + while (TRUE) /* Just serve events. */ chEvtWait(ALL_EVENTS, evhndl); return 0; } diff --git a/readme.txt b/readme.txt index cb8226b4b..eb8dc38c9 100644 --- a/readme.txt +++ b/readme.txt @@ -60,6 +60,7 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not complete yet. It is expanded as: ULONG32 waThread1[UserStackSpace(32) >> 2]; Now the demos use the new declaration style. +- Fixed a small problem in sleep functions introduced in 0.4.1. *** 0.4.1 *** - Modified the initialization code in order to have a dedicated idle thread in diff --git a/src/chschd.c b/src/chschd.c index 7ad33d82f..65a1fd360 100644 --- a/src/chschd.c +++ b/src/chschd.c @@ -25,13 +25,7 @@ #include /** @cond never*/ - ReadyList rlist; - -#ifdef CH_USE_SYSTEMTIME -volatile t_time stime; -#endif - /** @endcond */ /** @@ -44,7 +38,7 @@ void chSchInit(void) { rlist.r_prio = ABSPRIO; rlist.r_preempt = CH_TIME_QUANTUM; #ifdef CH_USE_SYSTEMTIME - stime = 0; + rlist.r_stime = 0; #endif } @@ -193,7 +187,7 @@ void chSchTimerHandlerI(void) { rlist.r_preempt--; #ifdef CH_USE_SYSTEMTIME - stime++; + rlist.r_stime++; #endif #ifdef CH_USE_VIRTUAL_TIMERS diff --git a/src/chsem.c b/src/chsem.c index 6f24b08ec..df783dc7a 100644 --- a/src/chsem.c +++ b/src/chsem.c @@ -113,6 +113,7 @@ void chSemWaitS(Semaphore *sp) { #ifdef CH_USE_SEMAPHORES_TIMEOUT static void wakeup(void *p) { + #ifdef CH_USE_DEBUG if (((Thread *)p)->p_state != PRWTSEM) chDbgPanic("chsem.c, wakeup()\r\n"); diff --git a/src/chsleep.c b/src/chsleep.c index e8703ab1a..ae6e394b8 100644 --- a/src/chsleep.c +++ b/src/chsleep.c @@ -25,6 +25,15 @@ #include #ifdef CH_USE_SLEEP +static void wakeup(void *p) { + +#ifdef CH_USE_DEBUG + if (((Thread *)p)->p_state != PRSLEEP) + chDbgPanic("chsleep.c, wakeup()\r\n"); +#endif + chSchReadyI(p, RDY_OK); +} + /** * Suspends the invoking thread for the specified time. * @param time the system ticks number @@ -34,7 +43,7 @@ void chThdSleep(t_time time) { chSysLock(); - chVTSetI(&vt, time, (t_vtfunc)chSchReadyI, currp); + chVTSetI(&vt, time, wakeup, currp); chSchGoSleepS(PRSLEEP); chSysUnlock(); @@ -53,7 +62,7 @@ void chThdSleepUntil(t_time time) { chSysLock(); - chVTSetI(&vt, (t_time)(time - stime), (t_vtfunc)chSchReadyI, currp); + chVTSetI(&vt, (t_time)(time - rlist.r_stime), wakeup, currp); chSchGoSleepS(PRSLEEP); chSysUnlock(); diff --git a/src/include/scheduler.h b/src/include/scheduler.h index 89bc37292..bb70a83af 100644 --- a/src/include/scheduler.h +++ b/src/include/scheduler.h @@ -44,6 +44,9 @@ typedef struct { #ifndef CH_CURRP_REGISTER_CACHE Thread *r_current; #endif +#ifdef CH_USE_SYSTEMTIME + volatile t_time r_stime; +#endif } ReadyList; extern ReadyList rlist; diff --git a/src/include/sleep.h b/src/include/sleep.h index e102a03a5..161842a29 100644 --- a/src/include/sleep.h +++ b/src/include/sleep.h @@ -32,7 +32,6 @@ extern "C" { void chThdSleep(t_time time); #ifdef CH_USE_SYSTEMTIME void chThdSleepUntil(t_time time); - t_time chSysGetTime(void); #endif /* CH_USE_SYSTEMTIME */ #endif /* CH_USE_SLEEP */ #ifdef __cplusplus @@ -47,7 +46,7 @@ extern "C" { * @note The function is available only if the \p CH_USE_SYSTEMTIME * option is enabled in \p chconf.h. */ -#define chSysGetTime() stime +#define chSysGetTime() rlist.r_stime #endif /* _SLEEP_H_ */ diff --git a/src/lib/evtimer.h b/src/lib/evtimer.h index dfe09f0be..5999563d1 100644 --- a/src/lib/evtimer.h +++ b/src/lib/evtimer.h @@ -50,16 +50,6 @@ extern "C" { (etp)->et_vt.vt_func = NULL, \ (etp)->et_interval = (i)) -/** - * Registers the invoking thread as listener on the timer event. - */ -#define evtRegister(etp, el, eid) chEvtRegister(&(etp)->et_es, el, eid) - -/** - * Unregisters the invoking thread as listener on the timer event. - */ -#define evtUnregister(etp, el) chEvtUnregister(&(etp)->et_es, el) - #endif /* _EVTIMER_H_ */ /** @} */