System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
pspatel321
Date:
Fri Nov 14 06:05:59 2014 +0000
Revision:
31:7eaa5e881b56
Parent:
30:91af74a299e1
Child:
32:e70407021ad2
Mostly working.  Wrote CAN in/out code.  Xbee still needs work.  My guess is that MODDMA breaks when used with RTOS.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pspatel321 30:91af74a299e1 1 #include "IOobjects.h"
pspatel321 30:91af74a299e1 2 #include "runTime.h"
pspatel321 30:91af74a299e1 3 #include "outDiagnostics.h"
pspatel321 31:7eaa5e881b56 4 #include "serviceCAN.h"
pspatel321 30:91af74a299e1 5
pspatel321 30:91af74a299e1 6 int main() {
pspatel321 31:7eaa5e881b56 7 wdt.kick(0.25); // Kick the watchdog timer, set the timeout to 110ms
pspatel321 30:91af74a299e1 8 pc.baud(921600);
pspatel321 30:91af74a299e1 9 pc.printf("\r\n\r\nSys Mgmt Reset\r\n");
pspatel321 30:91af74a299e1 10 can.mode(FIFO); // Use FIFO mode
pspatel321 30:91af74a299e1 11 NVIC_SetPriority(TIMER3_IRQn, 2); // Decrease timer3 priority (mbed timer, rtos)
pspatel321 30:91af74a299e1 12 NVIC_SetPriority(UART0_IRQn, 1); // Decrease serial priority to give CAN higher priority
pspatel321 30:91af74a299e1 13
pspatel321 30:91af74a299e1 14 // Did a watchdog reset occur since last power cycle?
pspatel321 30:91af74a299e1 15 if (wdt.checkFlag()) {
pspatel321 30:91af74a299e1 16 data.watchdogReset = true;
pspatel321 30:91af74a299e1 17 pc.printf("Watchdog Reset\r\n");
pspatel321 30:91af74a299e1 18 }
pspatel321 30:91af74a299e1 19
pspatel321 30:91af74a299e1 20 // Start the 10Hz data thread
pspatel321 30:91af74a299e1 21 Thread gather_10Hz(runTime::thread_gather_10Hz, 0, osPriorityHigh);
pspatel321 30:91af74a299e1 22
pspatel321 30:91af74a299e1 23 // Start the 100Hz data timer (more time critical than thread)
pspatel321 30:91af74a299e1 24 Thread gather_100Hz(runTime::thread_gather_100Hz, 0, osPriorityRealtime);
pspatel321 30:91af74a299e1 25
pspatel321 30:91af74a299e1 26 // Start the serial, CAN threads
pspatel321 30:91af74a299e1 27 Thread serial_out(outDiagnostics::thread_serialOut, 0, osPriorityAboveNormal, 6000); // Allocate 6kB RAM stack
pspatel321 31:7eaa5e881b56 28 Thread can_out(outDiagnostics::thread_canOut, 0, osPriorityAboveNormal); // Allocate 256B RAM stack
pspatel321 30:91af74a299e1 29
pspatel321 30:91af74a299e1 30 // Background task
pspatel321 30:91af74a299e1 31 while(1) {
pspatel321 30:91af74a299e1 32 // Service CAN and Xbee logic
pspatel321 31:7eaa5e881b56 33 if (canbus::serviceCAN());
pspatel321 30:91af74a299e1 34 }
pspatel321 30:91af74a299e1 35 }