log: Retouch documentation; Rearrenge level logic; Rename LOG_VERBOSITY to LOG_FORMAT...
[bertos.git] / bertos / drv / timer.c
index 0e756dbb6cb01c435062380cbd60536d0e165520..942726399b1e47b0ebb102acd06b308592494ec7 100644 (file)
  * the GNU General Public License.
  *
  * Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/)
- * Copyright 2000 Bernardo Innocenti <bernie@develer.com>
+ * Copyright 2000 Bernie Innocenti <bernie@codewiz.org>
  *
  * -->
  *
  * \brief Hardware independent timer driver (implementation)
  *
  * \version $Id$
- * \author Bernardo Innocenti <bernie@develer.com>
+ * \author Bernie Innocenti <bernie@codewiz.org>
  */
 
 #include "timer.h"
 
-#include <cpu/attr.h>
-#include <cpu/types.h>
-#include <cpu/irq.h>
-
+#include "cfg/cfg_timer.h"
+#include "cfg/cfg_wdt.h"
+#include "cfg/cfg_kern.h"
 #include <cfg/os.h>
 #include <cfg/debug.h>
 #include <cfg/module.h>
-#include <appconfig.h>
+
+#include <cpu/attr.h>
+#include <cpu/types.h>
+#include <cpu/irq.h>
 
 /*
  * Include platform-specific binding code if we're hosted.
@@ -73,7 +75,6 @@
 #endif
 
 #if CONFIG_KERNEL
-       #include <config_kern.h>
        #if CONFIG_KERN_PREEMPTIVE
                #include <hw/switch.h>
        #endif
@@ -162,7 +163,9 @@ 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)
 {
@@ -180,11 +183,12 @@ Timer *timer_abort(Timer *timer)
  */
 void timer_delayTicks(ticks_t delay)
 {
-#if defined(IRQ_ENABLED)
+#if defined(IRQ_ENABLED) && (!(ARCH & ARCH_EMUL))
        /* We shouldn't sleep with interrupts disabled */
        ASSERT(IRQ_ENABLED());
 #endif
 
+
 #if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
        Timer t;
 
@@ -337,3 +341,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 */