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 
25 #ifndef CANDEV_MCP2515_H
26 #define CANDEV_MCP2515_H
27 
28 #include <stdbool.h>
29 
30 #include "can/candev.h"
31 #include "cpu_conf.h"
32 #include "periph/gpio.h"
33 #include "periph/spi.h"
34 #include "mutex.h"
35 #include "xtimer.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
44 #ifndef CANDEV_MCP2515_DEFAULT_BITRATE
45 #define CANDEV_MCP2515_DEFAULT_BITRATE 125000
46 #endif
47 
51 #ifndef CANDEV_MCP2515_DEFAULT_SPT
52 #define CANDEV_MCP2515_DEFAULT_SPT 875
53 #endif
54 
58 #define MCP2515_TX_MAILBOXES 3
59 
80 #define MCP2515_RX_MAILBOXES 2
81 #define MCP2515_FILTERS_MB0 2
82 #define MCP2515_FILTERS_MB1 4
83 #define MCP2515_FILTERS (MCP2515_FILTERS_MB0 + MCP2515_FILTERS_MB1)
84 
88 
92 typedef struct candev_mcp2515_conf {
96  gpio_t cs_pin;
97  gpio_t rst_pin;
98  gpio_t int_pin;
99  uint32_t clk;
101 
113  struct can_frame rx_buf[MCP2515_RX_MAILBOXES];
115  uint32_t masks[MCP2515_RX_MAILBOXES];
117  canid_t filter_ids[MCP2515_RX_MAILBOXES][MCP2515_FILTERS_MB1];
120 };
121 
130  const candev_mcp2515_conf_t *conf);
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif /* CANDEV_MCP2515_H */
137 
candev_mcp2515_conf_t
struct candev_mcp2515_conf candev_mcp2515_conf_t
MCP2515 configuration descriptor.
candev
Structure to hold driver state.
Definition: candev.h:78
spi.h
Low-level SPI peripheral driver interface definition.
candev_mcp2515_conf::cs_pin
gpio_t cs_pin
Slave select pin.
Definition: candev_mcp2515.h:96
candev_mcp2515::conf
const candev_mcp2515_conf_t * conf
driver configuration
Definition: candev_mcp2515.h:109
candev_mcp2515::tx_mailbox
const struct can_frame * tx_mailbox[MCP2515_TX_MAILBOXES]
tx mailboxes local copy
Definition: candev_mcp2515.h:111
candev_mcp2515_conf::int_pin
gpio_t int_pin
Interrupt pin.
Definition: candev_mcp2515.h:98
spi_mode_t
spi_mode_t
Available SPI modes, defining the configuration of clock polarity and clock phase.
Definition: spi.h:157
candev_mcp2515::masks
uint32_t masks[MCP2515_RX_MAILBOXES]
masks list
Definition: candev_mcp2515.h:115
candev_mcp2515_conf::spi_clk
spi_clk_t spi_clk
SPI clock speed.
Definition: candev_mcp2515.h:95
candev_mcp2515::candev
candev_t candev
candev driver
Definition: candev_mcp2515.h:107
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
can_frame
Controller Area Network frame.
Definition: can.h:88
candev_mcp2515_conf::rst_pin
gpio_t rst_pin
Reset pin.
Definition: candev_mcp2515.h:97
candev_mcp2515_init
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.
candev_mcp2515_conf::spi
spi_t spi
SPI bus.
Definition: candev_mcp2515.h:93
candev.h
Definitions for low-level CAN driver interface.
candev_mcp2515::rx_buf
struct can_frame rx_buf[MCP2515_RX_MAILBOXES]
rx mailboxes local copy
Definition: candev_mcp2515.h:113
candev_mcp2515::wakeup_src
int wakeup_src
wakeup source
Definition: candev_mcp2515.h:119
mutex.h
Mutex for thread synchronization.
candev_mcp2515_conf
MCP2515 configuration descriptor.
Definition: candev_mcp2515.h:92
candev_mcp2515::filter_ids
canid_t filter_ids[MCP2515_RX_MAILBOXES][MCP2515_FILTERS_MB1]
filters list
Definition: candev_mcp2515.h:117
gpio.h
Low-level GPIO peripheral driver interface definitions.
candev_mcp2515_conf::spi_mode
spi_mode_t spi_mode
SPI mode.
Definition: candev_mcp2515.h:94
candev_mcp2515
MCP2515 device descriptor.
Definition: candev_mcp2515.h:105
candev_mcp2515_conf::clk
uint32_t clk
External clock frequency.
Definition: candev_mcp2515.h:99
MCP2515_TX_MAILBOXES
#define MCP2515_TX_MAILBOXES
Number of transmit mailboxes.
Definition: candev_mcp2515.h:58
xtimer.h
xtimer interface definitions
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
canid_t
uint32_t canid_t
Controller Area Network Identifier structure.
Definition: can.h:83