name STWIStatus.unk_2c

This commit is contained in:
PikalaxALT
2020-01-31 16:57:52 -05:00
parent 88bda9fabd
commit 5ca03c0e32
4 changed files with 28 additions and 25 deletions
+1 -1
View File
@@ -316,7 +316,7 @@ struct STWIStatus
void (*callbackID)(void); void (*callbackID)(void);
union RfuPacket *txPacket; union RfuPacket *txPacket;
union RfuPacket *rxPacket; union RfuPacket *rxPacket;
vu8 unk_2c; vu8 sending;
}; };
// This struct is used as u8 array in SDK. // This struct is used as u8 array in SDK.
+1 -1
View File
@@ -133,7 +133,7 @@ static void sio32intr_clock_master(void)
gSTWIStatus->state = 4; // error gSTWIStatus->state = 4; // error
} }
} }
gSTWIStatus->unk_2c = 0; gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM); Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM);
} }
+4 -4
View File
@@ -1144,11 +1144,11 @@ bool8 rfu_getMasterSlave(void)
if (masterSlave == AGB_CLK_MASTER) if (masterSlave == AGB_CLK_MASTER)
{ {
if (gSTWIStatus->unk_2c) if (gSTWIStatus->sending)
{ {
if (gSTWIStatus->reqActiveCommand == 39 if (gSTWIStatus->reqActiveCommand == ID_MS_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == 37 || gSTWIStatus->reqActiveCommand == ID_DATA_TX_AND_CHANGE_REQ
|| gSTWIStatus->reqActiveCommand == 55) || gSTWIStatus->reqActiveCommand == ID_RESUME_RETRANSMIT_AND_CHANGE_REQ)
masterSlave = AGB_CLK_SLAVE; masterSlave = AGB_CLK_SLAVE;
} }
} }
+22 -19
View File
@@ -39,7 +39,7 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b
gSTWIStatus->timerActive = 0; gSTWIStatus->timerActive = 0;
gSTWIStatus->error = 0; gSTWIStatus->error = 0;
gSTWIStatus->recoveryCount = 0; gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0; gSTWIStatus->sending = 0;
REG_RCNT = 0x100; // TODO: mystery bit? REG_RCNT = 0x100; // TODO: mystery bit?
REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS;
STWI_init_Callback_M(); STWI_init_Callback_M();
@@ -83,7 +83,7 @@ void AgbRFU_SoftReset(void)
gSTWIStatus->error = 0; gSTWIStatus->error = 0;
gSTWIStatus->msMode = AGB_CLK_MASTER; gSTWIStatus->msMode = AGB_CLK_MASTER;
gSTWIStatus->recoveryCount = 0; gSTWIStatus->recoveryCount = 0;
gSTWIStatus->unk_2c = 0; gSTWIStatus->sending = 0;
} }
void STWI_set_MS_mode(u8 mode) void STWI_set_MS_mode(u8 mode)
@@ -136,7 +136,7 @@ void STWI_set_Callback_ID(void (*func)(void)) // name in SDK, but is actually se
u16 STWI_poll_CommandEnd(void) u16 STWI_poll_CommandEnd(void)
{ {
while (gSTWIStatus->unk_2c == TRUE) while (gSTWIStatus->sending == 1)
; ;
return gSTWIStatus->error; return gSTWIStatus->error;
} }
@@ -203,7 +203,6 @@ void STWI_send_GameConfigREQ(const u8 *serial_gname, const u8 *uname)
if (!STWI_init(ID_GAME_CONFIG_REQ)) if (!STWI_init(ID_GAME_CONFIG_REQ))
{ {
gSTWIStatus->reqLength = 6; gSTWIStatus->reqLength = 6;
// TODO: what is unk1
packetBytes = gSTWIStatus->txPacket->rfuPacket8.data; packetBytes = gSTWIStatus->txPacket->rfuPacket8.data;
packetBytes += sizeof(u32); packetBytes += sizeof(u32);
*(u16 *)packetBytes = *(u16 *)serial_gname; *(u16 *)packetBytes = *(u16 *)serial_gname;
@@ -499,20 +498,17 @@ static void STWI_intr_timer(void)
STWI_stop_timer(); STWI_stop_timer();
STWI_reset_ClockCounter(); STWI_reset_ClockCounter();
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(255, 0); gSTWIStatus->callbackM(ID_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA_REQ, 0);
break; break;
} }
} }
static void STWI_set_timer(u8 unk) static void STWI_set_timer(u8 count)
{ {
vu16 *timerL; vu16 *timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
vu16 *timerH; vu16 *timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
timerL = &REG_TMCNT_L(gSTWIStatus->timerSelect);
timerH = &REG_TMCNT_H(gSTWIStatus->timerSelect);
REG_IME = 0; REG_IME = 0;
switch (unk) switch (count)
{ {
case 50: case 50:
*timerL = 0xFCCB; *timerL = 0xFCCB;
@@ -543,25 +539,31 @@ static void STWI_stop_timer(void)
REG_TMCNT_H(gSTWIStatus->timerSelect) = 0; REG_TMCNT_H(gSTWIStatus->timerSelect) = 0;
} }
/*
* Set up STWI to send REQ. Returns 1 if error (see below).
*/
static u16 STWI_init(u8 request) static u16 STWI_init(u8 request)
{ {
if (!REG_IME) if (!REG_IME)
{ {
// Can't start sending if IME is disabled.
gSTWIStatus->error = ERR_REQ_CMD_IME_DISABLE; gSTWIStatus->error = ERR_REQ_CMD_IME_DISABLE;
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error); gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE; return TRUE;
} }
else if (gSTWIStatus->unk_2c == TRUE) else if (gSTWIStatus->sending == 1)
{ {
// Already sending something. Cancel and error.
gSTWIStatus->error = ERR_REQ_CMD_SENDING; gSTWIStatus->error = ERR_REQ_CMD_SENDING;
gSTWIStatus->unk_2c = FALSE; gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error); gSTWIStatus->callbackM(request, gSTWIStatus->error);
return TRUE; return TRUE;
} }
else if(!gSTWIStatus->msMode) else if (gSTWIStatus->msMode == AGB_CLK_SLAVE)
{ {
// Can't send if clock slave
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_SLAVE; gSTWIStatus->error = ERR_REQ_CMD_CLOCK_SLAVE;
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(request, gSTWIStatus->error, gSTWIStatus); gSTWIStatus->callbackM(request, gSTWIStatus->error, gSTWIStatus);
@@ -569,7 +571,8 @@ static u16 STWI_init(u8 request)
} }
else else
{ {
gSTWIStatus->unk_2c = TRUE; // Good to go, start sending
gSTWIStatus->sending = 1;
gSTWIStatus->reqActiveCommand = request; gSTWIStatus->reqActiveCommand = request;
gSTWIStatus->state = 0; // master send req gSTWIStatus->state = 0; // master send req
gSTWIStatus->reqLength = 0; gSTWIStatus->reqLength = 0;
@@ -608,7 +611,7 @@ static s32 STWI_start_Command(void)
static s32 STWI_restart_Command(void) static s32 STWI_restart_Command(void)
{ {
if (gSTWIStatus->recoveryCount <= 1) if (gSTWIStatus->recoveryCount < 2)
{ {
++gSTWIStatus->recoveryCount; ++gSTWIStatus->recoveryCount;
STWI_start_Command(); STWI_start_Command();
@@ -618,14 +621,14 @@ static s32 STWI_restart_Command(void)
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) 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)
{ {
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT; gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0; gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error); gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
} }
else else
{ {
gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT; gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT;
gSTWIStatus->unk_2c = 0; gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error); gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error);
gSTWIStatus->state = 4; // error gSTWIStatus->state = 4; // error