From 3d27e7fdc5d80473e4d9af0fdd667eb414f20a8f Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 6 Nov 2013 01:21:50 +0000 Subject: main.c cleanup git-svn-id: https://svn.spreadspace.org/mur.sat@853 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/mpu/main.c | 58 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'software') 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) { -- cgit v1.2.3