trs80m1: add clock code but ifdef it back out due to an SDCC bug
authorAlan Cox <alan@linux.intel.com>
Wed, 11 Jul 2018 22:21:40 +0000 (23:21 +0100)
committerAlan Cox <alan@linux.intel.com>
Wed, 11 Jul 2018 22:21:40 +0000 (23:21 +0100)
Filed as #2770 in SDCC bug tracker

Kernel/platform-trs80m1/config.h
Kernel/platform-trs80m1/main.c

index 82b3a90..5cc1b4e 100644 (file)
@@ -1,5 +1,6 @@
 /* Set if you want RTC support and have an RTC on ports 0xB0-0xBC */
 #define CONFIG_RTC
+#define CONFIG_RTC_FULL
 /* Enable to make ^Z dump the inode table for debug */
 #undef CONFIG_IDUMP
 /* Enable to make ^A drop back into the monitor */
index 1a01555..72d9361 100644 (file)
@@ -2,6 +2,7 @@
 #include <timer.h>
 #include <kdata.h>
 #include <printf.h>
+#include <rtc.h>
 #include <devtty.h>
 #include <trs80.h>
 
@@ -101,6 +102,17 @@ void platform_discard(void)
 
 __sfr __at 0xB0 rtc_secl;
 __sfr __at 0xB1 rtc_sech;
+__sfr __at 0xB2 rtc_minl;
+__sfr __at 0xB3 rtc_minh;
+__sfr __at 0xB4 rtc_hourl;
+__sfr __at 0xB5 rtc_hourh;
+/* day of week is B6 */
+__sfr __at 0xB7 rtc_dayl;
+__sfr __at 0xB8 rtc_dayh;
+__sfr __at 0xB9 rtc_monl;
+__sfr __at 0xBA rtc_monh;
+__sfr __at 0xBB rtc_yearl;
+__sfr __at 0xBC rtc_yearh;
 
 /* FIXME: the RTC is optional so we should test for it first */
 uint8_t platform_rtc_secs(void)
@@ -117,6 +129,61 @@ uint8_t platform_rtc_secs(void)
     return rv;
 }
 
+int platform_rtc_read(void)
+{
+#if 0
+    /* We need SDCC bug 2770 fixed first */
+    uint16_t len;
+    struct cmos_rtc cmos;
+    uint8_t *p;
+    uint8_t r, y;
+
+    if (udata.u_count < len)
+        len = udata.u_count;
+
+    if (rtc_secl == 255) {
+      udata.u_error = EOPNOTSUPP;
+      return -1;
+    }
+
+    /* We do a full set of reads and if the seconds change retry - we
+       need to retry the lost as we might read as the second changes for
+       new year */
+    do {
+      p = cmos.data.bytes;
+      r = rtc_secl;
+      y  = (rtc_yearh << 4) | rtc_yearl;
+      if (y > 70)
+          *p++ = 19;
+      else
+          *p++ = 20;
+      *p++ = y;
+      *p++ = ((rtc_monh  & 1)<< 4) | rtc_monl;
+      *p++ = ((rtc_dayh & 3) << 4) | rtc_dayl;
+      *p++ = ((rtc_hourh & 3) << 4) | rtc_hourl;
+      *p++ = ((rtc_minh & 7) << 4) | rtc_minl;
+      *p++ = ((rtc_sech & 7) << 4) | rtc_secl;
+    } while ((r ^ rtc_secl) & 0x0F);
+
+    cmos.type = CMOS_RTC_BCD;
+    if (uput(&cmos, udata.u_base, len) == -1)
+        return -1;
+    return len;
+#else
+       udata.u_error = EOPNOTSUPP;
+       return -1;
+#endif    
+}
+
+/* Yes I'm a slacker .. this wants adding but it's ugly
+   because the seconds is always just set to 0 on any change. We
+   also need to deal with leap years here */
+int platform_rtc_write(void)
+{
+       udata.u_error = EOPNOTSUPP;
+       return -1;
+}
+
 #endif
 
 /*