新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > fatfs文件系統(tǒng)移植到STM32F10x

fatfs文件系統(tǒng)移植到STM32F10x

作者: 時間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
//文件系統(tǒng)與SD卡驅(qū)動接口文件diskio.c


#include "diskio.h"
#include "ffconf.h"
#include
#include "MMC_SD.h"

本文引用地址:http://m.butianyuan.cn/article/201611/321912.htm

DSTATUS disk_initialize (
BYTE drv
)
{
int Status;
switch (drv)
{
case 0 :
// Status = MSD0_Init();

Status = SD_Init();

if(Status==0){
return RES_OK;
}else{
return STA_NOINIT;
}
case 1 :
return RES_OK;
case 2 :
return RES_OK;
case 3 :
return RES_OK;
default:
return STA_NOINIT;
}
}


DSTATUS disk_status (
BYTE drv
)
{
switch (drv)
{
case 0 :
return RES_OK;
case 1 :
return RES_OK;
case 2 :
return RES_OK;
default:
return STA_NOINIT;
}
}

DRESULT disk_read (
BYTE drv,
BYTE *buff,
DWORD sector,
BYTE count
)
{
int Status;
if( !count )
{
return RES_PARERR;
}
switch (drv)
{
case 0:
if(count==1)
{
Status =SD_ReadSingleBlock( sector ,buff );
if(Status == 0){
return RES_OK;
}else{
return RES_ERROR;
}
}
else
{
Status = SD_ReadMultiBlock( sector , buff ,count);
if(Status == 0){
return RES_OK;
}else{
return RES_ERROR;
}
}
case 1:
if(count==1)
{
return RES_OK;
}
else
{
return RES_OK;
}

default:
return RES_ERROR;
}
}

#if _READONLY == 0
DRESULT disk_write (
BYTE drv,
const BYTE *buff,
DWORD sector,
BYTE count
)
{
int Status;
if( !count )
{
return RES_PARERR;
}
switch (drv)
{
case 0:
if(count==1)
{
Status = SD_WriteSingleBlock( sector , (uint8_t *)(&buff[0]) );
if(Status == 0){
return RES_OK;
}else{
return RES_ERROR;
}
}
else
{
Status = SD_WriteMultiBlock( sector , (uint8_t *)(&buff[0]) , count );
if(Status == 0){
return RES_OK;
}else{
return RES_ERROR;
}
}
case 1:
if(count==1)
{
return RES_OK;
}
else
{
return RES_OK;
}

default:return RES_ERROR;
}
}
#endif

DRESULT disk_ioctl (
BYTE drv,
BYTE ctrl,
void *buff
)
{
if (drv==0)
{
switch (ctrl)
{
case CTRL_SYNC :
return RES_OK;
case GET_SECTOR_COUNT :
*(DWORD*)buff = 4096;
return RES_OK;
case GET_SECTOR_SIZE :
*(WORD*)buff = 512;
return RES_OK;
case GET_BLOCK_SIZE :
*(WORD*)buff = 512;
return RES_OK;
case CTRL_POWER :
break;
case CTRL_LOCK :
break;
case CTRL_EJECT :
break;

case MMC_GET_TYPE :
break;
case MMC_GET_CSD :
break;
case MMC_GET_CID :
break;
case MMC_GET_OCR :
break;
case MMC_GET_SDSTAT :
break;
}
}
else{
return RES_PARERR;
}
return RES_PARERR;
}



DWORD get_fattime (void)
{

return 0;
}



評論


技術(shù)專區(qū)

關(guān)閉