Home

Timer


The interrupt routine TimerInt in interrupts.s does the basic work for timing services. This is triggered at regular intervals by the hardware timer chip. The primary purpose of this routine is to increment the variable Ticks which counts the number of timer interrupts since the system was started. Next the blocked task queue is checked to see if any tasks are waiting on a timer (the timer is implemented as a field in the task structure). If so, the timer field Task.timer is decremented. If this variable has reached zero then the task is re-awakened. The last job of the interrupt routine is to decrement the variable TimeSliceCount. If this has reached zero then it is reset to 5 and a call to SWITCH_TASKS is made. In other words, a task switch is called for every 5 ticks.

User programs can access the timer by making the system call nanosleep.) This routine fills in the field Task.timer with the requested time interval. It then sets the calling task to block until it receives instructions from the interrupt routine to re-awaken.