commit d54d2f07cf55f262267ac5bae4ff1549e315a0a6
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Fri Mar 16 11:43:09 2018 +0100

    Major overhaul (to version 1.1.0):
    - The bootloader toolchain now works with 32 bit device IDs (DiWheelDrive 1.1 = 0x01000101; PowerManagement 1.1 = 0x01010101; LightRing 1.0 = 0x017F0100).
      However, the system is still compatible to the old numbering scheme and legacy IDs for compatibility reasons.
      As a result, the new bootloader can be used with the old SerialBoot tool and vice versa.
    - In order to allow for 32 bit IDs, the CAN communication as modified.
      Packages which are larger than a single transmit are split into multiple CAN messages.
      An according handshaking mechanism (receiver acknowledges everey message) has been implemented.
      The device ID is not coded into the CAN message identifier anymore, but is transmitted as the first four bytes of the first CAN message of a XCP package transmission.
      However, the two lowermost bit of the CAN message identifier are now used as indicator flags for acknowledgment and subsequent transmission for simple filtering.
    - The bootloaders will not "double blink" the LED anymore, but indicate the XCP connection status.
    - The bootloader version has been incremented to 1.1.0.

diff --git a/Host/Source/SerialBoot/xcpmaster.c b/Host/Source/SerialBoot/xcpmaster.c
index 4186861..52786c9 100644
--- a/Host/Source/SerialBoot/xcpmaster.c
+++ b/Host/Source/SerialBoot/xcpmaster.c
@@ -23,11 +23,11 @@
 * You should have received a copy of the GNU General Public License along with OpenBLT.
 * If not, see <http://www.gnu.org/licenses/>.
 *
-* A special exception to the GPL is included to allow you to distribute a combined work 
-* that includes OpenBLT without being obliged to provide the source code for any 
+* A special exception to the GPL is included to allow you to distribute a combined work
+* that includes OpenBLT without being obliged to provide the source code for any
 * proprietary components. The exception text is included at the bottom of the license
 * file <license.html>.
-* 
+*
 * \endinternal
 ****************************************************************************************/
 
@@ -91,7 +91,7 @@
 /****************************************************************************************
 * Function prototypes
 ****************************************************************************************/
-static sb_uint8 XcpMasterSendCmdConnect(sb_uint8 flashingTargetID);
+static sb_uint8 XcpMasterSendCmdConnect(sb_uint32 flashingTargetID);
 static sb_uint8 XcpMasterSendCmdSetMta(sb_uint32 address);
 static sb_uint8 XcpMasterSendCmdUpload(sb_uint8 data[], sb_uint8 length);
 static sb_uint8 XcpMasterSendCmdProgramStart(void);
@@ -155,14 +155,14 @@ void XcpMasterDeinit(void)
 ** \return    SB_TRUE is successfull, SB_FALSE otherwise.
 **
 ****************************************************************************************/
-sb_uint8 XcpMasterConnect(sb_uint8 flashingTargetID)
+sb_uint8 XcpMasterConnect(sb_uint32 flashingTargetID)
 {
   sb_uint8 cnt;
   sb_uint8 retries = 1;
   if (flashingTargetID <= 0) {
     retries = XCP_MASTER_CONNECT_RETRIES;
   }
-  
+
   /* try to connect with a finite amount of retries */
   for (cnt=0; cnt<retries; cnt++)
   {
@@ -357,31 +357,38 @@ sb_uint8 XcpMasterProgramData(sb_uint32 addr, sb_uint32 len, sb_uint8 data[])
 ** \return    SB_TRUE is successfull, SB_FALSE otherwise.
 **
 ****************************************************************************************/
-static sb_uint8 XcpMasterSendCmdConnect(sb_uint8 flashingTargetID)
+static sb_uint8 XcpMasterSendCmdConnect(sb_uint32 flashingTargetID)
 {
-  sb_uint8 packetData[2];
+  sb_uint8 packetData[1+4];
   tXcpTransportResponsePacket *responsePacketPtr;
-  
+
   /* prepare the command packet */
   packetData[0] = XCP_MASTER_CMD_CONNECT;
-  packetData[1] = flashingTargetID; /* normal mode */
-  
-  /* send the packet */
-  if (XcpTransportSendPacket(packetData, 2, XCP_MASTER_CONNECT_TIMEOUT_MS) == SB_FALSE)
+  packetData[1] = (sb_uint8)(0xFF & flashingTargetID >> 0);
+  packetData[2] = (sb_uint8)(0xFF & flashingTargetID >> 8);
+  packetData[3] = (sb_uint8)(0xFF & flashingTargetID >> 16);
+  packetData[4] = (sb_uint8)(0xFF & flashingTargetID >> 24);
+
+  /* send the packet
+   * NOTE: For legacy support the following code depends on the MSB if the flashingTargetID.
+   *       If the MSB (packData[4]) is zero (i.e. 0x00??????) the system switches to legacy mode.
+   *       In legacy mode, the flashingTargetID was only one byte - the LSB (packingData[1]).
+   */
+  if (XcpTransportSendPacket(packetData, 1 + ((packetData[4] != 0) ? 4 : 1), XCP_MASTER_CONNECT_TIMEOUT_MS) == SB_FALSE)
   {
     /* cound not set packet or receive response within the specified timeout */
     return SB_FALSE;
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
     /* not a valid or positive response */
     return SB_FALSE;
   }
-  
+
   /* process response data */
   if ((responsePacketPtr->data[2] & 0x01) == 0)
   {
@@ -400,12 +407,12 @@ static sb_uint8 XcpMasterSendCmdConnect(sb_uint8 flashingTargetID)
   {
     xcpMaxDto = responsePacketPtr->data[5] + (responsePacketPtr->data[4] << 8);
   }
-  
+
   /* double check size configuration of the master */
   assert(XCP_MASTER_TX_MAX_DATA >= xcpMaxCto);
   assert(XCP_MASTER_RX_MAX_DATA >= xcpMaxDto);
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdConnect ***/
 
@@ -420,16 +427,16 @@ static sb_uint8 XcpMasterSendCmdSetMta(sb_uint32 address)
 {
   sb_uint8 packetData[8];
   tXcpTransportResponsePacket *responsePacketPtr;
-  
+
   /* prepare the command packet */
   packetData[0] = XCP_MASTER_CMD_SET_MTA;
   packetData[1] = 0; /* reserved */
   packetData[2] = 0; /* reserved */
   packetData[3] = 0; /* address extension not supported */
-  
+
   /* set the address taking into account byte ordering */
   XcpMasterSetOrderedLong(address, &packetData[4]);
-  
+
   /* send the packet */
   if (XcpTransportSendPacket(packetData, 8, XCP_MASTER_TIMEOUT_T4_MS) == SB_FALSE) //XCP_MASTER_TIMEOUT_T1_MS
   {
@@ -439,7 +446,7 @@ static sb_uint8 XcpMasterSendCmdSetMta(sb_uint32 address)
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
@@ -452,8 +459,8 @@ static sb_uint8 XcpMasterSendCmdSetMta(sb_uint32 address)
     printf(" (set MTA)\n");
     return SB_FALSE;
   }
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdSetMta ***/
 
@@ -470,10 +477,10 @@ static sb_uint8 XcpMasterSendCmdUpload(sb_uint8 data[], sb_uint8 length)
   sb_uint8 packetData[2];
   tXcpTransportResponsePacket *responsePacketPtr;
   sb_uint8 data_index;
-  
+
   /* cannot request more data then the max rx data - 1 */
   assert(length < XCP_MASTER_RX_MAX_DATA);
-  
+
   /* prepare the command packet */
   packetData[0] = XCP_MASTER_CMD_UPLOAD;
   packetData[1] = length;
@@ -487,7 +494,7 @@ static sb_uint8 XcpMasterSendCmdUpload(sb_uint8 data[], sb_uint8 length)
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
@@ -500,14 +507,14 @@ static sb_uint8 XcpMasterSendCmdUpload(sb_uint8 data[], sb_uint8 length)
     printf(" (upload)\n");
     return SB_FALSE;
   }
-  
+
   /* now store the uploaded data */
   for (data_index=0; data_index<length; data_index++)
   {
     data[data_index] = responsePacketPtr->data[data_index+1];
   }
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdUpload ***/
 
@@ -534,7 +541,7 @@ static sb_uint8 XcpMasterSendCmdProgramStart(void)
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
@@ -547,13 +554,13 @@ static sb_uint8 XcpMasterSendCmdProgramStart(void)
     printf(" (program start)\n");
     return SB_FALSE;
   }
-  
+
   /* store max number of bytes the slave allows for master->slave packets during the
    * programming session
    */
   xcpMaxProgCto = responsePacketPtr->data[3];
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdProgramStart ***/
 
@@ -579,21 +586,21 @@ static sb_uint8 XcpMasterSendCmdDisconnect(void)
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
     /* not a valid or positive response */
     return SB_FALSE;
   }
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdProgramStart ***/
 
 
 /************************************************************************************//**
-** \brief     Sends the XCP PROGRAM RESET command. Note that this command is a bit 
+** \brief     Sends the XCP PROGRAM RESET command. Note that this command is a bit
 **            different as in it does not require a response.
 ** \return    SB_TRUE is successfull, SB_FALSE otherwise.
 **
@@ -626,7 +633,7 @@ static sb_uint8 XcpMasterSendCmdProgramReset(void)
 
 //  /* still here so a response was received */
 //  responsePacketPtr = XcpTransportReadResponsePacket();
-//  
+//
 //  /* check if the reponse was valid */
 //  printf("response not valid\nlength: %u\nresponse: %i", responsePacketPtr->len, *(responsePacketPtr->data));
 //  if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
@@ -635,8 +642,8 @@ static sb_uint8 XcpMasterSendCmdProgramReset(void)
 //    return SB_FALSE;
 //  }
 
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdProgramReset ***/
 
@@ -653,10 +660,10 @@ static sb_uint8 XcpMasterSendCmdProgram(sb_uint8 length, sb_uint8 data[])
   sb_uint8 packetData[XCP_MASTER_TX_MAX_DATA];
   tXcpTransportResponsePacket *responsePacketPtr;
   sb_uint8 cnt;
-  
+
   /* verify that this number of bytes actually first in this command */
   assert(length <= (xcpMaxProgCto-2) && (xcpMaxProgCto <= XCP_MASTER_TX_MAX_DATA));
-  
+
   /* prepare the command packet */
   packetData[0] = XCP_MASTER_CMD_PROGRAM;
   packetData[1] = length;
@@ -674,7 +681,7 @@ static sb_uint8 XcpMasterSendCmdProgram(sb_uint8 length, sb_uint8 data[])
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
@@ -687,8 +694,8 @@ static sb_uint8 XcpMasterSendCmdProgram(sb_uint8 length, sb_uint8 data[])
     printf(" (program)\n");
     return SB_FALSE;
   }
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdProgram ***/
 
@@ -704,10 +711,10 @@ static sb_uint8 XcpMasterSendCmdProgramMax(sb_uint8 data[])
   sb_uint8 packetData[XCP_MASTER_TX_MAX_DATA];
   tXcpTransportResponsePacket *responsePacketPtr;
   sb_uint8 cnt;
-  
+
   /* verify that this number of bytes actually first in this command */
   assert(xcpMaxProgCto <= XCP_MASTER_TX_MAX_DATA);
-  
+
   /* prepare the command packet */
   packetData[0] = XCP_MASTER_CMD_PROGRAM_MAX;
   for (cnt=0; cnt<(xcpMaxProgCto-1); cnt++)
@@ -724,7 +731,7 @@ static sb_uint8 XcpMasterSendCmdProgramMax(sb_uint8 data[])
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
@@ -737,8 +744,8 @@ static sb_uint8 XcpMasterSendCmdProgramMax(sb_uint8 data[])
     printf(" (program max)\n");
     return SB_FALSE;
   }
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdProgramMax ***/
 
@@ -772,7 +779,7 @@ static sb_uint8 XcpMasterSendCmdProgramClear(sb_uint32 length)
   }
   /* still here so a response was received */
   responsePacketPtr = XcpTransportReadResponsePacket();
-  
+
   /* check if the reponse was valid */
   if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) )
   {
@@ -785,8 +792,8 @@ static sb_uint8 XcpMasterSendCmdProgramClear(sb_uint32 length)
     printf(" (program clear)\n");
     return SB_FALSE;
   }
-  
-  /* still here so all went well */  
+
+  /* still here so all went well */
   return SB_TRUE;
 } /*** end of XcpMasterSendCmdProgramClear ***/
 
