System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
main.cpp
- Committer:
- pspatel321
- Date:
- 2015-01-22
- Revision:
- 36:0afc0fc8f86b
- Parent:
- 34:18bcf276d3bf
- Child:
- 38:8efacce315ae
File content as of revision 36:0afc0fc8f86b:
#include "IOobjects.h"
#include "runTime.h"
#include "outDiagnostics.h"
#include "inCommands.h"
//#define DEBUG_MODE
void thread_watchDog(void const* args) {
tempData.wdtThreadId = Thread::gettid();
#ifdef DEBUG_MODE
wdt.kick();
#else
wdt.kick(WDT_TIME);
#endif
while(1) {
Thread::signal_wait(0x1F);
wdt.kick();
}
}
int main() {
pc.baud(BAUD);
pc.format(8, SerialBase::None, 2); // 2 Stop bits, reduce bad serial packets
pc.printf("\033[2J\033[2J\r\n"); // Clear screen
can.mode(FIFO);
NVIC_SetPriority(TIMER0_IRQn, 0);
NVIC_SetPriority(PWM1_IRQn, 1);
NVIC_SetPriority(CAN_IRQn, 2);
NVIC_SetPriority(UART0_IRQn, 3);
NVIC_SetPriority(TIMER3_IRQn, 4);
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 watchdog check-in thread
Thread watchdogCheck(thread_watchDog, 0, osPriorityRealtime, 128);
// Start the 100Hz data timer (priotity high)
RtosTimer sample(runTime::thread_sample, osTimerPeriodic);
sample.start(FAST_LOOP*1000);
// Start the serial, CAN threads
Thread serial_out(outDiagnostics::thread_serialOut, 0, osPriorityBelowNormal);
Thread can_out(outDiagnostics::thread_canOut, 0, osPriorityBelowNormal, 512);
// Start the input polling thread
Thread getInputs(inCommands::thread_getInputs, 0, osPriorityLow);
// Main task
while(1) {
runTime::gather(0);
osSignalSet((osThreadId)(tempData.wdtThreadId), 1<<0); // Signal watchdog thread
Thread::wait(GATHER_LOOP*1000);
}
}
