前言
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
一、fatfs是什么?
atFs [1] 是一个通用的文件系统(FAT/exFAT)模块,用于在小型嵌入式系统中实现FAT文件系统。 FatFs 组件的编写遵循ANSI C(C89),完全分离于磁盘 I/O 层,因此不依赖于硬件平台。它可以嵌入到资源有限的微控制器中,如 8051, PIC, AVR, ARM, Z80, RX等等,不需要做任何修改
二、移植步骤
1.下载fatfs文件系统源码
下载链接:http://elm-chan.org/fsw/ff/00index_e.html
2.源码结构分析
diskio.c:适配底层硬件接口读写操作,主要移植修改的重点
ff.c:文件系统协议层,几乎不用修改
ffunicode.c:字符编码层,可以选择utf8、ascii、GBK,根据需要选择
3.适配底层接口
1、DSTATUS disk_initialize
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive number to identify the drive */
)
{
uint8_t res = 0;
switch (pdrv)
{
case SD_CARD: /* SD卡 */
res = sd_init(); /* SD卡初始化 */
break;
case EX_FLASH: /* 外部flash */
// norflash_init();
break;
default:
res = 1;
break;
}
if (res)
{
return STA_NOINIT;
}
else
{
return 0; /* 初始化成功*/
}
}
2、DRESULT disk_read
DRESULT disk_read (
BYTE pdrv, /* Physical drive number to identify the drive */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to read */
)
{
uint8_t res = 0;
if (!count)return RES_PARERR; /* count不能等于0,否则返回参数错误 */
switch (pdrv)
{
case SD_CARD: /* SD卡 */
res = sd_read_disk(buff, sector, count);
while (res) /* 读出错 */
{
//printf("sd rd error:%d\r\n", res);
sd_init(); /* 重新初始化SD卡 */
res = sd_read_disk(buff, sector, count);
}
break;
case EX_FLASH:/* 外部flash */
// for (; count > 0; count--)
// {
// norflash_read(buff, SPI_FLASH_FATFS_BASE + sector * SPI_FLASH_SECTOR_SIZE, SPI_FLASH_SECTOR_SIZE);
// sector++;
// buff += SPI_FLASH_SECTOR_SIZE;
// }
// res = 0;
break;
default:
res = 1;
}
/* 处理返回值,将返回值转成ff.c的返回值 */
if (res == 0x00)
{
return RES_OK;
}
else
{
return RES_ERROR;
}
}
3、DRESULT disk_write
DRESULT disk_write (
BYTE pdrv, /* Physical drive number to identify the drive */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address in LBA */
UINT count /* Number of sectors to write */
)
{
uint8_t res = 0;
if (!count)return RES_PARERR; /* count不能等于0,否则返回参数错误 */
switch (pdrv)
{
case SD_CARD: /* SD卡 */
res = sd_write_disk((uint8_t *)buff, sector, count);
while (res) /* 写出错 */
{
//printf("sd wr error:%d\r\n", res);
sd_init(); /* 重新初始化SD卡 */
res = sd_write_disk((uint8_t *)buff, sector, count);
}
break;
case EX_FLASH: /* 外部flash */
// for (; count > 0; count--)
// {
// norflash_write((uint8_t *)buff, SPI_FLASH_FATFS_BASE + sector * SPI_FLASH_SECTOR_SIZE, SPI_FLASH_SECTOR_SIZE);
// sector++;
// buff += SPI_FLASH_SECTOR_SIZE;
// }
// res = 0;
break;
default:
res = 1;
}
/* 处理返回值,将返回值转成ff.c的返回值 */
if (res == 0x00)
{
return RES_OK;
}
else
{
return RES_ERROR;
}
}
总结
重点是底层接口读写适配