feat: standard vga support (mode switching, framebuffer remapping)
[lunaix-os.git] / lunaix-os / hal / timer / hwtimer.c
index 9c864c7bdd3f29eb03d6926d3ed387ec93921125..91dca07459d8e9caf450ecbaab8c9cddd78d8f6d 100644 (file)
@@ -1,40 +1,66 @@
 #include <hal/hwtimer.h>
 #include <lunaix/spike.h>
 
 #include <hal/hwtimer.h>
 #include <lunaix/spike.h>
 
-struct hwtimer_context* sys_hwtctx;
+#include <usr/lunaix/ioctl_defs.h>
 
 
-void
-hwtimer_init(u32_t hertz, void* tick_callback)
-{
-    struct hwtimer_context* hwt_ctx = hwtimer_choose();
-
-    hwt_ctx->init(hwt_ctx, hertz, tick_callback);
-    hwt_ctx->running_freq = hertz;
-
-    sys_hwtctx = hwt_ctx;
-}
+struct hwtimer* current_timer;
 
 ticks_t
 hwtimer_base_frequency()
 {
 
 ticks_t
 hwtimer_base_frequency()
 {
-    return sys_hwtctx->base_freq;
+    assert(current_timer);
+    return current_timer->base_freq;
 }
 
 ticks_t
 hwtimer_current_systicks()
 {
 }
 
 ticks_t
 hwtimer_current_systicks()
 {
-    return sys_hwtctx->systicks();
+    assert(current_timer);
+    return current_timer->systicks();
 }
 
 ticks_t
 hwtimer_to_ticks(u32_t value, int unit)
 {
 }
 
 ticks_t
 hwtimer_to_ticks(u32_t value, int unit)
 {
+    assert(current_timer);
     // in case system frequency is less than 1000Hz
     if (unit != TIME_MS) {
     // in case system frequency is less than 1000Hz
     if (unit != TIME_MS) {
-        return sys_hwtctx->running_freq * unit * value;
+        return current_timer->running_freq * unit * value;
     }
 
     }
 
-    ticks_t freq_ms = sys_hwtctx->running_freq / 1000;
+    ticks_t freq_ms = current_timer->running_freq / 1000;
 
     return freq_ms * value;
 
     return freq_ms * value;
+}
+
+static int
+__hwtimer_ioctl(struct device* dev, u32_t req, va_list args)
+{
+    struct hwtimer* hwt = (struct hwtimer*)dev->underlay;
+    switch (req) {
+        case TIMERIO_GETINFO:
+            // TODO
+            break;
+
+        default:
+            break;
+    }
+    return 0;
+}
+
+void
+hwtimer_init(u32_t hertz, void* tick_callback)
+{
+    struct hwtimer* hwt_ctx = hwtimer_choose();
+
+    hwt_ctx->init(hwt_ctx, hertz, tick_callback);
+    hwt_ctx->running_freq = hertz;
+
+    current_timer = hwt_ctx;
+
+    struct device* timerdev = device_allocsys(NULL, hwt_ctx);
+
+    timerdev->ops.exec_cmd = __hwtimer_ioctl;
+
+    device_register(timerdev, &hwt_ctx->class, hwt_ctx->name);
 }
\ No newline at end of file
 }
\ No newline at end of file