Added vfsGetFileStream() function.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15141 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-11-27 07:07:26 +00:00
parent fc7e00365d
commit 7419070c91
3 changed files with 27 additions and 2 deletions

View File

@ -113,8 +113,8 @@ static const ShellCommand commands[] = {
{NULL, NULL} {NULL, NULL}
}; };
static const ShellConfig shell_cfg1 = { static ShellConfig shell_cfg1 = {
(BaseSequentialStream *)&PORTAB_SD1, NULL,
commands commands
}; };
@ -174,6 +174,7 @@ static THD_FUNCTION(Thread1, arg) {
*/ */
int main(void) { int main(void) {
msg_t msg; msg_t msg;
vfs_file_node_t *file;
static const evhandler_t evhndl[] = { static const evhandler_t evhndl[] = {
InsertHandler, InsertHandler,
RemoveHandler, RemoveHandler,
@ -208,6 +209,13 @@ int main(void) {
chSysHalt("VFS"); chSysHalt("VFS");
} }
/* Opening a file for shell I/O.*/
msg = vfsOpenFile("/dev/VSD1", &file);
if (msg != VFS_RET_SUCCESS) {
chSysHalt("VFS");
}
shell_cfg1.sc_channel = vfsGetFileStream(file);
/* Creates the blinker thread.*/ /* Creates the blinker thread.*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
@ -217,6 +225,7 @@ int main(void) {
chEvtRegister(&shell_terminated, &el2, 2); chEvtRegister(&shell_terminated, &el2, 2);
while (true) { while (true) {
if (shelltp == NULL) { if (shelltp == NULL) {
/* Spawning a shell.*/
shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
"shell", NORMALPRIO + 1, "shell", NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1); shellThread, (void *)&shell_cfg1);

View File

@ -110,6 +110,7 @@ extern "C" {
msg_t vfsSetFilePosition(vfs_file_node_t *vfnp, vfs_offset_t offset); msg_t vfsSetFilePosition(vfs_file_node_t *vfnp, vfs_offset_t offset);
vfs_offset_t vfsGetFilePosition(vfs_file_node_t *vfnp); vfs_offset_t vfsGetFilePosition(vfs_file_node_t *vfnp);
vfs_offset_t vfsGetFileSize(vfs_file_node_t *vfnp); vfs_offset_t vfsGetFileSize(vfs_file_node_t *vfnp);
BaseSequentialStream *vfsGetFileStream(vfs_file_node_t *vfnp);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -472,4 +472,19 @@ vfs_offset_t vfsGetFileSize(vfs_file_node_t *vfnp) {
return vfnp->vmt->file_getsize((void *)vfnp); return vfnp->vmt->file_getsize((void *)vfnp);
} }
/**
* @brief Returns the inner stream associated to the file.
*
* @param[in] vfnp the pointer to the @p vfs_file_node_t object
* @return The current file size.
*
* @api
*/
BaseSequentialStream *vfsGetFileStream(vfs_file_node_t *vfnp) {
chDbgAssert(vfnp->refs > 0U, "zero count");
return vfnp->vmt->get_stream((void *)vfnp);
}
/** @} */ /** @} */