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@8:2b0d18ebbba9, 2020-06-10 (annotated)
- Committer:
- lorded
- Date:
- Wed Jun 10 22:31:30 2020 +0000
- Revision:
- 8:2b0d18ebbba9
- Parent:
- 7:467e350d1a10
- Child:
- 9:6126b83608be
initial canbus controller commit.;
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" |
lorded | 8:2b0d18ebbba9 | 21 | #include "heatcontrol.h" |
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 | |
lorded | 8:2b0d18ebbba9 | 49 | // external variables |
lorded | 8:2b0d18ebbba9 | 50 | volatile unsigned char idletimer; |
lorded | 8:2b0d18ebbba9 | 51 | char printbuff[256]; |
lorded | 8:2b0d18ebbba9 | 52 | |
lorded | 8:2b0d18ebbba9 | 53 | void DebugWrite(const char* str) { |
lorded | 8:2b0d18ebbba9 | 54 | pc.printf(str); |
lorded | 8:2b0d18ebbba9 | 55 | } |
lorded | 8:2b0d18ebbba9 | 56 | void resetTimer(struct sHeatVars *s) { |
lorded | 8:2b0d18ebbba9 | 57 | //TODO: This. |
lorded | 8:2b0d18ebbba9 | 58 | } |
lorded | 8:2b0d18ebbba9 | 59 | void resetTimerAsync(struct sHeatVars *s) { |
lorded | 8:2b0d18ebbba9 | 60 | //TODO: This. |
lorded | 8:2b0d18ebbba9 | 61 | } |
pangsk | 6:41a4ad385daa | 62 | int main() |
pangsk | 6:41a4ad385daa | 63 | { |
RogerJKelly | 7:467e350d1a10 | 64 | confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) |
pangsk | 3:05bb8f0bd7a4 | 65 | pc.baud(115200); |
RogerJKelly | 7:467e350d1a10 | 66 | |
pangsk | 3:05bb8f0bd7a4 | 67 | //Enable Pullup |
pangsk | 3:05bb8f0bd7a4 | 68 | click.mode(PullUp); |
pangsk | 6:41a4ad385daa | 69 | |
RogerJKelly | 7:467e350d1a10 | 70 | |
RogerJKelly | 7:467e350d1a10 | 71 | pc.printf("\n\nRIXEN Simulator v1.1 \r\n"); |
pangsk | 6:41a4ad385daa | 72 | |
pangsk | 6:41a4ad385daa | 73 | led1 = 1; |
pangsk | 6:41a4ad385daa | 74 | wait(0.1); |
pangsk | 6:41a4ad385daa | 75 | led2 = 1; |
pangsk | 6:41a4ad385daa | 76 | wait(0.1); |
pangsk | 6:41a4ad385daa | 77 | led3 = 1; |
pangsk | 6:41a4ad385daa | 78 | wait(0.1); |
pangsk | 6:41a4ad385daa | 79 | led4 = 1; |
pangsk | 6:41a4ad385daa | 80 | wait(0.2); |
pangsk | 6:41a4ad385daa | 81 | led1 = 0; led2 = 0; led3 = 0; led4 = 0; |
pangsk | 6:41a4ad385daa | 82 | |
pangsk | 0:908be729d27c | 83 | |
pangsk | 6:41a4ad385daa | 84 | wait(1); |
pangsk | 6:41a4ad385daa | 85 | |
RogerJKelly | 7:467e350d1a10 | 86 | //canspeed = CAN500; |
RogerJKelly | 7:467e350d1a10 | 87 | ecu.dtc = false; |
RogerJKelly | 7:467e350d1a10 | 88 | ecu.active_fault = false; |
pangsk | 3:05bb8f0bd7a4 | 89 | |
RogerJKelly | 7:467e350d1a10 | 90 | sim.canspeed(CANSPEED_500); |
pangsk | 6:41a4ad385daa | 91 | |
pangsk | 6:41a4ad385daa | 92 | wait(0.2); |
pangsk | 6:41a4ad385daa | 93 | led1 = 1; |
pangsk | 6:41a4ad385daa | 94 | |
RogerJKelly | 7:467e350d1a10 | 95 | timer.attach(&attime, 1); |
RogerJKelly | 7:467e350d1a10 | 96 | |
lorded | 8:2b0d18ebbba9 | 97 | |
lorded | 8:2b0d18ebbba9 | 98 | initHeaterState(&heaterState[0]); |
lorded | 8:2b0d18ebbba9 | 99 | initHeaterState(&heaterState[1]); |
lorded | 8:2b0d18ebbba9 | 100 | |
lorded | 8:2b0d18ebbba9 | 101 | heaterState[0].bustype = HEATERTYPECAN; |
lorded | 8:2b0d18ebbba9 | 102 | heaterState[0].heaternum = 1; |
lorded | 8:2b0d18ebbba9 | 103 | |
lorded | 8:2b0d18ebbba9 | 104 | heaterState[1].bustype = HEATERTYPENONE; |
lorded | 8:2b0d18ebbba9 | 105 | |
lorded | 8:2b0d18ebbba9 | 106 | |
RogerJKelly | 7:467e350d1a10 | 107 | while(1) // Main CAN loop |
RogerJKelly | 7:467e350d1a10 | 108 | { |
pangsk | 0:908be729d27c | 109 | |
lorded | 8:2b0d18ebbba9 | 110 | for (int i = 0; i < HEATERSTATECOUNT; i++) |
RogerJKelly | 7:467e350d1a10 | 111 | { |
lorded | 8:2b0d18ebbba9 | 112 | // wiced_update_system_monitor(&main_thread_monitor, 10 * 1000); |
lorded | 8:2b0d18ebbba9 | 113 | doHeatTaskCAN(&heaterState[i]); |
lorded | 8:2b0d18ebbba9 | 114 | // wiced_update_system_monitor(&main_thread_monitor, 10 * 1000); |
lorded | 8:2b0d18ebbba9 | 115 | doHeatLogicTask(&heaterState[i]); |
lorded | 8:2b0d18ebbba9 | 116 | if (i < HEATERSTATECOUNT) |
RogerJKelly | 7:467e350d1a10 | 117 | { |
lorded | 8:2b0d18ebbba9 | 118 | wait_ms(50); |
lorded | 8:2b0d18ebbba9 | 119 | } |
lorded | 8:2b0d18ebbba9 | 120 | else |
lorded | 8:2b0d18ebbba9 | 121 | { |
lorded | 8:2b0d18ebbba9 | 122 | //wiced_rtos_delay_milliseconds(50); |
lorded | 8:2b0d18ebbba9 | 123 | } |
pangsk | 6:41a4ad385daa | 124 | } |
pangsk | 6:41a4ad385daa | 125 | } |
pangsk | 6:41a4ad385daa | 126 | } |