我用EFSL 文件系统,由于需要对SD卡和USB host使用,在EFSL 的三个接口函数用了表示来判断使用哪种介质,如下:
[mw_shl_code=c,true]esint8 if_initInterface(hwInterface* file, eint8* opts)
{
euint32 sc;
if(MediaType == MEDIATYPE_SD) //SD card
{
if_spiInit(file); // init at low speed //
if (sd_Init(file) < 0)
{
DBG((TXT("Card failed to init, breaking up...\n")));
return(-1);
}
if (sd_State(file) < 0)
{
DBG((TXT("Card didn't return the ready state, breaking up...\n")));
return(-2);
}
sd_getDriveSize(file, &sc);
file->sectorCount = sc / 512;
if ( (sc % 512) != 0)
{
file->sectorCount--;
}
DBG((TXT("Drive Size is %lu Bytes (%lu Sectors)\n"), sc, file->sectorCount));
DBG((TXT("Init done...\n")));
}
else //U-disk
{
/*if(HCD_IsDeviceConnected(&USB_OTG_FS_dev))
{
file->sectorCount = USBH_MSC_Param.MSCapacity;
}*/
}
return(0);
}
esint8 if_writeBuf(hwInterface* file, euint32 address, euint8* buf)
{
esint8 status = -1;
// SD card and U pan //
if(MediaType == MEDIATYPE_SD)
{
return(sd_writeSector(file, address, buf));
}
else
{
/*if(HCD_IsDeviceConnected(&USB_OTG_FS_dev))
{
do
{
status = USBH_MSC_Write10(buf,address,USBH_MSC_PAGE_LENGTH);
USBH_MSC_HandleBOTXfer();
}
while((status == USBH_MSC_BUSY ) && \
(HCD_IsDeviceConnected(&USB_OTG_FS_dev)));
}*/
return(status);
}
}
esint8 if_readBuf(hwInterface* file, euint32 address, euint8* buf)
{
esint8 status = -1;
if(MediaType == MEDIATYPE_SD)
{
return(sd_readSector(file, address, buf, 512));
}
else
{
/*if(HCD_IsDeviceConnected(&USB_OTG_FS_dev))
{
do{
status = USBH_MSC_Read10(buf,address,512);
USBH_MSC_HandleBOTXfer();
}
while((status == USBH_MSC_BUSY ) && (HCD_IsDeviceConnected(&USB_OTG_FS_dev)));
}*/
return(status);
}
}[/mw_shl_code]
用变量MediaType 作标志,else 中的是USB host的处理函数,但是即使是用SD 卡模式,只要不注释else 部分,编译后都无法运行,jtag 仿真无法全速运行。如上,注释掉这三部分,程序没问题,但是我测试过,用SD卡模式根本没用调用else 部分的USB HOST 函数,那注不注释有什么关系呢?但是确实有影响,想不通。
再问一下,有没有好的方法可以让EFSL 支持多个存储设备,比如多个SD卡,或者还有其他存储介质的? |