* 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, 2008 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.
#endif
#if CONFIG_KERNEL
- #include <config_kern.h>
- #if CONFIG_KERN_PREEMPTIVE
- #include <hw/switch.h>
- #endif
#if CONFIG_KERN_SIGNALS
#include <kern/signal.h> /* sig_wait(), sig_check() */
#include <kern/proc.h> /* proc_current() */
volatile ticks_t _clock;
-#ifndef CONFIG_TIMER_DISABLE_EVENTS
+#if CONFIG_TIMER_EVENTS
/**
* List of active asynchronous timers.
/**
- * 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)
{
return timer;
}
-#endif /* CONFIG_TIMER_DISABLE_EVENTS */
+#endif /* CONFIG_TIMER_EVENTS */
/**
*/
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;
}
-#ifndef CONFIG_TIMER_DISABLE_UDELAY
+#if CONFIG_TIMER_UDELAY
/**
* Busy wait until the specified amount of high-precision ticks have elapsed.
timer_busyWait(delay);
}
-#endif /* CONFIG_TIMER_DISABLE_UDELAY */
+#endif /* CONFIG_TIMER_UDELAY */
/**
#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.
/* 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
/* Execute the associated event */
event_do(&timer->expire);
}
-#endif /* CONFIG_TIMER_DISABLE_EVENTS */
+#endif /* CONFIG_TIMER_EVENTS */
TIMER_STROBE_OFF;
}
{
TIMER_STROBE_INIT;
-#ifndef CONFIG_TIMER_DISABLE_EVENTS
+#if CONFIG_TIMER_EVENTS
LIST_INIT(&timers_queue);
#endif
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 */