diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-01-31 16:57:52 -0500 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-01-31 16:57:52 -0500 |
commit | 5ca03c0e32a723f9551b93e5aceb7b39d8ea10e6 (patch) | |
tree | a7372a18a8910936c26f6fd680d266652800f748 /src | |
parent | 88bda9fabd069ed281d845568b7d3c748bdea0e4 (diff) |
name STWIStatus.unk_2c
Diffstat (limited to 'src')
-rw-r--r-- | src/librfu_intr.c | 2 | ||||
-rw-r--r-- | src/librfu_rfu.c | 8 | ||||
-rw-r--r-- | src/librfu_stwi.c | 41 |
3 files changed, 27 insertions, 24 deletions
diff --git a/src/librfu_intr.c b/src/librfu_intr.c index 804658b77..23962a937 100644 --- a/src/librfu_intr.c +++ b/src/librfu_intr.c @@ -133,7 +133,7 @@ static void sio32intr_clock_master(void) gSTWIStatus->state = 4; // error } } - gSTWIStatus->unk_2c = 0; + gSTWIStatus->sending = 0; if (gSTWIStatus->callbackM != NULL) Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM); } diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 7aee90005..4016ee7e3 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -1144,11 +1144,11 @@ bool8 rfu_getMasterSlave(void) if (masterSlave == AGB_CLK_MASTER) { - if (gSTWIStatus->unk_2c) + if (gSTWIStatus->sending) { - if (gSTWIStatus->reqActiveCommand == 39 - || gSTWIStatus->reqActiveCommand == 37 - || gSTWIStatus->reqActiveCommand == 55) + if (gSTWIStatus->reqActiveCommand == ID_MS_CHANGE_REQ + || gSTWIStatus->reqActiveCommand == ID_DATA_TX_AND_CHANGE_REQ + || gSTWIStatus->reqActiveCommand == ID_RESUME_RETRANSMIT_AND_CHANGE_REQ) masterSlave = AGB_CLK_SLAVE; } } diff --git a/src/librfu_stwi.c b/src/librfu_stwi.c index 5e246c3fe..0287b358a 100644 --- a/src/librfu_stwi.c +++ b/src/librfu_stwi.c @@ -39,7 +39,7 @@ void STWI_init_all(struct RfuIntrStruct *interruptStruct, IntrFunc *interrupt, b gSTWIStatus->timerActive = 0; gSTWIStatus->error = 0; gSTWIStatus->recoveryCount = 0; - gSTWIStatus->unk_2c = 0; + gSTWIStatus->sending = 0; REG_RCNT = 0x100; // TODO: mystery bit? REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; STWI_init_Callback_M(); @@ -83,7 +83,7 @@ void AgbRFU_SoftReset(void) gSTWIStatus->error = 0; gSTWIStatus->msMode = AGB_CLK_MASTER; gSTWIStatus->recoveryCount = 0; - gSTWIStatus->unk_2c = 0; + gSTWIStatus->sending = 0; } 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) { - while (gSTWIStatus->unk_2c == TRUE) + while (gSTWIStatus->sending == 1) ; 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)) { gSTWIStatus->reqLength = 6; - // TODO: what is unk1 packetBytes = gSTWIStatus->txPacket->rfuPacket8.data; packetBytes += sizeof(u32); *(u16 *)packetBytes = *(u16 *)serial_gname; @@ -499,20 +498,17 @@ static void STWI_intr_timer(void) STWI_stop_timer(); STWI_reset_ClockCounter(); if (gSTWIStatus->callbackM != NULL) - gSTWIStatus->callbackM(255, 0); + gSTWIStatus->callbackM(ID_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA_REQ, 0); break; } } -static void STWI_set_timer(u8 unk) +static void STWI_set_timer(u8 count) { - vu16 *timerL; - vu16 *timerH; - - timerL = ®_TMCNT_L(gSTWIStatus->timerSelect); - timerH = ®_TMCNT_H(gSTWIStatus->timerSelect); + vu16 *timerL = ®_TMCNT_L(gSTWIStatus->timerSelect); + vu16 *timerH = ®_TMCNT_H(gSTWIStatus->timerSelect); REG_IME = 0; - switch (unk) + switch (count) { case 50: *timerL = 0xFCCB; @@ -543,25 +539,31 @@ static void STWI_stop_timer(void) REG_TMCNT_H(gSTWIStatus->timerSelect) = 0; } +/* + * Set up STWI to send REQ. Returns 1 if error (see below). + */ static u16 STWI_init(u8 request) { if (!REG_IME) { + // Can't start sending if IME is disabled. gSTWIStatus->error = ERR_REQ_CMD_IME_DISABLE; if (gSTWIStatus->callbackM != NULL) gSTWIStatus->callbackM(request, gSTWIStatus->error); 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->unk_2c = FALSE; + gSTWIStatus->sending = 0; if (gSTWIStatus->callbackM != NULL) gSTWIStatus->callbackM(request, gSTWIStatus->error); 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; if (gSTWIStatus->callbackM != NULL) gSTWIStatus->callbackM(request, gSTWIStatus->error, gSTWIStatus); @@ -569,7 +571,8 @@ static u16 STWI_init(u8 request) } else { - gSTWIStatus->unk_2c = TRUE; + // Good to go, start sending + gSTWIStatus->sending = 1; gSTWIStatus->reqActiveCommand = request; gSTWIStatus->state = 0; // master send req gSTWIStatus->reqLength = 0; @@ -608,7 +611,7 @@ static s32 STWI_start_Command(void) static s32 STWI_restart_Command(void) { - if (gSTWIStatus->recoveryCount <= 1) + if (gSTWIStatus->recoveryCount < 2) { ++gSTWIStatus->recoveryCount; 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) { gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT; - gSTWIStatus->unk_2c = 0; + gSTWIStatus->sending = 0; if (gSTWIStatus->callbackM != NULL) gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error); } else { gSTWIStatus->error = ERR_REQ_CMD_CLOCK_DRIFT; - gSTWIStatus->unk_2c = 0; + gSTWIStatus->sending = 0; if (gSTWIStatus->callbackM != NULL) gSTWIStatus->callbackM(gSTWIStatus->reqActiveCommand, gSTWIStatus->error); gSTWIStatus->state = 4; // error |