From 582ace5597d3bdefcd06b8b4ab673f48c81b969c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 22 Feb 2010 16:29:48 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1660 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- boards/GENERIC_SPC563/board.c | 1 + boards/GENERIC_SPC563/board.h | 1 + demos/PPC-SPC563-GCC/Makefile | 5 +- demos/PPC-SPC563-GCC/main.c | 105 ++++++++++++++++++++++++++++-- os/kernel/templates/chcore.h | 4 +- os/ports/GCC/PPC/SPC56x/vectors.s | 2 +- os/ports/GCC/PPC/chcore.h | 35 +++++++--- os/various/shell.c | 21 ++++-- 8 files changed, 152 insertions(+), 22 deletions(-) diff --git a/boards/GENERIC_SPC563/board.c b/boards/GENERIC_SPC563/board.c index 254d72dcc..63e882851 100644 --- a/boards/GENERIC_SPC563/board.c +++ b/boards/GENERIC_SPC563/board.c @@ -49,6 +49,7 @@ void hwinit1(void) { SIU.PCR[GPIO_BUTTON3].R = 0x0100; /* IBE. */ SIU.PCR[GPIO_BUTTON4].R = 0x0100; /* IBE. */ SIU.PCR[GPIO_SCI_A_TX].R = 0x0500; /* Primary | IBE. */ + SIU.PCR[GPIO_SCI_A_RX].R = 0x0500; /* Primary | IBE. */ /* * HAL initialization. diff --git a/boards/GENERIC_SPC563/board.h b/boards/GENERIC_SPC563/board.h index 5c7af7b60..78213a1ae 100644 --- a/boards/GENERIC_SPC563/board.h +++ b/boards/GENERIC_SPC563/board.h @@ -41,6 +41,7 @@ * I/O definitions. */ #define GPIO_SCI_A_TX 89 +#define GPIO_SCI_A_RX 90 #define GPIO_BUTTON1 179 #define GPIO_BUTTON2 181 diff --git a/demos/PPC-SPC563-GCC/Makefile b/demos/PPC-SPC563-GCC/Makefile index 65b19bc35..057de4ae0 100644 --- a/demos/PPC-SPC563-GCC/Makefile +++ b/demos/PPC-SPC563-GCC/Makefile @@ -55,7 +55,8 @@ CSRC = $(PORTSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(CHIBIOS)/os/various/evtimer.c \ - $(CHIBIOS)/os/various/memstreams.c \ + $(CHIBIOS)/os/various/shell.c \ + $(CHIBIOS)/os/various/syscalls.c \ main.c # C++ sources here. @@ -109,7 +110,7 @@ CPPWARN = -Wall -Wextra # # List all default C defines here, like -D_DEBUG=1 -DDEFS = +DDEFS = -DPPC_VARIANT=PPC_VARIANT_e200z3 # List all default ASM defines here, like -D_DEBUG=1 DADEFS = diff --git a/demos/PPC-SPC563-GCC/main.c b/demos/PPC-SPC563-GCC/main.c index df59fd598..db05b1283 100644 --- a/demos/PPC-SPC563-GCC/main.c +++ b/demos/PPC-SPC563-GCC/main.c @@ -17,13 +17,97 @@ along with this program. If not, see . */ +#include + #include "ch.h" #include "hal.h" #include "test.h" -#include "memstreams.h" +#include "shell.h" -int a = 1234; -uint8_t report_buffer[8192]; +#define SHELL_WA_SIZE THD_WA_SIZE(1024) +#define TEST_WA_SIZE THD_WA_SIZE(256) + +static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { + size_t n, size; + char buf[52]; + + (void)argv; + if (argc > 0) { + shellPrintLine(chp, "Usage: mem"); + return; + } + n = chHeapStatus(NULL, &size); + siprintf(buf, "core free memory : %i bytes", chCoreFree()); + shellPrintLine(chp, buf); + siprintf(buf, "heap fragments : %i", n); + shellPrintLine(chp, buf); + siprintf(buf, "heap free total : %i bytes", size); + shellPrintLine(chp, buf); +} + +static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { + static const char *states[] = { + "READY", + "CURRENT", + "SUSPENDED", + "WTSEM", + "WTMTX", + "WTCOND", + "SLEEPING", + "WTEXIT", + "WTOREVT", + "WTANDEVT", + "SNDMSG", + "WTMSG", + "FINAL" + }; + Thread *tp; + char buf[60]; + + (void)argv; + if (argc > 0) { + shellPrintLine(chp, "Usage: threads"); + return; + } + shellPrintLine(chp, " addr stack prio refs state time"); + tp = chRegFirstThread(); + do { + siprintf(buf, "%8p %8p %4u %4i %9s %u", + tp, tp->p_ctx.sp, (unsigned int)tp->p_prio, tp->p_refs - 1, + states[tp->p_state], (unsigned int)tp->p_time); + shellPrintLine(chp, buf); + tp = chRegNextThread(tp); + } while (tp != NULL); +} + +static void cmd_test(BaseChannel *chp, int argc, char *argv[]) { + Thread *tp; + + (void)argv; + if (argc > 0) { + shellPrintLine(chp, "Usage: test"); + return; + } + tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), + TestThread, chp); + if (tp == NULL) { + shellPrintLine(chp, "out of memory"); + return; + } + chThdWait(tp); +} + +static const ShellCommand commands[] = { + {"mem", cmd_mem}, + {"threads", cmd_threads}, + {"test", cmd_test}, + {NULL, NULL} +}; + +static const ShellConfig shell_cfg1 = { + (BaseChannel *)&SD1, + commands +}; /* * LEDs blinker thread, times are in milliseconds. @@ -32,7 +116,7 @@ static WORKING_AREA(waThread1, 128); static msg_t Thread1(void *arg) { (void)arg; - + SIU.GPDO[GPIO_LED1].R = 1; SIU.GPDO[GPIO_LED2].R = 1; SIU.GPDO[GPIO_LED3].R = 1; @@ -64,6 +148,7 @@ static msg_t Thread1(void *arg) { * on entry. */ int main(int argc, char **argv) { + Thread *shelltp = NULL; (void)argc; (void)argv; @@ -73,6 +158,11 @@ int main(int argc, char **argv) { */ sdStart(&SD1, NULL); + /* + * Shell manager initialization. + */ + shellInit(); + /* * Creates the blinker thread. */ @@ -82,6 +172,13 @@ int main(int argc, char **argv) { * 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. */ + } if (SIU.GPDI[GPIO_BUTTON1].B.PDI) { volatile msg_t result; #if 0 diff --git a/os/kernel/templates/chcore.h b/os/kernel/templates/chcore.h index 0e78dbcf5..e3fa8f0b9 100644 --- a/os/kernel/templates/chcore.h +++ b/os/kernel/templates/chcore.h @@ -46,9 +46,7 @@ #define CH_ARCHITECTURE_VARIANT_NAME "" /** - * @brief Base type for stack alignment. - * @details This type is used only for stack alignment reasons thus can be - * anything from a char to a double. + * @brief Base type for stack and memory alignment. */ typedef uint8_t stkalign_t; diff --git a/os/ports/GCC/PPC/SPC56x/vectors.s b/os/ports/GCC/PPC/SPC56x/vectors.s index 4b7e68ffe..3c8aed6a6 100644 --- a/os/ports/GCC/PPC/SPC56x/vectors.s +++ b/os/ports/GCC/PPC/SPC56x/vectors.s @@ -40,7 +40,7 @@ * override the weak symbol declared here. */ .section .vectors - .align 2 + .align 4 .globl _vectors _vectors: .long vector0 diff --git a/os/ports/GCC/PPC/chcore.h b/os/ports/GCC/PPC/chcore.h index 1351531f5..477b51f59 100644 --- a/os/ports/GCC/PPC/chcore.h +++ b/os/ports/GCC/PPC/chcore.h @@ -39,27 +39,46 @@ #define ENABLE_WFI_IDLE 0 #endif +/* Core variants identifiers.*/ +#define PPC_VARIANT_e200z3 3 /**< e200z3 core identifier. */ +#define PPC_VARIANT_e200z4 4 /**< e200z4 core identifier. */ + +/** + * @brief Core variant selector. + * @details This setting affects the predefined architecture strings and + * possibly code paths and structures into the port layer. + */ +#if !defined(PPC_VARIANT) || defined(__DOXYGEN__) +#define PPC_VARIANT PPC_VARIANT_e200z3 +#endif + /** * @brief Unique macro for the implemented architecture. */ -#define CH_ARCHITECTURE_PPCE200Z +#define CH_ARCHITECTURE_PPC /** * @brief Name of the implemented architecture. */ -#define CH_ARCHITECTURE_NAME "PowerPC" +#define CH_ARCHITECTURE_NAME "PowerPC" /** - * @brief Name of the architecture variant (optional). + * @brief Name of the architecture variant. */ -#define CH_CORE_VARIANT_NAME "e200zX" +#if (PPC_VARIANT == PPC_VARIANT_e200z3) || defined(__DOXYGEN__) +#define CH_CORE_VARIANT_NAME "e200z3" +#elif PPC_VARIANT == PPC_VARIANT_e200z4 +#define CH_CORE_VARIANT_NAME "e200z4" +#else +#error "unknown PowerPC variant specified" +#endif /** - * @brief Base type for stack alignment. - * @details This type is used only for stack alignment reasons thus can be - * anything from a char to a double. + * @brief Base type for stack and memory alignment. */ -typedef uint64_t stkalign_t; +typedef struct { + uint8_t a[8]; +} stkalign_t __attribute__((aligned(8))); /** * @brief Generic PPC register. diff --git a/os/various/shell.c b/os/various/shell.c index 41c78b1d8..8a0fd4d45 100644 --- a/os/various/shell.c +++ b/os/various/shell.c @@ -28,6 +28,7 @@ #include #include "ch.h" +#include "hal.h" #include "shell.h" #if SHELL_USE_IPRINTF @@ -84,13 +85,25 @@ static void cmd_info(BaseChannel *chp, int argc, char *argv[]) { return; } - shellPrint(chp, "Kernel version "); + shellPrint(chp, "Kernel version: "); shellPrintLine(chp, CH_KERNEL_VERSION); - shellPrint(chp, "Architecture "); - shellPrintLine(chp, CH_ARCHITECTURE_NAME); #ifdef __GNUC__ - shellPrint(chp, "GCC Version "); + shellPrint(chp, "GCC Version: "); shellPrintLine(chp, __VERSION__); +#endif + shellPrint(chp, "Architecture: "); + shellPrintLine(chp, CH_ARCHITECTURE_NAME); +#ifdef CH_CORE_VARIANT_NAME + shellPrint(chp, "Core Variant: "); + shellPrintLine(chp, CH_CORE_VARIANT_NAME); +#endif +#ifdef PLATFORM_NAME + shellPrint(chp, "Platform: "); + shellPrintLine(chp, PLATFORM_NAME); +#endif +#ifdef BOARD_NAME + shellPrint(chp, "Board: "); + shellPrintLine(chp, BOARD_NAME); #endif }