Midnight Sun Firmware
Loading...
Searching...
No Matches
mcp2515_hw.h
1#pragma once
2
3/************************************************************************************************
4 * @file mcp2515_hw.h
5 *
6 * @brief Header file for MCP2515 hardware
7 *
8 * @date 2025-01-31
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13
14/* Inter-component Headers */
15#include "can_hw.h"
16#include "can_msg.h"
17#include "can_queue.h"
18#include "gpio.h"
19#include "spi.h"
20
21/* Intra-component Headers */
22
29// SPI commands: Table 12-1
30typedef struct Mcp2515Errors {
31 uint8_t eflg;
32 uint8_t tec;
33 uint8_t rec;
35
36typedef struct Mcp2515Settings {
37 SpiPort spi_port;
38 SpiSettings spi_settings;
39
40 GpioAddress interrupt_pin;
41 GpioAddress RX0BF;
42 GpioAddress RX1BF;
43
44 // same can settings except MCP2515 does not support 1000kbps bitrate
45 CanSettings can_settings;
47
48typedef struct Mcp2515Storage {
49 SpiPort spi_port;
50 volatile CanQueue rx_queue;
51 Mcp2515Errors errors;
52 bool loopback;
54
55// Initializes CAN using the specified settings.
56StatusCode mcp2515_hw_init(Mcp2515Storage *rx_queue, const Mcp2515Settings *settings);
57
58// StatusCode mcp2515_hw_add_filter_in(uint32_t mask, uint32_t filter, bool extended);
59
60StatusCode mcp2515_hw_set_filter(CanMessageId *filters, bool loopback);
61
62CanHwBusStatus mcp2515_hw_bus_status(void);
63
64StatusCode mcp2515_hw_transmit(uint32_t id, bool extended, uint8_t *data, size_t len);
65
uint32_t CanMessageId
CAN message ID.
Definition: can_msg.h:35
CanHwBusStatus
CAN Bus status flags.
Definition: can_hw.h:37
SpiPort
SPI Port selection.
Definition: spi.h:34
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:66
Port and pin data.
Definition: gpio.h:112
Definition: mcp2515_hw.h:30
Definition: mcp2515_hw.h:36
Definition: mcp2515_hw.h:48
SPI settings struct.
Definition: spi.h:76