summaryrefslogtreecommitdiff
path: root/kernel/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/clock.c')
-rw-r--r--kernel/clock.c59
1 files changed, 28 insertions, 31 deletions
diff --git a/kernel/clock.c b/kernel/clock.c
index 96f71c4..7af47b7 100644
--- a/kernel/clock.c
+++ b/kernel/clock.c
@@ -30,8 +30,8 @@
*/
// pinwheel control variables
-static uint32_t pinwheel; // pinwheel counter
-static uint32_t pindex; // index into pinwheel string
+static uint32_t pinwheel; // pinwheel counter
+static uint32_t pindex; // index into pinwheel string
/*
** PUBLIC GLOBAL VARIABLES
@@ -52,15 +52,15 @@ uint32_t system_time;
** @param vector Vector number for the clock interrupt
** @param code Error code (0 for this interrupt)
*/
-static void clk_isr( int vector, int code ) {
-
+static void clk_isr(int vector, int code)
+{
// spin the pinwheel
++pinwheel;
- if( pinwheel == (CLOCK_FREQ / 10) ) {
+ if (pinwheel == (CLOCK_FREQ / 10)) {
pinwheel = 0;
++pindex;
- cio_putchar_at( 0, 0, "|/-\\"[ pindex & 3 ] );
+ cio_putchar_at(0, 0, "|/-\\"[pindex & 3]);
}
#if defined(SYSTEM_STATUS)
@@ -70,14 +70,11 @@ static void clk_isr( int vector, int code ) {
// Define the symbol SYSTEM_STATUS with a value equal to the desired
// reporting frequency, in seconds.
- if( (system_time % SEC_TO_TICKS(SYSTEM_STATUS)) == 0 ) {
- cio_printf_at( 1, 0, " queues: R[%u] W[%u] S[%u] Z[%u] I[%u] ",
- pcb_queue_length(ready),
- pcb_queue_length(waiting),
- pcb_queue_length(sleeping),
- pcb_queue_length(zombie),
- pcb_queue_length(sioread)
- );
+ if ((system_time % SEC_TO_TICKS(SYSTEM_STATUS)) == 0) {
+ cio_printf_at(1, 0, " queues: R[%u] W[%u] S[%u] Z[%u] I[%u] ",
+ pcb_queue_length(ready), pcb_queue_length(waiting),
+ pcb_queue_length(sleeping), pcb_queue_length(zombie),
+ pcb_queue_length(sioread));
}
#endif
@@ -91,42 +88,42 @@ static void clk_isr( int vector, int code ) {
do {
// if there isn't anyone in the sleep queue, we're done
- if( pcb_queue_empty(sleeping) ) {
+ if (pcb_queue_empty(sleeping)) {
break;
}
// peek at the first member of the queue
- pcb_t *tmp = pcb_queue_peek( sleeping );
- assert( tmp != NULL );
+ pcb_t *tmp = pcb_queue_peek(sleeping);
+ assert(tmp != NULL);
// the sleep queue is sorted in ascending order by wakeup
// time, so we know that the retrieved PCB's wakeup time is
// the earliest of any process on the sleep queue; if that
// time hasn't arrived yet, there's nobody left to awaken
- if( tmp->wakeup > system_time ) {
+ if (tmp->wakeup > system_time) {
break;
}
// OK, we need to wake this process up
- assert( pcb_queue_remove(sleeping,&tmp) == SUCCESS );
- schedule( tmp );
- } while( 1 );
+ assert(pcb_queue_remove(sleeping, &tmp) == SUCCESS);
+ schedule(tmp);
+ } while (1);
// next, we decrement the current process' remaining time
current->ticks -= 1;
// has it expired?
- if( current->ticks < 1 ) {
+ if (current->ticks < 1) {
// yes! reschedule it
- schedule( current );
+ schedule(current);
current = NULL;
// and pick a new process
dispatch();
}
// tell the PIC we're done
- outb( PIC1_CMD, PIC_EOI );
+ outb(PIC1_CMD, PIC_EOI);
}
/*
@@ -139,10 +136,10 @@ static void clk_isr( int vector, int code ) {
** Initializes the clock module
**
*/
-void clk_init( void ) {
-
+void clk_init(void)
+{
#if TRACING_INIT
- cio_puts( " Clock" );
+ cio_puts(" Clock");
#endif
// start the pinwheel
@@ -154,10 +151,10 @@ void clk_init( void ) {
// configure the clock
uint32_t divisor = PIT_FREQ / CLOCK_FREQ;
- outb( PIT_CONTROL_PORT, PIT_0_LOAD | PIT_0_SQUARE );
- outb( PIT_0_PORT, divisor & 0xff ); // LSB of divisor
- outb( PIT_0_PORT, (divisor >> 8) & 0xff ); // MSB of divisor
+ outb(PIT_CONTROL_PORT, PIT_0_LOAD | PIT_0_SQUARE);
+ outb(PIT_0_PORT, divisor & 0xff); // LSB of divisor
+ outb(PIT_0_PORT, (divisor >> 8) & 0xff); // MSB of divisor
// register the second-stage ISR
- install_isr( VEC_TIMER, clk_isr );
+ install_isr(VEC_TIMER, clk_isr);
}