From 4becbef6de9e4b5d6b8f027f91de846b4702a1cb Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 1 Oct 2012 13:54:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4729 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/PPC-SPC560P-GCC/Makefile | 8 ++--- demos/PPC-SPC560P-GCC/main.c | 82 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 4 deletions(-) (limited to 'demos') diff --git a/demos/PPC-SPC560P-GCC/Makefile b/demos/PPC-SPC560P-GCC/Makefile index 0d17f25cd..62303fdd1 100644 --- a/demos/PPC-SPC560P-GCC/Makefile +++ b/demos/PPC-SPC560P-GCC/Makefile @@ -51,7 +51,7 @@ include $(CHIBIOS)/os/hal/platforms/SPC560Pxx/platform.mk include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/ports/GCC/PPC/SPC560Pxx/port.mk include $(CHIBIOS)/os/kernel/kernel.mk -#include $(CHIBIOS)/test/test.mk +include $(CHIBIOS)/test/test.mk # Define linker script file here LDSCRIPT= $(PORTLD)/SPC560P44.ld @@ -63,10 +63,10 @@ CSRC = $(PORTSRC) \ $(HALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ + $(CHIBIOS)/os/various/evtimer.c \ + $(CHIBIOS)/os/various/shell.c \ + $(CHIBIOS)/os/various/chprintf.c \ main.c -# $(CHIBIOS)/os/various/evtimer.c \ -# $(CHIBIOS)/os/various/shell.c \ -# $(CHIBIOS)/os/various/chprintf.c \ # C++ sources here. CPPSRC = diff --git a/demos/PPC-SPC560P-GCC/main.c b/demos/PPC-SPC560P-GCC/main.c index 73df39549..b296da222 100644 --- a/demos/PPC-SPC560P-GCC/main.c +++ b/demos/PPC-SPC560P-GCC/main.c @@ -20,6 +20,75 @@ #include "ch.h" #include "hal.h" +#include "test.h" +#include "shell.h" +#include "chprintf.h" + +#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[]) { + 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", chCoreStatus()); + 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[] = {THD_STATE_NAMES}; + Thread *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, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n", + (uint32_t)tp, (uint32_t)tp->p_ctx.sp, + (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), + states[tp->p_state], (uint32_t)tp->p_time); + tp = chRegNextThread(tp); + } while (tp != NULL); +} + +static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { + Thread *tp; + + (void)argv; + if (argc > 0) { + chprintf(chp, "Usage: test\r\n"); + return; + } + tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), + TestThread, chp); + if (tp == NULL) { + chprintf(chp, "out of memory\r\n"); + return; + } + chThdWait(tp); +} + +static const ShellCommand commands[] = { + {"mem", cmd_mem}, + {"threads", cmd_threads}, + {"test", cmd_test}, + {NULL, NULL} +}; + +static const ShellConfig shell_cfg1 = { + (BaseSequentialStream *)&SD1, + commands +}; /* * LEDs blinker thread, times are in milliseconds. @@ -95,6 +164,7 @@ static msg_t Thread1(void *arg) { * Application entry point. */ int main(void) { + Thread *shelltp = NULL; /* * System initializations. @@ -106,6 +176,11 @@ int main(void) { halInit(); chSysInit(); + /* + * Activates the serial driver 1 using the driver default configuration. + */ + sdStart(&SD1, NULL); + /* * Creates the blinker thread. */ @@ -115,6 +190,13 @@ int main(void) { * Normal main() thread activity. */ while (TRUE) { + + if (!shelltp) + shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); + else if (chThdTerminated(shelltp)) { + chThdRelease(shelltp); /* Recovers memory of the previous shell. */ + shelltp = NULL; /* Triggers spawning of a new shell. */ + } chThdSleepMilliseconds(1000); } return 0; -- cgit v1.2.3