diff options
35 files changed, 150 insertions, 243 deletions
diff --git a/demos/SPC5/RT-SPC560B-EVB/Makefile b/demos/SPC5/RT-SPC560B-EVB/Makefile index 175063aad..798272346 100644 --- a/demos/SPC5/RT-SPC560B-EVB/Makefile +++ b/demos/SPC5/RT-SPC560B-EVB/Makefile @@ -91,7 +91,7 @@ include $(CHIBIOS)/os/hal/ports/SPC5/SPC560Bxx/platform.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
-include $(CHIBIOS)/os/common/startup/e200/compilers/GCC/mk/port.mk
+include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional).
include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
diff --git a/demos/SPC5/RT-SPC560B-EVB/main.c b/demos/SPC5/RT-SPC560B-EVB/main.c index 5b5d89d44..3f5e7e2c8 100644 --- a/demos/SPC5/RT-SPC560B-EVB/main.c +++ b/demos/SPC5/RT-SPC560B-EVB/main.c @@ -136,8 +136,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/demos/SPC5/RT-SPC560D-EVB/Makefile b/demos/SPC5/RT-SPC560D-EVB/Makefile index 01d02d200..f6b4064cd 100644 --- a/demos/SPC5/RT-SPC560D-EVB/Makefile +++ b/demos/SPC5/RT-SPC560D-EVB/Makefile @@ -91,7 +91,7 @@ include $(CHIBIOS)/os/hal/ports/SPC5/SPC560Dxx/platform.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
-include $(CHIBIOS)/os/common/startup/e200/compilers/GCC/mk/port.mk
+include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional).
include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
diff --git a/demos/SPC5/RT-SPC560D-EVB/main.c b/demos/SPC5/RT-SPC560D-EVB/main.c index 5b5d89d44..3f5e7e2c8 100644 --- a/demos/SPC5/RT-SPC560D-EVB/main.c +++ b/demos/SPC5/RT-SPC560D-EVB/main.c @@ -136,8 +136,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/demos/SPC5/RT-SPC560P-EVB/main.c b/demos/SPC5/RT-SPC560P-EVB/main.c index 07087821d..f0bc69b5d 100644 --- a/demos/SPC5/RT-SPC560P-EVB/main.c +++ b/demos/SPC5/RT-SPC560P-EVB/main.c @@ -136,8 +136,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/demos/SPC5/RT-SPC563M-EVB/main.c b/demos/SPC5/RT-SPC563M-EVB/main.c index 866212741..a273a25e6 100644 --- a/demos/SPC5/RT-SPC563M-EVB/main.c +++ b/demos/SPC5/RT-SPC563M-EVB/main.c @@ -119,8 +119,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/demos/SPC5/RT-SPC564A-EVB/main.c b/demos/SPC5/RT-SPC564A-EVB/main.c index 866212741..a273a25e6 100644 --- a/demos/SPC5/RT-SPC564A-EVB/main.c +++ b/demos/SPC5/RT-SPC564A-EVB/main.c @@ -119,8 +119,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/demos/SPC5/RT-SPC56EC-EVB/main.c b/demos/SPC5/RT-SPC56EC-EVB/main.c index 5b5d89d44..3f5e7e2c8 100644 --- a/demos/SPC5/RT-SPC56EC-EVB/main.c +++ b/demos/SPC5/RT-SPC56EC-EVB/main.c @@ -136,8 +136,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/demos/SPC5/RT-SPC56EL-EVB/main.c b/demos/SPC5/RT-SPC56EL-EVB/main.c index 07087821d..f0bc69b5d 100644 --- a/demos/SPC5/RT-SPC56EL-EVB/main.c +++ b/demos/SPC5/RT-SPC56EL-EVB/main.c @@ -136,8 +136,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c b/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c index ccc1f600e..9b363e69d 100644 --- a/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c +++ b/demos/STM32/CMSIS-STM32F407-DISCOVERY/main.c @@ -36,7 +36,7 @@ static void Thread1(void const *arg) { /*
* Thread definition block.
*/
-osThreadDef(Thread1, osPriorityAboveNormal, 128);
+osThreadDef(Thread1, osPriorityAboveNormal, 128, "blinker");
/*
* Application entry point.
diff --git a/demos/STM32/RT-STM32F103-MAPLEMINI/main.c b/demos/STM32/RT-STM32F103-MAPLEMINI/main.c index 6b85c77a0..5cde100ed 100644 --- a/demos/STM32/RT-STM32F103-MAPLEMINI/main.c +++ b/demos/STM32/RT-STM32F103-MAPLEMINI/main.c @@ -150,8 +150,8 @@ int __attribute__((noreturn)) main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/main.c b/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/main.c index 54fe64ee6..50f0d2cdf 100644 --- a/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/main.c +++ b/demos/STM32/RT-STM32F103-STM3210E_EVAL-FATFS-USB/main.c @@ -317,8 +317,8 @@ int main(void) { while (true) {
if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) {
shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
}
chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
}
diff --git a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c index 2588fb35a..cb564126b 100644 --- a/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c +++ b/demos/STM32/RT-STM32F103_INEMO_DISCOVERY/main.c @@ -150,8 +150,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/main.c b/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/main.c index 820163f4f..aa32b54ed 100644 --- a/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/main.c +++ b/demos/STM32/RT-STM32F407-DISCOVERY-MEMS/main.c @@ -249,8 +249,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile index 6b628df43..6d3804bc9 100644 --- a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile +++ b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/Makefile @@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk # Other files (optional). include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/hal/lib/streams/streams.mk +include $(CHIBIOS)/os/various/shell/shell.mk include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk @@ -117,10 +119,9 @@ CSRC = $(STARTUPSRC) \ $(TESTSRC) \ $(LWSRC) \ $(FATFSSRC) \ + $(STREAMSSRC) \ + $(SHELLSRC) \ $(CHIBIOS)/os/various/evtimer.c \ - $(CHIBIOS)/os/hal/lib/streams/memstreams.c \ - $(CHIBIOS)/os/hal/lib/streams/chprintf.c \ - $(CHIBIOS)/os/various/shell.c \ web/web.c usbcfg.c main.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global @@ -152,8 +153,8 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(LWINC) $(FATFSINC) \ - $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various + $(STREAMSINC) $(SHELLINC) $(LWINC) $(FATFSINC) \ + $(CHIBIOS)/os/various # # Project, sources and paths diff --git a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/main.c b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/main.c index fd3dfc619..384cdb4b3 100644 --- a/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/main.c +++ b/demos/STM32/RT-STM32F407-OLIMEX_E407-LWIP-FATFS-USB/main.c @@ -157,58 +157,6 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) { /*===========================================================================*/ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) -#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) - -static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { - size_t n, size; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: mem\r\n"); - return; - } - n = chHeapStatus(NULL, &size); - chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); - chprintf(chp, "heap fragments : %u\r\n", n); - chprintf(chp, "heap free total : %u bytes\r\n", size); -} - -static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { - static const char *states[] = {CH_STATE_NAMES}; - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: threads\r\n"); - return; - } - chprintf(chp, " addr stack prio refs state time\r\n"); - tp = chRegFirstThread(); - do { - chprintf(chp, "%08lx %08lx %4lu %4lu %9s\r\n", - (uint32_t)tp, (uint32_t)tp->p_ctx.r13, - (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), - states[tp->p_state]); - tp = chRegNextThread(tp); - } while (tp != NULL); -} - -static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { - thread_t *tp; - - (void)argv; - if (argc > 0) { - chprintf(chp, "Usage: test\r\n"); - return; - } - tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(), - TestThread, chp); - if (tp == NULL) { - chprintf(chp, "out of memory\r\n"); - return; - } - chThdWait(tp); -} static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) { FRESULT err; @@ -238,9 +186,6 @@ static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) { } static const ShellCommand commands[] = { - {"mem", cmd_mem}, - {"threads", cmd_threads}, - {"test", cmd_test}, {"tree", cmd_tree}, {NULL, NULL} }; @@ -254,6 +199,8 @@ static const ShellConfig shell_cfg1 = { /* Main and generic code. */ /*===========================================================================*/ +static thread_t *shelltp = NULL; + /* * Card insertion event. */ @@ -286,6 +233,18 @@ static void RemoveHandler(eventid_t id) { } /* + * Shell exit event. + */ +static void ShellHandler(eventid_t id) { + + (void)id; + if (chThdTerminatedX(shelltp)) { + chThdFreeToHeap(shelltp); /* Returning memory to heap. */ + shelltp = NULL; + } +} + +/* * Green LED blinker thread, times are in milliseconds. */ static THD_WORKING_AREA(waThread1, 128); @@ -303,12 +262,12 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point. */ int main(void) { - static thread_t *shelltp = NULL; static const evhandler_t evhndl[] = { InsertHandler, - RemoveHandler + RemoveHandler, + ShellHandler }; - event_listener_t el0, el1; + event_listener_t el0, el1, el2; /* * System initializations. @@ -367,19 +326,17 @@ int main(void) { http_server, NULL); /* - * Normal main() thread activity, in this demo it does nothing except - * sleeping in a loop and listen for events. + * Normal main() thread activity, handling SD card events and shell + * start/exit. */ chEvtRegister(&inserted_event, &el0, 0); chEvtRegister(&removed_event, &el1, 1); + chEvtRegister(&shell_terminated, &el2, 2); while (true) { - if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) - shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); - else if (chThdTerminatedX(shelltp)) { - chThdRelease(shelltp); /* Recovers memory of the previous shell. */ - shelltp = NULL; /* Triggers spawning of a new shell. */ - } - if (palReadPad(GPIOA, GPIOA_BUTTON_WKUP) != 0) { + if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) { + shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, + "shell", NORMALPRIO + 1, + shellThread, (void *)&shell_cfg1); } chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500))); } diff --git a/demos/STM32/RT-STM32F429-DISCOVERY/main.c b/demos/STM32/RT-STM32F429-DISCOVERY/main.c index 0f42d959f..a78734b5b 100644 --- a/demos/STM32/RT-STM32F429-DISCOVERY/main.c +++ b/demos/STM32/RT-STM32F429-DISCOVERY/main.c @@ -124,8 +124,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/Makefile b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/Makefile index f227ba035..888201574 100644 --- a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/Makefile +++ b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/Makefile @@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional).
include $(CHIBIOS)/test/rt/test.mk
+include $(CHIBIOS)/os/hal/lib/streams/streams.mk
+include $(CHIBIOS)/os/various/shell/shell.mk
include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk
include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk
@@ -117,10 +119,9 @@ CSRC = $(STARTUPSRC) \ $(TESTSRC) \
$(LWSRC) \
$(FATFSSRC) \
+ $(STREAMSSRC) \
+ $(SHELLSRC) \
$(CHIBIOS)/os/various/evtimer.c \
- $(CHIBIOS)/os/hal/lib/streams/memstreams.c \
- $(CHIBIOS)/os/hal/lib/streams/chprintf.c \
- $(CHIBIOS)/os/various/shell.c \
web/web.c usbcfg.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
@@ -152,8 +153,8 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM) INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
- $(LWINC) $(FATFSINC) \
- $(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various
+ $(STREAMSINC) $(SHELLINC) $(LWINC) $(FATFSINC) \
+ $(CHIBIOS)/os/various
#
# Project, sources and paths
diff --git a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/main.c b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/main.c index 6cad8655d..498c23319 100644 --- a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/main.c +++ b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/main.c @@ -157,58 +157,6 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) { /*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
-#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
-
-static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
- return;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-}
-
-static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {CH_STATE_NAMES};
- thread_t *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
- return;
- }
- chprintf(chp, " addr stack prio refs state time\r\n");
- tp = chRegFirstThread();
- do {
- chprintf(chp, "%08lx %08lx %4lu %4lu %9s\r\n",
- (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
- (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
- states[tp->p_state]);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-}
-
-static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- thread_t *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
- return;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
- return;
- }
- chThdWait(tp);
-}
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
FRESULT err;
@@ -238,9 +186,6 @@ static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) { }
static const ShellCommand commands[] = {
- {"mem", cmd_mem},
- {"threads", cmd_threads},
- {"test", cmd_test},
{"tree", cmd_tree},
{NULL, NULL}
};
@@ -254,6 +199,8 @@ static const ShellConfig shell_cfg1 = { /* Main and generic code. */
/*===========================================================================*/
+static thread_t *shelltp = NULL;
+
/*
* Card insertion event.
*/
@@ -286,6 +233,18 @@ static void RemoveHandler(eventid_t id) { }
/*
+ * Shell exit event.
+ */
+static void ShellHandler(eventid_t id) {
+
+ (void)id;
+ if (chThdTerminatedX(shelltp)) {
+ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
+ shelltp = NULL;
+ }
+}
+
+/*
* Green LED blinker thread, times are in milliseconds.
*/
static THD_WORKING_AREA(waThread1, 128);
@@ -303,12 +262,12 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point.
*/
int main(void) {
- static thread_t *shelltp = NULL;
static const evhandler_t evhndl[] = {
InsertHandler,
- RemoveHandler
+ RemoveHandler,
+ ShellHandler
};
- event_listener_t el0, el1;
+ event_listener_t el0, el1, el2;
/*
* System initializations.
@@ -372,19 +331,17 @@ int main(void) { http_server, NULL);
/*
- * Normal main() thread activity, in this demo it does nothing except
- * sleeping in a loop and listen for events.
+ * Normal main() thread activity, handling SD card events and shell
+ * start/exit.
*/
chEvtRegister(&inserted_event, &el0, 0);
chEvtRegister(&removed_event, &el1, 1);
+ chEvtRegister(&shell_terminated, &el2, 2);
while (true) {
- if (!shelltp && (SDU2.config->usbp->state == USB_ACTIVE))
- shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
- else if (chThdTerminatedX(shelltp)) {
- chThdRelease(shelltp); /* Recovers memory of the previous shell. */
- shelltp = NULL; /* Triggers spawning of a new shell. */
- }
- if (palReadPad(GPIOI, GPIOI_BUTTON_USER) != 0) {
+ if (!shelltp && (SDU2.config->usbp->state == USB_ACTIVE)) {
+ shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
}
chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
}
diff --git a/os/common/oslib/include/chdynamic.h b/os/common/oslib/include/chdynamic.h index 35b47cd93..fa42bf3ae 100644 --- a/os/common/oslib/include/chdynamic.h +++ b/os/common/oslib/include/chdynamic.h @@ -73,12 +73,13 @@ extern "C" { #endif
#if CH_CFG_USE_HEAP == TRUE
thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size,
- tprio_t prio, tfunc_t pf, void *arg);
+ const char *name, tprio_t prio,
+ tfunc_t pf, void *arg);
void chThdFreeToHeap(thread_t *tp);
#endif
#if CH_CFG_USE_MEMPOOLS == TRUE
- thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio,
- tfunc_t pf, void *arg);
+ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name,
+ tprio_t prio, tfunc_t pf, void *arg);
void chThdFreeToMemoryPool(thread_t *tp, memory_pool_t *mp);
#endif
#ifdef __cplusplus
diff --git a/os/common/oslib/src/chdynamic.c b/os/common/oslib/src/chdynamic.c index 80555a928..3865c318a 100644 --- a/os/common/oslib/src/chdynamic.c +++ b/os/common/oslib/src/chdynamic.c @@ -69,6 +69,7 @@ * @param[in] heapp heap from which allocate the memory or @p NULL for the
* default heap
* @param[in] size size of the working area to be allocated
+ * @param[in] name thread name
* @param[in] prio the priority level for the new thread
* @param[in] pf the thread function
* @param[in] arg an argument passed to the thread function. It can be
@@ -80,7 +81,8 @@ * @api
*/
thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size,
- tprio_t prio, tfunc_t pf, void *arg) {
+ const char *name, tprio_t prio,
+ tfunc_t pf, void *arg) {
void *wsp;
wsp = chHeapAllocAligned(heapp, size, PORT_WORKING_AREA_ALIGN);
@@ -88,13 +90,16 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, return NULL;
}
-#if CH_DBG_FILL_THREADS == TRUE
- _thread_memfill((uint8_t *)wsp,
- (uint8_t *)wsp + size,
- CH_DBG_STACK_FILL_VALUE);
-#endif
+ thread_descriptor_t td = {
+ name,
+ wsp,
+ (stkalign_t *)((uint8_t *)wsp + size),
+ prio,
+ pf,
+ arg
+ };
- return chThdCreateStatic(wsp, size, prio, pf, arg);
+ return chThdCreate(&td);
}
/**
@@ -131,6 +136,7 @@ void chThdFreeToHeap(thread_t *tp) { * and then release the allocated memory.
*
* @param[in] mp pointer to the memory pool object
+ * @param[in] name thread name
* @param[in] prio the priority level for the new thread
* @param[in] pf the thread function
* @param[in] arg an argument passed to the thread function. It can be
@@ -141,8 +147,8 @@ void chThdFreeToHeap(thread_t *tp) { *
* @api
*/
-thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio,
- tfunc_t pf, void *arg) {
+thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name,
+ tprio_t prio, tfunc_t pf, void *arg) {
void *wsp;
chDbgCheck(mp != NULL);
@@ -152,13 +158,16 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, tprio_t prio, return NULL;
}
-#if CH_DBG_FILL_THREADS == TRUE
- _thread_memfill((uint8_t *)wsp,
- (uint8_t *)wsp + mp->object_size,
- CH_DBG_STACK_FILL_VALUE);
-#endif
+ thread_descriptor_t td = {
+ name,
+ wsp,
+ (stkalign_t *)((uint8_t *)wsp + mp->object_size),
+ prio,
+ pf,
+ arg
+ };
- return chThdCreateStatic(wsp, mp->object_size, prio, pf, arg);
+ return chThdCreate(&td);
}
/**
diff --git a/os/common/ports/ARMCMx/cmsis_os/cmsis_os.c b/os/common/ports/ARMCMx/cmsis_os/cmsis_os.c index 6b328ea7f..04bebeb1d 100644 --- a/os/common/ports/ARMCMx/cmsis_os/cmsis_os.c +++ b/os/common/ports/ARMCMx/cmsis_os/cmsis_os.c @@ -119,6 +119,7 @@ osThreadId osThreadCreate(const osThreadDef_t *thread_def, void *argument) { thread_def->stacksize;
return (osThreadId)chThdCreateFromHeap(0,
THD_WORKING_AREA_SIZE(size),
+ thread_def->name,
NORMALPRIO+thread_def->tpriority,
(tfunc_t)thread_def->pthread,
argument);
diff --git a/os/common/ports/ARMCMx/cmsis_os/cmsis_os.h b/os/common/ports/ARMCMx/cmsis_os/cmsis_os.h index 41d96baed..1c0998baf 100644 --- a/os/common/ports/ARMCMx/cmsis_os/cmsis_os.h +++ b/os/common/ports/ARMCMx/cmsis_os/cmsis_os.h @@ -243,6 +243,7 @@ typedef struct os_thread_def { os_pthread pthread;
osPriority tpriority;
uint32_t stacksize;
+ const char *name;
} osThreadDef_t;
/**
@@ -301,14 +302,15 @@ typedef struct os_messageQ_def { * @brief Create a Thread definition.
*/
#if defined(osObjectsExternal)
-#define osThreadDef(name, priority, instances, stacksz) \
- extern const osThreadDef_t os_thread_def_##name
+#define osThreadDef(thd, priority, stacksz, name) \
+ extern const osThreadDef_t os_thread_def_##thd
#else
-#define osThreadDef(name, priority, stacksz) \
-const osThreadDef_t os_thread_def_##name = { \
- (name), \
+#define osThreadDef(thd, priority, stacksz, name) \
+const osThreadDef_t os_thread_def_##thd = { \
+ (thd), \
(priority), \
- (stacksz) \
+ (stacksz), \
+ (name) \
}
#endif
diff --git a/os/various/lwip_bindings/arch/sys_arch.c b/os/various/lwip_bindings/arch/sys_arch.c index 950213ef1..40577f2bc 100644 --- a/os/various/lwip_bindings/arch/sys_arch.c +++ b/os/various/lwip_bindings/arch/sys_arch.c @@ -204,32 +204,10 @@ void sys_mbox_set_invalid(sys_mbox_t *mbox) { sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread,
void *arg, int stacksize, int prio) {
- size_t wsz;
- void *wsp;
- syssts_t sts;
thread_t *tp;
- (void)name;
- wsz = THD_WORKING_AREA_SIZE(stacksize);
- wsp = chCoreAlloc(wsz);
- if (wsp == NULL)
- return NULL;
-
-#if CH_DBG_FILL_THREADS == TRUE
- _thread_memfill((uint8_t *)wsp,
- (uint8_t *)wsp + sizeof(thread_t),
- CH_DBG_THREAD_FILL_VALUE);
- _thread_memfill((uint8_t *)wsp + sizeof(thread_t),
- (uint8_t *)wsp + wsz,
- CH_DBG_STACK_FILL_VALUE);
-#endif
-
- sts = chSysGetStatusAndLockX();
- tp = chThdCreateI(wsp, wsz, prio, (tfunc_t)thread, arg);
- chRegSetThreadNameX(tp, name);
- chThdStartI(tp);
- chSysRestoreStatusX(sts);
-
+ tp = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(stacksize),
+ name, prio, (tfunc_t)thread, arg);
return (sys_thread_t)tp;
}
diff --git a/os/various/shell/shell.c b/os/various/shell/shell.c index 958afcaf1..0cbaedc81 100644 --- a/os/various/shell/shell.c +++ b/os/various/shell/shell.c @@ -130,7 +130,6 @@ THD_FUNCTION(shellThread, p) { 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> ");
diff --git a/os/various/shell/shell_cmd.c b/os/various/shell/shell_cmd.c index 7d592286b..6432f59d3 100644 --- a/os/various/shell/shell_cmd.c +++ b/os/various/shell/shell_cmd.c @@ -165,7 +165,8 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { chprintf(chp, "Usage: test\r\n");
return;
}
- tp = chThdCreateFromHeap(NULL, SHELL_CMD_TEST_WA_SIZE, chThdGetPriorityX(),
+ tp = chThdCreateFromHeap(NULL, SHELL_CMD_TEST_WA_SIZE,
+ "test", chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
diff --git a/testhal/STM32/STM32F0xx/USB_CDC/main.c b/testhal/STM32/STM32F0xx/USB_CDC/main.c index 809e389a2..23605c5c4 100644 --- a/testhal/STM32/STM32F0xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F0xx/USB_CDC/main.c @@ -152,8 +152,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/testhal/STM32/STM32F1xx/USB_CDC/main.c b/testhal/STM32/STM32F1xx/USB_CDC/main.c index 17c49f749..33889477c 100644 --- a/testhal/STM32/STM32F1xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F1xx/USB_CDC/main.c @@ -151,8 +151,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/testhal/STM32/STM32F37x/USB_CDC/main.c b/testhal/STM32/STM32F37x/USB_CDC/main.c index 20db587df..1f3fd7182 100644 --- a/testhal/STM32/STM32F37x/USB_CDC/main.c +++ b/testhal/STM32/STM32F37x/USB_CDC/main.c @@ -158,8 +158,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/testhal/STM32/STM32F3xx/USB_CDC/main.c b/testhal/STM32/STM32F3xx/USB_CDC/main.c index 11bb6bf5c..76e1c64bb 100644 --- a/testhal/STM32/STM32F3xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F3xx/USB_CDC/main.c @@ -159,8 +159,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c b/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c index 430f00848..f45c4611c 100644 --- a/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c +++ b/testhal/STM32/STM32F3xx/USB_CDC_IAD/main.c @@ -171,13 +171,13 @@ int main(void) { /* Starting shells.*/
if (shelltp1 == NULL) {
shelltp1 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell1", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
}
if (shelltp2 == NULL) {
shelltp2 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg2);
+ "shell2", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg2);
}
/* Waiting for an exit event then freeing terminated shells.*/
diff --git a/testhal/STM32/STM32F4xx/SDC/main.c b/testhal/STM32/STM32F4xx/SDC/main.c index 2aed5c496..5c319fc09 100644 --- a/testhal/STM32/STM32F4xx/SDC/main.c +++ b/testhal/STM32/STM32F4xx/SDC/main.c @@ -328,8 +328,8 @@ int main(void) { */
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
chThdSleepMilliseconds(1000);
diff --git a/testhal/STM32/STM32F4xx/USB_CDC/main.c b/testhal/STM32/STM32F4xx/USB_CDC/main.c index 02853f63a..cffc8427a 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F4xx/USB_CDC/main.c @@ -159,8 +159,8 @@ int main(void) { while (true) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
diff --git a/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c b/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c index 73751fb97..84c7ec3fc 100644 --- a/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c +++ b/testhal/STM32/STM32F4xx/USB_CDC_IAD/main.c @@ -164,13 +164,13 @@ int main(void) { /* Starting shells.*/
if (shelltp1 == NULL) {
shelltp1 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell1", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
}
if (shelltp2 == NULL) {
shelltp2 = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg2);
+ "shell2", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg2);
}
/* Waiting for an exit event then freeing terminated shells.*/
diff --git a/testhal/STM32/STM32F7xx/USB_CDC/main.c b/testhal/STM32/STM32F7xx/USB_CDC/main.c index f3a11be5a..940bde5a1 100644 --- a/testhal/STM32/STM32F7xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F7xx/USB_CDC/main.c @@ -158,8 +158,8 @@ int main(void) { while (true) {
if (SDU2.config->usbp->state == USB_ACTIVE) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- NORMALPRIO + 1, shellThread,
- (void *)&shell_cfg1);
+ "shell", NORMALPRIO + 1,
+ shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
|