Mario Bambagini / Mbed 2 deprecated car_chassis

Dependencies:   Servo mbed-rtos mbed

Committer:
mariob
Date:
Sun Aug 02 12:55:33 2015 +0000
Revision:
0:ce6055872f4e
Child:
1:79b1ee0f97ef
first commit: new car ECU

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariob 0:ce6055872f4e 1 #include "mbed.h"
mariob 0:ce6055872f4e 2 #include "car_config.hpp"
mariob 0:ce6055872f4e 3 #include "rtos.h"
mariob 0:ce6055872f4e 4
mariob 0:ce6055872f4e 5 int init();
mariob 0:ce6055872f4e 6
mariob 0:ce6055872f4e 7 int main()
mariob 0:ce6055872f4e 8 {
mariob 0:ce6055872f4e 9 init();
mariob 0:ce6055872f4e 10
mariob 0:ce6055872f4e 11 while(1) {};
mariob 0:ce6055872f4e 12 }
mariob 0:ce6055872f4e 13
mariob 0:ce6055872f4e 14 void init_led();
mariob 0:ce6055872f4e 15 void init_eeprom();
mariob 0:ce6055872f4e 16
mariob 0:ce6055872f4e 17 Thread *th_body;
mariob 0:ce6055872f4e 18 Thread *th_can;
mariob 0:ce6055872f4e 19
mariob 0:ce6055872f4e 20 void thread_body(void const *args);
mariob 0:ce6055872f4e 21 void thread_can(void const *args);
mariob 0:ce6055872f4e 22
mariob 0:ce6055872f4e 23 void init_threads ()
mariob 0:ce6055872f4e 24 {
mariob 0:ce6055872f4e 25 th_body = new Thread(thread_body);
mariob 0:ce6055872f4e 26 th_can = new Thread(thread_can);
mariob 0:ce6055872f4e 27 }
mariob 0:ce6055872f4e 28 void init_body();
mariob 0:ce6055872f4e 29
mariob 0:ce6055872f4e 30 int init ()
mariob 0:ce6055872f4e 31 {
mariob 0:ce6055872f4e 32
mariob 0:ce6055872f4e 33 init_body();
mariob 0:ce6055872f4e 34
mariob 0:ce6055872f4e 35 printf("INIT LED\r\n");
mariob 0:ce6055872f4e 36 init_led();
mariob 0:ce6055872f4e 37
mariob 0:ce6055872f4e 38 printf("INIT EEPROM\r\n");
mariob 0:ce6055872f4e 39 // init_eeprom();
mariob 0:ce6055872f4e 40
mariob 0:ce6055872f4e 41 printf("INIT CAN\r\n");
mariob 0:ce6055872f4e 42 init_can();
mariob 0:ce6055872f4e 43
mariob 0:ce6055872f4e 44
mariob 0:ce6055872f4e 45 printf("INIT THREAD\r\n");
mariob 0:ce6055872f4e 46 init_threads();
mariob 0:ce6055872f4e 47
mariob 0:ce6055872f4e 48
mariob 0:ce6055872f4e 49
mariob 0:ce6055872f4e 50 return true;
mariob 0:ce6055872f4e 51 }
mariob 0:ce6055872f4e 52
mariob 0:ce6055872f4e 53
mariob 0:ce6055872f4e 54 /****************** EEPROM ******************/
mariob 0:ce6055872f4e 55
mariob 0:ce6055872f4e 56 eeprom_t eeprom(p7, p5, p6, p9, PAGENUMBER, PAGESIZE);
mariob 0:ce6055872f4e 57
mariob 0:ce6055872f4e 58 t_eeprom_data eeprom_data[] = {
mariob 0:ce6055872f4e 59 //SIZE, ADDR
mariob 0:ce6055872f4e 60 { 2, 0}, //SOFTWARE VERSION
mariob 0:ce6055872f4e 61 { 2, 2}, //DATA VERSION
mariob 0:ce6055872f4e 62 { 4, 4}, //NUMBER OF STARTS
mariob 0:ce6055872f4e 63 { 4, 20}, //T_MISSING
mariob 0:ce6055872f4e 64 { 2, 22}, //MIN PWM ON
mariob 0:ce6055872f4e 65 { 2, 24}, //MAX PWM ON
mariob 0:ce6055872f4e 66 { 4, 40}, //ENGINE_LAST_MISSING
mariob 0:ce6055872f4e 67 { 4, 44} //BODY_LAST_MISSING
mariob 0:ce6055872f4e 68 };
mariob 0:ce6055872f4e 69
mariob 0:ce6055872f4e 70 void init_eeprom ()
mariob 0:ce6055872f4e 71 {
mariob 0:ce6055872f4e 72 eeprom.init(eeprom_data, sizeof(eeprom_data)/sizeof(t_eeprom_data));
mariob 0:ce6055872f4e 73
mariob 0:ce6055872f4e 74 uint16 sw = 0;
mariob 0:ce6055872f4e 75 uint16 dd = 0;
mariob 0:ce6055872f4e 76 uint32 num = 0;
mariob 0:ce6055872f4e 77 if ((eeprom.read(EEPROM_DATA_SW_VERS, (uint8*)(&sw)) != 2) ||
mariob 0:ce6055872f4e 78 (eeprom.read(EEPROM_DATA_DD_VERS, (uint8*)(&dd)) != 2) ||
mariob 0:ce6055872f4e 79 (sw != SW_VERSION) || (dd != DD_VERSION))
mariob 0:ce6055872f4e 80 {
mariob 0:ce6055872f4e 81 //error
mariob 0:ce6055872f4e 82 eeprom.reset();
mariob 0:ce6055872f4e 83 sw = SW_VERSION;
mariob 0:ce6055872f4e 84 eeprom.write(EEPROM_DATA_SW_VERS, (uint8*)(&sw));
mariob 0:ce6055872f4e 85 dd = DD_VERSION;
mariob 0:ce6055872f4e 86 eeprom.write(EEPROM_DATA_DD_VERS, (uint8*)(&dd));
mariob 0:ce6055872f4e 87 }
mariob 0:ce6055872f4e 88
mariob 0:ce6055872f4e 89 if (eeprom.read(EEPROM_DATA_NSTARTS, (uint8*)(&num)) != 4)
mariob 0:ce6055872f4e 90 num = 0xffffffff;
mariob 0:ce6055872f4e 91 num++;
mariob 0:ce6055872f4e 92 eeprom.write(EEPROM_DATA_NSTARTS, (unsigned char*)(&num));
mariob 0:ce6055872f4e 93 }