From: Alan Cox Date: Wed, 11 Jul 2018 22:21:40 +0000 (+0100) Subject: trs80m1: add clock code but ifdef it back out due to an SDCC bug X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=af7d302bbc2a59481230852182e9503341a1f3cf;p=FUZIX.git trs80m1: add clock code but ifdef it back out due to an SDCC bug Filed as #2770 in SDCC bug tracker --- diff --git a/Kernel/platform-trs80m1/config.h b/Kernel/platform-trs80m1/config.h index 82b3a90e..5cc1b4e2 100644 --- a/Kernel/platform-trs80m1/config.h +++ b/Kernel/platform-trs80m1/config.h @@ -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 */ diff --git a/Kernel/platform-trs80m1/main.c b/Kernel/platform-trs80m1/main.c index 1a015553..72d93612 100644 --- a/Kernel/platform-trs80m1/main.c +++ b/Kernel/platform-trs80m1/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -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 /*