firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
public
Collaboration diagram for public:

Data Structures

struct  CAN_Msg_t
struct  canlib_scheduled_msg_params

Typedefs

typedef void(* CAN_Rx_Handler_t) (CAN_Msg_t *msg_ptr)

Enumerations

enum  can_bus { CAN_1 = 0U , CAN_2 , CAN_3 , CAN_BUS_MAX }
 CAN bus ID enum. More...

Functions

void canlib_tx_task_init (Task_Init_t *init_ptr, enum can_bus bus, FDCAN_HandleTypeDef *hfdcan, uint16_t tx_queue_length)
 Initializes a FreeRTOS CAN transmit task for bus and creates a transmit queue with capacity tx_queue_length.
void canlib_rx_task_init (Task_Init_t *init_ptr, enum can_bus bus, FDCAN_HandleTypeDef *hfdcan, uint32_t rx_location, CAN_Rx_Handler_t handler)
 Initializes a FreeRTOS CAN receive task for bus that receives messages from rx_location. Calls callback when a new message is received.
void canlib_start (void)
 Starts all STM32 FDCAN peripherals that were registered to a CAN transmit or receive task.
void canlib_register_timeout_ids (enum can_bus bus, FDCAN_HandleTypeDef *hfdcan, uint32_t timeout_ids_ptr[], unsigned timeout_ids_cnt)
 Registers CAN messages for timeout tracking by the CAN receive task for a CAN bus (also sorts the array of CAN IDs in ascending order, lol)
TimerHandle_t canlib_register_scheduled_msgs (struct canlib_scheduled_msg_params *params_ptr)
 Registers an array of CAN messages for periodic transmission on a set interval with a FreeRTOS software timer.
uint32_t canlib_get_msg_timeout (enum can_bus bus, uint32_t msg_id)
 Get the time since a message with ID msg_id was received on bus. If the CAN ID wasn't registered with canlib_register_timeout_ids() first on initialization, the returned value will be CANLIB_TIMEOUT_INVALID (UINT32_MAX)
bool canlib_tx_generic (const CAN_Msg_t *msg_ptr, TickType_t block_time, bool is_critical)
 Queues a CAN message for transmission.
static __always_inline bool canlib_tx (const CAN_Msg_t *msg_ptr, TickType_t block_time)
static __always_inline bool canlib_tx_critical (const CAN_Msg_t *msg_ptr, TickType_t block_time)
bool canlib_is_bus_ok (enum can_bus bus)
 Checks for protocol errors on bus.

Detailed Description

Typedef Documentation

◆ CAN_Rx_Handler_t

typedef void(* CAN_Rx_Handler_t) (CAN_Msg_t *msg_ptr)

Enumeration Type Documentation

◆ can_bus

enum can_bus

CAN bus ID enum.

Enumerator
CAN_1 
CAN_2 
CAN_3 
CAN_BUS_MAX 

Function Documentation

◆ canlib_get_msg_timeout()

uint32_t canlib_get_msg_timeout ( enum can_bus bus,
uint32_t msg_id )

Get the time since a message with ID msg_id was received on bus. If the CAN ID wasn't registered with canlib_register_timeout_ids() first on initialization, the returned value will be CANLIB_TIMEOUT_INVALID (UINT32_MAX)

Parameters
bus
msg_idCAN ID registered for timeout tracking
Returns
unsigned Milliseconds since the message was received, or CANLIB_TIMEOUT_INVALID
Here is the caller graph for this function:

◆ canlib_is_bus_ok()

bool canlib_is_bus_ok ( enum can_bus bus)

Checks for protocol errors on bus.

Parameters
bus
Returns
true if the CAN bus is active and operating normally, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canlib_register_scheduled_msgs()

TimerHandle_t canlib_register_scheduled_msgs ( struct canlib_scheduled_msg_params * params_ptr)

Registers an array of CAN messages for periodic transmission on a set interval with a FreeRTOS software timer.

Parameters
params_ptrScheduled CAN message parameter struct
Returns
TimerHandle_t The FreeRTOS timer doing the transmitting. This can be stored and used to stop/start/restart transmission later, or simply discarded
Here is the call graph for this function:

◆ canlib_register_timeout_ids()

void canlib_register_timeout_ids ( enum can_bus bus,
FDCAN_HandleTypeDef * hfdcan,
uint32_t timeout_ids_ptr[],
unsigned timeout_ids_cnt )

Registers CAN messages for timeout tracking by the CAN receive task for a CAN bus (also sorts the array of CAN IDs in ascending order, lol)

Parameters
bus
timeout_ids_ptrArray of CAN IDs on bus to keep track of timeout data for
timeout_ids_cntLength of array
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canlib_rx_task_init()

void canlib_rx_task_init ( Task_Init_t * init_ptr,
enum can_bus bus,
FDCAN_HandleTypeDef * hfdcan,
uint32_t rx_location,
CAN_Rx_Handler_t handler )

Initializes a FreeRTOS CAN receive task for bus that receives messages from rx_location. Calls callback when a new message is received.

Warning
Don't initialize more than one CAN receive task for the same bus/FDCAN peripheral! Do not start the FDCAN peripheral with HAL_FDCAN_Start(). Call canlib_start() after initializing all transmit/receive tasks Register Callbacks must be enabled from within STM32CubeMX for FDCAN peripherals
Parameters
init_ptrTask initialization parameters
busCAN bus for the transmit task
hfdcanHAL FDCAN peripheral handle
rx_locationEither FDCAN_RX_FIFO0 or FDCAN_RX_FIFO1
callbackReceived message handler function for project-specific CAN message handling. Called when the task receives a new message
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canlib_start()

void canlib_start ( void )

Starts all STM32 FDCAN peripherals that were registered to a CAN transmit or receive task.

Warning
Call this function after (and only after) initializing all CAN transmit/receive tasks
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canlib_tx()

__always_inline bool canlib_tx ( const CAN_Msg_t * msg_ptr,
TickType_t block_time )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canlib_tx_critical()

__always_inline bool canlib_tx_critical ( const CAN_Msg_t * msg_ptr,
TickType_t block_time )
static
Here is the call graph for this function:

◆ canlib_tx_generic()

bool canlib_tx_generic ( const CAN_Msg_t * msg_ptr,
TickType_t block_time,
bool is_critical )

Queues a CAN message for transmission.

Parameters
msg_ptr
block_timeIn FreeRTOS kernel ticks
Returns
true on success. Fails if the transmit queue for the CAN bus is still full after block_time ticks
Here is the caller graph for this function:

◆ canlib_tx_task_init()

void canlib_tx_task_init ( Task_Init_t * init_ptr,
enum can_bus bus,
FDCAN_HandleTypeDef * hfdcan,
uint16_t tx_queue_length )

Initializes a FreeRTOS CAN transmit task for bus and creates a transmit queue with capacity tx_queue_length.

Warning
Don't initialize more than one CAN transmit task for the same bus/FDCAN peripheral! Do not start the FDCAN peripheral with HAL_FDCAN_Start(). Call canlib_start() after initializing all transmit/receive tasks Register Callbacks must be enabled from within STM32CubeMX for FDCAN peripherals
Parameters
init_ptrTask initialization parameters
busCAN bus for the transmit task
hfdcanHAL FDCAN peripheral handle
tx_queue_lengthTransmit queue capacity for this bus/task (number of CAN messages)
Here is the call graph for this function:
Here is the caller graph for this function: