rewrite the device subsystem interfaces (#48)
[lunaix-os.git] / lunaix-os / kernel / time / clock.c
index 3770dd00ce3088aa4dfff566768aa2615ff69a04..a5b9dd838a6a04e119f3ef28a082d0ddec455d5e 100644 (file)
@@ -1,6 +1,5 @@
-#include <hal/hwrtc.h>
-#include <hal/hwtimer.h>
 #include <lunaix/clock.h>
 #include <lunaix/clock.h>
+#include <lunaix/device.h>
 #include <lunaix/fs/twifs.h>
 #include <lunaix/spike.h>
 
 #include <lunaix/fs/twifs.h>
 #include <lunaix/spike.h>
 
@@ -20,12 +19,8 @@ __clock_read_datetime(struct twimap* map)
     clock_walltime(&dt);
     twimap_printf(map,
                   "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
     clock_walltime(&dt);
     twimap_printf(map,
                   "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
-                  dt.year,
-                  dt.month,
-                  dt.day,
-                  dt.hour,
-                  dt.minute,
-                  dt.second);
+                  dt.year, dt.month, dt.day,
+                  dt.hour, dt.minute, dt.second);
 }
 
 void
 }
 
 void
@@ -62,16 +57,22 @@ clock_unixtime()
 time_t
 clock_systime()
 {
 time_t
 clock_systime()
 {
-    if (!current_timer) {
+    if (!systimer) {
         return 0;
     }
 
     ticks_t t = hwtimer_current_systicks();
         return 0;
     }
 
     ticks_t t = hwtimer_current_systicks();
-    return t / current_timer->running_freq;
+    ticks_t tu = systimer->running_freq / 1000;
+
+    if (unlikely(!tu)) {
+        return t;
+    }
+
+    return t / (tu);
 }
 
 void
 clock_walltime(datetime_t* datetime)
 {
 }
 
 void
 clock_walltime(datetime_t* datetime)
 {
-    primary_rtc->get_walltime(primary_rtc, datetime);
+    sysrtc->ops->get_walltime(sysrtc, datetime);
 }
\ No newline at end of file
 }
\ No newline at end of file