feat: add support for process to conduct Intel x87 and MMX related task.
[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 1024
8
9 #define TIMER_MODE_PERIODIC 0x1
10
11 typedef uint32_t ticks_t;
12
13 struct lx_timer_context
14 {
15     struct lx_timer* active_timers;
16     /**
17      * @brief APIC timer base frequency (ticks per seconds)
18      *
19      */
20     ticks_t base_frequency;
21     /**
22      * @brief Desired system running frequency
23      *
24      */
25     uint32_t running_frequency;
26     /**
27      * @brief Ticks per hertz
28      *
29      */
30     ticks_t tphz;
31 };
32
33 struct lx_timer
34 {
35     struct llist_header link;
36     ticks_t deadline;
37     ticks_t counter;
38     void* payload;
39     void (*callback)(void*);
40     uint8_t flags;
41 };
42
43 /**
44  * @brief Initialize the system timer that runs at specified frequency
45  *
46  * @param frequency The frequency that timer should run in Hz.
47  */
48 void
49 timer_init(uint32_t frequency);
50
51 struct lx_timer*
52 timer_run_second(uint32_t second,
53                  void (*callback)(void*),
54                  void* payload,
55                  uint8_t flags);
56
57 struct lx_timer*
58 timer_run_ms(uint32_t millisecond,
59              void (*callback)(void*),
60              void* payload,
61              uint8_t flags);
62
63 struct lx_timer*
64 timer_run(ticks_t ticks, void (*callback)(void*), void* payload, uint8_t flags);
65
66 struct lx_timer_context*
67 timer_context();
68
69 #endif /* __LUNAIX_TIMER_H */