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: Servo mbed-rtos mbed
main.cpp@1:79b1ee0f97ef, 2015-08-31 (annotated)
- Committer:
- mariob
- Date:
- Mon Aug 31 22:25:57 2015 +0000
- Revision:
- 1:79b1ee0f97ef
- Parent:
- 0:ce6055872f4e
- Child:
- 2:7dfc8dd6aab3
first commit with the following features: CAN driver (it works), eeprom (it works but it is not used)
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:79b1ee0f97ef | 5 | #include "led.hpp" |
mariob | 1:79b1ee0f97ef | 6 | #include "body.hpp" |
mariob | 1:79b1ee0f97ef | 7 | #include "engine.hpp" |
mariob | 1:79b1ee0f97ef | 8 | #include "driver.hpp" |
mariob | 1:79b1ee0f97ef | 9 | #include "clock.hpp" |
mariob | 1:79b1ee0f97ef | 10 | |
mariob | 0:ce6055872f4e | 11 | int init(); |
mariob | 0:ce6055872f4e | 12 | |
mariob | 0:ce6055872f4e | 13 | int main() |
mariob | 0:ce6055872f4e | 14 | { |
mariob | 0:ce6055872f4e | 15 | init(); |
mariob | 0:ce6055872f4e | 16 | |
mariob | 0:ce6055872f4e | 17 | while(1) {}; |
mariob | 0:ce6055872f4e | 18 | } |
mariob | 0:ce6055872f4e | 19 | |
mariob | 0:ce6055872f4e | 20 | void init_eeprom(); |
mariob | 0:ce6055872f4e | 21 | |
mariob | 0:ce6055872f4e | 22 | Thread *th_body; |
mariob | 0:ce6055872f4e | 23 | Thread *th_can; |
mariob | 1:79b1ee0f97ef | 24 | Thread *th_engine; |
mariob | 1:79b1ee0f97ef | 25 | Thread *th_driver; |
mariob | 1:79b1ee0f97ef | 26 | Thread *th_clock; |
mariob | 0:ce6055872f4e | 27 | |
mariob | 0:ce6055872f4e | 28 | void init_threads () |
mariob | 0:ce6055872f4e | 29 | { |
mariob | 0:ce6055872f4e | 30 | th_body = new Thread(thread_body); |
mariob | 1:79b1ee0f97ef | 31 | th_engine = new Thread(thread_engine); |
mariob | 0:ce6055872f4e | 32 | th_can = new Thread(thread_can); |
mariob | 1:79b1ee0f97ef | 33 | th_driver = new Thread(thread_driver); |
mariob | 1:79b1ee0f97ef | 34 | th_clock = new Thread(thread_clock); |
mariob | 0:ce6055872f4e | 35 | } |
mariob | 0:ce6055872f4e | 36 | |
mariob | 0:ce6055872f4e | 37 | int init () |
mariob | 0:ce6055872f4e | 38 | { |
mariob | 1:79b1ee0f97ef | 39 | init_body(); |
mariob | 1:79b1ee0f97ef | 40 | init_clock(); |
mariob | 1:79b1ee0f97ef | 41 | init_driver(); |
mariob | 1:79b1ee0f97ef | 42 | init_engine(); |
mariob | 0:ce6055872f4e | 43 | |
mariob | 0:ce6055872f4e | 44 | printf("INIT LED\r\n"); |
mariob | 0:ce6055872f4e | 45 | init_led(); |
mariob | 1:79b1ee0f97ef | 46 | |
mariob | 1:79b1ee0f97ef | 47 | /* |
mariob | 0:ce6055872f4e | 48 | printf("INIT EEPROM\r\n"); |
mariob | 1:79b1ee0f97ef | 49 | init_eeprom(); |
mariob | 1:79b1ee0f97ef | 50 | */ |
mariob | 0:ce6055872f4e | 51 | |
mariob | 0:ce6055872f4e | 52 | printf("INIT CAN\r\n"); |
mariob | 0:ce6055872f4e | 53 | init_can(); |
mariob | 0:ce6055872f4e | 54 | |
mariob | 0:ce6055872f4e | 55 | printf("INIT THREAD\r\n"); |
mariob | 0:ce6055872f4e | 56 | init_threads(); |
mariob | 0:ce6055872f4e | 57 | |
mariob | 0:ce6055872f4e | 58 | return true; |
mariob | 0:ce6055872f4e | 59 | } |
mariob | 0:ce6055872f4e | 60 | |
mariob | 0:ce6055872f4e | 61 | |
mariob | 0:ce6055872f4e | 62 | /****************** EEPROM ******************/ |
mariob | 1:79b1ee0f97ef | 63 | /* |
mariob | 0:ce6055872f4e | 64 | eeprom_t eeprom(p7, p5, p6, p9, PAGENUMBER, PAGESIZE); |
mariob | 0:ce6055872f4e | 65 | |
mariob | 0:ce6055872f4e | 66 | t_eeprom_data eeprom_data[] = { |
mariob | 0:ce6055872f4e | 67 | //SIZE, ADDR |
mariob | 0:ce6055872f4e | 68 | { 2, 0}, //SOFTWARE VERSION |
mariob | 0:ce6055872f4e | 69 | { 2, 2}, //DATA VERSION |
mariob | 0:ce6055872f4e | 70 | { 4, 4}, //NUMBER OF STARTS |
mariob | 0:ce6055872f4e | 71 | { 4, 20}, //T_MISSING |
mariob | 0:ce6055872f4e | 72 | { 4, 40}, //ENGINE_LAST_MISSING |
mariob | 0:ce6055872f4e | 73 | { 4, 44} //BODY_LAST_MISSING |
mariob | 0:ce6055872f4e | 74 | }; |
mariob | 0:ce6055872f4e | 75 | |
mariob | 0:ce6055872f4e | 76 | void init_eeprom () |
mariob | 0:ce6055872f4e | 77 | { |
mariob | 0:ce6055872f4e | 78 | eeprom.init(eeprom_data, sizeof(eeprom_data)/sizeof(t_eeprom_data)); |
mariob | 0:ce6055872f4e | 79 | |
mariob | 0:ce6055872f4e | 80 | uint16 sw = 0; |
mariob | 0:ce6055872f4e | 81 | uint16 dd = 0; |
mariob | 0:ce6055872f4e | 82 | uint32 num = 0; |
mariob | 0:ce6055872f4e | 83 | if ((eeprom.read(EEPROM_DATA_SW_VERS, (uint8*)(&sw)) != 2) || |
mariob | 0:ce6055872f4e | 84 | (eeprom.read(EEPROM_DATA_DD_VERS, (uint8*)(&dd)) != 2) || |
mariob | 0:ce6055872f4e | 85 | (sw != SW_VERSION) || (dd != DD_VERSION)) |
mariob | 0:ce6055872f4e | 86 | { |
mariob | 0:ce6055872f4e | 87 | //error |
mariob | 0:ce6055872f4e | 88 | eeprom.reset(); |
mariob | 0:ce6055872f4e | 89 | sw = SW_VERSION; |
mariob | 0:ce6055872f4e | 90 | eeprom.write(EEPROM_DATA_SW_VERS, (uint8*)(&sw)); |
mariob | 0:ce6055872f4e | 91 | dd = DD_VERSION; |
mariob | 0:ce6055872f4e | 92 | eeprom.write(EEPROM_DATA_DD_VERS, (uint8*)(&dd)); |
mariob | 0:ce6055872f4e | 93 | } |
mariob | 0:ce6055872f4e | 94 | |
mariob | 0:ce6055872f4e | 95 | if (eeprom.read(EEPROM_DATA_NSTARTS, (uint8*)(&num)) != 4) |
mariob | 0:ce6055872f4e | 96 | num = 0xffffffff; |
mariob | 0:ce6055872f4e | 97 | num++; |
mariob | 0:ce6055872f4e | 98 | eeprom.write(EEPROM_DATA_NSTARTS, (unsigned char*)(&num)); |
mariob | 0:ce6055872f4e | 99 | } |
mariob | 1:79b1ee0f97ef | 100 | */ |