microHAL
An abstraction layer for your future F4xx projects
|
Function prototypes for the bxCAN interface. More...
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. | |
Function prototypes for the bxCAN interface.
This file contains all of the enums, macros, and function prototypes required for a functional CAN interface.
#define CAN | ( | NUM | ) |
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.
can | The selected CAN |
config | The action configuration |
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.
can | The selected CAN |
config | The baudrate configuration |
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.
can | The selected CAN |
lock | Whether the FIFO locks on overrun |
priority | The FIFO priority |
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.
can | The selected CAN |
filter | The selected filter (0..27) |
config | The filter configuration |
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.
can | The selected CAN |
|
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.
can | The selected CAN |
FIFO | The selected FIFO (Bool because it limits to 0..1) |
buffer | Pointer to the Mailbox buffer |
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.
buffer | The Mailbox buffer |
frame | Pointer to the frame structure |
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.
can | The selected CAN |
mode | The selected mode |
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.
can | The selected CAN |
filters | The CAN start bank |
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.
can | The selected CAN |
config | The ISR config |
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.
can | The selected CAN |
mode | The selected test mode |
void bxcan_set_time_triggered_mode | ( | const bxcan_peripheral_t | can, |
const _Bool | state ) |
Sets bxCAN time triggered communication.
can | The selected CAN |
state | On/off switch |
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.
can | The selected CAN |
frame | Pointer to the bxCAN frame |