Support to multi-threading and pthread interface (POSIX.1-2008) (#23)
[lunaix-os.git] / lunaix-os / hal / rtc / mc146818a.c
index 1a507653192df1d5a5d40cdba38a89b3a6718955..cb1ae33577fef7d853577fabf8d899fae8384e6b 100644 (file)
 #include <lunaix/isrm.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/status.h>
+#include <lunaix/pcontext.h>
 
 #include <hal/rtc/mc146818a.h>
 
 #include <klibc/string.h>
 
-#include <sys/interrupts.h>
 #include <sys/port_io.h>
 
 #define RTC_INDEX_PORT 0x70
@@ -145,8 +145,7 @@ mc146818_check_support(struct hwrtc* rtc)
 static void
 __rtc_tick(const isr_param* param)
 {
-    struct mc146818* state =
-      (struct mc146818*)isrm_get_payload(param->execp->vector);
+    struct mc146818* state = (struct mc146818*)isrm_get_payload(param);
 
     state->tick_counts++;
 
@@ -183,8 +182,8 @@ rtc_getcnt(struct hwrtc* rtc)
     return state->tick_counts;
 }
 
-static void
-rtc_init()
+static int
+rtc_init(struct device_def* devdef)
 {
     u8_t reg = rtc_read_reg(RTC_REG_A);
     reg = (reg & ~0x7f) | RTC_FREQUENCY_1024HZ | RTC_DIVIDER_33KHZ;
@@ -212,5 +211,15 @@ rtc_init()
     rtc->cls_mask = rtc_cls_mask;
     rtc->get_counts = rtc_getcnt;
     rtc->chfreq = rtc_chfreq;
+
+    hwrtc_register(&devdef->class, rtc);
+
+    return 0;
 }
-EXPORT_RTC_DEVICE(mc146818, rtc_init);
\ No newline at end of file
+
+static struct device_def devrtc_mc146818 = {
+    .name = "MC146818 RTC",
+    .class = DEVCLASS(DEVIF_SOC, DEVFN_TIME, DEV_RTC),
+    .init = rtc_init
+};
+EXPORT_DEVICE(mc146818, &devrtc_mc146818, load_timedev);
\ No newline at end of file