From 289c93827344bbc6953c7004bb3bd66d5799a861 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 30 Oct 2013 12:49:49 +0000 Subject: Improved shell. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6398 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/shell.c | 38 ++++++++++++++++++++++++++++++-------- os/various/shell.h | 1 + 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'os') diff --git a/os/various/shell.c b/os/various/shell.c index 62ffc5ce1..3aeb1e10a 100644 --- a/os/various/shell.c +++ b/os/various/shell.c @@ -138,7 +138,6 @@ static bool cmdexec(const ShellCommand *scp, BaseSequentialStream *chp, */ static msg_t shell_thread(void *p) { int n; - msg_t msg = MSG_OK; BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel; const ShellCommand *scp = ((ShellConfig *)p)->sc_commands; char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH]; @@ -190,22 +189,39 @@ static msg_t shell_thread(void *p) { } } } - /* Atomically broadcasting the event source and terminating the thread, - there is not a chSysUnlock() because the thread terminates upon return.*/ - chSysLock(); - chEvtBroadcastI(&shell_terminated); - chThdExitS(msg); - return 0; /* Never executed.*/ + shellExit(MSG_OK); + /* Never executed, silencing a warning.*/ + return 0; } /** * @brief Shell manager initialization. + * + * @api */ void shellInit(void) { chEvtObjectInit(&shell_terminated); } +/** + * @brief Terminates the shell. + * @note Must be invoked from the command handlers. + * @note Does not return. + * + * @param[in] msg shell exit code + * + * @api + */ +void shellExit(msg_t msg) { + + /* Atomically broadcasting the event source and terminating the thread, + there is not a chSysUnlock() because the thread terminates upon return.*/ + chSysLock(); + chEvtBroadcastI(&shell_terminated); + chThdExitS(msg); +} + /** * @brief Spawns a new shell. * @pre @p CH_CFG_USE_HEAP and @p CH_CFG_USE_DYNAMIC must be enabled. @@ -215,6 +231,8 @@ void shellInit(void) { * @param[in] prio priority level for the new shell * @return A pointer to the shell thread. * @retval NULL thread creation failed because memory allocation. + * + * @api */ #if CH_CFG_USE_HEAP && CH_CFG_USE_DYNAMIC thread_t *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio) { @@ -231,9 +249,11 @@ thread_t *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio) { * @param[in] size size of the shell working area * @param[in] prio priority level for the new shell * @return A pointer to the shell thread. + * + * @api */ thread_t *shellCreateStatic(const ShellConfig *scp, void *wsp, - size_t size, tprio_t prio) { + size_t size, tprio_t prio) { return chThdCreateStatic(wsp, size, prio, shell_thread, (void *)scp); } @@ -247,6 +267,8 @@ thread_t *shellCreateStatic(const ShellConfig *scp, void *wsp, * @return The operation status. * @retval TRUE the channel was reset or CTRL-D pressed. * @retval FALSE operation successful. + * + * @api */ bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) { char *p = line; diff --git a/os/various/shell.h b/os/various/shell.h index 7d576f36d..d7a7dbc60 100644 --- a/os/various/shell.h +++ b/os/various/shell.h @@ -70,6 +70,7 @@ extern event_source_t shell_terminated; extern "C" { #endif void shellInit(void); + void shellExit(msg_t msg); thread_t *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio); thread_t *shellCreateStatic(const ShellConfig *scp, void *wsp, size_t size, tprio_t prio); -- cgit v1.2.3