Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-STM32F103C8T6
main.cpp@7:467e350d1a10, 2020-06-10 (annotated)
- Committer:
- RogerJKelly
- Date:
- Wed Jun 10 20:15:48 2020 +0000
- Revision:
- 7:467e350d1a10
- Parent:
- 6:41a4ad385daa
- Child:
- 8:2b0d18ebbba9
RIXEN SIM with Maple Mini
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pangsk | 0:908be729d27c | 1 | /* |
pangsk | 0:908be729d27c | 2 | |
pangsk | 6:41a4ad385daa | 3 | mbed Can-Bus ECU simulator |
pangsk | 0:908be729d27c | 4 | |
pangsk | 6:41a4ad385daa | 5 | v1.0 December 2014 |
pangsk | 0:908be729d27c | 6 | |
pangsk | 0:908be729d27c | 7 | ******************************************************************************** |
pangsk | 0:908be729d27c | 8 | |
pangsk | 0:908be729d27c | 9 | WARNING: Use at your own risk, sadly this software comes with no guarantees. |
pangsk | 0:908be729d27c | 10 | This software is provided 'free' and in good faith, but the author does not |
pangsk | 0:908be729d27c | 11 | accept liability for any damage arising from its use. |
pangsk | 0:908be729d27c | 12 | |
pangsk | 0:908be729d27c | 13 | ******************************************************************************** |
pangsk | 0:908be729d27c | 14 | |
pangsk | 0:908be729d27c | 15 | */ |
RogerJKelly | 7:467e350d1a10 | 16 | //#include "MapleMini.h" |
RogerJKelly | 7:467e350d1a10 | 17 | #include "stm32f103c8t6.h" |
pangsk | 0:908be729d27c | 18 | #include "mbed.h" |
pangsk | 6:41a4ad385daa | 19 | #include "ecu_simulator.h" |
pangsk | 0:908be729d27c | 20 | #include "globals.h" |
pangsk | 0:908be729d27c | 21 | |
pangsk | 0:908be729d27c | 22 | |
RogerJKelly | 7:467e350d1a10 | 23 | // pinout for Maple Mini |
RogerJKelly | 7:467e350d1a10 | 24 | DigitalIn click(PA_1); // Button inputs |
RogerJKelly | 7:467e350d1a10 | 25 | // pinout for lpc1768 |
RogerJKelly | 7:467e350d1a10 | 26 | //DigitalIn click(p21); // Joystick inputs |
RogerJKelly | 7:467e350d1a10 | 27 | //DigitalIn right(p22); |
RogerJKelly | 7:467e350d1a10 | 28 | //DigitalIn down(p23); |
RogerJKelly | 7:467e350d1a10 | 29 | //DigitalIn left(p24); |
RogerJKelly | 7:467e350d1a10 | 30 | //DigitalIn up(p25); |
pangsk | 3:05bb8f0bd7a4 | 31 | |
pangsk | 6:41a4ad385daa | 32 | ecu_sim sim(CANSPEED_500); //Create object and set CAN speed |
pangsk | 6:41a4ad385daa | 33 | ecu_t ecu; |
pangsk | 6:41a4ad385daa | 34 | |
RogerJKelly | 7:467e350d1a10 | 35 | Ticker timer; |
RogerJKelly | 7:467e350d1a10 | 36 | |
RogerJKelly | 7:467e350d1a10 | 37 | void attime() |
RogerJKelly | 7:467e350d1a10 | 38 | { |
RogerJKelly | 7:467e350d1a10 | 39 | //second_tick = true; |
RogerJKelly | 7:467e350d1a10 | 40 | //myled = !myled; |
RogerJKelly | 7:467e350d1a10 | 41 | led1 = !led1; |
RogerJKelly | 7:467e350d1a10 | 42 | } |
pangsk | 0:908be729d27c | 43 | |
pangsk | 6:41a4ad385daa | 44 | // Menu defines |
pangsk | 0:908be729d27c | 45 | |
RogerJKelly | 7:467e350d1a10 | 46 | //unsigned char menu_state; |
RogerJKelly | 7:467e350d1a10 | 47 | //unsigned char canspeed; |
pangsk | 6:41a4ad385daa | 48 | |
pangsk | 6:41a4ad385daa | 49 | int main() |
pangsk | 6:41a4ad385daa | 50 | { |
RogerJKelly | 7:467e350d1a10 | 51 | confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) |
pangsk | 3:05bb8f0bd7a4 | 52 | pc.baud(115200); |
RogerJKelly | 7:467e350d1a10 | 53 | |
pangsk | 3:05bb8f0bd7a4 | 54 | //Enable Pullup |
pangsk | 3:05bb8f0bd7a4 | 55 | click.mode(PullUp); |
pangsk | 6:41a4ad385daa | 56 | |
RogerJKelly | 7:467e350d1a10 | 57 | |
RogerJKelly | 7:467e350d1a10 | 58 | pc.printf("\n\nRIXEN Simulator v1.1 \r\n"); |
pangsk | 6:41a4ad385daa | 59 | |
pangsk | 6:41a4ad385daa | 60 | led1 = 1; |
pangsk | 6:41a4ad385daa | 61 | wait(0.1); |
pangsk | 6:41a4ad385daa | 62 | led2 = 1; |
pangsk | 6:41a4ad385daa | 63 | wait(0.1); |
pangsk | 6:41a4ad385daa | 64 | led3 = 1; |
pangsk | 6:41a4ad385daa | 65 | wait(0.1); |
pangsk | 6:41a4ad385daa | 66 | led4 = 1; |
pangsk | 6:41a4ad385daa | 67 | wait(0.2); |
pangsk | 6:41a4ad385daa | 68 | led1 = 0; led2 = 0; led3 = 0; led4 = 0; |
pangsk | 6:41a4ad385daa | 69 | |
pangsk | 0:908be729d27c | 70 | |
pangsk | 6:41a4ad385daa | 71 | wait(1); |
pangsk | 6:41a4ad385daa | 72 | |
RogerJKelly | 7:467e350d1a10 | 73 | //canspeed = CAN500; |
RogerJKelly | 7:467e350d1a10 | 74 | ecu.dtc = false; |
RogerJKelly | 7:467e350d1a10 | 75 | ecu.active_fault = false; |
pangsk | 3:05bb8f0bd7a4 | 76 | |
RogerJKelly | 7:467e350d1a10 | 77 | sim.canspeed(CANSPEED_500); |
pangsk | 6:41a4ad385daa | 78 | |
pangsk | 6:41a4ad385daa | 79 | wait(0.2); |
pangsk | 6:41a4ad385daa | 80 | led1 = 1; |
pangsk | 6:41a4ad385daa | 81 | |
RogerJKelly | 7:467e350d1a10 | 82 | timer.attach(&attime, 1); |
RogerJKelly | 7:467e350d1a10 | 83 | |
RogerJKelly | 7:467e350d1a10 | 84 | while(1) // Main CAN loop |
RogerJKelly | 7:467e350d1a10 | 85 | { |
pangsk | 6:41a4ad385daa | 86 | sim.request(); |
pangsk | 0:908be729d27c | 87 | |
RogerJKelly | 7:467e350d1a10 | 88 | if(!click) |
RogerJKelly | 7:467e350d1a10 | 89 | { |
RogerJKelly | 7:467e350d1a10 | 90 | //update_param(DEC); |
RogerJKelly | 7:467e350d1a10 | 91 | if ( ecu.active_fault == true ) |
RogerJKelly | 7:467e350d1a10 | 92 | { |
RogerJKelly | 7:467e350d1a10 | 93 | ecu.active_fault = false; |
RogerJKelly | 7:467e350d1a10 | 94 | led4 = 0; |
RogerJKelly | 7:467e350d1a10 | 95 | } else { |
RogerJKelly | 7:467e350d1a10 | 96 | ecu.active_fault = true; |
RogerJKelly | 7:467e350d1a10 | 97 | led4 = 1; |
RogerJKelly | 7:467e350d1a10 | 98 | } |
RogerJKelly | 7:467e350d1a10 | 99 | wait(0.1); //Delay for auto repeat |
pangsk | 6:41a4ad385daa | 100 | } |
RogerJKelly | 7:467e350d1a10 | 101 | //wait(0.1); //Delay cause can bus problems |
RogerJKelly | 7:467e350d1a10 | 102 | //led1 = 1; |
RogerJKelly | 7:467e350d1a10 | 103 | //wait(0.1); |
RogerJKelly | 7:467e350d1a10 | 104 | //led1 = 0; |
pangsk | 6:41a4ad385daa | 105 | } |
pangsk | 6:41a4ad385daa | 106 | } |