X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/fef29e9e993e62f025d8cbfeb6b8d51588083b7e..b26d3165c52589d1f8de37bf0df27ad96f460f47:/lunaix-os/includes/lunaix/timer.h diff --git a/lunaix-os/includes/lunaix/timer.h b/lunaix-os/includes/lunaix/timer.h index 5c40696..5ab3864 100644 --- a/lunaix-os/includes/lunaix/timer.h +++ b/lunaix-os/includes/lunaix/timer.h @@ -4,39 +4,66 @@ #include #include -#define SYS_TIMER_FREQUENCY_HZ 2048UL +#define SYS_TIMER_FREQUENCY_HZ 1024 -#define TIMER_MODE_PERIODIC 0x1 +#define TIMER_MODE_PERIODIC 0x1 -struct lx_timer_context { - struct lx_timer *active_timers; - uint32_t base_frequency; - uint32_t running_frequency; - uint32_t tick_interval; +typedef u32_t ticks_t; + +struct lx_timer_context +{ + struct lx_timer* active_timers; + /** + * @brief APIC timer base frequency (ticks per seconds) + * + */ + ticks_t base_frequency; + /** + * @brief Desired system running frequency + * + */ + u32_t running_frequency; + /** + * @brief Ticks per hertz + * + */ + ticks_t tphz; }; -struct lx_timer { +struct lx_timer +{ struct llist_header link; - uint32_t deadline; - uint32_t counter; + ticks_t deadline; + ticks_t counter; void* payload; void (*callback)(void*); - uint8_t flags; + u8_t flags; }; - /** * @brief Initialize the system timer that runs at specified frequency - * + * * @param frequency The frequency that timer should run in Hz. */ void -timer_init(uint32_t frequency); +timer_init(u32_t frequency); + +struct lx_timer* +timer_run_second(u32_t second, + void (*callback)(void*), + void* payload, + u8_t flags); + +struct lx_timer* +timer_run_ms(u32_t millisecond, + void (*callback)(void*), + void* payload, + u8_t flags); -int -timer_run_second(uint32_t second, void (*callback)(void*), void* payload, uint8_t flags); +struct lx_timer* +timer_run(ticks_t ticks, void (*callback)(void*), void* payload, u8_t flags); -int -timer_run(uint32_t ticks, void (*callback)(void*), void* payload, uint8_t flags); +struct lx_timer_context* +timer_context(); #endif /* __LUNAIX_TIMER_H */