X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Ftimer.c;h=485cc0229d2192796b6c2cfe2d1ae630654a9984;hb=cfa8814ca45e8bae9b36713bc534ecb581834016;hp=4ddf06057503ff1370c59a7907810566a898a780;hpb=11da44352fcd4d33b173c976db45293ac1a87cca;p=bertos.git diff --git a/bertos/drv/timer.c b/bertos/drv/timer.c index 4ddf0605..485cc022 100644 --- a/bertos/drv/timer.c +++ b/bertos/drv/timer.c @@ -27,20 +27,20 @@ * the GNU General Public License. * * Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/) - * Copyright 2000 Bernardo Innocenti - * + * Copyright 2000, 2008 Bernie Innocenti * --> * * \brief Hardware independent timer driver (implementation) * * \version $Id$ - * \author Bernardo Innocenti + * \author Bernie Innocenti */ #include "timer.h" -#include -#include +#include "cfg/cfg_timer.h" +#include "cfg/cfg_wdt.h" +#include "cfg/cfg_kern.h" #include #include #include @@ -54,7 +54,8 @@ * Try the CPU specific one for bare-metal environments. */ #if OS_HOSTED - #include OS_CSOURCE(timer) + //#include OS_CSOURCE(timer) + #include #else #include CPU_CSOURCE(timer) #endif @@ -74,10 +75,6 @@ #endif #if CONFIG_KERNEL - #include - #if CONFIG_KERN_PREEMPTIVE - #include - #endif #if CONFIG_KERN_SIGNALS #include /* sig_wait(), sig_check() */ #include /* proc_current() */ @@ -107,7 +104,7 @@ volatile ticks_t _clock; -#ifndef CONFIG_TIMER_DISABLE_EVENTS +#if CONFIG_TIMER_EVENTS /** * List of active asynchronous timers. @@ -163,7 +160,10 @@ void timer_add(Timer *timer) /** - * Remove a timer from the timer queue before it has expired. + * Remove a timer from the timers queue before it has expired. + * + * \note Attempting to remove a timer already expired cause + * undefined behaviour. */ Timer *timer_abort(Timer *timer) { @@ -173,7 +173,7 @@ Timer *timer_abort(Timer *timer) return timer; } -#endif /* CONFIG_TIMER_DISABLE_EVENTS */ +#endif /* CONFIG_TIMER_EVENTS */ /** @@ -181,16 +181,14 @@ Timer *timer_abort(Timer *timer) */ void timer_delayTicks(ticks_t delay) { -#if defined(IRQ_ENABLED) /* We shouldn't sleep with interrupts disabled */ - ASSERT(IRQ_ENABLED()); -#endif + ASSERT_IRQ_ENABLED(); #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS Timer t; ASSERT(!sig_check(SIG_SINGLE)); - timer_set_event_signal(&t, proc_current(), SIG_SINGLE); + timer_setSignal(&t, proc_current(), SIG_SINGLE); timer_setDelay(&t, delay); timer_add(&t); sig_wait(SIG_SINGLE); @@ -211,7 +209,7 @@ void timer_delayTicks(ticks_t delay) } -#ifndef CONFIG_TIMER_DISABLE_UDELAY +#if CONFIG_TIMER_UDELAY /** * Busy wait until the specified amount of high-precision ticks have elapsed. @@ -257,7 +255,7 @@ void timer_delayHp(hptime_t delay) timer_busyWait(delay); } -#endif /* CONFIG_TIMER_DISABLE_UDELAY */ +#endif /* CONFIG_TIMER_UDELAY */ /** @@ -275,9 +273,10 @@ DEFINE_TIMER_ISR #pragma interrupt saveall #endif -#ifndef CONFIG_TIMER_DISABLE_EVENTS +#if CONFIG_TIMER_EVENTS Timer *timer; #endif + /* * On systems sharing IRQ line and vector, this check is needed * to ensure that IRQ is generated by timer source. @@ -293,7 +292,7 @@ DEFINE_TIMER_ISR /* Update the master ms counter */ ++_clock; -#ifndef CONFIG_TIMER_DISABLE_EVENTS +#if CONFIG_TIMER_EVENTS /* * Check the first timer request in the list and process * it when it has expired. Repeat this check until the @@ -314,7 +313,7 @@ DEFINE_TIMER_ISR /* Execute the associated event */ event_do(&timer->expire); } -#endif /* CONFIG_TIMER_DISABLE_EVENTS */ +#endif /* CONFIG_TIMER_EVENTS */ TIMER_STROBE_OFF; } @@ -328,7 +327,7 @@ void timer_init(void) { TIMER_STROBE_INIT; -#ifndef CONFIG_TIMER_DISABLE_EVENTS +#if CONFIG_TIMER_EVENTS LIST_INIT(&timers_queue); #endif @@ -338,3 +337,19 @@ void timer_init(void) MOD_INIT(timer); } + + +#if (ARCH & ARCH_EMUL) +/** + * Stop timer (only used by emulator) + */ +void timer_cleanup(void) +{ + MOD_CLEANUP(timer); + + timer_hw_cleanup(); + + // Hmmm... apparently, the demo app does not cleanup properly + //ASSERT(LIST_EMPTY(&timers_queue)); +} +#endif /* ARCH_EMUL */