新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2017-7-19
- 在线时间
- 2 小时
|
楼主 |
发表于 2017-7-19 13:24:39
|
显示全部楼层
本帖最后由 weihua8206 于 2017-7-19 13:38 编辑
代码如下所示:其中FTL的函数完全是按照原子哥的例程做的
/* Private function prototypes -----------------------------------------------*/
DSTATUS NAND_initialize (void);
DSTATUS NAND_status (void);
DRESULT NAND_read (BYTE*, DWORD, BYTE);
#if _USE_WRITE == 1
DRESULT NAND_write (const BYTE*, DWORD, BYTE);
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
DRESULT NAND_ioctl (BYTE, void*);
#endif /* _USE_IOCTL == 1 */
Diskio_drvTypeDef NAND_Driver =
{
NAND_initialize,
NAND_status,
NAND_read,
#if _USE_WRITE == 1
NAND_write,
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
NAND_ioctl,
#endif /* _USE_IOCTL == 1 */
};
DSTATUS NAND_initialize(void)
{
if(FTL_Init()) {return RES_ERROR;}
else {return RES_OK;}
}
DSTATUS NAND_status(void)
{
DRESULT res = RES_ERROR;
if(NAND_ReadStatus() == NAND_READY)
{
res = RES_OK;
}
else
{
res = RES_ERROR;
}
return res;
}
DRESULT NAND_read(BYTE *buff, DWORD sector, BYTE count)
{
DRESULT res = RES_ERROR;
res = FTL_ReadSectors(buff,sector,512,count); //读取数据
if(res == 0x00) {return RES_OK;}
else {return RES_ERROR;}
}
#if _USE_WRITE == 1
DRESULT NAND_write(const BYTE *buff, DWORD sector, BYTE count)
{
DRESULT res = RES_ERROR;
res=FTL_WriteSectors((u8*)buff,sector,512,count);//写入数据
if(res == 0x00) {return RES_OK;}
else {return RES_ERROR;}
}
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
DRESULT NAND_ioctl(BYTE cmd, void *buff)
{
DRESULT res = RES_ERROR;
switch(cmd)
{
case CTRL_SYNC:
res = RES_OK;
break;
case GET_SECTOR_SIZE:
*(WORD*)buff = 512; //NAND FLASH扇区强制为512字节大小
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(WORD*)buff = nand_dev.page_mainsize/512;//block大小,定义成一个page的大小
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = nand_dev.valid_blocknum*nand_dev.block_pagenum*nand_dev.page_mainsize/512;//NAND FLASH的总扇区大小
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
}
#endif /* _USE_IOCTL == 1 */
|
|