#include <const.h>
#include <arch/i386.h>
#include <kernel/floppy.h>
#include <kernel/task.h>
#include <kernel/clock.h>
Go to the source code of this file.
Functions | |||||
| void | init_clock () | ||||
| Initialize channel 0 of the 8253A timer. | |||||
| void | stop_clock () | ||||
| Reset the clock for rebooting. | |||||
| void | delay (dword millisec) | ||||
Delay some milliseconds
| |||||
| void | set_timeout (timeout_t *t, unsigned int millisec) | ||||
Initialize a timeout variable.
| |||||
| bool | is_timeout (timeout_t *t) | ||||
Check if a timeout has been elapsed.
| |||||
| dword | sys_get_ticks () | ||||
Return the system ticks.
| |||||
| void | clock_thread () | ||||
| This is a task that occurs at every clock tick. | |||||
Variables | |||||
| volatile dword | ticks = 0 | ||||
| System ticks. | |||||
Definition in file clock.c.
|
|
This is a task that occurs at every clock tick.
Into this routine you can put every periodical task. Definition at line 109 of file clock.c.
00110 {
00111 ticks++;
00112 floppy_thread();
00113 }
|
|
|
Delay some milliseconds
Definition at line 51 of file clock.c.
00052 {
00053 dword count, elapsed;
00054 dword IF = GET_IF();
00055
00056 // Start timer //
00057 elapsed = 0;
00058
00059 while (elapsed < millisec)
00060 {
00061 // Poll ticks in memory //
00062 count = ticks;
00063
00064 // Auto-sleep //
00065 enable();
00066 idle();
00067
00068 // Update elapsed time //
00069 elapsed += (ticks - count)*1000/HZ;
00070 }
00071
00072 SET_IF(IF);
00073 }
|
|
|
Initialize channel 0 of the 8253A timer.
Definition at line 21 of file clock.c.
00022 {
00023 dword IF = GET_IF();
00024
00025 disable();
00026
00027 outportb(TIMER_MODE, SQUARE_WAVE); // set timer on
00028 outportb(TIMER0, TIMER_COUNT & 0xFF); // timer low byte
00029 outportb(TIMER0, TIMER_COUNT >> 8); // timer high byte
00030
00031 SET_IF(IF);
00032 }
|
|
|
Check if a timeout has been elapsed.
Definition at line 87 of file clock.c.
00088 {
00089 // Check if a timeout has gone //
00090 uint32_t elapsed;
00091 elapsed = ticks - t->start_ticks;
00092 return( elapsed >= t->ticks_to_wait );
00093 }
|
|
||||||||||||
|
Initialize a timeout variable.
Definition at line 79 of file clock.c.
00080 {
00081 t->start_ticks = ticks;
00082 t->ticks_to_wait = millisec * HZ / 1000;
00083 }
|
|
|
Reset the clock for rebooting.
Definition at line 35 of file clock.c.
|
|
|
Return the system ticks.
Definition at line 97 of file clock.c.
00098 {
00099 return(ticks);
00100 }
|
|
|
System ticks.
|
1.2.18