amstradnc: clock support
authorAlan Cox <alan@linux.intel.com>
Sun, 7 Oct 2018 21:14:35 +0000 (22:14 +0100)
committerAlan Cox <alan@linux.intel.com>
Sun, 7 Oct 2018 21:14:35 +0000 (22:14 +0100)
Also adjust the config for the NC200 as it was spilling over the boundary

Kernel/platform-amstradnc/config.h
Kernel/platform-amstradnc/m146818.c [new file with mode: 0644]
Kernel/platform-amstradnc/main.c
Kernel/platform-amstradnc/nc100/Makefile
Kernel/platform-amstradnc/nc100/fuzix.lnk
Kernel/platform-amstradnc/nc200/Makefile
Kernel/platform-amstradnc/nc200/fuzix.lnk

index 9a2284d..ba0009a 100644 (file)
@@ -3,6 +3,7 @@
 
 /* We have an RTC */
 #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 */
@@ -55,7 +56,7 @@
 /* Device parameters */
 #define NUM_DEV_TTY 2
 #define TTYDEV   BOOT_TTY /* Device used by kernel for messages, panics */
-#define NBUFS    10       /* Number of block buffers */
+#define NBUFS    9       /* Number of block buffers */
 #ifdef CONFIG_NC200
 #define NMOUNTS        2         /* Floppy can also be mounted */
 #define BOOTDEVICENAMES "hd#,fd#"
diff --git a/Kernel/platform-amstradnc/m146818.c b/Kernel/platform-amstradnc/m146818.c
new file mode 100644 (file)
index 0000000..95a2bfa
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *     This is intended for the NC200. It assumes 24 hour clock mode and
+ *     decimal. The year is 1990 based. This is all fine for the NC200
+ *     as that is how the firmware/OS leave it.
+ */
+
+#include <kernel.h>
+#include <kdata.h>
+#include <stdbool.h>
+#include <printf.h>
+#include <rtc.h>
+
+__sfr __at 0xD0 rtc_second;
+__sfr __at 0xD2 rtc_minute;
+__sfr __at 0xD4 rtc_hour;
+__sfr __at 0xD7 rtc_day;
+__sfr __at 0xD8 rtc_month;
+__sfr __at 0xD9 rtc_year;
+__sfr __at 0xDA rtc_rega;
+
+uint8_t platform_rtc_secs(void) __naked
+{
+        static uint8_t last;
+        if (rtc_rega & 0x80)
+            return last;
+        return rtc_second;
+}
+
+/* Full RTC support (for read - no write yet) */
+int platform_rtc_read(void)
+{
+       uint16_t len = sizeof(struct cmos_rtc);
+       uint16_t y;
+       irqflags_t flags;
+       struct cmos_rtc cmos;
+       uint8_t *p = cmos.data.bytes;
+
+       if (udata.u_count < len)
+               len = udata.u_count;
+
+sync:
+        while(rtc_rega & 0x80);        /* Wait for UIP to clear */
+        
+        flags = di();
+        if (rtc_rega & 0x80)
+            goto sync;
+
+        /* We are now safe for 244uS */
+       y = rtc_year + 1990;
+       *p++ = y;
+       *p++ = y >> 8;
+       *p++ = rtc_month;
+       *p++ = rtc_day;
+        *p++ = rtc_hour;
+        *p++ = rtc_minute;
+        *p++ = rtc_second;
+        irqrestore(flags);
+
+       cmos.type = CMOS_RTC_DEC;
+       if (uput(&cmos, udata.u_base, len) == -1)
+               return -1;
+       return len;
+}
+
+int platform_rtc_write(void)
+{
+       udata.u_error = -EOPNOTSUPP;
+       return -1;
+}
index 7f8a607..20e3a33 100644 (file)
@@ -45,19 +45,3 @@ void map_init(void)
 {
 }
 
-__sfr __at 0xD0 rtc_secl;
-__sfr __at 0xD1 rtc_sech;
-__sfr __at 0xDD rtc_page;
-
-uint8_t platform_rtc_secs(void)
-{
-    uint8_t sl, rv;
-    /* Make sure we are seeing the seconds not NVRAM */
-    rtc_page = 0;
-    /* BCD encoded */
-    do {
-        sl = rtc_secl;
-        rv = sl + rtc_sech * 10;
-    } while (sl != rtc_secl);
-    return rv;
-}
index 5f8fceb..160dcfb 100644 (file)
@@ -1,6 +1,6 @@
 
 CSRCS = ../devlpr.c ../devtty.c ../devrd.c ../devaudio.c ../devgfx.c
-CSRCS += ../devices.c ../main.c
+CSRCS += ../devices.c ../main.c ../tc8521.c
 
 ASRCS = ../nc100.s ../crt0.s
 ASRCS += ../tricks.s ../commonmem.s
index c6f21f7..683a996 100644 (file)
@@ -39,5 +39,6 @@ platform-amstradnc/devlpr.rel
 platform-amstradnc/devtty.rel
 platform-amstradnc/devaudio.rel
 platform-amstradnc/devgfx.rel
+platform-amstradnc/tc8521.rel
 font4x6.rel
 -e
index 2d6b79e..80405e0 100644 (file)
@@ -7,6 +7,7 @@ CSRCS = \
        ../devgfx.c \
        ../devices.c \
        ../main.c \
+       ../m146818.c
 
 ASRCS = \
        ../nc100.s \
index d664db7..46af87f 100644 (file)
@@ -41,5 +41,6 @@ platform-amstradnc/devlpr.rel
 platform-amstradnc/devtty.rel
 platform-amstradnc/devaudio.rel
 platform-amstradnc/devgfx.rel
+platform-amstradnc/m146818.rel
 font4x6.rel
 -e