Just4Trionic - CAN and BDM FLASH programmer for Saab cars

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers t7utils.h Source File

t7utils.h

00001 
00002 // t7utils.h - information and definitions needed for communicating with the T7 ECU
00003 
00004 // (C) 2011, 2012 Sophie Dexter
00005 
00006 #ifndef __T7UTILS_H__
00007 #define __T7UTILS_H__
00008 
00009 #include "mbed.h"
00010 
00011 #include "common.h"
00012 #include "canutils.h"
00013 
00014 #define T7CMNDID 0x220
00015 #define T7RESPID 0x238
00016 #define T7SEC_ID 0x240
00017 #define T7SEC_RX 0x258
00018 #define T7ACK_ID 0x266
00019 #define T7ANYMSG 0x0
00020 
00021 
00022 // initialise T7
00023 
00024 #define T7INITMSG   {0x3F,0x81,0x00,0x11,0x02,0x40,0x00,0x00}
00025 
00026 // authenticate with T7
00027 
00028 #define T7SEC_MSG   {0x40,0xA1,0x02,0x27,0x05,0x00,0x00,0x00}
00029 #define T7KEY_MSG   {0x40,0xA1,0x04,0x27,0x06,0x00,0x00,0x00}
00030 
00031 #define T7ACK_MSG   {0x40,0xA1,0x3F,0x00,0x00,0x00,0x00,0x00}
00032 
00033 // read_trionic7
00034 
00035 #define T7DMP_END   {0x40,0xA1,0x01,0x82,0x00,0x00,0x00,0x00}
00036 //#define T7DMPJP1A   {0x41,0xA1,0x08,0x2C,0xF0,0x03,0x00,0xEF}    // 0x000000 length=0xEF
00037 #define T7DMPJP1A   {0x41,0xA1,0x08,0x2C,0xF0,0x03,0x00,0x80}    // 0x000000 length=0x80 (128 bytes)
00038 #define T7DMPJP1B   {0x00,0xA1,0x00,0x00,0x00,0x00,0x00,0x00}
00039 #define T7DMPPOST   {0x40,0xA1,0x01,0x3E,0x00,0x00,0x00,0x00}
00040 #define T7DMPDATA   {0x40,0xA1,0x02,0x21,0xF0,0x00,0x00,0x00}
00041 #define T7DMP_ACK   {0x40,0xA1,0x20,0x00,0x00,0x00,0x00,0x00}
00042 
00043 // flash_trionic7
00044 
00045 #define T7FLASTRT   {0x41,0xA1,0x08,0x34,0x00,0x00,0x00,0x00}    // Start  = 0x000000
00046 #define T7FLASIZE   {0x00,0xA1,0x00,0x00,0x00,0x00,0x00,0x00}    // Length = 0x000000
00047 #define T7FLAJP1A   {0x41,0xA1,0x08,0x34,0x00,0x00,0x00,0x00}    // Start  = 0x000000
00048 #define T7FLAJP1B   {0x00,0xA1,0x08,0x00,0x00,0x00,0x00,0x00}    // Length = 0x080000
00049 #define T7FLABINA   {0x41,0xA1,0x08,0x34,0x00,0x00,0x00,0x00}    // Start  = 0x000000
00050 #define T7FLABINB   {0x00,0xA1,0x07,0x00,0x00,0x00,0x00,0x00}    // Length = 0x070000
00051 #define T7FLAHDRA   {0x41,0xA1,0x08,0x34,0x07,0xFF,0x00,0x00}    // Start  = 0x07FF00
00052 #define T7FLAHDRB   {0x00,0xA1,0x00,0x01,0x00,0x00,0x00,0x00}    // Length = 0x000100
00053 #define T7FLA_END   {0x40,0xA1,0x01,0x37,0x00,0x00,0x00,0x00}
00054 #define T7FLAEXIT   {0x40,0xA1,0x02,0x31,0x54,0x00,0x00,0x00}
00055 #define T7FLA_ACK   {0x40,0xA1,0x3F,0x00,0x00,0x00,0x00,0x00}        // 266h
00056 
00057 
00058 #define T7MESSAGETIMEOUT 50             // 50 milliseconds (0.05 of a second) - Seems to be plenty of time to wait for messages on the CAN bus
00059 #define T7LONGERTIMEOUT 500             // 500 milliseconds (0.5 of a second) - Some messages seem to need longer
00060 #define T7CHECKSUMTIMEOUT 2000          // 2 seconds (2,000 milliseconds) - Usually takes less than a second so allowing 2 is plenty
00061 #define T7CONNECTTIMEOUT 5000           // 5 seconds (5,000 milliseconds) - Usually takes 3 seconds so allowing 5 is plenty
00062 #define T7ERASETIMEOUT 40000            // 40 seconds (40,000 milliseconds) - Usually takes less than 20 seconds so allowing 40 is plenty
00063 
00064 extern bool t7_initialise();
00065 extern bool t7_authenticate();
00066 extern FILE * t7_file_open(const char* fname);
00067 extern bool t7_dump(bool blockmode);
00068 extern bool t7_erase();
00069 extern bool t7_flash(FILE *, bool blockmode);
00070 extern bool t7_recover(FILE *);
00071 bool t7_flash_segment(FILE *, uint32_t address, uint32_t size, bool blockmode);
00072 extern bool t7_reset();
00073 /* global constants */
00074 //#define init_msg        { 0x3F, 0x81, 0x00, 0x11, 0x02, 0x40, 0x00, 0x00 }
00075 
00076 // ask_header_trionic7
00077 
00078 //#define query           { 0x40, 0xA1, 0x02, 0x1A, 0x00, 0x00, 0x00, 0x00 }
00079 //#define ack             { 0x40, 0xA1, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00 }
00080 
00081 // ask_header2_trionic7
00082 
00083 //#define query           { 0x40, 0xA1, 0x02, 0x1A, 0x00, 0x00, 0x00, 0x00 }
00084 //#define ack             { 0x40, 0xA1, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00 }
00085 
00086 
00087 // authenticate_trionic7
00088 
00089 #define security_msg        { 0x40, 0xA1, 0x02, 0x27, 0x05, 0x00, 0x00, 0x00 }
00090 #define security_msg_reply  { 0x40, 0xA1, 0x04, 0x27, 0x06, 0x00, 0x00, 0x00 }
00091 #define ack                 { 0x40, 0xA1, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00 }
00092  
00093 
00094 // erase_trionic7
00095 
00096 //#define erase_msg1      { 0x40, 0xA1, 0x02, 0x31, 0x52, 0x00, 0x00, 0x00 }
00097 //#define erase_msg2      { 0x40, 0xA1, 0x02, 0x31, 0x53, 0x00, 0x00, 0x00 }
00098 //#define confirm_msg     { 0x40, 0xA1, 0x01, 0x3E, 0x00, 0x00, 0x00, 0x00 }
00099 
00100 
00101 // program_trionic7
00102 
00103 //#define jump_msg1a          { 0x41, 0xA1, 0x08, 0x34, 0x00, 0x00, 0x00, 0x00 }    // 0x000000 length=0x07B000
00104 #define jump_msg1b          { 0x00, 0xA1, 0x07, 0xB0, 0x00, 0x00, 0x00, 0x00 }
00105 #define jump_msg2a          { 0x41, 0xA1, 0x08, 0x34, 0x07, 0xFF, 0x00, 0x00 }    // 0x07FF00 length=0x000100
00106 #define jump_msg2b          { 0x00, 0xA1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 }
00107 #define end_data_msg        { 0x40, 0xA1, 0x01, 0x37, 0x00, 0x00, 0x00, 0x00 }
00108 #define exit_diag_msg       { 0x40, 0xA1, 0x02, 0x31, 0x54, 0x00, 0x00, 0x00 }
00109 #define req_diag_result_msg { 0x3F, 0x81, 0x01, 0x33, 0x02, 0x40, 0x00, 0x00 }  // 220h
00110 #define ack                 { 0x40, 0xA1, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00 }        // 266h
00111 
00112 // program_trionic7_tis
00113 
00114 //#define jump_msg1a          { 0x41, 0xA1, 0x08, 0x34, 0x00, 0x00, 0x00, 0x00 }    // 0x000000 length=0x070000
00115 //#define jump_msg1b          { 0x00, 0xA1, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00 }
00116 //#define jump_msg2a          { 0x41, 0xA1, 0x08, 0x34, 0x07, 0xFF, 0x00, 0x00 }    // 0x07FF00 length=0x000100
00117 //#define jump_msg2b          { 0x00, 0xA1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 }
00118 //#define end_data_msg        { 0x40, 0xA1, 0x01, 0x37, 0x00, 0x00, 0x00, 0x00 }
00119 //#define exit_diag_msg       { 0x40, 0xA1, 0x02, 0x31, 0x54, 0x00, 0x00, 0x00 }
00120 //#define req_diag_result_msg { 0x3F, 0x81, 0x01, 0x33, 0x02, 0x40, 0x00, 0x00 }  // 220h
00121 //#define ack                 { 0x40, 0xA1, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00 }        // 266h
00122 
00123 
00124 // verify_trionic7
00125 //#define init_msg        { 0x20, 0x81, 0x00, 0x11, 0x02, 0x42, 0x00, 0x00 }
00126 //#define end_data_msg    { 0x40, 0xA1, 0x01, 0x82, 0x00, 0x00, 0x00, 0x00 }
00127 //#define jump_msg1a      { 0x41, 0xA1, 0x08, 0x2C, 0xF0, 0x03, 0x00, 0xEF }    // 0x000000 length=0xEF
00128 //#define jump_msg1b      { 0x00, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
00129 //#define post_jump_msg   { 0x40, 0xA1, 0x01, 0x3E, 0x00, 0x00, 0x00, 0x00 }
00130 //#define data_msg        { 0x40, 0xA1, 0x02, 0x21, 0xF0, 0x00, 0x00, 0x00 }
00131 //#define ack             { 0x40, 0xA1, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00 }
00132 
00133 
00134 #endif