System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
main.cpp
- Committer:
- pspatel321
- Date:
- 2015-01-07
- Revision:
- 34:18bcf276d3bf
- Parent:
- 33:6bc82b6b62e5
- Child:
- 36:0afc0fc8f86b
File content as of revision 34:18bcf276d3bf:
#include "IOobjects.h" #include "runTime.h" #include "outDiagnostics.h" #include "inCommands.h" int main() { wdt.kick(); // Kick the watchdog timer pc.baud(BAUD); pc.format(8, SerialBase::None, 2); // 2 Stop bits, reduce bad serial packets can.mode(FIFO); NVIC_SetPriority(TIMER3_IRQn, 4); NVIC_SetPriority(UART0_IRQn, 0); NVIC_SetPriority(CAN_IRQn, 3); NVIC_SetPriority(TIMER0_IRQn, 1); NVIC_SetPriority(PWM1_IRQn, 2); bool normalReset = true; // Did a watchdog reset occur since last power cycle? if (wdt.checkFlag()) { wdt.clearFlag(); // Clear flag data.watchdogReset = true; pc.printf("Sys Mgmt Watchdog Reset\r\n"); normalReset=false; } // Did a brownout reset occur since last power cycle? if (LPC_SC->RSID & (1<<3)) { LPC_SC->RSID = (1<<3); // Clear flag pc.printf("Sys Mgmt Brownout Reset\r\n"); normalReset=false; } // Print normal reset string if (normalReset) pc.printf("Sys Mgmt Reset\r\n"); // Start the 10Hz data thread Thread gather(runTime::thread_gather, 0, osPriorityHigh, 512); // Start the 100Hz data timer (more time critical than thread) RtosTimer sample(runTime::thread_sample, osTimerPeriodic); sample.start(FAST_LOOP*1000); // Start the serial, CAN threads Thread serial_out(outDiagnostics::thread_serialOut, 0, osPriorityAboveNormal, 2000); // Allocate 6kB RAM stack Thread can_out(outDiagnostics::thread_canOut, 0, osPriorityAboveNormal, 512); // Allocate 256B RAM stack wdt.kick(1); // Startup complete, normal timeout // Background task while(1) { // Service CAN and Xbee logic inCommands::serviceCAN(); inCommands::receiveMsgXbee(); int ret = inCommands::serviceSerial(); if (ret == -1) tempData.parseGoodChar = 'x'; if (ret == 1) tempData.parseGoodChar = 251; wdt.kick(); } }