diff --git a/demos/STM32/RT-VFS-FATFS/cfg/stm32g474re_nucleo64/vfsconf.h b/demos/STM32/RT-VFS-FATFS/cfg/stm32g474re_nucleo64/vfsconf.h index 0dae7c97b..bf08e04e5 100644 --- a/demos/STM32/RT-VFS-FATFS/cfg/stm32g474re_nucleo64/vfsconf.h +++ b/demos/STM32/RT-VFS-FATFS/cfg/stm32g474re_nucleo64/vfsconf.h @@ -90,6 +90,29 @@ /** @} */ +/*===========================================================================*/ +/** + * @name FatFS driver settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Number of directory nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_FATFS_DIR_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_FATFS_DIR_NODES_NUM 1 +#endif + +/** + * @brief Number of file nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_FATFS_FILE_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_FATFS_FILE_NODES_NUM 2 +#endif + +/** @} */ + #endif /* VFSCONF_H */ /** @} */ diff --git a/demos/STM32/RT-VFS-FATFS/cfg/stm32l4r9ai_discovery/vfsconf.h b/demos/STM32/RT-VFS-FATFS/cfg/stm32l4r9ai_discovery/vfsconf.h index 0dae7c97b..bf08e04e5 100644 --- a/demos/STM32/RT-VFS-FATFS/cfg/stm32l4r9ai_discovery/vfsconf.h +++ b/demos/STM32/RT-VFS-FATFS/cfg/stm32l4r9ai_discovery/vfsconf.h @@ -90,6 +90,29 @@ /** @} */ +/*===========================================================================*/ +/** + * @name FatFS driver settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Number of directory nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_FATFS_DIR_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_FATFS_DIR_NODES_NUM 1 +#endif + +/** + * @brief Number of file nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_FATFS_FILE_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_FATFS_FILE_NODES_NUM 2 +#endif + +/** @} */ + #endif /* VFSCONF_H */ /** @} */ diff --git a/demos/STM32/RT-VFS-FATFS/make/stm32l4r9ai_discovery.make b/demos/STM32/RT-VFS-FATFS/make/stm32l4r9ai_discovery.make index 9b0d142b4..cba277db4 100644 --- a/demos/STM32/RT-VFS-FATFS/make/stm32l4r9ai_discovery.make +++ b/demos/STM32/RT-VFS-FATFS/make/stm32l4r9ai_discovery.make @@ -108,6 +108,7 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMv7-M/compilers/GCC/mk/port.mk # VFS files (optional). include $(CHIBIOS)/os/vfs/vfs.mk +include $(CHIBIOS)/os/vfs/drivers/overlay/drvoverlay.mk include $(CHIBIOS)/os/vfs/drivers/streams/drvstreams.mk include $(CHIBIOS)/os/vfs/drivers/fatfs/drvfatfs.mk # Auto-build files in ./source recursively. diff --git a/os/vfs/drivers/fatfs/drvfatfs.c b/os/vfs/drivers/fatfs/drvfatfs.c index 53a533033..c2bcf4206 100644 --- a/os/vfs/drivers/fatfs/drvfatfs.c +++ b/os/vfs/drivers/fatfs/drvfatfs.c @@ -30,8 +30,6 @@ #include "vfs.h" #include "drvfatfs.h" -#include "ff.h" - /*===========================================================================*/ /* Module local definitions. */ /*===========================================================================*/ @@ -96,60 +94,6 @@ /* Module local types. */ /*===========================================================================*/ -/** - * @brief @p vfs_fatfs_driver_t virtual methods table. - */ -struct vfs_fatfs_driver_vmt { - __vfs_fatfs_driver_methods -}; - -/** - * @brief Type of a structure representing a VFS FatFS driver. - */ -typedef struct vfs_drv_streams { - /** - * @brief Virtual Methods Table. - */ - const struct vfs_fatfs_driver_vmt *vmt; - __vfs_fatfs_driver_data -} vfs_fatfs_driver_t; - -/** - * @brief @p vfs_fatfs_dir_node_t virtual methods table. - */ -struct vfs_fatfs_dir_node_vmt { - __vfs_fatfs_dir_node_methods -}; - -/** - * @brief Type of a structure representing a FatFS directory VFS node. - */ -typedef struct vfs_fatfs_dir_node { - /** - * @brief Virtual Methods Table. - */ - const struct vfs_fatfs_dir_node_vmt *vmt; - __vfs_fatfs_dir_node_data -} vfs_fatfs_dir_node_t; - -/** - * @brief @p vfs_fatfs_file_node_t virtual methods table. - */ -struct vfs_fatfs_file_node_vmt { - __vfs_fatfs_file_node_methods -}; - -/** - * @brief Type of a structure representing a FatFS file VFS node. - */ -typedef struct vfs_fatfs_file_node { - /** - * @brief Virtual Methods Table. - */ - const struct vfs_fatfs_file_node_vmt *vmt; - __vfs_fatfs_file_node_data -} vfs_fatfs_file_node_t; - /*===========================================================================*/ /* Module local variables. */ /*===========================================================================*/ diff --git a/os/vfs/drivers/fatfs/drvfatfs.h b/os/vfs/drivers/fatfs/drvfatfs.h index 2075c28b0..3d0fdd7ab 100644 --- a/os/vfs/drivers/fatfs/drvfatfs.h +++ b/os/vfs/drivers/fatfs/drvfatfs.h @@ -28,7 +28,7 @@ #ifndef DRVFATFS_H #define DRVFATFS_H -#include "vfs.h" +#include "ff.h" /*===========================================================================*/ /* Module constants. */ @@ -42,10 +42,123 @@ /* Derived constants and error checks. */ /*===========================================================================*/ +/* Configuration options checks.*/ +#if !defined(DRV_CFG_FATFS_DIR_NODES_NUM) +#error "DRV_CFG_FATFS_DIR_NODES_NUM not defined in vfsconf.h" +#endif + +#if !defined(DRV_CFG_FATFS_FILE_NODES_NUM) +#error "DRV_CFG_FATFS_FILE_NODES_NUM not defined in vfsconf.h" +#endif + +#if DRV_CFG_FATFS_DIR_NODES_NUM < 1 +#error "invalid value for DRV_CFG_FATFS_DIR_NODES_NUM" +#endif + +#if DRV_CFG_FATFS_FILE_NODES_NUM < 1 +#error "invalid value for DRV_CFG_FATFS_FILE_NODES_NUM" +#endif + /*===========================================================================*/ /* Module data structures and types. */ /*===========================================================================*/ +/** + * @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_dir_node_t virtual methods table. + */ +struct vfs_fatfs_dir_node_vmt { + __vfs_fatfs_dir_node_methods +}; + +/** + * @brief Type of a structure representing a FatFS directory VFS node. + */ +typedef struct vfs_fatfs_dir_node { + /** + * @brief Virtual Methods Table. + */ + const struct vfs_fatfs_dir_node_vmt *vmt; + __vfs_fatfs_dir_node_data +} vfs_fatfs_dir_node_t; + +/** + * @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; + +/** + * @brief @p vfs_fatfs_file_node_t virtual methods table. + */ +struct vfs_fatfs_file_node_vmt { + __vfs_fatfs_file_node_methods +}; + +/** + * @brief Type of a structure representing a FatFS file VFS node. + */ +typedef struct vfs_fatfs_file_node { + /** + * @brief Virtual Methods Table. + */ + const struct vfs_fatfs_file_node_vmt *vmt; + __vfs_fatfs_file_node_data +} vfs_fatfs_file_node_t; + +/** + * @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_driver_t virtual methods table. + */ +struct vfs_fatfs_driver_vmt { + __vfs_fatfs_driver_methods +}; + +/** + * @brief Type of a structure representing a VFS FatFS driver. + */ +typedef struct vfs_drv_streams { + /** + * @brief Virtual Methods Table. + */ + const struct vfs_fatfs_driver_vmt *vmt; + __vfs_fatfs_driver_data +} vfs_fatfs_driver_t; + /*===========================================================================*/ /* Module macros. */ /*===========================================================================*/ diff --git a/os/vfs/drivers/overlay/drvoverlay.h b/os/vfs/drivers/overlay/drvoverlay.h index 41729582b..9d4caa65c 100644 --- a/os/vfs/drivers/overlay/drvoverlay.h +++ b/os/vfs/drivers/overlay/drvoverlay.h @@ -28,8 +28,6 @@ #ifndef DRVOVERLAY_H #define DRVOVERLAY_H -#include "vfs.h" - /*===========================================================================*/ /* Module constants. */ /*===========================================================================*/ @@ -43,6 +41,14 @@ /*===========================================================================*/ /* Configuration options checks.*/ +#if !defined(DRV_CFG_OVERLAY_DIR_NODES_NUM) +#error "DRV_CFG_OVERLAY_DIR_NODES_NUM not defined in vfsconf.h" +#endif + +#if !defined(DRV_CFG_OVERLAY_DRV_MAX) +#error "DRV_CFG_OVERLAY_DRV_MAX not defined in vfsconf.h" +#endif + #if DRV_CFG_OVERLAY_DIR_NODES_NUM < 1 #error "invalid value for DRV_CFG_OVERLAY_DIR_NODES_NUM" #endif diff --git a/os/vfs/drivers/streams/drvstreams.h b/os/vfs/drivers/streams/drvstreams.h index 1a5e5b7c2..1e4f53895 100644 --- a/os/vfs/drivers/streams/drvstreams.h +++ b/os/vfs/drivers/streams/drvstreams.h @@ -28,8 +28,6 @@ #ifndef DRVSTREAMS_H #define DRVSTREAMS_H -#include "vfs.h" - /*===========================================================================*/ /* Module constants. */ /*===========================================================================*/ @@ -43,6 +41,14 @@ /*===========================================================================*/ /* Configuration options checks.*/ +#if !defined(DRV_CFG_STREAMS_DIR_NODES_NUM) +#error "DRV_CFG_STREAMS_DIR_NODES_NUM not defined in vfsconf.h" +#endif + +#if !defined(DRV_CFG_STREAMS_FILE_NODES_NUM) +#error "DRV_CFG_STREAMS_FILE_NODES_NUM not defined in vfsconf.h" +#endif + #if DRV_CFG_STREAMS_DIR_NODES_NUM < 1 #error "invalid value for DRV_CFG_STREAMS_DIR_NODES_NUM" #endif diff --git a/os/vfs/include/vfschecks.h b/os/vfs/include/vfschecks.h index dcc85c5d4..4b61e55f4 100644 --- a/os/vfs/include/vfschecks.h +++ b/os/vfs/include/vfschecks.h @@ -48,6 +48,15 @@ #error "obsolete or unknown configuration file" #endif +/* Configuration options checks.*/ +#if !defined(VFS_CFG_MAX_NAMELEN) +#error "VFS_CFG_MAX_NAMELEN not defined in vfsconf.h" +#endif + +#if VFS_CFG_MAX_NAMELEN < 12 +#error "invalid value for VFS_CFG_MAX_NAMELEN" +#endif + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ diff --git a/os/vfs/templates/vfsconf.h b/os/vfs/templates/vfsconf.h index 0dae7c97b..bf08e04e5 100644 --- a/os/vfs/templates/vfsconf.h +++ b/os/vfs/templates/vfsconf.h @@ -90,6 +90,29 @@ /** @} */ +/*===========================================================================*/ +/** + * @name FatFS driver settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Number of directory nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_FATFS_DIR_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_FATFS_DIR_NODES_NUM 1 +#endif + +/** + * @brief Number of file nodes pre-allocated in the pool. + */ +#if !defined(DRV_CFG_FATFS_FILE_NODES_NUM) || defined(__DOXYGEN__) +#define DRV_CFG_FATFS_FILE_NODES_NUM 2 +#endif + +/** @} */ + #endif /* VFSCONF_H */ /** @} */