Decoupling Architectural-specific Code (#35)
[lunaix-os.git] / lunaix-os / includes / lunaix / timer.h
index 0c65ffd0205dff61a319cc763c369a48d9389039..08718adc474a1d8147476b739bb35be9b92d8fc4 100644 (file)
@@ -2,41 +2,73 @@
 #define __LUNAIX_TIMER_H
 
 #include <lunaix/ds/llist.h>
-#include <stdint.h>
+#include <lunaix/time.h>
+#include <lunaix/hart_state.h>
 
-#define SYS_TIMER_FREQUENCY_HZ      2048
+#define SYS_TIMER_FREQUENCY_HZ 1000
 
-#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;
+struct lx_timer_context
+{
+    struct lx_timer* active_timers;
+    /**
+     * @brief timer hardware base frequency (ticks per seconds)
+     *
+     */
+    ticks_t base_frequency;
+    /**
+     * @brief Desired system running frequency
+     *
+     */
+    ticks_t running_frequency;
+    /**
+     * @brief Ticks per hertz
+     *
+     */
+    ticks_t tphz;
 };
 
-struct lx_timer {
+struct timer_init_param
+{
+    struct lx_timer_context* context;
+    void* timer_update_isr;
+};
+
+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();
+
+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 */