Document siirtc a bit more

This commit is contained in:
Diegoisawesome 2019-01-30 19:48:28 -06:00
parent 6b2dda422b
commit 3f1a7330dd

View file

@ -46,6 +46,19 @@
#define CMD_TIME CMD(3)
#define CMD_ALARM CMD(4)
#define SCK_HI 1
#define SIO_HI 2
#define CS_HI 4
#define DIR_0_IN 0
#define DIR_0_OUT 1
#define DIR_1_IN 0
#define DIR_1_OUT 2
#define DIR_2_IN 0
#define DIR_2_OUT 4
#define DIR_ALL_IN (DIR_0_IN | DIR_1_IN | DIR_2_IN)
#define DIR_ALL_OUT (DIR_0_OUT | DIR_1_OUT | DIR_2_OUT)
#define GPIO_PORT_DATA (*(vu16 *)0x80000C4)
#define GPIO_PORT_DIRECTION (*(vu16 *)0x80000C6)
#define GPIO_PORT_READ_ENABLE (*(vu16 *)0x80000C8)
@ -126,15 +139,15 @@ bool8 SiiRtcReset()
sLocked = TRUE;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
GPIO_PORT_DIRECTION = 7;
GPIO_PORT_DIRECTION = DIR_ALL_OUT;
WriteCommand(CMD_RESET | WR);
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -154,14 +167,14 @@ bool8 SiiRtcGetStatus(struct SiiRtcInfo *rtc)
sLocked = TRUE;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
GPIO_PORT_DIRECTION = 7;
GPIO_PORT_DIRECTION = DIR_ALL_OUT;
WriteCommand(CMD_STATUS | RD);
GPIO_PORT_DIRECTION = 5;
GPIO_PORT_DIRECTION = DIR_0_OUT | DIR_1_IN | DIR_2_OUT;
statusData = ReadData();
@ -170,8 +183,8 @@ bool8 SiiRtcGetStatus(struct SiiRtcInfo *rtc)
| ((statusData & STATUS_INTME) >> 2)
| ((statusData & STATUS_INTFE) >> 1);
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -187,22 +200,22 @@ bool8 SiiRtcSetStatus(struct SiiRtcInfo *rtc)
sLocked = TRUE;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
statusData = STATUS_24HOUR
| ((rtc->status & SIIRTCINFO_INTAE) << 3)
| ((rtc->status & SIIRTCINFO_INTME) << 2)
| ((rtc->status & SIIRTCINFO_INTFE) << 1);
GPIO_PORT_DIRECTION = 7;
GPIO_PORT_DIRECTION = DIR_ALL_OUT;
WriteCommand(CMD_STATUS | WR);
WriteData(statusData);
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -218,22 +231,22 @@ bool8 SiiRtcGetDateTime(struct SiiRtcInfo *rtc)
sLocked = TRUE;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
GPIO_PORT_DIRECTION = 7;
GPIO_PORT_DIRECTION = DIR_ALL_OUT;
WriteCommand(CMD_DATETIME | RD);
GPIO_PORT_DIRECTION = 5;
GPIO_PORT_DIRECTION = DIR_0_OUT | DIR_1_IN | DIR_2_OUT;
for (i = 0; i < DATETIME_BUF_LEN; i++)
DATETIME_BUF(rtc, i) = ReadData();
INFO_BUF(rtc, OFFSET_HOUR) &= 0x7F;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -249,18 +262,18 @@ bool8 SiiRtcSetDateTime(struct SiiRtcInfo *rtc)
sLocked = TRUE;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
GPIO_PORT_DIRECTION = 7;
GPIO_PORT_DIRECTION = DIR_ALL_OUT;
WriteCommand(CMD_DATETIME | WR);
for (i = 0; i < DATETIME_BUF_LEN; i++)
WriteData(DATETIME_BUF(rtc, i));
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -276,22 +289,22 @@ bool8 SiiRtcGetTime(struct SiiRtcInfo *rtc)
sLocked = TRUE;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
GPIO_PORT_DIRECTION = 7;
GPIO_PORT_DIRECTION = DIR_ALL_OUT;
WriteCommand(CMD_TIME | RD);
GPIO_PORT_DIRECTION = 5;
GPIO_PORT_DIRECTION = DIR_0_OUT | DIR_1_IN | DIR_2_OUT;
for (i = 0; i < TIME_BUF_LEN; i++)
TIME_BUF(rtc, i) = ReadData();
INFO_BUF(rtc, OFFSET_HOUR) &= 0x7F;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -307,18 +320,18 @@ bool8 SiiRtcSetTime(struct SiiRtcInfo *rtc)
sLocked = TRUE;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
GPIO_PORT_DIRECTION = 7;
GPIO_PORT_DIRECTION = DIR_ALL_OUT;
WriteCommand(CMD_TIME | WR);
for (i = 0; i < TIME_BUF_LEN; i++)
WriteData(TIME_BUF(rtc, i));
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -347,18 +360,18 @@ bool8 SiiRtcSetAlarm(struct SiiRtcInfo *rtc)
alarmData[1] = rtc->alarmMinute;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
GPIOPortDirection = 7; // Why is this the only instance that uses a symbol?
GPIOPortDirection = DIR_ALL_OUT; // Why is this the only instance that uses a symbol?
WriteCommand(CMD_ALARM | WR);
for (i = 0; i < 2; i++)
WriteData(alarmData[i]);
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = 1;
GPIO_PORT_DATA = SCK_HI;
GPIO_PORT_DATA = SCK_HI;
sLocked = FALSE;
@ -373,10 +386,10 @@ static int WriteCommand(u8 value)
for (i = 0; i < 8; i++)
{
temp = ((value >> (7 - i)) & 1);
GPIO_PORT_DATA = (temp << 1) | 4;
GPIO_PORT_DATA = (temp << 1) | 4;
GPIO_PORT_DATA = (temp << 1) | 4;
GPIO_PORT_DATA = (temp << 1) | 5;
GPIO_PORT_DATA = (temp << 1) | CS_HI;
GPIO_PORT_DATA = (temp << 1) | CS_HI;
GPIO_PORT_DATA = (temp << 1) | CS_HI;
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
}
// control reaches end of non-void function
@ -390,10 +403,10 @@ static int WriteData(u8 value)
for (i = 0; i < 8; i++)
{
temp = ((value >> i) & 1);
GPIO_PORT_DATA = (temp << 1) | 4;
GPIO_PORT_DATA = (temp << 1) | 4;
GPIO_PORT_DATA = (temp << 1) | 4;
GPIO_PORT_DATA = (temp << 1) | 5;
GPIO_PORT_DATA = (temp << 1) | CS_HI;
GPIO_PORT_DATA = (temp << 1) | CS_HI;
GPIO_PORT_DATA = (temp << 1) | CS_HI;
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
}
// control reaches end of non-void function
@ -407,14 +420,14 @@ static u8 ReadData()
for (i = 0; i < 8; i++)
{
GPIO_PORT_DATA = 4;
GPIO_PORT_DATA = 4;
GPIO_PORT_DATA = 4;
GPIO_PORT_DATA = 4;
GPIO_PORT_DATA = 4;
GPIO_PORT_DATA = 5;
GPIO_PORT_DATA = CS_HI;
GPIO_PORT_DATA = CS_HI;
GPIO_PORT_DATA = CS_HI;
GPIO_PORT_DATA = CS_HI;
GPIO_PORT_DATA = CS_HI;
GPIO_PORT_DATA = SCK_HI | CS_HI;
temp = ((GPIO_PORT_DATA & 2) >> 1);
temp = ((GPIO_PORT_DATA & SIO_HI) >> 1);
value = (value >> 1) | (temp << 7); // UB: accessing uninitialized var
}