Browse Source

[Timers] Miscellaneous timer system fixes

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.
tags/v0.9.4
Michael Brown 17 years ago
parent
commit
2652abdc5f
4 changed files with 60 additions and 44 deletions
  1. 1
    1
      src/core/serial.c
  2. 37
    22
      src/core/timer.c
  3. 2
    9
      src/include/gpxe/init.h
  4. 20
    12
      src/include/gpxe/timer.h

+ 1
- 1
src/core/serial.c View File

@@ -263,6 +263,6 @@ struct startup_fn serial_startup_fn __startup_fn ( STARTUP_NORMAL ) = {
263 263
  * early debug messages.  It is safe to call serial_init() multiple
264 264
  * times.
265 265
  */
266
-struct init_fn serial_init_fn __init_fn ( INIT_EARLY ) = {
266
+struct init_fn serial_init_fn __init_fn ( INIT_CONSOLE ) = {
267 267
 	.initialise = serial_init,
268 268
 };

+ 37
- 22
src/core/timer.c View File

@@ -22,7 +22,6 @@
22 22
 #include <assert.h>
23 23
 #include <gpxe/init.h>
24 24
 #include <gpxe/timer.h>
25
-#include <stdio.h>
26 25
 
27 26
 static struct timer ts_table[0]
28 27
 	__table_start ( struct timer, timers );
@@ -53,48 +52,64 @@ static void timer_init(void)
53 52
 	struct timer *ts;
54 53
 
55 54
 	for (ts = ts_table; ts < ts_table_end; ts++) {
56
-		if (ts->init && ts->init() >= 0) {
55
+		if ( ts->init() == 0 ) {
57 56
 			used_ts = ts;
58
-			break;
57
+			return;
59 58
 		}
60 59
 	}
61 60
 
62
-	assert(used_ts);
61
+	/* No timer found; we cannot continue */
62
+	assert ( 0 );
63
+	while ( 1 ) {};
63 64
 }
64 65
 
65 66
 struct init_fn ts_init_fn __init_fn ( INIT_NORMAL ) = {
66 67
 	.initialise = timer_init,
67 68
 };
68 69
 
69
-/* Functions for public use. */
70
-
71
-tick_t currticks(void)
72
-{
70
+/**
71
+ * Read current time
72
+ *
73
+ * @ret ticks	Current time, in ticks
74
+ */
75
+tick_t currticks ( void ) {
73 76
 	tick_t ct;
74 77
 	assert(used_ts);
75 78
 
76 79
 	ct = used_ts->currticks();
77
-	DBG("currticks: %ld seconds and %06ld microseconds\n", ct/USECS_IN_SEC, ct%USECS_IN_SEC);
80
+	DBG ( "currticks: %ld.%06ld seconds\n",
81
+	      ct / USECS_IN_SEC, ct % USECS_IN_SEC );
78 82
 
79 83
 	return ct;
80 84
 }
81 85
 
82
-void udelay(unsigned int usecs)
83
-{
84
-	used_ts->udelay(usecs);
86
+/**
87
+ * Delay
88
+ *
89
+ * @v usecs	Time to delay, in microseconds
90
+ */
91
+void udelay ( unsigned int usecs ) {
92
+	assert(used_ts);
93
+	used_ts->udelay ( usecs );
85 94
 }
86 95
 
87
-void mdelay(unsigned int msecs)
88
-{
89
-	while(msecs--)
90
-		used_ts->udelay(USECS_IN_MSEC);
96
+/**
97
+ * Delay
98
+ *
99
+ * @v msecs	Time to delay, in milliseconds
100
+ */
101
+void mdelay ( unsigned int msecs ) {
102
+	while ( msecs-- )
103
+		udelay ( USECS_IN_MSEC );
91 104
 }
92 105
 
93
-unsigned int sleep(unsigned int secs)
94
-{
95
-	while (secs--)
96
-		mdelay(MSECS_IN_SEC);
97
-
106
+/**
107
+ * Delay
108
+ *
109
+ * @v secs	Time to delay, in seconds
110
+ */
111
+unsigned int sleep ( unsigned int secs ) {
112
+	while ( secs-- )
113
+		mdelay ( MSECS_IN_SEC );
98 114
 	return 0;
99 115
 }
100
-

+ 2
- 9
src/include/gpxe/init.h View File

@@ -22,7 +22,8 @@ struct init_fn {
22 22
  */
23 23
 
24 24
 #define INIT_EARLY	01	/**< Early initialisation */
25
-#define INIT_NORMAL	02	/**< Normal initialisation */
25
+#define	INIT_CONSOLE	02	/**< Console initialisation */
26
+#define INIT_NORMAL	03	/**< Normal initialisation */
26 27
 
27 28
 /** @} */
28 29
 
@@ -54,14 +55,6 @@ struct startup_fn {
54 55
 
55 56
 /** @} */
56 57
 
57
-/* Use double digits to avoid problems with "10" < "9" on alphabetic sort */
58
-#define	INIT_CONSOLE	02
59
-#define	INIT_GDBSYM	03
60
-#define	INIT_CPU	04
61
-#define	INIT_TIMERS	05
62
-#define	INIT_LOADBUF	08
63
-#define	INIT_PCMCIA	09
64
-
65 58
 extern void initialise ( void );
66 59
 extern void startup ( void );
67 60
 extern void shutdown ( void );

+ 20
- 12
src/include/gpxe/timer.h View File

@@ -3,7 +3,7 @@
3 3
 
4 4
 #include <stddef.h>
5 5
 
6
-typedef uint32_t tick_t;
6
+typedef unsigned long tick_t;
7 7
 
8 8
 #define MSECS_IN_SEC (1000)
9 9
 #define USECS_IN_SEC (1000*1000)
@@ -11,22 +11,30 @@ typedef uint32_t tick_t;
11 11
 
12 12
 #define	TICKS_PER_SEC	USECS_IN_SEC
13 13
 
14
-tick_t currticks(void);
14
+extern tick_t currticks ( void );
15 15
 
16
-void generic_currticks_udelay(unsigned int usecs);
16
+extern void generic_currticks_udelay ( unsigned int usecs );
17 17
 
18
+/** A timer */
18 19
 struct timer {
19
-	/* Returns zero on successful initialisation. */
20
-	int (*init) (void);
21
-
22
-	/* Return the current time, int mictoseconds since the beginning. */
23
-	tick_t (*currticks) (void);
24
-
25
-	/* Sleep for a few useconds. */
26
-	void (*udelay) (unsigned int useconds);
20
+	/** Initialise timer
21
+	 *
22
+	 * @ret rc	Return status code
23
+	 */
24
+	int ( * init ) ( void );
25
+	/** Read current time
26
+	 *
27
+	 * @ret ticks	Current time, in ticks
28
+	 */
29
+	tick_t ( * currticks ) ( void );
30
+	/** Delay
31
+	 *
32
+	 * @v usecs	Time to delay, in microseconds
33
+	 */
34
+	void ( * udelay ) ( unsigned int usecs );
27 35
 };
28 36
 
29
-#define __timer(order) __table (struct timer, timers, order)
37
+#define __timer( order ) __table ( struct timer, timers, order )
30 38
 
31 39
 #endif	/* GPXE_TIMER_H */
32 40
 

Loading…
Cancel
Save