X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Ftimer.c;h=d832059086a563134303e16f87146f5cd1691bba;hb=fbb255258c626502f8d7ba583ca138f903e03b75;hp=808a6a7fba25fa24d59b5d955ae760fb70ef992f;hpb=9c41a52cad9f3a8e7c7ec1c29f8722c722d4698d;p=bertos.git diff --git a/bertos/drv/timer.c b/bertos/drv/timer.c index 808a6a7f..d8320590 100644 --- a/bertos/drv/timer.c +++ b/bertos/drv/timer.c @@ -27,21 +27,21 @@ * 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 "cfg/cfg_timer.h" #include "cfg/cfg_wdt.h" -#include "cfg/cfg_kern.h" +#include "cfg/cfg_proc.h" +#include "cfg/cfg_signal.h" #include #include #include @@ -49,22 +49,27 @@ #include #include #include +#include // cpu_relax() /* * Include platform-specific binding code if we're hosted. * 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) + #ifndef WIZ_AUTOGEN + #warning Deprecated: now you should include timer_ directly in the makefile. Remove this line and the following once done. + #include CPU_CSOURCE(timer) + #endif #endif /* * Sanity check for config parameters required by this module. */ -#if !defined(CONFIG_KERNEL) || ((CONFIG_KERNEL != 0) && CONFIG_KERNEL != 1) - #error CONFIG_KERNEL must be set to either 0 or 1 in config.h +#if !defined(CONFIG_KERN) || ((CONFIG_KERN != 0) && CONFIG_KERN != 1) + #error CONFIG_KERN must be set to either 0 or 1 in config.h #endif #if !defined(CONFIG_WATCHDOG) || ((CONFIG_WATCHDOG != 0) && CONFIG_WATCHDOG != 1) #error CONFIG_WATCHDOG must be set to either 0 or 1 in config.h @@ -74,15 +79,10 @@ #include #endif -#if CONFIG_KERNEL - #if CONFIG_KERN_PREEMPTIVE - #include - #endif - #if CONFIG_KERN_SIGNALS - #include /* sig_wait(), sig_check() */ - #include /* proc_current() */ - #include /* BV() */ - #endif +#if defined (CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS + #include /* sig_wait(), sig_check() */ + #include /* proc_current() */ + #include /* BV() */ #endif @@ -107,7 +107,7 @@ volatile ticks_t _clock; -#ifndef CONFIG_TIMER_DISABLE_EVENTS +#if CONFIG_TIMER_EVENTS /** * List of active asynchronous timers. @@ -125,7 +125,7 @@ REGISTER static List timers_queue; void timer_add(Timer *timer) { Timer *node; - cpuflags_t flags; + cpu_flags_t flags; /* Inserting timers twice causes mayhem. */ @@ -163,7 +163,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 +176,7 @@ Timer *timer_abort(Timer *timer) return timer; } -#endif /* CONFIG_TIMER_DISABLE_EVENTS */ +#endif /* CONFIG_TIMER_EVENTS */ /** @@ -181,17 +184,14 @@ Timer *timer_abort(Timer *timer) */ void timer_delayTicks(ticks_t delay) { -#if defined(IRQ_ENABLED) && (!(ARCH & ARCH_EMUL)) /* We shouldn't sleep with interrupts disabled */ - ASSERT(IRQ_ENABLED()); -#endif - + IRQ_ASSERT_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); @@ -202,17 +202,13 @@ void timer_delayTicks(ticks_t delay) /* Busy wait */ while (timer_clock() - start < delay) - { -#if CONFIG_WATCHDOG - wdt_reset(); -#endif - } + cpu_relax(); #endif /* !CONFIG_KERN_SIGNALS */ } -#ifndef CONFIG_TIMER_DISABLE_UDELAY +#if CONFIG_TIMER_UDELAY /** * Busy wait until the specified amount of high-precision ticks have elapsed. @@ -258,7 +254,7 @@ void timer_delayHp(hptime_t delay) timer_busyWait(delay); } -#endif /* CONFIG_TIMER_DISABLE_UDELAY */ +#endif /* CONFIG_TIMER_UDELAY */ /** @@ -276,9 +272,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. @@ -294,7 +291,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 @@ -315,7 +312,7 @@ DEFINE_TIMER_ISR /* Execute the associated event */ event_do(&timer->expire); } -#endif /* CONFIG_TIMER_DISABLE_EVENTS */ +#endif /* CONFIG_TIMER_EVENTS */ TIMER_STROBE_OFF; } @@ -327,11 +324,15 @@ MOD_DEFINE(timer) */ void timer_init(void) { - TIMER_STROBE_INIT; + #if CONFIG_KERN_IRQ + MOD_CHECK(irq); + #endif -#ifndef CONFIG_TIMER_DISABLE_EVENTS - LIST_INIT(&timers_queue); -#endif + #if CONFIG_TIMER_EVENTS + LIST_INIT(&timers_queue); + #endif + + TIMER_STROBE_INIT; _clock = 0; @@ -339,3 +340,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 */