System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Files at this revision

API Documentation at this revision

Comitter:
martydd3
Date:
Wed Oct 01 12:52:26 2014 +0000
Child:
1:e02eb179aed3
Commit message:
Added LPCDigitalOut, LPCDigitalIn, and CANBuffer Libaries; Comments on code in SysMngmt.cpp involving register and pin access; Note: LPCDigitalOut.h defines a void mode(PinMode) which isn't in LPCDigitalOut.cpp, causes a linking error if used

Changed in this revision

CANBuffer.lib Show annotated file Show diff for this revision Revisions of this file
Get_IMD/Get_IMD.h Show annotated file Show diff for this revision Revisions of this file
LPCDigitalIn.lib Show annotated file Show diff for this revision Revisions of this file
LPCDigitalOut.lib Show annotated file Show diff for this revision Revisions of this file
PollSwitch/PollSwitch.h Show annotated file Show diff for this revision Revisions of this file
RTCStore/Store_RTC.h Show annotated file Show diff for this revision Revisions of this file
SysMngmt.cpp Show annotated file Show diff for this revision Revisions of this file
SysMngmt.h Show annotated file Show diff for this revision Revisions of this file
Temperature_Read/TemperatureRead.h Show annotated file Show diff for this revision Revisions of this file
XBee/XBee_Lib.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CANBuffer.lib	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Penn-Electric-Racing/code/CANBuffer/#0d8e82a5db8d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Get_IMD/Get_IMD.h	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,146 @@
+#include "mbed.h"
+#include "string.h"
+/*
+#include "Get_IMD.h"
+DigitalOut myled(LED1);
+
+int main() 
+{
+    IMD_Measurement_Output IMD_Result;
+    while(1) 
+    {
+        IMD_Result=Get_Measurement();
+        pc.printf("Frequency:%f\n\r",IMD_Result.Frequency);
+        pc.printf("Duty Cycle:%f\n\r",IMD_Result.Duty_Cycle);
+        pc.printf("State:%s\n\n\r",IMD_Result.State);
+    }
+}
+*/
+
+//Serial pc(USBTX,USBRX);
+
+#ifndef GET_IMD_H
+    #define GET_IMD_H  
+    typedef struct
+    {
+        float Frequency;
+        float Duty_Cycle;
+        char State[50];
+        char Encoded_Status;
+    }IMD_Measurement_Output;
+    
+    bool FirstFE=true;
+    bool FirstRE=true;
+    uint32_t ON_Period =0;
+    uint32_t INT0_RE,INT0_FE;
+    uint32_t CAP0RE=0, CAP0FE=1, CRO_I=4;
+    IMD_Measurement_Output Result;
+    
+    extern "C" void TIMER0_IRQHandler(void)
+    {
+        INT0_RE=LPC_TIM0->CCR;
+        INT0_FE=LPC_TIM0->CCR;
+        
+        
+        if(((INT0_FE & (1 << CAP0FE)) >> CAP0FE))
+        {
+            if(!FirstFE)
+            {
+                //pc.printf("LPC_TIM1->TC in FE:%d\n\r",LPC_TIM1->TC);                
+                ON_Period = LPC_TIM1->TC;
+                //pc.printf("On Period:%d\n\r",ON_Period);
+                LPC_TIM0->CCR   |=  ((1<<0) | (1<<2));      //Copy TC to CRO on Rising Edge AND Generate Interrupt                
+                LPC_TIM0->CCR   &=  ~(1<<1);     //Disable Falling Edge
+            }
+            else
+                FirstFE=false;                            
+        }
+        else if((INT0_RE & (1 << CAP0RE))>> CAP0RE)
+        {
+            //pc.printf("On Period In RE:%d\n\r",ON_Period);
+            if(!FirstRE)
+            {
+                //pc.printf("LPC_TIM1->TC in RE:%d\n\r",LPC_TIM1->TC);
+                //pc.printf("On Period In RE:%d\n\r",ON_Period);
+                Result.Frequency=((1/(float)LPC_TIM1->TC)*1000);
+                Result.Duty_Cycle=((ON_Period/(float)LPC_TIM1->TC)*100);
+                LPC_TIM0->CCR   |=  ((1<<1) | (1<<2));      //Copy TC to CRO on Falling Edge AND Generate Interrupt                             
+                LPC_TIM0->CCR   &=  ~(1<<0);                //Disable Rising Edge
+                LPC_TIM1->TCR   |=  (1<<1);                 //Reset Timer1
+                LPC_TIM1->TCR   &=  ~(1<<1);                 //Restart Timer1
+            }
+            else
+                FirstRE=false;    
+        }
+        LPC_TIM0->IR |= (1<<CRO_I);                         //Reset Counter0 Interrupt
+        return;  
+    }
+    
+    void init()
+    {
+        Result.Frequency=0;
+        Result.Duty_Cycle=0;
+        strcpy(Result.State,"");
+        //Set pin as capture mode
+        //Initialize Counter2
+        LPC_PINCON->PINSEL3 |=  ((1<<21) | (1<<20));          //Set Pin1.26 as CAP0.0 
+        LPC_SC->PCONP       |=  (1<<1);                    //PowerOn Timer/Counter0.
+        LPC_TIM0->CCR       |=  ((1<<1) | (1<<2));          //Copy TC to CRO on Falling Edge AND Generate Interrupt
+        NVIC_SetPriority(TIMER0_IRQn,255);
+        NVIC_EnableIRQ(TIMER0_IRQn);                        //Enable TIMER0 IRQ      
+        
+        //Initiallize Timer1
+        LPC_SC->PCONP       |=  (1<<2);                     //PoewerOn Timer/Counter1
+        LPC_SC->PCLKSEL0    |=  ((1<<4) | (1<<5));          //Prescale Timer1 CCLK/8  
+        LPC_TIM1->CTCR      &=  ~((1<<1) | (1<<0));         //Set Timer/Counter1 as as Timer mode
+        LPC_TIM1->PR        =   11985;                      //Timeout every 1msec(Timer Resolution)
+        LPC_TIM1->TCR       |=  (1<<1);                     //Reset Timer1
+        LPC_TIM1->TCR       |=  (1<<0);                     //Enable Timer1
+        //LPC_TIM1->TCR       &=  ~(1<<1);                 //Restart Timer1              
+        FirstRE=false;
+        FirstFE=false;
+    }    
+    
+    void Disable()
+    {
+        LPC_TIM1->TCR   |=  (1<<1);                     //Reset Timer1
+        LPC_TIM0->IR    |=  (1<<4);                     //Reset Counter0 Interrupt
+        NVIC_DisableIRQ(TIMER0_IRQn);
+    }
+    
+    IMD_Measurement_Output Get_Measurement()
+    {
+        init();
+        wait_ms(300);
+        Disable();
+        if(Result.Frequency >=5 && Result.Frequency <15){
+                strcpy(Result.State, "Normal condition");
+                Result.Encoded_Status='1';
+            }
+        else if(Result.Frequency >=15 && Result.Frequency <25){
+                strcpy(Result.State, "underVoltage condition");
+                Result.Encoded_Status='2';
+            }
+        else if(Result.Frequency >=25 && Result.Frequency <35)
+                {
+                    if(Result.Duty_Cycle <=15){
+                        strcpy(Result.State, "Insulation measurement:good");
+                        Result.Encoded_Status='3';
+                    }
+                    else if(Result.Duty_Cycle > 85 && Result.Duty_Cycle < 100){
+                        strcpy(Result.State, "Insulation measurement:bad");
+                        Result.Encoded_Status='4';
+                    }    
+                }
+        else if(Result.Frequency >=35 && Result.Frequency <45){
+                strcpy(Result.State, "Device error");
+                Result.Encoded_Status='5';
+            }
+        else if(Result.Frequency >=45 && Result.Frequency <55){
+                strcpy(Result.State, "Connection fault earth");    
+                Result.Encoded_Status='6';
+            }                                            
+        return Result; 
+    }
+    
+    #endif/* GET_IMD_H */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCDigitalIn.lib	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/Penn-Electric-Racing/code/LPCDigitalIn/#fbd18a1431cf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCDigitalOut.lib	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/Penn-Electric-Racing/code/LPCDigitalOut/#6e44ba5dde94
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PollSwitch/PollSwitch.h	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,45 @@
+#include"LPCDigitalOut.h"
+#include"LPCDigitalIn.h"
+
+//Serial pc(USBTX,USBRX);
+
+uint16_t PollSwitch()
+{
+    uint16_t a=0;
+    int switchn=0, i=0;
+    LPC_pin PollPin[12]={p1_0, p1_1, p1_4, p1_8, p1_9, p1_10, p1_14, p1_15, p1_16, p1_17, p1_27, p1_28};
+    LPCDigitalOut poll[12]={    LPCDigitalOut(PollPin[0]),
+                                LPCDigitalOut(PollPin[1]),
+                                LPCDigitalOut(PollPin[2]),
+                                LPCDigitalOut(PollPin[3]),
+                                LPCDigitalOut(PollPin[4]),
+                                LPCDigitalOut(PollPin[5]),
+                                LPCDigitalOut(PollPin[6]),
+                                LPCDigitalOut(PollPin[7]),
+                                LPCDigitalOut(PollPin[8]),
+                                LPCDigitalOut(PollPin[9]),
+                                LPCDigitalOut(PollPin[10]),
+                                LPCDigitalOut(PollPin[11])};
+    
+    /*
+    _(invariant each iteration input is mode neither)
+    _(ensures all are inputs mode neither)
+    _(at a time only one is ioutput)
+    */
+    
+    for(i=0; i<11; i++){
+        ++switchn;
+       
+        poll[i].write(1);
+        
+        wait_ms(25);
+        
+        //poll[i+1].mode(PullDown);
+        a|=((1 - poll[i+1].read()) << switchn);
+    
+        //poll[i].mode(PullNone);
+        //poll[i+1].mode(PullNone);
+    }
+   // poll[i].mode(neither);        
+    return a;
+}    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTCStore/Store_RTC.h	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,50 @@
+/*  Test Code
+    #include "Battery_Status.h"
+    #include"mbed.h"   
+    BatteryStatus battery;
+    
+    int main()
+    {
+        //battery.write(6.92,0);
+        printf("LPC_RTC->GPREG0:%f\n\r",battery.read(0));
+        //battery.write(7.92,1);
+        printf("LPC_RTC->GPREG1:%f\n\r",battery.read(1));
+        //battery.write(8.92,2);
+        printf("LPC_RTC->GPREG2:%f\n\r",battery.read(2));
+        //battery.write(9.92,3);
+        printf("LPC_RTC->GPREG3:%f\n\r",battery.read(3));
+        //battery.write(10.92,4);
+        printf("LPC_RTC->GPREG4:%f\n\r",battery.read(4));
+    }
+*/        
+
+#ifndef _BATTERY_STATUS_
+#define _BATTERY_STATUS_
+#include"mbed.h"
+
+#define _GPREG_BASE 0x40024044
+
+// RTC = Real-Time Clock
+
+class RTCStore
+{
+    public:
+      RTCStore()
+      {
+          LPC_SC->PCONP |= (1<<9);        //Enable RTC Peripheral
+      }
+      
+      void write(float data, int block)
+      {
+         *(uint32_t*)(_GPREG_BASE + (0x04*block)) = *((uint32_t*)&data);
+         //LPC_RTC->GPREG0 = *((uint32_t*)&data);
+      }
+      
+      float read(int block)
+      {
+          return *((float*)(uint32_t*)(_GPREG_BASE + (0x04*block)));
+          //return *((float*)&(LPC_RTC->GPREG0));
+      }              
+};
+#endif /* _BATTERY_STATUS_ */
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysMngmt.cpp	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,265 @@
+/*
+    Reads CAN Messages and various data inputs, outputs using Xbee radio modules
+
+    Revised Sept 30, 2014: Began analyzing and commenting program, trying to figure out what the hell it does (Martin Deng)
+*/
+
+#include"SysMngmt.h"
+#include"Get_IMD.h"
+#include"PollSwitch.h"
+#include"TemperatureRead.h"
+#include"Store_RTC.h"
+#include"XBee_Lib.h"
+#include"CANBuffer.h"
+
+
+RTCStore store;
+CANBuffer RecieveBuffer(CAN1, MEDIUM);
+XBee250x XbeeTx;
+
+//Possible problems in IMD coz change of counter
+//Possible problems in BatteryStatus coz change in library
+
+/*
+
+Attach Ticker every 10msec to 
+Get IMD
+Poll Switches
+Temperature Read
+Get Battery State
+End Ticker Send message through CAN
+
+CAN interrupt Rx Interrupt
+Recieve CAN message into a buffer. Return
+Buffer values(as long as !empty) -> SD Card, Xbee -> remove element
+*/
+
+/*
+extern "C" void CAN_IRQHandler(void)
+{
+    CANMessage Rxmsg;
+    CAN_SysM.read(Rxmsg);
+    RecieveBuffer.add(Rxmsg);
+}
+*/
+
+extern "C" void TIMER2_IRQHandler(void)
+{
+    if((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt
+    {
+        //printf("Every 1ms\n\r");
+        LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag
+        
+        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   
+    }
+}    
+
+
+void Poll()
+{
+    uint16_t Rxpoll;
+    uint16_t recv,temp,i=0;              //Test
+    char Result[4]={0};
+    Rxpoll=PollSwitch();
+    
+    Result[0]=(char)(Rxpoll&0x00ff);
+    Result[1]=(char)((Rxpoll&0xff00)>>8);    
+    CANMessage Txmsg(410,Result,sizeof(Result));
+    CAN_SysM.write(Txmsg);
+    
+    //Test
+    recv=(((uint16_t)Txmsg.data[1]<<8) | (0x00ff&(uint16_t)Txmsg.data[0]));
+    printf("Recv:%d\n\r",recv);
+    
+    while(i <= 12)
+    {
+        temp=recv;
+        if(((temp & (1 << i))>>i)==1)
+            pc.printf("Switch OFF:%d\n\r",i);
+        ++i;
+    }
+}    
+
+
+void Temp()
+{
+    float DC_DC_Temperature, Coolant1_Temperature, Coolant2_Temperature, ChargerFET_Temperature;
+    float Resistance;
+    float Vadc;
+    int i;
+    ftc send, recv;
+    recv.FLOAT=0.0;
+    send.FLOAT=0.0;
+        
+    Vadc=DC_DC.read()*VDD;
+    Resistance=((float)R10K*Vadc)/((float)VDD + Vadc);
+    DC_DC_Temperature=ReadTemp(TR_NXFT15XH103FA_Map, Resistance, TABLE_SIZE_NXFT15XH103FA); 
+    send.FLOAT=DC_DC_Temperature;
+    CANMessage Txmsg_DC_DC(450,send.C_FLOAT,sizeof(send.C_FLOAT));
+    CAN_SysM.write(Txmsg_DC_DC);
+    
+    for(i=0; i<4;i++)
+        recv.C_FLOAT[i]=Txmsg_DC_DC.data[i];
+    pc.printf("DC_DC:%f\n\r",recv.FLOAT);
+    
+    Vadc=ChargerFET.read()*VDD;
+    Resistance=((float)R10K*Vadc)/((float)VDD + Vadc);
+    ChargerFET_Temperature=ReadTemp(TR_NXFT15XH103FA_Map, Resistance, TABLE_SIZE_NXFT15XH103FA);       
+    send.FLOAT=ChargerFET_Temperature;
+    CANMessage Txmsg_ChargerFET(451,send.C_FLOAT,sizeof(send.C_FLOAT));
+    CAN_SysM.write(Txmsg_ChargerFET);
+    
+    for(i=0; i<4;i++)
+        recv.C_FLOAT[i]=Txmsg_ChargerFET.data[i];
+    pc.printf("ChargerFET:%f\n\r",recv.FLOAT);
+    
+    Vadc=Coolant1.read()*VDD;
+    Resistance=((float)R10K*Vadc)/((float)VDD + Vadc);
+    Coolant1_Temperature=ReadTemp(TR_NTCLP00E3103H_Map, Resistance, TABLE_SIZE_NTCLP00E3103H);
+    send.FLOAT=Coolant1_Temperature;
+    CANMessage Txmsg_Coolant1(452,send.C_FLOAT,sizeof(send.C_FLOAT));
+    CAN_SysM.write(Txmsg_Coolant1);
+    //Control Fans
+    
+    for(i=0; i<4;i++)
+        recv.C_FLOAT[i]=Txmsg_Coolant1.data[i];
+    pc.printf("Coolant1:%f\n\r",recv.FLOAT);
+    
+    Vadc=Coolant2.read()*VDD;
+    Resistance=((float)R10K*Vadc)/((float)VDD + Vadc);
+    Coolant2_Temperature=ReadTemp(TR_NTCLP00E3103H_Map, Resistance, TABLE_SIZE_NTCLP00E3103H);   
+    send.FLOAT=Coolant2_Temperature;
+    CANMessage Txmsg_Coolant2(453,send.C_FLOAT,sizeof(send.C_FLOAT));
+    CAN_SysM.write(Txmsg_Coolant2);
+    //Control Fans
+    
+    for(i=0; i<4;i++)
+        recv.C_FLOAT[i]=Txmsg_Coolant2.data[i];
+    pc.printf("Coolant2:%f\n\r",recv.FLOAT);
+}    
+
+void IMD()
+{
+    IMD_Measurement_Output IMD_Signal;
+    char status[4];
+    ftc send;
+    
+    IMD_Signal=Get_Measurement();
+    send.FLOAT=IMD_Signal.Frequency;
+    CANMessage Txmsg_Frequency(421,send.C_FLOAT,sizeof(send.C_FLOAT));
+    CAN_SysM.write(Txmsg_Frequency);
+    
+    send.FLOAT=IMD_Signal.Duty_Cycle;
+    CANMessage Txmsg_DutyCycle(422,send.C_FLOAT,sizeof(send.C_FLOAT));
+    CAN_SysM.write(Txmsg_DutyCycle);
+    
+    status[0]=Result.Encoded_Status;
+    CANMessage Txmsg_Status(423,status,sizeof(status));
+    CAN_SysM.write(Txmsg_Status);
+}    
+
+void Battery()
+{
+    RTCStore reg;
+    ftc send;
+
+    send.FLOAT=reg.read(0);
+    CANMessage Txmsg_BATmA_Hr(440,send.C_FLOAT,sizeof(send.C_FLOAT));
+    CAN_SysM.write(Txmsg_BATmA_Hr);
+    
+    send.FLOAT=reg.read(1);
+    CANMessage Txmsg_DCA_msec(442,send.C_FLOAT,sizeof(send.C_FLOAT));     
+    CAN_SysM.write(Txmsg_DCA_msec);
+}    
+
+/*
+    Activates a whole crapload of functions and pins on the chip
+*/
+void Init()
+{   
+    /* 
+        Timers to call various functions at different intervals
+        These things behave weirdly when wait(ms) is involved. Probably have to rewrite
+    */
+    
+    //ReadIMD.attach(&IMD,0.1);
+    //PollSDSwitch.attach(&Poll,0.1);
+    
+    //ReadTemperature.attach(&Temp,0.1);
+    //ReadBatteryState.attach(&Battery,0.1);
+    
+    /*
+        Initialize Timer2 for Battery State
+        
+        LPC_SC                      0x400F C000 (System Control)
+        ->PCONP                     0x400F C0C4 (Power Control for Peripherals Register) 
+        |= (1<<22)                  22 Bit (Timer 2 power/clock control bit)
+        
+        ->PCLKSEL1                  Peripheral Clock Selection register 1 (controls rate of clock signal supplied to peripheral)
+        |= ((1<<12) | (1<<13));     12:13 Bits (Peripheral Clock Selection for TIMER2)
+        
+        LPC_TIM2                    0x4009 0000 (Timer 2)
+        ->TCR                       0x4009 0004 (Timer Control Register)
+        |= (1<<0);                  0 Bit (Counter Enable)
+        
+        ->MR0                       0x4009 0018 (Match Register)
+        
+        ->MCR                       0x4009 0014 (Match Control Register)
+        
+    */
+    LPC_SC->PCONP       |= (1<<22);                     //PoewerOn Timer/Counter2
+    LPC_SC->PCLKSEL1    |= ((1<<12) | (1<<13));         //Prescale Timer2 CCLK/8  
+    LPC_TIM2->TCR       |=  (1<<0);                     //Enable Timer2
+    LPC_TIM2->MR0       =   11999;                      // 1msec
+    LPC_TIM2->MCR       |=  (1<<0);
+    
+    NVIC_SetPriority(TIMER0_IRQn,200);                  //IMD Capture Interrupt
+    NVIC_SetPriority(TIMER1_IRQn,200);                  //IMD 1msec sampling Interrupt
+    NVIC_SetPriority(TIMER2_IRQn,1);                    //Battery 1msec sampling Interrupt
+    NVIC_SetPriority(TIMER3_IRQn,255);                  //mbed Timer/Ticker/Wait Interrupt
+    NVIC_SetPriority(CAN_IRQn,2);
+    
+    NVIC_EnableIRQ(TIMER2_IRQn);                        //Enable TIMER2 IRQ 
+    
+    CAN_SysM.mode(CAN::GlobalTest);
+    //NVIC_EnableIRQ(CAN_IRQn);
+    //NVIC_EnableIRQ(CANActivity_IRQn);
+}    
+
+/*
+    Main Loop: Currently reads CANMessages from Can interface (Pins: rd = p30, td = p29)
+    Send CANMessage data through XBee radio transmitters
+    
+*/
+int main() {
+    CANMessage Rxmsg;    
+    
+    Init();
+    
+    while(1)
+    {
+        if(CAN_SysM.read(Rxmsg))
+            RecieveBuffer.txWrite(Rxmsg);
+        while(RecieveBuffer.rxRead(Rxmsg))
+        {
+           XbeeTx.send(Rxmsg);
+        }    
+        
+        //Poll();
+        //Temp();
+        //Battery();
+    }
+    //Temp();
+    //IMD();
+    //Battery();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysMngmt.h	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,42 @@
+#ifndef _SYSMNGMT_
+#define _SYSMNGMT_
+#include "mbed.h"
+
+#define MSEC_HRS 2.77778e-7
+#define DC_DC_ISENSE_OFFSET_V 0.5
+#define DC_DC_ISENSE_INCREMENT 0.133
+
+#define BAT_ISENSE_OFFSET_V 1.65
+#define BAT_ISENSE_INCREMENT 0.5297
+    
+Serial pc(USBTX,USBRX);
+CAN CAN_SysM(p30,p29);
+
+//Temperature Input
+AnalogIn Coolant1(p17); //Brass ones
+AnalogIn Coolant2(p16); //Brass ones
+AnalogIn DC_DC(p18);    //Murata
+AnalogIn ChargerFET(p15);//Murata
+AnalogIn BatISense(p19);
+AnalogIn DCSense(p20);
+
+typedef union convert{
+        float FLOAT;
+        char C_FLOAT[4];
+        }ftc;
+
+// Call function at reccuring interval
+Ticker ReadIMD, PollSDSwitch, ReadTemperature, ReadBatteryState;
+
+double BATmA_Hr;
+float DCA_msec,BATA_msec;
+float Bat_I_Ratio,DC_I_Ratio;
+CANMessage RxBuffer[10]={};
+
+/*
+PwmOut Pump(p26);
+PwmOut Fan1(p25);
+PwmOut Fan2(p24);
+PwmOut Fan3(p23);
+*/
+#endif /* _SYSMNGMT_ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Temperature_Read/TemperatureRead.h	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,271 @@
+/*
+Test Code
+#include "mbed.h"
+#include "TemperatureRead.h"
+
+AnalogIn Vin(p15);
+int main()
+{
+    float resistance,temperature,Vadc=0;
+    while(1)
+    {
+        Vadc=Vin.read()*VDD;
+        //printf("Vadc:%f\n\r",Vadc);
+        while(Vadc>0)
+        {
+            Vadc=Vin.read()*VDD;
+            printf("Vadc:%f\n\r",Vadc);
+            resistance=((float)R10K*Vadc)/((float)VDD + Vadc);
+            temperature=ReadTemp(TR_USP10982_Map, resistance, TABLE_SIZE_USP10982);
+            printf("Resistance:%f \n\r",resistance);
+            printf("Temperature:%f \n\r",temperature);
+            wait(0.5);
+        }   
+    }
+}    
+*/
+#ifndef _TEMPERATURE_READ_
+#define _TEMPERATURE_READ_
+
+#define TABLE_SIZE_NXFT15XH103FA 34
+#define TABLE_SIZE_NTCLP00E3103H 26
+#define TABLE_SIZE_USP10982 121  
+#define R10K 10                        //Consider Resistance in Kohms
+#define VDD 3.33
+typedef struct 
+{
+    float x;
+    float y;
+}Temp_Resistance;
+
+Temp_Resistance TR_NXFT15XH103FA_Map[TABLE_SIZE_NXFT15XH103FA] ={
+    { .x=   197.388 , .y=   -40 },
+    { .x=   149.395 , .y=   -35 },
+    { .x=   114.345 , .y=   -30 },
+    { .x=   88.381  , .y=   -25 },
+    { .x=   68.915  , .y=   -20 },
+    { .x=   54.166  , .y=   -15 },
+    { .x=   42.889  , .y=   -10 },
+    { .x=   34.196  , .y=   -5  },
+    { .x=   27.445  , .y=   0   },
+    { .x=   22.165  , .y=   5   },
+    { .x=   18.01   , .y=   10  },
+    { .x=   14.72   , .y=   15  },
+    { .x=   12.099  , .y=   20  },
+    { .x=   10      , .y=   25  },
+    { .x=   8.309   , .y=   30  },
+    { .x=   6.939   , .y=   35  },
+    { .x=   5.824   , .y=   40  },
+    { .x=   4.911   , .y=   45  },
+    { .x=   4.16    , .y=   50  },
+    { .x=   3.539   , .y=   55  },
+    { .x=   3.024   , .y=   60  },
+    { .x=   2.593   , .y=   65  },
+    { .x=   2.233   , .y=   70  },
+    { .x=   1.929   , .y=   75  },
+    { .x=   1.673   , .y=   80  },
+    { .x=   1.455   , .y=   85  },
+    { .x=   1.27    , .y=   90  },
+    { .x=   1.112   , .y=   95  },
+    { .x=   0.976   , .y=   100 },
+    { .x=   0.86    , .y=   105 },
+    { .x=   0.759   , .y=   110 },
+    { .x=   0.673   , .y=   115 },
+    { .x=   0.598   , .y=   120 },
+    { .x=   0.532   , .y=   125 },
+    };
+    
+Temp_Resistance TR_NTCLP00E3103H_Map[TABLE_SIZE_NTCLP00E3103H] ={
+    { .x=   332.094 , .y=   -40 },
+    { .x=   239.9   , .y=   -35 },
+    { .x=   175.2   , .y=   -30 },
+    { .x=   129.287 , .y=   -25 },
+    { .x=   96.358  , .y=   -20 },
+    { .x=   72.5    , .y=   -15 },
+    { .x=   55.046  , .y=   -10 },
+    { .x=   42.157  , .y=   -5  },
+    { .x=   32.554  , .y=   0   },
+    { .x=   25.339  , .y=   5   },
+    { .x=   19.872  , .y=   10  },
+    { .x=   15.698  , .y=   15  },
+    { .x=   12.488  , .y=   20  },
+    { .x=   10      , .y=   25  },
+    { .x=   8.059   , .y=   30  },
+    { .x=   6.535   , .y=   35  },
+    { .x=   5.33    , .y=   40  },
+    { .x=   4.372   , .y=   45  },
+    { .x=   3.605   , .y=   50  },
+    { .x=   2.989   , .y=   55  },
+    { .x=   2.49    , .y=   60  },
+    { .x=   2.084   , .y=   65  },
+    { .x=   1.753   , .y=   70  },
+    { .x=   1.481   , .y=   75  },
+    { .x=   1.256   , .y=   80  },
+    { .x=   1.07    , .y=   85  },
+
+    };    
+    
+Temp_Resistance TR_USP10982_Map[TABLE_SIZE_USP10982] ={
+    { .x=   336.479 , .y=   -40 },
+    { .x=   314.904 , .y=   -39 },
+    { .x=   294.848 , .y=   -38 },
+    { .x=   276.194 , .y=   -37 },
+    { .x=   258.838 , .y=   -36 },
+    { .x=   242.681 , .y=   -35 },
+    { .x=   227.632 , .y=   -34 },
+    { .x=   213.61  , .y=   -33 },
+    { .x=   200.539 , .y=   -32 },
+    { .x=   188.349 , .y=   -31 },
+    { .x=   176.974 , .y=   -30 },
+    { .x=   166.356 , .y=   -29 },
+    { .x=   156.441 , .y=   -28 },
+    { .x=   147.177 , .y=   -27 },
+    { .x=   138.518 , .y=   -26 },
+    { .x=   130.421 , .y=   -25 },
+    { .x=   122.847 , .y=   -24 },
+    { .x=   115.759 , .y=   -23 },
+    { .x=   109.122 , .y=   -22 },
+    { .x=   102.906 , .y=   -21 },
+    { .x=   97.081  , .y=   -20 },
+    { .x=   91.621  , .y=   -19 },
+    { .x=   86.501  , .y=   -18 },
+    { .x=   81.698  , .y=   -17 },
+    { .x=   77.19   , .y=   -16 },
+    { .x=   72.957  , .y=   -15 },
+    { .x=   68.982  , .y=   -14 },
+    { .x=   65.246  , .y=   -13 },
+    { .x=   61.736  , .y=   -12 },
+    { .x=   58.434  , .y=   -11 },
+    { .x=   55.329  , .y=   -10 },
+    { .x=   52.407  , .y=   -9  },
+    { .x=   49.656  , .y=   -8  },
+    { .x=   47.066  , .y=   -7  },
+    { .x=   44.626  , .y=   -6  },
+    { .x=   42.327  , .y=   -5  },
+    { .x=   40.159  , .y=   -4  },
+    { .x=   38.115  , .y=   -3  },
+    { .x=   36.187  , .y=   -2  },
+    { .x=   34.368  , .y=   -1  },
+    { .x=   32.65   , .y=   0   },
+    { .x=   31.029  , .y=   1   },
+    { .x=   29.498  , .y=   2   },
+    { .x=   28.052  , .y=   3   },
+    { .x=   26.685  , .y=   4   },
+    { .x=   25.392  , .y=   5   },
+    { .x=   24.17   , .y=   6   },
+    { .x=   23.013  , .y=   7   },
+    { .x=   21.918  , .y=   8   },
+    { .x=   20.882  , .y=   9   },
+    { .x=   19.901  , .y=   10  },
+    { .x=   18.971  , .y=   11  },
+    { .x=   18.09   , .y=   12  },
+    { .x=   17.255  , .y=   13  },
+    { .x=   16.463  , .y=   14  },
+    { .x=   15.712  , .y=   15  },
+    { .x=   14.999  , .y=   16  },
+    { .x=   14.323  , .y=   17  },
+    { .x=   13.681  , .y=   18  },
+    { .x=   13.072  , .y=   19  },
+    { .x=   12.493  , .y=   20  },
+    { .x=   11.942  , .y=   21  },
+    { .x=   11.419  , .y=   22  },
+    { .x=   10.922  , .y=   23  },
+    { .x=   10.45   , .y=   24  },
+    { .x=   10      , .y=   25  },
+    { .x=   9.572   , .y=   26  },
+    { .x=   9.165   , .y=   27  },
+    { .x=   8.777   , .y=   28  },
+    { .x=   8.408   , .y=   29  },
+    { .x=   8.057   , .y=   30  },
+    { .x=   7.722   , .y=   31  },
+    { .x=   7.402   , .y=   32  },
+    { .x=   7.098   , .y=   33  },
+    { .x=   6.808   , .y=   34  },
+    { .x=   6.531   , .y=   35  },
+    { .x=   6.267   , .y=   36  },
+    { .x=   6.015   , .y=   37  },
+    { .x=   5.775   , .y=   38  },
+    { .x=   5.545   , .y=   39  },
+    { .x=   5.326   , .y=   40  },
+    { .x=   5.117   , .y=   41  },
+    { .x=   4.917   , .y=   42  },
+    { .x=   4.725   , .y=   43  },
+    { .x=   4.543   , .y=   44  },
+    { .x=   4.368   , .y=   45  },
+    { .x=   4.201   , .y=   46  },
+    { .x=   4.041   , .y=   47  },
+    { .x=   3.888   , .y=   48  },
+    { .x=   3.742   , .y=   49  },
+    { .x=   3.602   , .y=   50  },
+    { .x=   3.468   , .y=   51  },
+    { .x=   3.34    , .y=   52  },
+    { .x=   3.217   , .y=   53  },
+    { .x=   3.099   , .y=   54  },
+    { .x=   2.986   , .y=   55  },
+    { .x=   2.878   , .y=   56  },
+    { .x=   2.774   , .y=   57  },
+    { .x=   2.675   , .y=   58  },
+    { .x=   2.579   , .y=   59  },
+    { .x=   2.488   , .y=   60  },
+    { .x=   2.4     , .y=   61  },
+    { .x=   2.316   , .y=   62  },
+    { .x=   2.235   , .y=   63  },
+    { .x=   2.157   , .y=   64  },
+    { .x=   2.083   , .y=   65  },
+    { .x=   2.011   , .y=   66  },
+    { .x=   1.942   , .y=   67  },
+    { .x=   1.876   , .y=   68  },
+    { .x=   1.813   , .y=   69  },
+    { .x=   1.752   , .y=   70  },
+    { .x=   1.693   , .y=   71  },
+    { .x=   1.637   , .y=   72  },
+    { .x=   1.582   , .y=   73  },
+    { .x=   1.53    , .y=   74  },
+    { .x=   1.48    , .y=   75  },
+    { .x=   1.432   , .y=   76  },
+    { .x=   1.385   , .y=   77  },
+    { .x=   1.34    , .y=   78  },
+    { .x=   1.297   , .y=   79  },
+    { .x=   1.255   , .y=   80  },
+    };
+        
+float ReadTemp(const Temp_Resistance *table, float value, size_t SIZE)
+{
+    //Search using Binary Search. Logarithmic passes
+    int result=SIZE, slope=0;
+    size_t firstPos=0;
+    size_t lastPos=SIZE;
+    size_t middlePos=0;
+    size_t temp_mid=1;
+    //printf("Value:%f\n\r",value);
+    while(temp_mid!=middlePos)
+    {
+        temp_mid=middlePos;
+        middlePos = firstPos + (lastPos-firstPos)/2;
+        if(table[middlePos].x == value)
+        {
+            lastPos = middlePos;
+            result = middlePos;
+        }
+        
+        if(table[middlePos].x < value) 
+        {
+            lastPos = middlePos;
+            result = middlePos;         
+        }
+        
+        else if(table[middlePos].x > value)
+        {
+            firstPos = middlePos;
+        }
+    }
+    //printf("Result:%d\n\r",result);
+    if(result == 0)
+        return  table[result].y;
+    else if(result == SIZE)
+        return  table[result - 1].y;
+    
+    slope = (table[result].y - table[result-1].y)/(table[result].x - table[result-1].x);
+    return (slope*(value - table[result].x) + table[result].y);          
+}
+#endif /*_TEMPERATURE_READ_*/   
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XBee/XBee_Lib.h	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,112 @@
+/*
+Test Code
+//#include "XBee_Lib.h"
+#include "mbed.h"
+#include<sstream>
+#include <cstring>
+#include <string>
+Serial xbee(p28,p27);
+Serial pc(USBTX,USBRX);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut reset(p5);
+DigitalIn CTS(p6, PullNone);
+DigitalIn in(p21, PullDown);
+
+int main() 
+{
+    //char a[]="Hello.....";
+    //int i=0;
+    //while(a[i]!='\0')
+    xbee.baud(250000);
+    char a[63];
+    char b[100];
+    
+    a[0]='\x31';
+    for(int j=1; j<=60; j++)
+    {
+        if(a[j-1]=='\x39')
+        {
+            a[j]='\x41';
+        }
+        else if(a[j-1]=='\x5A')
+        {
+            a[j]='\x61';
+        } 
+        else   
+         a[j]=a[j-1]+1;
+    }
+    a[61]='\n';
+    a[62]='\r';
+    char data[8]="";
+    data[0]='a';
+    data[1]='b';
+    data[2]='c';
+    string stri;
+    
+    //pc.printf("%s",a);
+    reset=0;
+    wait_ms(1);
+    reset=1;
+    wait_ms(1);         
+    
+      
+    std::ostringstream ostr;
+    ostr<<data;
+    stri=ostr.str(); 
+    std::strcpy (b, (ostr.str()).c_str());
+    pc.printf("%s",b);
+    while(1)
+    {
+        while(in.read())
+        {
+            pc.printf("Sending Data...\n\r");
+            xbee.printf("%s",b);
+            
+            if(CTS.read()==1)
+            {
+                pc.printf("DI buffer full\n\r");
+                led2=1;
+                //break;
+                while(CTS.read()){}
+                pc.printf("DI buffer has place\n\r");
+                led2=0;
+                //i=0;
+            } 
+               
+            //wait_ms(1000);
+            led1=!led1;
+            //++i;
+        }
+    }
+}
+*/
+#ifndef XBEE_LIB_H
+#define XBEE_LIB_H
+    
+#include"LPCDigitalOut.h"
+#include"mbed.h"
+#include<sstream>
+
+Serial Xbee_e1(p9,p10);
+Serial Xbee_e2(p13,p14);          
+
+// Used for wireless communications with Xbee
+
+//Include the send function only in the main code.
+class XBee250x
+{
+    public:     
+        XBee250x()
+        {
+            Xbee_e1.baud(250000);
+            Xbee_e2.baud(250000);
+        }    
+                
+        void send(CANMessage Rxmsg)
+        {
+            Xbee_e1.printf("%c \t %d \t %s \n\r",Rxmsg.id, Rxmsg.len, Rxmsg.data);
+            Xbee_e2.printf("%c \t %d \t %s \n\r",Rxmsg.id, Rxmsg.len, Rxmsg.data);
+        }    
+};    
+#endif  /*XBEE_LIB_H*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 01 12:52:26 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file