Sophie Dexter
/
Just4Trionic
Just4Trionic - CAN and BDM FLASH programmer for Saab cars
T5Utils.cpp@0:e0b964252a05, 2010-05-19 (annotated)
- Committer:
- Just4pLeisure
- Date:
- Wed May 19 12:39:18 2010 +0000
- Revision:
- 0:e0b964252a05
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Just4pLeisure | 0:e0b964252a05 | 1 | /******************************************************************************* |
Just4pLeisure | 0:e0b964252a05 | 2 | |
Just4pLeisure | 0:e0b964252a05 | 3 | T5Utils.cpp - By Sophie Dexter, April 2010 |
Just4pLeisure | 0:e0b964252a05 | 4 | |
Just4pLeisure | 0:e0b964252a05 | 5 | This C++ module provides functions for communicating simple messages to and from |
Just4pLeisure | 0:e0b964252a05 | 6 | the T5 ECU |
Just4pLeisure | 0:e0b964252a05 | 7 | |
Just4pLeisure | 0:e0b964252a05 | 8 | ******************************************************************************** |
Just4pLeisure | 0:e0b964252a05 | 9 | |
Just4pLeisure | 0:e0b964252a05 | 10 | WARNING: Use at your own risk, sadly this software comes with no guarantees. |
Just4pLeisure | 0:e0b964252a05 | 11 | This software is provided 'free' and in good faith, but the author does not |
Just4pLeisure | 0:e0b964252a05 | 12 | accept liability for any damage arising from its use. |
Just4pLeisure | 0:e0b964252a05 | 13 | |
Just4pLeisure | 0:e0b964252a05 | 14 | *******************************************************************************/ |
Just4pLeisure | 0:e0b964252a05 | 15 | |
Just4pLeisure | 0:e0b964252a05 | 16 | #include "T5Utils.h" |
Just4pLeisure | 0:e0b964252a05 | 17 | |
Just4pLeisure | 0:e0b964252a05 | 18 | // |
Just4pLeisure | 0:e0b964252a05 | 19 | // T5Open enables the CAN chip and sets the CAN speed to 615 kbits. |
Just4pLeisure | 0:e0b964252a05 | 20 | // |
Just4pLeisure | 0:e0b964252a05 | 21 | // This function is a 'quick fix' for now. |
Just4pLeisure | 0:e0b964252a05 | 22 | // |
Just4pLeisure | 0:e0b964252a05 | 23 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 24 | // return: bool TRUE if all went OK, |
Just4pLeisure | 0:e0b964252a05 | 25 | // |
Just4pLeisure | 0:e0b964252a05 | 26 | bool T5Open() { |
Just4pLeisure | 0:e0b964252a05 | 27 | CANOpen (); |
Just4pLeisure | 0:e0b964252a05 | 28 | return TRUE; |
Just4pLeisure | 0:e0b964252a05 | 29 | } |
Just4pLeisure | 0:e0b964252a05 | 30 | |
Just4pLeisure | 0:e0b964252a05 | 31 | // |
Just4pLeisure | 0:e0b964252a05 | 32 | // T5Close disables the CAN chip. |
Just4pLeisure | 0:e0b964252a05 | 33 | // |
Just4pLeisure | 0:e0b964252a05 | 34 | // This function is a 'quick fix' for now. |
Just4pLeisure | 0:e0b964252a05 | 35 | // |
Just4pLeisure | 0:e0b964252a05 | 36 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 37 | // return: bool TRUE if all went OK, |
Just4pLeisure | 0:e0b964252a05 | 38 | // |
Just4pLeisure | 0:e0b964252a05 | 39 | bool T5Close() { |
Just4pLeisure | 0:e0b964252a05 | 40 | CANClose (); |
Just4pLeisure | 0:e0b964252a05 | 41 | return TRUE; |
Just4pLeisure | 0:e0b964252a05 | 42 | } |
Just4pLeisure | 0:e0b964252a05 | 43 | |
Just4pLeisure | 0:e0b964252a05 | 44 | // |
Just4pLeisure | 0:e0b964252a05 | 45 | // T5WaitResponse |
Just4pLeisure | 0:e0b964252a05 | 46 | // |
Just4pLeisure | 0:e0b964252a05 | 47 | // Waits for a response message with the correct message id from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 48 | // The response is a single ascii character from the symboltable. |
Just4pLeisure | 0:e0b964252a05 | 49 | // |
Just4pLeisure | 0:e0b964252a05 | 50 | // Returns an error ('BELL' character) if: |
Just4pLeisure | 0:e0b964252a05 | 51 | // a response is not received before the timeout |
Just4pLeisure | 0:e0b964252a05 | 52 | // the message length is less than 8 bytes (all messages should be 8 bytes) |
Just4pLeisure | 0:e0b964252a05 | 53 | // the message type is incorrect |
Just4pLeisure | 0:e0b964252a05 | 54 | // |
Just4pLeisure | 0:e0b964252a05 | 55 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 56 | // return: a single char that is the response from the T5 ECU |
Just4pLeisure | 0:e0b964252a05 | 57 | // |
Just4pLeisure | 0:e0b964252a05 | 58 | char T5WaitResponse() { |
Just4pLeisure | 0:e0b964252a05 | 59 | char T5RxMsg[8]; |
Just4pLeisure | 0:e0b964252a05 | 60 | if (!CANWaitTimeout(RESPID, T5RxMsg, 8, T5MESSAGETIMEOUT)) return '\a'; |
Just4pLeisure | 0:e0b964252a05 | 61 | if (T5RxMsg[0] != 0xC6) return '\a'; |
Just4pLeisure | 0:e0b964252a05 | 62 | return T5RxMsg[2]; |
Just4pLeisure | 0:e0b964252a05 | 63 | } |
Just4pLeisure | 0:e0b964252a05 | 64 | |
Just4pLeisure | 0:e0b964252a05 | 65 | // |
Just4pLeisure | 0:e0b964252a05 | 66 | // |
Just4pLeisure | 0:e0b964252a05 | 67 | // T5WaitResponsePrint |
Just4pLeisure | 0:e0b964252a05 | 68 | // |
Just4pLeisure | 0:e0b964252a05 | 69 | // Waits for a response message with the correct message id from the T5 ECU and displays the whole message: |
Just4pLeisure | 0:e0b964252a05 | 70 | // |
Just4pLeisure | 0:e0b964252a05 | 71 | // wiiildddddddddddddddd |
Just4pLeisure | 0:e0b964252a05 | 72 | // iii - is the CAN message id |
Just4pLeisure | 0:e0b964252a05 | 73 | // l - is the message length, should always be 8 for T5 messages |
Just4pLeisure | 0:e0b964252a05 | 74 | // dd,dd,dd,dd,dd,dd,dd,dd are the CAN message data bytes |
Just4pLeisure | 0:e0b964252a05 | 75 | // |
Just4pLeisure | 0:e0b964252a05 | 76 | // Returns an error if: |
Just4pLeisure | 0:e0b964252a05 | 77 | // a response is not received before the timeout |
Just4pLeisure | 0:e0b964252a05 | 78 | // the message length is less than 8 bytes (all messages should be 8 bytes) |
Just4pLeisure | 0:e0b964252a05 | 79 | // the message type is incorrect |
Just4pLeisure | 0:e0b964252a05 | 80 | // |
Just4pLeisure | 0:e0b964252a05 | 81 | // Inputs: none |
Just4pLeisure | 0:e0b964252a05 | 82 | // return: bool TRUE if a qualifying message was received |
Just4pLeisure | 0:e0b964252a05 | 83 | // FALSE if a message wasn't received in time, had the wrong id etc... |
Just4pLeisure | 0:e0b964252a05 | 84 | // |
Just4pLeisure | 0:e0b964252a05 | 85 | bool T5WaitResponsePrint() { |
Just4pLeisure | 0:e0b964252a05 | 86 | char T5RxMsg[8]; |
Just4pLeisure | 0:e0b964252a05 | 87 | if (!CANWaitTimeout(RESPID, T5RxMsg, 8, T5CHECKSUMTIMEOUT)) return FALSE; |
Just4pLeisure | 0:e0b964252a05 | 88 | printf("w%03x8", RESPID); |
Just4pLeisure | 0:e0b964252a05 | 89 | for (char i=0; i<8; i++) { |
Just4pLeisure | 0:e0b964252a05 | 90 | printf("%02x", T5RxMsg[i]); |
Just4pLeisure | 0:e0b964252a05 | 91 | } |
Just4pLeisure | 0:e0b964252a05 | 92 | printf("\n\r"); |
Just4pLeisure | 0:e0b964252a05 | 93 | return TRUE; |
Just4pLeisure | 0:e0b964252a05 | 94 | } |
Just4pLeisure | 0:e0b964252a05 | 95 | |
Just4pLeisure | 0:e0b964252a05 | 96 | // T5GetSymbol |
Just4pLeisure | 0:e0b964252a05 | 97 | // |
Just4pLeisure | 0:e0b964252a05 | 98 | // Reads a single symbol name (in the symbol table) from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 99 | // T5GetSymbol sends ACK messages to the T5 ECU and stores the |
Just4pLeisure | 0:e0b964252a05 | 100 | // reply characters in a string until a '\n' character is received |
Just4pLeisure | 0:e0b964252a05 | 101 | // when the function returns with the pointer to that string. |
Just4pLeisure | 0:e0b964252a05 | 102 | // |
Just4pLeisure | 0:e0b964252a05 | 103 | // inputs: a pointer to the string used to store the symbol name. |
Just4pLeisure | 0:e0b964252a05 | 104 | // return: a pointer to the string used to store the symbol name. |
Just4pLeisure | 0:e0b964252a05 | 105 | // |
Just4pLeisure | 0:e0b964252a05 | 106 | char *T5GetSymbol(char *s) { |
Just4pLeisure | 0:e0b964252a05 | 107 | do { |
Just4pLeisure | 0:e0b964252a05 | 108 | if (T5Ack()) { |
Just4pLeisure | 0:e0b964252a05 | 109 | } |
Just4pLeisure | 0:e0b964252a05 | 110 | *s = T5WaitResponse(); |
Just4pLeisure | 0:e0b964252a05 | 111 | } while (*s++ != '\n'); |
Just4pLeisure | 0:e0b964252a05 | 112 | *s = '\0'; |
Just4pLeisure | 0:e0b964252a05 | 113 | return s; |
Just4pLeisure | 0:e0b964252a05 | 114 | } |
Just4pLeisure | 0:e0b964252a05 | 115 | |
Just4pLeisure | 0:e0b964252a05 | 116 | // T5ReadCmnd |
Just4pLeisure | 0:e0b964252a05 | 117 | // |
Just4pLeisure | 0:e0b964252a05 | 118 | // Sends a 'read' type command to the T5 ECU. 'read' commands are used to read something from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 119 | // |
Just4pLeisure | 0:e0b964252a05 | 120 | // inputs: a 'char' which is the type of 'read' requested (e.g. symbol table, version etc). |
Just4pLeisure | 0:e0b964252a05 | 121 | // return: bool TRUE if the message was sent within the timeout period, |
Just4pLeisure | 0:e0b964252a05 | 122 | // FALSE if the message couldn't be sent. |
Just4pLeisure | 0:e0b964252a05 | 123 | // |
Just4pLeisure | 0:e0b964252a05 | 124 | bool T5ReadCmnd(char c) { |
Just4pLeisure | 0:e0b964252a05 | 125 | char T5TxMsg[] = T5_RDCMND; |
Just4pLeisure | 0:e0b964252a05 | 126 | T5TxMsg[1] = c; |
Just4pLeisure | 0:e0b964252a05 | 127 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 128 | } |
Just4pLeisure | 0:e0b964252a05 | 129 | |
Just4pLeisure | 0:e0b964252a05 | 130 | // |
Just4pLeisure | 0:e0b964252a05 | 131 | // T5WriteCmnd is unfinished |
Just4pLeisure | 0:e0b964252a05 | 132 | // |
Just4pLeisure | 0:e0b964252a05 | 133 | bool T5WriteCmnd(unsigned int addr, char data) { |
Just4pLeisure | 0:e0b964252a05 | 134 | return FALSE; |
Just4pLeisure | 0:e0b964252a05 | 135 | } |
Just4pLeisure | 0:e0b964252a05 | 136 | |
Just4pLeisure | 0:e0b964252a05 | 137 | // T5ReadRAM |
Just4pLeisure | 0:e0b964252a05 | 138 | // |
Just4pLeisure | 0:e0b964252a05 | 139 | // Reads 6 bytes of the adaption data from the SRAM in the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 140 | // |
Just4pLeisure | 0:e0b964252a05 | 141 | // inputs: a pointer to an array of 6 bytes for storing the data read from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 142 | // the address to read SRAM data from in the T5 ECU |
Just4pLeisure | 0:e0b964252a05 | 143 | // return: a pointer to an array of 6 bytes for storing the data read from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 144 | // |
Just4pLeisure | 0:e0b964252a05 | 145 | char *T5ReadRAM(char *data, unsigned int addr) { |
Just4pLeisure | 0:e0b964252a05 | 146 | T5RAMCmnd(addr); |
Just4pLeisure | 0:e0b964252a05 | 147 | T5WaitRAM(data); |
Just4pLeisure | 0:e0b964252a05 | 148 | return data; |
Just4pLeisure | 0:e0b964252a05 | 149 | } |
Just4pLeisure | 0:e0b964252a05 | 150 | |
Just4pLeisure | 0:e0b964252a05 | 151 | // T5ReadFLASH |
Just4pLeisure | 0:e0b964252a05 | 152 | // |
Just4pLeisure | 0:e0b964252a05 | 153 | // Reads 6 bytes of the FLASH in the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 154 | // |
Just4pLeisure | 0:e0b964252a05 | 155 | // inputs: a pointer to an array of 6 bytes for storing the data read from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 156 | // the address to read SRAM data from in the T5 ECU |
Just4pLeisure | 0:e0b964252a05 | 157 | // return: a pointer to an array of 6 bytes for storing the data read from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 158 | // |
Just4pLeisure | 0:e0b964252a05 | 159 | char *T5ReadFLASH(char *data, unsigned int addr) { |
Just4pLeisure | 0:e0b964252a05 | 160 | T5RAMCmnd(addr); |
Just4pLeisure | 0:e0b964252a05 | 161 | T5WaitRAM(data); |
Just4pLeisure | 0:e0b964252a05 | 162 | return data; |
Just4pLeisure | 0:e0b964252a05 | 163 | } |
Just4pLeisure | 0:e0b964252a05 | 164 | |
Just4pLeisure | 0:e0b964252a05 | 165 | // |
Just4pLeisure | 0:e0b964252a05 | 166 | // T5RAMCmnd |
Just4pLeisure | 0:e0b964252a05 | 167 | // |
Just4pLeisure | 0:e0b964252a05 | 168 | // Sends a command to the ECU asking the T5 ECU to send some SRAM data |
Just4pLeisure | 0:e0b964252a05 | 169 | // |
Just4pLeisure | 0:e0b964252a05 | 170 | // inputs: the address to read SRAM data from in the T5 ECU |
Just4pLeisure | 0:e0b964252a05 | 171 | // return: bool TRUE if the message was sent within the timeout period, |
Just4pLeisure | 0:e0b964252a05 | 172 | // FALSE if the message couldn't be sent. |
Just4pLeisure | 0:e0b964252a05 | 173 | // |
Just4pLeisure | 0:e0b964252a05 | 174 | bool T5RAMCmnd(unsigned int addr) { |
Just4pLeisure | 0:e0b964252a05 | 175 | char T5TxMsg[] = T5RAMCMND; |
Just4pLeisure | 0:e0b964252a05 | 176 | T5TxMsg[1] = ((char)(addr >> 24)); // high high byte of address |
Just4pLeisure | 0:e0b964252a05 | 177 | T5TxMsg[2] = ((char)(addr >> 16)); // high low byte of address |
Just4pLeisure | 0:e0b964252a05 | 178 | T5TxMsg[3] = ((char)(addr >> 8)); // low high byte of address |
Just4pLeisure | 0:e0b964252a05 | 179 | T5TxMsg[4] = ((char)(addr)); // low low byte of address |
Just4pLeisure | 0:e0b964252a05 | 180 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 181 | } |
Just4pLeisure | 0:e0b964252a05 | 182 | |
Just4pLeisure | 0:e0b964252a05 | 183 | // |
Just4pLeisure | 0:e0b964252a05 | 184 | // T5WaitRAM |
Just4pLeisure | 0:e0b964252a05 | 185 | // |
Just4pLeisure | 0:e0b964252a05 | 186 | // Waits for the T5 ECU to send some SRAM data |
Just4pLeisure | 0:e0b964252a05 | 187 | // |
Just4pLeisure | 0:e0b964252a05 | 188 | // There is something back-to-front about the way this works, but it does :-) |
Just4pLeisure | 0:e0b964252a05 | 189 | // |
Just4pLeisure | 0:e0b964252a05 | 190 | // inputs: a pointer to an array of 6 bytes for storing the data read from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 191 | // return: a pointer to an array of 6 bytes for storing the data read from the T5 ECU. |
Just4pLeisure | 0:e0b964252a05 | 192 | // |
Just4pLeisure | 0:e0b964252a05 | 193 | char *T5WaitRAM(char *data) { |
Just4pLeisure | 0:e0b964252a05 | 194 | char T5RxMsg[8]; |
Just4pLeisure | 0:e0b964252a05 | 195 | CANWaitTimeout(RESPID, T5RxMsg, 8, T5MESSAGETIMEOUT); |
Just4pLeisure | 0:e0b964252a05 | 196 | // if (T5RxMsg[0] != 0xC6) return FALSE; |
Just4pLeisure | 0:e0b964252a05 | 197 | // if (T5RxMsg[0] != 0x0C) return FALSE; |
Just4pLeisure | 0:e0b964252a05 | 198 | for (int i=2; i<8; i++) |
Just4pLeisure | 0:e0b964252a05 | 199 | data[7-i] = T5RxMsg[i]; |
Just4pLeisure | 0:e0b964252a05 | 200 | return data; |
Just4pLeisure | 0:e0b964252a05 | 201 | } |
Just4pLeisure | 0:e0b964252a05 | 202 | |
Just4pLeisure | 0:e0b964252a05 | 203 | // T5Ack |
Just4pLeisure | 0:e0b964252a05 | 204 | // |
Just4pLeisure | 0:e0b964252a05 | 205 | // Sends an 'ACK' message to the T5 ECU to prompt the T5 to send the next |
Just4pLeisure | 0:e0b964252a05 | 206 | // ascii character from the symboltable |
Just4pLeisure | 0:e0b964252a05 | 207 | // |
Just4pLeisure | 0:e0b964252a05 | 208 | // Returns an error if: |
Just4pLeisure | 0:e0b964252a05 | 209 | // the 'ACK' message cannot be sent before the timeout |
Just4pLeisure | 0:e0b964252a05 | 210 | // |
Just4pLeisure | 0:e0b964252a05 | 211 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 212 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 213 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 214 | |
Just4pLeisure | 0:e0b964252a05 | 215 | bool T5Ack() { |
Just4pLeisure | 0:e0b964252a05 | 216 | char T5TxMsg[] = T5ACKCMND; |
Just4pLeisure | 0:e0b964252a05 | 217 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 218 | } |
Just4pLeisure | 0:e0b964252a05 | 219 | |
Just4pLeisure | 0:e0b964252a05 | 220 | // |
Just4pLeisure | 0:e0b964252a05 | 221 | // T5SendBootAddress |
Just4pLeisure | 0:e0b964252a05 | 222 | // |
Just4pLeisure | 0:e0b964252a05 | 223 | // Send an address where 'bootloader' or FLASH CAN messages are uploaded to. |
Just4pLeisure | 0:e0b964252a05 | 224 | // The number of bytes (up to 0x7F) that will be sent in the following CAN messages is also sent. |
Just4pLeisure | 0:e0b964252a05 | 225 | // |
Just4pLeisure | 0:e0b964252a05 | 226 | // inputs: an unsigned int, the address where messages should be sent. |
Just4pLeisure | 0:e0b964252a05 | 227 | // an int, the number of bytes (up to 0x7F) that will be sent in the following CAN messages. |
Just4pLeisure | 0:e0b964252a05 | 228 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 229 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 230 | // |
Just4pLeisure | 0:e0b964252a05 | 231 | bool T5SendBootAddress(unsigned int addr, int len) { |
Just4pLeisure | 0:e0b964252a05 | 232 | char T5TxMsg[] = T5_BTCMND; |
Just4pLeisure | 0:e0b964252a05 | 233 | T5TxMsg[1] = ((char)(addr >> 24)); // high high byte of address |
Just4pLeisure | 0:e0b964252a05 | 234 | T5TxMsg[2] = ((char)(addr >> 16)); // high low byte of address |
Just4pLeisure | 0:e0b964252a05 | 235 | T5TxMsg[3] = ((char)(addr >> 8)); // low high byte of address |
Just4pLeisure | 0:e0b964252a05 | 236 | T5TxMsg[4] = ((char)(addr)); // low low byte of address |
Just4pLeisure | 0:e0b964252a05 | 237 | T5TxMsg[5] = ((char)(len)); // number of bytes to upload (sent in following messages) |
Just4pLeisure | 0:e0b964252a05 | 238 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 239 | } |
Just4pLeisure | 0:e0b964252a05 | 240 | |
Just4pLeisure | 0:e0b964252a05 | 241 | // Upload 'bootloader' or new FLASH byts to T5 ECU in CAN messages |
Just4pLeisure | 0:e0b964252a05 | 242 | // |
Just4pLeisure | 0:e0b964252a05 | 243 | // The CAN messages are made up of 1 byte which is added to the address given in the T5SendBootAddress meaassge |
Just4pLeisure | 0:e0b964252a05 | 244 | // followed by 7 bytes of data. |
Just4pLeisure | 0:e0b964252a05 | 245 | // The first byte normally starts at 0x00 and increases by 7 in following messages until another T5SendBootAddress message is sent e.g. |
Just4pLeisure | 0:e0b964252a05 | 246 | // 00,dd,dd,dd,dd,dd,dd,dd,dd 'dd' bytes are the data bytes, 7 in each CAN message except the last one which may have less. |
Just4pLeisure | 0:e0b964252a05 | 247 | // 07,dd,dd,dd,dd,dd,dd,dd,dd |
Just4pLeisure | 0:e0b964252a05 | 248 | // 0E,dd,dd,dd,dd,dd,dd,dd,dd (0x0E is 14) |
Just4pLeisure | 0:e0b964252a05 | 249 | // 15,dd,dd,dd,dd,dd,dd,dd,dd (0x15 is 21) |
Just4pLeisure | 0:e0b964252a05 | 250 | // etc. |
Just4pLeisure | 0:e0b964252a05 | 251 | // |
Just4pLeisure | 0:e0b964252a05 | 252 | // inputs: a pointer to an array of 8 bytes to be sent to the T5 ECU SRAM or FLASH. |
Just4pLeisure | 0:e0b964252a05 | 253 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 254 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 255 | // |
Just4pLeisure | 0:e0b964252a05 | 256 | bool T5SendBootFrame (char *frame) { |
Just4pLeisure | 0:e0b964252a05 | 257 | return (CANSendTimeout (CMNDID, frame, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 258 | } |
Just4pLeisure | 0:e0b964252a05 | 259 | |
Just4pLeisure | 0:e0b964252a05 | 260 | // |
Just4pLeisure | 0:e0b964252a05 | 261 | // T5StartBootLoader |
Just4pLeisure | 0:e0b964252a05 | 262 | // |
Just4pLeisure | 0:e0b964252a05 | 263 | // Send the jump to address to the T5 ECU for starting the 'bootloader'. |
Just4pLeisure | 0:e0b964252a05 | 264 | // The jump address must be somewhere in RAM (addresses 0x0000 to 0x8000). |
Just4pLeisure | 0:e0b964252a05 | 265 | // (The start address comes from the S7/8/9 line in the S19 file.) |
Just4pLeisure | 0:e0b964252a05 | 266 | // |
Just4pLeisure | 0:e0b964252a05 | 267 | // inputs: an unsigned int, the address to jump to start of 'bootloader'. |
Just4pLeisure | 0:e0b964252a05 | 268 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 269 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 270 | // |
Just4pLeisure | 0:e0b964252a05 | 271 | bool T5StartBootLoader (unsigned int addr) { |
Just4pLeisure | 0:e0b964252a05 | 272 | char T5TxMsg[] = T5JMPCMND; |
Just4pLeisure | 0:e0b964252a05 | 273 | T5TxMsg[3] = ((char)(addr >> 8)); // low byte of address |
Just4pLeisure | 0:e0b964252a05 | 274 | T5TxMsg[4] = ((char)(addr)); // high byte of address |
Just4pLeisure | 0:e0b964252a05 | 275 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 276 | } |
Just4pLeisure | 0:e0b964252a05 | 277 | |
Just4pLeisure | 0:e0b964252a05 | 278 | // |
Just4pLeisure | 0:e0b964252a05 | 279 | // T5BootCSumCmnd |
Just4pLeisure | 0:e0b964252a05 | 280 | // |
Just4pLeisure | 0:e0b964252a05 | 281 | // Send the checksum command to Bootloader |
Just4pLeisure | 0:e0b964252a05 | 282 | // |
Just4pLeisure | 0:e0b964252a05 | 283 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 284 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 285 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 286 | // |
Just4pLeisure | 0:e0b964252a05 | 287 | bool T5BootCSumCmnd() { |
Just4pLeisure | 0:e0b964252a05 | 288 | char T5TxMsg[] = T5SUMCMND; |
Just4pLeisure | 0:e0b964252a05 | 289 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 290 | } |
Just4pLeisure | 0:e0b964252a05 | 291 | |
Just4pLeisure | 0:e0b964252a05 | 292 | // |
Just4pLeisure | 0:e0b964252a05 | 293 | // T5BootResetCmnd |
Just4pLeisure | 0:e0b964252a05 | 294 | // |
Just4pLeisure | 0:e0b964252a05 | 295 | // Send 'exit and restart T5' command to the Bootloader |
Just4pLeisure | 0:e0b964252a05 | 296 | // |
Just4pLeisure | 0:e0b964252a05 | 297 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 298 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 299 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 300 | // |
Just4pLeisure | 0:e0b964252a05 | 301 | bool T5BootResetCmnd() { |
Just4pLeisure | 0:e0b964252a05 | 302 | char T5TxMsg[] = T5RSTCMND; |
Just4pLeisure | 0:e0b964252a05 | 303 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 304 | } |
Just4pLeisure | 0:e0b964252a05 | 305 | |
Just4pLeisure | 0:e0b964252a05 | 306 | // |
Just4pLeisure | 0:e0b964252a05 | 307 | // T5BootFLASHType |
Just4pLeisure | 0:e0b964252a05 | 308 | // |
Just4pLeisure | 0:e0b964252a05 | 309 | // Send 'get FLASH chip types' command to the Bootloader |
Just4pLeisure | 0:e0b964252a05 | 310 | // |
Just4pLeisure | 0:e0b964252a05 | 311 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 312 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 313 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 314 | // |
Just4pLeisure | 0:e0b964252a05 | 315 | bool T5BootFLASHType() { |
Just4pLeisure | 0:e0b964252a05 | 316 | char T5TxMsg[] = T5TYPCMND; |
Just4pLeisure | 0:e0b964252a05 | 317 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 318 | } |
Just4pLeisure | 0:e0b964252a05 | 319 | |
Just4pLeisure | 0:e0b964252a05 | 320 | // |
Just4pLeisure | 0:e0b964252a05 | 321 | // T5BootEraseCmnd |
Just4pLeisure | 0:e0b964252a05 | 322 | // |
Just4pLeisure | 0:e0b964252a05 | 323 | // Send 'erase FLASH chip types' command to the Bootloader |
Just4pLeisure | 0:e0b964252a05 | 324 | // |
Just4pLeisure | 0:e0b964252a05 | 325 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 326 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 327 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 328 | // |
Just4pLeisure | 0:e0b964252a05 | 329 | bool T5BootEraseCmnd() { |
Just4pLeisure | 0:e0b964252a05 | 330 | char T5TxMsg[] = T5ERACMND; |
Just4pLeisure | 0:e0b964252a05 | 331 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 332 | } |
Just4pLeisure | 0:e0b964252a05 | 333 | |
Just4pLeisure | 0:e0b964252a05 | 334 | // |
Just4pLeisure | 0:e0b964252a05 | 335 | // T5BootDumpFLASHCmnd |
Just4pLeisure | 0:e0b964252a05 | 336 | // |
Just4pLeisure | 0:e0b964252a05 | 337 | // Send 'Dump FLASH BIN file' command |
Just4pLeisure | 0:e0b964252a05 | 338 | // |
Just4pLeisure | 0:e0b964252a05 | 339 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 340 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 341 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 342 | // |
Just4pLeisure | 0:e0b964252a05 | 343 | extern bool T5BootDumpFLASHCmnd() { |
Just4pLeisure | 0:e0b964252a05 | 344 | char T5TxMsg[] = T5DMPCMND; |
Just4pLeisure | 0:e0b964252a05 | 345 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 346 | } |
Just4pLeisure | 0:e0b964252a05 | 347 | |
Just4pLeisure | 0:e0b964252a05 | 348 | // |
Just4pLeisure | 0:e0b964252a05 | 349 | // T5WaitFLASH |
Just4pLeisure | 0:e0b964252a05 | 350 | // |
Just4pLeisure | 0:e0b964252a05 | 351 | // Waits for the T5 ECU to send 4 bytes of FLASH data when dumping the FLASH |
Just4pLeisure | 0:e0b964252a05 | 352 | // |
Just4pLeisure | 0:e0b964252a05 | 353 | // CAN messages look like this: |
Just4pLeisure | 0:e0b964252a05 | 354 | // A6,04,dd,dd,dd,dd,08,08 |
Just4pLeisure | 0:e0b964252a05 | 355 | // A6 - means FLASH dump type message |
Just4pLeisure | 0:e0b964252a05 | 356 | // 04 - means (at least) 4 more bytes still to come |
Just4pLeisure | 0:e0b964252a05 | 357 | // dd,dd,dd,dd are 4 data bytes |
Just4pLeisure | 0:e0b964252a05 | 358 | // The last message looks like this: |
Just4pLeisure | 0:e0b964252a05 | 359 | // A6,00,dd,dd,dd,dd,08,08 |
Just4pLeisure | 0:e0b964252a05 | 360 | // A6 - means FLASH dump type message |
Just4pLeisure | 0:e0b964252a05 | 361 | // 00 - means no more bytes after this CAN message |
Just4pLeisure | 0:e0b964252a05 | 362 | // dd,dd,dd,dd are the last 4 data bytes |
Just4pLeisure | 0:e0b964252a05 | 363 | // |
Just4pLeisure | 0:e0b964252a05 | 364 | // inputs: a pointer to an array of 8 bytes for the CAN message containing FLASH data. |
Just4pLeisure | 0:e0b964252a05 | 365 | // return: a pointer to an array of 8 bytes for the CAN message containing FLASH data. |
Just4pLeisure | 0:e0b964252a05 | 366 | // |
Just4pLeisure | 0:e0b964252a05 | 367 | char *T5WaitFLASH(char *data) { |
Just4pLeisure | 0:e0b964252a05 | 368 | char T5RxMsg[8]; |
Just4pLeisure | 0:e0b964252a05 | 369 | CANWaitTimeout(RESPID, T5RxMsg, 8, T5MESSAGETIMEOUT); |
Just4pLeisure | 0:e0b964252a05 | 370 | // if (T5RxMsg[0] != 0xC6) return FALSE; |
Just4pLeisure | 0:e0b964252a05 | 371 | // if (T5RxMsg[0] != 0x0C) return FALSE; |
Just4pLeisure | 0:e0b964252a05 | 372 | for (int i=0; i<8; i++) |
Just4pLeisure | 0:e0b964252a05 | 373 | data[i] = T5RxMsg[i]; |
Just4pLeisure | 0:e0b964252a05 | 374 | return data; |
Just4pLeisure | 0:e0b964252a05 | 375 | } |
Just4pLeisure | 0:e0b964252a05 | 376 | |
Just4pLeisure | 0:e0b964252a05 | 377 | // |
Just4pLeisure | 0:e0b964252a05 | 378 | // T5BootResetCmnd |
Just4pLeisure | 0:e0b964252a05 | 379 | // |
Just4pLeisure | 0:e0b964252a05 | 380 | // Send 'C3 - Get last address' command to the Bootloader |
Just4pLeisure | 0:e0b964252a05 | 381 | // |
Just4pLeisure | 0:e0b964252a05 | 382 | // inputs: none |
Just4pLeisure | 0:e0b964252a05 | 383 | // return: bool TRUE if message was sent OK, |
Just4pLeisure | 0:e0b964252a05 | 384 | // FALSE if message could not be sent. |
Just4pLeisure | 0:e0b964252a05 | 385 | // |
Just4pLeisure | 0:e0b964252a05 | 386 | bool T5BootC3Command() { |
Just4pLeisure | 0:e0b964252a05 | 387 | char T5TxMsg[] = T5EOFCMND; |
Just4pLeisure | 0:e0b964252a05 | 388 | return (CANSendTimeout (CMNDID, T5TxMsg, 8, T5MESSAGETIMEOUT)); |
Just4pLeisure | 0:e0b964252a05 | 389 | } |