/** * @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 Terminates the current thread. * @details The thread goes in the @p THD_STATE_FINAL state holding the * specified exit status code, other threads can retrieve the * exit status code by invoking the function @p chThdWait(). * @post Eventual code after this function will never be executed, * this function never returns. The compiler has no way to * know this so do not assume that the compiler would remove * the dead code. * * @param[in] msg thread exit code * * @api */ void chThdExit(msg_t msg) { chSysLock(); chThdExitS(msg); /* The thread never returns here.*/ }
void BaseThread::exitS(msg_t msg) { chThdExitS(msg); }
/** * @brief Shell thread function. * * @param[in] p pointer to a @p BaseSequentialStream object * @return Termination reason. * @retval RDY_OK terminated by command. * @retval RDY_RESET terminated by reset condition on the I/O channel. */ 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]; char *args[SHELL_MAX_ARGUMENTS + 1]; chRegSetThreadName("shell"); chprintf(chp, "\r\nChibiOS/RT Shell\r\n"); while (TRUE) { chprintf(chp, "ch> "); if (shellGetLine(chp, line, sizeof(line))) { chprintf(chp, "\r\nlogout"); break; } lp = _strtok(line, " \009", &tokp); cmd = lp; n = 0; while ((lp = _strtok(NULL, " \009", &tokp)) != NULL) { if (n >= SHELL_MAX_ARGUMENTS) { chprintf(chp, "too many arguments\r\n"); cmd = NULL; break; } args[n++] = lp; } args[n] = NULL; if (cmd != NULL) { if (strcasecmp(cmd, "exit") == 0) { if (n > 0) { usage(chp, "exit"); continue; } break; } else if (strcasecmp(cmd, "help") == 0) { if (n > 0) { usage(chp, "help"); continue; } chprintf(chp, "Commands: help exit "); list_commands(chp, local_commands); if (scp != NULL) list_commands(chp, scp); chprintf(chp, "\r\n"); } else if (cmdexec(local_commands, chp, cmd, n, args) && ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) { chprintf(chp, "%s", cmd); chprintf(chp, " ?\r\n"); } } } /* 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.*/ }