From: Alan Cox Date: Sat, 17 Nov 2018 13:21:19 +0000 (+0000) Subject: sam: rtc support now appears to be in working order X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6f3c14dd6a426b7a58ce30851683933fa99a0481;p=FUZIX.git sam: rtc support now appears to be in working order --- diff --git a/Kernel/platform-sam/README b/Kernel/platform-sam/README index c1f6a123..c766dd97 100644 --- a/Kernel/platform-sam/README +++ b/Kernel/platform-sam/README @@ -40,6 +40,7 @@ Stub code is in the low parts of the low banks and the top of the high banks so we have two copier routines one for each half. - Control key debugging + - Review and test signal handling paths more - AtomIDE driver (prob need minimal copiers in high stubs) - RTC driver - Serial driver @@ -69,7 +70,6 @@ Boot from the created floppy .mgt file Filesystem on Atomlite. If using simcoupe dd it 534 bytes into the image Select device 0 for boot to get atomlite (you can do partitions) - DONE - Crashes on interrupt preempt (Fixed I hope) DONE - Fix signal handling crashes ( ditto ) DONE - Run out of pages - suggests child exit/bank32 isn't cleaning diff --git a/Kernel/platform-sam/config.h b/Kernel/platform-sam/config.h index df1c54eb..635314e6 100644 --- a/Kernel/platform-sam/config.h +++ b/Kernel/platform-sam/config.h @@ -1,4 +1,5 @@ #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-sam/discard.c b/Kernel/platform-sam/discard.c index 7b26ec14..191d99e3 100644 --- a/Kernel/platform-sam/discard.c +++ b/Kernel/platform-sam/discard.c @@ -7,6 +7,9 @@ #include #include +/* FIXME */ +extern int strcmp(const char *, const char *); + void map_init(void) { } @@ -25,7 +28,10 @@ void pagemap_init(void) uint8_t platform_param(char *p) { - used(p); + if (strcmp(p, "rtc") == 0) { + samrtc = 1; + return 1; + } return 0; } diff --git a/Kernel/platform-sam/msm6242b.c b/Kernel/platform-sam/msm6242b.c index 0b32f2ef..9d7e68c6 100644 --- a/Kernel/platform-sam/msm6242b.c +++ b/Kernel/platform-sam/msm6242b.c @@ -4,11 +4,12 @@ #include #include +#include #include #include static uint8_t rtc_buf[6]; -static uint8_t samrtc = 0; +uint8_t samrtc; uint8_t platform_rtc_secs(void) { @@ -19,7 +20,7 @@ uint8_t platform_rtc_secs(void) do { r = samrtc_in(0); - v = samrtc_in(1); + v = samrtc_in(0x10); } while (r != samrtc_in(0)); return v * 10 + r; @@ -30,9 +31,9 @@ static void read_clock_once(void) uint8_t *p = rtc_buf; uint8_t n = 0; - while(n < 12) { - *p++ = samrtc_in(n) | (samrtc_in(n + 1) << 4); - n += 2; + while(n < 0xC0) { + *p++ = samrtc_in(n) | (samrtc_in(n + 0x10) << 4); + n += 0x20; } } @@ -54,6 +55,7 @@ int platform_rtc_read(void) uint8_t *p = cmos.data.bytes; if (!samrtc) { + kputs("nortc\n"); udata.u_error = -EOPNOTSUPP; return -1; } @@ -63,16 +65,11 @@ int platform_rtc_read(void) read_clock(); y = rtc_buf[5]; - /* 1980 based year , if its 0x20 or more we are in 2000-2079 and - need to adjust the clock up by 2000 and back by 10. If not well - then its 1980-1999 so just needs 0x1980 adding to the 0-9 we have */ - if (y >= 0x20) - y += 0x19F0; - else - y += 0x1980; - *p++ = y >> 8; + /* Year is the low 2 digits. We work on the basis that it's past + 2000 now so just assume 20xx */ + *p++ = 0x20; *p++ = y; - *p++ = rtc_buf[4]; /* month */ + *p++ = rtc_buf[4] - 1; /* month (convert from 1 based) */ *p++ = rtc_buf[3]; /* day */ *p++ = rtc_buf[2]; /* Hour */ *p++ = rtc_buf[1]; /* Minute */ @@ -94,20 +91,23 @@ uint8_t platform_rtc_probe(void) { uint8_t r; + if (samrtc) + return 1; + for (r = 0; r < 12; r++) { if (samrtc_in(r) > 9) return 0; } /* Now play with 24 hour mode */ - r = samrtc_in(15); + r = samrtc_in(0xF0); r &= ~4; - samrtc_out(15 | (r << 8)); - if (samrtc_in(15) != r) + samrtc_out(0xF0 | (r << 8)); + if (samrtc_in(0xF0) != r) return 0; r |= 4; /* 24 hour */ - samrtc_out(15 | (r << 8)); - if (samrtc_in(15) != r) + samrtc_out(0xF0 | (r << 8)); + if (samrtc_in(0xF0) != r) return 0; /* Looks like we have a valid Sam RTC */ samrtc = 1; diff --git a/Kernel/platform-sam/msm6242b.h b/Kernel/platform-sam/msm6242b.h index 1a892f4b..9ee1c903 100644 --- a/Kernel/platform-sam/msm6242b.h +++ b/Kernel/platform-sam/msm6242b.h @@ -2,3 +2,5 @@ extern uint8_t samrtc_in(uint8_t reg) __z88dk_fastcall; extern void samrtc_out(uint16_t rv) __z88dk_fastcall; extern uint8_t platform_rtc_probe(void); + +extern uint8_t samrtc;