From 4bfa6fe511b6b11ae5c72d4111ce1603b012f1d9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Jun 2019 08:32:31 -0600 Subject: [PATCH] arch/z80/src/ez80: Correct setting of RTC time. --- arch/z80/src/ez80/ez80_rtc.c | 33 +++++++++++++++++++-------------- arch/z80/src/ez80/ez80_rtc.h | 2 +- configs/makerlisp/README.txt | 1 + 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/z80/src/ez80/ez80_rtc.c b/arch/z80/src/ez80/ez80_rtc.c index ca1c69cab9..b10ad21c7f 100644 --- a/arch/z80/src/ez80/ez80_rtc.c +++ b/arch/z80/src/ez80/ez80_rtc.c @@ -135,8 +135,10 @@ volatile bool g_rtc_enabled = false; /* Debug */ +#ifdef CONFIG_DEBUG_RTC_INFO static void rtc_dumpregs(FAR const char *msg); static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg); +#endif /* Register access */ @@ -302,7 +304,7 @@ static void set_raw_time(FAR const struct rtc_timeregs_s *rtcregs) outp(EZ80_RTC_DOW, rtcregs->dow); outp(EZ80_RTC_DOM, rtcregs->dom); outp(EZ80_RTC_MON, rtcregs->mon); - outp(EZ80_RTC_YR, rtcregs->yr); + outp(EZ80_RTC_YR, rtcregs->yr); outp(EZ80_RTC_CEN, rtcregs->cen); rtc_unlock(); } @@ -508,22 +510,23 @@ int up_rtc_getdatetime(FAR struct tm *tp) get_raw_time(&tmpregs); get_raw_time(&timeregs); } - while (tmpregs.min != timeregs.min && - tmpregs.hrs != timeregs.hrs && - tmpregs.dom != timeregs.dom && - tmpregs.mon != timeregs.mon && - tmpregs.yr != timeregs.yr && + while (tmpregs.min != timeregs.min || + tmpregs.hrs != timeregs.hrs || + tmpregs.dom != timeregs.dom || + tmpregs.mon != timeregs.mon || + tmpregs.yr != timeregs.yr || tmpregs.cen != timeregs.cen); - /* Convert the RTC time to fields in struct tm format. All of the EZ80 - * ranges of values correspond between struct tm and the time register. + /* Convert the RTC time to fields in struct tm format. Most of the EZ80 + * ranges of values correspond between struct tm and the time registers. + * Exceptions: Month and year. */ tp->tm_sec = timeregs.sec; tp->tm_min = timeregs.min; - tp->tm_hour = timeregs.min; + tp->tm_hour = timeregs.hrs; tp->tm_mday = timeregs.dom; - tp->tm_mon = timeregs.dom - 1; /* Range is 0-11 */ + tp->tm_mon = timeregs.mon - 1; /* Range is 0-11 */ /* Years since 1900 */ @@ -555,16 +558,18 @@ int ez80_rtc_setdatetime(FAR const struct tm *tp) uint16_t year; uint16_t cen; + rtc_dumptime(tp, "Requested time"); + timeregs.sec = tp->tm_sec; timeregs.min = tp->tm_min; - timeregs.min = tp->tm_hour; + timeregs.hrs = tp->tm_hour; timeregs.dom = tp->tm_mday; - timeregs.dom = tp->tm_mon + 1; /* Range is 1-12 */ + timeregs.mon = tp->tm_mon + 1; /* Range is 1-12 */ /* Years AD */ year = tp->tm_year + 1900; - cen = year * 100; + cen = year / 100; timeregs.cen = cen; timeregs.yr = year - 100 * cen; @@ -646,7 +651,7 @@ int ez80_rtc_setalarm(FAR struct alm_setalarm_s *alminfo) /* Enable the alarm */ rtc_unlock(); - outp(EZ80_RTC_ACTRL, EZ80_RTX_AALL); + outp(EZ80_RTC_ACTRL, EZ80_RTC_AALL); regval = inp(EZ80_RTC_CTRL); regval |= ~EZ80_RTC_INTEN; diff --git a/arch/z80/src/ez80/ez80_rtc.h b/arch/z80/src/ez80/ez80_rtc.h index 18cdb59e7c..0922fe9a34 100644 --- a/arch/z80/src/ez80/ez80_rtc.h +++ b/arch/z80/src/ez80/ez80_rtc.h @@ -62,7 +62,7 @@ #define EZ80_RTC_AMINEN (1 << 1) /* Bit 1: Enable minutes alarm */ #define EZ80_RTC_AHRSEN (1 << 2) /* Bit 4: Enable hours alarm */ #define EZ80_RTC_ADOWEN (1 << 3) /* Bit 3: Enable day-of-week alarm */ -#define EZ80_RTX_AALL 0x0f /* All times */ +#define EZ80_RTC_AALL 0x0f /* All times */ /* CTRL register */ diff --git a/configs/makerlisp/README.txt b/configs/makerlisp/README.txt index db5787c564..17c50abc39 100644 --- a/configs/makerlisp/README.txt +++ b/configs/makerlisp/README.txt @@ -356,3 +356,4 @@ Configuration Subdirectories Reads from the SD are successful, but writes to the SD card (creating files, creating directories, etc) hang. + 2019-06-18: The RTC now appears to be fully functional.