Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
10:db13782f05d9
Parent:
9:ada056631cac
Child:
11:1d086618dd18
--- a/SysMngmt.cpp	Thu Oct 16 15:13:49 2014 +0000
+++ b/SysMngmt.cpp	Sun Oct 19 22:46:46 2014 +0000
@@ -4,12 +4,18 @@
     Revised Sept 30, 2014: Began analyzing and commenting program, trying to figure out what the hell it does (Martin Deng)
 */
 
-#include "SysMngmt.h"
+//#include "SysMngmt.h"
+
+/*
 #include "Get_IMD.h"
 #include "PollSwitch.h"
 #include "TemperatureRead.h"
+*/
+
 #include "Store_RTC.h"
 #include "XBee_Lib.h"
+
+
 #include "CANBuffer.h"
 
 #include "mbed.h"
@@ -20,6 +26,68 @@
 #include "DC_DC.h"
 #include "PollSwitch.h"
 #include "IMD.h"
+#include "CurrentMonitor.h"
+
+CANBuffer rxBuffer(CAN1, MEDIUM);
+//XBee250x XbeeTx;
+Serial pc1(USBTX,USBRX);
+
+char sys_src_id = 4;                // source address of system management
+char reset_id = 0x010;
+
+extern "C" void mbed_reset();
+
+void soft_reset(){
+    //http://developer.mbed.org/forum/mbed/topic/890/   
+    mbed_reset();    
+}
+
+int main() {
+    CANMessage rx_msg;   
+    Watchdog wdt;
+     
+    wdt.kick(10.0);
+    pc1.baud(115200);
+
+    FanPump fanPump(&rxBuffer);
+    DC dc_dc(&fanPump, &rxBuffer);
+    PollSwitch pollSwitch(&rxBuffer);
+    IMD imdMonitor(&rxBuffer);
+    CurrentMonitor curMonitor(&rxBuffer);
+    
+    fanPump.start_update();
+    dc_dc.start_update();
+    pollSwitch.start_update();
+    imdMonitor.start_update();
+    curMonitor.start_update();
+
+    while(1)
+    {
+        if(rxBuffer.rxRead(rx_msg)){
+            if(rx_msg.id == reset_id)
+                soft_reset();
+            
+            char src_addr = (rx_msg.id & 0x0700) >> 8;      // get bits 10:8
+            
+            if(src_addr == sys_src_id){
+                char cont_id = (rx_msg.id & 0x00FF);        // get bits 7:0
+                
+                // only control fans of dc_dc converter is on
+                if(cont_id == RX_FAN_ID && dc_dc.is_on())
+                {
+                    fanPump.set_fan((FanSelect)rx_msg.data[0], rx_msg.data[1]);
+                }
+                
+                if(cont_id == RX_DC_DC_ID){
+                    dc_dc.set(rx_msg.data[0]);
+                }
+            } // check for correct src_addr
+        } // check CANBuffer
+        
+        wdt.kick();
+    } // main while loop
+}
+
 
 //Possible problems in IMD coz change of counter
 //Possible problems in BatteryStatus coz change in library
@@ -51,34 +119,10 @@
     
     Interrupt handler, This is probably linked to the Timer 2 interrupt request somewhere by the libraries
 
-extern "C" void TIMER2_IRQHandler(void)
-{
-    if((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt
-    {
-        // This probably shouldn't be here, never have a printf() in an interrupt, locks up the main thread
-        // printf("Every 1ms\n\r");
-        
-        LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag
-        
-        // gonna hope all these calculations are correct
-        // writes to RTC store, but there's no read code here
-        // 2 misleading things. First, RTC store writes to a general purpose register
-        // secondly, no code reads from this register in this .cpp, but maybe some other code does
-        
-        Bat_I_Ratio=BatISense.read();
-        BATA_msec=(((Bat_I_Ratio*3.3) - BAT_ISENSE_OFFSET_V)/BAT_ISENSE_INCREMENT);
-        BATmA_Hr+=(BATA_msec*MSEC_HRS);
-        store.write(BATmA_Hr,0);
-                
-        DC_I_Ratio=DCSense.read(); 
-        DCA_msec=(((DC_I_Ratio*3.3) - DC_DC_ISENSE_OFFSET_V)/DC_DC_ISENSE_INCREMENT);
-        store.write(DCA_msec,1);
-        
-        LPC_TIM2->TCR       |=  (1<<1);                     //Reset Timer1
-        LPC_TIM2->TCR       &=  ~(1<<1);                    //Re Enable Timer1   
-    }
-}    
+*/
 
+
+/*
     Appears to read a whole bunch of DigitalOut pins in void PollSwitch(), store the value in uint16_t Rxpoll,
     and write the result to the CAN bus
 
@@ -261,51 +305,3 @@
     Main Loop: Currently reads CANMessages from Can interface (Pins: rd = p30, td = p29)
     Send CANMessage data through XBee radio transmitters
 */
-
-
-CANBuffer rxBuffer(CAN1, MEDIUM);
-XBee250x XbeeTx;
-Serial pc1(USBTX,USBRX);
-
-char sys_src_id = 4;                // source address of system management
-
-int main() {
-    CANMessage rx_msg;   
-    Watchdog wdt;
-     
-    wdt.kick(10.0);
-    pc1.baud(115200);
-
-    FanPump fanPump(&rxBuffer);
-    DC dc_dc(&fanPump, &rxBuffer);
-    PollSwitch pollSwitch(&rxBuffer);
-    IMD imdMonitor(&rxBuffer);
-    
-    fanPump.start_update();
-    dc_dc.start_update();
-    pollSwitch.start_update();
-    imdMonitor.start_update();
-
-    while(1)
-    {
-        if(rxBuffer.rxRead(rx_msg)){
-            char src_addr = (rx_msg.id & 0x0700) >> 8;      // get bits 10:8
-            
-            if(src_addr == sys_src_id){
-                char cont_id = (rx_msg.id & 0x00FF);        // get bits 7:0
-                
-                // only control fans of dc_dc converter is on
-                if(cont_id == RX_FAN_ID && dc_dc.is_on())
-                {
-                    fanPump.set_fan((FanSelect)rx_msg.data[0], rx_msg.data[1]);
-                }
-                
-                if(cont_id == RX_DC_DC_ID){
-                    dc_dc.set(rx_msg.data[0]);
-                }
-            } // check for correct src_addr
-        } // check CANBuffer
-        
-        wdt.kick();
-    } // main while loop
-}