|
| bool | core_CAN_init (FDCAN_GlobalTypeDef *fdcan, uint32_t baudrate) |
| | Initialize an FDCAN module, the RX and TX pins, the TX queue (if enabled), and the RX queue or message buffer (if enabled).
|
| |
|
core_CAN_module_t * | core_CAN_convert (FDCAN_GlobalTypeDef *fdcan) |
| |
| bool | core_CAN_send_message (FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data) |
| | Add a CAN message to the hardware FIFO.
|
| |
| bool | core_CAN_send_fd_message (FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data) |
| | Add an FDCAN message to the hardware FIFO.
|
| |
| bool | core_CAN_add_message_to_tx_queue (FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint64_t data) |
| | Add a CAN frame to the TX queue. This function is only available if CORE_CAN_DISABLE_TX_QUEUE is set to 0.
|
| |
| bool | core_CAN_add_extended_message_to_tx_queue (FDCAN_GlobalTypeDef *can, uint32_t id, uint8_t dlc, uint8_t *data) |
| | Add a CAN frame to the TX queue. This function is only available if CORE_CAN_DISABLE_TX_QUEUE is set to 0.
|
| |
| bool | core_CAN_send_from_tx_queue_task (FDCAN_GlobalTypeDef *can) |
| | Loop for sending data in the TX queue over CAN. This function must be run in its own task. This function is only available if CORE_CAN_DISABLE_TX_QUEUE is set to 0.
|
| |
| bool | core_CAN_receive_from_queue (FDCAN_GlobalTypeDef *can, CanMessage_s *received_message) |
| | If a frame is waiting in the RX queue, copy it to the given location.
|
| |
| bool | core_CAN_receive_extended_from_queue (FDCAN_GlobalTypeDef *can, CanExtendedMessage_s *received_message) |
| | If a frame is waiting in the RX queue, copy it to the given location.
|
| |
| bool | core_CAN_add_filter (FDCAN_GlobalTypeDef *can, bool isExtended, uint32_t id1, uint32_t id2) |
| | Add an RX filter for the given FDCAN module.
|
| |
Core FDCAN library.
This core library component is used to interface with the FDCAN hardware.
Initialization
An FDCAN module is initialized by calling the core_CAN_init() function. The CAN bitrate is set to CORE_CAN_BITRATE, which is given in bits/second and defined in core_config.h. If CORE_FDCANx_AUTO_RETRANSMISSION is set to 1 in core_config.h, the FDCANx module will be cofigured to automatically retransmit packets that were not acknowledged. If CORE_FDCANx_USE_FD is set to 1 in core_config.h, the FDCANx module will be able to send and receive FD CAN frames as well as standard CAN frames.
Transmitting
Transmission on the CAN bus is managed by a FreeRTOS queue and occurs in two parts. First, the user code adds a CAN frame to the queue with core_CAN_add_message_to_tx_queue() (classic and FD CAN) or with core_CAN_add_extended_message_to_tx_queue() (FD CAN only).
The user code must also run core_CAN_send_from_tx_queue_task() in a dedicated FreeRTOS task. If core_CAN_send_from_tx_queue_task(), an error has occurred while transmitting.
Internally, a FreeRTOS semaphore is used to ensure only one message sits in the hardware CAN queue at a time. The semaphore is given whenever a transmission completes (or fails) and is taken whenever a message is added to the hardware queue.
Alternatively, the user can disable the FreeRTOS queue by defining CORE_CAN_DISABLE_TX_QUEUE in core_config.h. This is useful if the user needs finer control over the transmission, wants to synchronize CAN transmissions between FDCAN modules, or would like to save SRAM space. The RX queue is not affected and the user can access the semaphore using core_CAN_convert(), but will be responsible for taking the semaphore.
Receiving
In order to enable receiving CAN frames, the user code must first set up one or more filters using the core_CAN_add_filter() function. When a frame matching any of the applied filters is received, the FDCAN hardware triggers an interrupt that processes the received data.
There are two options for processing received frames: queues or message buffers. If CORE_CAN_USE_MSGBUF is not set, then one RX queue is created for each initialized CAN module. When the receive interrupt is triggered, the received frame is inserted into the corresponding queue. Queues are preferred when data from different busses is processed separately and when different busses are assigned different priorities. However, a queue can only store a fixed number of elements, and a fixed amount of space will be allocated for each message, regardless of the message's size.
If CORE_CAN_USE_MSGBUF is set to 1, then up to three RX message buffers can be created. Each FDCAN module can then be connected to one of the three message buffers. This allows data from multiple busses to be combined into one message buffer, which is helpful if data from all busses is processed identically. Furthermore, message will only take up as much space in the message buffer as needed, allowing the space to be used more efficiently.
If not using message buffers, the user code must define a task that repeatedly calls core_CAN_receive_from_queue() (classic CAN) or core_CAN_receive_extended_from_queue() (FD CAN only). If using message buffers, the user code must define a task that repeatedly calls core_CAN_receive_from_msgbuf(). These functions will wait up to CORE_CAN_RX_TIMEOUT for a message to appear in the buffer before returning.