diff options
author | YamaArashi <shadow962@live.com> | 2016-04-05 02:39:13 -0700 |
---|---|---|
committer | YamaArashi <shadow962@live.com> | 2016-04-05 02:39:13 -0700 |
commit | 35157edc129183a85dbb3b2468a55af7a0b9d50c (patch) | |
tree | 18e89caa98e3824a19d27ea343fa78d96db0f64c | |
parent | 1d398297a94f918651f532f066a9909761341d62 (diff) |
rename RTC functions/variables
-rw-r--r-- | asm/rom.s | 4 | ||||
-rw-r--r-- | include/rtc.h | 40 | ||||
-rw-r--r-- | include/rtc_util.h | 24 | ||||
-rw-r--r-- | iwram_syms.txt | 6 | ||||
-rw-r--r-- | src/librtc.c | 283 | ||||
-rw-r--r-- | src/rtc_util.c | 102 |
6 files changed, 237 insertions, 222 deletions
@@ -620,7 +620,7 @@ DoSoftReset: ; 80006B4 ands r2, r1 strh r2, [r0, 0xA] ldrh r0, [r0, 0xA] - bl RTC_Protect + bl SiiRtcProtect movs r0, 0xFF bl SoftReset pop {r4} @@ -18851,7 +18851,7 @@ sub_8009A64: ; 8009A64 adds r1, 0x4 movs r0, 0x7 strh r0, [r1] - bl RtcGetStatus + bl RtcGetErrorStatus movs r1, 0xFF lsls r1, 4 ands r1, r0 diff --git a/include/rtc.h b/include/rtc.h index 5ecff238f..5864f95b8 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -3,11 +3,11 @@ #include "gba/gba.h" -#define RTC_INFO_CTRL_UNK1 0x01 // unknown -#define RTC_INFO_CTRL_IRQ_ENABLE 0x02 // per-minute IRQ enable -#define RTC_INFO_CTRL_UNK2 0x04 // unknown -#define RTC_INFO_CTRL_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode -#define RTC_INFO_CTRL_POWER_FAILURE 0x80 // power failure occurred +#define SIIRTCINFO_INTFE 0x01 // frequency interrupt enable +#define SIIRTCINFO_INTME 0x02 // per-minute interrupt enable +#define SIIRTCINFO_INTAE 0x04 // alarm interrupt enable +#define SIIRTCINFO_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode +#define SIIRTCINFO_POWER 0x80 // power on or power failure occurred enum { @@ -25,7 +25,7 @@ enum MONTH_DEC }; -struct RtcInfo +struct SiiRtcInfo { u8 year; u8 month; @@ -34,21 +34,21 @@ struct RtcInfo u8 hour; u8 minute; u8 second; - u8 control; - u8 unknown1; - u8 unknown2; + u8 status; + u8 alarmHour; + u8 alarmMinute; }; -void RTC_Unprotect(); -void RTC_Protect(); -u8 RTC_Probe(); -bool8 RTC_Reset(); -bool8 RTC_GetControl(struct RtcInfo *rtc); -bool8 RTC_SetControl(struct RtcInfo *rtc); -bool8 RTC_GetDateTime(struct RtcInfo *rtc); -bool8 RTC_SetDateTime(struct RtcInfo *rtc); -bool8 RTC_GetTime(struct RtcInfo *rtc); -bool8 RTC_SetTime(struct RtcInfo *rtc); -bool8 RTC_SetUnknownData(struct RtcInfo *rtc); +void SiiRtcUnprotect(); +void SiiRtcProtect(); +u8 SiiRtcProbe(); +bool8 SiiRtcReset(); +bool8 SiiRtcGetStatus(struct SiiRtcInfo *rtc); +bool8 SiiRtcSetStatus(struct SiiRtcInfo *rtc); +bool8 SiiRtcGetDateTime(struct SiiRtcInfo *rtc); +bool8 SiiRtcSetDateTime(struct SiiRtcInfo *rtc); +bool8 SiiRtcGetTime(struct SiiRtcInfo *rtc); +bool8 SiiRtcSetTime(struct SiiRtcInfo *rtc); +bool8 SiiRtcSetAlarm(struct SiiRtcInfo *rtc); #endif // GUARD_RTC_H diff --git a/include/rtc_util.h b/include/rtc_util.h index c92566e94..039d7e4fd 100644 --- a/include/rtc_util.h +++ b/include/rtc_util.h @@ -3,22 +3,22 @@ #include "global.h" -#define RTC_STAT_INIT_ERROR 0x0001 -#define RTC_STAT_INIT_WARNING 0x0002 +#define RTC_INIT_ERROR 0x0001 +#define RTC_INIT_WARNING 0x0002 -#define RTC_STAT_ERR_12HOUR_CLOCK 0x0010 -#define RTC_STAT_ERR_POWER_FAILURE 0x0020 -#define RTC_STAT_ERR_INVALID_YEAR 0x0040 -#define RTC_STAT_ERR_INVALID_MONTH 0x0080 -#define RTC_STAT_ERR_INVALID_DAY 0x0100 -#define RTC_STAT_ERR_INVALID_HOUR 0x0200 -#define RTC_STAT_ERR_INVALID_MINUTE 0x0400 -#define RTC_STAT_ERR_INVALID_SECOND 0x0800 +#define RTC_ERR_12HOUR_CLOCK 0x0010 +#define RTC_ERR_POWER_FAILURE 0x0020 +#define RTC_ERR_INVALID_YEAR 0x0040 +#define RTC_ERR_INVALID_MONTH 0x0080 +#define RTC_ERR_INVALID_DAY 0x0100 +#define RTC_ERR_INVALID_HOUR 0x0200 +#define RTC_ERR_INVALID_MINUTE 0x0400 +#define RTC_ERR_INVALID_SECOND 0x0800 -#define RTC_STAT_ERROR_FLAGS 0x0FF0 +#define RTC_ERROR_FLAGS 0x0FF0 void RtcInit(); -u16 RtcGetStatus(); +u16 RtcGetErrorStatus(); void RtcReset(); void FormatDecimalTime(u8 *dest, s32 hour, s32 minute, s32 second); void FormatHexTime(u8 *dest, s32 hour, s32 minute, s32 second); diff --git a/iwram_syms.txt b/iwram_syms.txt index 844e2b433..b3ad6eb06 100644 --- a/iwram_syms.txt +++ b/iwram_syms.txt @@ -1,11 +1,11 @@ -gRtcStatus = 0x3000458; -gRtcInfo = 0x3000460; +gRtcErrorStatus = 0x3000458; +gRtc = 0x3000460; gRtcProbeResult = 0x300046C; gRtcSavedIme = 0x300046E; gPlayTimeCounterState = 0x300057C; -gRtcLocked = 0x3000F36; +gSiiRtcLocked = 0x3000F36; gUnknownStringVar = 0x3002900; diff --git a/src/librtc.c b/src/librtc.c index b87862a8f..5ed3b4fc7 100644 --- a/src/librtc.c +++ b/src/librtc.c @@ -1,88 +1,104 @@ #include "gba/gba.h" #include "rtc.h" -#define RTC_CTRL_UNK1 0x02 // unknown -#define RTC_CTRL_IRQ_ENABLE 0x08 // per-minute IRQ enable -#define RTC_CTRL_UNK2 0x20 // unknown -#define RTC_CTRL_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode -#define RTC_CTRL_POWER_FAILURE 0x80 // power failure occurred - -#define OFFSET_YEAR offsetof(struct RtcInfo, year) -#define OFFSET_MONTH offsetof(struct RtcInfo, month) -#define OFFSET_DAY offsetof(struct RtcInfo, day) -#define OFFSET_DAY_OF_WEEK offsetof(struct RtcInfo, dayOfWeek) -#define OFFSET_HOUR offsetof(struct RtcInfo, hour) -#define OFFSET_MINUTE offsetof(struct RtcInfo, minute) -#define OFFSET_SECOND offsetof(struct RtcInfo, second) -#define OFFSET_CONTROL offsetof(struct RtcInfo, control) -#define OFFSET_UNKNOWN1 offsetof(struct RtcInfo, unknown1) -#define OFFSET_UNKNOWN2 offsetof(struct RtcInfo, unknown2) - -#define RTC_BUF(info, index) (*((u8 *)(info) + (index))) - -#define RTC_DATETIME_BUF(info, index) (*((u8 *)(info) + OFFSET_YEAR + (index))) -#define RTC_DATETIME_BUF_LEN (OFFSET_SECOND - OFFSET_YEAR + 1) - -#define RTC_TIME_BUF(info, index) (*((u8 *)(info) + OFFSET_HOUR + (index))) -#define RTC_TIME_BUF_LEN (OFFSET_SECOND - OFFSET_HOUR + 1) - -#define RTC_CMD_RESET 0x60 -#define RTC_CMD_WR_CONTROL 0x62 -#define RTC_CMD_RD_CONTROL 0x63 -#define RTC_CMD_WR_DATETIME 0x64 -#define RTC_CMD_RD_DATETIME 0x65 -#define RTC_CMD_WR_TIME 0x66 -#define RTC_CMD_RD_TIME 0x67 -#define RTC_CMD_WR_UNKNOWN 0x68 +#define STATUS_INTFE 0x02 // frequency interrupt enable +#define STATUS_INTME 0x08 // per-minute interrupt enable +#define STATUS_INTAE 0x20 // alarm interrupt enable +#define STATUS_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode +#define STATUS_POWER 0x80 // power on or power failure occurred + +#define TEST_MODE 0x80 // flag in the "second" byte + +#define ALARM_AM 0x00 +#define ALARM_PM 0x80 + +#define OFFSET_YEAR offsetof(struct SiiRtcInfo, year) +#define OFFSET_MONTH offsetof(struct SiiRtcInfo, month) +#define OFFSET_DAY offsetof(struct SiiRtcInfo, day) +#define OFFSET_DAY_OF_WEEK offsetof(struct SiiRtcInfo, dayOfWeek) +#define OFFSET_HOUR offsetof(struct SiiRtcInfo, hour) +#define OFFSET_MINUTE offsetof(struct SiiRtcInfo, minute) +#define OFFSET_SECOND offsetof(struct SiiRtcInfo, second) +#define OFFSET_STATUS offsetof(struct SiiRtcInfo, status) +#define OFFSET_ALARM_HOUR offsetof(struct SiiRtcInfo, alarmHour) +#define OFFSET_ALARM_MINUTE offsetof(struct SiiRtcInfo, alarmMinute) + +#define INFO_BUF(info, index) (*((u8 *)(info) + (index))) + +#define DATETIME_BUF(info, index) INFO_BUF(info, OFFSET_YEAR + index) +#define DATETIME_BUF_LEN (OFFSET_SECOND - OFFSET_YEAR + 1) + +#define TIME_BUF(info, index) INFO_BUF(info, OFFSET_HOUR + index) +#define TIME_BUF_LEN (OFFSET_SECOND - OFFSET_HOUR + 1) + +#define WR 0 // command for writing data +#define RD 1 // command for reading data + +#define CMD(n) (0x60 | (n << 1)) + +#define CMD_RESET CMD(0) +#define CMD_STATUS CMD(1) +#define CMD_DATETIME CMD(2) +#define CMD_TIME CMD(3) +#define CMD_ALARM CMD(4) extern vu16 GPIOPortData; extern vu16 GPIOPortDirection; extern vu16 GPIOPortReadEnable; -extern bool8 gRtcLocked; +extern bool8 gSiiRtcLocked; -s32 RTC_WriteCommand(u8 value); -s32 RTC_WriteData(u8 value); -u8 RTC_ReadData(); -void RTC_EnableGpioPortRead(); -void RTC_DisableGpioPortRead(); +static int WriteCommand(u8 value); +static int WriteData(u8 value); +static u8 ReadData(); +static void EnableGpioPortRead(); +static void DisableGpioPortRead(); -void RTC_Unprotect() +void SiiRtcUnprotect() { - RTC_EnableGpioPortRead(); - gRtcLocked = FALSE; + EnableGpioPortRead(); + gSiiRtcLocked = FALSE; } -void RTC_Protect() +void SiiRtcProtect() { - RTC_DisableGpioPortRead(); - gRtcLocked = TRUE; + DisableGpioPortRead(); + gSiiRtcLocked = TRUE; } -u8 RTC_Probe() +u8 SiiRtcProbe() { u8 errorCode; - struct RtcInfo rtc; + struct SiiRtcInfo rtc; - if (!RTC_GetControl(&rtc)) + if (!SiiRtcGetStatus(&rtc)) return 0; errorCode = 0; - if ((rtc.control & (RTC_INFO_CTRL_POWER_FAILURE | RTC_INFO_CTRL_24HOUR)) == RTC_INFO_CTRL_POWER_FAILURE - || (rtc.control & (RTC_INFO_CTRL_POWER_FAILURE | RTC_INFO_CTRL_24HOUR)) == 0) + if ((rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == SIIRTCINFO_POWER + || (rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == 0) { - if (!RTC_Reset()) + // The RTC is in 12-hour mode. Reset it and switch to 24-hour mode. + + // Note that the conditions are redundant and equivalent to simply + // "(rtc.status & SIIRTCINFO_24HOUR) == 0". It's possible that this + // was also intended to handle resetting the clock after power failure + // but a mistake was made. + + if (!SiiRtcReset()) return 0; errorCode++; } - RTC_GetTime(&rtc); + SiiRtcGetTime(&rtc); - if (rtc.second & 0x80) + if (rtc.second & TEST_MODE) { - if (!RTC_Reset()) + // The RTC is in test mode. Reset it to leave test mode. + + if (!SiiRtcReset()) return (errorCode << 4) & 0xF0; errorCode++; @@ -91,257 +107,256 @@ u8 RTC_Probe() return (errorCode << 4) | 1; } -bool8 RTC_Reset() +bool8 SiiRtcReset() { u8 result; - struct RtcInfo rtc; + struct SiiRtcInfo rtc; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; GPIOPortData = 1; GPIOPortData = 5; GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_RESET); + WriteCommand(CMD_RESET | WR); GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; - rtc.control = RTC_INFO_CTRL_24HOUR; + rtc.status = SIIRTCINFO_24HOUR; - result = RTC_SetControl(&rtc); + result = SiiRtcSetStatus(&rtc); return result; } -bool8 RTC_GetControl(struct RtcInfo *rtc) +bool8 SiiRtcGetStatus(struct SiiRtcInfo *rtc) { - u8 controlData; + u8 statusData; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; GPIOPortData = 1; GPIOPortData = 5; GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_RD_CONTROL); + WriteCommand(CMD_STATUS | RD); GPIOPortDirection = 5; - controlData = RTC_ReadData(); + statusData = ReadData(); - rtc->control = (controlData & (RTC_CTRL_POWER_FAILURE | RTC_CTRL_24HOUR)) - | ((controlData & RTC_CTRL_UNK2) >> 3) - | ((controlData & RTC_CTRL_IRQ_ENABLE) >> 2) - | ((controlData & RTC_CTRL_UNK1) >> 1); + rtc->status = (statusData & (STATUS_POWER | STATUS_24HOUR)) + | ((statusData & STATUS_INTAE) >> 3) + | ((statusData & STATUS_INTME) >> 2) + | ((statusData & STATUS_INTFE) >> 1); GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; return TRUE; } -bool8 RTC_SetControl(struct RtcInfo *rtc) +bool8 SiiRtcSetStatus(struct SiiRtcInfo *rtc) { - u8 controlData; + u8 statusData; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; GPIOPortData = 1; GPIOPortData = 5; - controlData = RTC_CTRL_24HOUR - | ((rtc->control & RTC_INFO_CTRL_UNK2) << 3) - | ((rtc->control & RTC_INFO_CTRL_IRQ_ENABLE) << 2) - | ((rtc->control & RTC_INFO_CTRL_UNK1) << 1); + statusData = STATUS_24HOUR + | ((rtc->status & SIIRTCINFO_INTAE) << 3) + | ((rtc->status & SIIRTCINFO_INTME) << 2) + | ((rtc->status & SIIRTCINFO_INTFE) << 1); GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_WR_CONTROL); + WriteCommand(CMD_STATUS | WR); - RTC_WriteData(controlData); + WriteData(statusData); GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; return TRUE; } -bool8 RTC_GetDateTime(struct RtcInfo *rtc) +bool8 SiiRtcGetDateTime(struct SiiRtcInfo *rtc) { u8 i; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; GPIOPortData = 1; GPIOPortData = 5; GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_RD_DATETIME); + WriteCommand(CMD_DATETIME | RD); GPIOPortDirection = 5; - for (i = 0; i < RTC_DATETIME_BUF_LEN; i++) - RTC_DATETIME_BUF(rtc, i) = RTC_ReadData(); + for (i = 0; i < DATETIME_BUF_LEN; i++) + DATETIME_BUF(rtc, i) = ReadData(); - RTC_BUF(rtc, OFFSET_HOUR) &= 0x7F; + INFO_BUF(rtc, OFFSET_HOUR) &= 0x7F; GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; return TRUE; } -bool8 RTC_SetDateTime(struct RtcInfo *rtc) +bool8 SiiRtcSetDateTime(struct SiiRtcInfo *rtc) { u8 i; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; GPIOPortData = 1; GPIOPortData = 5; GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_WR_DATETIME); + WriteCommand(CMD_DATETIME | WR); - for (i = 0; i < RTC_DATETIME_BUF_LEN; i++) - RTC_WriteData(RTC_DATETIME_BUF(rtc, i)); + for (i = 0; i < DATETIME_BUF_LEN; i++) + WriteData(DATETIME_BUF(rtc, i)); GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; return TRUE; } -bool8 RTC_GetTime(struct RtcInfo *rtc) +bool8 SiiRtcGetTime(struct SiiRtcInfo *rtc) { u8 i; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; GPIOPortData = 1; GPIOPortData = 5; GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_RD_TIME); + WriteCommand(CMD_TIME | RD); GPIOPortDirection = 5; - for (i = 0; i < RTC_TIME_BUF_LEN; i++) - RTC_TIME_BUF(rtc, i) = RTC_ReadData(); + for (i = 0; i < TIME_BUF_LEN; i++) + TIME_BUF(rtc, i) = ReadData(); - RTC_BUF(rtc, OFFSET_HOUR) &= 0x7F; + INFO_BUF(rtc, OFFSET_HOUR) &= 0x7F; GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; return TRUE; } -bool8 RTC_SetTime(struct RtcInfo *rtc) +bool8 SiiRtcSetTime(struct SiiRtcInfo *rtc) { u8 i; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; GPIOPortData = 1; GPIOPortData = 5; GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_WR_TIME); + WriteCommand(CMD_TIME | WR); - for (i = 0; i < RTC_TIME_BUF_LEN; i++) - RTC_WriteData(RTC_TIME_BUF(rtc, i)); + for (i = 0; i < TIME_BUF_LEN; i++) + WriteData(TIME_BUF(rtc, i)); GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; return TRUE; } -bool8 RTC_SetUnknownData(struct RtcInfo *rtc) +bool8 SiiRtcSetAlarm(struct SiiRtcInfo *rtc) { u8 i; - u8 a[2]; + u8 alarmData[2]; - if (gRtcLocked == TRUE) + if (gSiiRtcLocked == TRUE) return FALSE; - gRtcLocked = TRUE; + gSiiRtcLocked = TRUE; - // unknown1 appears to be a BCD number in the range 0-11, - // so it may be an hour in 12-hour format. - // Months are normally 1-12. + // Decode BCD. + alarmData[0] = (rtc->alarmHour & 0xF) + 10 * ((rtc->alarmHour >> 4) & 0xF); - a[0] = ((rtc->unknown1 & 0xF) + 10 * ((rtc->unknown1 >> 4) & 0xF)); + // The AM/PM flag must be set correctly even in 24-hour mode. - if (a[0] < 12) - a[0] = rtc->unknown1; + if (alarmData[0] < 12) + alarmData[0] = rtc->alarmHour | ALARM_AM; else - a[0] = rtc->unknown1 | 0x80; + alarmData[0] = rtc->alarmHour | ALARM_PM; - a[1] = rtc->unknown2; + alarmData[1] = rtc->alarmMinute; GPIOPortData = 1; GPIOPortData = 5; GPIOPortDirection = 7; - RTC_WriteCommand(RTC_CMD_WR_UNKNOWN); + WriteCommand(CMD_ALARM | WR); for (i = 0; i < 2; i++) - RTC_WriteData(a[i]); + WriteData(alarmData[i]); GPIOPortData = 1; GPIOPortData = 1; - gRtcLocked = FALSE; + gSiiRtcLocked = FALSE; return TRUE; } -s32 RTC_WriteCommand(u8 value) +static int WriteCommand(u8 value) { u8 i; u8 temp; @@ -358,7 +373,7 @@ s32 RTC_WriteCommand(u8 value) // control reaches end of non-void function } -s32 RTC_WriteData(u8 value) +static int WriteData(u8 value) { u8 i; u8 temp; @@ -375,7 +390,7 @@ s32 RTC_WriteData(u8 value) // control reaches end of non-void function } -u8 RTC_ReadData() +static u8 ReadData() { u8 i; u8 temp; @@ -397,12 +412,12 @@ u8 RTC_ReadData() return value; } -void RTC_EnableGpioPortRead() +static void EnableGpioPortRead() { GPIOPortReadEnable = 1; } -void RTC_DisableGpioPortRead() +static void DisableGpioPortRead() { GPIOPortReadEnable = 0; } diff --git a/src/rtc_util.c b/src/rtc_util.c index ba69d1d67..940b1fea9 100644 --- a/src/rtc_util.c +++ b/src/rtc_util.c @@ -3,11 +3,11 @@ #include "rtc_util.h" #include "string_util.h" -extern const struct RtcInfo gDefaultRtcInfo; +extern const struct SiiRtcInfo gDefaultRtcInfo; extern const s32 gNumDaysInMonths[]; -extern u16 gRtcStatus; -extern struct RtcInfo gRtcInfo; +extern u16 gRtcErrorStatus; +extern struct SiiRtcInfo gRtc; extern u8 gRtcProbeResult; extern u16 gRtcSavedIme; @@ -18,13 +18,13 @@ void RtcRestoreInterrupts(); u32 ConvertBcdToBinary(u8 bcd); bool8 IsLeapYear(u8 year); u16 ConvertDateToDayCount(u8 year, u8 month, u8 day); -u16 RtcGetDayCount(struct RtcInfo *rtc); -void RtcGetInfo(struct RtcInfo *rtc); -void RtcGetDateTime(struct RtcInfo *rtc); -void RtcGetControl(struct RtcInfo *rtc); -void RtcGetRawInfo(struct RtcInfo *rtc); -u16 RtcCheckInfo(struct RtcInfo *rtc); -void RtcCalcTimeDifference(struct RtcInfo *rtc, struct Time *result, struct Time *t); +u16 RtcGetDayCount(struct SiiRtcInfo *rtc); +void RtcGetInfo(struct SiiRtcInfo *rtc); +void RtcGetDateTime(struct SiiRtcInfo *rtc); +void RtcGetStatus(struct SiiRtcInfo *rtc); +void RtcGetRawInfo(struct SiiRtcInfo *rtc); +u16 RtcCheckInfo(struct SiiRtcInfo *rtc); +void RtcCalcTimeDifference(struct SiiRtcInfo *rtc, struct Time *result, struct Time *t); void RtcDisableInterrupts() { @@ -94,7 +94,7 @@ u16 ConvertDateToDayCount(u8 year, u8 month, u8 day) return dayCount; } -u16 RtcGetDayCount(struct RtcInfo *rtc) +u16 RtcGetDayCount(struct SiiRtcInfo *rtc) { u8 year = ConvertBcdToBinary(rtc->year); u8 month = ConvertBcdToBinary(rtc->month); @@ -104,114 +104,114 @@ u16 RtcGetDayCount(struct RtcInfo *rtc) void RtcInit() { - gRtcStatus = 0; + gRtcErrorStatus = 0; RtcDisableInterrupts(); - RTC_Unprotect(); - gRtcProbeResult = RTC_Probe(); + SiiRtcUnprotect(); + gRtcProbeResult = SiiRtcProbe(); RtcRestoreInterrupts(); if (!(gRtcProbeResult & 0xF)) { - gRtcStatus = RTC_STAT_INIT_ERROR; + gRtcErrorStatus = RTC_INIT_ERROR; return; } if (gRtcProbeResult & 0xF0) - gRtcStatus = RTC_STAT_INIT_WARNING; + gRtcErrorStatus = RTC_INIT_WARNING; else - gRtcStatus = 0; + gRtcErrorStatus = 0; - RtcGetRawInfo(&gRtcInfo); - gRtcStatus = RtcCheckInfo(&gRtcInfo); + RtcGetRawInfo(&gRtc); + gRtcErrorStatus = RtcCheckInfo(&gRtc); } -u16 RtcGetStatus() +u16 RtcGetErrorStatus() { - return gRtcStatus; + return gRtcErrorStatus; } -void RtcGetInfo(struct RtcInfo *rtc) +void RtcGetInfo(struct SiiRtcInfo *rtc) { - if (gRtcStatus & RTC_STAT_ERROR_FLAGS) + if (gRtcErrorStatus & RTC_ERROR_FLAGS) *rtc = gDefaultRtcInfo; else RtcGetRawInfo(rtc); } -void RtcGetDateTime(struct RtcInfo *rtc) +void RtcGetDateTime(struct SiiRtcInfo *rtc) { RtcDisableInterrupts(); - RTC_GetDateTime(rtc); + SiiRtcGetDateTime(rtc); RtcRestoreInterrupts(); } -void RtcGetControl(struct RtcInfo *rtc) +void RtcGetStatus(struct SiiRtcInfo *rtc) { RtcDisableInterrupts(); - RTC_GetControl(rtc); + SiiRtcGetStatus(rtc); RtcRestoreInterrupts(); } -void RtcGetRawInfo(struct RtcInfo *rtc) +void RtcGetRawInfo(struct SiiRtcInfo *rtc) { - RtcGetControl(rtc); + RtcGetStatus(rtc); RtcGetDateTime(rtc); } -u16 RtcCheckInfo(struct RtcInfo *rtc) +u16 RtcCheckInfo(struct SiiRtcInfo *rtc) { u16 errorFlags = 0; s32 year; s32 month; s32 value; - if (rtc->control & RTC_INFO_CTRL_POWER_FAILURE) - errorFlags |= RTC_STAT_ERR_POWER_FAILURE; + if (rtc->status & SIIRTCINFO_POWER) + errorFlags |= RTC_ERR_POWER_FAILURE; - if (!(rtc->control & RTC_INFO_CTRL_24HOUR)) - errorFlags |= RTC_STAT_ERR_12HOUR_CLOCK; + if (!(rtc->status & SIIRTCINFO_24HOUR)) + errorFlags |= RTC_ERR_12HOUR_CLOCK; year = ConvertBcdToBinary(rtc->year); if (year == 0xFF) - errorFlags |= RTC_STAT_ERR_INVALID_YEAR; + errorFlags |= RTC_ERR_INVALID_YEAR; month = ConvertBcdToBinary(rtc->month); if (month == 0xFF || month == 0 || month > 12) - errorFlags |= RTC_STAT_ERR_INVALID_MONTH; + errorFlags |= RTC_ERR_INVALID_MONTH; value = ConvertBcdToBinary(rtc->day); if (value == 0xFF) - errorFlags |= RTC_STAT_ERR_INVALID_DAY; + errorFlags |= RTC_ERR_INVALID_DAY; if (month == MONTH_FEB) { if (value > IsLeapYear(year) + gNumDaysInMonths[month - 1]) - errorFlags |= RTC_STAT_ERR_INVALID_DAY; + errorFlags |= RTC_ERR_INVALID_DAY; } else { if (value > gNumDaysInMonths[month - 1]) - errorFlags |= RTC_STAT_ERR_INVALID_DAY; + errorFlags |= RTC_ERR_INVALID_DAY; } value = ConvertBcdToBinary(rtc->hour); if (value > 24) - errorFlags |= RTC_STAT_ERR_INVALID_HOUR; + errorFlags |= RTC_ERR_INVALID_HOUR; value = ConvertBcdToBinary(rtc->minute); if (value > 60) - errorFlags |= RTC_STAT_ERR_INVALID_MINUTE; + errorFlags |= RTC_ERR_INVALID_MINUTE; value = ConvertBcdToBinary(rtc->second); if (value > 60) - errorFlags |= RTC_STAT_ERR_INVALID_SECOND; + errorFlags |= RTC_ERR_INVALID_SECOND; return errorFlags; } @@ -219,7 +219,7 @@ u16 RtcCheckInfo(struct RtcInfo *rtc) void RtcReset() { RtcDisableInterrupts(); - RTC_Reset(); + SiiRtcReset(); RtcRestoreInterrupts(); } @@ -245,7 +245,7 @@ void FormatHexTime(u8 *dest, s32 hour, s32 minute, s32 second) void FormatHexRtcTime(u8 *dest) { - FormatHexTime(dest, gRtcInfo.hour, gRtcInfo.minute, gRtcInfo.second); + FormatHexTime(dest, gRtc.hour, gRtc.minute, gRtc.second); } void FormatDecimalDate(u8 *dest, s32 year, s32 month, s32 day) @@ -268,7 +268,7 @@ void FormatHexDate(u8 *dest, s32 year, s32 month, s32 day) *dest = EOS; } -void RtcCalcTimeDifference(struct RtcInfo *rtc, struct Time *result, struct Time *t) +void RtcCalcTimeDifference(struct SiiRtcInfo *rtc, struct Time *result, struct Time *t) { u16 days = RtcGetDayCount(rtc); result->seconds = ConvertBcdToBinary(rtc->second) - t->seconds; @@ -297,8 +297,8 @@ void RtcCalcTimeDifference(struct RtcInfo *rtc, struct Time *result, struct Time void RtcCalcLocalTime() { - RtcGetInfo(&gRtcInfo); - RtcCalcTimeDifference(&gRtcInfo, &gLocalTime, &gSaveBlock2.localTimeOffset); + RtcGetInfo(&gRtc); + RtcCalcTimeDifference(&gRtc, &gLocalTime, &gSaveBlock2.localTimeOffset); } void RtcInitLocalTimeOffset(s32 hour, s32 minute) @@ -312,8 +312,8 @@ void RtcCalcLocalTimeOffset(s32 days, s32 hours, s32 minutes, s32 seconds) gLocalTime.hours = hours; gLocalTime.minutes = minutes; gLocalTime.seconds = seconds; - RtcGetInfo(&gRtcInfo); - RtcCalcTimeDifference(&gRtcInfo, &gSaveBlock2.localTimeOffset, &gLocalTime); + RtcGetInfo(&gRtc); + RtcCalcTimeDifference(&gRtc, &gSaveBlock2.localTimeOffset, &gLocalTime); } void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2) @@ -344,6 +344,6 @@ void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2) u32 RtcGetMinuteCount() { - RtcGetInfo(&gRtcInfo); - return (24 * 60) * RtcGetDayCount(&gRtcInfo) + 60 * gRtcInfo.hour + gRtcInfo.minute; + RtcGetInfo(&gRtc); + return (24 * 60) * RtcGetDayCount(&gRtc) + 60 * gRtc.hour + gRtc.minute; } |