summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-08-28 02:48:21 +0000
committerChristian Pointner <equinox@mur.at>2013-08-28 02:48:21 +0000
commit4ef06df354f5252982988815d4c30b182bd12692 (patch)
tree7f5783a28c38017f2b5ec2142e5208a013fc140e /software
parentadded 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')
-rw-r--r--software/mpu/main.c40
-rw-r--r--software/mpu/usb-cdc-shell.c73
-rw-r--r--software/mpu/usb-cdc-shell.h8
3 files changed, 86 insertions, 35 deletions
diff --git a/software/mpu/main.c b/software/mpu/main.c
index 461c071..a737d9b 100644
--- a/software/mpu/main.c
+++ b/software/mpu/main.c
@@ -36,6 +36,17 @@
#include "heartbeat.h"
#include "usb-cdc-shell.h"
+static void reboot(void)
+{
+ NVIC_SystemReset();
+}
+
+static void reset2bootloader(void)
+{
+ NVIC_SystemReset();
+ /* TODO: not just reset but go to bootloader */
+}
+
/*
* Application entry point.
*/
@@ -52,8 +63,31 @@ int main(void)
chSysInit();
heartbeatInit();
- usbCDCShellInit();
- while (TRUE) {
- usbCDCShellRun();
+ int8_t ret = usbCDCShellRun();
+
+ /* the debug shell returned - we have to halt, reboot or goto bootloader */
+
+ /* Safely stop critical threads */
+ /* nothing here. */
+
+ /* Invoke the xxxStop() method on all the active device drivers */
+ chSysDisable();
+
+ /* Stop the system timer whose service routine invokes chSysTimerHandlerI(). */
+ SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk);
+
+ /* Disable any other interrupt source that may invoke OS APIs */
+ /* nothing here. */
+
+ /* Perform any application related de-initialization. */
+ /* nothing here. */
+
+ chSysEnable();
+ /* the OS is stopped now */
+
+ switch(ret) {
+ case MPU_BOOTLOADER: reset2bootloader(); break;
+ case MPU_REBOOT: reboot(); break;
}
+ for(;;); /* halting system, aka loop endlessly */
}
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;
}
diff --git a/software/mpu/usb-cdc-shell.h b/software/mpu/usb-cdc-shell.h
index f44df9d..412fd30 100644
--- a/software/mpu/usb-cdc-shell.h
+++ b/software/mpu/usb-cdc-shell.h
@@ -33,7 +33,11 @@
#ifndef MURSAT_usb_cdc_shell_h_INCLUDED
#define MURSAT_usb_cdc_shell_h_INCLUDED
-void usbCDCShellInit(void);
-void usbCDCShellRun(void);
+#define MPU_HALT 0
+#define MPU_CONTINUE 1
+#define MPU_REBOOT 2
+#define MPU_BOOTLOADER 3
+
+int8_t usbCDCShellRun(void);
#endif