From 4ef06df354f5252982988815d4c30b182bd12692 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 28 Aug 2013 02:48:21 +0000 Subject: implemented system shutdown and reboot (not yet finished) git-svn-id: https://svn.spreadspace.org/mur.sat@846 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/mpu/main.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'software/mpu/main.c') 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 */ } -- cgit v1.2.3