2 #include <asm/system.h>
7 volatile unsigned long timer_ticks
= 0;
8 volatile unsigned long count_down
= 0;
13 #define TIME_REQUESTS 64
16 unsigned long timer_ticks
;
18 struct timer_list
*next
;
19 } timer_list
[TIME_REQUESTS
], * next_timer
= NULL
;
23 void add_timer( unsigned long timer_ticks
, void (*fn
)(void))
33 for (p
= timer_list
; p
< timer_list
+ TIME_REQUESTS
; p
++)
36 if (p
>= timer_list
+ TIME_REQUESTS
)
37 panic("No more time requests free");
39 p
->timer_ticks
= timer_ticks
;
41 while (p
->next
&& p
->timer_ticks
> p
->next
->timer_ticks
) {
42 p
->timer_ticks
-= p
->next
->timer_ticks
;
47 timer_ticks
= p
->timer_ticks
;
48 p
->timer_ticks
= p
->next
->timer_ticks
;
49 p
->next
->timer_ticks
= timer_ticks
;
58 * Yeah, we are implenmenting our SLEEP function,
60 * Hope it works well cause i just know the folloing
61 * ways to implenment it by now. And you konw, it's
65 void sleep(unsigned long sleep_value
)
67 unsigned long now_ticks
= timer_ticks
;
70 }while ( timer_ticks
< now_ticks
+ sleep_value
);
79 * Yeah, we also implenment a COUNT_DOWN here.
80 * it's sounds like we have lots things well.
88 next_timer
->timer_ticks
--;
89 while (next_timer
&& next_timer
->timer_ticks
<=0) {
93 next_timer
->fn
= NULL
;
94 next_timer
= next_timer
->next
;
99 //if (current_DOR & 0xf0)
100 // do_floppy_timer();
103 void timer_init(int hz
)
105 unsigned int divisor
= 1193180/hz
;
107 outb(divisor
&0xff, 0x40);
108 outb(divisor
>>8, 0x40);
109 set_trap_gate(0x20,timer_interrupt
);
110 outb(inb(0x21)&0xfe, 0x21);