diff options
author | Christian Pointner <equinox@mur.at> | 2013-08-28 02:48:21 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2013-08-28 02:48:21 +0000 |
commit | 4ef06df354f5252982988815d4c30b182bd12692 (patch) | |
tree | 7f5783a28c38017f2b5ec2142e5208a013fc140e /software/mpu/usb-cdc-shell.c | |
parent | added hardware support for SMT32F405 (diff) |
implemented system shutdown and reboot (not yet finished)
git-svn-id: https://svn.spreadspace.org/mur.sat@846 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/mpu/usb-cdc-shell.c')
-rw-r--r-- | software/mpu/usb-cdc-shell.c | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/software/mpu/usb-cdc-shell.c b/software/mpu/usb-cdc-shell.c index d58833d..c36ca19 100644 --- a/software/mpu/usb-cdc-shell.c +++ b/software/mpu/usb-cdc-shell.c @@ -171,6 +171,8 @@ static const SerialUSBConfig serusbcfg = { /* Command line related. */ /*===========================================================================*/ +static int8_t shell_return_code; + #define SHELL_WA_SIZE THD_WA_SIZE(2048) #define TEST_WA_SIZE THD_WA_SIZE(256) @@ -229,43 +231,49 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) chThdWait(tp); } -static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) +static void cmd_halt(BaseSequentialStream *chp, int argc, char *argv[]) { - static uint8_t buf[] = - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; + (void)argv; + if (argc > 0) { + chprintf(chp, "Usage: halt\r\n"); + return; + } + shell_return_code = MPU_HALT; + chprintf(chp, "halting system.\r\n"); + /* TODO: tell shell to terminate - but how??? */ +} +static void cmd_reboot(BaseSequentialStream *chp, int argc, char *argv[]) +{ (void)argv; if (argc > 0) { - chprintf(chp, "Usage: write\r\n"); + chprintf(chp, "Usage: reboot\r\n"); return; } + shell_return_code = MPU_REBOOT; + chprintf(chp, "rebooting system ...\r\n"); + /* TODO: tell shell to terminate - but how??? */ +} - while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) { - chSequentialStreamWrite(&SDU1, buf, sizeof buf - 1); +static void cmd_bootloader(BaseSequentialStream *chp, int argc, char *argv[]) +{ + (void)argv; + if (argc > 0) { + chprintf(chp, "Usage: bootloader\r\n"); + return; } - chprintf(chp, "\r\n\nstopped\r\n"); + shell_return_code = MPU_BOOTLOADER; + chprintf(chp, "rebooting to bootloader ...\r\n"); + /* TODO: tell shell to terminate - but how??? */ } static const ShellCommand commands[] = { {"mem", cmd_mem}, {"threads", cmd_threads}, {"test", cmd_test}, - {"write", cmd_write}, + {"halt", cmd_halt}, + {"reboot", cmd_reboot}, + {"bootloader", cmd_bootloader}, {NULL, NULL} }; @@ -278,33 +286,38 @@ static const ShellConfig shell_cfg1 = { /* Public Interface. */ /*===========================================================================*/ -void usbCDCShellInit(void) +int8_t usbCDCShellRun(void) { sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); palSetPad(GPIOA, GPIOA_USB_DISC); usbDisconnectBus(serusbcfg.usbp); - chThdSleepMilliseconds(1500); + + chThdSleepMilliseconds(100); + usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); palClearPad(GPIOA, GPIOA_USB_DISC); shellInit(); -} - -void usbCDCShellRun(void) -{ + shell_return_code = MPU_CONTINUE; Thread *shelltp = NULL; - while (TRUE) { if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) 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 (shell_return_code != MPU_CONTINUE) break; } chThdSleepMilliseconds(1000); } + + usbStop(serusbcfg.usbp); + sduStop(&SDU1); + palSetPad(GPIOA, GPIOA_USB_DISC); + + return shell_return_code; } |