System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

main.cpp

Committer:
pspatel321
Date:
2015-01-06
Revision:
33:6bc82b6b62e5
Parent:
32:e70407021ad2
Child:
34:18bcf276d3bf

File content as of revision 33:6bc82b6b62e5:

#include "IOobjects.h"
#include "runTime.h"
#include "outDiagnostics.h"
#include "serviceCAN.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);
    DigitalOut led1(LED1);
    
    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");
        led1=1;
        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);
    
    // 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, 6000);     // Allocate 6kB RAM stack
    //Thread can_out(outDiagnostics::thread_canOut, 0, osPriorityAboveNormal);            // Allocate 256B RAM stack
    
    wdt.kick(WDT_TIME);     // Startup complete, normal timeout
    
    // Background task
    while(1) {
        // Service CAN and Xbee logic
        //if (canbus::serviceCAN());
        //canbus::receiveMsgXbee();
        wdt.kick();
    }
}