#include <timer.h>
#include <kdata.h>
#include <printf.h>
+#include <rtc.h>
#include <devtty.h>
#include <trs80.h>
__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)
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
/*