System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
pspatel321
Date:
Wed Jan 07 03:25:50 2015 +0000
Revision:
34:18bcf276d3bf
Parent:
33:6bc82b6b62e5
Child:
36:0afc0fc8f86b
Added serial input.  Updated glvBat coulomb counter to match AMS, brought in changes to outDiag and inCommands from AMS.

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 34:18bcf276d3bf 4 #include "inCommands.h"
pspatel321 30:91af74a299e1 5
pspatel321 30:91af74a299e1 6 int main() {
pspatel321 33:6bc82b6b62e5 7 wdt.kick(); // Kick the watchdog timer
pspatel321 33:6bc82b6b62e5 8 pc.baud(BAUD);
pspatel321 33:6bc82b6b62e5 9 pc.format(8, SerialBase::None, 2); // 2 Stop bits, reduce bad serial packets
pspatel321 30:91af74a299e1 10
pspatel321 33:6bc82b6b62e5 11 can.mode(FIFO);
pspatel321 34:18bcf276d3bf 12 NVIC_SetPriority(TIMER3_IRQn, 4);
pspatel321 34:18bcf276d3bf 13 NVIC_SetPriority(UART0_IRQn, 0);
pspatel321 34:18bcf276d3bf 14 NVIC_SetPriority(CAN_IRQn, 3);
pspatel321 34:18bcf276d3bf 15 NVIC_SetPriority(TIMER0_IRQn, 1);
pspatel321 34:18bcf276d3bf 16 NVIC_SetPriority(PWM1_IRQn, 2);
pspatel321 33:6bc82b6b62e5 17
pspatel321 33:6bc82b6b62e5 18 bool normalReset = true;
pspatel321 30:91af74a299e1 19 // Did a watchdog reset occur since last power cycle?
pspatel321 30:91af74a299e1 20 if (wdt.checkFlag()) {
pspatel321 33:6bc82b6b62e5 21 wdt.clearFlag(); // Clear flag
pspatel321 30:91af74a299e1 22 data.watchdogReset = true;
pspatel321 33:6bc82b6b62e5 23 pc.printf("Sys Mgmt Watchdog Reset\r\n");
pspatel321 33:6bc82b6b62e5 24 normalReset=false;
pspatel321 30:91af74a299e1 25 }
pspatel321 33:6bc82b6b62e5 26 // Did a brownout reset occur since last power cycle?
pspatel321 33:6bc82b6b62e5 27 if (LPC_SC->RSID & (1<<3)) {
pspatel321 33:6bc82b6b62e5 28 LPC_SC->RSID = (1<<3); // Clear flag
pspatel321 33:6bc82b6b62e5 29 pc.printf("Sys Mgmt Brownout Reset\r\n");
pspatel321 33:6bc82b6b62e5 30 normalReset=false;
pspatel321 33:6bc82b6b62e5 31 }
pspatel321 33:6bc82b6b62e5 32 // Print normal reset string
pspatel321 33:6bc82b6b62e5 33 if (normalReset) pc.printf("Sys Mgmt Reset\r\n");
pspatel321 33:6bc82b6b62e5 34
pspatel321 30:91af74a299e1 35 // Start the 10Hz data thread
pspatel321 34:18bcf276d3bf 36 Thread gather(runTime::thread_gather, 0, osPriorityHigh, 512);
pspatel321 30:91af74a299e1 37
pspatel321 30:91af74a299e1 38 // Start the 100Hz data timer (more time critical than thread)
pspatel321 34:18bcf276d3bf 39 RtosTimer sample(runTime::thread_sample, osTimerPeriodic);
pspatel321 34:18bcf276d3bf 40 sample.start(FAST_LOOP*1000);
pspatel321 33:6bc82b6b62e5 41
pspatel321 30:91af74a299e1 42 // Start the serial, CAN threads
pspatel321 34:18bcf276d3bf 43 Thread serial_out(outDiagnostics::thread_serialOut, 0, osPriorityAboveNormal, 2000); // Allocate 6kB RAM stack
pspatel321 34:18bcf276d3bf 44 Thread can_out(outDiagnostics::thread_canOut, 0, osPriorityAboveNormal, 512); // Allocate 256B RAM stack
pspatel321 33:6bc82b6b62e5 45
pspatel321 34:18bcf276d3bf 46 wdt.kick(1); // Startup complete, normal timeout
pspatel321 30:91af74a299e1 47 // Background task
pspatel321 30:91af74a299e1 48 while(1) {
pspatel321 30:91af74a299e1 49 // Service CAN and Xbee logic
pspatel321 34:18bcf276d3bf 50 inCommands::serviceCAN();
pspatel321 34:18bcf276d3bf 51 inCommands::receiveMsgXbee();
pspatel321 34:18bcf276d3bf 52
pspatel321 34:18bcf276d3bf 53 int ret = inCommands::serviceSerial();
pspatel321 34:18bcf276d3bf 54 if (ret == -1) tempData.parseGoodChar = 'x';
pspatel321 34:18bcf276d3bf 55 if (ret == 1) tempData.parseGoodChar = 251;
pspatel321 33:6bc82b6b62e5 56 wdt.kick();
pspatel321 30:91af74a299e1 57 }
pspatel321 30:91af74a299e1 58 }