walnutcy

FreeRTOS读取SD卡 (原创)

0
阅读(3571)

经过一段时间的努力,目前已可用我的MLC3890读取SD卡了,

采用的文件系统是uC/FS, 由于是之前公司购买的,也不算是盗版,呵呵.
目前只是移植了SD卡的读写,可以通过ARM7读写SD卡,但由于拿到的文件系统仍不支持长名文件名,还得花点心思去看看,看年能不能搞定长文件名支持.
移植SD卡到uC/FS主要需要提供的函数为:
const FS_DEVICE_TYPE FS__mmcdevice_driver =
{
"mmc",
FS_MMC_MAXUNIT,
_FS_MMC_GetStatus,
FS__MMC_ReadSector, //扇区读
FS__MMC_WriteSector,// 扇区写
_FS_MMC_IoCtl,
#if 0 /* not yet released FS_MMC_SUPPORT_BURST */
_FS_MMC_ReadBurst,
_FS_MMC_WriteBurst,
#else
NULL,
NULL,
#endif
_MMC_InitDevice, /* _MMC_InitDevice */
_FS_MMC_InitMedium
};
其实可以直接写一个SD卡的读写驱动往上移,呵呵,毕竟SD卡的读写命令也是蛮多的.
static void _FS_MMC_InitMedium(FS_U8 Unit){
int i;
i = SD_Initialize(); // 激活SD卡,
if (i != 0) { /* init failed, no valid card in slot */
FS_DEBUG_WARN("MMC: Init failure, no valid card found");
}
}
static int _MMC_InitDevice(FS_U8 Unit)
{
SD_HardWareInit(); // add by walter 20080902 IO口初始化,SPI初始化.
return 0;
}
static int _FS_MMC_GetStatus(FS_U8 Unit) {
return SD_ChkCard(); //通过检测电子信号,确认卡在不在卡槽
}
static int _FS_MMC_IoCtl(FS_U8 Unit, FS_I32 Cmd, FS_I32 Aux, void *pBuffer)
{
FS_DEV_INFO * pDevInfo;
FS_USE_PARA(Aux);
switch (Cmd) {
case FS_CMD_CHK_DSKCHANGE: /* check for disk change */
return _DiskHasChanged(Unit);
case FS_CMD_GET_DEVINFO: /* Get general device information */
if(!SD_GetCardInfo())
{ // 主要是为了得到卡的容量等相关信息,供uc/fs调用.
pDevInfo = (FS_DEV_INFO *)pBuffer;
pDevInfo->BytesPerSector = sds.block_len;
pDevInfo->NumSectors = sds.block_num;
}
break;
default:
break;
}
return 0;
}
int FS__MMC_WriteSector(FS_U8 DevIndex, FS_U32 Sector, void* pBuffer)
{
if(SD_WriteBlock(Sector,pBuffer))
return -1;
return 0;
}
static int FS__MMC_ReadSector(FS_U8 DevIndex, FS_U32 Sector, void *pBuffer)
{
if(SD_ReadBlock(Sector,pBuffer))
return -1;
return 0;
}


Baidu
map