]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[Timers] Miscellaneous timer system fixes
authorMichael Brown <mcb30@etherboot.org>
Tue, 18 Mar 2008 14:48:28 +0000 (14:48 +0000)
committerMichael Brown <mcb30@etherboot.org>
Tue, 18 Mar 2008 14:48:28 +0000 (14:48 +0000)
Add missing comments to timer code.

Lock system if no suitable timer source is found.

Fix initialisation order so that timers are initialised before code that
needs to use them.

src/core/serial.c
src/core/timer.c
src/include/gpxe/init.h
src/include/gpxe/timer.h

index f6d0ecbb9670e8b2303cafe1eb589f6935b3562a..a5b3f9135892d037d4994dc45a3b3949541afbaf 100644 (file)
@@ -263,6 +263,6 @@ struct startup_fn serial_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
  * early debug messages.  It is safe to call serial_init() multiple
  * times.
  */
-struct init_fn serial_init_fn __init_fn ( INIT_EARLY ) = {
+struct init_fn serial_init_fn __init_fn ( INIT_CONSOLE ) = {
        .initialise = serial_init,
 };
index e736f5285f408368426b0074d85f1952322a6d85..ef80c0441b79e2ec33013a8f31154791be31dff9 100644 (file)
@@ -22,7 +22,6 @@
 #include <assert.h>
 #include <gpxe/init.h>
 #include <gpxe/timer.h>
-#include <stdio.h>
 
 static struct timer ts_table[0]
        __table_start ( struct timer, timers );
@@ -53,48 +52,64 @@ static void timer_init(void)
        struct timer *ts;
 
        for (ts = ts_table; ts < ts_table_end; ts++) {
-               if (ts->init && ts->init() >= 0) {
+               if ( ts->init() == 0 ) {
                        used_ts = ts;
-                       break;
+                       return;
                }
        }
 
-       assert(used_ts);
+       /* No timer found; we cannot continue */
+       assert ( 0 );
+       while ( 1 ) {};
 }
 
 struct init_fn ts_init_fn __init_fn ( INIT_NORMAL ) = {
        .initialise = timer_init,
 };
 
-/* Functions for public use. */
-
-tick_t currticks(void)
-{
+/**
+ * Read current time
+ *
+ * @ret ticks  Current time, in ticks
+ */
+tick_t currticks ( void ) {
        tick_t ct;
        assert(used_ts);
 
        ct = used_ts->currticks();
-       DBG("currticks: %ld seconds and %06ld microseconds\n", ct/USECS_IN_SEC, ct%USECS_IN_SEC);
+       DBG ( "currticks: %ld.%06ld seconds\n",
+             ct / USECS_IN_SEC, ct % USECS_IN_SEC );
 
        return ct;
 }
 
-void udelay(unsigned int usecs)
-{
-       used_ts->udelay(usecs);
+/**
+ * Delay
+ *
+ * @v usecs    Time to delay, in microseconds
+ */
+void udelay ( unsigned int usecs ) {
+       assert(used_ts);
+       used_ts->udelay ( usecs );
 }
 
-void mdelay(unsigned int msecs)
-{
-       while(msecs--)
-               used_ts->udelay(USECS_IN_MSEC);
+/**
+ * Delay
+ *
+ * @v msecs    Time to delay, in milliseconds
+ */
+void mdelay ( unsigned int msecs ) {
+       while ( msecs-- )
+               udelay ( USECS_IN_MSEC );
 }
 
-unsigned int sleep(unsigned int secs)
-{
-       while (secs--)
-               mdelay(MSECS_IN_SEC);
-
+/**
+ * Delay
+ *
+ * @v secs     Time to delay, in seconds
+ */
+unsigned int sleep ( unsigned int secs ) {
+       while ( secs-- )
+               mdelay ( MSECS_IN_SEC );
        return 0;
 }
-
index a5caa3e0ef6d66f3c007f0c4ecf99312ea09bc28..d83aa5e55d9bb6d873fcb48f03ccabf5925dcf57 100644 (file)
@@ -22,7 +22,8 @@ struct init_fn {
  */
 
 #define INIT_EARLY     01      /**< Early initialisation */
-#define INIT_NORMAL    02      /**< Normal initialisation */
+#define        INIT_CONSOLE    02      /**< Console initialisation */
+#define INIT_NORMAL    03      /**< Normal initialisation */
 
 /** @} */
 
@@ -54,14 +55,6 @@ struct startup_fn {
 
 /** @} */
 
-/* Use double digits to avoid problems with "10" < "9" on alphabetic sort */
-#define        INIT_CONSOLE    02
-#define        INIT_GDBSYM     03
-#define        INIT_CPU        04
-#define        INIT_TIMERS     05
-#define        INIT_LOADBUF    08
-#define        INIT_PCMCIA     09
-
 extern void initialise ( void );
 extern void startup ( void );
 extern void shutdown ( void );
index 4a4cf5b2ff02c19accc189aecae394836b7aae13..ecd300015d97f5da6ca91ab469980e3e9102cd63 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <stddef.h>
 
-typedef uint32_t tick_t;
+typedef unsigned long tick_t;
 
 #define MSECS_IN_SEC (1000)
 #define USECS_IN_SEC (1000*1000)
@@ -11,22 +11,30 @@ typedef uint32_t tick_t;
 
 #define        TICKS_PER_SEC   USECS_IN_SEC
 
-tick_t currticks(void);
+extern tick_t currticks ( void );
 
-void generic_currticks_udelay(unsigned int usecs);
+extern void generic_currticks_udelay ( unsigned int usecs );
 
+/** A timer */
 struct timer {
-       /* Returns zero on successful initialisation. */
-       int (*init) (void);
-
-       /* Return the current time, int mictoseconds since the beginning. */
-       tick_t (*currticks) (void);
-
-       /* Sleep for a few useconds. */
-       void (*udelay) (unsigned int useconds);
+       /** Initialise timer
+        *
+        * @ret rc      Return status code
+        */
+       int ( * init ) ( void );
+       /** Read current time
+        *
+        * @ret ticks   Current time, in ticks
+        */
+       tick_t ( * currticks ) ( void );
+       /** Delay
+        *
+        * @v usecs     Time to delay, in microseconds
+        */
+       void ( * udelay ) ( unsigned int usecs );
 };
 
-#define __timer(order) __table (struct timer, timers, order)
+#define __timer( order ) __table ( struct timer, timers, order )
 
 #endif /* GPXE_TIMER_H */