diff --git a/.cproject b/.cproject index 23d9a73..8f85a2c 100644 --- a/.cproject +++ b/.cproject @@ -644,7 +644,7 @@ mingw32-make.exe - -s -j 4 + -s -j 2 all true false diff --git a/USDK/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c b/USDK/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c index 8e05b4b..59ae1d7 100644 --- a/USDK/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c +++ b/USDK/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c @@ -235,6 +235,7 @@ s8 sdio_sd_init(void) { } sdio_status = SDIO_SD_OK; if (HalSdioHostOp.HalSdioHostChangeSdClock(&SdioHostAdapter, +// SD_CLK_20_8MHZ) != HAL_OK) SD_CLK_41_6MHZ) != HAL_OK) DBG_SDIO_INFO("SD card does not support high speed.\n"); } @@ -259,7 +260,7 @@ s8 sdio_sd_setClock(SD_CLK_FREQUENCY SDCLK) { DBG_SDIO_ERR("Malloc ADMA2 table fail.\n"); return -1; } - DBG_SDIO_INFO("SD card set CLK %d Hz\n", PLATFORM_CLOCK/(4<<(SD_CLK_41_6MHZ-SDCLK))); + DBG_SDIO_INFO("SD card set CLK %d Hz\n", PLATFORM_CLOCK/(2 << (SD_CLK_41_6MHZ - SDCLK))); sta = HalSdioHostOp.HalSdioHostChangeSdClock(&SdioHostAdapter, SDCLK); rtw_mfree(padma, sizeof(ADMA2_DESC_FMT)); if (sta) diff --git a/USDK/component/common/file_system/fatfs/disk_if/inc/sdcard.h b/USDK/component/common/file_system/fatfs/disk_if/inc/sdcard.h index a9ed1d8..e4340f9 100644 --- a/USDK/component/common/file_system/fatfs/disk_if/inc/sdcard.h +++ b/USDK/component/common/file_system/fatfs/disk_if/inc/sdcard.h @@ -1,6 +1,6 @@ #ifndef _SDCARD_H_ #define _SDCARD_H_ -#include "fatfs_ext/inc/ff_driver.h" +#include "ff_driver.h" extern ll_diskio_drv SD_disk_Driver; #endif diff --git a/USDK/component/common/file_system/fatfs/disk_if/inc/usbdisk.h b/USDK/component/common/file_system/fatfs/disk_if/inc/usbdisk.h index 023616b..0bd79a6 100644 --- a/USDK/component/common/file_system/fatfs/disk_if/inc/usbdisk.h +++ b/USDK/component/common/file_system/fatfs/disk_if/inc/usbdisk.h @@ -1,7 +1,7 @@ #ifndef _USBDISK_H_ #define _USBDISK_H_ -#include "fatfs_ext/inc/ff_driver.h" +#include "ff_driver.h" extern ll_diskio_drv USB_disk_Driver; #endif diff --git a/USDK/component/soc/realtek/8195a/fwlib/bitband_io.h b/USDK/component/soc/realtek/8195a/fwlib/bitband_io.h index 3fb4c60..45d75c3 100644 --- a/USDK/component/soc/realtek/8195a/fwlib/bitband_io.h +++ b/USDK/component/soc/realtek/8195a/fwlib/bitband_io.h @@ -1,6 +1,7 @@ #ifndef _BITBAND_IO_H_ #define _BITBAND_IO_H_ +#include "PinNames.h" #include "hal_platform.h" #include "hal_api.h" #include "hal_gpio.h" @@ -143,4 +144,10 @@ #define BITBAND_K5 ucBITBAND_PERI(GPIO_REG_BASE+GPIO_PORTC_DR,25) //Port = 2, bit = 25, K5 #define BITBAND_K6 ucBITBAND_PERI(GPIO_REG_BASE+GPIO_PORTC_DR,26) //Port = 2, bit = 26, K6 +volatile uint8_t * BitBandAddr(void *addr, uint8_t bit); +volatile uint8_t * BitBandPeriAddr(void *addr, uint8_t bit); +volatile uint8_t * GetOutPinBitBandAddr(PinName pin); +volatile uint8_t * GetInPinBitBandAddr(PinName pin); +volatile uint8_t * HardSetPin(PinName pin, HAL_GPIO_PIN_MODE pmode, uint8_t val); + #endif // _BITBAND_IO_H_ diff --git a/USDK/component/soc/realtek/8195a/fwlib/hal_sdio_host.h b/USDK/component/soc/realtek/8195a/fwlib/hal_sdio_host.h index f4f3106..1603e31 100644 --- a/USDK/component/soc/realtek/8195a/fwlib/hal_sdio_host.h +++ b/USDK/component/soc/realtek/8195a/fwlib/hal_sdio_host.h @@ -46,24 +46,24 @@ typedef enum _SDIO_XFER_TYPE_{ }SDIO_XFER_TYPE; typedef struct _HAL_SDIO_HOST_ADAPTER_{ - IRQ_HANDLE IrqHandle; //+0..6(u32) Irq Handler - ADMA2_DESC_FMT *AdmaDescTbl; //+7(u32) - u32 Response[4]; //+8..11(u32) - u32 CardOCR; //+12 - u32 CardStatus; //+13 - u32 IsWriteProtect; //+14 - u8 SdStatus[SD_STATUS_LEN]; //+15.. - u8 Csd[CSD_REG_LEN]; //+31 - volatile u8 CmdCompleteFlg; //+128(u8) - volatile u8 XferCompleteFlg; //+129(u8) - volatile u8 ErrIntFlg; - volatile u8 CardCurState; - u8 IsSdhc; - u8 CurrSdClk; //+133? - u16 RCA; - u16 SdSpecVer; - SDIO_ERR_TYPE errType; - SDIO_XFER_TYPE XferType; + IRQ_HANDLE IrqHandle; //+0.. + ADMA2_DESC_FMT *AdmaDescTbl; //+16 + u32 Response[4]; //+20,24,28,32 + u32 CardOCR; //+36 + u32 CardStatus; //+40 + u32 IsWriteProtect; //+44 + u8 SdStatus[SD_STATUS_LEN]; //+48.. + u8 Csd[CSD_REG_LEN]; //+112.. + volatile u8 CmdCompleteFlg; //+128 + volatile u8 XferCompleteFlg; //+129 + volatile u8 ErrIntFlg; //+130 + volatile u8 CardCurState; //+131 + u8 IsSdhc; //+132 + u8 CurrSdClk; //+133 + u16 RCA; //+134 + u16 SdSpecVer; //+136 + SDIO_ERR_TYPE errType; //+140 + SDIO_XFER_TYPE XferType; //+144 VOID (*XferCompCallback)(VOID *pAdapter); VOID *XferCompCbPara; VOID (*ErrorCallback)(VOID *pAdapter); diff --git a/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio_host.h b/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio_host.h index 7b3039e..82d3f26 100644 --- a/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio_host.h +++ b/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio_host.h @@ -425,14 +425,14 @@ typedef struct _ADMA2_DESC_FMT_ /* 0x0E */ typedef struct _SDIO_HOST_CMD_FMT_ { - u16 RespType:2; - u16 Rsvd0:1; - u16 CmdCrcChkEn:1; - u16 CmdIdxChkEn:1; - u16 DataPresent:1; - u16 CmdType:2; - u16 CmdIdx:6; - u16 Rsvd1:2; + u16 RespType:2; //bit:0..1 + u16 Rsvd0:1; //bit:2 + u16 CmdCrcChkEn:1; //bit:3 + u16 CmdIdxChkEn:1; //bit:4 + u16 DataPresent:1; //bit:5 + u16 CmdType:2; //bit:6..7 + u16 CmdIdx:6; //bit:8..13 + u16 Rsvd1:2; //bit:14..15 }SDIO_HOST_CMD_FMT, *PSDIO_HOST_CMD_FMT; typedef struct _SDIO_HOST_CMD_ diff --git a/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_sdio_host.c b/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_sdio_host.c index 318be6e..31b22a0 100644 --- a/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_sdio_host.c +++ b/USDK/component/soc/realtek/8195a/fwlib/rtl8195a/src/rtl8195a_sdio_host.c @@ -1,6 +1,7 @@ /* */ #include "rtl8195a.h" +#include "hal_sdio_host.h" #include "rtl8195a_sdio_host.h" //------------------------------------------------------------------------- // Function declarations @@ -11,7 +12,7 @@ void SdioHostSdBusPwrCtrl(uint8_t En, int a2); int SdioHostSdClkCtrl(void *Data, int En, int Divisor); int SdioHostChkDataLineActive(uint32_t Timeout); - int SdioHostChkCmdInhibitCMD(uint32_t Timeout); + int SdioHostChkCmdInhibitCMD(void); //uint32_t Timeout); int SdioHostChkCmdInhibitDAT(uint32_t Timeout); uint32_t SdioHostIsrHandle(void *Data); int HalSdioHostDeInitRtl8195a(void *Data); @@ -69,15 +70,13 @@ HAL_Status SdioHostIsTimeout(u32 StartCount, u32 TimeoutCnt) { //----- SdioHostSendCmd(PSDIO_HOST_CMD) void SdioHostSendCmd(PSDIO_HOST_CMD Cmd) { - u16 reg_cmd = ((*(u8 *) &Cmd->CmdFmt & 0x3B) | (*(u8 *) &Cmd->CmdFmt & 0xC0) - | ((*((u8 *) &Cmd->CmdFmt + 1) & 0x3F) << 8)); HAL_SDIOH_REG32(REG_SDIO_HOST_ARG) = Cmd->Arg; // 40058008 = Cmd->Arg - HAL_SDIOH_REG16(REG_SDIO_HOST_CMD) = reg_cmd; // 4005800E = reg_cmd + HAL_SDIOH_REG16(REG_SDIO_HOST_CMD) = *(u16 *) &Cmd->CmdFmt; // & 0x3FFB; } //----- HAL_Status SdioHostGetResponse(void *Data, int RspType) { - PHAL_SDIO_HOST_ADAPTER psha = Data; + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; HAL_Status result; if (psha) { @@ -115,7 +114,7 @@ void SdioHostSdBusPwrCtrl(void) { //----- HAL_Status SdioHostSdClkCtrl(void *Data, int En, u8 Divisor) { // SD_CLK_DIVISOR - PHAL_SDIO_HOST_ADAPTER psha = Data; // u8 *v3; // r3@1 v3 = Data; + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; if (HAL_SDIOH_REG32(REG_SDIO_HOST_PRESENT_STATE) & (PRES_STATE_CMD_INHIBIT_CMD | PRES_STATE_CMD_INHIBIT_DAT)) { return HAL_BUSY; @@ -163,131 +162,52 @@ HAL_Status SdioHostSdClkCtrl(void *Data, int En, u8 Divisor) { // SD_CLK_DIVISOR return HAL_OK; } -//----- SdioHostChkDataLineActive(uint32_t Timeout) -HAL_Status SdioHostChkDataLineActive(uint32_t Timeout) { +#define SD_CHK_TIMEOUT 3225 + +//----- SdioHostChkDataLineActive +HAL_Status SdioHostChkDataLineActive(void) { HAL_Status result; u32 t1 = HalTimerOp.HalTimerReadCount(1); do { if ((HAL_SDIOH_REG32(REG_SDIO_HOST_PRESENT_STATE) & PRES_STATE_DAT_LINE_ACTIVE) == 0) break; - result = SdioHostIsTimeout(t1, 3225); + result = SdioHostIsTimeout(t1, SD_CHK_TIMEOUT); } while (result != HAL_TIMEOUT); return result; } -//----- SdioHostChkCmdInhibitCMD(uint32_t Timeout) -HAL_Status SdioHostChkCmdInhibitCMD(uint32_t Timeout) { +//----- SdioHostChkCmdInhibitCMD +HAL_Status SdioHostChkCmdInhibitCMD(void) { HAL_Status result; u32 t1 = HalTimerOp.HalTimerReadCount(1); do { if ((HAL_SDIOH_REG32(REG_SDIO_HOST_PRESENT_STATE) & PRES_STATE_CMD_INHIBIT_CMD) == 0) break; - result = SdioHostIsTimeout(t1, 3225); + result = SdioHostIsTimeout(t1, SD_CHK_TIMEOUT); } while (result != HAL_TIMEOUT); return result; } -//----- SdioHostChkCmdInhibitDAT(uint32_t Timeout) -int SdioHostChkCmdInhibitDAT(uint32_t Timeout) { +//----- SdioHostChkCmdInhibitDAT +int SdioHostChkCmdInhibitDAT(void) { HAL_Status result; u32 t1 = HalTimerOp.HalTimerReadCount(1); do { if ((HAL_SDIOH_REG32(REG_SDIO_HOST_PRESENT_STATE) & PRES_STATE_CMD_INHIBIT_DAT) == 0) break; - result = SdioHostIsTimeout(t1, 3225); + result = SdioHostIsTimeout(t1, SD_CHK_TIMEOUT); } while (result != HAL_TIMEOUT); return result; } -//----- (0000028C) -------------------------------------------------------- -void SdioHostIsrHandle(void *Data) { - PHAL_SDIO_HOST_ADAPTER psha = Data; - u16 status = HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS);// v40058030; - - HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_SIG_EN) = 0; - if (status) { - if (status & NOR_INT_STAT_CMD_COMP) - psha->CmdCompleteFlg = 1; - if (status & NOR_INT_STAT_XFER_COMP) { - psha->XferCompleteFlg = 1; - if ((status & NOR_INT_STAT_ERR_INT) == 0) { - if (psha->XferCompCallback) - psha->XferCompCallback(psha->XferCompCbPara); - - } else if (HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS) & - ( ERR_INT_STAT_DATA_TIMEOUT - | ERR_INT_STAT_DATA_CRC - | ERR_INT_STAT_DATA_END_BIT)) { -/* - DBG_SDIO_ERR("\r[SDIO Err]XFER CP with ErrIntVal: 0x%04X /0x%04X -- TYPE 0x%02X\n", - status, - HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS), - psha->CmdCompleteFlg?); -*/ - psha->errType = SDIO_ERR_DAT_CRC; - if (psha->ErrorCallback) - psha->ErrorCallback(psha->ErrorCbPara); - } - - } - if (status & NOR_INT_STAT_CARD_INSERT) // 0x40 - { - SdioHostSdClkCtrl(psha, 1, BASE_CLK_DIVIDED_BY_128); // BASE_CLK_DIVIDED_BY_128 - SdioHostSdBusPwrCtrl(); - if (psha->CardInsertCallBack) - psha->CardInsertCallBack(psha->CardInsertCbPara); - } - if (status & NOR_INT_STAT_CARD_REMOVAL) // 0x80 - { - HAL_SDIOH_REG8(REG_SDIO_HOST_PWR_CTRL) &= ~PWR_CTRL_SD_BUS_PWR; - SdioHostSdClkCtrl(psha, 0, BASE_CLK); // BASE_CLK - if (psha->CardRemoveCallBack) - psha->CardRemoveCallBack(psha->CardRemoveCbPara); - } - if (status & NOR_INT_STAT_CARD_INT) // 0x100 ) - { - u16 val = HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS_EN); - HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS_EN) = val & (~NOR_INT_STAT_EN_CARD_INT); - DBG_SDIO_ERR("CARD INT: 0x%04X\n", status); - HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS_EN) = val; - - } - if (status & NOR_INT_STAT_ERR_INT) // 0x8000 ) - { - HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_SIG_EN) = 0; - u16 err = HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS); -/* - DBG_SDIO_ERR("\r[SDIO Err]XFER CP with ErrIntVal: 0x%04X /0x%04X -- TYPE 0x%02X\n", - status, - err, - psha->CmdCompleteFlg?); -*/ - if (psha->CmdCompleteFlg) { - SdioHostErrIntRecovery(psha); - goto ir_end; - } - DiagPrintf("\r[SDIO Err]Read/Write command Error\n"); - - psha->ErrIntFlg = 1; - } - } -ir_end: - HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_SIG_EN) - = NOR_INT_SIG_EN_CMD_COMP - | NOR_INT_SIG_EN_XFER_COMP - | NOR_INT_SIG_EN_CARD_REMOVAL - | NOR_INT_SIG_EN_CARD_INT; // 195; -} - -//----- (00000328) -------------------------------------------------------- +//----- HalSdioHostDeInitRtl8195a HAL_Status HalSdioHostDeInitRtl8195a(IN VOID *Data) { - void *v1; // r5@1 HAL_Status ret; // r4@1 - PHAL_SDIO_HOST_ADAPTER psha = Data; + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; HAL_SDIOH_REG8(REG_SDIO_HOST_PWR_CTRL) &= ~PWR_CTRL_SD_BUS_PWR; ret = SdioHostSdClkCtrl(psha, 0, BASE_CLK); if (ret == HAL_OK) { @@ -307,13 +227,11 @@ HAL_Status HalSdioHostDeInitRtl8195a(IN VOID *Data) { } return ret; } -// 23DC: using guessed type int VectorIrqDisRtl8195A(u32); -// 23E0: using guessed type int VectorIrqUnRegisterRtl8195A(u32); -// 23E4: using guessed type int HalPinCtrlRtl8195A(u32, u32, u32); -//----- (000003C0) -------------------------------------------------------- +//----- HalSdioHostEnableRtl8195a HAL_Status HalSdioHostEnableRtl8195a(IN VOID *Data) // // PHAL_SDIO_HOST_ADAPTER Data { +// PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; ACTCK_SDIOH_CCTRL(ON); SLPCK_SDIOH_CCTRL(ON); HAL_SDIOH_REG16(REG_SDIO_HOST_CLK_CTRL) |= CLK_CTRL_INTERAL_CLK_EN; @@ -321,7 +239,7 @@ HAL_Status HalSdioHostEnableRtl8195a(IN VOID *Data) // // PHAL_SDIO_HOST_ADAPTER return SdioHostSdClkCtrl(Data, 1, BASE_CLK_DIVIDED_BY_2); } -//----- (000003F8) -------------------------------------------------------- +//----- HalSdioHostDisableRtl8195a HAL_Status HalSdioHostDisableRtl8195a(IN VOID *Data) { int result; // r0@1 @@ -354,7 +272,7 @@ HAL_Status HalSdioHostIrqInitRtl8195a(IN VOID *Data) // PIRQ_HANDLE Data //----- HalSdioHostInitHostRtl8195a HAL_Status HalSdioHostInitHostRtl8195a(IN VOID *Data) { - PHAL_SDIO_HOST_ADAPTER psha = Data; + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; HAL_WRITE32(PERI_ON_BASE, REG_PESOC_HCI_CLK_CTRL0, HAL_READ32(PERI_ON_BASE, REG_PESOC_HCI_CLK_CTRL0) & (~BIT_SOC_ACTCK_SDIO_DEV_EN)); @@ -406,41 +324,40 @@ HAL_Status HalSdioHostInitHostRtl8195a(IN VOID *Data) { return HAL_TIMEOUT; } } - HAL_SDIOH_REG32(0x1000) |= 0x400); // 40059000 |= 0x400; + HAL_SDIOH_REG32(0x1000) |= 0x400; // 40059000 |= 0x400; if (HAL_SDIOH_REG32(REG_SDIO_HOST_CAPABILITIES) & CAPA_ADMA2_SUPPORT) HAL_SDIOH_REG16(REG_SDIO_HOST_HOST_CTRL) = 0x10; // 32-bit Address ADMA2 is selected HAL_SDIOH_REG8(REG_SDIO_HOST_TIMEOUT_CTRL) = 0x0E; // TMCLK x 2^27 return HAL_OK; } -//----- (00000578) -------------------------------------------------------- +//----- HalSdioHostStopTransferRtl8195a HAL_Status HalSdioHostStopTransferRtl8195a(IN VOID *Data) { - u8 *v2; // r4@1 - int result; // r0@2 - char v4; // r2@4 - uint32_t v5; // r1@4 - signed int v6; // r2@4 - SDIO_HOST_CMD Cmd; // [sp+0h] [bp-10h]@1 + HAL_Status result; + SDIO_HOST_CMD Cmd; + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; - *(u32 *) &Cmd.CmdFmt = Data; - Cmd.Arg = a2; - PHAL_SDIO_HOST_ADAPTER psha = Data; // v2 = Data; if (psha) { - result = SdioHostChkCmdInhibitCMD((uint32_t) Data); + result = SdioHostChkCmdInhibitCMD(); //(uint32_t) Data); if (result == HAL_OK) { - result = SdioHostChkCmdInhibitDAT(0); + result = SdioHostChkCmdInhibitDAT(); if (result == HAL_OK) { - Cmd.CmdFmt = (SDIO_HOST_CMD_FMT) ((*(u8 *) &Cmd.CmdFmt | 0x1B) - & 0xDF | 0xC0); - v4 = *((u8 *) &Cmd.CmdFmt + 1); - v2[128] = 0; - v2[129] = 0; + + psha->CmdCompleteFlg = 0; + psha->XferType = SDIO_XFER_NOR; + psha->XferCompleteFlg = 0; + + Cmd.CmdFmt.RespType = RSP_LEN_48_CHK_BUSY; + Cmd.CmdFmt.Rsvd0 = 0; + Cmd.CmdFmt.CmdCrcChkEn = 1; + Cmd.CmdFmt.CmdIdxChkEn = 0; + Cmd.CmdFmt.DataPresent = NO_DATA; + Cmd.CmdFmt.CmdType = ABORT; + Cmd.CmdFmt.CmdIdx = CMD_STOP_TRANSMISSION; + Cmd.CmdFmt.Rsvd1 = 0; Cmd.Arg = 0; - *((u8 *) &Cmd.CmdFmt + 1) = v4 & 0xC0 | 0xC; + SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete(v2, v5); - if (result == HAL_OK) - result = SdioHostChkXferComplete(v2, 0x1388u, v6); } } } else { @@ -449,13 +366,13 @@ HAL_Status HalSdioHostStopTransferRtl8195a(IN VOID *Data) { return result; } -//----- (000005D8) -------------------------------------------------------- -HAL_Status SdioHostErrIntRecovery(void *Data, int a2, signed int a3) { - PHAL_SDIO_HOST_ADAPTER psha = Data; +//----- SdioHostErrIntRecovery +HAL_Status SdioHostErrIntRecovery(void *Data) { + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; int t; if (!psha) return HAL_ERR_PARA; - DBG_SDIO_ERR("Recovering error interrupt...\n", a2, a3); + DBG_SDIO_ERR("Recovering error interrupt...\n"); u16 ierr = HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS); // v40058032; if (HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS) @@ -522,200 +439,360 @@ HAL_Status SdioHostErrIntRecovery(void *Data, int a2, signed int a3) { DBG_SDIO_ERR("Stop transmission error!\n"); return HAL_ERR_UNKNOWN; } -// 23D4: using guessed type int DiagPrintf(const char *, ...); -// 23F0: using guessed type int HalDelayUs(u32); -//----- (00000748) -------------------------------------------------------- -signed int SdioHostChkXferComplete(void *Data, uint32_t Timeout, signed int a3) { - uint32_t v3; // r6@1 - u8 *v4; // r4@1 - uint32_t v5; // r5@3 - uint32_t v6; // r7@3 - signed int result; // r0@9 +//----- (0000028C) -------------------------------------------------------- +void SdioHostIsrHandle(void *Data) { + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; + u16 status = HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS);// v40058030; - v3 = Timeout; - v4 = Data; - if (Data) { - if (Timeout - 1 > 0xFFFFFFFD) { - v6 = 0; - v5 = 0; - } else { - v5 = 1000 * Timeout / 0x1F; - v6 = (*((int (**)(u32)) &HalTimerOp + 2))(1); - } - do { - while (1) { - if (v4[129] && v40058024 & 0x100000) - return 0; - if (v4[130]) - return SdioHostErrIntRecovery(v4, Timeout, a3); - if (!v5) - break; - result = SdioHostIsTimeout(v6, v5); - if (result == 2) - return result; + HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_SIG_EN) = 0; + if (status) { + if (status & NOR_INT_STAT_CMD_COMP) + psha->CmdCompleteFlg = 1; + if (status & NOR_INT_STAT_XFER_COMP) { + psha->XferCompleteFlg = 1; + if ((status & NOR_INT_STAT_ERR_INT) == 0) { + if (psha->XferCompCallback) + psha->XferCompCallback(psha->XferCompCbPara); + + } else if (HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS) & + ( ERR_INT_STAT_DATA_TIMEOUT + | ERR_INT_STAT_DATA_CRC + | ERR_INT_STAT_DATA_END_BIT)) { + DBG_SDIO_ERR("\r[SDIO Err]XFER CP with ErrIntVal: 0x%04X /0x%04X -- TYPE 0x%02X\n", + status, + HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS), + psha->XferType); + psha->errType = SDIO_ERR_DAT_CRC; + if (psha->ErrorCallback) + psha->ErrorCallback(psha->ErrorCbPara); } - } while (v3); - result = 1; + + } + if (status & NOR_INT_STAT_CARD_INSERT) // 0x40 + { + SdioHostSdClkCtrl(psha, 1, BASE_CLK_DIVIDED_BY_128); // BASE_CLK_DIVIDED_BY_128 + SdioHostSdBusPwrCtrl(); + if (psha->CardInsertCallBack) + psha->CardInsertCallBack(psha->CardInsertCbPara); + } + if (status & NOR_INT_STAT_CARD_REMOVAL) // 0x80 + { + HAL_SDIOH_REG8(REG_SDIO_HOST_PWR_CTRL) &= ~PWR_CTRL_SD_BUS_PWR; + SdioHostSdClkCtrl(psha, 0, BASE_CLK); // BASE_CLK + if (psha->CardRemoveCallBack) + psha->CardRemoveCallBack(psha->CardRemoveCbPara); + } + if (status & NOR_INT_STAT_CARD_INT) // 0x100 ) + { + u16 val = HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS_EN); + HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS_EN) = val & (~NOR_INT_STAT_EN_CARD_INT); + DBG_SDIO_ERR("CARD INT: 0x%04X\n", status); + HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_STATUS_EN) = val; + + } + if (status & NOR_INT_STAT_ERR_INT) // 0x8000 ) + { + HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_SIG_EN) = 0; + u16 err = HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS); + + DBG_SDIO_ERR("\r[SDIO Err]XFER CP with ErrIntVal: 0x%04X /0x%04X -- TYPE 0x%02X\n", + status, + err, + psha->CmdCompleteFlg); + + if (psha->CmdCompleteFlg) { + SdioHostErrIntRecovery(psha); + goto ir_end; + } + DiagPrintf("\r[SDIO Err]Read/Write command Error\n"); + + psha->ErrIntFlg = 1; + } + } +ir_end: + HAL_SDIOH_REG16(REG_SDIO_HOST_NORMAL_INT_SIG_EN) + = NOR_INT_SIG_EN_CMD_COMP + | NOR_INT_SIG_EN_XFER_COMP + | NOR_INT_SIG_EN_CARD_REMOVAL + | NOR_INT_SIG_EN_CARD_INT; // 195; +} + +//----- SdioHostChkCmdComplete +HAL_Status SdioHostChkCmdComplete(void *Data, uint32_t Timeout) { +{ + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; + uint32_t TimeoutCnt; + uint32_t StartCount; + HAL_Status result; + + + if (psha) { + if (Timeout == SDIO_HOST_WAIT_FOREVER) { + StartCount = 0; + TimeoutCnt = 0; + } else { + TimeoutCnt = 1000 * Timeout / 31; + StartCount = HalTimerOp.HalTimerReadCount(1); // v6 = (*((int (**)(u32)) &HalTimerOp + 2))(1); + } + while(psha->CmdCompleteFlg == 0) { + if(psha->ErrIntFlg) + return SdioHostErrIntRecovery(psha); + if(TimeoutCnt) { + result = SdioHostIsTimeout(StartCount, TimeoutCnt); + if (result == HAL_TIMEOUT) + return result; + } else if(Timeout == 0) { + result = HAL_BUSY; + return result; + } + } + result = HAL_OK; + } else + result = HAL_ERR_PARA; + return result; +} + +//----- SdioHostGetCSD +HAL_Status SdioHostGetCSD(void *Data) +{ + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; + HAL_Status result; + SDIO_HOST_CMD Cmd; + + if (psha) { + result = SdioHostChkCmdInhibitCMD(); + if (result == HAL_OK) { + + Cmd.CmdFmt.RespType = RSP_LEN_136; + Cmd.CmdFmt.Rsvd0 = 0; + Cmd.CmdFmt.CmdCrcChkEn = 1; + Cmd.CmdFmt.CmdIdxChkEn = 0; + Cmd.CmdFmt.DataPresent = NO_DATA; + Cmd.CmdFmt.CmdType = NORMAL; + Cmd.CmdFmt.CmdIdx = CMD_SEND_CSD; + Cmd.CmdFmt.Rsvd1 = 0; + Cmd.Arg = psha->RCA << 16; + + psha->CmdCompleteFlg = 0; + psha->XferType = 0; + + SdioHostSendCmd(&Cmd); + result = SdioHostChkCmdComplete(psha, 50); + if(result == HAL_OK) { + SdioHostGetResponse(psha, Cmd.CmdFmt.RespType); + psha->Csd[15] = 1; + uint32 x = psha->Response[3]; + psha->Csd[0] = x >> 16; + psha->Csd[1] = x >> 8; + psha->Csd[2] = x; + x = psha->Response[2]; + psha->Csd[3] = x >> 24; + psha->Csd[4] = x >> 16; + psha->Csd[5] = x >> 8; + psha->Csd[6] = x; + x = psha->Response[1]; + psha->Csd[7] = x >> 24; + psha->Csd[8] = x >> 16; + psha->Csd[9] = x >> 8; + psha->Csd[10] = x; + x = psha->Response[0]; + psha->Csd[11] = x >> 24; + psha->Csd[12] = x >> 16; + psha->Csd[13] = x >> 8; + psha->Csd[14] = x; + } + } + } else + result = HAL_ERR_PARA; + return result; +} + +//----- SdioHostChkXferComplete +HAL_Status SdioHostChkXferComplete(void *Data) +{ + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; + uint32_t StartCount; + HAL_Status result; + if (psha) { + StartCount = HalTimerOp.HalTimerReadCount(1); + while(psha->XferCompleteFlg == 0 + && (HAL_SDIOH_REG32(REG_SDIO_HOST_PRESENT_STATE) + & PRES_STATE_DAT0_SIGNAL_LEVEL) == 0) { + if(psha->ErrIntFlg) + return SdioHostErrIntRecovery(psha); + result = SdioHostIsTimeout(StartCount, 161290); + if (result == HAL_TIMEOUT) + return result; + } + result = HAL_OK; } else { - result = 3; + result = HAL_ERR_PARA; } return result; } -//----- (000007C4) -------------------------------------------------------- -signed int SdioHostChkCmdComplete(void *Data, uint32_t Timeout) { - void *v2; // r4@1 - int v3; // r1@2 - signed int v4; // r2@2 - uint32_t v5; // r5@2 - signed int result; // r0@5 - - v2 = Data; - if (Data) { - v5 = (*((int (**)(u32, u32)) &HalTimerOp + 2))(1, Timeout); - while (!*((u8 *) v2 + 128)) { - if (*((u8 *) v2 + 130)) - return SdioHostErrIntRecovery(v2, v3, v4); - result = SdioHostIsTimeout(v5, 1612); - if (result == 2) - return result; - } - result = 0; - } else - result = 3; - - return result; -} - -//----- (0000080C) -------------------------------------------------------- -int SdioHostCardSelection(void *Data, int Select, int a3) { - u8 *v3; // r4@1 - int result; // r0@3 - char v5; // r3@5 - int v6; // r3@5 - uint32_t v7; // r1@5 - signed int v8; // r2@5 - signed int v9; // r5@6 - char v10; // r3@11 - uint32_t v11; // r1@11 +//----- SdioHostCardSelection +HAL_Status SdioHostCardSelection(void *Data, int Select) { + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; + HAL_Status result; SDIO_HOST_CMD Cmd; // [sp+0h] [bp-18h]@1 - int v13; // [sp+8h] [bp-10h]@1 - *(u32 *) &Cmd.CmdFmt = Data; - Cmd.Arg = Select; - v13 = a3; - v3 = Data; - if (Data) { - if (Select == 1) { - result = SdioHostChkCmdInhibitCMD((uint32_t) Data); - if (!result) { + if (psha) { + result = SdioHostChkCmdInhibitCMD(); + if (result == HAL_OK) { + psha->CmdCompleteFlg = 0; + psha->XferType = SDIO_XFER_NOR; + psha->XferCompleteFlg = 0; + + if (Select == 1) { result = SdioHostChkCmdInhibitDAT(0); - if (!result) { - Cmd.CmdFmt = (SDIO_HOST_CMD_FMT) ((*(u8 *) &Cmd.CmdFmt - | 0x1B) & 0x1F); - v5 = *((u8 *) &Cmd.CmdFmt + 1); - v3[128] = 0; - *((u8 *) &Cmd.CmdFmt + 1) = v5 & 0xC0 | 7; - v6 = *((u16 *) v3 + 67); - v3[129] = 0; - Cmd.Arg = v6 << 16; + if (result == HAL_OK) { + + Cmd.CmdFmt.RespType = RSP_LEN_48_CHK_BUSY; + Cmd.CmdFmt.Rsvd0 = 0; + Cmd.CmdFmt.CmdCrcChkEn = 1; + Cmd.CmdFmt.CmdIdxChkEn = 1; + Cmd.CmdFmt.DataPresent = NO_DATA; + Cmd.CmdFmt.CmdType = NORMAL; + Cmd.CmdFmt.CmdIdx = CMD_SELECT_DESELECT_CARD; + Cmd.CmdFmt.Rsvd1 = 0; + Cmd.Arg = psha->RCA << 16; + + SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete(v3, v7); - if (!result) { - v9 = SdioHostChkXferComplete(v3, 0x1388u, v8); - if (v9 - || (SdioHostGetResponse(v3, - *(u8 *) &Cmd.CmdFmt & 3), v3[24] == 7)) { - result = v9; - } else { + result = SdioHostChkCmdComplete(psha, 50); + if(result == HAL_OK) { + result = SdioHostChkXferComplete(psha); + if(result != HAL_OK) return result; + result = SdioHostGetResponse(psha, Cmd.CmdFmt.RespType); + if(result != HAL_OK) return result; + if((uint8)psha->Response[1] != 7) return result; + else { DBG_SDIO_ERR("Command index error!\n"); - result = 238; + result = HAL_ERR_UNKNOWN; } } } - } - } else { - result = SdioHostChkCmdInhibitCMD((uint32_t) Data); - if (!result) { - *(u8 *) &Cmd.CmdFmt &= 4u; - v10 = *((u8 *) &Cmd.CmdFmt + 1); - v3[128] = 0; - Cmd.Arg = 0; - *((u8 *) &Cmd.CmdFmt + 1) = v10 & 0xC0 | 7; + } else { + + Cmd.CmdFmt.RespType = NO_RSP; + Cmd.CmdFmt.Rsvd0 = 0; + Cmd.CmdFmt.CmdCrcChkEn = 0; + Cmd.CmdFmt.CmdIdxChkEn = 0; + Cmd.CmdFmt.DataPresent = NO_DATA; + Cmd.CmdFmt.CmdType = NORMAL; + Cmd.CmdFmt.CmdIdx = CMD_SELECT_DESELECT_CARD; + Cmd.CmdFmt.Rsvd1 = 0; + Cmd.Arg = psha->RCA << 16; + + SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete(v3, v11); + result = SdioHostChkCmdComplete(psha, 50); } } - } else { + } else result = HAL_ERR_PARA; + return result; +} + + + + + + + + + + + + + + + + + + + + + +//----- (00000D34) -------------------------------------------------------- +HAL_Status SdioHostSwitchFunction(void *Data, int Mode, int Fn2Sel, int Fn1Sel, + uint8_t *StatusBuf) +{ + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; + HAL_Status result; // r0@3 + SDIO_HOST_CMD Cmd; // [sp+0h] [bp-20h]@1 + + u8 *v5; // r4@1 + uint32_t v6; // r0@1 + int v7; // r5@1 + int v8; // r6@1 + char v9; // r7@3 + char v11; // r3@5 + uint32_t v12; // r1@5 + signed int v13; // r2@6 + uint32_t v14; // r1@6 + + + int v16; // [sp+8h] [bp-18h]@1 + + *(u32 *) &Cmd.CmdFmt = Data; + Cmd.Arg = Mode; + v16 = Fn2Sel; + v5 = Data; + v6 = *((u32 *) Data + 4); + v7 = Mode; + v8 = Fn2Sel; + if (!v6 || ((u8) Fn1Sel | (u8) v6) & 3) { result = 3; + } else { + HAL_SDIOH_REG32(REG_SDIO_HOST_ADMA_SYS_ADDR) = (uint32)psha->AdmaDescTbl; // v40058058 = v6; + HAL_SDIOH_REG16(REG_SDIO_HOST_BLK_SIZE) = 64; // v40058004 = 64; + HAL_SDIOH_REG32(REG_SDIO_HOST_XFER_MODE) = XFER_MODE_DATA_XFER_DIR | XFER_MODE_DMA_EN; // v4005800C = 17; + + v9 = *(u8 *) v6; + *(u16 *) (v6 + 2) = 64; + *(u8 *) v6 = ((v9 | 3) & 0xFB | 4 * ((Fn1Sel | v6) & 1)) & 0xEF + | 16 * ((Fn1Sel | v6) & 1) | 0x20; + *(u32 *) (v6 + 4) = Fn1Sel; + result = SdioHostChkCmdInhibitCMD();//v6); + if (!result) { + result = SdioHostChkDataLineActive(); + if (result == HAL_OK) { + Cmd.CmdFmt = (SDIO_HOST_CMD_FMT) ((*(u8 *) &Cmd.CmdFmt & 0xF4 + | 0x3A) & 0x3F); + v11 = *((u8 *) &Cmd.CmdFmt + 1); + v5[128] = 0; + *((u8 *) &Cmd.CmdFmt + 1) = v11 & 0xC0 | 6; + v5[129] = 0; + Cmd.Arg = v8 | 0xFFFFF0 | (v7 << 31); + SdioHostSendCmd(&Cmd); + result = SdioHostChkCmdComplete(v5);//, v12); + if (!result) { + SdioHostGetResponse(v5, *(u8 *) &Cmd.CmdFmt & 3); + result = SdioHostChkXferComplete(v5, 0x1388u, v13); + if (result) { + if (result != 16) { + if (HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS) & ERR_INT_STAT_ADMA) { + HAL_SDIOH_REG16(REG_SDIO_HOST_ERROR_INT_STATUS) = ERR_INT_STAT_ADMA; + if (HalSdioHostStopTransferRtl8195a(psha)) { + DBG_SDIO_ERR("Stop transmission error!\n"); + } + } + } + result = 238; + } + } + } + } } return result; } -// 23D4: using guessed type int DiagPrintf(const char *, ...); -//----- (000008FC) -------------------------------------------------------- -int SdioHostGetCSD(void *Data, uint32_t a2) { - void *v2; // r4@1 - int result; // r0@2 - int v4; // r3@3 - uint32_t v5; // r1@3 - signed int v6; // r6@3 - unsigned int v7; // r3@4 - unsigned int v8; // r2@4 - unsigned int v9; // r3@4 - unsigned int v10; // r2@4 - unsigned int v11; // r3@4 - unsigned int v12; // r2@4 - unsigned int v13; // r3@4 - SDIO_HOST_CMD Cmd; // [sp+0h] [bp-18h]@1 - *(u32 *) &Cmd.CmdFmt = Data; - Cmd.Arg = a2; - v2 = Data; - if (Data) { - result = SdioHostChkCmdInhibitCMD((uint32_t) Data); - if (!result) { - Cmd.CmdFmt = (SDIO_HOST_CMD_FMT) ((*(u8 *) &Cmd.CmdFmt & 0xFC | 9) - & 0xF); - *((u8 *) &Cmd.CmdFmt + 1) = *((u8 *) &Cmd.CmdFmt + 1) & 0xC0 | 9; - v4 = *((u16 *) v2 + 67); - *((u8 *) v2 + 128) = 0; - Cmd.Arg = v4 << 16; - SdioHostSendCmd(&Cmd); - v6 = SdioHostChkCmdComplete(v2, v5); - if (!v6) { - SdioHostGetResponse(v2, *(u8 *) &Cmd.CmdFmt & 3); - v7 = *((u32 *) v2 + 8); - *((u8 *) v2 + 127) = 1; - *((u8 *) v2 + 112) = v7 >> 16; - *((u8 *) v2 + 114) = v7; - v8 = v7 >> 8; - v9 = *((u32 *) v2 + 7); - *((u8 *) v2 + 113) = v8; - *((u8 *) v2 + 115) = BYTE3(v9); - *((u8 *) v2 + 116) = v9 >> 16; - *((u8 *) v2 + 118) = v9; - v10 = v9 >> 8; - v11 = *((u32 *) v2 + 6); - *((u8 *) v2 + 117) = v10; - *((u8 *) v2 + 119) = BYTE3(v11); - *((u8 *) v2 + 120) = v11 >> 16; - *((u8 *) v2 + 122) = v11; - v12 = v11 >> 8; - v13 = *((u32 *) v2 + 5); - *((u8 *) v2 + 121) = v12; - *((u8 *) v2 + 123) = BYTE3(v13); - *((u8 *) v2 + 124) = v13 >> 16; - *((u8 *) v2 + 125) = BYTE1(v13); - *((u8 *) v2 + 126) = v13; - } - result = v6; - } else - result = 3; - return result; - } -} + + + //----- (000009CC) -------------------------------------------------------- HAL_Status HalSdioHostReadBlocksDmaRtl8195a(IN VOID *Data, IN u64 ReadAddr, IN u32 BlockCnt) { @@ -755,7 +832,7 @@ IN u32 BlockCnt) { if (BlockCnt != 1) break; v4005800C = 17; - LABEL_18: result = SdioHostChkCmdInhibitCMD(result); + LABEL_18: result = SdioHostChkCmdInhibitCMD();//result); if (result) return result; result = SdioHostChkDataLineActive(0); @@ -770,7 +847,7 @@ IN u32 BlockCnt) { *((u8 *) &Cmd.CmdFmt + 1) = v12 & 0xC0 | 0x11; Cmd.Arg = v4; SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete((void *) v5, v13); + result = SdioHostChkCmdComplete((void *) v5);//, v13); if (result) goto LABEL_21; SdioHostGetResponse((void *) v5, *(u8 *) &Cmd.CmdFmt & 3); @@ -794,7 +871,7 @@ IN u32 BlockCnt) { v4005800C = 55; if (BlockCnta <= 1) goto LABEL_18; - result = SdioHostChkCmdInhibitCMD(result); + result = SdioHostChkCmdInhibitCMD();//result); if (result) return result; result = SdioHostChkDataLineActive(0); @@ -809,7 +886,7 @@ IN u32 BlockCnt) { *((u8 *) &Cmd.CmdFmt + 1) = v7 & 0xC0 | 0x12; Cmd.Arg = v4; SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete((void *) v5, v8); + result = SdioHostChkCmdComplete((void *) v5);//, v8); if (!result) { SdioHostGetResponse((void *) v5, *(u8 *) &Cmd.CmdFmt & 3); result = SdioHostChkXferComplete((void *) v5, 0x1388u, v9); @@ -834,7 +911,7 @@ IN u32 BlockCnt) { HAL_Status HalSdioHostWriteBlocksDmaRtl8195a(IN VOID *Data, IN u64 WriteAddr, IN u32 BlockCnt) { - + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; PHAL_SDIO_HOST_ADAPTER pSdioHostAdapter = (PHAL_SDIO_HOST_ADAPTER) Data; //int v5; // r6@1 uint32_t sec_count; // v4; // r4@1 @@ -886,7 +963,7 @@ IN u32 BlockCnt) { if (BlockCnt > 1) break; - LABEL_23: result = SdioHostChkCmdInhibitCMD(result); + LABEL_23: result = SdioHostChkCmdInhibitCMD();//result); if (result != HAL_OK) return result; result = SdioHostChkDataLineActive(0); @@ -901,7 +978,7 @@ IN u32 BlockCnt) { *((u8 *) &Cmd.CmdFmt + 1) = v10 & 0xC0 | 0x18; Cmd.Arg = sec_count; SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete((void *) v5, v11); + result = SdioHostChkCmdComplete((void *) v5);//, v11); if (result) goto LABEL_26; SdioHostGetResponse((void *) pSdioHostAdapter, @@ -928,7 +1005,7 @@ IN u32 BlockCnt) { return 238; } } - result = SdioHostChkCmdInhibitCMD(result); + result = SdioHostChkCmdInhibitCMD();//result); if (result != HAL_OK) return result; result = SdioHostChkDataLineActive(0); @@ -943,7 +1020,7 @@ IN u32 BlockCnt) { *((u8 *) &Cmd.CmdFmt + 1) = v7 & 0xC0 | 0x19; Cmd.Arg = sec_count; SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete((void *) v5, v8); + result = SdioHostChkCmdComplete((void *) v5);//, v8); if (!result) { SdioHostGetResponse((void *) pSdioHostAdapter, *(u8 *) &Cmd.CmdFmt & 3); @@ -969,73 +1046,6 @@ IN u32 BlockCnt) { } // 23D4: using guessed type int DiagPrintf(const char *, ...); -//----- (00000D34) -------------------------------------------------------- -int SdioHostSwitchFunction(void *Data, int Mode, int Fn2Sel, int Fn1Sel, - uint8_t *StatusBuf) { - u8 *v5; // r4@1 - uint32_t v6; // r0@1 - int v7; // r5@1 - int v8; // r6@1 - char v9; // r7@3 - int result; // r0@3 - char v11; // r3@5 - uint32_t v12; // r1@5 - signed int v13; // r2@6 - uint32_t v14; // r1@6 - SDIO_HOST_CMD Cmd; // [sp+0h] [bp-20h]@1 - int v16; // [sp+8h] [bp-18h]@1 - - *(u32 *) &Cmd.CmdFmt = Data; - Cmd.Arg = Mode; - v16 = Fn2Sel; - v5 = Data; - v6 = *((u32 *) Data + 4); - v7 = Mode; - v8 = Fn2Sel; - if (!v6 || ((u8) Fn1Sel | (u8) v6) & 3) { - result = 3; - } else { - v40058058 = v6; - v40058004 = 64; - v4005800C = 17; - v9 = *(u8 *) v6; - *(u16 *) (v6 + 2) = 64; - *(u8 *) v6 = ((v9 | 3) & 0xFB | 4 * ((Fn1Sel | v6) & 1)) & 0xEF - | 16 * ((Fn1Sel | v6) & 1) | 0x20; - *(u32 *) (v6 + 4) = Fn1Sel; - result = SdioHostChkCmdInhibitCMD(v6); - if (!result) { - result = SdioHostChkDataLineActive(0); - if (!result) { - Cmd.CmdFmt = (SDIO_HOST_CMD_FMT) ((*(u8 *) &Cmd.CmdFmt & 0xF4 - | 0x3A) & 0x3F); - v11 = *((u8 *) &Cmd.CmdFmt + 1); - v5[128] = 0; - *((u8 *) &Cmd.CmdFmt + 1) = v11 & 0xC0 | 6; - v5[129] = 0; - Cmd.Arg = v8 | 0xFFFFF0 | (v7 << 31); - SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete(v5, v12); - if (!result) { - SdioHostGetResponse(v5, *(u8 *) &Cmd.CmdFmt & 3); - result = SdioHostChkXferComplete(v5, 0x1388u, v13); - if (result) { - if (result != 16) { - if (v40058032 & 0x200) { - v40058032 = 512; - if (HalSdioHostStopTransferRtl8195a(v5, v14)) { - DBG_SDIO_ERR("Stop transmission error!\n"); - } - } - } - result = 238; - } - } - } - } - } - return result; -} // 23D4: using guessed type int DiagPrintf(const char *, ...); //----- (00000E34) -------------------------------------------------------- @@ -1055,7 +1065,7 @@ HAL_Status HalSdioHostGetCardStatusRtl8195a(IN VOID *Data) { v3 = Data; if (!Data) return 3; - result = SdioHostChkCmdInhibitCMD((uint32_t) Data); + result = SdioHostChkCmdInhibitCMD();//(uint32_t) Data); if (result) return result; Cmd.CmdFmt = @@ -1065,7 +1075,7 @@ HAL_Status HalSdioHostGetCardStatusRtl8195a(IN VOID *Data) { *((u8 *) &Cmd.CmdFmt + 1) = v5 & 0xC0 | 0xD; Cmd.Arg = *((u16 *) v3 + 67) << 16; SdioHostSendCmd(&Cmd); - v7 = SdioHostChkCmdComplete(v3, v6); + v7 = SdioHostChkCmdComplete(v3);//, v6); if (v7) return v7; SdioHostGetResponse(v3, *(u8 *) &Cmd.CmdFmt & 3); @@ -1142,7 +1152,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { v7 = 3; goto LABEL_115; }; - v4 = SdioHostChkCmdInhibitCMD((uint32_t) Data); + v4 = SdioHostChkCmdInhibitCMD();//(uint32_t) Data); if (!v4) { v5 = (char) v52; v3[128] = 0; @@ -1150,7 +1160,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { v53 = 0; BYTE1(v52) &= 0xC0u; SdioHostSendCmd((SDIO_HOST_CMD *) &v52); - v4 = SdioHostChkCmdComplete(v3, v6); + v4 = SdioHostChkCmdComplete(v3);//, v6); }; v7 = v4; if (v4) { @@ -1159,12 +1169,12 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { }; goto LABEL_115; - v9 = SdioHostChkCmdInhibitCMD(0); + v9 = SdioHostChkCmdInhibitCMD();//0); if (v9 || (LOBYTE(v52) = (((u8) v52 & 0xF4 | 0x1A) & 0xDF | 32 * (v7 & 1)) & 0x3F | ((v7 & 3) << 6), BYTE1(v52) = BYTE1(v52) & 0xC0 | 8, v3[128] = v7, v53 = 426, SdioHostSendCmd( - (SDIO_HOST_CMD *) &v52), (v9 = SdioHostChkCmdComplete(v3, + (SDIO_HOST_CMD *) &v52), (v9 = SdioHostChkCmdComplete(v3);//, v10)) != 0)) { v7 = v9; if (v9) @@ -1199,7 +1209,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { goto LABEL_115; } } - v13 = SdioHostChkCmdInhibitCMD(v9); + v13 = SdioHostChkCmdInhibitCMD();//v9); if (v13) goto LABEL_63; LOBYTE (v52) = ((u8) v52 & 0xFC | 0x1A) & 0x1F; @@ -1208,7 +1218,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { BYTE1 (v52) = v14; v53 = v7; SdioHostSendCmd((SDIO_HOST_CMD *) &v52); - v13 = SdioHostChkCmdComplete(v3, v15); + v13 = SdioHostChkCmdComplete(v3);//, v15); if (v13) goto LABEL_63; v16 = SdioHostGetResponse(v3, (u8) v52 & 3); @@ -1229,12 +1239,11 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { LABEL_57: v7 = 238; goto LABEL_60; }; - v13 = SdioHostChkCmdInhibitCMD(v16); + v13 = SdioHostChkCmdInhibitCMD();//v16); if (v13 || (LOBYTE(v52) = ((u8) v52 & 0xFC | 2) & 7, v18 = BYTE1(v52) & 0xC0 | 0x29, v3[128] = v7, BYTE1(v52) = v18, v53 = v7, SdioHostSendCmd( - (SDIO_HOST_CMD *) &v52), (v13 = SdioHostChkCmdComplete(v3, - v19)) != 0)) { + (SDIO_HOST_CMD *) &v52), (v13 = SdioHostChkCmdComplete(v3)) != 0)) { LABEL_63: v7 = v13; if (!v13) goto LABEL_64; @@ -1251,7 +1260,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { v22 = __CFADD__(v21--, -1); if (!v22) goto LABEL_51; - v13 = SdioHostChkCmdInhibitCMD(v20); + v13 = SdioHostChkCmdInhibitCMD();//v20); if (v13) goto LABEL_63; LOBYTE (v52) = ((u8) v52 & 0xFC | 0x1A) & 0x1F; @@ -1260,7 +1269,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { v53 = 0; BYTE1 (v52) = v23 & 0xC0 | 0x37; SdioHostSendCmd((SDIO_HOST_CMD *) &v52); - v13 = SdioHostChkCmdComplete(v3, v24); + v13 = SdioHostChkCmdComplete(v3);//, v24); if (v13) goto LABEL_63; v25 = SdioHostGetResponse(v3, (u8) v52 & 3); @@ -1280,7 +1289,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { LABEL_62: v13 = 238; goto LABEL_63; } - v13 = SdioHostChkCmdInhibitCMD(v25); + v13 = SdioHostChkCmdInhibitCMD();//v25); if (v13) goto LABEL_63; LOBYTE (v52) = ((u8) v52 & 0xFC | 2) & 7; @@ -1289,7 +1298,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { BYTE1 (v52) = v27 & 0xC0 | 0x29; v53 = 1077673984; SdioHostSendCmd((SDIO_HOST_CMD *) &v52); - v13 = SdioHostChkCmdComplete(v3, v28); + v13 = SdioHostChkCmdComplete(v3);//, v28); if (v13) goto LABEL_63; SdioHostGetResponse(v3, (u8) v52 & 3); @@ -1314,12 +1323,11 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { } DiagPrintf(v29); LABEL_64: v30 = HalDelayUs(20); - v31 = SdioHostChkCmdInhibitCMD(v30); + v31 = SdioHostChkCmdInhibitCMD();//v30); if (v31 || (LOBYTE(v52) = ((u8) v52 & 0xF4 | 9) & 0xF, v32 = BYTE1(v52) & 0xC0 | 2, v3[128] = v7, BYTE1(v52) = v32, v53 = v7, SdioHostSendCmd( - (SDIO_HOST_CMD *) &v52), (v31 = SdioHostChkCmdComplete(v3, - v33)) != 0)) { + (SDIO_HOST_CMD *) &v52), (v31 = SdioHostChkCmdComplete(v3)) != 0)) { v7 = v31; if (!v31) goto LABEL_70; @@ -1330,12 +1338,11 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { goto LABEL_115; } v31 = SdioHostGetResponse(v3, (u8) v52 & 3); - LABEL_70: v34 = SdioHostChkCmdInhibitCMD(v31); + LABEL_70: v34 = SdioHostChkCmdInhibitCMD();//v31); if (v34 || (LOBYTE(v52) = ((u8) v52 & 0xF4 | 0x1A) & 0x1F, v35 = BYTE1(v52) & 0xC0 | 3, v3[128] = v7, BYTE1(v52) = v35, v53 = v7, SdioHostSendCmd( - (SDIO_HOST_CMD *) &v52), (v34 = SdioHostChkCmdComplete(v3, - v36)) != 0)) { + (SDIO_HOST_CMD *) &v52), (v34 = SdioHostChkCmdComplete(v3)) != 0)) { v7 = v34; if (v34) goto LABEL_79; @@ -1372,7 +1379,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { LABEL_108: DiagPrintf(v41, v40); goto LABEL_113; } - v42 = SdioHostChkCmdInhibitCMD(0); + v42 = SdioHostChkCmdInhibitCMD();//0); if (v42) goto LABEL_120; LOBYTE (v52) = ((u8) v52 & 0xFC | 0x1A) & 0x1F; @@ -1381,7 +1388,7 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { v3[128] = v7; v53 = v45; SdioHostSendCmd((SDIO_HOST_CMD *) &v52); - v42 = SdioHostChkCmdComplete(v3, v46); + v42 = SdioHostChkCmdComplete(v3);//, v46); if (v42) goto LABEL_120; v47 = SdioHostGetResponse(v3, (u8) v52 & 3); @@ -1394,12 +1401,11 @@ HAL_Status HalSdioHostInitCardRtl8195a(IN VOID *Data) { } goto LABEL_96; } - v42 = SdioHostChkCmdInhibitCMD(v47); + v42 = SdioHostChkCmdInhibitCMD();//v47); if (v42 || (LOBYTE(v52) = ((u8) v52 & 0xFC | 0x1A) & 0x1F, v49 = BYTE1(v52) & 0xC0 | 6, v3[128] = v7, BYTE1(v52) = v49, v53 = 2, SdioHostSendCmd( - (SDIO_HOST_CMD *) &v52), (v42 = SdioHostChkCmdComplete(v3, - v50)) != 0)) { + (SDIO_HOST_CMD *) &v52), (v42 = SdioHostChkCmdComplete(v3)) != 0)) { LABEL_120: v7 = v42; if (v42) goto LABEL_102; @@ -1477,7 +1483,7 @@ HAL_Status HalSdioHostGetSdStatusRtl8195a(IN VOID *Data) { v6 = (u8) ((v5 | 3) & 0xEB) | 0x20; *(u8 *) v3 = v6; *(u32 *) (v3 + 4) = v4 + 48; - result = SdioHostChkCmdInhibitCMD(v6); + result = SdioHostChkCmdInhibitCMD();//v6); if (!result) { Cmd.CmdFmt = (SDIO_HOST_CMD_FMT) ((*(u8 *) &Cmd.CmdFmt & 0xFC | 0x1A) @@ -1487,7 +1493,7 @@ HAL_Status HalSdioHostGetSdStatusRtl8195a(IN VOID *Data) { v4[128] = 0; Cmd.Arg = v8 << 16; SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete(v4, v9); + result = SdioHostChkCmdComplete(v4); if (!result) { SdioHostGetResponse(v4, *(u8 *) &Cmd.CmdFmt & 3); if (v4[24] != 55) { @@ -1506,7 +1512,7 @@ HAL_Status HalSdioHostGetSdStatusRtl8195a(IN VOID *Data) { } return 238; } - result = SdioHostChkCmdInhibitCMD(*((u32 *) v4 + 5) << 26); + result = SdioHostChkCmdInhibitCMD();//*((u32 *) v4 + 5) << 26); if (!result) { result = SdioHostChkDataLineActive(0); if (!result) { @@ -1518,7 +1524,7 @@ HAL_Status HalSdioHostGetSdStatusRtl8195a(IN VOID *Data) { Cmd.Arg = 0; *((u8 *) &Cmd.CmdFmt + 1) = v12 & 0xC0 | 0xD; SdioHostSendCmd(&Cmd); - result = SdioHostChkCmdComplete(v4, v13); + result = SdioHostChkCmdComplete(v4);//, v13); if (!result) { SdioHostGetResponse(v4, *(u8 *) &Cmd.CmdFmt & 3); v15 = SdioHostChkXferComplete(v4, 0x1388u, v14); @@ -1546,11 +1552,11 @@ HAL_Status HalSdioHostGetSdStatusRtl8195a(IN VOID *Data) { // 23D4: using guessed type int DiagPrintf(const char *, ...); //----- (00001668) -------------------------------------------------------- +// SD_CLK_FREQUENCY Frequency HAL_Status HalSdioHostChangeSdClockRtl8195a(IN VOID *Data, IN u8 Frequency) { - PHAL_SDIO_HOST_ADAPTER v2 /*pSdioHostAdapter*/= - (PHAL_SDIO_HOST_ADAPTER) Data; - u8 * v2; // r5@1 - int v3; // r4@6 + PHAL_SDIO_HOST_ADAPTER pSdioHostAdapter = (PHAL_SDIO_HOST_ADAPTER) Data; // v2 = Data; u8 * v2; // r5@1 + PHAL_SDIO_HOST_ADAPTER psha = (PHAL_SDIO_HOST_ADAPTER)Data; + HAL_Status ret = HAL_ERR_PARA; // int v3; // r4@6 int v4; // r2@8 int v5; // r0@10 int v6; // r0@10 @@ -1567,65 +1573,65 @@ HAL_Status HalSdioHostChangeSdClockRtl8195a(IN VOID *Data, IN u8 Frequency) { int v17; // r0@34 int v18; // r0@36 const char *v19; // r0@40 - int v20; // r2@52 - char v22; // [sp+0h] [bp-58h]@11 + u8 Divisor; // int v20; // r2@52 + char v22; // SDIO_HOST_CMD [sp+0h] [bp-58h]@11 char v23; // [sp+1h] [bp-57h]@11 int v24; // [sp+4h] [bp-54h]@11 + uint8_t StatusData[64]; // [sp+8h] [bp-50h]@8 - v2 = Data; - if (!Data || (unsigned int) (Frequency - 5) > 3) - return 3; - if (v2.CurrSdClk == Frequency) { - DBG_SDIO_WARN( - "Current SDCLK frequency is already the specified value...\n"); - return 0; + + if (!psha || Frequency > SD_CLK_41_6MHZ) + return ret; + if (psha->CurrSdClk == Frequency) { + DBG_SDIO_WARN("Current SDCLK frequency is already the specified value...\n"); + ret = HAL_OK; + return ret; } - if (Frequency != SD_CLK_41_6MHZ) { // SD_CLK_41_6MHZ - if (Frequency == SD_CLK_10_4MHZ) // SD_CLK_10_4MHZ - v20 = BASE_CLK_DIVIDED_BY_4; - else if (Frequency == SD_CLK_20_8MHZ) // SD_CLK_20_8MHZ - v20 = BASE_CLK_DIVIDED_BY_2; - else if (Frequency != SD_CLK_5_2MHZ) { // SD_CLK_5_2MHZ + if (Frequency != SD_CLK_41_6MHZ) { + if (Frequency == SD_CLK_10_4MHZ) + Divisor = BASE_CLK_DIVIDED_BY_4; // 10.4 MHz + else if (Frequency == SD_CLK_20_8MHZ) + Divisor = BASE_CLK_DIVIDED_BY_2; // 20.8 MHz + else if (Frequency != SD_CLK_5_2MHZ) { DBG_SDIO_ERR("Unsupported SDCLK frequency!\n"); - v3 = 3; - goto LABEL_60; + return ret; } - v20 = BASE_CLK_DIVIDED_BY_8; + Divisor = BASE_CLK_DIVIDED_BY_8; // 5.2 MHZ } - v3 = SdioHostSdClkCtrl(Data, 1, v20); - if (!v3) - return 0; - LABEL_60: if (!(ConfigDebugErr & 0x400)) { - return v3; - v19 = "\r[SDIO Err]Host changes clock fail!\n"; // DBG_SDIO_ERR(" - goto LABEL_62; - } - v4 = *((u32 *) Data + 4); + ret = SdioHostSdClkCtrl(psha, 1, Divisor); + if (ret == HAL_OK) return ret; + DBG_SDIO_ERR("Host changes clock fail!\n"); + return ret; + *(u32 *) StatusData = 0; *(u32 *) &StatusData[4] = 0; - if (!v4 || v4 & 3) - return 3; - v40058058 = v4; - v40058004 = 8; - v4005800C = 17; - v5 = (u8) ((*(u8 *) v4 | 3) & 0xEB) | 0x20; - *(u8 *) v4 = v5; - *(u16 *) (v4 + 2) = 8; - *(u32 *) (v4 + 4) = StatusData; - v6 = SdioHostChkCmdInhibitCMD(v5); - if (v6) - goto LABEL_70; - v22 = (v22 & 0xF4 | 0x1A) & 0x1F; - v7 = v23; - v2[128] = 0; - v23 = v7 & 0xC0 | 0x37; - v24 = *((u16 *) v2 + 67) << 16; - SdioHostSendCmd((SDIO_HOST_CMD *) &v22); - v6 = SdioHostChkCmdComplete(v2, v8); - if (v6) - goto LABEL_70; - v9 = SdioHostGetResponse(v2, v22 & 3); + + PADMA2_DESC_FMT pAdmaDescTbl = psha->AdmaDescTbl; + if (pAdmaDescTbl == NULL || ((uint32)(pAdmaDescTbl) & 3)) { + ret = HAL_ERR_PARA; + return ret; + } + HAL_SDIOH_REG32(REG_SDIO_HOST_ADMA_SYS_ADDR) = psha->AdmaDescTbl; // v40058058 = v4; + HAL_SDIOH_REG16(REG_SDIO_HOST_BLK_SIZE) = 8; // v40058004 = 8; + HAL_SDIOH_REG16(REG_SDIO_HOST_XFER_MODE) = XFER_MODE_DMA_EN | XFER_MODE_DATA_XFER_DIR; // v4005800C = 17; + // v5 = (u8) ((*(u8 *) v4 | 3) & 0xEB) | 0x20; + // *(u8 *) v4 = v5; + pAdmaDescTbl->Attrib1.Int = 0; + pAdmaDescTbl->Attrib1.Act1 = 1; + pAdmaDescTbl->Len1 = 8; // *(u16 *) (v4 + 2) = 8; + pAdmaDescTbl->Addr2 = &StatusData; // *(u32 *) (v4 + 4) = StatusData; + ret = SdioHostChkCmdInhibitCMD();//v5); + if (ret != HAL_OK) return ret; + SDIO_HOST_CMD sdhcmd; + sdhcmd.CmdFmt.CmdCrcChkEn = 1; // v22 = (v22 & 0xF4 | 0x1A) & 0x1F; + sdhcmd.CmdFmt.CmdIdx = 0x37; // v23 = v7 & 0xC0 | 0x37; + pSdioHostAdapter->CmdCompleteFlg = 0; // v2[128] = 0; + sdhcmd.Arg = pSdioHostAdapter->Csd[?] << 16; // v24 = *((u16 *) v2 + 67) << 16; + SdioHostSendCmd((SDIO_HOST_CMD *) &sdhcmd); + ret = SdioHostChkCmdComplete(psha);//, v8); + if (ret != HAL_OK) return ret; + v9 = SdioHostGetResponse(psha, v22 & 3); if (v2[24] != 55) { if (!(ConfigDebugErr & 0x400)) return 238; @@ -1639,18 +1645,17 @@ HAL_Status HalSdioHostChangeSdClockRtl8195a(IN VOID *Data, IN u8 Frequency) { v10 = "\r[SDIO Err]ACMD isn't expected!\n"; goto LABEL_15; } - v6 = SdioHostChkCmdInhibitCMD(v9); + v6 = SdioHostChkCmdInhibitCMD();//v9); if (v6 || (v6 = SdioHostChkDataLineActive(0)) != 0 - || (v22 = (v22 & 0xF4 | 0x3A) & 0x3F, v11 = v23, v2[128] = 0, v2[129] = + || (v22 = (v22 & 0xF4 | 0x3A) & 0x3F, v11 = v23, psha v2[128] = 0, v2[129] = 0, v24 = 0, v23 = v11 & 0xC0 | 0x33, SdioHostSendCmd( - (SDIO_HOST_CMD *) &v22), (v6 = SdioHostChkCmdComplete(v2, - v12)) != 0)) { + (SDIO_HOST_CMD *) &v22), (v6 = SdioHostChkCmdComplete(psha)) != 0)) { LABEL_70: v3 = v6; if (v6) return v3; } else { SdioHostGetResponse(v2, v22 & 3); - v14 = SdioHostChkXferComplete(v2, 0x1388u, v13); + v14 = SdioHostChkXferComplete(psha, 0x1388u, v13); if (v14) { if (v14 == 16) return 238; @@ -1658,7 +1663,7 @@ HAL_Status HalSdioHostChangeSdClockRtl8195a(IN VOID *Data, IN u8 Frequency) { if (!(v40058032 & 0x200)) return 238; v40058032 = 512; - if (!HalSdioHostStopTransferRtl8195a(v2, v15) + if (!HalSdioHostStopTransferRtl8195a(psha, v15) || !(ConfigDebugErr & 0x400)) return 238; v10 = "\r[SDIO Err]Stop transmission error!\n"; @@ -1668,12 +1673,12 @@ HAL_Status HalSdioHostChangeSdClockRtl8195a(IN VOID *Data, IN u8 Frequency) { *((u16 *) v2 + 68) = StatusData[0] & 0xF; } if (*((u16 *) v2 + 68)) { - v16 = SdioHostSwitchFunction(v2, 0, 15, (int) StatusData, + v16 = SdioHostSwitchFunction(psha, 0, 15, (int) StatusData, *(uint8_t **) &v22); if (v16) return v16; if (StatusData[13] & 2) { - v17 = SdioHostSwitchFunction(v2, v16, 1, (int) StatusData, + v17 = SdioHostSwitchFunction(psha, v16, 1, (int) StatusData, *(uint8_t **) &v22); if (v17) return v17; @@ -1693,7 +1698,7 @@ HAL_Status HalSdioHostChangeSdClockRtl8195a(IN VOID *Data, IN u8 Frequency) { v10 = "\r[SDIO Err]Card changes to High-Speed fail!\n"; goto LABEL_15; } - v3 = SdioHostSdClkCtrl(v2, 1, v18); + v3 = SdioHostSdClkCtrl(psha, 1, v18); if (v3) { if (!(ConfigDebugErr & 0x400)) return v3; @@ -1744,7 +1749,7 @@ IN u64 EndAddr) { v4 = a2 >> 9; v3 = EndAddra >> 9; } - result = SdioHostChkCmdInhibitCMD(EndAddr); + result = SdioHostChkCmdInhibitCMD();//EndAddr); if (!result) { v16.CmdFmt = (SDIO_HOST_CMD_FMT) ((*(u8 *) &v16.CmdFmt & 0xFC | 0x1A) & 0x1F); @@ -1753,12 +1758,12 @@ IN u64 EndAddr) { *((u8 *) &v16.CmdFmt + 1) = v7 & 0xC0 | 0x20; v16.Arg = v4; SdioHostSendCmd(&v16); - result = SdioHostChkCmdComplete((void *) v5, v8); + result = SdioHostChkCmdComplete((void *) v5); if (!result) { v9 = SdioHostGetResponse((void *) v5, *(u8 *) &v16.CmdFmt & 3); if (*(u8 *) (v5 + 24) != 32) goto LABEL_20; - result = SdioHostChkCmdInhibitCMD(v9); + result = SdioHostChkCmdInhibitCMD();//v9); if (result) return result; v16.CmdFmt = @@ -1769,7 +1774,7 @@ IN u64 EndAddr) { *((u8 *) &v16.CmdFmt + 1) = v10 & 0xC0 | 0x21; v16.Arg = v3; SdioHostSendCmd(&v16); - result = SdioHostChkCmdComplete((void *) v5, v11); + result = SdioHostChkCmdComplete((void *) v5); if (result) return result; v12 = SdioHostGetResponse((void *) v5, *(u8 *) &v16.CmdFmt & 3); @@ -1778,7 +1783,7 @@ IN u64 EndAddr) { DBG_SDIO_ERR("Command index error!\n"); result = 238; } else { - result = SdioHostChkCmdInhibitCMD(v12); + result = SdioHostChkCmdInhibitCMD();//v12); if (!result) { result = SdioHostChkCmdInhibitDAT(0); if (!result) { @@ -1790,7 +1795,7 @@ IN u64 EndAddr) { v16.Arg = 0; *((u8 *) &v16.CmdFmt + 1) = v13 & 0xC0 | 0x26; SdioHostSendCmd(&v16); - result = SdioHostChkCmdComplete((void *) v5, v14); + result = SdioHostChkCmdComplete((void *) v5); if (!result) result = SdioHostChkXferComplete((void *) v5, 0x1388u, v15); @@ -1904,7 +1909,7 @@ HAL_Status HalSdioHostSetWriteProtectRtl8195a(IN VOID *Data, IN u8 Setting) { *(u16 *) (v2 + 2) = 16; *(u8 *) v2 = v10 & 0xC8 | 0x23; *(u32 *) (v2 + 4) = tmp; - result = SdioHostChkCmdInhibitCMD(1u); + result = SdioHostChkCmdInhibitCMD();//1u); if (!result) { result = SdioHostChkDataLineActive(0); if (!result) { @@ -1915,7 +1920,7 @@ HAL_Status HalSdioHostSetWriteProtectRtl8195a(IN VOID *Data, IN u8 Setting) { ret = 0; v17 = v12 & 0xC0 | 0x1B; SdioHostSendCmd((SDIO_HOST_CMD *) &v16); - result = SdioHostChkCmdComplete(v3, v13); + result = SdioHostChkCmdComplete(v3); if (!result) { SdioHostGetResponse(v3, v16 & 3); if (*((u32 *) v3 + 5) & 0x4000000) { diff --git a/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard.a b/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard.a index a4e51c7..32634f1 100644 Binary files a/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard.a and b/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard.a differ diff --git a/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard_v2.a b/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard_v2.a index ac74986..0244ef5 100644 Binary files a/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard_v2.a and b/USDK/component/soc/realtek/8195a/misc/bsp/lib/common/GCC/lib_sdcard_v2.a differ diff --git a/USDK/sdkset.mk b/USDK/sdkset.mk index 43c207e..ba7e7bc 100644 --- a/USDK/sdkset.mk +++ b/USDK/sdkset.mk @@ -40,7 +40,7 @@ all: LIBS +=_wlan _platform_new _wps _websocket _xmodem _mdns mp: LIBS +=_wlan_mp _platform_new _wps _websocket _xmodem _mdns endif ifdef USE_SDIOH -LIBS += _sdcard +LIBS += _sdcard_v2 CFLAGS += -DCONFIG_FATFS_EN=1 endif # m c nosys gcc @@ -364,16 +364,17 @@ endif #utilities - FatFS ifdef USE_FATFS INCLUDES += sdk/component/common/file_system/fatfs +INCLUDES += sdk/component/common/file_system/fatfs/fatfs_ext/inc INCLUDES += sdk/component/common/file_system/fatfs/r0.10c/include SRC_C += sdk/component/common/file_system/fatfs/fatfs_ext/src/ff_driver.c SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/diskio.c SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/ff.c SRC_C += sdk/component/common/file_system/fatfs/r0.10c/src/option/ccsbcs.c +endif ifdef USE_SDIOH INCLUDES += sdk/component/common/file_system/fatfs/disk_if/inc SRC_C += sdk/component/common/file_system/fatfs/disk_if/src/sdcard.c endif -endif # Reversed SDK component #ADD_SRC_C += sdk/component/soc/realtek/8195a/cmsis/device/app_start.c diff --git a/project.mk b/project.mk index 5c37ed5..83062cd 100644 --- a/project.mk +++ b/project.mk @@ -3,7 +3,7 @@ #============================================= #WEB_INA219_DRV = 1 #WEB_ADC_DRV = 1 -#WEB_SDCARD = 1 +USE_SDCARD = 1 #USE_AT = 1 #USE_FATFS = 1 #USE_SDIOH = 1 @@ -17,6 +17,11 @@ USE_NEWCONSOLE = 1 USE_WIFI_API = 1 endif +ifdef USE_SDCARD +USE_FATFS = 1 +USE_SDIOH = 1 +endif + #RTOSDIR=freertos_v8.1.2 RTOSDIR=freertos_v9.0.0 LWIPDIR=lwip_v1.4.1 @@ -36,9 +41,7 @@ ADD_SRC_C += project/src/console/wifi_console.c ADD_SRC_C += project/src/console/wlan_tst.c #ADD_SRC_C += project/src/console/pwm_tst.c -ifdef WEB_SDCARD -USE_FATFS = 1 -USE_SDIOH = 1 +ifdef USE_SDCARD ADD_SRC_C += project/src/console/sd_fat.c endif diff --git a/project/src/console/sd_fat.c b/project/src/console/sd_fat.c index 9ff86de..69bf080 100644 --- a/project/src/console/sd_fat.c +++ b/project/src/console/sd_fat.c @@ -211,6 +211,71 @@ void sd_unmount(FATFS *m_fs) { SD_DeInit(); // sdio_sd_deinit(); } +void read_file_test(char* file_name) { + FIL *f = malloc(sizeof(FIL)); + if (f_open(f, file_name, FA_READ) == FR_OK) { + char * buf = malloc(2048); + unsigned int bytesread =0; + unsigned int totalread=0; + do { + if (f_read(f, buf, 2048, &bytesread) != FR_OK) { + totalread += bytesread; + printf("Read error!"); + break; + } + totalread += bytesread; + } + while (bytesread !=0); + free(buf); + f_close(f); + } else { + printf("No open file!"); + } + free(f); +} + + +LOCAL void fATHF(int argc, char *argv[]) { + uint8 buf[512]; + FATFS * fs = sd_mount(); + if (fs != NULL) { + u8 * pbuf = (u8 *) malloc(512); // char *lfn = malloc (_MAX_LFN + 1); + if (pbuf != NULL) { + DIR dir; + FILINFO fno; + struct os_tm tm; + fno.lfname = (TCHAR*) pbuf; + fno.lfsize = 512; + u8 * sdir; + if(argc > 1 + && argv[1] != NULL + && (sdir = (u8 *) malloc(strlen(argv[1]) + 4)) != NULL ) + strcpy(strcpy(sdir, logical_drv) + 3, argv[1]); + else sdir = logical_drv; + if (f_opendir(&dir, sdir) == FR_OK) { + while (f_readdir(&dir, &fno) == FR_OK && fno.fname[0] != 0) { + if ((fno.fattrib & AM_VOL)==0 && fno.fsize > 0) { + if (*fno.lfname) { + strcpy(strcpy(buf, logical_drv) + 3, fno.lfname); + } else { + strcpy(strcpy(buf, logical_drv) + 3, fno.fname); + } + TickType_t t1 = xTaskGetTickCount(); + read_file_test(buf); + t1 = xTaskGetTickCount() - t1; + if(t1 == 0) t1 = 1; + printf("%u kbytes/sec\t%s\n", t1, buf); + } + } + } else + printf("FATFS: Open dir fail!\n"); + free(pbuf); + if(sdir != logical_drv) free(sdir); + } + } + sd_unmount(fs); + +} /* Test SD */ LOCAL void fATHS(int argc, char *argv[]) { // HalPinCtrlRtl8195A(UART0,0,0); @@ -311,8 +376,9 @@ LOCAL void fATHS(int argc, char *argv[]) { } -MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_spitst[] = { - {"ATHS", 0, fATHS, ": SD test"} +MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_dscard[] = { + {"ATHS", 0, fATHS, ": SD test"}, + {"ATHF", 0, fATHF, ": SD file read"} }; #endif // CONFIG_SDIO_HOST_EN