System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
33:6bc82b6b62e5
Parent:
32:e70407021ad2
Child:
34:18bcf276d3bf
--- a/main.cpp	Sun Nov 16 02:43:58 2014 +0000
+++ b/main.cpp	Tue Jan 06 20:45:26 2015 +0000
@@ -4,32 +4,49 @@
 #include "serviceCAN.h"
 
 int main() {
-    wdt.kick(0.11);                     // Kick the watchdog timer, set the timeout to 110ms
-    pc.baud(921600);
-    pc.printf("\r\n\r\nSys Mgmt Reset\r\n");
-    can.mode(FIFO);                     // Use FIFO mode
-    NVIC_SetPriority(TIMER3_IRQn, 2);   // Decrease timer3 priority (mbed timer, rtos)
-    NVIC_SetPriority(UART0_IRQn, 1);    // Decrease serial priority to give CAN higher priority
+    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("Watchdog Reset\r\n");
+        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_10Hz(runTime::thread_gather_10Hz, 0, osPriorityHigh);
+    // Thread gather(runTime::thread_gather, 0, osPriorityHigh);
     
     // Start the 100Hz data timer (more time critical than thread)
-    Thread gather_100Hz(runTime::thread_gather_100Hz, 0, osPriorityRealtime);
-
+    //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
+    //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());
+        //if (canbus::serviceCAN());
+        //canbus::receiveMsgXbee();
+        wdt.kick();
     }
 }
\ No newline at end of file