System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
main.cpp@33:6bc82b6b62e5, 2015-01-06 (annotated)
- Committer:
- pspatel321
- Date:
- Tue Jan 06 20:45:26 2015 +0000
- Revision:
- 33:6bc82b6b62e5
- Parent:
- 32:e70407021ad2
- Child:
- 34:18bcf276d3bf
Updated IDs to match AMS, added a constants.h file.
Who changed what in which revision?
User | Revision | Line number | New 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 | 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 | 33:6bc82b6b62e5 | 12 | DigitalOut led1(LED1); |
pspatel321 | 33:6bc82b6b62e5 | 13 | |
pspatel321 | 33:6bc82b6b62e5 | 14 | bool normalReset = true; |
pspatel321 | 30:91af74a299e1 | 15 | // Did a watchdog reset occur since last power cycle? |
pspatel321 | 30:91af74a299e1 | 16 | if (wdt.checkFlag()) { |
pspatel321 | 33:6bc82b6b62e5 | 17 | wdt.clearFlag(); // Clear flag |
pspatel321 | 30:91af74a299e1 | 18 | data.watchdogReset = true; |
pspatel321 | 33:6bc82b6b62e5 | 19 | pc.printf("Sys Mgmt Watchdog Reset\r\n"); |
pspatel321 | 33:6bc82b6b62e5 | 20 | led1=1; |
pspatel321 | 33:6bc82b6b62e5 | 21 | normalReset=false; |
pspatel321 | 30:91af74a299e1 | 22 | } |
pspatel321 | 33:6bc82b6b62e5 | 23 | // Did a brownout reset occur since last power cycle? |
pspatel321 | 33:6bc82b6b62e5 | 24 | if (LPC_SC->RSID & (1<<3)) { |
pspatel321 | 33:6bc82b6b62e5 | 25 | LPC_SC->RSID = (1<<3); // Clear flag |
pspatel321 | 33:6bc82b6b62e5 | 26 | pc.printf("Sys Mgmt Brownout Reset\r\n"); |
pspatel321 | 33:6bc82b6b62e5 | 27 | normalReset=false; |
pspatel321 | 33:6bc82b6b62e5 | 28 | } |
pspatel321 | 33:6bc82b6b62e5 | 29 | // Print normal reset string |
pspatel321 | 33:6bc82b6b62e5 | 30 | if (normalReset) pc.printf("Sys Mgmt Reset\r\n"); |
pspatel321 | 33:6bc82b6b62e5 | 31 | |
pspatel321 | 30:91af74a299e1 | 32 | // Start the 10Hz data thread |
pspatel321 | 33:6bc82b6b62e5 | 33 | // Thread gather(runTime::thread_gather, 0, osPriorityHigh); |
pspatel321 | 30:91af74a299e1 | 34 | |
pspatel321 | 30:91af74a299e1 | 35 | // Start the 100Hz data timer (more time critical than thread) |
pspatel321 | 33:6bc82b6b62e5 | 36 | //RtosTimer sample(runTime::thread_sample, osTimerPeriodic); |
pspatel321 | 33:6bc82b6b62e5 | 37 | //sample.start(FAST_LOOP*1000); |
pspatel321 | 33:6bc82b6b62e5 | 38 | |
pspatel321 | 30:91af74a299e1 | 39 | // Start the serial, CAN threads |
pspatel321 | 30:91af74a299e1 | 40 | Thread serial_out(outDiagnostics::thread_serialOut, 0, osPriorityAboveNormal, 6000); // Allocate 6kB RAM stack |
pspatel321 | 33:6bc82b6b62e5 | 41 | //Thread can_out(outDiagnostics::thread_canOut, 0, osPriorityAboveNormal); // Allocate 256B RAM stack |
pspatel321 | 33:6bc82b6b62e5 | 42 | |
pspatel321 | 33:6bc82b6b62e5 | 43 | wdt.kick(WDT_TIME); // Startup complete, normal timeout |
pspatel321 | 30:91af74a299e1 | 44 | |
pspatel321 | 30:91af74a299e1 | 45 | // Background task |
pspatel321 | 30:91af74a299e1 | 46 | while(1) { |
pspatel321 | 30:91af74a299e1 | 47 | // Service CAN and Xbee logic |
pspatel321 | 33:6bc82b6b62e5 | 48 | //if (canbus::serviceCAN()); |
pspatel321 | 33:6bc82b6b62e5 | 49 | //canbus::receiveMsgXbee(); |
pspatel321 | 33:6bc82b6b62e5 | 50 | wdt.kick(); |
pspatel321 | 30:91af74a299e1 | 51 | } |
pspatel321 | 30:91af74a299e1 | 52 | } |