Fixed overlay driver and scanning loop in the demo.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15171 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
40f335c681
commit
c2450fd8d4
|
@ -44,6 +44,36 @@
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/**
|
||||||
|
* @name VFS drivers
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS Overlay Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_OVERLAY) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_OVERLAY TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS Streams Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_STREAMS) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_STREAMS TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS FatFS Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_FATFS) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_FATFS TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/**
|
/**
|
||||||
* @name Overlay driver settings
|
* @name Overlay driver settings
|
||||||
|
|
|
@ -44,6 +44,36 @@
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/**
|
||||||
|
* @name VFS drivers
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS Overlay Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_OVERLAY) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_OVERLAY TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS Streams Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_STREAMS) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_STREAMS TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS FatFS Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_FATFS) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_FATFS TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/**
|
/**
|
||||||
* @name Overlay driver settings
|
* @name Overlay driver settings
|
||||||
|
|
|
@ -158,6 +158,7 @@ static void scan_nodes(BaseSequentialStream *chp, char *path) {
|
||||||
strcpy(path + i, fn);
|
strcpy(path + i, fn);
|
||||||
strcat(path + i, "/");
|
strcat(path + i, "/");
|
||||||
scan_nodes(chp, path);
|
scan_nodes(chp, path);
|
||||||
|
path[i] = '\0';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chprintf(chp, "%s%s\r\n", path, fn);
|
chprintf(chp, "%s%s\r\n", path, fn);
|
||||||
|
@ -322,9 +323,15 @@ int main(void) {
|
||||||
sdStart(&PORTAB_SD1, NULL);
|
sdStart(&PORTAB_SD1, NULL);
|
||||||
nullObjectInit(&nullstream);
|
nullObjectInit(&nullstream);
|
||||||
|
|
||||||
|
#if defined(DEMO_USE_FATFS)
|
||||||
|
/* Initializing an overlay VFS object overlaying a FatFS driver,
|
||||||
|
no need for names, both are root.*/
|
||||||
|
drvOverlayObjectInit(&vfs_root, drvFatFSInit(""), "");
|
||||||
|
#else
|
||||||
/* Initializing an overlay VFS object as a root, no 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, "");
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Registering a streams VFS driver on the VFS overlay root as "/dev".*/
|
/* Registering a streams VFS driver on the VFS overlay root as "/dev".*/
|
||||||
msg = drvOverlayRegisterDriver(&vfs_root,
|
msg = drvOverlayRegisterDriver(&vfs_root,
|
||||||
|
@ -335,14 +342,6 @@ int main(void) {
|
||||||
chSysHalt("VFS");
|
chSysHalt("VFS");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEMO_USE_FATFS)
|
|
||||||
/* Registering the VFS FatFS wrapped driver as "/fatfs".*/
|
|
||||||
msg = drvOverlayRegisterDriver(&vfs_root, drvFatFSInit("fatfs"));
|
|
||||||
if (msg != VFS_RET_SUCCESS) {
|
|
||||||
chSysHalt("VFS");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Opening a file for shell I/O.*/
|
/* Opening a file for shell I/O.*/
|
||||||
msg = vfsOpenFile((vfs_driver_t *)&vfs_root,
|
msg = vfsOpenFile((vfs_driver_t *)&vfs_root,
|
||||||
"/dev/VSD1",
|
"/dev/VSD1",
|
||||||
|
|
|
@ -86,7 +86,7 @@ static msg_t match_driver(vfs_overlay_driver_t *odp,
|
||||||
|
|
||||||
/* Searching among registered drivers.*/
|
/* Searching among registered drivers.*/
|
||||||
pp = &odp->drivers[0];
|
pp = &odp->drivers[0];
|
||||||
while (pp < odp->next_driver) {
|
while (pp < &odp->drivers[odp->next_driver]) {
|
||||||
if (strncmp(fname, (*pp)->rootname, VFS_CFG_MAX_NAMELEN) == 0) {
|
if (strncmp(fname, (*pp)->rootname, VFS_CFG_MAX_NAMELEN) == 0) {
|
||||||
*vdpp = *pp;
|
*vdpp = *pp;
|
||||||
return VFS_RET_SUCCESS;
|
return VFS_RET_SUCCESS;
|
||||||
|
@ -116,16 +116,25 @@ static msg_t drv_open_dir(void *instance,
|
||||||
if (*scanpath == '\0') {
|
if (*scanpath == '\0') {
|
||||||
|
|
||||||
/* Creating a root directory node.*/
|
/* Creating a root directory node.*/
|
||||||
vfs_overlay_dir_node_t *onp = chPoolAlloc(&drvp->dir_nodes_pool);
|
vfs_overlay_dir_node_t *odnp = chPoolAlloc(&drvp->dir_nodes_pool);
|
||||||
if (onp != NULL) {
|
if (odnp != NULL) {
|
||||||
|
|
||||||
/* Node object initialization.*/
|
/* Node object initialization.*/
|
||||||
onp->vmt = &dir_node_vmt;
|
odnp->vmt = &dir_node_vmt;
|
||||||
onp->refs = 1U;
|
odnp->refs = 1U;
|
||||||
onp->driver = (vfs_driver_t *)instance;
|
odnp->driver = (vfs_driver_t *)instance;
|
||||||
onp->index = 0U;
|
odnp->index = 0U;
|
||||||
|
odnp->overlaid_root = NULL;
|
||||||
|
|
||||||
*vdnpp = (vfs_directory_node_t *)onp;
|
/* Trying to obtain a root node from the overlaid driver, it
|
||||||
|
could fail, in that case the pointer stays at NULL.*/
|
||||||
|
if (drvp->overlaid_drv != NULL) {
|
||||||
|
(void) drvp->overlaid_drv->vmt->open_dir((void *)drvp->overlaid_drv,
|
||||||
|
"/",
|
||||||
|
&odnp->overlaid_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
*vdnpp = (vfs_directory_node_t *)odnp;
|
||||||
return VFS_RET_SUCCESS;
|
return VFS_RET_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +203,11 @@ static void node_dir_release(void *instance) {
|
||||||
|
|
||||||
if (--odnp->refs == 0U) {
|
if (--odnp->refs == 0U) {
|
||||||
|
|
||||||
|
/* Releasing the overlaid driver root node, if taken.*/
|
||||||
|
if (odnp->overlaid_root != NULL) {
|
||||||
|
odnp->overlaid_root->vmt->release((void *)odnp->overlaid_root);
|
||||||
|
}
|
||||||
|
|
||||||
chPoolFree(&drvp->dir_nodes_pool, (void *)odnp);
|
chPoolFree(&drvp->dir_nodes_pool, (void *)odnp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,7 +224,7 @@ static msg_t node_dir_next(void *instance, vfs_node_info_t *nip) {
|
||||||
vfs_overlay_dir_node_t *odnp = (vfs_overlay_dir_node_t *)instance;
|
vfs_overlay_dir_node_t *odnp = (vfs_overlay_dir_node_t *)instance;
|
||||||
vfs_overlay_driver_t *drvp = (vfs_overlay_driver_t *)odnp->driver;
|
vfs_overlay_driver_t *drvp = (vfs_overlay_driver_t *)odnp->driver;
|
||||||
|
|
||||||
if (odnp->index < DRV_CFG_OVERLAY_DRV_MAX) {
|
if (odnp->index < drvp->next_driver) {
|
||||||
nip->attr = VFS_NODE_ATTR_ISDIR | VFS_NODE_ATTR_READONLY;
|
nip->attr = VFS_NODE_ATTR_ISDIR | VFS_NODE_ATTR_READONLY;
|
||||||
nip->size = (vfs_offset_t)0;
|
nip->size = (vfs_offset_t)0;
|
||||||
strcpy(nip->name, drvp->drivers[odnp->index]->rootname);
|
strcpy(nip->name, drvp->drivers[odnp->index]->rootname);
|
||||||
|
@ -219,6 +233,20 @@ static msg_t node_dir_next(void *instance, vfs_node_info_t *nip) {
|
||||||
|
|
||||||
return VFS_RET_SUCCESS;
|
return VFS_RET_SUCCESS;
|
||||||
}
|
}
|
||||||
|
if (odnp->overlaid_root != NULL) {
|
||||||
|
if (odnp->index == drvp->next_driver) {
|
||||||
|
|
||||||
|
odnp->index++;
|
||||||
|
|
||||||
|
return odnp->overlaid_root->vmt->dir_first((void *)odnp->overlaid_root,
|
||||||
|
nip);
|
||||||
|
}
|
||||||
|
if (odnp->index > drvp->next_driver) {
|
||||||
|
|
||||||
|
return odnp->overlaid_root->vmt->dir_next((void *)odnp->overlaid_root,
|
||||||
|
nip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return VFS_RET_EOF;
|
return VFS_RET_EOF;
|
||||||
}
|
}
|
||||||
|
@ -244,7 +272,7 @@ vfs_driver_t *drvOverlayObjectInit(vfs_overlay_driver_t *vodp,
|
||||||
vodp->vmt = &driver_vmt;
|
vodp->vmt = &driver_vmt;
|
||||||
vodp->rootname = rootname;
|
vodp->rootname = rootname;
|
||||||
vodp->overlaid_drv = overlaid_drv;
|
vodp->overlaid_drv = overlaid_drv;
|
||||||
vodp->next_driver = &vodp->drivers[0];
|
vodp->next_driver = 0U;
|
||||||
|
|
||||||
/* Initializing pools.*/
|
/* Initializing pools.*/
|
||||||
chPoolObjectInit(&vodp->dir_nodes_pool,
|
chPoolObjectInit(&vodp->dir_nodes_pool,
|
||||||
|
@ -271,11 +299,11 @@ msg_t drvOverlayRegisterDriver(vfs_overlay_driver_t *vodp,
|
||||||
vfs_driver_t *vdp) {
|
vfs_driver_t *vdp) {
|
||||||
msg_t err;
|
msg_t err;
|
||||||
|
|
||||||
if (vodp->next_driver >= &vodp->drivers[DRV_CFG_OVERLAY_DRV_MAX]) {
|
if (vodp->next_driver >= DRV_CFG_OVERLAY_DRV_MAX) {
|
||||||
err = VFS_RET_NO_RESOURCE;
|
err = VFS_RET_NO_RESOURCE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*vodp->next_driver++ = vdp;
|
vodp->drivers[vodp->next_driver++] = vdp;
|
||||||
err = VFS_RET_SUCCESS;
|
err = VFS_RET_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,9 @@
|
||||||
*/
|
*/
|
||||||
#define __vfs_overlay_dir_node_data \
|
#define __vfs_overlay_dir_node_data \
|
||||||
__vfs_directory_node_data \
|
__vfs_directory_node_data \
|
||||||
unsigned index;
|
unsigned index; \
|
||||||
|
/* Root node of the overlaid driver or NULL.*/ \
|
||||||
|
vfs_directory_node_t *overlaid_root; \
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief @p vfs_overlay_dir_node_t virtual methods table.
|
* @brief @p vfs_overlay_dir_node_t virtual methods table.
|
||||||
|
@ -110,7 +112,7 @@ typedef struct vfs_overlay_dir_node {
|
||||||
/* Static storage of directory nodes.*/ \
|
/* Static storage of directory nodes.*/ \
|
||||||
vfs_overlay_dir_node_t dir_nodes[DRV_CFG_OVERLAY_DIR_NODES_NUM]; \
|
vfs_overlay_dir_node_t dir_nodes[DRV_CFG_OVERLAY_DIR_NODES_NUM]; \
|
||||||
/* Next registration slot.*/ \
|
/* Next registration slot.*/ \
|
||||||
vfs_driver_t **next_driver; \
|
unsigned next_driver; \
|
||||||
/* Registration slots.*/ \
|
/* Registration slots.*/ \
|
||||||
vfs_driver_t *drivers[DRV_CFG_OVERLAY_DRV_MAX];
|
vfs_driver_t *drivers[DRV_CFG_OVERLAY_DRV_MAX];
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,18 @@
|
||||||
#error "invalid value for VFS_CFG_MAX_NAMELEN"
|
#error "invalid value for VFS_CFG_MAX_NAMELEN"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_OVERLAY)
|
||||||
|
#error "VFS_CFG_ENABLE_DRV_OVERLAY not defined in vfsconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_STREAMS)
|
||||||
|
#error "VFS_CFG_ENABLE_DRV_STREAMS not defined in vfsconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_FATFS)
|
||||||
|
#error "VFS_CFG_ENABLE_DRV_FATFS not defined in vfsconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Derived constants and error checks. */
|
/* Derived constants and error checks. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -44,6 +44,36 @@
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/**
|
||||||
|
* @name VFS drivers
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS Overlay Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_OVERLAY) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_OVERLAY TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS Streams Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_STREAMS) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_STREAMS TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enables the VFS FatFS Driver.
|
||||||
|
*/
|
||||||
|
#if !defined(VFS_CFG_ENABLE_DRV_FATFS) || defined(__DOXYGEN__)
|
||||||
|
#define VFS_CFG_ENABLE_DRV_FATFS TRUE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/**
|
/**
|
||||||
* @name Overlay driver settings
|
* @name Overlay driver settings
|
||||||
|
|
|
@ -107,6 +107,7 @@
|
||||||
- FIX: Fixed DMA stream not disabled in STM32 QUADSPIv1 driver (bug #1203)
|
- FIX: Fixed DMA stream not disabled in STM32 QUADSPIv1 driver (bug #1203)
|
||||||
(backported to 20.3.5)(backported to 21.11.1).
|
(backported to 20.3.5)(backported to 21.11.1).
|
||||||
- FIX: Fixed I2C4 DMA streams for STM32L496 (bug #1202)
|
- FIX: Fixed I2C4 DMA streams for STM32L496 (bug #1202)
|
||||||
|
(backported to 20.3.5)(backported to 21.11.1).
|
||||||
- FIX: Fixed STM32_SDMMC2_NUMBER on STM32H7 (bug #1201)
|
- FIX: Fixed STM32_SDMMC2_NUMBER on STM32H7 (bug #1201)
|
||||||
(backported to 20.3.5)(backported to 21.11.1).
|
(backported to 20.3.5)(backported to 21.11.1).
|
||||||
- FIX: Fixed STM32G0B1 demo application hangs debuggers (bug #1200)
|
- FIX: Fixed STM32G0B1 demo application hangs debuggers (bug #1200)
|
||||||
|
|
Loading…
Reference in New Issue