microHAL
An abstraction layer for your future F4xx projects
Loading...
Searching...
No Matches
bxcan.h File Reference

Function prototypes for the bxCAN interface. More...

#include <stdint.h>
#include "stm32f4xx.h"
#include "defines.h"

Go to the source code of this file.

Data Structures

struct  bxCANMailboxRegs
 Contains bxCAN Mailbox registers. More...
 
struct  bxCANFilterRegs
 Contains bxCAN Filter registers. More...
 
struct  bxCANRegs
 Contains bxCAN registers. More...
 
struct  bxCANISR
 
struct  bxCANBitrateConfig
 Contains bxCAN baudrate configuration. More...
 
struct  bxCANFilterConfig
 Contains bxCAN filter configuration. More...
 
struct  bxCANAutomationConfig
 
struct  bxCANFrame
 Contains bxCAN frame structure. More...
 
struct  bxCANErrorInfo
 Contains bxCAN error info. More...
 

Macros

#define CAN(NUM)
 

Typedefs

typedef enum bxcan_peripheral bxcan_peripheral_t
 Available bxCAN operation modes.
 
typedef enum bxcan_mode bxcan_mode_t
 Available bxCAN operation modes.
 
typedef enum bxcan_test_mode bxcan_test_mode_t
 Available bxCAN test modes.
 
typedef enum bxcan_fifo_priority bxcan_fifo_priority_t
 Available bxCAN FIFO priorities.
 

Enumerations

enum  bxcan_peripheral { BXCAN_PERIPH_LEN }
 Available bxCAN operation modes.
 
enum  bxcan_mode { BXCAN_MODE_INIT = 0x0 , BXCAN_MODE_NORM , BXCAN_MODE_LPOW }
 Available bxCAN operation modes.
 
enum  bxcan_test_mode { BXCAN_TEST_MODE_NONE = 0x0 , BXCAN_TEST_MODE_LOOP , BXCAN_TEST_MODE_SLNT , BXCAN_TEST_MODE_BOTH }
 Available bxCAN test modes.
 
enum  bxcan_fifo_priority { BXCAN_FIFO_PRIORITY_ID = 0x0 , BXCAN_FIFO_PRIORITY_RQ }
 Available bxCAN FIFO priorities.
 

Functions

void bxcan_set_current_mode (const bxcan_peripheral_t can, const bxcan_mode_t mode)
 Sets the bxCAN to the specified mode.
 
void bxcan_set_test_mode (const bxcan_peripheral_t can, const bxcan_test_mode_t mode)
 Configures bxCAN test mode features.
 
void bxcan_set_time_triggered_mode (const bxcan_peripheral_t can, const _Bool state)
 Sets bxCAN time triggered communication.
 
void bxcan_set_interrupts (const bxcan_peripheral_t can, const struct bxCANISR config)
 Enables the specified bxCAN interrupts.
 
void bxcan_configure_bitrate (const bxcan_peripheral_t can, const struct bxCANBitrateConfig config)
 Configures the bxCAN bitrate according to config.
 
void bxcan_configure_automation (const bxcan_peripheral_t can, const struct bxCANAutomationConfig config)
 Configures the bxCAN automation according to config.
 
void bxcan_configure_fifo (const bxcan_peripheral_t can, const _Bool lock, const bxcan_fifo_priority_t priority)
 Configures the bxCAN FIFO according to config.
 
void bxcan_set_filter_start (const bxcan_peripheral_t can, const uint8_t filters)
 Sets the desired bxCAN filter start bank.
 
void bxcan_configure_filter (const bxcan_peripheral_t can, const uint8_t filter, const struct bxCANFilterConfig config)
 Configures the bxCAN filter according to config.
 
void bxcan_tx_frame (const bxcan_peripheral_t can, struct bxCANFrame *frame)
 Transmits the specified CAN frame.
 
void bxcan_rx_frame_fetch (const bxcan_peripheral_t can, const _Bool FIFO, struct bxCANMailboxRegs *buffer)
 Fetches received CAN frame data.
 
void bxcan_rx_frame_process (const struct bxCANMailboxRegs buffer, struct bxCANFrame *frame)
 Extracts received CAN frame data.
 
const struct bxCANErrorInfo bxcan_get_error_info (const bxcan_peripheral_t can)
 Fetches all CAN errors.
 

Detailed Description

Function prototypes for the bxCAN interface.

This file contains all of the enums, macros, and function prototypes required for a functional CAN interface.

Author
Vasileios Ch. (BillisC)
Bug
None, yet.

Macro Definition Documentation

◆ CAN

#define CAN ( NUM)
Value:
(struct bxCANRegs *)(CAN1_BASE + (0x400UL * (uint8_t)NUM))
Contains bxCAN registers.
Definition bxcan.h:48

Function Documentation

◆ bxcan_configure_automation()

void bxcan_configure_automation ( const bxcan_peripheral_t can,
const struct bxCANAutomationConfig config )

Configures the bxCAN automation according to config.

The configuration options for the auto actions are located in the bxCANAutomationConfig struct. Please note that the AutoReTx is inverted when written in the register.

Parameters
canThe selected CAN
configThe action configuration
Returns
None

◆ bxcan_configure_bitrate()

void bxcan_configure_bitrate ( const bxcan_peripheral_t can,
const struct bxCANBitrateConfig config )

Configures the bxCAN bitrate according to config.

The configuration options for the baudrate is located in the bxCANBitrateConfig struct. Make sure to not exceed the bit limit of the values and to calculate the expected outcome beforehand.

Parameters
canThe selected CAN
configThe baudrate configuration
Returns
None

◆ bxcan_configure_fifo()

void bxcan_configure_fifo ( const bxcan_peripheral_t can,
const _Bool lock,
const bxcan_fifo_priority_t priority )

Configures the bxCAN FIFO according to config.

The available priorities for the FIFOs are available in the bxcan_fifo_priority_t enum.

Parameters
canThe selected CAN
lockWhether the FIFO locks on overrun
priorityThe FIFO priority
Returns
None

◆ bxcan_configure_filter()

void bxcan_configure_filter ( const bxcan_peripheral_t can,
const uint8_t filter,
const struct bxCANFilterConfig config )

Configures the bxCAN filter according to config.

The configuration options for the filter banks are located in the bxCANFilterConfig struct. The ID and Mask ID fields are represented by two 16-bit uints each, with the 0 index being the lower nibble. The filter initialization mode will be termporarily enabled to apply the requested changes.

Parameters
canThe selected CAN
filterThe selected filter (0..27)
configThe filter configuration
Returns
None

◆ bxcan_get_error_info()

const struct bxCANErrorInfo bxcan_get_error_info ( const bxcan_peripheral_t can)

Fetches all CAN errors.

The error data are stored in a bxCANErrorInfo struct.

Parameters
canThe selected CAN
Returns
Error information data

◆ bxcan_rx_frame_fetch()

void bxcan_rx_frame_fetch ( const bxcan_peripheral_t can,
const _Bool FIFO,
struct bxCANMailboxRegs * buffer )
inline

Fetches received CAN frame data.

The data of the frame are fetched in the struct as soon as one of the FIFOs have a pending message. It is recommended to pair this with interrupts, otherwise it might be too slow. The frame configuration can be found under the bxCANFrame struct.

Parameters
canThe selected CAN
FIFOThe selected FIFO (Bool because it limits to 0..1)
bufferPointer to the Mailbox buffer
Returns
None

◆ bxcan_rx_frame_process()

void bxcan_rx_frame_process ( const struct bxCANMailboxRegs buffer,
struct bxCANFrame * frame )

Extracts received CAN frame data.

The data of the register buffer are extracted in the frame struct. The frame configuration can be found under the bxCANFrame struct.

Parameters
bufferThe Mailbox buffer
framePointer to the frame structure
Returns
None

◆ bxcan_set_current_mode()

void bxcan_set_current_mode ( const bxcan_peripheral_t can,
const bxcan_mode_t mode )

Sets the bxCAN to the specified mode.

The available operation modes for CAN are specified in the bxcan_mode_t enum. Any other value will be ignored.

Parameters
canThe selected CAN
modeThe selected mode
Returns
None

◆ bxcan_set_filter_start()

void bxcan_set_filter_start ( const bxcan_peripheral_t can,
const uint8_t filters )

Sets the desired bxCAN filter start bank.

If the MCU has a single CAN this function does nothing. Otherwise a 6-bit filter number may be set to change the amount of filters allowed for CAN1 and CAN2 peripherals. Consult the reference manual to set this appropriately. Any value above six bits will be ignored.

Parameters
canThe selected CAN
filtersThe CAN start bank
Returns
None

◆ bxcan_set_interrupts()

void bxcan_set_interrupts ( const bxcan_peripheral_t can,
const struct bxCANISR config )

Enables the specified bxCAN interrupts.

The available interrupts are located in the bxCANISR struct.

Parameters
canThe selected CAN
configThe ISR config
Returns
None

◆ bxcan_set_test_mode()

void bxcan_set_test_mode ( const bxcan_peripheral_t can,
const bxcan_test_mode_t mode )

Configures bxCAN test mode features.

The available test modes for CAN are specified in the bxcan_test_mode_t enum. Any other value will be ignored.

Parameters
canThe selected CAN
modeThe selected test mode
Returns
None

◆ bxcan_set_time_triggered_mode()

void bxcan_set_time_triggered_mode ( const bxcan_peripheral_t can,
const _Bool state )

Sets bxCAN time triggered communication.

Parameters
canThe selected CAN
stateOn/off switch
Returns
None

◆ bxcan_tx_frame()

void bxcan_tx_frame ( const bxcan_peripheral_t can,
struct bxCANFrame * frame )

Transmits the specified CAN frame.

The frame is put in one of the transmit mailboxes and gets sent afterwards in the bus. The frame configuration can be found under the bxCANFrame struct.

Parameters
canThe selected CAN
framePointer to the bxCAN frame
Returns
None