1.2 CAN-TP Use Cases
CAN-TP is a versatile Transport Protocol for embedded nodes/devices in a system. When messages being sent over CAN/CAN-FD exceed the maximum packet size CAN-TP is used for message handling between the sending and receiving nodes/devices. CAN-TP is used primarily in Automotive settings. This is because CAN itself is made for environments that could cause communication issues. It uses a bus(wire) that is noise immune. This means most outside interference won't affect the values sent through the CAN Packet. Additionally CAN utilizes CRC to determine when an error has occurred. For example, a vehicle may have multiple CAN buses where nodes/devices need to communicate with each other. The other need is when nodes/devices need to be updated to a new firmware and this could be done through a CAN bus using a bootloader. Examples of nodes/devices vary from sensors checking status of parts for safety reasons to radio audio. Though vehicles are the main use case for this type of Transport Protocol, CAN-TP can be used for any application that requires multiple devices to communicate between each other on a singular bus.
-
If CAN_TP_RxPause() is used anywhere by the user, CAN_TP_RxResume() will be required before another CAN-Packet will be read in. A timeout can occur in two places:
-
CAN_TP_RxResume() is not called before continuing.
-
Added functionality takes longer than the timeout period (1s).
void CAN_TP_Pause_example(void){
if(CAN_TP_IsRxPaused()){
//Do something while Rx is paused.......
//If the messages should resume call the resume function.
CAN_TP_RxResume();
}
}
Use case 2: Reading in the CAN-TP message This example focuses on reading in the message when it is received. This method can be called in the main while loop to check if the message being received is complete.
uint8_t rxBuffer[512]; void CAN_TP_ReadingMessages(void){ if(CAN_TP_isMessageReady()){ size_t messageLength = CAN_TP_MessageLengthGet(); if(CAN_TP_getMessage(rxBuffer)){ //Message was read in successful. //Perform tasks on Received message....... } } }
Use case 3: Sending a message over CAN-TP This example sends a message using CAN-TP's MessageSend function.
uint8_t message[3] = {3, 0, 0}; void CAN_TP_SendingMessage(void){ CAN_TP_MessageSend(message, sizeof(message)); }
Use case 4: CAN-TP functionality. The main loop calls the required CAN_TP_Initialize() function before interacting with any other function of CAN-TP. The CAN_TP_Tick() needs to be called every 1ms to track the timeout of the CAN packets. CAN_TP_Tasks() in the main function's while loop is required to iterate through all the required tasks CAN-TP needs to get done. This example also shows the use of the RxMessageBufferSet which allows the use of an alternate buffer.
uint8_t rxBuffer[1024]; int main(void) { SYSTEM_Initialize(); CAN_TP_Initialize(); Timer1.TimeoutCallbackRegister(&CAN_TP_Tick); //(); //These are configured in the Melody CAN-TP module configurations. CAN_TP_RxBlockSizeSet(10); //default is 0 CAN_TP_RxSeparationTimeSet(10); //default is 1 //The default Buffer of 512 set in can-tp can be swapped out for a custom Buffer. CAN_TP_RxMessageBufferSet(rxBuffer, sizeof(rxBuffer)); while(1) { CAN_TP_Tasks(); } }