forked from xuos/xiuos
feat support sdio read/write/configure function
This commit is contained in:
parent
7b32e213ce
commit
d7507bcd6e
|
@ -40,6 +40,13 @@ menu "ok1052-c feature"
|
||||||
int "stack size for interrupt"
|
int "stack size for interrupt"
|
||||||
default 4096
|
default 4096
|
||||||
|
|
||||||
|
menu "config board peripheral"
|
||||||
|
config MOUNT_SDCARD
|
||||||
|
bool "mount cd card"
|
||||||
|
default n
|
||||||
|
select BSP_USING_SDIO
|
||||||
|
endmenu
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,24 @@ extern int ExtSramInit(void);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(FS_VFS) && defined(MOUNT_SDCARD)
|
||||||
|
#include <iot-vfs.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Mount SD card
|
||||||
|
* @return 0
|
||||||
|
*/
|
||||||
|
int MountSDCard(void)
|
||||||
|
{
|
||||||
|
if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, FSTYPE_FATFS, "/") == 0)
|
||||||
|
KPrintf("sd card mount to '/'");
|
||||||
|
else
|
||||||
|
KPrintf("sd card mount to '/' failed!");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
|
#if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
|
||||||
#include "fsl_lpi2c.h"
|
#include "fsl_lpi2c.h"
|
||||||
#endif /* SDK_I2C_BASED_COMPONENT_USED */
|
#endif /* SDK_I2C_BASED_COMPONENT_USED */
|
||||||
|
@ -624,13 +642,11 @@ void InitBoardHardware()
|
||||||
CLOCK_SetMux(kCLOCK_SemcMux, 1);
|
CLOCK_SetMux(kCLOCK_SemcMux, 1);
|
||||||
CLOCK_SetDiv(kCLOCK_SemcDiv, 1);
|
CLOCK_SetDiv(kCLOCK_SemcDiv, 1);
|
||||||
|
|
||||||
if (BOARD_InitSEMC() != kStatus_Success)
|
if (BOARD_InitSEMC() != kStatus_Success) {
|
||||||
{
|
|
||||||
KPrintf("\r\n SEMC Init Failed\r\n");
|
KPrintf("\r\n SEMC Init Failed\r\n");
|
||||||
}
|
}
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
ExtSramInit();
|
ExtSramInit();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -188,16 +188,12 @@ static uint32 SdioConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||||
NULL_PARAM_CHECK(configure_info);
|
NULL_PARAM_CHECK(configure_info);
|
||||||
|
|
||||||
if (configure_info->configure_cmd == OPER_BLK_GETGEOME) {
|
if (configure_info->configure_cmd == OPER_BLK_GETGEOME) {
|
||||||
// NULL_PARAM_CHECK(configure_info->private_data);
|
NULL_PARAM_CHECK(configure_info->private_data);
|
||||||
// struct DeviceBlockArrange *args = (struct DeviceBlockArrange *)configure_info->private_data;
|
struct DeviceBlockArrange *args = (struct DeviceBlockArrange *)configure_info->private_data;
|
||||||
// //SD_GetCardInfo(&SDCardInfo);
|
|
||||||
|
|
||||||
// // args->size_perbank = SDCardInfo.CardBlockSize;
|
args->size_perbank = g_sd.blockSize;
|
||||||
// // args->block_size = SDCardInfo.CardBlockSize;
|
args->block_size = g_sd.blockSize;
|
||||||
// // if(SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
|
args->bank_num = g_sd.blockCount;
|
||||||
// // args->bank_num = (SDCardInfo.SD_csd.DeviceSize + 1) * 1024;
|
|
||||||
// // else
|
|
||||||
// // args->bank_num = SDCardInfo.CardCapacity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
|
@ -230,37 +226,18 @@ static uint32 SdioClose(void *dev)
|
||||||
static uint32 SdioRead(void *dev, struct BusBlockReadParam *read_param)
|
static uint32 SdioRead(void *dev, struct BusBlockReadParam *read_param)
|
||||||
{
|
{
|
||||||
uint8 ret = EOK;
|
uint8 ret = EOK;
|
||||||
|
uint32 sector = read_param->pos;
|
||||||
|
uint32 block_num = read_param->size;
|
||||||
|
uint8 *read_buffer = (uint8 *)read_param->buffer;
|
||||||
|
|
||||||
KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
||||||
|
|
||||||
// if (((uint32)read_param->buffer & 0x03) != 0) {
|
if (kStatus_Success != SD_ReadBlocks(&g_sd, read_buffer, sector, block_num)) {
|
||||||
// uint64_t sector;
|
KPrintf("Read multiple data blocks failed.\r\n");
|
||||||
// uint8_t* temp;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// sector = (uint64_t)read_param->pos * SDCARD_SECTOR_SIZE;
|
KSemaphoreAbandon(sd_lock);
|
||||||
// temp = (uint8_t*)read_param->buffer;
|
|
||||||
|
|
||||||
// for (uint8 i = 0; i < read_param->size; i++) {
|
|
||||||
// ret = SD_ReadBlock((uint8_t *)SDBuffer, sector, 1);
|
|
||||||
// if(ret != SD_OK) {
|
|
||||||
// KPrintf("read failed: %d, buffer 0x%08x\n", ret, temp);
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// memcpy(temp, SDBuffer, SDCARD_SECTOR_SIZE);
|
|
||||||
|
|
||||||
// sector += SDCARD_SECTOR_SIZE;
|
|
||||||
// temp += SDCARD_SECTOR_SIZE;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// ret = SD_ReadBlock((uint8_t *)read_param->buffer, (uint64_t)read_param->pos * SDCARD_SECTOR_SIZE, read_param->size);
|
|
||||||
// if (ret != SD_OK) {
|
|
||||||
// KPrintf("read failed: %d, buffer 0x%08x\n", ret, (uint8_t *)read_param->buffer);
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// KSemaphoreAbandon(sd_lock);
|
|
||||||
|
|
||||||
return read_param->size;
|
return read_param->size;
|
||||||
}
|
}
|
||||||
|
@ -268,35 +245,16 @@ static uint32 SdioRead(void *dev, struct BusBlockReadParam *read_param)
|
||||||
static uint32 SdioWrite(void *dev, struct BusBlockWriteParam *write_param)
|
static uint32 SdioWrite(void *dev, struct BusBlockWriteParam *write_param)
|
||||||
{
|
{
|
||||||
uint8 ret = EOK;
|
uint8 ret = EOK;
|
||||||
|
uint32 sector = write_param->pos;
|
||||||
|
uint32 block_num = write_param->size;
|
||||||
|
const uint8 *write_buffer = (uint8 *)write_param->buffer;
|
||||||
|
|
||||||
// KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
||||||
|
|
||||||
// if (((uint32)write_param->buffer & 0x03) != 0) {
|
if (kStatus_Success != SD_WriteBlocks(&g_sd, write_buffer, sector, block_num)) {
|
||||||
// uint64_t sector;
|
KPrintf("Write multiple data blocks failed.\r\n");
|
||||||
// uint8_t* temp;
|
return 0;
|
||||||
|
}
|
||||||
// sector = (uint64_t)write_param->pos * SDCARD_SECTOR_SIZE;
|
|
||||||
// temp = (uint8_t*)write_param->buffer;
|
|
||||||
|
|
||||||
// for (uint8 i = 0; i < write_param->size; i++) {
|
|
||||||
// memcpy(SDBuffer, temp, SDCARD_SECTOR_SIZE);
|
|
||||||
|
|
||||||
// ret = SD_WriteBlock((uint8_t *)SDBuffer, sector, 1);
|
|
||||||
// if(ret != SD_OK) {
|
|
||||||
// KPrintf("write failed: %d, buffer 0x%08x\n", ret, temp);
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// sector += SDCARD_SECTOR_SIZE;
|
|
||||||
// temp += SDCARD_SECTOR_SIZE;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// ret = SD_WriteBlock((uint8_t *)write_param->buffer, (uint64_t)write_param->pos * SDCARD_SECTOR_SIZE, write_param->size);
|
|
||||||
// if (ret != SD_OK) {
|
|
||||||
// KPrintf("write failed: %d, buffer 0x%08x\n", ret, (uint8_t *)write_param->buffer);
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
KSemaphoreAbandon(sd_lock);
|
KSemaphoreAbandon(sd_lock);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue