Timer re-worked!
[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      2048UL
8
9 #define TIMER_MODE_PERIODIC   0x1
10
11 struct lx_timer_context {
12     struct lx_timer *active_timers;
13     uint32_t base_frequency;
14     uint32_t running_frequency;
15     uint32_t tick_interval;
16 };
17
18 struct lx_timer {
19     struct llist_header link;
20     uint32_t deadline;
21     uint32_t counter;
22     void* payload;
23     void (*callback)(void*);
24     uint8_t flags;
25 };
26
27
28 /**
29  * @brief Initialize the system timer that runs at specified frequency
30  * 
31  * @param frequency The frequency that timer should run in Hz.
32  */
33 void
34 timer_init(uint32_t frequency);
35
36 int
37 timer_run_second(uint32_t second, void (*callback)(void*), void* payload, uint8_t flags);
38
39 int
40 timer_run(uint32_t ticks, void (*callback)(void*), void* payload, uint8_t flags);
41
42 #endif /* __LUNAIX_TIMER_H */