CELIS/SYSTEM/FATFS/src/diskio.c

191 lines
5.5 KiB
C
Raw Normal View History

#include "sd.h"
#include "diskio.h"
//#include "mymalloc.h"
#define SD_CARD 0 //SD<53><44>,<2C><><EFBFBD><EFBFBD>Ϊ0
#define SD_CARD 0 //SD<53><44>,<2C><><EFBFBD><EFBFBD>Ϊ0
#define FLASH_SECTOR_SIZE 512 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
#define FLASH_BLOCK_SIZE 8 //ÿ<><C3BF>BLOCK<43><4B>8<EFBFBD><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>̽ӿں<D3BF><DABA><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>pdrv<72><76><EFBFBD><EFBFBD><EFBFBD>̱<EFBFBD><CCB1><EFBFBD> */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״ֵ̬ */
/*-------------------------------------------------*/
DSTATUS disk_initialize (BYTE pdrv)
{
u8 res=0;
switch(pdrv)
{
case SD_CARD://SD<53><44>
res = SD_Init();
if(res)//STM32 SPI<50><49>bug,<2C><>sd<73><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>SPI<50><49>д<EFBFBD>
{
SD_SPI_ReadWriteByte(0xff);//<2F><EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>ʱ<EFBFBD><CAB1>
}
break;
default:
res=1;
}
if(res)return STA_NOINIT;
else return 0; //<2F><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
}
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>״̬<D7B4>ӿں<D3BF><DABA><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>pdrv<72><76><EFBFBD><EFBFBD><EFBFBD>̱<EFBFBD><CCB1><EFBFBD> */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״ֵ̬ */
/*-------------------------------------------------*/
DSTATUS disk_status (BYTE pdrv)
{
return 0;
}
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿں<D3BF><DABA><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>pdrv<72><76><EFBFBD><EFBFBD><EFBFBD>̱<EFBFBD><CCB1><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>buff: <20><><EFBFBD>յ<EFBFBD>ַ */
/*<2A><> <20><><EFBFBD><EFBFBD>count:<3A><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״ֵ̬ */
/*-------------------------------------------------*/
DRESULT disk_read (BYTE pdrv,BYTE *buff,DWORD sector,UINT count)
{
u8 res=0;
if (!count)return RES_PARERR;//count<6E><74><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD>򷵻ز<F2B7B5BB><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
switch(pdrv)
{
case SD_CARD://SD<53><44>
res=SD_ReadDisk(buff,sector,count);
if(res)//STM32 SPI<50><49>bug,<2C><>sd<73><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>SPI<50><49>д<EFBFBD>
{
SD_SPI_ReadWriteByte(0xff);//<2F><EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>ʱ<EFBFBD><CAB1>
}
break;
default:
res=1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>SPI_SD_driver.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵת<D6B5><D7AA>ff.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵ
if(res==0x00)return RES_OK;
else return RES_ERROR;
}
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ӿں<D3BF><DABA><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>pdrv<72><76><EFBFBD><EFBFBD><EFBFBD>̱<EFBFBD><CCB1><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>buff: д<><EFBFBD><EBBBBA><EFBFBD><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>count:<3A><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״ֵ̬ */
/*-------------------------------------------------*/
#if _USE_WRITE //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD>ޣ<EFBFBD>"diskio.h"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DRESULT disk_write (BYTE pdrv,const BYTE *buff,DWORD sector,UINT count)
{
u8 res=0;
if (!count)return RES_PARERR;//count<6E><74><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD>򷵻ز<F2B7B5BB><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
switch(pdrv)
{
case SD_CARD://SD<53><44>
res=SD_WriteDisk((u8*)buff,sector,count);
break;
default:
res=1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>SPI_SD_driver.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵת<D6B5><D7AA>ff.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵ
if(res == 0x00)return RES_OK;
else return RES_ERROR;
}
#endif /* _READONLY */
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>pdrv<72><76><EFBFBD><EFBFBD><EFBFBD>̱<EFBFBD><CCB1><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>ctrl:<3A><><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>buff:<3A><><EFBFBD><EFBFBD>/<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״ֵ̬ */
/*-------------------------------------------------*/
#if _USE_IOCTL //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD>ޣ<EFBFBD>"diskio.h"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DRESULT disk_ioctl (BYTE pdrv,BYTE cmd,void *buff)
{
DRESULT res;
if(pdrv==SD_CARD)//SD<53><44>
{
switch(cmd)
{
case CTRL_SYNC:
//SD_CS=0;
if(SD_WaitReady()==0)
res = RES_OK;
else
res = RES_ERROR;
//SD_CS=1;
break;
case GET_SECTOR_SIZE:
*(WORD*)buff = 512;
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(WORD*)buff = 8;
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = SD_GetSectorCount();
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
}else res=RES_ERROR;//<2F><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>֧<EFBFBD><D6A7>
return res;
}
#endif
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
/*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5> */
/*-------------------------------------------------*/
DWORD get_fattime (void)
{
return 0; //ûʵ<C3BB><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
#include <stdlib.h>
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD>size<7A><65><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ŀռ<C4BF><D5BC><EFBFBD>С */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>ָ<EFBFBD><D6B8> */
/*-------------------------------------------------*/
void *ff_memalloc (UINT size)
{
return (void*)malloc(size);
}
/*-------------------------------------------------*/
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD> */
/*<2A><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ͷŵ<CDB7><C5B5>ڴ<EFBFBD><DAB4><EFBFBD>ָ<EFBFBD><D6B8> */
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> */
/*-------------------------------------------------*/
void ff_memfree (void* mf)
{
free(mf);
}