use constants

This commit is contained in:
jiangzhengwenjz
2020-01-10 03:17:00 +08:00
parent f12c1edf3f
commit 0ce29c0ee9
11 changed files with 354 additions and 346 deletions
+166 -167
View File
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -17,10 +17,10 @@ s32 AgbRFU_checkID(u8 r5)
if (REG_IME == 0)
return -1;
r8 = REG_IE;
gRfuState->state = 10;
gSTWIStatus->state = 10;
STWI_set_Callback_ID(Sio32IDIntr);
Sio32IDInit();
r4 = &REG_TMCNT_L(gRfuState->timerSelect);
r4 = &REG_TMCNT_L(gSTWIStatus->timerSelect);
r5 *= 8;
while (--r5 != 0xFF)
{
@@ -38,7 +38,7 @@ s32 AgbRFU_checkID(u8 r5)
REG_IME = 0;
REG_IE = r8;
REG_IME = 1;
gRfuState->state = 0;
gSTWIStatus->state = 0;
STWI_set_Callback_ID(NULL);
return r6;
}
@@ -46,7 +46,7 @@ s32 AgbRFU_checkID(u8 r5)
static void Sio32IDInit(void)
{
REG_IME = 0;
REG_IE &= ~((8 << gRfuState->timerSelect) | INTR_FLAG_SERIAL);
REG_IE &= ~((8 << gSTWIStatus->timerSelect) | INTR_FLAG_SERIAL);
REG_IME = 1;
REG_RCNT = 0;
REG_SIOCNT = SIO_32BIT_MODE;
+146 -144
View File
@@ -8,6 +8,8 @@ static void STWI_stop_timer(void);
static s32 STWI_restart_Command(void);
static s32 STWI_reset_ClockCounter(void);
struct STWIStatus *gSTWIStatus;
void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, bool8 copyInterruptToRam)
{
// If we're copying our interrupt into RAM, DMA it to block1 and use
@@ -17,27 +19,27 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
{
*interrupt = (IntrFunc)interruptStruct->block1;
DmaCopy16(3, &IntrSIO32, interruptStruct->block1, sizeof(interruptStruct->block1));
gRfuState = &interruptStruct->block2;
gSTWIStatus = &interruptStruct->block2;
}
else
{
*interrupt = IntrSIO32;
gRfuState = (struct STWIStatus *)interruptStruct->block1;
gSTWIStatus = (struct STWIStatus *)interruptStruct->block1;
}
gRfuState->rxPacket = &interruptStruct->rxPacketAlloc;
gRfuState->txPacket = &interruptStruct->txPacketAlloc;
gRfuState->msMode = 1;
gRfuState->state = 0;
gRfuState->reqLength = 0;
gRfuState->reqNext = 0;
gRfuState->ackLength = 0;
gRfuState->ackNext = 0;
gRfuState->ackActiveCommand = 0;
gRfuState->timerState = 0;
gRfuState->timerActive = 0;
gRfuState->error = 0;
gRfuState->recoveryCount = 0;
gRfuState->unk_2c = 0;
gSTWIStatus->rxPacket = &interruptStruct->rxPacketAlloc;
gSTWIStatus->txPacket = &interruptStruct->txPacketAlloc;
gSTWIStatus->msMode = 1;
gSTWIStatus->state = 0;
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->ackLength = 0;
gSTWIStatus->ackNext = 0;
gSTWIStatus->ackActiveCommand = 0;
gSTWIStatus->timerState = 0;
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0;
REG_RCNT = 0x100; // TODO: mystery bit?
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
STWI_init_Callback_M();
@@ -48,8 +50,8 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
void STWI_init_timer(IntrFunc *interrupt, s32 timerSelect)
{
*interrupt = STWI_intr_timer;
gRfuState->timerSelect = timerSelect;
IntrEnable(INTR_FLAG_TIMER0 << gRfuState->timerSelect);
gSTWIStatus->timerSelect = timerSelect;
IntrEnable(INTR_FLAG_TIMER0 << gSTWIStatus->timerSelect);
}
void AgbRFU_SoftReset(void)
@@ -59,8 +61,8 @@ void AgbRFU_SoftReset(void)
REG_RCNT = 0x8000;
REG_RCNT = 0x80A0; // all these bits are undocumented
timerL = &REG_TMCNT_L(gRfuState->timerSelect);
timerH = &REG_TMCNT_H(gRfuState->timerSelect);
timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
*timerH = 0;
*timerL = 0;
*timerH = TIMER_ENABLE | TIMER_1024CLK;
@@ -69,24 +71,24 @@ void AgbRFU_SoftReset(void)
*timerH = 3;
REG_RCNT = 0x80A0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
gRfuState->state = 0;
gRfuState->reqLength = 0;
gRfuState->reqNext = 0;
gRfuState->reqActiveCommand = 0;
gRfuState->ackLength = 0;
gRfuState->ackNext = 0;
gRfuState->ackActiveCommand = 0;
gRfuState->timerState = 0;
gRfuState->timerActive = 0;
gRfuState->error = 0;
gRfuState->msMode = 1;
gRfuState->recoveryCount = 0;
gRfuState->unk_2c = 0;
gSTWIStatus->state = 0;
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->reqActiveCommand = 0;
gSTWIStatus->ackLength = 0;
gSTWIStatus->ackNext = 0;
gSTWIStatus->ackActiveCommand = 0;
gSTWIStatus->timerState = 0;
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->msMode = 1;
gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0;
}
void STWI_set_MS_mode(u8 mode)
{
gRfuState->msMode = mode;
gSTWIStatus->msMode = mode;
}
u16 STWI_read_status(u8 index)
@@ -94,13 +96,13 @@ u16 STWI_read_status(u8 index)
switch (index)
{
case 0:
return gRfuState->error;
return gSTWIStatus->error;
case 1:
return gRfuState->msMode;
return gSTWIStatus->msMode;
case 2:
return gRfuState->state;
return gSTWIStatus->state;
case 3:
return gRfuState->reqActiveCommand;
return gSTWIStatus->reqActiveCommand;
default:
return 0xFFFF;
}
@@ -119,31 +121,31 @@ void STWI_init_Callback_S(void)
// The callback can take 2 or 3 arguments.
void STWI_set_Callback_M(void *callbackM)
{
gRfuState->callbackM = callbackM;
gSTWIStatus->callbackM = callbackM;
}
void STWI_set_Callback_S(void (*callbackS)(u16))
{
gRfuState->callbackS = callbackS;
gSTWIStatus->callbackS = callbackS;
}
void STWI_set_Callback_ID(void (*func)(void)) // name in SDK, but is actually setting a function pointer
{
gRfuState->unk_20 = func;
gSTWIStatus->unk_20 = func;
}
u16 STWI_poll_CommandEnd(void)
{
while (gRfuState->unk_2c == TRUE)
while (gSTWIStatus->unk_2c == TRUE)
;
return gRfuState->error;
return gSTWIStatus->error;
}
void STWI_send_ResetREQ(void)
{
if (!STWI_init(ID_RESET_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -152,7 +154,7 @@ void STWI_send_LinkStatusREQ(void)
{
if (!STWI_init(ID_LINK_STATUS_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -161,7 +163,7 @@ void STWI_send_VersionStatusREQ(void)
{
if (!STWI_init(ID_VERSION_STATUS_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -170,7 +172,7 @@ void STWI_send_SystemStatusREQ(void)
{
if (!STWI_init(ID_SYSTEM_STATUS_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -179,7 +181,7 @@ void STWI_send_SlotStatusREQ(void)
{
if (!STWI_init(ID_SLOT_STATUS_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -188,7 +190,7 @@ void STWI_send_ConfigStatusREQ(void)
{
if (!STWI_init(ID_CONFIG_STATUS_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -200,9 +202,9 @@ void STWI_send_GameConfigREQ(const u8 *unk1, const u8 *data)
if (!STWI_init(ID_GAME_CONFIG_REQ))
{
gRfuState->reqLength = 6;
gSTWIStatus->reqLength = 6;
// TODO: what is unk1
packetBytes = gRfuState->txPacket->rfuPacket8.data;
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*(u16 *)packetBytes = *(u16 *)unk1;
packetBytes += sizeof(u16);
@@ -229,8 +231,8 @@ void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3)
{
u8 *packetBytes;
gRfuState->reqLength = 1;
packetBytes = gRfuState->txPacket->rfuPacket8.data;
gSTWIStatus->reqLength = 1;
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*packetBytes++ = unk3;
*packetBytes++ = unk2;
@@ -243,7 +245,7 @@ void STWI_send_SC_StartREQ(void)
{
if (!STWI_init(ID_SC_START_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -252,7 +254,7 @@ void STWI_send_SC_PollingREQ(void)
{
if (!STWI_init(ID_SC_POLL_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -261,7 +263,7 @@ void STWI_send_SC_EndREQ(void)
{
if (!STWI_init(ID_SC_END_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -270,7 +272,7 @@ void STWI_send_SP_StartREQ(void)
{
if (!STWI_init(ID_SP_START_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -279,7 +281,7 @@ void STWI_send_SP_PollingREQ(void)
{
if (!STWI_init(ID_SP_POLL_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -288,7 +290,7 @@ void STWI_send_SP_EndREQ(void)
{
if (!STWI_init(ID_SP_END_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -297,8 +299,8 @@ void STWI_send_CP_StartREQ(u16 unk1)
{
if (!STWI_init(ID_CP_START_REQ))
{
gRfuState->reqLength = 1;
gRfuState->txPacket->rfuPacket32.data[0] = unk1;
gSTWIStatus->reqLength = 1;
gSTWIStatus->txPacket->rfuPacket32.data[0] = unk1;
STWI_start_Command();
}
}
@@ -307,7 +309,7 @@ void STWI_send_CP_PollingREQ(void)
{
if (!STWI_init(ID_CP_POLL_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -316,7 +318,7 @@ void STWI_send_CP_EndREQ(void)
{
if (!STWI_init(ID_CP_END_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -328,8 +330,8 @@ void STWI_send_DataTxREQ(const void *in, u8 size)
u8 reqLength = (size / sizeof(u32));
if (size & (sizeof(u32) - 1))
reqLength += 1;
gRfuState->reqLength = reqLength;
CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->reqLength * sizeof(u32));
gSTWIStatus->reqLength = reqLength;
CpuCopy32(in, gSTWIStatus->txPacket->rfuPacket32.data, gSTWIStatus->reqLength * sizeof(u32));
STWI_start_Command();
}
}
@@ -341,8 +343,8 @@ void STWI_send_DataTxAndChangeREQ(const void *in, u8 size)
u8 reqLength = (size / sizeof(u32));
if (size & (sizeof(u32) - 1))
reqLength += 1;
gRfuState->reqLength = reqLength;
CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->reqLength * sizeof(u32));
gSTWIStatus->reqLength = reqLength;
CpuCopy32(in, gSTWIStatus->txPacket->rfuPacket32.data, gSTWIStatus->reqLength * sizeof(u32));
STWI_start_Command();
}
}
@@ -351,7 +353,7 @@ void STWI_send_DataRxREQ(void)
{
if (!STWI_init(ID_DATA_RX_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -360,7 +362,7 @@ void STWI_send_MS_ChangeREQ(void)
{
if (!STWI_init(ID_MS_CHANGE_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -371,14 +373,14 @@ void STWI_send_DataReadyAndChangeREQ(u8 unk)
{
if (!unk)
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
}
else
{
u8 *packetBytes;
gRfuState->reqLength = 1;
packetBytes = gRfuState->txPacket->rfuPacket8.data;
gSTWIStatus->reqLength = 1;
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*packetBytes++ = unk;
*packetBytes++ = 0;
@@ -395,8 +397,8 @@ void STWI_send_DisconnectedAndChangeREQ(u8 unk0, u8 unk1)
{
u8 *packetBytes;
gRfuState->reqLength = 1;
packetBytes = gRfuState->txPacket->rfuPacket8.data;
gSTWIStatus->reqLength = 1;
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32);
*packetBytes++ = unk0;
*packetBytes++ = unk1;
@@ -410,7 +412,7 @@ void STWI_send_ResumeRetransmitAndChangeREQ(void)
{
if (!STWI_init(ID_RESUME_RETRANSMIT_AND_CHANGE_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -419,8 +421,8 @@ void STWI_send_DisconnectREQ(u8 unk)
{
if (!STWI_init(ID_DISCONNECT_REQ))
{
gRfuState->reqLength = 1;
gRfuState->txPacket->rfuPacket32.data[0] = unk;
gSTWIStatus->reqLength = 1;
gSTWIStatus->txPacket->rfuPacket32.data[0] = unk;
STWI_start_Command();
}
}
@@ -429,8 +431,8 @@ void STWI_send_TestModeREQ(u8 unk0, u8 unk1)
{
if (!STWI_init(ID_TEST_MODE_REQ))
{
gRfuState->reqLength = 1;
gRfuState->txPacket->rfuPacket32.data[0] = unk0 | (unk1 << 8);
gSTWIStatus->reqLength = 1;
gSTWIStatus->txPacket->rfuPacket32.data[0] = unk0 | (unk1 << 8);
STWI_start_Command();
}
}
@@ -442,9 +444,9 @@ void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2)
if (!STWI_init(ID_CPR_START_REQ))
{
gRfuState->reqLength = 2;
gSTWIStatus->reqLength = 2;
arg1 = unk1 | (unk0 << 16);
packetData = gRfuState->txPacket->rfuPacket32.data;
packetData = gSTWIStatus->txPacket->rfuPacket32.data;
packetData[0] = arg1;
packetData[1] = unk2;
STWI_start_Command();
@@ -455,7 +457,7 @@ void STWI_send_CPR_PollingREQ(void)
{
if (!STWI_init(ID_CPR_POLL_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -464,7 +466,7 @@ void STWI_send_CPR_EndREQ(void)
{
if (!STWI_init(ID_CPR_END_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
@@ -473,18 +475,18 @@ void STWI_send_StopModeREQ(void)
{
if (!STWI_init(ID_STOP_MODE_REQ))
{
gRfuState->reqLength = 0;
gSTWIStatus->reqLength = 0;
STWI_start_Command();
}
}
static void STWI_intr_timer(void)
{
switch (gRfuState->timerState)
switch (gSTWIStatus->timerState)
{
// TODO: Make an enum for these
case 2:
gRfuState->timerActive = 1;
gSTWIStatus->timerActive = 1;
STWI_set_timer(50);
break;
case 1:
@@ -493,11 +495,11 @@ static void STWI_intr_timer(void)
STWI_restart_Command();
break;
case 3:
gRfuState->timerActive = 1;
gSTWIStatus->timerActive = 1;
STWI_stop_timer();
STWI_reset_ClockCounter();
if (gRfuState->callbackM != NULL)
gRfuState->callbackM(255, 0);
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(255, 0);
break;
}
}
@@ -507,78 +509,78 @@ static void STWI_set_timer(u8 unk)
vu16 *timerL;
vu16 *timerH;
timerL = &REG_TMCNT_L(gRfuState->timerSelect);
timerH = &REG_TMCNT_H(gRfuState->timerSelect);
timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
REG_IME = 0;
switch (unk)
{
case 50:
*timerL = 0xFCCB;
gRfuState->timerState = 1;
gSTWIStatus->timerState = 1;
break;
case 80:
*timerL = 0xFAE0;
gRfuState->timerState = 2;
gSTWIStatus->timerState = 2;
break;
case 100:
*timerL = 0xF996;
gRfuState->timerState = 3;
gSTWIStatus->timerState = 3;
break;
case 130:
*timerL = 0xF7AD;
gRfuState->timerState = 4;
gSTWIStatus->timerState = 4;
break;
}
*timerH = TIMER_ENABLE | TIMER_INTR_ENABLE | TIMER_1024CLK;
REG_IF = INTR_FLAG_TIMER0 << gRfuState->timerSelect;
REG_IF = INTR_FLAG_TIMER0 << gSTWIStatus->timerSelect;
REG_IME = 1;
}
static void STWI_stop_timer(void)
{
gRfuState->timerState = 0;
REG_TMCNT_L(gRfuState->timerSelect) = 0;
REG_TMCNT_H(gRfuState->timerSelect) = 0;
gSTWIStatus->timerState = 0;
REG_TMCNT_L(gSTWIStatus->timerSelect) = 0;
REG_TMCNT_H(gSTWIStatus->timerSelect) = 0;
}
static u16 STWI_init(u8 request)
{
if (!REG_IME)
{
gRfuState->error = 6;
if (gRfuState->callbackM != NULL)
gRfuState->callbackM(request, gRfuState->error);
gSTWIStatus->error = ERR_REQ_CMD_IME_DISABLE;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE;
}
else if (gRfuState->unk_2c == TRUE)
else if (gSTWIStatus->unk_2c == TRUE)
{
gRfuState->error = 2;
gRfuState->unk_2c = FALSE;
if (gRfuState->callbackM != NULL)
gRfuState->callbackM(request, gRfuState->error);
gSTWIStatus->error = ERR_REQ_CMD_SENDING;
gSTWIStatus->unk_2c = FALSE;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE;
}
else if(!gRfuState->msMode)
else if(!gSTWIStatus->msMode)
{
gRfuState->error = 4;
if (gRfuState->callbackM != NULL)
gRfuState->callbackM(request, gRfuState->error, gRfuState);
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_SLAVE;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error, gSTWIStatus);
return TRUE;
}
else
{
gRfuState->unk_2c = TRUE;
gRfuState->reqActiveCommand = request;
gRfuState->state = 0;
gRfuState->reqLength = 0;
gRfuState->reqNext = 0;
gRfuState->ackLength = 0;
gRfuState->ackNext = 0;
gRfuState->ackActiveCommand = 0;
gRfuState->timerState = 0;
gRfuState->timerActive = 0;
gRfuState->error = 0;
gRfuState->recoveryCount = 0;
gSTWIStatus->unk_2c = TRUE;
gSTWIStatus->reqActiveCommand = request;
gSTWIStatus->state = 0;
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
gSTWIStatus->ackLength = 0;
gSTWIStatus->ackNext = 0;
gSTWIStatus->ackActiveCommand = 0;
gSTWIStatus->timerState = 0;
gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0;
gSTWIStatus->recoveryCount = 0;
REG_RCNT = 0x100;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
return FALSE;
@@ -589,15 +591,15 @@ static s32 STWI_start_Command(void)
{
u16 imeTemp;
// equivalent to gRfuState->txPacket->rfuPacket32.command,
// equivalent to gSTWIStatus->txPacket->rfuPacket32.command,
// but the cast here is required to avoid register issue
*(u32 *)gRfuState->txPacket->rfuPacket8.data = 0x99660000 | (gRfuState->reqLength << 8) | gRfuState->reqActiveCommand;
REG_SIODATA32 = gRfuState->txPacket->rfuPacket32.command;
gRfuState->state = 0;
gRfuState->reqNext = 1;
*(u32 *)gSTWIStatus->txPacket->rfuPacket8.data = 0x99660000 | (gSTWIStatus->reqLength << 8) | gSTWIStatus->reqActiveCommand;
REG_SIODATA32 = gSTWIStatus->txPacket->rfuPacket32.command;
gSTWIStatus->state = 0;
gSTWIStatus->reqNext = 1;
imeTemp = REG_IME;
REG_IME = 0;
REG_IE |= (INTR_FLAG_TIMER0 << gRfuState->timerSelect);
REG_IE |= (INTR_FLAG_TIMER0 << gSTWIStatus->timerSelect);
REG_IE |= INTR_FLAG_SERIAL;
REG_IME = imeTemp;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_MULTI_BUSY | SIO_115200_BPS;
@@ -606,27 +608,27 @@ static s32 STWI_start_Command(void)
static s32 STWI_restart_Command(void)
{
if (gRfuState->recoveryCount <= 1)
if (gSTWIStatus->recoveryCount <= 1)
{
++gRfuState->recoveryCount;
++gSTWIStatus->recoveryCount;
STWI_start_Command();
}
else
{
if (gRfuState->reqActiveCommand == ID_MS_CHANGE_REQ || gRfuState->reqActiveCommand == ID_DATA_TX_AND_CHANGE_REQ || gRfuState->reqActiveCommand == ID_UNK35_REQ || gRfuState->reqActiveCommand == ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
if (gSTWIStatus->reqActiveCommand == ID_MS_CHANGE_REQ || gSTWIStatus->reqActiveCommand == ID_DATA_TX_AND_CHANGE_REQ || gSTWIStatus->reqActiveCommand == ID_UNK35_REQ || gSTWIStatus->reqActiveCommand == ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
{
gRfuState->error = 1;
gRfuState->unk_2c = 0;
if (gRfuState->callbackM != NULL)
gRfuState->callbackM(gRfuState->reqActiveCommand, gRfuState->error);
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
}
else
{
gRfuState->error = 1;
gRfuState->unk_2c = 0;
if (gRfuState->callbackM != NULL)
gRfuState->callbackM(gRfuState->reqActiveCommand, gRfuState->error);
gRfuState->state = 4; // TODO: what's 4
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0;
if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
gSTWIStatus->state = 4; // TODO: what's 4
}
}
return 0;
@@ -634,9 +636,9 @@ static s32 STWI_restart_Command(void)
static s32 STWI_reset_ClockCounter(void)
{
gRfuState->state = 5; // TODO: what is 5
gRfuState->reqLength = 0;
gRfuState->reqNext = 0;
gSTWIStatus->state = 5; // TODO: what is 5
gSTWIStatus->reqLength = 0;
gSTWIStatus->reqNext = 0;
REG_SIODATA32 = (1 << 31);
REG_SIOCNT = 0;
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;