Macros | Functions | Variables
canard_stm32.c File Reference
#include "canard_stm32.h"
#include "_internal_bxcan.h"
#include <unistd.h>
Include dependency graph for canard_stm32.c:

Go to the source code of this file.

Macros

#define BXCAN   CANARD_STM32_CAN1
 

Functions

int16_t canardSTM32ConfigureAcceptanceFilters (const CanardSTM32AcceptanceFilterConfiguration *const filter_configs, const uint8_t num_filter_configs)
 
CanardSTM32Stats canardSTM32GetStats (void)
 
int16_t canardSTM32Init (const CanardSTM32CANTimings *const timings, const CanardSTM32IfaceMode iface_mode)
 
int16_t canardSTM32Receive (CanardCANFrame *const out_frame)
 
int16_t canardSTM32Transmit (const CanardCANFrame *const frame)
 
static uint32_t convertFrameIDCanardToRegister (const uint32_t id)
 Converts libcanard ID value into the bxCAN TX ID register format. More...
 
static uint32_t convertFrameIDRegisterToCanard (const uint32_t id)
 Converts bxCAN TX/RX (sic! both RX/TX are supported) ID register value into the libcanard ID format. More...
 
static bool isFramePriorityHigher (uint32_t a, uint32_t b)
 
static void processErrorStatus (void)
 
static bool waitMSRINAKBitStateChange (volatile const CanardSTM32CANType *const bxcan, const bool target_state)
 

Variables

static bool g_abort_tx_on_error = false
 
static CanardSTM32Stats g_stats
 

Macro Definition Documentation

◆ BXCAN

#define BXCAN   CANARD_STM32_CAN1

Definition at line 17 of file canard_stm32.c.

Function Documentation

◆ canardSTM32ConfigureAcceptanceFilters()

int16_t canardSTM32ConfigureAcceptanceFilters ( const CanardSTM32AcceptanceFilterConfiguration *const  filter_configs,
const uint8_t  num_filter_configs 
)

Sets up acceptance filters according to the provided list of ID and masks. Note that when the interface is reinitialized, hardware acceptance filters are reset. Also note that during filter reconfiguration, some RX frames may be lost.

Setting zero filters will result in rejection of all frames. In order to accept all frames, set one filter with ID = Mask = 0, which is also the default configuration.

Return values
0Success
negativeError

Definition at line 449 of file canard_stm32.c.

◆ canardSTM32GetStats()

CanardSTM32Stats canardSTM32GetStats ( void  )

Returns the running interface statistics.

Definition at line 565 of file canard_stm32.c.

◆ canardSTM32Init()

int16_t canardSTM32Init ( const CanardSTM32CANTimings *const  timings,
const CanardSTM32IfaceMode  iface_mode 
)

Initializes the CAN controller at the specified bit rate. The mode can be either normal, silent, or auto-abort on error; in silent mode the controller will be only listening, not affecting the state of the bus; in the auto abort mode the controller will cancel the pending transmissions if a bus error is encountered. The auto abort mode is needed for dynamic node ID allocation procedure; please refer to the UAVCAN specification for more information about this topic.

This function can be invoked any number of times; every invocation re-initializes everything from scratch.

WARNING: The clock of the CAN module must be enabled before this function is invoked! If CAN2 is used, CAN1 must be also enabled!

WARNING: The driver is not thread-safe! It does not use IRQ or critical sections though, so it is safe to invoke its API functions from the IRQ context from the application.

Return values
0Success
negativeError

Definition at line 168 of file canard_stm32.c.

◆ canardSTM32Receive()

int16_t canardSTM32Receive ( CanardCANFrame *const  out_frame)

Reads one frame from the hardware RX FIFO, unless all FIFO are empty. This function does never block.

Return values
1Read successfully
0The buffer is empty
negativeError

Definition at line 387 of file canard_stm32.c.

◆ canardSTM32Transmit()

int16_t canardSTM32Transmit ( const CanardCANFrame *const  frame)

Pushes one frame into the TX buffer, if there is space. Note that proper care is taken to ensure that no inner priority inversion is taking place. This function does never block.

Return values
1Transmitted successfully
0No space in the buffer
negativeError

Definition at line 281 of file canard_stm32.c.

◆ convertFrameIDCanardToRegister()

static uint32_t convertFrameIDCanardToRegister ( const uint32_t  id)
static

Converts libcanard ID value into the bxCAN TX ID register format.

Definition at line 69 of file canard_stm32.c.

◆ convertFrameIDRegisterToCanard()

static uint32_t convertFrameIDRegisterToCanard ( const uint32_t  id)
static

Converts bxCAN TX/RX (sic! both RX/TX are supported) ID register value into the libcanard ID format.

Definition at line 91 of file canard_stm32.c.

◆ isFramePriorityHigher()

static bool isFramePriorityHigher ( uint32_t  a,
uint32_t  b 
)
static

Definition at line 28 of file canard_stm32.c.

◆ processErrorStatus()

static void processErrorStatus ( void  )
static

Definition at line 146 of file canard_stm32.c.

◆ waitMSRINAKBitStateChange()

static bool waitMSRINAKBitStateChange ( volatile const CanardSTM32CANType *const  bxcan,
const bool  target_state 
)
static

A properly functioning bus will exhibit 11 consecutive recessive bits at the end of every correct transmission, or while the bus is idle. The 11 consecutive recessive bits are made up of: 1 bit - acknowledgement delimiter 7 bit - end of frame bits 3 bit - inter frame space This adds up to 11; therefore, it is not really necessary to wait longer than a few frame TX intervals.

Definition at line 118 of file canard_stm32.c.

Variable Documentation

◆ g_abort_tx_on_error

bool g_abort_tx_on_error = false
static

Definition at line 25 of file canard_stm32.c.

◆ g_stats

CanardSTM32Stats g_stats
static

Definition at line 23 of file canard_stm32.c.



uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03