From 8f89ec3c0bb6f4bc5a77afd37ebb3919181f7a4d Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 21 Feb 2016 10:45:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8919 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- .../Makefile | 11 +-- .../RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/main.c | 91 ++++++---------------- 2 files changed, 30 insertions(+), 72 deletions(-) (limited to 'demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB') 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. */ @@ -285,6 +232,18 @@ static void RemoveHandler(eventid_t id) { fs_ready = FALSE; } +/* + * 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. */ @@ -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))); } -- cgit v1.2.3