Snapdragon® Telematics Application Framework (TelAF) Interface Specification
|
A controller area network (CAN) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other. It is a high-integrity serial bus system for networking intelligent devices and has emerged as the standard in-vehicle network.
The functions of this API are provided by the tafCanSvc application service.
The following example illustrates how to bind to the CAN service.
bindings: { clientExe.clientComponent.taf_can -> tafCanSvc.taf_can }
taf_can_InfProtocol_t canInfType = TAF_CAN_RAW_SOCK; char* infNamePtr = "can0"; taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf(infNamePtr, canInfType); if (canInfRef != NULL) { uint32_t frameId = 0x123; taf_can_CanFrameRef_t frameRef = taf_can_CreateCanFrame(canInfRef, frameId); if(frameRef != NULL) { //Process after succesfully creating Can frame } }
Sets filter to receive CAN frame for the given frame ID. Applications can set filters with taf_can_SetFilter().
In the example code snippet, the filter is set to receive CAN frames for frame ID "0x123" in the requested CanInfRef.
taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf("can0", TAF_CAN_RAW_SOCK); uint32_t frameId = 0x123; if(taf_can_SetFilter(canInfRef, frameId) == LE_OK) { //Process after succesfully setting receive filter }
If local loopback is enabled, the messages sent from the given interface (can0/can1/..) are looped back to the same CAN interface, so all applications bound with the given CAN interface can receive the message.
Applications can enable or disable loopback with the taf_can_EnableLoopback() or taf_can_DisableLoopback() functions. To meet multi-user needs, local loopback is enabled by default.
taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf("can0", TAF_CAN_RAW_SOCK); if(taf_can_EnableLoopback(canInfRef) == LE_OK) { //Process after succesfully enabling the loopback } if(taf_can_DisableLoopback(canInfRef) == LE_OK) { //Process after succesfully disabling the loopback }
When receiving messages sent from the same CanInterface reference, Reception of the application's own sent CAN frame is usually unwanted, therefore it is disabled by default.
taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf("can0", TAF_CAN_RAW_SOCK); if(taf_can_EnableRcvOwnMsg(canInfRef) == LE_OK) { //Process after succesfully enabling the reception of own sent CAN frame } if(taf_can_DisableRcvOwnMsg(canInfRef) == LE_OK) { //Process after succesfully disabling the reception of own sent CAN frame }
The new CAN FD capable CAN controllers support two different bitrates for the arbitration phase and the payload phase of the CAN FD frame and up to 64 bytes of payload.
taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf("can0", TAF_CAN_RAW_SOCK); if(taf_can_IsFdSupported(canInfRef) == true) { //Process if device support FD Frame type. } if(taf_can_EnableFdFrame(canInfRef) == LE_OK) { //Process after succesfully enabling the CAN FD frame } if(taf_can_GetFdStatus(canInfRef) == true) { //Process successful if CAN FD frame is enabled }
The handler can be managed with the taf_can_AddCanEventHandler() and taf_can_RemoveCanEventHandler() functions.
To receive CAN frame when <received_can_id> & frIdMask == <frameId> & frIdMask, register a handler function using taf_can_AddCanEventHandler().
static void CanHandlerFunction ( taf_can_CanInterfaceRef_t canInfRef, bool isCanFdFrame, uint32_t frameId, const uint8_t* dataPtr, void* contextPtr ) { // Process after succesfully receiving message } taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf("can0", TAF_CAN_RAW_SOCK); taf_can_CanEventHandlerRef_t handlerRef = NULL; handlerRef = taf_can_AddCanEventHandler(canInfRef, frameId, frIdMask, CanHandlerFunction, NULL);
To remove the handler function, call taf_can_RemoveCanEventHandler().
taf_can_RemoveCanEventHandler(handlerRef);
taf_can_SetPayload() – Sets data up to 64 bytes in hexadecimal form.
taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf("can0", TAF_CAN_RAW_SOCK); uint32_t frameId = 0x123; taf_can_CanFrameRef_t frameRef = taf_can_CreateCanFrame(canInfRef, frameId); uint8_t dataPtr[TAF_CAN_DATA_MAX_LENGTH] = 0x1234ab34; if(taf_can_SetPayload(frameRef, dataPtr) == LE_OK) { //Process after succesfully setting the data }
taf_can_SetFrameType() – Sets CAN frame type to send.
The application sets CAN frame type with the taf_can_SetFrameType().
taf_can_FrameType_t frameType = TAF_CAN_CAN_FRAME; if(taf_can_SetFrameType(frameRef, frameType) == LE_OK) { //Process after succesfully setting frame type }
taf_can_SendFrame() – Sends frame of any CAN frame type. Before sending CAN frame, sets the frame type using taf_can_SetFrameType() and payload using taf_can_SetPayload().
if(taf_can_SendFrame(frameRef) == LE_OK) { //Process after succesfully sending CAN frame }
The application can close the opened socket and deallocate the allocated memory for a created CAN interface with the taf_can_DeleteCanInf() function.
taf_can_CanInterfaceRef_t canInfRef = taf_can_CreateCanInf("can0", TAF_CAN_RAW_SOCK); if(taf_can_DeleteCanInf(canInfRef) == LE_OK) { //Process after succesfully deleting the created CAN interface }
The application can deallocate the allocated memory for a created CAN frame using the taf_can_DeleteCanFrame() function.
if(taf_can_DeleteCanFrame(frameRef) == LE_OK) { //Process after succesfully deleting the created CAN frame }