From 3d576f5929303b40037e36729299ebe988998079 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 30 Oct 2013 12:44:57 +0000 Subject: Improved shell. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@6397 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/shell.c | 36 +++++++++++++++++++++++++++++------- os/various/shell.h | 1 + readme.txt | 2 ++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/os/various/shell.c b/os/various/shell.c index ceb4342db..5315fe68a 100644 --- a/os/various/shell.c +++ b/os/various/shell.c @@ -135,10 +135,11 @@ static bool_t cmdexec(const ShellCommand *scp, BaseSequentialStream *chp, * @return Termination reason. * @retval RDY_OK terminated by command. * @retval RDY_RESET terminated by reset condition on the I/O channel. + * + * @notapi */ static msg_t shell_thread(void *p) { int n; - msg_t msg = RDY_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 +191,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(RDY_OK); + /* Never executed, silencing a warning.*/ + return 0; } /** * @brief Shell manager initialization. + * + * @api */ void shellInit(void) { chEvtInit(&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_USE_HEAP and @p CH_USE_DYNAMIC must be enabled. @@ -215,6 +233,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_USE_HEAP && CH_USE_DYNAMIC Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio) { @@ -247,6 +267,8 @@ Thread *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_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) { char *p = line; diff --git a/os/various/shell.h b/os/various/shell.h index 384a6a200..ef2676a74 100644 --- a/os/various/shell.h +++ b/os/various/shell.h @@ -70,6 +70,7 @@ extern EventSource shell_terminated; extern "C" { #endif void shellInit(void); + void shellExit(msg_t msg); Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio); Thread *shellCreateStatic(const ShellConfig *scp, void *wsp, size_t size, tprio_t prio); diff --git a/readme.txt b/readme.txt index 66d242c99..140faa831 100644 --- a/readme.txt +++ b/readme.txt @@ -116,6 +116,8 @@ (backported to 2.6.0). - FIX: Fixed MS2ST() and US2ST() macros error (bug #415)(backported to 2.6.0, 2.4.4, 2.2.10, NilRTOS). +- NEW: Added a new function shellExit() to the shell. It allows to exit the + shell from any command handler. - NEW: Added support for STM32F401/STM32F42x/STM32F43x devices. - NEW: Added support for STM32F0xx platform in RTCv2 driver. - NEW: Improvements to the STM32F4xx backup domain initialization. -- cgit v1.2.3