summaryrefslogtreecommitdiff
path: root/software/mpu/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'software/mpu/main.c')
-rw-r--r--software/mpu/main.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/software/mpu/main.c b/software/mpu/main.c
index 9224531..90c5ef9 100644
--- a/software/mpu/main.c
+++ b/software/mpu/main.c
@@ -36,25 +36,35 @@
#include "heartbeat.h"
#include "usb-cdc-shell.h"
-static void reboot(void)
+static void sysInit(void)
{
- NVIC_SystemReset();
+ /*
+ * System initializations.
+ * - HAL initialization, this also initializes the configured device drivers
+ * and performs the board-specific initializations.
+ * - Kernel initialization, the main() function becomes a thread and the
+ * RTOS is active.
+ */
+ halInit();
+ chSysInit();
}
-static void reset2bootloader(void)
+static void subsystemsInit(void)
{
- NVIC_SystemReset();
- /* TODO: not just reset but go to bootloader */
+ /* call init functions of all subsystems which should spawn threads for their task */
+ heartbeatInit();
}
-static void shutdown(void)
+static void subsystemsStop(void)
{
/* Safely stop critical threads, aka call shutdown functions of all subsystems */
- /* nothing here. */
+ /* -> invoke the xxxStop() method on all the active device drivers */
- /* Invoke the xxxStop() method on all the active device drivers */
- /* nothing here. */
+ /* nothing here ... for now anyway */
+}
+static void sysShutdown(void)
+{
chSysDisable();
/* Stop the system timer whose service routine invokes chSysTimerHandlerI(). */
@@ -69,29 +79,31 @@ static void shutdown(void)
chSysEnable();
}
+
+static void reboot(void)
+{
+ NVIC_SystemReset();
+}
+
+static void reset2bootloader(void)
+{
+ NVIC_SystemReset();
+ /* TODO: not just reset but go to bootloader */
+}
+
/*
* Application entry point.
*/
int main(void)
{
- /*
- * System initializations.
- * - HAL initialization, this also initializes the configured device drivers
- * and performs the board-specific initializations.
- * - Kernel initialization, the main() function becomes a thread and the
- * RTOS is active.
- */
- halInit();
- chSysInit();
- /* the base os is ready now */
-
- /* call init functions of all subsystems which should spawn threads for their task */
- heartbeatInit();
+ sysInit(); /* the base os is ready now */
+ subsystemsInit();
int8_t ret = usbCDCShellRun();
/* the debug shell returned - we have to halt, reboot or goto bootloader */
- shutdown();
+ subsystemsStop();
+ sysShutdown();
/* the OS is stopped now */
switch(ret) {