Midnight Sun Firmware
Loading...
Searching...
No Matches
can_hw.h
1#pragma once
2
3/************************************************************************************************
4 * @file can_hw.h
5 *
6 * @brief Header file for CAN HW Interface
7 *
8 * @date 2024-11-03
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14#include <stddef.h>
15#include <stdint.h>
16
17/* Inter-component Headers */
18#include "gpio.h"
19#include "status.h"
20
21/* Intra-component Headers */
22#include "can_queue.h"
23
30#ifdef CAN_HW_DEV_USE_CAN0
31#define CAN_HW_DEV_INTERFACE "can0"
32#else
33#define CAN_HW_DEV_INTERFACE "vcan0"
34#endif
35
37typedef enum {
42
55typedef enum {
62
71typedef struct CanSettings {
72 uint16_t device_id;
76 bool loopback;
77 bool silent;
79
88StatusCode can_hw_init(const CanQueue* rx_queue, const CanSettings *settings);
89
100StatusCode can_hw_add_filter_in(uint32_t mask, uint32_t filter, bool extended);
101
109
120StatusCode can_hw_transmit(uint32_t id, bool extended, const uint8_t *data, size_t len);
121
131bool can_hw_receive(uint32_t *id, bool *extended, uint64_t *data, size_t *len);
132
bool can_hw_receive(uint32_t *id, bool *extended, uint64_t *data, size_t *len)
Receives CAN data from the bus.
Definition: can_hw.c:225
StatusCode can_hw_transmit(uint32_t id, bool extended, const uint8_t *data, size_t len)
Transmits CAN data on the bus.
Definition: can_hw.c:189
StatusCode can_hw_add_filter_in(uint32_t mask, uint32_t filter, bool extended)
Sets a filter on the CAN interface.
Definition: can_hw.c:157
CanHwBusStatus can_hw_bus_status(void)
Fetches the CAN bus status.
Definition: can_hw.c:177
StatusCode can_hw_init(const CanQueue *rx_queue, const CanSettings *settings)
Initialize the CAN interface.
Definition: can_hw.c:90
CanHwBusStatus
CAN Bus status flags.
Definition: can_hw.h:37
CanHwBitrate
Selection for the supported CAN Bitrates.
Definition: can_hw.h:55
@ CAN_HW_BUS_STATUS_OK
Definition: can_hw.h:38
@ CAN_HW_BUS_STATUS_ERROR
Definition: can_hw.h:39
@ CAN_HW_BUS_STATUS_OFF
Definition: can_hw.h:40
@ CAN_HW_BITRATE_500KBPS
Definition: can_hw.h:58
@ CAN_HW_BITRATE_1000KBPS
Definition: can_hw.h:59
@ CAN_HW_BITRATE_125KBPS
Definition: can_hw.h:56
@ CAN_HW_BITRATE_250KBPS
Definition: can_hw.h:57
@ NUM_CAN_HW_BITRATES
Definition: can_hw.h:60
StatusCode
StatusCodes for various errors.
Definition: status.h:27
CAN queue data structure to store received CAN messages.
Definition: can_queue.h:34
CAN Settings.
Definition: bootloader_can.h:58
bool loopback
Definition: bootloader_can.h:61
CanHwBitrate bitrate
Definition: can_hw.h:73
GpioAddress rx
Definition: can_hw.h:75
bool silent
Definition: bootloader_can.h:62
uint16_t device_id
Definition: bootloader_can.h:59
GpioAddress tx
Definition: can_hw.h:74
Port and pin data.
Definition: gpio.h:112