update sdcard driver.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@423 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
8e7da44914
commit
39c53a4b71
|
@ -158,7 +158,7 @@ int mp3_decoder_run(struct mp3_decoder* decoder)
|
|||
if (decoder->read_offset < 0)
|
||||
{
|
||||
/* discard this data */
|
||||
rt_kprintf("outof sync\n");
|
||||
rt_kprintf("outof sync, byte left: %d\n", decoder->bytes_left);
|
||||
|
||||
decoder->bytes_left = 0;
|
||||
return 0;
|
||||
|
@ -439,8 +439,14 @@ void mp3_get_info(const char* filename, struct tag_info* info)
|
|||
rt_size_t fd_fetch(void* parameter, rt_uint8_t *buffer, rt_size_t length)
|
||||
{
|
||||
int fd = (int)parameter;
|
||||
return read(fd, (char*)buffer, length);
|
||||
int read_bytes;
|
||||
|
||||
read_bytes = read(fd, (char*)buffer, length);
|
||||
if (read_bytes <= 0) return 0;
|
||||
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
void mp3(char* filename)
|
||||
{
|
||||
int fd;
|
||||
|
@ -492,6 +498,7 @@ rt_size_t http_data_fetch(void* parameter, rt_uint8_t *buffer, rt_size_t length)
|
|||
{
|
||||
return net_buf_read(buffer, length);
|
||||
}
|
||||
|
||||
void http_mp3(char* url)
|
||||
{
|
||||
struct http_session* session;
|
||||
|
|
|
@ -175,7 +175,7 @@ SD_Error SD_Init(void)
|
|||
SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;
|
||||
SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;
|
||||
SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;
|
||||
SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;
|
||||
SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Enable;
|
||||
SDIO_Init(&SDIO_InitStructure);
|
||||
|
||||
return(errorstatus);
|
||||
|
@ -953,11 +953,21 @@ SD_Error SD_ReadBlock(uint32_t addr, uint32_t *readbuff, uint16_t BlockSize)
|
|||
}
|
||||
else if (DeviceMode == SD_DMA_MODE)
|
||||
{
|
||||
rt_tick_t tick;
|
||||
|
||||
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
|
||||
SDIO_DMACmd(ENABLE);
|
||||
tick = rt_tick_get();
|
||||
DMA_RxConfiguration(readbuff, BlockSize);
|
||||
while (DMA_GetFlagStatus(DMA2_FLAG_TC4) == RESET)
|
||||
{}
|
||||
{
|
||||
if ((TransferError != SD_OK) || (rt_tick_get() - tick > 2))
|
||||
{
|
||||
errorstatus = SD_ERROR;
|
||||
// rt_kprintf("sd error\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(errorstatus);
|
||||
}
|
||||
|
@ -1151,11 +1161,21 @@ SD_Error SD_ReadMultiBlocks(uint32_t addr, uint32_t *readbuff, uint16_t BlockSiz
|
|||
}
|
||||
else if (DeviceMode == SD_DMA_MODE)
|
||||
{
|
||||
rt_tick_t tick;
|
||||
|
||||
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
|
||||
SDIO_DMACmd(ENABLE);
|
||||
tick = rt_tick_get();
|
||||
DMA_RxConfiguration(readbuff, (NumberOfBlocks * BlockSize));
|
||||
while (DMA_GetFlagStatus(DMA2_FLAG_TC4) == RESET)
|
||||
{}
|
||||
{
|
||||
if ((TransferError != SD_OK) || (rt_tick_get() - tick > 2))
|
||||
{
|
||||
errorstatus = SD_ERROR;
|
||||
// rt_kprintf("sd error\n");
|
||||
return errorstatus;
|
||||
}
|
||||
}
|
||||
while ((TransferEnd == 0) && (TransferError == SD_OK))
|
||||
{}
|
||||
if (TransferError != SD_OK)
|
||||
|
@ -3001,10 +3021,13 @@ static rt_err_t rt_sdcard_close(rt_device_t dev)
|
|||
static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
|
||||
{
|
||||
SD_Error status;
|
||||
rt_uint32_t nr = size / SECTOR_SIZE;
|
||||
rt_uint32_t nr = size / SECTOR_SIZE, retry;
|
||||
|
||||
rt_sem_take(&sd_lock, RT_WAITING_FOREVER);
|
||||
|
||||
retry = 3;
|
||||
while(retry)
|
||||
{
|
||||
/* read all sectors */
|
||||
if (((rt_uint32_t)buffer % 4 != 0) ||
|
||||
((rt_uint32_t)buffer > 0x20080000))
|
||||
|
@ -3037,6 +3060,10 @@ static rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_
|
|||
}
|
||||
}
|
||||
|
||||
if (status == SD_OK) break;
|
||||
|
||||
retry --;
|
||||
}
|
||||
rt_sem_release(&sd_lock);
|
||||
|
||||
if (status == SD_OK) return size;
|
||||
|
@ -3110,7 +3137,7 @@ void rt_hw_sdcard_init()
|
|||
status = SD_SelectDeselect((u32) (SDCardInfo.RCA << 16));
|
||||
if (status != SD_OK) goto __return;
|
||||
|
||||
SD_EnableWideBusOperation(SDIO_BusWide_4b);
|
||||
SD_EnableWideBusOperation(SDIO_BusWide_1b);
|
||||
SD_SetDeviceMode(SD_DMA_MODE);
|
||||
|
||||
/* get the first sector to read partition table */
|
||||
|
|
Loading…
Reference in New Issue