Sophie Dexter
/
Just4Trionic
Just4Trionic - CAN and BDM FLASH programmer for Saab cars
t7can.cpp@6:2fbcbebed28c, 2016-04-23 (annotated)
- Committer:
- Just4pLeisure
- Date:
- Sat Apr 23 18:31:40 2016 +0000
- Revision:
- 6:2fbcbebed28c
- Parent:
- 5:1775b4b13232
Version 1.6 Faster T7 P-BUS FLASHing algorithm, longer T8 erase timeout fixed BDM register display function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Just4pLeisure | 3:92dae9083c83 | 1 | /******************************************************************************* |
Just4pLeisure | 3:92dae9083c83 | 2 | |
Just4pLeisure | 3:92dae9083c83 | 3 | trionic7.cpp - CAN Bus functions for Just4Trionic by Just4pLeisure |
Just4pLeisure | 4:682d96ff6d79 | 4 | (c) 2011, 2012 by Sophie Dexter |
Just4pLeisure | 3:92dae9083c83 | 5 | |
Just4pLeisure | 3:92dae9083c83 | 6 | This C++ module provides functions for reading and writing the FLASH chips and |
Just4pLeisure | 3:92dae9083c83 | 7 | SRAM in Trionic7 ECUs. (Writing the adaption data back to SRAM not done yet). |
Just4pLeisure | 3:92dae9083c83 | 8 | |
Just4pLeisure | 3:92dae9083c83 | 9 | Some functions need an additional 'bootloader' program to be sent to the T5 ECU |
Just4pLeisure | 3:92dae9083c83 | 10 | before they can be used. These functions are: Identifying the T5 ECU type and |
Just4pLeisure | 3:92dae9083c83 | 11 | FLASH chips, dumping the FLASH chips, erasing the FLASH chips, writing to the |
Just4pLeisure | 3:92dae9083c83 | 12 | FLASH chips and calculating the FLASH chips' checksum. |
Just4pLeisure | 3:92dae9083c83 | 13 | |
Just4pLeisure | 3:92dae9083c83 | 14 | My version of the bootloader, BOOTY.S19, includes some features not in other |
Just4pLeisure | 3:92dae9083c83 | 15 | bootloaders; identifying the ECU and FLASH chip types, a 'safer' way of dumping |
Just4pLeisure | 3:92dae9083c83 | 16 | the FLASH chips and the ability to program AMD 29F010 type FLASH chips |
Just4pLeisure | 3:92dae9083c83 | 17 | |
Just4pLeisure | 3:92dae9083c83 | 18 | ******************************************************************************** |
Just4pLeisure | 3:92dae9083c83 | 19 | |
Just4pLeisure | 3:92dae9083c83 | 20 | WARNING: Use at your own risk, sadly this software comes with no guarantees. |
Just4pLeisure | 3:92dae9083c83 | 21 | This software is provided 'free' and in good faith, but the author does not |
Just4pLeisure | 3:92dae9083c83 | 22 | accept liability for any damage arising from its use. |
Just4pLeisure | 3:92dae9083c83 | 23 | |
Just4pLeisure | 3:92dae9083c83 | 24 | *******************************************************************************/ |
Just4pLeisure | 3:92dae9083c83 | 25 | |
Just4pLeisure | 3:92dae9083c83 | 26 | #include "t7can.h" |
Just4pLeisure | 3:92dae9083c83 | 27 | |
Just4pLeisure | 3:92dae9083c83 | 28 | // constants |
Just4pLeisure | 3:92dae9083c83 | 29 | #define CMD_BUF_LENGTH 32 ///< command buffer size |
Just4pLeisure | 3:92dae9083c83 | 30 | |
Just4pLeisure | 3:92dae9083c83 | 31 | // static variables |
Just4pLeisure | 3:92dae9083c83 | 32 | static char cmd_buffer[CMD_BUF_LENGTH]; ///< command string buffer |
Just4pLeisure | 3:92dae9083c83 | 33 | |
Just4pLeisure | 3:92dae9083c83 | 34 | //static uint32_t cmd_addr; ///< address (optional) |
Just4pLeisure | 3:92dae9083c83 | 35 | //static uint32_t cmd_value; ///< value (optional) |
Just4pLeisure | 3:92dae9083c83 | 36 | //static uint32_t cmd_result; ///< result |
Just4pLeisure | 3:92dae9083c83 | 37 | |
Just4pLeisure | 3:92dae9083c83 | 38 | //static uint32_t flash_start = 0; |
Just4pLeisure | 3:92dae9083c83 | 39 | |
Just4pLeisure | 3:92dae9083c83 | 40 | // private functions |
Just4pLeisure | 3:92dae9083c83 | 41 | uint8_t execute_t7_cmd(); |
Just4pLeisure | 3:92dae9083c83 | 42 | void t7_can_show_help(); |
Just4pLeisure | 3:92dae9083c83 | 43 | void t7_can_show_full_help(); |
Just4pLeisure | 3:92dae9083c83 | 44 | |
Just4pLeisure | 6:2fbcbebed28c | 45 | // private variables |
Just4pLeisure | 6:2fbcbebed28c | 46 | bool ibus = false; |
Just4pLeisure | 6:2fbcbebed28c | 47 | bool pbus = false; |
Just4pLeisure | 6:2fbcbebed28c | 48 | |
Just4pLeisure | 6:2fbcbebed28c | 49 | void t7_can() |
Just4pLeisure | 6:2fbcbebed28c | 50 | { |
Just4pLeisure | 3:92dae9083c83 | 51 | // Start the CAN bus system |
Just4pLeisure | 4:682d96ff6d79 | 52 | // Note that at the moment this is only for T7 ECUs at 500 kbits |
Just4pLeisure | 3:92dae9083c83 | 53 | t7_can_show_help(); |
Just4pLeisure | 3:92dae9083c83 | 54 | |
Just4pLeisure | 4:682d96ff6d79 | 55 | char data[8]; |
Just4pLeisure | 6:2fbcbebed28c | 56 | ibus = false; |
Just4pLeisure | 6:2fbcbebed28c | 57 | pbus = false; |
Just4pLeisure | 4:682d96ff6d79 | 58 | printf("Trying to listen to CAN I-Bus (47619 Bit/s)...\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 59 | can_configure(2, 47619, 1); |
Just4pLeisure | 4:682d96ff6d79 | 60 | if (can_wait_timeout(T7ANYMSG, data, 8, T7MESSAGETIMEOUT)) { |
Just4pLeisure | 4:682d96ff6d79 | 61 | printf("Connected to Saab I-Bus\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 62 | printf("Switching to I-Bus active mode\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 63 | can_configure(2, 47619, 0); |
Just4pLeisure | 6:2fbcbebed28c | 64 | ibus = true; |
Just4pLeisure | 4:682d96ff6d79 | 65 | } else { |
Just4pLeisure | 4:682d96ff6d79 | 66 | printf("I did not receive any I-Bus messages\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 67 | printf("Trying to listen to CAN P-Bus (500 kBit/s)...\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 68 | can_configure(2, 500000, 1); |
Just4pLeisure | 4:682d96ff6d79 | 69 | if (can_wait_timeout(T7ANYMSG, data, 8, T7MESSAGETIMEOUT)) { |
Just4pLeisure | 4:682d96ff6d79 | 70 | printf("Connected to Saab P-Bus\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 71 | printf("Switching to P-Bus active mode\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 72 | can_configure(2, 500000, 0); |
Just4pLeisure | 6:2fbcbebed28c | 73 | pbus = true; |
Just4pLeisure | 4:682d96ff6d79 | 74 | } else { |
Just4pLeisure | 4:682d96ff6d79 | 75 | printf("I did not receive any P-Bus messages\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 76 | printf("Switching to P-Bus active mode\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 77 | can_configure(2, 500000, 0); |
Just4pLeisure | 4:682d96ff6d79 | 78 | if (can_wait_timeout(T7ANYMSG, data, 8, T7CONNECTTIMEOUT)) { |
Just4pLeisure | 4:682d96ff6d79 | 79 | printf("Connected to Saab P-Bus\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 80 | pbus = true; |
Just4pLeisure | 4:682d96ff6d79 | 81 | //can_active(); |
Just4pLeisure | 4:682d96ff6d79 | 82 | } else { |
Just4pLeisure | 4:682d96ff6d79 | 83 | printf("FAILED to connect!\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 84 | led4 = 1; |
Just4pLeisure | 4:682d96ff6d79 | 85 | } |
Just4pLeisure | 4:682d96ff6d79 | 86 | } |
Just4pLeisure | 4:682d96ff6d79 | 87 | } |
Just4pLeisure | 4:682d96ff6d79 | 88 | |
Just4pLeisure | 4:682d96ff6d79 | 89 | // if (t7_initialise()) |
Just4pLeisure | 4:682d96ff6d79 | 90 | // printf("Connected to Saab I-Bus\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 91 | // else { |
Just4pLeisure | 4:682d96ff6d79 | 92 | // printf("Opening CAN channel to Saab P-Bus (500 kBit/s)...\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 93 | // can_set_speed(500000); |
Just4pLeisure | 4:682d96ff6d79 | 94 | // if (t7_initialise()) |
Just4pLeisure | 4:682d96ff6d79 | 95 | // printf("Connected to Saab P-Bus\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 96 | // else { |
Just4pLeisure | 4:682d96ff6d79 | 97 | // printf("FAILED to connect!\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 98 | // led4 = 1; |
Just4pLeisure | 4:682d96ff6d79 | 99 | // } |
Just4pLeisure | 4:682d96ff6d79 | 100 | // } |
Just4pLeisure | 4:682d96ff6d79 | 101 | |
Just4pLeisure | 4:682d96ff6d79 | 102 | // if (t7_initialise()) |
Just4pLeisure | 4:682d96ff6d79 | 103 | // printf("Trionic 7 Connection OK\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 104 | // else |
Just4pLeisure | 4:682d96ff6d79 | 105 | // printf("Trionic 7 Connection Failed\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 106 | // t7_authenticate(); |
Just4pLeisure | 4:682d96ff6d79 | 107 | // if (t7_authenticate()) |
Just4pLeisure | 4:682d96ff6d79 | 108 | // printf("Security Key Accepted\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 109 | // else |
Just4pLeisure | 4:682d96ff6d79 | 110 | // printf("Security Key Failed\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 111 | |
Just4pLeisure | 4:682d96ff6d79 | 112 | // main loop |
Just4pLeisure | 3:92dae9083c83 | 113 | *cmd_buffer = '\0'; |
Just4pLeisure | 3:92dae9083c83 | 114 | char ret; |
Just4pLeisure | 3:92dae9083c83 | 115 | char rx_char; |
Just4pLeisure | 3:92dae9083c83 | 116 | while (true) { |
Just4pLeisure | 3:92dae9083c83 | 117 | // read chars from USB |
Just4pLeisure | 3:92dae9083c83 | 118 | // send received messages to the pc over USB connection |
Just4pLeisure | 3:92dae9083c83 | 119 | // This function displays any CAN messages that are 'missed' by the other functions |
Just4pLeisure | 3:92dae9083c83 | 120 | // Can messages might be 'missed' because they are received after a 'timeout' period |
Just4pLeisure | 3:92dae9083c83 | 121 | // or because they weren't expected, e.g. if the T5 ECU resets for some reason |
Just4pLeisure | 3:92dae9083c83 | 122 | // t7_show_can_message(); |
Just4pLeisure | 3:92dae9083c83 | 123 | silent_can_message(); |
Just4pLeisure | 3:92dae9083c83 | 124 | if (pc.readable()) { |
Just4pLeisure | 3:92dae9083c83 | 125 | // turn Error LED off for next command |
Just4pLeisure | 3:92dae9083c83 | 126 | led4 = 0; |
Just4pLeisure | 3:92dae9083c83 | 127 | rx_char = pc.getc(); |
Just4pLeisure | 3:92dae9083c83 | 128 | switch (rx_char) { |
Just4pLeisure | 3:92dae9083c83 | 129 | // 'ESC' key to go back to mbed Just4Trionic 'home' menu |
Just4pLeisure | 3:92dae9083c83 | 130 | case '\e': |
Just4pLeisure | 3:92dae9083c83 | 131 | can_close(); |
Just4pLeisure | 3:92dae9083c83 | 132 | return; |
Just4pLeisure | 3:92dae9083c83 | 133 | // end-of-command reached |
Just4pLeisure | 3:92dae9083c83 | 134 | case TERM_OK : |
Just4pLeisure | 3:92dae9083c83 | 135 | // execute command and return flag via USB |
Just4pLeisure | 3:92dae9083c83 | 136 | timer.reset(); |
Just4pLeisure | 3:92dae9083c83 | 137 | timer.start(); |
Just4pLeisure | 3:92dae9083c83 | 138 | ret = execute_t7_cmd(); |
Just4pLeisure | 3:92dae9083c83 | 139 | pc.putc(ret); |
Just4pLeisure | 3:92dae9083c83 | 140 | printf("Completed in %.3f seconds.\r\n", timer.read()); |
Just4pLeisure | 3:92dae9083c83 | 141 | // reset command buffer |
Just4pLeisure | 3:92dae9083c83 | 142 | *cmd_buffer = '\0'; |
Just4pLeisure | 3:92dae9083c83 | 143 | // light up LED |
Just4pLeisure | 3:92dae9083c83 | 144 | // ret == TERM_OK ? led_on(LED_ACT) : led_on(LED_ERR); |
Just4pLeisure | 3:92dae9083c83 | 145 | ret == TERM_OK ? led3 = 1 : led4 = 1; |
Just4pLeisure | 3:92dae9083c83 | 146 | break; |
Just4pLeisure | 3:92dae9083c83 | 147 | // another command char |
Just4pLeisure | 3:92dae9083c83 | 148 | default: |
Just4pLeisure | 3:92dae9083c83 | 149 | // store in buffer if space permits |
Just4pLeisure | 3:92dae9083c83 | 150 | if (StrLen(cmd_buffer) < CMD_BUF_LENGTH - 1) { |
Just4pLeisure | 3:92dae9083c83 | 151 | StrAddc(cmd_buffer, rx_char); |
Just4pLeisure | 3:92dae9083c83 | 152 | } |
Just4pLeisure | 3:92dae9083c83 | 153 | break; |
Just4pLeisure | 3:92dae9083c83 | 154 | } |
Just4pLeisure | 3:92dae9083c83 | 155 | } |
Just4pLeisure | 3:92dae9083c83 | 156 | } |
Just4pLeisure | 3:92dae9083c83 | 157 | } |
Just4pLeisure | 3:92dae9083c83 | 158 | |
Just4pLeisure | 3:92dae9083c83 | 159 | //----------------------------------------------------------------------------- |
Just4pLeisure | 3:92dae9083c83 | 160 | /** |
Just4pLeisure | 3:92dae9083c83 | 161 | Executes a command and returns result flag (does not transmit the flag |
Just4pLeisure | 3:92dae9083c83 | 162 | itself). |
Just4pLeisure | 3:92dae9083c83 | 163 | |
Just4pLeisure | 3:92dae9083c83 | 164 | @return command flag (success / failure) |
Just4pLeisure | 3:92dae9083c83 | 165 | */ |
Just4pLeisure | 6:2fbcbebed28c | 166 | uint8_t execute_t7_cmd() |
Just4pLeisure | 6:2fbcbebed28c | 167 | { |
Just4pLeisure | 3:92dae9083c83 | 168 | |
Just4pLeisure | 3:92dae9083c83 | 169 | // uint8_t cmd_length = strlen(cmd_buffer); |
Just4pLeisure | 3:92dae9083c83 | 170 | // command groups |
Just4pLeisure | 3:92dae9083c83 | 171 | switch (*cmd_buffer) { |
Just4pLeisure | 3:92dae9083c83 | 172 | // CHECK_ARGLENGTH(0); |
Just4pLeisure | 6:2fbcbebed28c | 173 | // Initialise a T7 CAN session |
Just4pLeisure | 3:92dae9083c83 | 174 | case 'i' : |
Just4pLeisure | 4:682d96ff6d79 | 175 | if (t7_initialise()) { |
Just4pLeisure | 6:2fbcbebed28c | 176 | printf("SUCCESS! Trionic 7 CAN Connection OK.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 177 | return TERM_OK; |
Just4pLeisure | 4:682d96ff6d79 | 178 | } else { |
Just4pLeisure | 6:2fbcbebed28c | 179 | printf("FAILURE! No CAN connection to Trionic 7.\\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 180 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 181 | } |
Just4pLeisure | 6:2fbcbebed28c | 182 | // Get security clearance for T7 CAN session |
Just4pLeisure | 3:92dae9083c83 | 183 | case 'a' : |
Just4pLeisure | 4:682d96ff6d79 | 184 | if (t7_authenticate()) { |
Just4pLeisure | 6:2fbcbebed28c | 185 | printf("SUCCESS! Security Key Accepted.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 186 | return TERM_OK; |
Just4pLeisure | 4:682d96ff6d79 | 187 | } else { |
Just4pLeisure | 6:2fbcbebed28c | 188 | printf("FAILURE! Unable to obtain a Security Key.\\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 189 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 190 | } |
Just4pLeisure | 6:2fbcbebed28c | 191 | // Erase the FLASH chips |
Just4pLeisure | 3:92dae9083c83 | 192 | case 'e': |
Just4pLeisure | 3:92dae9083c83 | 193 | return t7_erase() |
Just4pLeisure | 3:92dae9083c83 | 194 | ? TERM_OK : TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 195 | // DUMP the T5 ECU BIN file stored in the FLASH chips |
Just4pLeisure | 4:682d96ff6d79 | 196 | case 'D': |
Just4pLeisure | 4:682d96ff6d79 | 197 | if (!t7_authenticate()) { |
Just4pLeisure | 4:682d96ff6d79 | 198 | if (!t7_initialise()) { |
Just4pLeisure | 6:2fbcbebed28c | 199 | printf("FAILURE! No CAN connection to Trionic 7.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 200 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 201 | } |
Just4pLeisure | 4:682d96ff6d79 | 202 | if (!t7_authenticate()) { |
Just4pLeisure | 6:2fbcbebed28c | 203 | printf("FAILURE! Unable to obtain a Security Key.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 204 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 205 | } |
Just4pLeisure | 4:682d96ff6d79 | 206 | } |
Just4pLeisure | 3:92dae9083c83 | 207 | case 'd': |
Just4pLeisure | 6:2fbcbebed28c | 208 | return t7_dump(pbus) |
Just4pLeisure | 3:92dae9083c83 | 209 | ? TERM_OK : TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 210 | // Send a FLASH update file to the T5 ECU |
Just4pLeisure | 6:2fbcbebed28c | 211 | case 'F': { |
Just4pLeisure | 6:2fbcbebed28c | 212 | FILE *fp = t7_file_open("/local/modified.bin"); // Open "modified.bin" on the local file system |
Just4pLeisure | 6:2fbcbebed28c | 213 | if (!fp) { |
Just4pLeisure | 6:2fbcbebed28c | 214 | printf("FAILURE! Unable to find the BIN file \"MODIFIED.BIN\"\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 215 | return TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 216 | } |
Just4pLeisure | 4:682d96ff6d79 | 217 | if (!t7_authenticate()) { |
Just4pLeisure | 4:682d96ff6d79 | 218 | if (!t7_initialise()) { |
Just4pLeisure | 6:2fbcbebed28c | 219 | printf("FAILURE! No CAN connection to Trionic 7.\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 220 | fclose(fp); |
Just4pLeisure | 4:682d96ff6d79 | 221 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 222 | } |
Just4pLeisure | 4:682d96ff6d79 | 223 | if (!t7_authenticate()) { |
Just4pLeisure | 6:2fbcbebed28c | 224 | printf("FAILURE! Unable to obtain a Security Key.\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 225 | fclose(fp); |
Just4pLeisure | 4:682d96ff6d79 | 226 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 227 | } |
Just4pLeisure | 4:682d96ff6d79 | 228 | } |
Just4pLeisure | 4:682d96ff6d79 | 229 | if (!t7_erase()) { |
Just4pLeisure | 6:2fbcbebed28c | 230 | printf("FAILURE: Unable to Erase FLASH!\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 231 | fclose(fp); |
Just4pLeisure | 6:2fbcbebed28c | 232 | return TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 233 | } |
Just4pLeisure | 6:2fbcbebed28c | 234 | bool result = t7_flash(fp, pbus); |
Just4pLeisure | 6:2fbcbebed28c | 235 | fclose(fp); |
Just4pLeisure | 6:2fbcbebed28c | 236 | return result ? TERM_OK : TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 237 | } |
Just4pLeisure | 6:2fbcbebed28c | 238 | case 'f': { |
Just4pLeisure | 6:2fbcbebed28c | 239 | FILE *fp = t7_file_open("/local/modified.bin"); // Open "modified.bin" on the local file system |
Just4pLeisure | 6:2fbcbebed28c | 240 | if (!fp) { |
Just4pLeisure | 6:2fbcbebed28c | 241 | printf("FAILURE! Unable to find the BIN file \"MODIFIED.BIN\"\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 242 | return TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 243 | } |
Just4pLeisure | 6:2fbcbebed28c | 244 | bool result = t7_flash(fp, pbus); |
Just4pLeisure | 6:2fbcbebed28c | 245 | fclose(fp); |
Just4pLeisure | 6:2fbcbebed28c | 246 | return result ? TERM_OK : TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 247 | } |
Just4pLeisure | 6:2fbcbebed28c | 248 | // Recovery FLASHes the entire BIN file and using 'safe' but slow 4 byte at a time transfers |
Just4pLeisure | 6:2fbcbebed28c | 249 | case 'R': { |
Just4pLeisure | 6:2fbcbebed28c | 250 | FILE *fp = t7_file_open("/local/modified.bin"); // Open "modified.bin" on the local file system |
Just4pLeisure | 6:2fbcbebed28c | 251 | if (!fp) { |
Just4pLeisure | 6:2fbcbebed28c | 252 | printf("FAILURE! Unable to find the BIN file \"MODIFIED.BIN\"\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 253 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 254 | } |
Just4pLeisure | 6:2fbcbebed28c | 255 | if (!t7_authenticate()) { |
Just4pLeisure | 6:2fbcbebed28c | 256 | if (!t7_initialise()) { |
Just4pLeisure | 6:2fbcbebed28c | 257 | printf("FAILURE! No CAN connection to Trionic 7.\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 258 | fclose(fp); |
Just4pLeisure | 6:2fbcbebed28c | 259 | return TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 260 | } |
Just4pLeisure | 6:2fbcbebed28c | 261 | if (!t7_authenticate()) { |
Just4pLeisure | 6:2fbcbebed28c | 262 | printf("FAILURE! Unable to obtain a Security Key.\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 263 | fclose(fp); |
Just4pLeisure | 6:2fbcbebed28c | 264 | return TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 265 | } |
Just4pLeisure | 6:2fbcbebed28c | 266 | } |
Just4pLeisure | 6:2fbcbebed28c | 267 | if (!t7_erase()) { |
Just4pLeisure | 6:2fbcbebed28c | 268 | printf("FAILURE: Unable to Erase FLASH!\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 269 | fclose(fp); |
Just4pLeisure | 6:2fbcbebed28c | 270 | return TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 271 | } |
Just4pLeisure | 6:2fbcbebed28c | 272 | bool result = t7_recover(fp); |
Just4pLeisure | 6:2fbcbebed28c | 273 | fclose(fp); |
Just4pLeisure | 6:2fbcbebed28c | 274 | return result ? TERM_OK : TERM_ERR; |
Just4pLeisure | 6:2fbcbebed28c | 275 | } |
Just4pLeisure | 4:682d96ff6d79 | 276 | // Try to connect to CAN I-BUS |
Just4pLeisure | 6:2fbcbebed28c | 277 | case 'I' : { |
Just4pLeisure | 6:2fbcbebed28c | 278 | char data[8]; |
Just4pLeisure | 4:682d96ff6d79 | 279 | printf("Trying to open CAN I-Bus (47619 Bit/s)...\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 280 | ibus = true; |
Just4pLeisure | 6:2fbcbebed28c | 281 | pbus = false; |
Just4pLeisure | 4:682d96ff6d79 | 282 | can_close(); |
Just4pLeisure | 4:682d96ff6d79 | 283 | //can_monitor(); |
Just4pLeisure | 4:682d96ff6d79 | 284 | can_set_speed(47619); |
Just4pLeisure | 4:682d96ff6d79 | 285 | can_open(); |
Just4pLeisure | 4:682d96ff6d79 | 286 | if (can_wait_timeout(T7ANYMSG, data, 8, T7CONNECTTIMEOUT)) { |
Just4pLeisure | 6:2fbcbebed28c | 287 | printf("SUCCESS! Connected to Saab I-Bus.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 288 | //can_active(); |
Just4pLeisure | 4:682d96ff6d79 | 289 | return TERM_OK; |
Just4pLeisure | 4:682d96ff6d79 | 290 | } else { |
Just4pLeisure | 4:682d96ff6d79 | 291 | printf("I did not receive any I-Bus messages\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 292 | printf("FAILURE! Unable to connect Saab I-Bus.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 293 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 294 | } |
Just4pLeisure | 6:2fbcbebed28c | 295 | } |
Just4pLeisure | 4:682d96ff6d79 | 296 | // Try to connect to CAN P-BUS |
Just4pLeisure | 6:2fbcbebed28c | 297 | case 'P' : { |
Just4pLeisure | 6:2fbcbebed28c | 298 | char data[8]; |
Just4pLeisure | 4:682d96ff6d79 | 299 | printf("Trying to open CAN P-Bus (500 kBit/s)...\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 300 | ibus = false; |
Just4pLeisure | 6:2fbcbebed28c | 301 | pbus = true; |
Just4pLeisure | 4:682d96ff6d79 | 302 | can_close(); |
Just4pLeisure | 4:682d96ff6d79 | 303 | //can_monitor(); |
Just4pLeisure | 4:682d96ff6d79 | 304 | can_set_speed(500000); |
Just4pLeisure | 4:682d96ff6d79 | 305 | can_open(); |
Just4pLeisure | 4:682d96ff6d79 | 306 | if (can_wait_timeout(T7ANYMSG, data, 8, T7CONNECTTIMEOUT)) { |
Just4pLeisure | 6:2fbcbebed28c | 307 | printf("SUCCESS! Connected to Saab P-Bus.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 308 | //can_active(); |
Just4pLeisure | 4:682d96ff6d79 | 309 | return TERM_OK; |
Just4pLeisure | 4:682d96ff6d79 | 310 | } else { |
Just4pLeisure | 4:682d96ff6d79 | 311 | printf("I did not receive any P-Bus messages\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 312 | printf("FAILURE! Unable to connect Saab P-Bus.\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 313 | return TERM_ERR; |
Just4pLeisure | 4:682d96ff6d79 | 314 | } |
Just4pLeisure | 6:2fbcbebed28c | 315 | } |
Just4pLeisure | 4:682d96ff6d79 | 316 | // Print help |
Just4pLeisure | 3:92dae9083c83 | 317 | case 'h': |
Just4pLeisure | 3:92dae9083c83 | 318 | t7_can_show_help(); |
Just4pLeisure | 3:92dae9083c83 | 319 | return TERM_OK; |
Just4pLeisure | 3:92dae9083c83 | 320 | case 'H': |
Just4pLeisure | 3:92dae9083c83 | 321 | t7_can_show_full_help(); |
Just4pLeisure | 3:92dae9083c83 | 322 | return TERM_OK; |
Just4pLeisure | 3:92dae9083c83 | 323 | default: |
Just4pLeisure | 3:92dae9083c83 | 324 | t7_can_show_help(); |
Just4pLeisure | 3:92dae9083c83 | 325 | break; |
Just4pLeisure | 3:92dae9083c83 | 326 | } |
Just4pLeisure | 4:682d96ff6d79 | 327 | // unknown command |
Just4pLeisure | 3:92dae9083c83 | 328 | return TERM_ERR; |
Just4pLeisure | 3:92dae9083c83 | 329 | } |
Just4pLeisure | 3:92dae9083c83 | 330 | |
Just4pLeisure | 3:92dae9083c83 | 331 | // |
Just4pLeisure | 3:92dae9083c83 | 332 | // Trionic7ShowHelp |
Just4pLeisure | 3:92dae9083c83 | 333 | // |
Just4pLeisure | 3:92dae9083c83 | 334 | // Displays a list of things that can be done with the T5 ECU. |
Just4pLeisure | 3:92dae9083c83 | 335 | // |
Just4pLeisure | 3:92dae9083c83 | 336 | // inputs: none |
Just4pLeisure | 3:92dae9083c83 | 337 | // return: none |
Just4pLeisure | 3:92dae9083c83 | 338 | // |
Just4pLeisure | 6:2fbcbebed28c | 339 | void t7_can_show_help() |
Just4pLeisure | 6:2fbcbebed28c | 340 | { |
Just4pLeisure | 3:92dae9083c83 | 341 | printf("Trionic 7 Command Menu\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 342 | printf("======================\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 343 | printf("D - DUMP the T7 ECU FLASH to a file 'ORIGINAL.BIN'\r\n"); |
Just4pLeisure | 5:1775b4b13232 | 344 | printf("F - FLASH the update file 'MODIFIED.BIN' to the T7\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 345 | printf("R - Recovery FLASH T7 with update file 'MODIFIED.BIN'\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 346 | printf("\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 347 | printf("I - Try to open CAN I-Bus (47619 Bit/s)\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 348 | printf("P - Try to open CAN P-Bus (500 kBit/s)\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 349 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 350 | printf("'ESC' - Return to Just4Trionic Main Menu\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 351 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 352 | printf("h - Show this help menu\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 353 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 354 | return; |
Just4pLeisure | 3:92dae9083c83 | 355 | } |
Just4pLeisure | 3:92dae9083c83 | 356 | // |
Just4pLeisure | 3:92dae9083c83 | 357 | // t7_can_show_full_help |
Just4pLeisure | 3:92dae9083c83 | 358 | // |
Just4pLeisure | 3:92dae9083c83 | 359 | // Displays a complete list of things that can be done with the T5 ECU. |
Just4pLeisure | 3:92dae9083c83 | 360 | // |
Just4pLeisure | 3:92dae9083c83 | 361 | // inputs: none |
Just4pLeisure | 3:92dae9083c83 | 362 | // return: none |
Just4pLeisure | 3:92dae9083c83 | 363 | // |
Just4pLeisure | 6:2fbcbebed28c | 364 | void t7_can_show_full_help() |
Just4pLeisure | 6:2fbcbebed28c | 365 | { |
Just4pLeisure | 3:92dae9083c83 | 366 | printf("Trionic 7 Command Menu\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 367 | printf("======================\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 368 | printf("D - DUMP the T7 ECU FLASH to a file 'ORIGINAL.BIN'\r\n"); |
Just4pLeisure | 5:1775b4b13232 | 369 | printf("F - FLASH the update file 'MODIFIED.BIN' to the T7\r\n"); |
Just4pLeisure | 6:2fbcbebed28c | 370 | printf("R - Recovery FLASH T7 with update file 'MODIFIED.BIN'\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 371 | printf("\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 372 | printf("I - Try to open CAN I-Bus (47619 Bit/s)\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 373 | printf("P - Try to open CAN P-Bus (500 kBit/s)\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 374 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 375 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 376 | printf("i - Send initialisation message to T7\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 377 | printf("a - Send Authentication key to T7\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 378 | printf("d - Dump T7 Bin file 'ORIGINAL.BIN'\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 379 | printf("e - Erase the FLASH in the T7 ECU\r\n"); |
Just4pLeisure | 4:682d96ff6d79 | 380 | printf("f - FLASH the file 'MODIFIED.BIN' to the T7 ECU\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 381 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 382 | printf("'ESC' - Return to Just4Trionic Main Menu\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 383 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 384 | printf("H - Show this help menu\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 385 | printf("\r\n"); |
Just4pLeisure | 3:92dae9083c83 | 386 | return; |
Just4pLeisure | 3:92dae9083c83 | 387 | } |
Just4pLeisure | 3:92dae9083c83 | 388 | |
Just4pLeisure | 3:92dae9083c83 | 389 |