Penn Electric Racing / Mbed 2 deprecated REVO_Updated_Steering

Dependencies:   CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses

Fork of REVO_Updated_Steering by Penn Electric

Files at this revision

API Documentation at this revision

Comitter:
palimar
Date:
Sat Oct 18 18:26:44 2014 +0000
Parent:
15:da14227cdd1d
Child:
17:e97c889873e2
Child:
28:3ebe6db73fe0
Commit message:
Removed Digital_InOut.h, rewrote all code to handle input and code with LPCDigitalOut.h, added Tyrell's reset code and added CANBuffer.

Changed in this revision

CANBuffer.lib Show annotated file Show diff for this revision Revisions of this file
Digital_InOut.lib Show diff for this revision Revisions of this file
Digital_Out.h Show diff for this revision Revisions of this file
Steering.cpp Show annotated file Show diff for this revision Revisions of this file
Steering.h Show annotated file Show diff for this revision Revisions of this file
--- a/CANBuffer.lib	Sat Oct 18 17:19:43 2014 +0000
+++ b/CANBuffer.lib	Sat Oct 18 18:26:44 2014 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Penn-Electric-Racing/code/CANBuffer/#fbfd7c8a93b5
+http://developer.mbed.org/teams/Penn-Electric-Racing/code/CANBuffer/#110f268af846
--- a/Digital_InOut.lib	Sat Oct 18 17:19:43 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/kiran_mbed/code/Digital_InOut/#b4bc3430a055
--- a/Digital_Out.h	Sat Oct 18 17:19:43 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,315 +0,0 @@
-/*
-Test Code
-#include "Digital_Out.h"
-
-//Serial pc(USBTX,USBRX);
-
-int main()
-{
-    Digital_Out ledPin1(p1_18,1);
-    Digital_Out ledPin2(p1_20,0);
-    Digital_Out ledPin3(p1_21,1);
-    Digital_Out ledPin4(p1_23,0);
-     
-    
-    wait(0.5);
-    while(1)
-    {
-        ledPin1= !ledPin1;
-        ledPin2= !ledPin2;
-        ledPin3= !ledPin3;
-        ledPin4= !ledPin4;
-         
-        wait(0.5);
-        ledPin1= !ledPin1;
-        ledPin2= !ledPin2;
-        ledPin3= !ledPin3;
-        ledPin4= !ledPin4;
-        
-        wait(0.5);
-    }
-
-Digital_Out pin(p0_0);
-
-DigitalOut myled(LED1);
-
-Timer t;
-int main() {
-   t.reset();
-   t.start();
-   for (int i = 0; i < 1000000; i++){
-    pin = 1;
-    pin = 0;
-   }
-       t.stop();
-
-   unsigned int time1 = t.read_us(); 
-    
-    t.reset();
-    t.start();
-    for (int i = 0; i < 1000000; i++) {
-    myled = 1;
-    myled = 0;
-    }
-    t.stop();
-    unsigned int time2 = t.read_us();
-    printf("Library time: %d, mbed time: %d\r\n", time1, time2);
-    while(1) {
-
-    }
-}
-*/
-
-#ifndef DIGITAL_OUT_H
-    #define DIGITAL_OUT_H
-    
-    #include"mbed.h"
-        
-    #define _PINSEL_BASE 0x4002C000
-    #define _FIODIR_BASE 0x2009C000
-    #define _FIOSET_BASE 0x2009C018
-    #define _FIOCLR_BASE 0x2009C01C
-    #define _FIOPIN_BASE 0x2009C014
-    
-    #ifndef _PIN_
-        #define _PIN_
-        typedef struct
-        {
-            int port;
-            int pin;
-        }Pin;
-    #endif /* _PIN_ */
-    
-    #ifndef _PIN_NAME_
-        #define _PIN_NAME_
-        // Note many pins are not available as fully functional GPIOs, they are ommitted below
-        enum Pin_Name
-        {
-            p0_0 = 0,
-            p0_1 = 1,
-            p0_2 = 2,
-            p0_3 = 3,
-            p0_4 = 4,
-            p0_5 = 5,
-            p0_6 = 6,
-            p0_7 = 7,
-            p0_8 = 8,
-            p0_9 = 9,
-            p0_10 = 10,
-            p0_11 = 11,
-            /*p0_12 = 12,
-            p0_13 = 13,
-            p0_14 = 14,*/
-            p0_15 = 15,
-            p0_16 = 16,
-        
-            p0_17 = 17,
-            p0_18 = 18,
-            p0_19 = 19,
-            p0_20 = 20,
-            p0_21 = 21,
-            p0_22 = 22,
-            p0_23 = 23,
-            p0_24 = 24,
-            p0_25 = 25,
-            p0_26 = 26,
-          /*  p0_27 = 27,
-            p0_28 = 28,
-            p0_29 = 29,
-            p0_30 = 30,*/
-        
-        
-            p1_0 = 100,
-            p1_1 = 101,
-           /* p1_2 = 102,
-            p1_3 = 103,*/
-            p1_4 = 104,
-           /* p1_5 = 105,
-            p1_6 = 106,
-            p1_7 = 107,*/
-            p1_8 = 108,
-            p1_9 = 109,
-            p1_10 = 110,
-           /* p1_11 = 111,
-            p1_12 = 112,
-            p1_13 = 113,*/
-            p1_14 = 114,
-            p1_15 = 115,
-        
-            p1_16 = 116,
-            p1_17 = 117,
-            p1_18 = 118,
-            p1_19 = 119,
-            p1_20 = 120,
-            p1_21 = 121,
-            p1_22 = 122,
-            p1_23 = 123,
-            p1_24 = 124,
-            p1_25 = 125,
-            p1_26 = 126,
-            p1_27 = 127,
-            p1_28 = 128,
-            p1_29 = 129,
-            p1_30 = 130,
-        
-        
-            p2_0 = 200,
-            p2_1 = 201,
-            p2_2 = 202,
-            p2_3 = 203,
-            p2_4 = 204,
-            p2_5 = 205,
-            p2_6 = 206,
-            p2_7 = 207,
-            p2_8 = 208,
-            p2_9 = 209,
-            p2_10 = 210,
-            p2_11 = 211,
-            p2_12 = 212,
-            p2_13 = 213,
-           /* p2_14 = 214,
-            p2_15 = 215,
-        
-            p2_16 = 216,
-            p2_17 = 217,
-            p2_18 = 218,
-            p2_19 = 219,
-            p2_20 = 220,
-            p2_21 = 221,
-            p2_22 = 222,
-            p2_23 = 223,
-            p2_24 = 224,
-            p2_25 = 225,
-            p2_26 = 226,
-            p2_27 = 227,
-            p2_28 = 228,
-            p2_29 = 229,
-            p2_30 = 230,*/
-        
-        
-           /* p3_0 = 300,
-            p3_1 = 301,
-            p3_2 = 302,
-            p3_3 = 303,
-            p3_4 = 304,
-            p3_5 = 305,
-            p3_6 = 306,
-            p3_7 = 307,
-            p3_8 = 308,
-            p3_9 = 309,
-            p3_10 = 310,
-            p3_11 = 311,
-            p3_12 = 312,
-            p3_13 = 313,
-            p3_14 = 314,
-            p3_15 = 315,
-        
-            p3_16 = 316,
-            p3_17 = 317,
-            p3_18 = 318,
-            p3_19 = 319,
-            p3_20 = 320,
-            p3_21 = 321,
-            p3_22 = 322,
-            p3_23 = 323,
-            p3_24 = 324,*/
-            p3_25 = 325,
-            p3_26 = 326,
-            /*p3_27 = 327,
-            p3_28 = 328,
-            p3_29 = 329,
-            p3_30 = 330,*/
-        
-            /*p4_0 = 400,
-            p4_1 = 401,
-            p4_2 = 402,
-            p4_3 = 403,
-            p4_4 = 404,
-            p4_5 = 405,
-            p4_6 = 406,
-            p4_7 = 407,
-            p4_8 = 408,
-            p4_9 = 409,
-            p4_10 = 410,
-            p4_11 = 411,
-            p4_12 = 412,
-            p4_13 = 413,
-            p4_14 = 414,
-            p4_15 = 415,
-        
-            p4_16 = 416,
-            p4_17 = 417,
-            p4_18 = 418,
-            p4_19 = 419,
-            p4_20 = 420,
-            p4_21 = 421,
-            p4_22 = 422,
-            p4_23 = 423,
-            p4_24 = 424,
-            p4_25 = 425,
-            p4_26 = 426,
-            p4_27 = 427,*/
-            p4_28 = 428,
-            p4_29 = 429,
-            /*p4_30 = 430*/
-        
-        };
-    #endif /* _PIN_NAME_ */
-    
-    
-    class Digital_Out
-    {
-        private:    Pin _pin;
-        public:     Digital_Out(Pin_Name IPin)
-                    {
-                        _pin.port=(IPin/100);
-                        _pin.pin=(IPin%100);
-                        const int PINSELx = ((_pin.port*2) + (1* (_pin.pin > 15) ? 1:0));
-                        const int FIODIRx = _pin.port;
-                        
-                        *(uint32_t*)(_PINSEL_BASE + (PINSELx*4)) &= ~(1 << ((_pin.pin%16)*2) | (1 << (((_pin.pin%16)*2)+1)));          //GPIO
-                        *(uint32_t*)(_FIODIR_BASE + (FIODIRx*0x20)) |= (1 << _pin.pin);                                        //Output
-                    }
-                    
-                    Digital_Out(Pin_Name IPin, int value)
-                    {
-                        _pin.port=(IPin/100);
-                        _pin.pin=(IPin%100);
-                        const int PINSELx = ((_pin.port*2) + (1* (_pin.pin > 15) ? 1:0));
-                        const int FIODIRx = _pin.port;
-                        
-                        *(uint32_t*)(_PINSEL_BASE + (PINSELx*4)) &= ~(1 << ((_pin.pin%16)*2) | (1 << (((_pin.pin%16)*2)+1)));           //GPIO
-                        *(uint32_t*)(_FIODIR_BASE + (FIODIRx*0x20)) |= (1 << _pin.pin);                                        //Output
-                        *(uint32_t*)((_FIOSET_BASE*value) + (_FIOCLR_BASE*(1-value)) + (_pin.port*0x20)) |= (1 << _pin.pin);   //Write     
-                    }
-                    
-                    void write(int value)
-                    {
-                        if (value != 1 && value != 0) return;
-                        *(uint32_t*)((_FIOSET_BASE*value)+(_FIOCLR_BASE*(1-value)) + (_pin.port*0x20)) |= (1 << _pin.pin);     //Write     
-                    }
-                    
-                    int read()
-                    {
-                        return ((*(uint32_t*)(_FIOPIN_BASE +_pin.port*0x20) & (1 << _pin.pin)) >> _pin.pin);                          //Read
-                    }
-                    
-                    Digital_Out& operator= (int value)
-                    {
-                        write(value);
-                        return *this;
-                    }
-                    
-                    Digital_Out& operator= (Digital_Out& rhs)
-                    {
-                        write(rhs.read());
-                        return *this;
-                    }
-                    
-                    operator int()
-                    {
-                        return read();
-                    }
-    };
-
-#endif /*DIGITAL_OUT_H*/
\ No newline at end of file
--- a/Steering.cpp	Sat Oct 18 17:19:43 2014 +0000
+++ b/Steering.cpp	Sat Oct 18 18:26:44 2014 +0000
@@ -14,7 +14,7 @@
     display.PrintString(" HOME SCREEN");
     while( !(biSWTL.read() || biSWTR.read() || biSWBR.read()) )
     {
-        if(CAN_Steering.read(Rxmsg))
+        if(CAN_Steering_Buffer.rxRead(Rxmsg))
         {
             for(int i=0; i<4; i++)
                 rcv.C_FLOAT[i]=Rxmsg.data[i];
@@ -58,7 +58,7 @@
     while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
     {
         printf("iN LOOP1");
-        if(CAN_Steering.read(Rxmsg))
+        if(CAN_Steering_Buffer.rxRead(Rxmsg))
         {
             for(int i=0; i<4; i++)
                 rcv.C_FLOAT[i]=Rxmsg.data[i];
@@ -126,7 +126,7 @@
     while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
     {
         printf("iN LOOP2");
-        if(CAN_Steering.read(Rxmsg))
+        if(CAN_Steering_Buffer.rxRead(Rxmsg))
         {
             for(int i=0; i<4; i++)
                 rcv.C_FLOAT[i]=Rxmsg.data[i];
@@ -221,7 +221,7 @@
     }
     
     for(int i = 0; i < 10; i++){
-        CAN_Steering.write(Txmsg_drive_status_request);
+        CAN_Steering_Buffer.txWrite(Txmsg_drive_status_request);
     }
 
     display.ClearScreen();
@@ -237,6 +237,8 @@
 
 void reset()
 {
+    CAN_Steering_Buffer.txWriteDirect(Txmsg_reset);
+    mbed_reset();
     display.ClearScreen();
     display.SelectFont(Arial12,BLACK,ReadData);
     display.GotoXY(16,16);
@@ -252,7 +254,7 @@
     float power_ratio;
     ftc rcv;
     rcv.FLOAT=0.0;
-    if(CAN_Steering.read(Rxmsg))
+    if(CAN_Steering_Buffer.rxRead(Rxmsg))
     {   
         if(Rxmsg.id == BATTERY_POWER_ID)
         {
@@ -268,7 +270,6 @@
 void Init()
 {
     pc.baud(230400);
-    CAN_Steering.frequency(500000);
     drive_status = 0;
     drive_status_request = 1;
     reset_body = 0;
--- a/Steering.h	Sat Oct 18 17:19:43 2014 +0000
+++ b/Steering.h	Sat Oct 18 18:26:44 2014 +0000
@@ -3,13 +3,13 @@
 
 #include "mbed.h"
 #include "rtos.h"
-#include "Digital_InOut.h"
 #include "KS0108.h"
 
 #include "Arial12.h"
 #include "Arial14.h"
 #include "Comic24.h"
 #include "vivaldi16.h"
+#include "CANBuffer.h"
 
 #define SWITCH_ID 410
 
@@ -29,41 +29,40 @@
 #define AMS_BATTERY_STATE 0x30E          // AIRS 7 and 6 // Precharge 3
 
 Serial pc(USBTX,USBRX);
-CAN CAN_Steering(p9,p10);
-Digital_InOut CAN_Silent(p3_26, 0, output);
+CANBuffer CAN_Steering_Buffer(CAN1,MEDIUM);
+LPCDigitalOut CAN_Silent(p3_26, 0);
+
+extern "C" void mbed_reset();
 
 KS0108 display(p26, p21, p22, p23, p25, p24, p8, p7, p6, p5, p13, p14, p12, p11); 
 Ticker call_ledstream;
 
-Digital_InOut l1(p1_28,1,output);//    SW2
-Digital_InOut l2(p1_26,1,output);//    SW4
+LPCDigitalOut l1(p1_28,1);//    SW2
+LPCDigitalOut l2(p1_26,1);//    SW4
     
-Digital_InOut l3(p1_24,1,output);//    SW6
-Digital_InOut l4(p0_24,1,output);//    SW8
+LPCDigitalOut l3(p1_24,1);//    SW6
+LPCDigitalOut l4(p0_24,1);//    SW8
 
-Digital_InOut u1(p1_14,0,output);//    SW9 
-Digital_InOut u2(p1_9,0,output);//     SW11
+LPCDigitalOut u1(p1_14,0);//    SW9 
+LPCDigitalOut u2(p1_9,0);//     SW11
 
-Digital_InOut u3(p1_4,0,output);//     SW13
-Digital_InOut u4(p1_0,0,output);//     SW15
+LPCDigitalOut u3(p1_4,0);//     SW13
+LPCDigitalOut u4(p1_0,0);//     SW15
 
 AnalogOut ledstream(p18);
 
 //SW1 - SW3
-Digital_InOut boSW1(p1_29,1,output);
-Digital_InOut biSWBR(p1_27,pull_down,input);     //BRight
+LPCDigitalOut boSW1(p1_29,1);
+LPCDigitalOut biSWBR(p1_27,1);     //BRight
 
-Digital_InOut boSW5(p1_25,1,output);
-Digital_InOut biSWBL(p1_22,pull_down,input);     //BLeft
+LPCDigitalOut boSW5(p1_25,1);
+LPCDigitalOut biSWBL(p1_22,1);     //BLeft
 
-//Digital_InOut boSW5(P1_25,1,output);
-//Digital_InOut biSW7(P1_22,pull_down,input);
+LPCDigitalOut boSW10(p1_10,1);
+LPCDigitalOut biSWTR(p1_8,1);     //TRight
 
-Digital_InOut boSW10(p1_10,1,output);
-Digital_InOut biSWTR(p1_8,pull_down,input);     //TRight
-
-Digital_InOut boSW14(p1_1,1,output);
-Digital_InOut biSWTL(p0_25,pull_down,input);    //TLeft
+LPCDigitalOut boSW14(p1_1,1);
+LPCDigitalOut biSWTL(p0_25,1);    //TLeft
 
 typedef union convert{
         float FLOAT;