1#include <avr/interrupt.h>
38 EMCUCR &= ~(1 << ISC2);
53 uint32_t
id = msg.
id & 0x1FFFFFFF;
55 uint8_t EID0 =
id & 0xFF;
56 uint8_t EID8 = (
id >> 8) & 0xFF;
57 uint8_t SIDL = ((
id >> 16) & 0x03)
59 | ((
id >> 18) & 0xE0);
60 uint8_t SIDH = (
id >> 21) & 0xFF;
67 uint8_t ID_MSB = (0x7F8 & msg.
id) >> 3;
68 uint8_t ID_LSB = (0x7 & msg.
id) << 5;
77 if ((buff0_status & 0x8) != 0x8) {
79 LOG_ERR(
"TX Buffer0 overflow, message too large", -2);
82 for (uint8_t i = 0; i < msg.
dlc; i++) {
110 ID_LSB = (ID_LSB & 0xE0) >> 5;
111 out->
id = (ID_MSB << 3) | (ID_LSB & 0x7);
114 out->
dlc = (length & 0xF);
119 for (uint8_t i = 0; i < out->
dlc; i++) {
142 ID_LSB = (ID_LSB & 0xE0) >> 5;
143 out->
id = (ID_MSB << 3) | (ID_LSB & 0x7);
146 out->
dlc = (length & 0xF);
151 for (uint8_t i = 0; i < out->
dlc; i++) {
233 LOG_ERR(
"SPI to CAN controller is not in configuration mode after reset!",
240 LOG_ERR(
"There is an interrupt request when booting the SPI-CAN controller",
253 LOG_ERR(
"Couldnt configure MCP2515 RX0 Buffer", -3);
261 LOG_ERR(
"Couldnt configure MCP2515 RX1", -4);
273 EMCUCR &= ~(1 << ISC2);
279 LOG_ERR(
"Couldnt set IRQ config for MCP2515", -5);
290 LOG_ERR(
"Couldnt configure BRP for MCP2515", -6);
310 LOG_ERR(
"MCP2515 could not be set to NORMAL mode when init completed", -9);
static volatile uint8_t rxq_head
struct can_device * can_irq
int8_t MCP2515_write_n(struct can_device *dev, uint8_t addr, uint8_t *data)
struct CAN_frame new_message
struct CAN_frame rxq[CAN_RXQ_SIZE]
static volatile uint8_t rxq_tail
int can_rxq_add(struct CAN_frame *msg)
Add a CAN frame to the internal receive queue.
int8_t can_write(struct can_device *dev, struct CAN_frame msg)
Write a CAN frame to the MCP2515 transmit buffer.
int8_t MCP2515_read_status(struct can_device *dev, uint8_t *out)
int8_t MCP2515_bit_modify(struct can_device *dev, uint8_t reg, uint8_t mask, uint8_t set_val)
int8_t MCP2515_request_to_send(struct can_device *dev, uint8_t buffer)
int8_t can_init(struct can_device *dev)
Initialize a CAN device.
int8_t can_read_rx1(struct can_device *dev, struct CAN_frame *out)
Read a message from RX buffer 1.
int8_t MCP2515_read(struct can_device *dev, uint8_t addr, uint8_t *out)
int8_t MCP2515_write(struct can_device *dev, uint8_t addr, uint8_t data)
int8_t MCP2515_init(struct can_device *dev)
int can_rxq_pull(struct CAN_frame *out)
Pull a CAN frame from the internal receive queue.
int8_t MCP2515_reset(struct can_device *dev)
int8_t can_read_rx0(struct can_device *dev, struct CAN_frame *out)
Read a message from RX buffer 0.
#define LOG_ERR(msg, status)
#define LOG_MODULE_DEFINE(name)
int spi_send_n(enum spi_slave *slave, unsigned char *data, int length)
Send a sequence of bytes to a slave without reading response.
int spi_ready(void)
Check if the SPI subsystem is initialized.
int spi_duplex(enum spi_slave *slave, unsigned char *data, unsigned char *out, int length)
Full-duplex SPI transfer.
int spi_send(enum spi_slave *slave, unsigned char data)
Send a single byte to a slave.
int spi_init(void)
Initialize SPI in master mode.
Logging interface for debug messages.
#define CAN_INTERRUPT_ISR_REGISTER
#define MCP2515_TXRTS_CONF
#define MCP2515_TXRTSCTRL
#define MCP2515_READ_STATUS
Represents a full CAN frame for sending/receiving.
Represents a CAN device, storing the SPI slave controlling the MCP2515.