candev_mcp2515.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 OTA keys S.A.
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
27 #include <stdbool.h>
28 
29 #include "can/candev.h"
30 #include "cpu_conf.h"
31 #include "periph/gpio.h"
32 #include "periph/spi.h"
33 #include "mutex.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
42 #ifndef CANDEV_MCP2515_DEFAULT_BITRATE
43 #define CANDEV_MCP2515_DEFAULT_BITRATE 500000
44 #endif
45 
49 #ifndef CANDEV_MCP2515_DEFAULT_SPT
50 #define CANDEV_MCP2515_DEFAULT_SPT 875
51 #endif
52 
56 #define MCP2515_TX_MAILBOXES 3
57 
78 #define MCP2515_RX_MAILBOXES 2
79 #define MCP2515_FILTERS_MB0 2
80 #define MCP2515_FILTERS_MB1 4
81 #define MCP2515_FILTERS (MCP2515_FILTERS_MB0 + MCP2515_FILTERS_MB1)
85 typedef struct candev_mcp2515 candev_mcp2515_t;
86 
90 typedef struct candev_mcp2515_conf {
91  spi_t spi;
94  gpio_t cs_pin;
95  gpio_t rst_pin;
96  gpio_t int_pin;
97  uint32_t clk;
99 
111  struct can_frame rx_buf[MCP2515_RX_MAILBOXES];
113  uint32_t masks[MCP2515_RX_MAILBOXES];
115  canid_t filter_ids[MCP2515_RX_MAILBOXES][MCP2515_FILTERS_MB1];
118 };
119 
128  const candev_mcp2515_conf_t *conf);
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
spi_clk_t
Definition: periph_cpu.h:351
Definitions for low-level CAN driver interface.
Low-level GPIO peripheral driver interface definitions.
#define MCP2515_TX_MAILBOXES
Number of transmit mailboxes.
void candev_mcp2515_init(candev_mcp2515_t *dev, const candev_mcp2515_conf_t *conf)
Initialize a mcp2515 device by assigning a timing and an SPI configuration conf.
struct candev_mcp2515_conf candev_mcp2515_conf_t
MCP2515 configuration descriptor.
uint32_t canid_t
Controller Area Network Identifier structure.
Definition: can.h:95
spi_mode_t
Support SPI modes.
Definition: periph_cpu.h:42
Mutex for thread synchronization.
Low-level SPI peripheral driver interface definition.
Controller Area Network frame.
Definition: can.h:100
MCP2515 configuration descriptor.
gpio_t cs_pin
Slave select pin.
uint32_t clk
External clock frequency.
gpio_t rst_pin
Reset pin.
spi_clk_t spi_clk
SPI clock speed.
spi_t spi
SPI bus.
gpio_t int_pin
Interrupt pin.
spi_mode_t spi_mode
SPI mode.
MCP2515 device descriptor.
struct can_frame rx_buf[MCP2515_RX_MAILBOXES]
rx mailboxes local copy
canid_t filter_ids[MCP2515_RX_MAILBOXES][MCP2515_FILTERS_MB1]
filters list
candev_t candev
candev driver
int wakeup_src
wakeup source
const candev_mcp2515_conf_t * conf
driver configuration
const struct can_frame * tx_mailbox[MCP2515_TX_MAILBOXES]
tx mailboxes local copy
uint32_t masks[MCP2515_RX_MAILBOXES]
masks list
Structure to hold driver state.
Definition: candev.h:76