From 7de420b89f4e0df10436a7ee2f065c416e0cd6f4 Mon Sep 17 00:00:00 2001 From: pvvx Date: Mon, 5 Dec 2016 16:23:24 +0300 Subject: [PATCH] fix error (Ameba SDK) --- .../drivers/sdio/realtek/sdio_host/src/sd.c | 36 ++++++++++++------- .../sdio/realtek/sdio_host/src/sdio_host.c | 20 ++++++----- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sd.c b/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sd.c index d4e46f7..9959b62 100644 --- a/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sd.c +++ b/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sd.c @@ -10,7 +10,6 @@ #define SIZE_BLOCK_ADMA 512 - SemaphoreHandle_t sdWSema; void sd_xfer_done_callback(void *obj) { @@ -30,9 +29,11 @@ SD_RESULT SD_WaitReady() { SD_RESULT SD_Init() { SD_RESULT result; - if (sdio_sd_init() != 0) result = SD_INITERR; + if (sdio_sd_init() != 0) + result = SD_INITERR; else { - if (sdio_sd_getProtection() != 0) result = SD_PROTECTED; + if (sdio_sd_getProtection() != 0) + result = SD_PROTECTED; RtlInitSema(&sdWSema, 0); sdio_sd_hook_xfer_cmp_cb(sd_xfer_done_callback, 0); sdio_sd_hook_xfer_err_cb(sd_xfer_err_callback, 0); @@ -67,14 +68,17 @@ SD_RESULT SD_SetCLK(SD_CLK CLK) { // DBG_SDIO_INFO("clk = %d ?\n", CLK); return SD_ERROR; } - if(result) return SD_ERROR; + if (result) + return SD_ERROR; return SD_OK; } //----- SD_Status SD_RESULT SD_Status() { - if (sdio_sd_isReady()) return SD_NODISK; - else return sdio_sd_getProtection() != 0; + if (sdio_sd_isReady()) + return SD_NODISK; + else + return sdio_sd_getProtection() != 0; } //----- SD_GetCID @@ -84,8 +88,10 @@ SD_RESULT SD_GetCID(u8 *cid_data) { //----- SD_GetCSD SD_RESULT SD_GetCSD(u8 *csd_data) { - if (sdio_sd_getCSD(csd_data)) return SD_ERROR; - else return SD_OK; + if (sdio_sd_getCSD(csd_data)) + return SD_ERROR; + else + return SD_OK; } //----- SD_GetCapacity @@ -93,8 +99,10 @@ SD_RESULT SD_GetCapacity(uint32_t *sector_count) { u32 sc = sdio_sd_getCapacity(); *sector_count = sc; - if (sc != 0) return SD_OK; - else return SD_ERROR; + if (sc != 0) + return SD_OK; + else + return SD_ERROR; } //----- SD_ReadBlocks @@ -102,7 +110,7 @@ SD_RESULT SD_ReadBlocks(u32 sector, u8 *data, u32 count) { int rd_count; unsigned char * buf; - if ((u32)data & 3) { + if ((u32) data & 3) { buf = pvPortMalloc(SIZE_BLOCK_ADMA); if (buf == NULL) DBG_SDIO_ERR("Fail to malloc cache for SDIO host!\n"); @@ -119,11 +127,13 @@ SD_RESULT SD_ReadBlocks(u32 sector, u8 *data, u32 count) { data += SIZE_BLOCK_ADMA; } vPortFree(buf); - if (rd_count) return SD_ERROR; + if (rd_count) + return SD_ERROR; return SD_OK; } else { if (sdio_read_blocks(sector, data, count) == 0) { - if (RtlDownSemaWithTimeout(&sdWSema, 1000) == 1) return SD_OK; + if (RtlDownSemaWithTimeout(&sdWSema, 1000) == 1) + return SD_OK; DBG_SDIO_ERR("SD_ReadBlocks timeout\n"); } } diff --git a/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c b/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c index 38daacd..71c7009 100644 --- a/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c +++ b/RTL00_SDKV35a/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c @@ -205,8 +205,9 @@ s8 sdio_write_blocks(uint32_t sector, const uint8_t *buffer, uint32_t count) { } SdioHostAdapter.AdmaDescTbl = gAdmaTbls; } - HAL_Status result = HalSdioHostOp.HalSdioHostWriteBlocksDma(&SdioHostAdapter, - (unsigned long long) sector * SIZE_BLOCK_ADMA, count); + HAL_Status result = HalSdioHostOp.HalSdioHostWriteBlocksDma( + &SdioHostAdapter, (unsigned long long) sector * SIZE_BLOCK_ADMA, + count); if (result) { DBG_SDIO_ERR("write fail(0x%02x)\n", result); return -1; @@ -239,6 +240,7 @@ s8 sdio_sd_init(void) { void sdio_sd_deinit() { if (sdio_status > SDIO_SD_NONE) sdio_status = 1; + sdio_deinit_host(); // add pvvx (fix SD_DeInit()) } //----- @@ -276,7 +278,8 @@ s8 sdio_sd_setProtection(bool protection) { goto LABEL_8; hls = HalSdioHostOp.HalSdioHostSetWriteProtect(&SdioHostAdapter, 1); } else { - if (sd_protected == 0) goto LABEL_8; + if (sd_protected == 0) + goto LABEL_8; hls = HalSdioHostOp.HalSdioHostSetWriteProtect(&SdioHostAdapter, 0); } if (hls) { @@ -284,13 +287,11 @@ s8 sdio_sd_setProtection(bool protection) { result = -1; goto LABEL_17; } -LABEL_8: - sd_protected = protection; -LABEL_7: + LABEL_8: sd_protected = protection; + LABEL_7: DBG_SDIO_INFO("Set SD card Protection done.\n"); result = 0; -LABEL_17: - rtw_mfree(padma, sizeof(ADMA2_DESC_FMT)); + LABEL_17: rtw_mfree(padma, sizeof(ADMA2_DESC_FMT)); return result; } return -1; @@ -364,7 +365,8 @@ u32 sdio_sd_getCapacity(void) { if ((csd[0] & 0xC0) == 64) result = (u16) (csd[9] + 1 + (csd[8] << 8)) << 9; else - result = (4 * csd[7] + ((u32) csd[8] >> 6) + 1 + ((csd[6] & 3) << 10)) + result = (4 * csd[7] + ((u32) csd[8] >> 6) + 1 + + ((csd[6] & 3) << 10)) << ((csd[5] & 0xF) + (csd[10] >> 7) + 2 * (csd[9] & 3) - 8); result *= 2; }