mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/fatfs: VFS: internally handle fatfs_mtd_devs
This makes FAT behave more like the other file systems supported by VFS. The `fatfs_mtd_devs` array is populated internally so the application does not have to handle this.
This commit is contained in:
parent
2f6aa71946
commit
ae06265de0
@ -45,8 +45,8 @@ static mtd_sdcard_t mtd_sdcard_dev = {
|
|||||||
.sd_card = &sdcard_spi_devs[0],
|
.sd_card = &sdcard_spi_devs[0],
|
||||||
.params = &sdcard_spi_params[0],
|
.params = &sdcard_spi_params[0],
|
||||||
};
|
};
|
||||||
static mtd_dev_t *mtd0 = (mtd_dev_t*)&mtd_sdcard_dev;
|
static mtd_dev_t *mtd_sdcard = (mtd_dev_t*)&mtd_sdcard_dev;
|
||||||
#define MTD_0 mtd0
|
#define MTD_0 mtd_sdcard
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Flash mount point */
|
/* Flash mount point */
|
||||||
@ -111,9 +111,6 @@ static spiffs_desc_t fs_desc = {
|
|||||||
* this example focus on basic usage, i.e. entire memory used */
|
* this example focus on basic usage, i.e. entire memory used */
|
||||||
static fatfs_desc_t fs_desc;
|
static fatfs_desc_t fs_desc;
|
||||||
|
|
||||||
/* provide mtd devices for use within diskio layer of fatfs */
|
|
||||||
mtd_dev_t *fatfs_mtd_devs[FF_VOLUMES];
|
|
||||||
|
|
||||||
/* fatfs driver will be used */
|
/* fatfs driver will be used */
|
||||||
#define FS_DRIVER fatfs_file_system
|
#define FS_DRIVER fatfs_file_system
|
||||||
#endif
|
#endif
|
||||||
@ -311,12 +308,12 @@ static const shell_command_t shell_commands[] = {
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS) || defined(MODULE_LITTLEFS2))
|
#if defined(MTD_0) && \
|
||||||
|
(defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS) || \
|
||||||
|
defined(MODULE_LITTLEFS2) || defined(MODULE_FATFS_VFS))
|
||||||
/* spiffs and littlefs need a mtd pointer
|
/* spiffs and littlefs need a mtd pointer
|
||||||
* by default the whole memory is used */
|
* by default the whole memory is used */
|
||||||
fs_desc.dev = MTD_0;
|
fs_desc.dev = MTD_0;
|
||||||
#elif defined(MTD_0) && defined(MODULE_FATFS_VFS)
|
|
||||||
fatfs_mtd_devs[fs_desc.vol_idx] = MTD_0;
|
|
||||||
#endif
|
#endif
|
||||||
int res = vfs_mount(&const_mount);
|
int res = vfs_mount(&const_mount);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
static int fatfs_err_to_errno(int32_t err);
|
static int fatfs_err_to_errno(int32_t err);
|
||||||
static void _fatfs_time_to_timespec(WORD fdate, WORD ftime, time_t *time);
|
static void _fatfs_time_to_timespec(WORD fdate, WORD ftime, time_t *time);
|
||||||
|
|
||||||
|
mtd_dev_t *fatfs_mtd_devs[FF_VOLUMES];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Concatenate drive number and path into the buffer provided by fs_desc
|
* @brief Concatenate drive number and path into the buffer provided by fs_desc
|
||||||
*
|
*
|
||||||
@ -46,6 +48,25 @@ static void _build_abs_path(fatfs_desc_t *fs_desc, const char *name)
|
|||||||
fs_desc->vol_idx, name);
|
fs_desc->vol_idx, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _init(vfs_mount_t *mountp)
|
||||||
|
{
|
||||||
|
fatfs_desc_t *fs_desc = mountp->private_data;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < ARRAY_SIZE(fatfs_mtd_devs); ++i) {
|
||||||
|
if (fatfs_mtd_devs[i] == fs_desc->dev) {
|
||||||
|
/* already initialized */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (fatfs_mtd_devs[i] == NULL) {
|
||||||
|
fatfs_mtd_devs[i] = fs_desc->dev;
|
||||||
|
fs_desc->vol_idx = i;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static int _mount(vfs_mount_t *mountp)
|
static int _mount(vfs_mount_t *mountp)
|
||||||
{
|
{
|
||||||
/* if one of the lines below fail to compile you probably need to adjust
|
/* if one of the lines below fail to compile you probably need to adjust
|
||||||
@ -57,6 +78,11 @@ static int _mount(vfs_mount_t *mountp)
|
|||||||
|
|
||||||
fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data;
|
fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data;
|
||||||
|
|
||||||
|
if (_init(mountp)) {
|
||||||
|
DEBUG("can't find free slot in fatfs_mtd_devs\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
_build_abs_path(fs_desc, "");
|
_build_abs_path(fs_desc, "");
|
||||||
|
|
||||||
memset(&fs_desc->fat_fs, 0, sizeof(fs_desc->fat_fs));
|
memset(&fs_desc->fat_fs, 0, sizeof(fs_desc->fat_fs));
|
||||||
|
@ -54,6 +54,7 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
typedef struct fatfs_desc {
|
typedef struct fatfs_desc {
|
||||||
FATFS fat_fs; /**< FatFs work area needed for each volume */
|
FATFS fat_fs; /**< FatFs work area needed for each volume */
|
||||||
|
mtd_dev_t *dev; /**< MTD device to use */
|
||||||
uint8_t vol_idx; /**< low level device that is used by FatFs */
|
uint8_t vol_idx; /**< low level device that is used by FatFs */
|
||||||
|
|
||||||
/** most FatFs file operations need an absolute path. This buffer provides
|
/** most FatFs file operations need an absolute path. This buffer provides
|
||||||
|
@ -54,9 +54,7 @@ static const char test_txt[] = "the test file content 123 abc";
|
|||||||
static const char test_txt2[] = "another text";
|
static const char test_txt2[] = "another text";
|
||||||
static const char test_txt3[] = "hello world for vfs";
|
static const char test_txt3[] = "hello world for vfs";
|
||||||
|
|
||||||
static fatfs_desc_t fatfs = {
|
static fatfs_desc_t fatfs;
|
||||||
.vol_idx = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
static vfs_mount_t _test_vfs_mount = {
|
static vfs_mount_t _test_vfs_mount = {
|
||||||
.mount_point = MNT_PATH,
|
.mount_point = MNT_PATH,
|
||||||
@ -64,9 +62,6 @@ static vfs_mount_t _test_vfs_mount = {
|
|||||||
.private_data = (void *)&fatfs,
|
.private_data = (void *)&fatfs,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* provide mtd devices for use within diskio layer of fatfs */
|
|
||||||
mtd_dev_t *fatfs_mtd_devs[FF_VOLUMES];
|
|
||||||
|
|
||||||
#if defined(MODULE_MTD_NATIVE) || defined(MODULE_MTD_MCI)
|
#if defined(MODULE_MTD_NATIVE) || defined(MODULE_MTD_MCI)
|
||||||
/* mtd devices are provided in the board's board_init.c*/
|
/* mtd devices are provided in the board's board_init.c*/
|
||||||
extern mtd_dev_t *mtd0;
|
extern mtd_dev_t *mtd0;
|
||||||
@ -402,17 +397,16 @@ int main(void)
|
|||||||
mtd_sdcard_devs[i].base.driver = &mtd_sdcard_driver;
|
mtd_sdcard_devs[i].base.driver = &mtd_sdcard_driver;
|
||||||
mtd_sdcard_devs[i].sd_card = &sdcard_spi_devs[i];
|
mtd_sdcard_devs[i].sd_card = &sdcard_spi_devs[i];
|
||||||
mtd_sdcard_devs[i].params = &sdcard_spi_params[i];
|
mtd_sdcard_devs[i].params = &sdcard_spi_params[i];
|
||||||
fatfs_mtd_devs[i] = &mtd_sdcard_devs[i].base;
|
|
||||||
mtd_init(&mtd_sdcard_devs[i].base);
|
mtd_init(&mtd_sdcard_devs[i].base);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MODULE_MTD_NATIVE) || defined(MODULE_MTD_MCI)
|
#if defined(MODULE_MTD_NATIVE) || defined(MODULE_MTD_MCI)
|
||||||
fatfs_mtd_devs[fatfs.vol_idx] = mtd0;
|
fatfs.dev = mtd0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MODULE_MTD_SDCARD)
|
#if defined(MODULE_MTD_SDCARD)
|
||||||
fatfs_mtd_devs[fatfs.vol_idx] = mtd_sdcard;
|
fatfs.dev = mtd_sdcard;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("Tests for FatFs over VFS - test results will be printed "
|
printf("Tests for FatFs over VFS - test results will be printed "
|
||||||
|
Loading…
Reference in New Issue
Block a user