diff --git a/Target/Source/ARM7_LPC2000/can.c b/Target/Source/ARM7_LPC2000/can.c index 726758cc..4dcd12d4 100644 --- a/Target/Source/ARM7_LPC2000/can.c +++ b/Target/Source/ARM7_LPC2000/can.c @@ -246,12 +246,14 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool CanReceivePacket(blt_int8u *data) +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len) { blt_int32u rxMsgId; + blt_int8u rxMsgDlc; blt_bool result = BLT_FALSE; /* check if a new message was received */ @@ -268,6 +270,13 @@ blt_bool CanReceivePacket(blt_int8u *data) /* see if this is the message identifier that we are interested in */ if (rxMsgId == BOOT_COM_CAN_RX_MSG_ID) { + /* store the message data length */ + rxMsgDlc = ((blt_int8u)(CAN1RFS >> 16)) & 0x0Fu; + if (rxMsgDlc > 8) + { + rxMsgDlc = 8; + } + *len = rxMsgDlc; /* store the message data */ data[0] = (blt_int8u)CAN1RDA; data[1] = (blt_int8u)(CAN1RDA >> 8); diff --git a/Target/Source/ARM7_LPC2000/uart.c b/Target/Source/ARM7_LPC2000/uart.c index 61fb9ddf..24791875 100644 --- a/Target/Source/ARM7_LPC2000/uart.c +++ b/Target/Source/ARM7_LPC2000/uart.c @@ -165,10 +165,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -208,6 +209,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM0_STM32F0/can.c b/Target/Source/ARMCM0_STM32F0/can.c index 71340fd0..bb5f281f 100644 --- a/Target/Source/ARMCM0_STM32F0/can.c +++ b/Target/Source/ARMCM0_STM32F0/can.c @@ -222,10 +222,11 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool CanReceivePacket(blt_int8u *data) +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len) { CanRxMsg rxMsg; blt_int8u byteIdx; @@ -252,6 +253,7 @@ blt_bool CanReceivePacket(blt_int8u *data) /* is the identifier a match to the bootloader reception message identifier? */ if (canIdMatched == BLT_TRUE) { + *len = rxMsg.DLC; for (byteIdx=0; byteIdxsFIFOMailBox[0].RDTR)) & 0x0fu; /* store the received packet data */ data[0] = (blt_int8u)0xFF & CANx->sFIFOMailBox[0].RDLR; data[1] = (blt_int8u)0xFF & (CANx->sFIFOMailBox[0].RDLR >> 8); diff --git a/Target/Source/ARMCM3_STM32F1/uart.c b/Target/Source/ARMCM3_STM32F1/uart.c index 6fee7d90..22f2ec60 100644 --- a/Target/Source/ARMCM3_STM32F1/uart.c +++ b/Target/Source/ARMCM3_STM32F1/uart.c @@ -159,10 +159,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -202,6 +203,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM3_STM32F1/usb.c b/Target/Source/ARMCM3_STM32F1/usb.c index 020e9df4..c2dbaab8 100644 --- a/Target/Source/ARMCM3_STM32F1/usb.c +++ b/Target/Source/ARMCM3_STM32F1/usb.c @@ -171,10 +171,11 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UsbReceivePacket(blt_int8u *data) +blt_bool UsbReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_USB_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -214,7 +215,8 @@ blt_bool UsbReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; - + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM3_STM32F2/can.c b/Target/Source/ARMCM3_STM32F2/can.c index 5e827993..c4ea9e1e 100644 --- a/Target/Source/ARMCM3_STM32F2/can.c +++ b/Target/Source/ARMCM3_STM32F2/can.c @@ -365,10 +365,11 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool CanReceivePacket(blt_int8u *data) +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len) { blt_int32u rxMsgId; blt_bool result = BLT_FALSE; @@ -392,6 +393,7 @@ blt_bool CanReceivePacket(blt_int8u *data) if (rxMsgId == BOOT_COM_CAN_RX_MSG_ID) { result = BLT_TRUE; + *len = ((blt_int8u)(CANx->sFIFOMailBox[0].RDTR)) & 0x0fu; /* store the received packet data */ data[0] = (blt_int8u)0xFF & CANx->sFIFOMailBox[0].RDLR; data[1] = (blt_int8u)0xFF & (CANx->sFIFOMailBox[0].RDLR >> 8); diff --git a/Target/Source/ARMCM3_STM32F2/uart.c b/Target/Source/ARMCM3_STM32F2/uart.c index 4641e6a3..b6d5fbaa 100644 --- a/Target/Source/ARMCM3_STM32F2/uart.c +++ b/Target/Source/ARMCM3_STM32F2/uart.c @@ -135,10 +135,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -178,6 +179,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM4_STM32F3/can.c b/Target/Source/ARMCM4_STM32F3/can.c index bae2383c..cc90b107 100644 --- a/Target/Source/ARMCM4_STM32F3/can.c +++ b/Target/Source/ARMCM4_STM32F3/can.c @@ -269,10 +269,11 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool CanReceivePacket(blt_int8u *data) +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len) { blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID; blt_bool result = BLT_FALSE; @@ -314,6 +315,7 @@ blt_bool CanReceivePacket(blt_int8u *data) { data[byteIdx] = canHandle.pRxMsg->Data[byteIdx]; } + *len = canHandle.pRxMsg->DLC; /* update the return value to indicate that new packet data was received. */ result = BLT_TRUE; } diff --git a/Target/Source/ARMCM4_STM32F3/uart.c b/Target/Source/ARMCM4_STM32F3/uart.c index df7203a7..1d8c5063 100644 --- a/Target/Source/ARMCM4_STM32F3/uart.c +++ b/Target/Source/ARMCM4_STM32F3/uart.c @@ -125,10 +125,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -168,6 +169,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM4_STM32F4/can.c b/Target/Source/ARMCM4_STM32F4/can.c index 5a751ebe..fcc81121 100644 --- a/Target/Source/ARMCM4_STM32F4/can.c +++ b/Target/Source/ARMCM4_STM32F4/can.c @@ -365,10 +365,11 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool CanReceivePacket(blt_int8u *data) +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len) { blt_int32u rxMsgId; blt_bool result = BLT_FALSE; @@ -392,6 +393,7 @@ blt_bool CanReceivePacket(blt_int8u *data) if (rxMsgId == BOOT_COM_CAN_RX_MSG_ID) { result = BLT_TRUE; + *len = ((blt_int8u)(CANx->sFIFOMailBox[0].RDTR)) & 0x0fu; /* store the received packet data */ data[0] = (blt_int8u)0xFF & CANx->sFIFOMailBox[0].RDLR; data[1] = (blt_int8u)0xFF & (CANx->sFIFOMailBox[0].RDLR >> 8); diff --git a/Target/Source/ARMCM4_STM32F4/uart.c b/Target/Source/ARMCM4_STM32F4/uart.c index 708dad45..8c01ff3b 100644 --- a/Target/Source/ARMCM4_STM32F4/uart.c +++ b/Target/Source/ARMCM4_STM32F4/uart.c @@ -136,10 +136,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -179,6 +180,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM4_STM32F4/usb.c b/Target/Source/ARMCM4_STM32F4/usb.c index be78b32a..1ecfe3e9 100644 --- a/Target/Source/ARMCM4_STM32F4/usb.c +++ b/Target/Source/ARMCM4_STM32F4/usb.c @@ -172,10 +172,11 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UsbReceivePacket(blt_int8u *data) +blt_bool UsbReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_USB_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -215,7 +216,8 @@ blt_bool UsbReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; - + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM4_STM32L4/can.c b/Target/Source/ARMCM4_STM32L4/can.c index afeddedc..9874d4ec 100644 --- a/Target/Source/ARMCM4_STM32L4/can.c +++ b/Target/Source/ARMCM4_STM32L4/can.c @@ -278,10 +278,11 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool CanReceivePacket(blt_int8u *data) +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len) { blt_int32u rxMsgId = BOOT_COM_CAN_RX_MSG_ID; blt_bool result = BLT_FALSE; @@ -302,7 +303,7 @@ blt_bool CanReceivePacket(blt_int8u *data) } else { - /* negate the ID-type bit */ + /* negate the ID-type bit. */ rxMsgId &= ~0x80000000; /* was an 29-bit CAN message received that matches? */ if ( (rxMsgHeader.ExtId == rxMsgId) && @@ -313,6 +314,11 @@ blt_bool CanReceivePacket(blt_int8u *data) } } } + /* store the data length. */ + if (result == BLT_TRUE) + { + *len = rxMsgHeader.DLC; + } /* Give the result back to the caller. */ return result; } /*** end of CanReceivePacket ***/ diff --git a/Target/Source/ARMCM4_STM32L4/uart.c b/Target/Source/ARMCM4_STM32L4/uart.c index aa862728..d3d1d17b 100644 --- a/Target/Source/ARMCM4_STM32L4/uart.c +++ b/Target/Source/ARMCM4_STM32L4/uart.c @@ -133,10 +133,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -176,6 +177,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM4_TM4C/uart.c b/Target/Source/ARMCM4_TM4C/uart.c index eef56ecb..32818113 100644 --- a/Target/Source/ARMCM4_TM4C/uart.c +++ b/Target/Source/ARMCM4_TM4C/uart.c @@ -111,10 +111,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -154,6 +155,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM4_TM4C/usb.c b/Target/Source/ARMCM4_TM4C/usb.c index 4574fff2..8e85c91b 100644 --- a/Target/Source/ARMCM4_TM4C/usb.c +++ b/Target/Source/ARMCM4_TM4C/usb.c @@ -186,10 +186,11 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UsbReceivePacket(blt_int8u *data) +blt_bool UsbReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_USB_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -229,7 +230,8 @@ blt_bool UsbReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; - + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/ARMCM4_XMC4/can.c b/Target/Source/ARMCM4_XMC4/can.c index 2fe886cd..bd633930 100644 --- a/Target/Source/ARMCM4_XMC4/can.c +++ b/Target/Source/ARMCM4_XMC4/can.c @@ -245,10 +245,11 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE is a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool CanReceivePacket(blt_int8u *data) +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len) { blt_int8u byteIdx; blt_bool result = BLT_FALSE; @@ -259,6 +260,7 @@ blt_bool CanReceivePacket(blt_int8u *data) /* read out and process the newly received data */ if (XMC_CAN_MO_ReceiveData(&receiveMsgObj) == XMC_CAN_STATUS_SUCCESS) { + *len = receiveMsgObj.can_data_length; for (byteIdx=0; byteIdxrxSlot.dsr[byte_idx]; } + *len = rxMsgLen; } /* release the receive object by clearing the rx flag */ CAN->crflg &= RXF_BIT; diff --git a/Target/Source/HCS12/uart.c b/Target/Source/HCS12/uart.c index 4360b013..500014c3 100644 --- a/Target/Source/HCS12/uart.c +++ b/Target/Source/HCS12/uart.c @@ -154,10 +154,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -197,6 +198,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/TRICORE_TC1798/uart.c b/Target/Source/TRICORE_TC1798/uart.c index d3c90fba..d379bcb0 100644 --- a/Target/Source/TRICORE_TC1798/uart.c +++ b/Target/Source/TRICORE_TC1798/uart.c @@ -163,10 +163,11 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool UartReceivePacket(blt_int8u *data) +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len) { static blt_int8u xcpCtoReqPacket[BOOT_COM_UART_RX_MAX_DATA+1]; /* one extra for length */ static blt_int8u xcpCtoRxLength; @@ -206,6 +207,8 @@ blt_bool UartReceivePacket(blt_int8u *data) CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength); /* done with cto packet reception */ xcpCtoRxInProgress = BLT_FALSE; + /* set the packet length */ + *len = xcpCtoRxLength; /* packet reception complete */ return BLT_TRUE; } diff --git a/Target/Source/can.h b/Target/Source/can.h index 84905258..d0920eed 100644 --- a/Target/Source/can.h +++ b/Target/Source/can.h @@ -34,7 +34,7 @@ ****************************************************************************************/ void CanInit(void); void CanTransmitPacket(blt_int8u *data, blt_int8u len); -blt_bool CanReceivePacket(blt_int8u *data); +blt_bool CanReceivePacket(blt_int8u *data, blt_int8u *len); #endif /* BOOT_COM_CAN_ENABLE > 0 */ diff --git a/Target/Source/com.c b/Target/Source/com.c index 9a2f9912..90e98f07 100644 --- a/Target/Source/com.c +++ b/Target/Source/com.c @@ -97,43 +97,44 @@ void ComInit(void) ****************************************************************************************/ void ComTask(void) { + blt_int8u xcpPacketLen; /* make xcpCtoReqPacket static for runtime efficiency */ static blt_int8u xcpCtoReqPacket[BOOT_COM_RX_MAX_DATA]; #if (BOOT_COM_CAN_ENABLE > 0) - if (CanReceivePacket(&xcpCtoReqPacket[0]) == BLT_TRUE) + if (CanReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE) { /* make this the active interface */ comActiveInterface = COM_IF_CAN; /* process packet */ - XcpPacketReceived(&xcpCtoReqPacket[0]); + XcpPacketReceived(&xcpCtoReqPacket[0], xcpPacketLen); } #endif #if (BOOT_COM_UART_ENABLE > 0) - if (UartReceivePacket(&xcpCtoReqPacket[0]) == BLT_TRUE) + if (UartReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE) { /* make this the active interface */ comActiveInterface = COM_IF_UART; /* process packet */ - XcpPacketReceived(&xcpCtoReqPacket[0]); + XcpPacketReceived(&xcpCtoReqPacket[0], xcpPacketLen); } #endif #if (BOOT_COM_USB_ENABLE > 0) - if (UsbReceivePacket(&xcpCtoReqPacket[0]) == BLT_TRUE) + if (UsbReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE) { /* make this the active interface */ comActiveInterface = COM_IF_USB; /* process packet */ - XcpPacketReceived(&xcpCtoReqPacket[0]); + XcpPacketReceived(&xcpCtoReqPacket[0], xcpPacketLen); } #endif #if (BOOT_COM_NET_ENABLE > 0) - if (NetReceivePacket(&xcpCtoReqPacket[0]) == BLT_TRUE) + if (NetReceivePacket(&xcpCtoReqPacket[0], &xcpPacketLen) == BLT_TRUE) { /* make this the active interface */ comActiveInterface = COM_IF_NET; /* process packet */ - XcpPacketReceived(&xcpCtoReqPacket[0]); + XcpPacketReceived(&xcpCtoReqPacket[0], xcpPacketLen); } #endif } /*** end of ComTask ***/ diff --git a/Target/Source/net.c b/Target/Source/net.c index 62cc7ab1..7f32e2a2 100644 --- a/Target/Source/net.c +++ b/Target/Source/net.c @@ -171,10 +171,11 @@ void NetTransmitPacket(blt_int8u *data, blt_int8u len) /************************************************************************************//** ** \brief Receives a communication interface packet if one is present. ** \param data Pointer to byte array where the data is to be stored. +** \param len Pointer where the length of the packet is to be stored. ** \return BLT_TRUE if a packet was received, BLT_FALSE otherwise. ** ****************************************************************************************/ -blt_bool NetReceivePacket(blt_int8u *data) +blt_bool NetReceivePacket(blt_int8u *data, blt_int8u *len) { /* run the TCP/IP server task function, which will handle the reception and * transmission of XCP packets @@ -238,7 +239,7 @@ void NetApp(void) s->dto_len = 0; /* the first 4 bytes contain a counter value in which we are not really interested */ newDataPtr = uip_appdata; - XcpPacketReceived(&newDataPtr[4]); + XcpPacketReceived(&newDataPtr[4], (blt_int8u)(uip_datalen() - 4)); } } /*** end of NetApp ***/ diff --git a/Target/Source/net.h b/Target/Source/net.h index d162d059..f6c35978 100644 --- a/Target/Source/net.h +++ b/Target/Source/net.h @@ -58,7 +58,7 @@ typedef struct net_state void NetInit(void); void NetApp(void); void NetTransmitPacket(blt_int8u *data, blt_int8u len); -blt_bool NetReceivePacket(blt_int8u *data); +blt_bool NetReceivePacket(blt_int8u *data, blt_int8u *len); #else /* BOOT_COM_NET_ENABLE > 0 */ typedef struct net_state diff --git a/Target/Source/uart.h b/Target/Source/uart.h index 649edc1e..f925cddd 100644 --- a/Target/Source/uart.h +++ b/Target/Source/uart.h @@ -34,7 +34,7 @@ ****************************************************************************************/ void UartInit(void); void UartTransmitPacket(blt_int8u *data, blt_int8u len); -blt_bool UartReceivePacket(blt_int8u *data); +blt_bool UartReceivePacket(blt_int8u *data, blt_int8u *len); #endif /* BOOT_COM_UART_ENABLE > 0 */ diff --git a/Target/Source/usb.h b/Target/Source/usb.h index 6a00f090..803a1a6a 100644 --- a/Target/Source/usb.h +++ b/Target/Source/usb.h @@ -35,7 +35,7 @@ void UsbInit(void); void UsbFree(void); void UsbTransmitPacket(blt_int8u *data, blt_int8u len); -blt_bool UsbReceivePacket(blt_int8u *data); +blt_bool UsbReceivePacket(blt_int8u *data, blt_int8u *len); /**************************************************************************************** * Hook functions diff --git a/Target/Source/xcp.c b/Target/Source/xcp.c index c26740a5..dca72dee 100644 --- a/Target/Source/xcp.c +++ b/Target/Source/xcp.c @@ -104,7 +104,7 @@ static void XcpCmdProgramPrepare(blt_int8u *data); * Hook functions ****************************************************************************************/ #if (XCP_PACKET_RECEIVED_HOOK_EN == 1) -extern blt_bool XcpPacketReceivedHook(blt_int8u *data); +extern blt_bool XcpPacketReceivedHook(blt_int8u *data, blt_int8u len); #endif #if (XCP_RES_PAGING_EN == 1) @@ -193,17 +193,22 @@ void XcpPacketTransmitted(void) /************************************************************************************//** ** \brief Informs the core that a new packet was received by the transport layer. ** \param data Pointer to byte buffer with packet data. +** \param len Number of bytes in the packet. ** \return none ** ****************************************************************************************/ -void XcpPacketReceived(blt_int8u *data) +void XcpPacketReceived(blt_int8u *data, blt_int8u len) { -#if (XCP_PACKET_RECEIVED_HOOK_EN == 1) + +#if (XCP_PACKET_RECEIVED_HOOK_EN == 0) + /* suppress compiler warning due to unused parameter. */ + (void)len; +#else /* give the hook function a chance to process this packet. A return value of BLT_TRUE * indicates that the hook function processed the packet and that no further processing * is required. */ - if (XcpPacketReceivedHook(data) == BLT_TRUE) + if (XcpPacketReceivedHook(data, len) == BLT_TRUE) { /* packet processed by hook function so no need to continue. */ return; diff --git a/Target/Source/xcp.h b/Target/Source/xcp.h index 01e9c98c..c56cded5 100644 --- a/Target/Source/xcp.h +++ b/Target/Source/xcp.h @@ -235,7 +235,7 @@ void XcpInit(void); blt_bool XcpIsConnected(void); void XcpPacketTransmitted(void); -void XcpPacketReceived(blt_int8u *data); +void XcpPacketReceived(blt_int8u *data, blt_int8u len); /****************************************************************************************