diff options
Diffstat (limited to '')
-rw-r--r-- | kernel/old/clock.c (renamed from kernel/old/drivers/clock.c) | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/kernel/old/drivers/clock.c b/kernel/old/clock.c index 9f3d4be..96f71c4 100644 --- a/kernel/old/drivers/clock.c +++ b/kernel/old/clock.c @@ -1,3 +1,11 @@ +/** +** @file clock.c +** +** @author CSCI-452 class of 20245 +** +** @brief Clock module implementation +*/ + #define KERNEL_SRC #include <common.h> @@ -22,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 @@ -44,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) @@ -62,11 +70,14 @@ 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 @@ -80,42 +91,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 ); } /* @@ -128,10 +139,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 @@ -143,10 +154,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 ); } |