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 
21 #ifndef MCP2515_H
22 #define MCP2515_H
23 
24 #include "mcp2515_defines.h"
25 #include "candev_mcp2515.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
35  MODE_NORMAL = MCP2515_CANSTAT_OPMOD_NORMAL,
36  MODE_SLEEP = MCP2515_CANSTAT_OPMOD_SLEEP,
37  MODE_LOOPBACK = MCP2515_CANSTAT_OPMOD_LOOPBACK,
38  MODE_LISTEN_ONLY = MCP2515_CANSTAT_OPMOD_LISTEN_ONLY,
39  MODE_CONFIG = MCP2515_CANSTAT_OPMOD_CONFIGURATION,
40  MODE_UNKNOWN = -1
41 };
42 
47  INT_RX0 = MCP2515_CANINTF_RX0IF,
48  INT_RX1 = MCP2515_CANINTF_RX1IF,
49  INT_TX0 = MCP2515_CANINTF_TX0IF,
50  INT_TX1 = MCP2515_CANINTF_TX1IF,
51  INT_TX2 = MCP2515_CANINTF_TX2IF,
52  INT_ERROR = MCP2515_CANINTF_ERRIF,
53  INT_WAKEUP = MCP2515_CANINTF_WAKIF,
54  INT_MESSAGE_ERROR = MCP2515_CANINTF_MERRF,
55 };
56 
61  ERR_WARNING = MCP2515_EFLG_EWARN,
62  ERR_RX_WARNING = MCP2515_EFLG_RXWAR,
63  ERR_TX_WARNING = MCP2515_EFLG_TXWAR,
64  ERR_RX_PASSIVE = MCP2515_EFLG_RXEP,
65  ERR_TX_PASSIVE = MCP2515_EFLG_TXEP,
66  ERR_TX_BUS_OFF = MCP2515_EFLG_TXBO,
67  ERR_RX_0_OVERFLOW = MCP2515_EFLG_RX0OVR,
68  ERR_RX_1_OVERFLOW = MCP2515_EFLG_RX1OVR,
69 };
70 
72 #define MCP2515_WKUP_SRC_INTERNAL 1
73 
90 int mcp2515_init(candev_mcp2515_t *dev, void (*irq_cb)(void *));
91 
100 
110 
121 int mcp2515_send(candev_mcp2515_t *dev, const struct can_frame *frame,
122  int mailbox);
123 
134 int mcp2515_receive(candev_mcp2515_t *dev, struct can_frame *frame,
135  int mailbox);
136 
146 int mcp2515_abort(candev_mcp2515_t *dev, int mailbox);
147 
156 
166  enum mcp2515_mode mode);
167 
174 
183 
194 
204 int mcp2515_tx_err_occurred(candev_mcp2515_t *dev, int mailbox);
205 
217 
226 
258 int mcp2515_set_filter(candev_mcp2515_t *dev, int filter_id, uint32_t filter);
259 
287 int mcp2515_set_mask(candev_mcp2515_t *dev, int mailbox, uint32_t mask);
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 
293 #endif /* MCP2515_H */
294 
mcp2515_send
int mcp2515_send(candev_mcp2515_t *dev, const struct can_frame *frame, int mailbox)
Send frame through the corresponding tx mailbox.
mcp2515_mode
mcp2515_mode
MCP2515 mode.
Definition: mcp2515.h:34
mcp2515_get_irq
enum mcp2515_interrupt mcp2515_get_irq(candev_mcp2515_t *dev)
Get MCP2515 interrupt type.
mcp2515_receive
int mcp2515_receive(candev_mcp2515_t *dev, struct can_frame *frame, int mailbox)
Receive frame from the corresponding rx mailbox.
mcp2515_get_mode
enum mcp2515_mode mcp2515_get_mode(candev_mcp2515_t *dev)
Get MCP2515 mode of operation.
mcp2515_interrupt
mcp2515_interrupt
MCP2515 interrupt.
Definition: mcp2515.h:46
candev_mcp2515.h
Definition of the implementation of the CAN controller driver.
mcp2515_set_filter
int mcp2515_set_filter(candev_mcp2515_t *dev, int filter_id, uint32_t filter)
Set the @ filter_id to the position in the mailbox.
mcp2515_abort
int mcp2515_abort(candev_mcp2515_t *dev, int mailbox)
Abort communication.
mcp2515_init_irqs
int mcp2515_init_irqs(candev_mcp2515_t *dev)
Initialize MCP2515 interrupts.
can_frame
Controller Area Network frame.
Definition: can.h:88
mcp2515_set_mode
enum mcp2515_mode mcp2515_set_mode(candev_mcp2515_t *dev, enum mcp2515_mode mode)
Set MCP2515 mode of operation.
mcp2515_error
mcp2515_error
MCP2515 error.
Definition: mcp2515.h:60
mcp2515_set_mask
int mcp2515_set_mask(candev_mcp2515_t *dev, int mailbox, uint32_t mask)
Set the @ mask to the mailbox.
mcp2515_configure_bittiming
int mcp2515_configure_bittiming(candev_mcp2515_t *dev)
Configure the bit timing of the MCP2515.
mcp2515_get_errors
uint8_t mcp2515_get_errors(candev_mcp2515_t *dev)
Get the error flags.
mcp2515_init
int mcp2515_init(candev_mcp2515_t *dev, void(*irq_cb)(void *))
Initialize pins and SPI interface.
candev_mcp2515
MCP2515 device descriptor.
Definition: candev_mcp2515.h:105
mcp2515_clear_irq
int mcp2515_clear_irq(candev_mcp2515_t *dev, enum mcp2515_interrupt irq)
Clear MCP2515 interrupt.
mcp2515_reset
void mcp2515_reset(candev_mcp2515_t *dev)
Reset MCP2515 device with dedicated pin.
mcp2515_wake_up
void mcp2515_wake_up(candev_mcp2515_t *dev)
Wake up MCP2515.
mcp2515_defines.h
Driver for the Microchip MCP2515 can controller.
mcp2515_tx_err_occurred
int mcp2515_tx_err_occurred(candev_mcp2515_t *dev, int mailbox)
Get if an tx error occurred on MCP2515.