ROM Comm / Mbed 2 deprecated rixen_sim_STM32F103

Dependencies:   mbed mbed-STM32F103C8T6

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 
00003 mbed Can-Bus ECU simulator
00004 
00005 v1.0 December 2014
00006 
00007 ********************************************************************************
00008 
00009 WARNING: Use at your own risk, sadly this software comes with no guarantees.
00010 This software is provided 'free' and in good faith, but the author does not
00011 accept liability for any damage arising from its use.
00012 
00013 ********************************************************************************
00014 
00015 */
00016 //#include "MapleMini.h"
00017 #include "stm32f103c8t6.h"
00018 #include "mbed.h"
00019 #include "ecu_simulator.h"
00020 #include "globals.h"
00021 
00022 
00023 // pinout for Maple Mini
00024 DigitalIn click(PA_1);   // Button inputs
00025 // pinout for lpc1768
00026 //DigitalIn click(p21);   // Joystick inputs
00027 //DigitalIn right(p22);
00028 //DigitalIn down(p23);
00029 //DigitalIn left(p24);
00030 //DigitalIn up(p25);
00031 
00032 ecu_sim sim(CANSPEED_500);     //Create object and set CAN speed
00033 ecu_t ecu;
00034 
00035 Ticker timer;
00036 
00037 void attime() 
00038 {
00039     //second_tick = true;
00040     //myled = !myled;
00041     led1 = !led1;
00042 }
00043 
00044 // Menu defines
00045 
00046 //unsigned char menu_state;
00047 //unsigned char canspeed;
00048 
00049 int main() 
00050 {
00051     confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
00052     pc.baud(115200);
00053     
00054     //Enable Pullup 
00055     click.mode(PullUp);
00056 
00057     
00058     pc.printf("\n\nRIXEN Simulator v1.1 \r\n"); 
00059       
00060     led1 = 1;
00061     wait(0.1);
00062     led2 = 1;
00063     wait(0.1);
00064     led3 = 1;
00065     wait(0.1);
00066     led4 = 1;
00067     wait(0.2);
00068     led1 = 0; led2 = 0; led3 = 0; led4 = 0;
00069        
00070     
00071     wait(1);
00072     
00073     //canspeed = CAN500;
00074     ecu.dtc = false;
00075     ecu.active_fault = false;
00076     
00077     sim.canspeed(CANSPEED_500); 
00078     
00079     wait(0.2);
00080     led1 = 1;
00081     
00082     timer.attach(&attime, 1);
00083     
00084     while(1)  // Main CAN loop
00085     {
00086         sim.request();
00087         
00088         if(!click)
00089         {
00090             //update_param(DEC);
00091             if ( ecu.active_fault == true )
00092             {
00093                 ecu.active_fault = false;
00094                 led4 = 0;               
00095             } else {
00096                 ecu.active_fault = true;
00097                 led4 = 1;
00098             } 
00099             wait(0.1);   //Delay for auto repeat           
00100         }
00101         //wait(0.1);   //Delay cause can bus problems
00102         //led1 = 1;
00103         //wait(0.1);
00104         //led1 = 0; 
00105     }
00106 }