firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
can_rtos.h File Reference

FreeRTOS CAN receive and transmit tasks for STM32H7xx. More...

#include <stdint.h>
#include <stdbool.h>
#include "iem_types.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "stm32h7xx_hal.h"
Include dependency graph for can_rtos.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CAN_Msg_t
struct  canlib_scheduled_msg_params

Macros

#define CAN_BUS_CNT   ((uint8_t)CAN_BUS_MAX)
#define IS_CAN_BUS(bus)
#define CANLIB_TIMEOUT_INVALID   UINT32_MAX
#define CAN_DATA_MAX   8U

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

FreeRTOS CAN receive and transmit tasks for STM32H7xx.

Author
Jamie Pruett :)
Date
2025-01-14

Macro Definition Documentation

◆ CAN_BUS_CNT

#define CAN_BUS_CNT   ((uint8_t)CAN_BUS_MAX)

◆ CAN_DATA_MAX

#define CAN_DATA_MAX   8U

◆ CANLIB_TIMEOUT_INVALID

#define CANLIB_TIMEOUT_INVALID   UINT32_MAX

◆ IS_CAN_BUS

#define IS_CAN_BUS ( bus)
Value:
((bus) >= 0 && (bus) < CAN_BUS_MAX)
@ CAN_BUS_MAX
Definition can_rtos.h:27