git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15154 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
ab568fd909
commit
1b3d34696d
|
@ -111,6 +111,13 @@
|
||||||
#define DRV_CFG_FATFS_FILE_NODES_NUM 2
|
#define DRV_CFG_FATFS_FILE_NODES_NUM 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mount mode for FatFS.
|
||||||
|
*/
|
||||||
|
#if !defined(DRV_CFG_FATFS_MOUNT_MODE) || defined(__DOXYGEN__)
|
||||||
|
#define DRV_CFG_FATFS_MOUNT_MODE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* VFSCONF_H */
|
#endif /* VFSCONF_H */
|
||||||
|
|
|
@ -111,6 +111,13 @@
|
||||||
#define DRV_CFG_FATFS_FILE_NODES_NUM 2
|
#define DRV_CFG_FATFS_FILE_NODES_NUM 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mount mode for FatFS.
|
||||||
|
*/
|
||||||
|
#if !defined(DRV_CFG_FATFS_MOUNT_MODE) || defined(__DOXYGEN__)
|
||||||
|
#define DRV_CFG_FATFS_MOUNT_MODE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* VFSCONF_H */
|
#endif /* VFSCONF_H */
|
||||||
|
|
|
@ -229,7 +229,7 @@ int main(void) {
|
||||||
sdStart(&PORTAB_SD1, NULL);
|
sdStart(&PORTAB_SD1, NULL);
|
||||||
nullObjectInit(&nullstream);
|
nullObjectInit(&nullstream);
|
||||||
|
|
||||||
/* Initializing an overlay VFS object as a root, bo overlaid driver,
|
/* Initializing an overlay VFS object as a root, no overlaid driver,
|
||||||
no need for a name.*/
|
no need for a name.*/
|
||||||
drvOverlayObjectInit(&vfs_root, NULL, "");
|
drvOverlayObjectInit(&vfs_root, NULL, "");
|
||||||
|
|
||||||
|
|
|
@ -34,58 +34,6 @@
|
||||||
/* Module local definitions. */
|
/* Module local definitions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Number of directory nodes pre-allocated in the pool.
|
|
||||||
*/
|
|
||||||
#define DRV_DIR_NODES_NUM 1
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Number of file nodes pre-allocated in the pool.
|
|
||||||
*/
|
|
||||||
#define DRV_FILE_NODES_NUM 2
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief @p vfs_fatfs_driver_t specific methods.
|
|
||||||
*/
|
|
||||||
#define __vfs_fatfs_driver_methods \
|
|
||||||
__vfs_driver_methods
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief @p vfs_fatfs_driver_t specific data.
|
|
||||||
*/
|
|
||||||
#define __vfs_fatfs_driver_data \
|
|
||||||
__vfs_driver_data \
|
|
||||||
memory_pool_t file_nodes_pool; \
|
|
||||||
memory_pool_t dir_nodes_pool; \
|
|
||||||
memory_pool_t info_nodes_pool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief @p vfs_fatfs_dir_node_t specific methods.
|
|
||||||
*/
|
|
||||||
#define __vfs_fatfs_dir_node_methods \
|
|
||||||
__vfs_directory_node_methods
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief @p vfs_fatfs_dir_node_t specific data.
|
|
||||||
*/
|
|
||||||
#define __vfs_fatfs_dir_node_data \
|
|
||||||
__vfs_directory_node_data \
|
|
||||||
DIR dir;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief @p vfs_fatfs_file_node_t specific methods.
|
|
||||||
*/
|
|
||||||
#define __vfs_fatfs_file_node_methods \
|
|
||||||
__vfs_file_node_methods
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief @p vfs_fatfs_file_node_t specific data.
|
|
||||||
*/
|
|
||||||
#define __vfs_fatfs_file_node_data \
|
|
||||||
__vfs_file_node_data \
|
|
||||||
FIL file; \
|
|
||||||
BaseSequentialStream *stream;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module exported variables. */
|
/* Module exported variables. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -139,8 +87,8 @@ static const struct vfs_fatfs_file_node_vmt file_node_vmt = {
|
||||||
.file_getsize = node_file_getsize
|
.file_getsize = node_file_getsize
|
||||||
};
|
};
|
||||||
|
|
||||||
static vfs_fatfs_dir_node_t drv_dir_nodes[DRV_DIR_NODES_NUM];
|
static vfs_fatfs_dir_node_t drv_dir_nodes[DRV_CFG_FATFS_DIR_NODES_NUM];
|
||||||
static vfs_fatfs_file_node_t drv_file_nodes[DRV_FILE_NODES_NUM];
|
static vfs_fatfs_file_node_t drv_file_nodes[DRV_CFG_FATFS_FILE_NODES_NUM];
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module local functions. */
|
/* Module local functions. */
|
||||||
|
@ -335,19 +283,19 @@ static void node_file_release(void *instance) {
|
||||||
static BaseSequentialStream *node_file_get_stream(void *instance) {
|
static BaseSequentialStream *node_file_get_stream(void *instance) {
|
||||||
vfs_fatfs_file_node_t *fffnp = (vfs_fatfs_file_node_t *)instance;
|
vfs_fatfs_file_node_t *fffnp = (vfs_fatfs_file_node_t *)instance;
|
||||||
|
|
||||||
return fffnp->stream;
|
return &fffnp->stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t node_file_read(void *instance, uint8_t *buf, size_t n) {
|
static ssize_t node_file_read(void *instance, uint8_t *buf, size_t n) {
|
||||||
vfs_fatfs_file_node_t *fffnp = (vfs_fatfs_file_node_t *)instance;
|
vfs_fatfs_file_node_t *fffnp = (vfs_fatfs_file_node_t *)instance;
|
||||||
|
|
||||||
return streamRead(fffnp->stream, buf, n);
|
return streamRead(&fffnp->stream, buf, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t node_file_write(void *instance, const uint8_t *buf, size_t n) {
|
static ssize_t node_file_write(void *instance, const uint8_t *buf, size_t n) {
|
||||||
vfs_fatfs_file_node_t *fffnp = (vfs_fatfs_file_node_t *)instance;
|
vfs_fatfs_file_node_t *fffnp = (vfs_fatfs_file_node_t *)instance;
|
||||||
|
|
||||||
return streamWrite(fffnp->stream, buf, n);
|
return streamWrite(&fffnp->stream, buf, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static msg_t node_file_setpos(void *instance, vfs_offset_t offset) {
|
static msg_t node_file_setpos(void *instance, vfs_offset_t offset) {
|
||||||
|
@ -379,13 +327,13 @@ static vfs_offset_t node_file_getsize(void *instance) {
|
||||||
/**
|
/**
|
||||||
* @brief VFS FatFS object initialization.
|
* @brief VFS FatFS object initialization.
|
||||||
*
|
*
|
||||||
* @param[out] vodp pointer to a @p vfs_fatfs_driver_t structure
|
* @param[out] ffdp pointer to a @p vfs_fatfs_driver_t structure
|
||||||
* @param[in] rootname name to be attributed to this object
|
* @param[in] rootname name to be attributed to this object
|
||||||
* @return A pointer to this initialized object.
|
* @return A pointer to this initialized object.
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
vfs_driver_t *drvFatfsObjectInit(vfs_fatfs_driver_t *ffdp,
|
vfs_driver_t *drvFatFSObjectInit(vfs_fatfs_driver_t *ffdp,
|
||||||
const char *rootname) {
|
const char *rootname) {
|
||||||
|
|
||||||
ffdp->vmt = &driver_vmt;
|
ffdp->vmt = &driver_vmt;
|
||||||
|
@ -405,12 +353,40 @@ vfs_driver_t *drvFatfsObjectInit(vfs_fatfs_driver_t *ffdp,
|
||||||
/* Preloading pools.*/
|
/* Preloading pools.*/
|
||||||
chPoolLoadArray(&ffdp->dir_nodes_pool,
|
chPoolLoadArray(&ffdp->dir_nodes_pool,
|
||||||
drv_dir_nodes,
|
drv_dir_nodes,
|
||||||
DRV_DIR_NODES_NUM);
|
DRV_CFG_FATFS_DIR_NODES_NUM);
|
||||||
chPoolLoadArray(&ffdp->file_nodes_pool,
|
chPoolLoadArray(&ffdp->file_nodes_pool,
|
||||||
drv_file_nodes,
|
drv_file_nodes,
|
||||||
DRV_FILE_NODES_NUM);
|
DRV_CFG_FATFS_FILE_NODES_NUM);
|
||||||
|
|
||||||
return (vfs_driver_t *)ffdp;
|
return (vfs_driver_t *)ffdp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mounts a FatFS volume.
|
||||||
|
*
|
||||||
|
* @param[in] ffdp pointer to a @p vfs_fatfs_driver_t structure
|
||||||
|
* @return The operation result.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
msg_t drvFatFSMount(vfs_fatfs_driver_t *ffdp) {
|
||||||
|
|
||||||
|
return translate_error(f_mount(&ffdp->fs,
|
||||||
|
ffdp->rootname,
|
||||||
|
DRV_CFG_FATFS_MOUNT_MODE));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unmounts a FatFS volume.
|
||||||
|
*
|
||||||
|
* @param[in] ffdp pointer to a @p vfs_fatfs_driver_t structure
|
||||||
|
* @return The operation result.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
msg_t drvFatFSUnmount(vfs_fatfs_driver_t *ffdp) {
|
||||||
|
|
||||||
|
return translate_error(f_unmount(ffdp->rootname));
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -51,6 +51,10 @@
|
||||||
#error "DRV_CFG_FATFS_FILE_NODES_NUM not defined in vfsconf.h"
|
#error "DRV_CFG_FATFS_FILE_NODES_NUM not defined in vfsconf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(DRV_CFG_FATFS_MOUNT_MODE)
|
||||||
|
#error "DRV_CFG_FATFS_MOUNT_MODE not defined in vfsconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if DRV_CFG_FATFS_DIR_NODES_NUM < 1
|
#if DRV_CFG_FATFS_DIR_NODES_NUM < 1
|
||||||
#error "invalid value for DRV_CFG_FATFS_DIR_NODES_NUM"
|
#error "invalid value for DRV_CFG_FATFS_DIR_NODES_NUM"
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,6 +63,10 @@
|
||||||
#error "invalid value for DRV_CFG_FATFS_FILE_NODES_NUM"
|
#error "invalid value for DRV_CFG_FATFS_FILE_NODES_NUM"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (DRV_CFG_FATFS_MOUNT_MODE < 0) || (DRV_CFG_FATFS_MOUNT_MODE > 1)
|
||||||
|
#error "invalid value for DRV_CFG_FATFS_MOUNT_MODE"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module data structures and types. */
|
/* Module data structures and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -106,7 +114,7 @@ typedef struct vfs_fatfs_dir_node {
|
||||||
#define __vfs_fatfs_file_node_data \
|
#define __vfs_fatfs_file_node_data \
|
||||||
__vfs_file_node_data \
|
__vfs_file_node_data \
|
||||||
FIL file; \
|
FIL file; \
|
||||||
BaseSequentialStream *stream;
|
BaseSequentialStream stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief @p vfs_fatfs_file_node_t virtual methods table.
|
* @brief @p vfs_fatfs_file_node_t virtual methods table.
|
||||||
|
@ -139,7 +147,8 @@ typedef struct vfs_fatfs_file_node {
|
||||||
__vfs_driver_data \
|
__vfs_driver_data \
|
||||||
memory_pool_t file_nodes_pool; \
|
memory_pool_t file_nodes_pool; \
|
||||||
memory_pool_t dir_nodes_pool; \
|
memory_pool_t dir_nodes_pool; \
|
||||||
memory_pool_t info_nodes_pool;
|
memory_pool_t info_nodes_pool; \
|
||||||
|
FATFS fs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief @p vfs_fatfs_driver_t virtual methods table.
|
* @brief @p vfs_fatfs_driver_t virtual methods table.
|
||||||
|
@ -170,8 +179,10 @@ typedef struct vfs_drv_streams {
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
vfs_driver_t *drvFatfsObjectInit(vfs_fatfs_driver_t *ffdp,
|
vfs_driver_t *drvFatFSObjectInit(vfs_fatfs_driver_t *ffdp,
|
||||||
const char *rootname);
|
const char *rootname);
|
||||||
|
msg_t drvFatFSMount(vfs_fatfs_driver_t *ffdp);
|
||||||
|
msg_t drvFatFSUnmount(vfs_fatfs_driver_t *ffdp);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,6 +111,13 @@
|
||||||
#define DRV_CFG_FATFS_FILE_NODES_NUM 2
|
#define DRV_CFG_FATFS_FILE_NODES_NUM 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mount mode for FatFS.
|
||||||
|
*/
|
||||||
|
#if !defined(DRV_CFG_FATFS_MOUNT_MODE) || defined(__DOXYGEN__)
|
||||||
|
#define DRV_CFG_FATFS_MOUNT_MODE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* VFSCONF_H */
|
#endif /* VFSCONF_H */
|
||||||
|
|
Loading…
Reference in New Issue