Midnight Sun Firmware
|
CAN library. More...
Classes | |
struct | CanStorage |
Storage class for the device ID and RX data. More... | |
struct | CanSettings |
CAN Settings. More... | |
union | CanId |
CAN message ID. More... | |
struct | CanMessage |
CAN message structure. More... | |
struct | CanQueue |
CAN queue data structure to store received CAN messages. More... | |
struct | CanWatchDog |
Software defined CAN watchdog. More... | |
Macros | |
#define | CAN_TIMEOUT_MS 5U |
Maximum time permitted for a CAN transaction. | |
#define | CAN_HW_DEV_INTERFACE "vcan0" |
#define | CAN_MSG_MAX_STD_IDS (1 << 11) |
Maximum permitted CAN ID for 11-bit identifiers. | |
#define | CAN_QUEUE_SIZE 64U |
Maximum number of CAN messages permitted for the CAN queue. | |
#define | can_queue_init(can_queue) |
#define | can_queue_push(can_queue, source) queue_send(&(can_queue)->queue, (source), 0) |
#define | can_queue_push_from_isr(can_queue, source, high_prio_woken) queue_send_from_isr(&(can_queue)->queue, (source), high_prio_woken) |
#define | can_queue_peek(can_queue, dest) queue_peek(&(can_queue)->queue, (dest), 0) |
#define | can_queue_pop(can_queue, dest) queue_receive(&(can_queue)->queue, (dest), 0) |
#define | can_queue_pop_from_isr(can_queue, dest, higher_prio_woken) queue_receive_from_isr(&(can_queue)->queue, (dest), high_prio_woken) |
#define | can_queue_size(can_queue) queue_get_num_items(&(can_queue)->queue) |
Typedefs | |
typedef struct CanStorage | CanStorage |
Storage class for the device ID and RX data. | |
typedef struct CanSettings | CanSettings |
CAN Settings. More... | |
typedef uint32_t | CanMessageId |
CAN message ID. More... | |
typedef union CanId | CanId |
CAN message ID. | |
typedef struct CanMessage | CanMessage |
CAN message structure. More... | |
typedef struct CanQueue | CanQueue |
CAN queue data structure to store received CAN messages. More... | |
typedef struct CanWatchDog | CanWatchDog |
Software defined CAN watchdog. | |
Enumerations | |
enum | CanHwBusStatus { CAN_HW_BUS_STATUS_OK = 0 , CAN_HW_BUS_STATUS_ERROR , CAN_HW_BUS_STATUS_OFF } |
CAN Bus status flags. More... | |
enum | CanHwBitrate { CAN_HW_BITRATE_125KBPS , CAN_HW_BITRATE_250KBPS , CAN_HW_BITRATE_500KBPS , CAN_HW_BITRATE_1000KBPS , NUM_CAN_HW_BITRATES } |
Selection for the supported CAN Bitrates. More... | |
Functions | |
StatusCode | can_init (CanStorage *storage, const CanSettings *settings) |
Initialize the CAN interface. More... | |
StatusCode | can_add_filter_in (CanMessageId msg_id) |
Sets a filter on the CAN interface. More... | |
StatusCode | can_transmit (const CanMessage *msg) |
Transmits CAN data on the bus. More... | |
StatusCode | can_receive (const CanMessage *msg) |
Receives CAN data from the bus. More... | |
StatusCode | run_can_tx_all () |
Transmit all CAN data. More... | |
StatusCode | run_can_tx_fast () |
Transmit all fast-cycle CAN data. More... | |
StatusCode | run_can_tx_medium () |
Transmit all medium-cycle CAN data. More... | |
StatusCode | run_can_tx_slow () |
Transmit all slow-cycle CAN data. More... | |
StatusCode | run_can_rx_all () |
Receive all CAN data. More... | |
StatusCode | clear_rx_struct () |
Clear the RX data struct. More... | |
StatusCode | clear_tx_struct () |
Clear the TX data struct. More... | |
StatusCode | can_hw_init (const CanQueue *rx_queue, const CanSettings *settings) |
Initialize the CAN interface. More... | |
StatusCode | can_hw_add_filter_in (uint32_t mask, uint32_t filter, bool extended) |
Sets a filter on the CAN interface. More... | |
CanHwBusStatus | can_hw_bus_status (void) |
Fetches the CAN bus status. More... | |
StatusCode | can_hw_transmit (uint32_t id, bool extended, const uint8_t *data, size_t len) |
Transmits CAN data on the bus. More... | |
bool | can_hw_receive (uint32_t *id, bool *extended, uint64_t *data, size_t *len) |
Receives CAN data from the bus. More... | |
StatusCode | check_all_can_watchdogs () |
Checks all CAN watchdogs. More... | |
StatusCode | check_fast_can_watchdogs () |
Checks CAN watchdogs for messages in fast-cycle. More... | |
StatusCode | check_medium_can_watchdogs () |
Checks CAN watchdogs for messages in medium-cycle. More... | |
StatusCode | check_slow_can_watchdogs () |
Checks CAN watchdogs for messages in slow-cycle. More... | |
void | clear_all_rx_received () |
void | clear_fast_rx_received () |
void | clear_medium_rx_received () |
void | clear_slow_rx_received () |
CAN library.
#define can_queue_init | ( | can_queue | ) |
typedef struct CanMessage CanMessage |
CAN message structure.
CAN ID is subjected to arbitration where lower ID's are given higher priority Extended ID flag indicates a 29-bit ID or an 11-bit ID Data length code ias 4 bit value indicating the number of bytes in the payload CAN Frames hold 8 bytes of data at most
typedef uint32_t CanMessageId |
CAN message ID.
11 Bits in standard mode 29 Bits in extended mode
typedef struct CanSettings CanSettings |
CAN Settings.
TX Pin will transmit data. RX pin will receive data. The bitrate is the number of bits sent per second. The device ID is the CAN ID of the STM32 node. Loopback will internally connect the transmit and receive CAN lines for testing. Silent mode is used for only listening to the bus.
enum CanHwBitrate |
Selection for the supported CAN Bitrates.
CAN bit timing is composed of multiple time segments:
enum CanHwBusStatus |
StatusCode can_add_filter_in | ( | CanMessageId | msg_id | ) |
Sets a filter on the CAN interface.
msg_id | Message ID of the message to filter |
StatusCode can_hw_add_filter_in | ( | uint32_t | mask, |
uint32_t | filter, | ||
bool | extended | ||
) |
Sets a filter on the CAN interface.
The filter works as such: if INCOMING_MSG_ID & mask == filter & mask, the message is handled
mask | Determines which bits in the received ID are considered during filtering |
filter | Specifies the pattern the CAN ID must adhere to |
extended | Boolean to use CAN extended ID feature |
CanHwBusStatus can_hw_bus_status | ( | void | ) |
Fetches the CAN bus status.
StatusCode can_hw_init | ( | const CanQueue * | rx_queue, |
const CanSettings * | settings | ||
) |
Initialize the CAN interface.
rx_queue | Pointer to the CAN RX queue |
settings | Pointer to the CAN settings |
bool can_hw_receive | ( | uint32_t * | id, |
bool * | extended, | ||
uint64_t * | data, | ||
size_t * | len | ||
) |
Receives CAN data from the bus.
id | Pointer to store the CAN ID received |
extended | Pointer to a flag to indicate CAN extended ID feature |
data | Pointer to a buffer to store data |
len | Pointer to the number of CAN messages received |
StatusCode can_hw_transmit | ( | uint32_t | id, |
bool | extended, | ||
const uint8_t * | data, | ||
size_t | len | ||
) |
Transmits CAN data on the bus.
id | CAN message ID |
extended | Boolean to use CAN extended ID feature |
data | Pointer to the data to transmit |
len | Size of the data to transfer |
StatusCode can_init | ( | CanStorage * | storage, |
const CanSettings * | settings | ||
) |
Initialize the CAN interface.
storage | Pointer to the CAN storage |
settings | Pointer to the CAN settings |
StatusCode can_receive | ( | const CanMessage * | msg | ) |
Receives CAN data from the bus.
msg | Pointer to the message to update on receive |
StatusCode can_transmit | ( | const CanMessage * | msg | ) |
Transmits CAN data on the bus.
msg | Pointer to the message to transmit |
StatusCode check_all_can_watchdogs | ( | ) |
Checks all CAN watchdogs.
This will throw a LOG_WARN if a message has missed its watchdog
StatusCode check_fast_can_watchdogs | ( | ) |
Checks CAN watchdogs for messages in fast-cycle.
This will throw a LOG_WARN if a message has missed its watchdog
StatusCode check_medium_can_watchdogs | ( | ) |
Checks CAN watchdogs for messages in medium-cycle.
This will throw a LOG_WARN if a message has missed its watchdog
StatusCode check_slow_can_watchdogs | ( | ) |
Checks CAN watchdogs for messages in slow-cycle.
This will throw a LOG_WARN if a message has missed its watchdog
StatusCode clear_rx_struct | ( | ) |
Clear the RX data struct.
StatusCode clear_tx_struct | ( | ) |
Clear the TX data struct.
StatusCode run_can_rx_all | ( | ) |
Receive all CAN data.
StatusCode run_can_tx_all | ( | ) |
Transmit all CAN data.
StatusCode run_can_tx_fast | ( | ) |
Transmit all fast-cycle CAN data.
StatusCode run_can_tx_medium | ( | ) |
Transmit all medium-cycle CAN data.
StatusCode run_can_tx_slow | ( | ) |
Transmit all slow-cycle CAN data.