Basic PS/2 keyboard driver, and ...
[lunaix-os.git] / lunaix-os / includes / lunaix / timer.h
1 #ifndef __LUNAIX_TIMER_H
2 #define __LUNAIX_TIMER_H
3
4 #include <lunaix/ds/llist.h>
5 #include <stdint.h>
6
7 #define SYS_TIMER_FREQUENCY_HZ      2048
8
9 #define TIMER_MODE_PERIODIC   0x1
10
11 typedef uint32_t ticks_t;
12
13 struct lx_timer_context {
14     struct lx_timer *active_timers;
15     /**
16      * @brief APIC timer base frequency (ticks per seconds)
17      * 
18      */
19     ticks_t base_frequency;
20     /**
21      * @brief Desired system running frequency
22      * 
23      */
24     uint32_t running_frequency;
25     /**
26      * @brief Ticks per second relative to desired system running frequency
27      * 
28      */
29     ticks_t tps;
30 };
31
32 struct lx_timer {
33     struct llist_header link;
34     ticks_t deadline;
35     ticks_t counter;
36     void* payload;
37     void (*callback)(void*);
38     uint8_t flags;
39 };
40
41
42 /**
43  * @brief Initialize the system timer that runs at specified frequency
44  * 
45  * @param frequency The frequency that timer should run in Hz.
46  */
47 void
48 timer_init(uint32_t frequency);
49
50 int
51 timer_run_second(uint32_t second, void (*callback)(void*), void* payload, uint8_t flags);
52 timer_run_ms(uint32_t millisecond, void (*callback)(void*), void* payload, uint8_t flags);
53
54 int
55 timer_run(ticks_t ticks, void (*callback)(void*), void* payload, uint8_t flags);
56
57 struct lx_timer_context* 
58 timer_context();
59
60 #endif /* __LUNAIX_TIMER_H */