summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-11-01 18:41:52 +0000
committerChristian Pointner <equinox@mur.at>2013-11-01 18:41:52 +0000
commit9f9fe09c817e529e874f544cb538633c5354ecc7 (patch)
treec456ade432e42856cd3000fadd5c11d51ee27e7b /contrib
parentsome cleanups (diff)
applied upstream shell patch for chibios 2.6.1
changed shell code to work with upstream patch git-svn-id: https://svn.spreadspace.org/mur.sat@851 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'contrib')
-rw-r--r--contrib/patches/chibios-2.6.1-shell.patch1878
1 files changed, 75 insertions, 1803 deletions
diff --git a/contrib/patches/chibios-2.6.1-shell.patch b/contrib/patches/chibios-2.6.1-shell.patch
index 595ee59..9e5a7ac 100644
--- a/contrib/patches/chibios-2.6.1-shell.patch
+++ b/contrib/patches/chibios-2.6.1-shell.patch
@@ -1,1822 +1,94 @@
-Index: testhal/STM32F30x/USB_CDC/main.c
-===================================================================
---- testhal/STM32F30x/USB_CDC/main.c (Revision 6305)
-+++ testhal/STM32F30x/USB_CDC/main.c (Arbeitskopie)
-@@ -342,28 +342,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -374,26 +376,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
- static uint8_t buf[] =
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
-@@ -415,13 +421,15 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: write\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
-
- while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
- chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1);
- }
- chprintf(chp, "\r\n\nstopped\r\n");
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: testhal/STM32F1xx/USB_CDC_F107/main.c
-===================================================================
---- testhal/STM32F1xx/USB_CDC_F107/main.c (Revision 6305)
-+++ testhal/STM32F1xx/USB_CDC_F107/main.c (Arbeitskopie)
-@@ -335,28 +335,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -367,26 +369,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
- static uint8_t buf[] =
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
-@@ -408,13 +414,15 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: write\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
-
- while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
- chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1);
- }
- chprintf(chp, "\r\n\nstopped\r\n");
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: testhal/STM32F1xx/RTC_FATTIME/main.c
-===================================================================
---- testhal/STM32F1xx/RTC_FATTIME/main.c (Revision 6305)
-+++ testhal/STM32F1xx/RTC_FATTIME/main.c (Arbeitskopie)
-@@ -373,7 +373,7 @@
- /**
- *
- */
--void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
-+int8_t cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
- (void)argc;
- (void)argv;
- FRESULT err;
-@@ -391,7 +391,7 @@
- chprintf(chp, "ERROR! Chibios compiled without RTC support.");
- chprintf(chp, "Enable HAL_USE_RCT in you halconf.h");
- chThdSleepMilliseconds(100);
-- return;
-+ return SHELL_CMD_CONTINUE;
- #endif
-
- chprintf(chp, "Trying to connect SDIO... ");
-@@ -487,6 +487,8 @@
- else{
- chSysHalt();
- }
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- /*===========================================================================*/
-Index: testhal/STM32F1xx/USB_CDC/main.c
-===================================================================
---- testhal/STM32F1xx/USB_CDC/main.c (Revision 6305)
-+++ testhal/STM32F1xx/USB_CDC/main.c (Arbeitskopie)
-@@ -335,28 +335,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -367,26 +369,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
- static uint8_t buf[] =
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
-@@ -408,13 +414,15 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: write\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
-
- while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
- chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1);
- }
- chprintf(chp, "\r\n\nstopped\r\n");
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: testhal/STM32F37x/USB_CDC/main.c
-===================================================================
---- testhal/STM32F37x/USB_CDC/main.c (Revision 6305)
-+++ testhal/STM32F37x/USB_CDC/main.c (Arbeitskopie)
-@@ -341,28 +341,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -373,26 +375,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
- static uint8_t buf[] =
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
-@@ -414,13 +420,15 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: write\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
-
- while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
- chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1);
- }
- chprintf(chp, "\r\n\nstopped\r\n");
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: testhal/STM32F4xx/RTC/main.c
+Index: os/various/shell.c
===================================================================
---- testhal/STM32F4xx/RTC/main.c (Revision 6305)
-+++ testhal/STM32F4xx/RTC/main.c (Arbeitskopie)
-@@ -83,11 +83,11 @@
- __WFI();
- }
-
--static void cmd_sleep(BaseSequentialStream *chp, int argc, char *argv[]){
-+static int8_t cmd_sleep(BaseSequentialStream *chp, int argc, char *argv[]){
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: sleep\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, "Going to sleep.\r\n");
-
-@@ -95,12 +95,14 @@
-
- /* going to anabiosis */
- func_sleep();
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- /*
- *
- */
--static void cmd_alarm(BaseSequentialStream *chp, int argc, char *argv[]){
-+static int8_t cmd_alarm(BaseSequentialStream *chp, int argc, char *argv[]){
- int i = 0;
-
- (void)argv;
-@@ -111,7 +113,7 @@
- if ((argc == 1) && (strcmp(argv[0], "get") == 0)){
- rtcGetAlarm(&RTCD1, 0, &alarmspec);
- chprintf(chp, "%D%s",alarmspec," - alarm in STM internal format\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
-
- if ((argc == 2) && (strcmp(argv[0], "set") == 0)){
-@@ -119,7 +121,7 @@
- alarmspec.tv_datetime = ((i / 10) & 7 << 4) | (i % 10) | RTC_ALRMAR_MSK4 |
- RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK2;
- rtcSetAlarm(&RTCD1, 0, &alarmspec);
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- else{
- goto ERROR;
-@@ -129,12 +131,14 @@
- chprintf(chp, "Usage: alarm get\r\n");
- chprintf(chp, " alarm set N\r\n");
- chprintf(chp, "where N is alarm time in seconds\r\n");
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- /*
- *
+--- os/various/shell.c (Revision 6402)
++++ os/various/shell.c (Arbeitskopie)
+@@ -135,10 +135,11 @@
+ * @return Termination reason.
+ * @retval RDY_OK terminated by command.
+ * @retval RDY_RESET terminated by reset condition on the I/O channel.
++ *
++ * @notapi
*/
--static void cmd_date(BaseSequentialStream *chp, int argc, char *argv[]){
-+static int8_t cmd_date(BaseSequentialStream *chp, int argc, char *argv[]){
- (void)argv;
- struct tm timp;
-
-@@ -153,14 +157,14 @@
- rtcGetTimeTm(&RTCD1, &timp);
- chprintf(chp, "%s%s",asctime(&timp)," - formatted time string\r\n");
+ 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,16 +191,15 @@
+ }
}
-- return;
-+ return SHELL_CMD_CONTINUE;
}
-
- if ((argc == 2) && (strcmp(argv[0], "set") == 0)){
- unix_time = atol(argv[1]);
- if (unix_time > 0){
- rtcSetTimeUnixSec(&RTCD1, unix_time);
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- else{
- goto ERROR;
-@@ -176,7 +180,8 @@
- chprintf(chp, "where N is time in seconds sins Unix epoch\r\n");
- chprintf(chp, "you can get current N value from unix console by the command\r\n");
- chprintf(chp, "%s", "date +\%s\r\n");
-- return;
-+
-+ return SHELL_CMD_CONTINUE;
+- /* 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;
}
- static SerialConfig ser_cfg = {
-Index: testhal/STM32F4xx/RTC_FATTIME/main.c
-===================================================================
---- testhal/STM32F4xx/RTC_FATTIME/main.c (Revision 6305)
-+++ testhal/STM32F4xx/RTC_FATTIME/main.c (Arbeitskopie)
-@@ -51,7 +51,7 @@
/**
- *
+ * @brief Shell manager initialization.
++ *
++ * @api
*/
--void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
-+int8_t cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
- (void)argc;
- (void)argv;
- FRESULT err;
-@@ -66,7 +66,7 @@
- chprintf(chp, "ERROR! Chibios compiled without RTC support.");
- chprintf(chp, "Enable HAL_USE_RCT in you halconf.h");
- chThdSleepMilliseconds(100);
-- return;
-+ return SHELL_CMD_CONTINUE;
- #endif
-
- chprintf(chp, "Trying to connect SDIO... ");
-@@ -162,6 +162,8 @@
- else{
- chSysHalt();
- }
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- /*
-Index: testhal/STM32F4xx/USB_CDC/main.c
-===================================================================
---- testhal/STM32F4xx/USB_CDC/main.c (Revision 6305)
-+++ testhal/STM32F4xx/USB_CDC/main.c (Arbeitskopie)
-@@ -335,28 +335,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
+ void shellInit(void) {
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -367,26 +369,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
+@@ -207,6 +207,24 @@
}
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
+ /**
++ * @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) {
+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
- static uint8_t buf[] =
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
- "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
-@@ -408,13 +414,15 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: write\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
-
- while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
- chSequentialStreamWrite(&SDU2, buf, sizeof buf - 1);
- }
- chprintf(chp, "\r\n\nstopped\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 SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: testhal/STM32F4xx/SDC/main.c
-===================================================================
---- testhal/STM32F4xx/SDC/main.c (Revision 6305)
-+++ testhal/STM32F4xx/SDC/main.c (Arbeitskopie)
-@@ -101,7 +101,7 @@
- /**
++/**
+ * @brief Spawns a new shell.
+ * @pre @p CH_USE_MALLOC_HEAP and @p CH_USE_DYNAMIC must be enabled.
*
+@@ -215,6 +233,8 @@
+ * @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
*/
--void cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
-+int8_t cmd_sdiotest(BaseSequentialStream *chp, int argc, char *argv[]){
- (void)argc;
- (void)argv;
- uint32_t i = 0;
-@@ -325,6 +325,8 @@
- else{
- chSysHalt();
- }
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
-
-Index: demos/ARMCM4-STM32F407-LWIP-FATFS-USB/main.c
-===================================================================
---- demos/ARMCM4-STM32F407-LWIP-FATFS-USB/main.c (Revision 6305)
-+++ demos/ARMCM4-STM32F407-LWIP-FATFS-USB/main.c (Arbeitskopie)
-@@ -461,28 +461,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -493,26 +495,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
- FRESULT err;
- uint32_t clusters;
- FATFS *fsp;
-@@ -520,16 +526,16 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: tree\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- if (!fs_ready) {
- chprintf(chp, "File System not mounted\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- err = f_getfree("/", &clusters, &fsp);
- if (err != FR_OK) {
- chprintf(chp, "FS: f_getfree() failed\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp,
- "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
-@@ -537,6 +543,8 @@
- clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE);
- fbuff[0] = 0;
- scan_files(chp, (char *)fbuff);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/PPC-SPC56EL-GCC/main.c
-===================================================================
---- demos/PPC-SPC56EL-GCC/main.c (Revision 6305)
-+++ demos/PPC-SPC56EL-GCC/main.c (Arbeitskopie)
-@@ -23,28 +23,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(1024)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -55,23 +57,27 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/Posix-GCC/main.c
-===================================================================
---- demos/Posix-GCC/main.c (Revision 6305)
-+++ demos/Posix-GCC/main.c (Arbeitskopie)
-@@ -32,28 +32,30 @@
- static Thread *shelltp1;
- static Thread *shelltp2;
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -64,23 +66,27 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/ARMCM4-STM32F407-DISCOVERY-MEMS/main.c
-===================================================================
---- demos/ARMCM4-STM32F407-DISCOVERY-MEMS/main.c (Revision 6305)
-+++ demos/ARMCM4-STM32F407-DISCOVERY-MEMS/main.c (Arbeitskopie)
-@@ -34,28 +34,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -66,21 +68,23 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
- }
-Index: demos/ARMCM3-STM32F103ZG-FATFS/main.c
-===================================================================
---- demos/ARMCM3-STM32F103ZG-FATFS/main.c (Revision 6305)
-+++ demos/ARMCM3-STM32F103ZG-FATFS/main.c (Arbeitskopie)
-@@ -154,28 +154,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -186,26 +188,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
- FRESULT err;
- uint32_t clusters;
- FATFS *fsp;
-@@ -213,16 +219,16 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: tree\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- if (!fs_ready) {
- chprintf(chp, "File System not mounted\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- err = f_getfree("/", &clusters, &fsp);
- if (err != FR_OK) {
- chprintf(chp, "FS: f_getfree() failed\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp,
- "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
-@@ -230,6 +236,8 @@
- clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE);
- fbuff[0] = 0;
- scan_files(chp, (char *)fbuff);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/PPC-SPC563M-GCC/main.c
-===================================================================
---- demos/PPC-SPC563M-GCC/main.c (Revision 6305)
-+++ demos/PPC-SPC563M-GCC/main.c (Arbeitskopie)
-@@ -25,28 +25,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(1024)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -57,23 +59,27 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/ARMCM3-STM32F103-FATFS/main.c
-===================================================================
---- demos/ARMCM3-STM32F103-FATFS/main.c (Revision 6305)
-+++ demos/ARMCM3-STM32F103-FATFS/main.c (Arbeitskopie)
-@@ -176,28 +176,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -208,26 +210,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
- FRESULT err;
- uint32_t clusters;
- FATFS *fsp;
-@@ -235,16 +241,16 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: tree\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- if (!fs_ready) {
- chprintf(chp, "File System not mounted\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- err = f_getfree("/", &clusters, &fsp);
- if (err != FR_OK) {
- chprintf(chp, "FS: f_getfree() failed\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp,
- "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
-@@ -252,6 +258,8 @@
- clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE);
- fbuff[0] = 0;
- scan_files(chp, (char *)fbuff);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/ARMCM3-STM32F107-FATFS/main.c
-===================================================================
---- demos/ARMCM3-STM32F107-FATFS/main.c (Revision 6305)
-+++ demos/ARMCM3-STM32F107-FATFS/main.c (Arbeitskopie)
-@@ -168,28 +168,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(2048)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -200,26 +202,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
- FRESULT err;
- uint32_t clusters;
- FATFS *fsp;
-@@ -227,16 +233,16 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: tree\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- if (!fs_ready) {
- chprintf(chp, "File System not mounted\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- err = f_getfree("/", &clusters, &fsp);
- if (err != FR_OK) {
- chprintf(chp, "FS: f_getfree() failed\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp,
- "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
-@@ -244,6 +250,8 @@
- clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE);
- fbuff[0] = 0;
- scan_files(chp, (char *)fbuff);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/PPC-SPC560B-GCC/main.c
-===================================================================
---- demos/PPC-SPC560B-GCC/main.c (Revision 6305)
-+++ demos/PPC-SPC560B-GCC/main.c (Arbeitskopie)
-@@ -23,28 +23,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(1024)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -55,23 +57,27 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-@@ -173,6 +179,11 @@
- chSysInit();
-
- /*
-+ * Shell manager initialization.
-+ */
-+ shellInit();
-+
-+ /*
- * Activates the serial driver 1 using the driver default configuration.
- */
- sdStart(&SD1, NULL);
-Index: demos/ARM7-AT91SAM7X-FATFS-GCC/main.c
-===================================================================
---- demos/ARM7-AT91SAM7X-FATFS-GCC/main.c (Revision 6305)
-+++ demos/ARM7-AT91SAM7X-FATFS-GCC/main.c (Arbeitskopie)
-@@ -188,28 +188,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(1024)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -220,26 +222,30 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
- FRESULT err;
- uint32_t clusters;
- FATFS *fsp;
-@@ -247,16 +253,16 @@
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: tree\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- if (!fs_ready) {
- chprintf(chp, "File System not mounted\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- err = f_getfree("/", &clusters, &fsp);
- if (err != FR_OK) {
- chprintf(chp, "FS: f_getfree() failed\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp,
- "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
-@@ -264,6 +270,8 @@
- clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE);
- fbuff[0] = 0;
- scan_files(chp, (char *)fbuff);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/PPC-SPC564A-GCC/main.c
-===================================================================
---- demos/PPC-SPC564A-GCC/main.c (Revision 6305)
-+++ demos/PPC-SPC564A-GCC/main.c (Arbeitskopie)
-@@ -25,28 +25,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(1024)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -57,23 +59,27 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/PPC-SPC560P-GCC/main.c
-===================================================================
---- demos/PPC-SPC560P-GCC/main.c (Revision 6305)
-+++ demos/PPC-SPC560P-GCC/main.c (Arbeitskopie)
-@@ -23,28 +23,30 @@
- #define SHELL_WA_SIZE THD_WA_SIZE(1024)
- #define TEST_WA_SIZE THD_WA_SIZE(256)
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -55,23 +57,27 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: demos/Win32-MinGW/main.c
-===================================================================
---- demos/Win32-MinGW/main.c (Revision 6305)
-+++ demos/Win32-MinGW/main.c (Arbeitskopie)
-@@ -30,28 +30,30 @@
- static Thread *shelltp1;
- static Thread *shelltp2;
-
--static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {THD_STATE_NAMES};
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
-@@ -62,23 +64,27 @@
- states[tp->p_state], (uint32_t)tp->p_time);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- Thread *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chThdWait(tp);
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- static const ShellCommand commands[] = {
-Index: os/various/shell.c
-===================================================================
---- os/various/shell.c (Revision 6305)
-+++ os/various/shell.c (Arbeitskopie)
-@@ -64,12 +64,12 @@
- }
- }
-
--static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
-
- (void)argv;
- if (argc > 0) {
- usage(chp, "info");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
-
- chprintf(chp, "Kernel: %s\r\n", CH_KERNEL_VERSION);
-@@ -94,16 +94,20 @@
- chprintf(chp, "Build time: %s%s%s\r\n", __DATE__, " - ", __TIME__);
- #endif
- #endif
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
--static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
-+static int8_t cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
-
- (void)argv;
- if (argc > 0) {
- usage(chp, "systime");
-- return;
-+ return SHELL_CMD_CONTINUE;
- }
- chprintf(chp, "%lu\r\n", (unsigned long)chTimeNow());
-+
-+ return SHELL_CMD_CONTINUE;
- }
-
- /**
-@@ -116,11 +120,11 @@
- };
-
- static bool_t cmdexec(const ShellCommand *scp, BaseSequentialStream *chp,
-- char *name, int argc, char *argv[]) {
-+ char *name, int argc, char *argv[], int8_t *cont) {
-
- while (scp->sc_name != NULL) {
- if (strcasecmp(scp->sc_name, name) == 0) {
-- scp->sc_function(chp, argc, argv);
-+ *cont = scp->sc_function(chp, argc, argv);
- return FALSE;
- }
- scp++;
-@@ -143,6 +147,7 @@
- const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
- char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
- char *args[SHELL_MAX_ARGUMENTS + 1];
-+ int8_t cont = SHELL_CMD_CONTINUE;
-
- chRegSetThreadName("shell");
- chprintf(chp, "\r\nChibiOS/RT Shell\r\n");
-@@ -183,11 +188,13 @@
- 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))) {
-+ else if (cmdexec(local_commands, chp, cmd, n, args, &cont) &&
-+ ((scp == NULL) || cmdexec(scp, chp, cmd, n, args, &cont))) {
- chprintf(chp, "%s", cmd);
- chprintf(chp, " ?\r\n");
- }
-+ if(cont == SHELL_CMD_EXIT)
-+ break;
- }
- }
- /* Atomically broadcasting the event source and terminating the thread,
+ #if CH_USE_HEAP && CH_USE_DYNAMIC
+ Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio) {
+@@ -247,6 +267,8 @@
+ * @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;
Index: os/various/shell.h
===================================================================
---- os/various/shell.h (Revision 6305)
+--- os/various/shell.h (Revision 6402)
+++ os/various/shell.h (Arbeitskopie)
-@@ -40,9 +40,19 @@
+@@ -70,6 +70,7 @@
+ extern "C" {
#endif
-
- /**
-+ * @brief The shell will terminate when a command returns this.
-+ */
-+#define SHELL_CMD_EXIT 0
-+
-+/**
-+ * @brief The shell continues to run when a command returns this.
-+ */
-+#define SHELL_CMD_CONTINUE 1
-+
-+/**
- * @brief Command handler function type.
- */
--typedef void (*shellcmd_t)(BaseSequentialStream *chp, int argc, char *argv[]);
-+typedef int8_t (*shellcmd_t)(BaseSequentialStream *chp, int argc, char *argv[]);
-
- /**
- * @brief Custom command entry type.
+ 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);