Put timer driver on diet.
[bertos.git] / drv / timer.c
index 385ef9c3f811b9c95441207c7329e00f1a42cf68..0621336856fb561587d4d7ea00a68ae2f4be7ad0 100755 (executable)
 
 /*
  * $Log$
+ * Revision 1.9  2004/07/21 00:15:13  bernie
+ * Put timer driver on diet.
+ *
+ * Revision 1.8  2004/07/18 21:57:07  bernie
+ * Fix preprocessor warning with potentially undefined symbol.
+ *
+ * Revision 1.6  2004/06/07 18:10:06  aleph
+ * Remove free pool of timers; use user-provided Timer structure instead
+ *
  * Revision 1.5  2004/06/07 15:56:55  aleph
  * Some tabs cleanup and add timer strobe macros
  *
 #include "kdebug.h"
 #include "timer.h"
 
-#ifdef CONFIG_KERN_SIGNALS
-#include <kern/proc.h>
+#if defined(CONFIG_KERN_SIGNALS) && CONFIG_KERN_SIGNALS
+       #include <kern/proc.h>
 #endif
 
-#if (ARCH & ARCH_EMUL)
+#if defined(ARCH_EMUL) && (ARCH & ARCH_EMUL)
        #error To be recoded
 #elif defined(__AVR__)
        #include "timer_avr.h"
 #endif
 
 
-/*! Number of available timers */
-#define MAX_TIMERS 4
-
-
 //! Master system clock (1ms accuracy)
 volatile time_t _clock;
 
-static Timer soft_timers[MAX_TIMERS];   /*!< Pool of Timer structures */
-static List timers_pool;                /*!< Pool of free timers */
-REGISTER static List timers_queue;      /*!< Active timers */
-
-
-/*!
- * Return a new timer picking and removing it from the available
- * timers pool. Return NULL if no more timers are available.
- */
-Timer *timer_new(void)
-{
-       Timer *timer;
-       cpuflags_t flags;
-
-       DISABLE_IRQSAVE(flags);
-
-       /* Should never happen */
-       if (ISLISTEMPTY(&timers_pool))
-       {
-               ENABLE_IRQRESTORE(flags);
-               DB(kprintf("Tmrspool empty\n");)
-               return NULL;
-       }
-
-       /* Get a timer from the free pool */
-       timer = (Timer *)timers_pool.head;
-       REMOVE((Node *)timer);
-
-       ENABLE_IRQRESTORE(flags);
-
-       return timer;
-}
 
+#ifndef CONFIG_TIMER_DISABLE_EVENTS
 
 /*!
- * Delete a timer, putting it in the available timers queue.
+ * List of active asynchronous timers.
  */
-void timer_delete(Timer *timer)
-{
-       cpuflags_t flags;
-       DISABLE_IRQSAVE(flags);
-       ADDHEAD(&timers_pool, &timer->link);
-       ENABLE_IRQRESTORE(flags);
-}
+REGISTER static List timers_queue;
 
 
 /*!
@@ -157,6 +125,8 @@ Timer *timer_abort(Timer *timer)
        return timer;
 }
 
+#endif /* CONFIG_TIMER_DISABLE_EVENTS */
+
 
 /*!
  * Wait for the specified amount of time (expressed in ms)
@@ -183,6 +153,7 @@ void timer_delay(time_t time)
 }
 
 
+#ifndef CONFIG_TIMER_DISABLE_UDELAY
 /*!
  * Wait for the specified amount of time (expressed in microseconds)
  *
@@ -207,6 +178,7 @@ void timer_udelay(utime_t usec_delay)
        while (timer_hw_hpread() - start < delay)
        {}
 }
+#endif /* CONFIG_TIMER_DISABLE_UDELAY */
 
 
 /*!
@@ -215,14 +187,18 @@ void timer_udelay(utime_t usec_delay)
  */
 DEFINE_TIMER_ISR
 {
-       /* With the Metrowerks compiler, the only way to force the compiler generate
-          an interrupt service routine is to put a pragma directive within the function
-          body. */
+       /*
+        * With the Metrowerks compiler, the only way to force the compiler generate
+        * an interrupt service routine is to put a pragma directive within the function
+        * body.
+        */
        #ifdef __MWERKS__
        #pragma interrupt saveall
        #endif
 
+#ifndef CONFIG_TIMER_DISABLE_EVENTS
        Timer *timer;
+#endif
 
        TIMER_STROBE_ON;
 
@@ -231,6 +207,7 @@ DEFINE_TIMER_ISR
        /* Update the master ms counter */
        ++_clock;
 
+#ifndef CONFIG_TIMER_DISABLE_EVENTS
        /*
         * Check the first timer request in the list and process
         * it when it has expired. Repeat this check until the
@@ -250,6 +227,7 @@ DEFINE_TIMER_ISR
                /* Execute the associated event */
                event_doIntr(&timer->expire);
        }
+#endif /* CONFIG_TIMER_DISABLE_EVENTS */
 
        TIMER_STROBE_OFF;
 }
@@ -260,19 +238,13 @@ DEFINE_TIMER_ISR
  */
 void timer_init(void)
 {
-       int i;
-
        TIMER_STROBE_INIT;
 
+#ifndef CONFIG_TIMER_DISABLE_EVENTS
        INITLIST(&timers_queue);
-       INITLIST(&timers_pool);
-
-       /* Init all software timers in the free pool */
-       for (i = 0; i < MAX_TIMERS; i++)
-               ADDTAIL(&timers_pool, (Node *)&soft_timers[i]);
+#endif
 
        _clock = 0;
 
        timer_hw_init();
 }
-