mirror of
https://github.com/drasko/open-ameba.git
synced 2024-11-22 05:54:17 +00:00
fix error (Ameba SDK)
This commit is contained in:
parent
d34db1740e
commit
7de420b89f
2 changed files with 34 additions and 22 deletions
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
#define SIZE_BLOCK_ADMA 512
|
#define SIZE_BLOCK_ADMA 512
|
||||||
|
|
||||||
|
|
||||||
SemaphoreHandle_t sdWSema;
|
SemaphoreHandle_t sdWSema;
|
||||||
|
|
||||||
void sd_xfer_done_callback(void *obj) {
|
void sd_xfer_done_callback(void *obj) {
|
||||||
|
@ -30,9 +29,11 @@ SD_RESULT SD_WaitReady() {
|
||||||
SD_RESULT SD_Init() {
|
SD_RESULT SD_Init() {
|
||||||
SD_RESULT result;
|
SD_RESULT result;
|
||||||
|
|
||||||
if (sdio_sd_init() != 0) result = SD_INITERR;
|
if (sdio_sd_init() != 0)
|
||||||
|
result = SD_INITERR;
|
||||||
else {
|
else {
|
||||||
if (sdio_sd_getProtection() != 0) result = SD_PROTECTED;
|
if (sdio_sd_getProtection() != 0)
|
||||||
|
result = SD_PROTECTED;
|
||||||
RtlInitSema(&sdWSema, 0);
|
RtlInitSema(&sdWSema, 0);
|
||||||
sdio_sd_hook_xfer_cmp_cb(sd_xfer_done_callback, 0);
|
sdio_sd_hook_xfer_cmp_cb(sd_xfer_done_callback, 0);
|
||||||
sdio_sd_hook_xfer_err_cb(sd_xfer_err_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);
|
// DBG_SDIO_INFO("clk = %d ?\n", CLK);
|
||||||
return SD_ERROR;
|
return SD_ERROR;
|
||||||
}
|
}
|
||||||
if(result) return SD_ERROR;
|
if (result)
|
||||||
|
return SD_ERROR;
|
||||||
return SD_OK;
|
return SD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- SD_Status
|
//----- SD_Status
|
||||||
SD_RESULT SD_Status() {
|
SD_RESULT SD_Status() {
|
||||||
if (sdio_sd_isReady()) return SD_NODISK;
|
if (sdio_sd_isReady())
|
||||||
else return sdio_sd_getProtection() != 0;
|
return SD_NODISK;
|
||||||
|
else
|
||||||
|
return sdio_sd_getProtection() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- SD_GetCID
|
//----- SD_GetCID
|
||||||
|
@ -84,8 +88,10 @@ SD_RESULT SD_GetCID(u8 *cid_data) {
|
||||||
|
|
||||||
//----- SD_GetCSD
|
//----- SD_GetCSD
|
||||||
SD_RESULT SD_GetCSD(u8 *csd_data) {
|
SD_RESULT SD_GetCSD(u8 *csd_data) {
|
||||||
if (sdio_sd_getCSD(csd_data)) return SD_ERROR;
|
if (sdio_sd_getCSD(csd_data))
|
||||||
else return SD_OK;
|
return SD_ERROR;
|
||||||
|
else
|
||||||
|
return SD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- SD_GetCapacity
|
//----- SD_GetCapacity
|
||||||
|
@ -93,8 +99,10 @@ SD_RESULT SD_GetCapacity(uint32_t *sector_count) {
|
||||||
|
|
||||||
u32 sc = sdio_sd_getCapacity();
|
u32 sc = sdio_sd_getCapacity();
|
||||||
*sector_count = sc;
|
*sector_count = sc;
|
||||||
if (sc != 0) return SD_OK;
|
if (sc != 0)
|
||||||
else return SD_ERROR;
|
return SD_OK;
|
||||||
|
else
|
||||||
|
return SD_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- SD_ReadBlocks
|
//----- SD_ReadBlocks
|
||||||
|
@ -119,11 +127,13 @@ SD_RESULT SD_ReadBlocks(u32 sector, u8 *data, u32 count) {
|
||||||
data += SIZE_BLOCK_ADMA;
|
data += SIZE_BLOCK_ADMA;
|
||||||
}
|
}
|
||||||
vPortFree(buf);
|
vPortFree(buf);
|
||||||
if (rd_count) return SD_ERROR;
|
if (rd_count)
|
||||||
|
return SD_ERROR;
|
||||||
return SD_OK;
|
return SD_OK;
|
||||||
} else {
|
} else {
|
||||||
if (sdio_read_blocks(sector, data, count) == 0) {
|
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");
|
DBG_SDIO_ERR("SD_ReadBlocks timeout\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,8 +205,9 @@ s8 sdio_write_blocks(uint32_t sector, const uint8_t *buffer, uint32_t count) {
|
||||||
}
|
}
|
||||||
SdioHostAdapter.AdmaDescTbl = gAdmaTbls;
|
SdioHostAdapter.AdmaDescTbl = gAdmaTbls;
|
||||||
}
|
}
|
||||||
HAL_Status result = HalSdioHostOp.HalSdioHostWriteBlocksDma(&SdioHostAdapter,
|
HAL_Status result = HalSdioHostOp.HalSdioHostWriteBlocksDma(
|
||||||
(unsigned long long) sector * SIZE_BLOCK_ADMA, count);
|
&SdioHostAdapter, (unsigned long long) sector * SIZE_BLOCK_ADMA,
|
||||||
|
count);
|
||||||
if (result) {
|
if (result) {
|
||||||
DBG_SDIO_ERR("write fail(0x%02x)\n", result);
|
DBG_SDIO_ERR("write fail(0x%02x)\n", result);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -239,6 +240,7 @@ s8 sdio_sd_init(void) {
|
||||||
void sdio_sd_deinit() {
|
void sdio_sd_deinit() {
|
||||||
if (sdio_status > SDIO_SD_NONE)
|
if (sdio_status > SDIO_SD_NONE)
|
||||||
sdio_status = 1;
|
sdio_status = 1;
|
||||||
|
sdio_deinit_host(); // add pvvx (fix SD_DeInit())
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----
|
//-----
|
||||||
|
@ -276,7 +278,8 @@ s8 sdio_sd_setProtection(bool protection) {
|
||||||
goto LABEL_8;
|
goto LABEL_8;
|
||||||
hls = HalSdioHostOp.HalSdioHostSetWriteProtect(&SdioHostAdapter, 1);
|
hls = HalSdioHostOp.HalSdioHostSetWriteProtect(&SdioHostAdapter, 1);
|
||||||
} else {
|
} else {
|
||||||
if (sd_protected == 0) goto LABEL_8;
|
if (sd_protected == 0)
|
||||||
|
goto LABEL_8;
|
||||||
hls = HalSdioHostOp.HalSdioHostSetWriteProtect(&SdioHostAdapter, 0);
|
hls = HalSdioHostOp.HalSdioHostSetWriteProtect(&SdioHostAdapter, 0);
|
||||||
}
|
}
|
||||||
if (hls) {
|
if (hls) {
|
||||||
|
@ -284,13 +287,11 @@ s8 sdio_sd_setProtection(bool protection) {
|
||||||
result = -1;
|
result = -1;
|
||||||
goto LABEL_17;
|
goto LABEL_17;
|
||||||
}
|
}
|
||||||
LABEL_8:
|
LABEL_8: sd_protected = protection;
|
||||||
sd_protected = protection;
|
|
||||||
LABEL_7:
|
LABEL_7:
|
||||||
DBG_SDIO_INFO("Set SD card Protection done.\n");
|
DBG_SDIO_INFO("Set SD card Protection done.\n");
|
||||||
result = 0;
|
result = 0;
|
||||||
LABEL_17:
|
LABEL_17: rtw_mfree(padma, sizeof(ADMA2_DESC_FMT));
|
||||||
rtw_mfree(padma, sizeof(ADMA2_DESC_FMT));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -364,7 +365,8 @@ u32 sdio_sd_getCapacity(void) {
|
||||||
if ((csd[0] & 0xC0) == 64)
|
if ((csd[0] & 0xC0) == 64)
|
||||||
result = (u16) (csd[9] + 1 + (csd[8] << 8)) << 9;
|
result = (u16) (csd[9] + 1 + (csd[8] << 8)) << 9;
|
||||||
else
|
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);
|
<< ((csd[5] & 0xF) + (csd[10] >> 7) + 2 * (csd[9] & 3) - 8);
|
||||||
result *= 2;
|
result *= 2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue