2 #include <asm/system.h>
7 volatile unsigned long timer_ticks
= 0;
8 volatile unsigned long count_down
= 0;
10 extern timer_interrupt(void);
14 #define TIME_REQUESTS 64
17 unsigned long timer_ticks
;
19 struct timer_list
*next
;
20 } timer_list
[TIME_REQUESTS
], * next_timer
= NULL
;
24 void add_timer( unsigned long timer_ticks
, void (*fn
)(void))
34 for (p
= timer_list
; p
< timer_list
+ TIME_REQUESTS
; p
++)
37 if (p
>= timer_list
+ TIME_REQUESTS
)
38 panic("No more time requests free");
40 p
->timer_ticks
= timer_ticks
;
42 while (p
->next
&& p
->timer_ticks
> p
->next
->timer_ticks
) {
43 p
->timer_ticks
-= p
->next
->timer_ticks
;
48 timer_ticks
= p
->timer_ticks
;
49 p
->timer_ticks
= p
->next
->timer_ticks
;
50 p
->next
->timer_ticks
= timer_ticks
;
59 * Yeah, we are implenmenting our SLEEP function,
61 * Hope it works well cause i just know the folloing
62 * ways to implenment it by now. And you konw, it's
66 void sleep(unsigned long sleep_value
)
68 unsigned long now_ticks
= timer_ticks
;
71 }while ( timer_ticks
< now_ticks
+ sleep_value
);
80 * Yeah, we also implenment a COUNT_DOWN here.
81 * it's sounds like we have lots things well.
89 next_timer
->timer_ticks
--;
90 while (next_timer
&& next_timer
->timer_ticks
<=0) {
94 next_timer
->fn
= NULL
;
95 next_timer
= next_timer
->next
;
100 //if (current_DOR & 0xf0)
101 // do_floppy_timer();
104 void timer_init(int hz
)
106 unsigned int divisor
= 1193180/hz
;
108 outb(divisor
&0xff, 0x40);
109 outb(divisor
>>8, 0x40);
110 set_trap_gate(0x20,timer_interrupt
);
111 outb(inb(0x21)&0xfe, 0x21);