Driver for the Microchip MCP2515 can controller. More...
Driver for the Microchip MCP2515 can controller.
Definition of the MCP2515 CAN controller driver.
Definition in file mcp2515.h.
Go to the source code of this file.
#define | MCP2515_WKUP_SRC_INTERNAL 1 |
Wake up source. | |
#define | MCP2515_RECV_FILTER_EN 0 |
Acceptance mode (enable/disable filtering) | |
enum | mcp2515_mode { MODE_NORMAL = MCP2515_CANSTAT_OPMOD_NORMAL , MODE_SLEEP = MCP2515_CANSTAT_OPMOD_SLEEP , MODE_LOOPBACK = MCP2515_CANSTAT_OPMOD_LOOPBACK , MODE_LISTEN_ONLY = MCP2515_CANSTAT_OPMOD_LISTEN_ONLY , MODE_CONFIG = MCP2515_CANSTAT_OPMOD_CONFIGURATION , MODE_UNKNOWN = -1 } |
MCP2515 mode. More... | |
enum | mcp2515_interrupt { INT_RX0 = MCP2515_CANINTF_RX0IF , INT_RX1 = MCP2515_CANINTF_RX1IF , INT_TX0 = MCP2515_CANINTF_TX0IF , INT_TX1 = MCP2515_CANINTF_TX1IF , INT_TX2 = MCP2515_CANINTF_TX2IF , INT_ERROR = MCP2515_CANINTF_ERRIF , INT_WAKEUP = MCP2515_CANINTF_WAKIF , INT_MESSAGE_ERROR = MCP2515_CANINTF_MERRF } |
MCP2515 interrupt. More... | |
enum | mcp2515_error { ERR_WARNING = MCP2515_EFLG_EWARN , ERR_RX_WARNING = MCP2515_EFLG_RXWAR , ERR_TX_WARNING = MCP2515_EFLG_TXWAR , ERR_RX_PASSIVE = MCP2515_EFLG_RXEP , ERR_TX_PASSIVE = MCP2515_EFLG_TXEP , ERR_TX_BUS_OFF = MCP2515_EFLG_TXBO , ERR_RX_0_OVERFLOW = MCP2515_EFLG_RX0OVR , ERR_RX_1_OVERFLOW = MCP2515_EFLG_RX1OVR } |
MCP2515 error. More... | |
int | mcp2515_init (candev_mcp2515_t *dev, void(*irq_cb)(void *)) |
Initialize pins and SPI interface. | |
void | mcp2515_reset (candev_mcp2515_t *dev) |
Reset MCP2515 device with dedicated pin. | |
int | mcp2515_init_irqs (candev_mcp2515_t *dev) |
Initialize MCP2515 interrupts. | |
int | mcp2515_send (candev_mcp2515_t *dev, const struct can_frame *frame, int mailbox) |
Send frame through the corresponding tx mailbox . | |
int | mcp2515_receive (candev_mcp2515_t *dev, struct can_frame *frame, int mailbox) |
Receive frame from the corresponding rx mailbox . | |
int | mcp2515_abort (candev_mcp2515_t *dev, int mailbox) |
Abort communication. | |
enum mcp2515_mode | mcp2515_get_mode (candev_mcp2515_t *dev) |
Get MCP2515 mode of operation. | |
enum mcp2515_mode | mcp2515_set_mode (candev_mcp2515_t *dev, enum mcp2515_mode mode) |
Set MCP2515 mode of operation. | |
void | mcp2515_wake_up (candev_mcp2515_t *dev) |
Wake up MCP2515. | |
enum mcp2515_interrupt | mcp2515_get_irq (candev_mcp2515_t *dev) |
Get MCP2515 interrupt type. | |
int | mcp2515_clear_irq (candev_mcp2515_t *dev, enum mcp2515_interrupt irq) |
Clear MCP2515 interrupt. | |
int | mcp2515_tx_err_occurred (candev_mcp2515_t *dev, int mailbox) |
Get if an tx error occurred on MCP2515. | |
int | mcp2515_configure_bittiming (candev_mcp2515_t *dev) |
Configure the bit timing of the MCP2515. | |
uint8_t | mcp2515_get_errors (candev_mcp2515_t *dev) |
Get the error flags. | |
int | mcp2515_set_filter (candev_mcp2515_t *dev, int filter_id, uint32_t filter) |
Set the @ filter_id to the position in the mailbox. | |
int | mcp2515_set_mask (candev_mcp2515_t *dev, int mailbox, uint32_t mask) |
Set the @ mask to the mailbox. | |
#define MCP2515_RECV_FILTER_EN 0 |
enum mcp2515_error |
enum mcp2515_interrupt |
enum mcp2515_mode |
int mcp2515_abort | ( | candev_mcp2515_t * | dev, |
int | mailbox | ||
) |
Abort communication.
[in] | dev | device descriptor |
[in] | mailbox | mailbox |
int mcp2515_clear_irq | ( | candev_mcp2515_t * | dev, |
enum mcp2515_interrupt | irq | ||
) |
Clear MCP2515 interrupt.
[in] | dev | device descriptor |
[in] | irq | interrupt to clear |
int mcp2515_configure_bittiming | ( | candev_mcp2515_t * | dev | ) |
Configure the bit timing of the MCP2515.
The information about the bit timing should be contained in dev descriptor.
[in] | dev | device descriptor |
uint8_t mcp2515_get_errors | ( | candev_mcp2515_t * | dev | ) |
Get the error flags.
[in] | dev | device descriptor |
enum mcp2515_interrupt mcp2515_get_irq | ( | candev_mcp2515_t * | dev | ) |
Get MCP2515 interrupt type.
[in] | dev | device descriptor |
enum mcp2515_mode mcp2515_get_mode | ( | candev_mcp2515_t * | dev | ) |
Get MCP2515 mode of operation.
[in] | dev | device descriptor |
int mcp2515_init | ( | candev_mcp2515_t * | dev, |
void(*)(void *) | irq_cb | ||
) |
Initialize pins and SPI interface.
The device descriptor contains all information related to pins and SPI interface. This function initialize all corresponding fields and relies the irq_cb
callback function to the pin interruption. The pin interruption should be configured in the device descriptor.
[out] | dev | device descriptor |
[in] | irq_cb | callback function called when an interrupt is raised from the MCP2515. The MCP2515 makes the interruption through the interruption pin. |
int mcp2515_init_irqs | ( | candev_mcp2515_t * | dev | ) |
Initialize MCP2515 interrupts.
[in] | dev | device descriptor |
int mcp2515_receive | ( | candev_mcp2515_t * | dev, |
struct can_frame * | frame, | ||
int | mailbox | ||
) |
Receive frame from the corresponding rx mailbox
.
[in] | dev | device descriptor |
[out] | frame | the receive frame |
[in] | mailbox | rx mailbox |
void mcp2515_reset | ( | candev_mcp2515_t * | dev | ) |
Reset MCP2515 device with dedicated pin.
The MCP2515 device is reset by toggling the rst pin.
[in] | dev | device descriptor |
int mcp2515_send | ( | candev_mcp2515_t * | dev, |
const struct can_frame * | frame, | ||
int | mailbox | ||
) |
Send frame through the corresponding tx mailbox
.
[in] | dev | device descriptor |
[in] | frame | the frame to send |
[in] | mailbox | tx mailbox |
int mcp2515_set_filter | ( | candev_mcp2515_t * | dev, |
int | filter_id, | ||
uint32_t | filter | ||
) |
Set the @ filter_id to the position in the mailbox.
filter_id
corresponds to the position in the MCP2515 mailbox as follow:
The MCP2515 managed 6 acceptance filters in 2 rx mailboxes:
MB0 MB1 +------+ +------+mask 0 | RXM0 | | RXM1 | mask 1 +======+ +======+ filter 0 | RXF0 | | RXF2 | filter 2 +---—+ +---—+ filter 1 | RXF1 | | RXF3 | filter 3 +---—+ +---—+ | RXF4 | filter 4 +---—+ | RXF5 | filter 5 +---—+
[in] | dev | device descriptor |
[in] | filter_id | filter identifier in the MCP2515 mailbox |
[in] | filter | acceptance filter can identifier |
int mcp2515_set_mask | ( | candev_mcp2515_t * | dev, |
int | mailbox, | ||
uint32_t | mask | ||
) |
Set the @ mask to the mailbox.
The MCP2515 managed 6 acceptance filters in 2 rx mailboxes:
MB0 MB1 +------+ +------+mask 0 | RXM0 | | RXM1 | mask 1 +======+ +======+ filter 0 | RXF0 | | RXF2 | filter 2 +---—+ +---—+ filter 1 | RXF1 | | RXF3 | filter 3 +---—+ +---—+ | RXF4 | filter 4 +---—+ | RXF5 | filter 5 +---—+
[in] | dev | device descriptor |
[in] | mailbox | rx mailbox |
[in] | mask | acceptance mask |
enum mcp2515_mode mcp2515_set_mode | ( | candev_mcp2515_t * | dev, |
enum mcp2515_mode | mode | ||
) |
Set MCP2515 mode of operation.
[in] | dev | device descriptor |
[in] | mode | mode of operation to set |
int mcp2515_tx_err_occurred | ( | candev_mcp2515_t * | dev, |
int | mailbox | ||
) |
Get if an tx error occurred on MCP2515.
[in] | dev | device descriptor |
[in] | mailbox | tx mailbox |
void mcp2515_wake_up | ( | candev_mcp2515_t * | dev | ) |
Wake up MCP2515.
[in] | dev | device descriptor |