mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 04:52:59 +01:00
drivers/mcp2515: fix to add filters
drivers/mcp2515: enable filtering The current driver implementation initializes the driver in a way to receive all the CAN messages without matching the filters. This commit changes that by adding a macro definition that will be enabling or disabling the filtering and accordingly set the appropriate mcp2515 acceptance mode
This commit is contained in:
parent
7b827f405c
commit
3f9866e709
@ -421,7 +421,6 @@ static int _get(candev_t *candev, canopt_t opt, void *value, size_t max_len)
|
|||||||
static int _set_filter(candev_t *dev, const struct can_filter *filter)
|
static int _set_filter(candev_t *dev, const struct can_filter *filter)
|
||||||
{
|
{
|
||||||
DEBUG("inside _set_filter of MCP2515\n");
|
DEBUG("inside _set_filter of MCP2515\n");
|
||||||
bool filter_added = true;
|
|
||||||
struct can_filter f = *filter;
|
struct can_filter f = *filter;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
enum mcp2515_mode mode;
|
enum mcp2515_mode mode;
|
||||||
@ -453,7 +452,7 @@ static int _set_filter(candev_t *dev, const struct can_filter *filter)
|
|||||||
/* Browse on each mailbox to find an empty space */
|
/* Browse on each mailbox to find an empty space */
|
||||||
int mailbox_index = 0;
|
int mailbox_index = 0;
|
||||||
|
|
||||||
while (mailbox_index < MCP2515_RX_MAILBOXES && !filter_added) {
|
while (mailbox_index < MCP2515_RX_MAILBOXES) {
|
||||||
/* mask unused */
|
/* mask unused */
|
||||||
if (dev_mcp->masks[mailbox_index] == 0) {
|
if (dev_mcp->masks[mailbox_index] == 0) {
|
||||||
/* set mask */
|
/* set mask */
|
||||||
@ -467,7 +466,7 @@ static int _set_filter(candev_t *dev, const struct can_filter *filter)
|
|||||||
dev_mcp->filter_ids[mailbox_index][0] = f.can_id;
|
dev_mcp->filter_ids[mailbox_index][0] = f.can_id;
|
||||||
|
|
||||||
/* function succeeded */
|
/* function succeeded */
|
||||||
filter_added = true;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mask existed and same mask */
|
/* mask existed and same mask */
|
||||||
@ -498,7 +497,7 @@ static int _set_filter(candev_t *dev, const struct can_filter *filter)
|
|||||||
dev_mcp->filter_ids[mailbox_index][filter_pos] = f.can_id;
|
dev_mcp->filter_ids[mailbox_index][filter_pos] = f.can_id;
|
||||||
|
|
||||||
/* function succeeded */
|
/* function succeeded */
|
||||||
filter_added = true;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mailbox_index++;
|
mailbox_index++;
|
||||||
@ -513,7 +512,8 @@ static int _set_filter(candev_t *dev, const struct can_filter *filter)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filter_added;
|
/* Filter added */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _remove_filter(candev_t *dev, const struct can_filter *filter)
|
static int _remove_filter(candev_t *dev, const struct can_filter *filter)
|
||||||
|
@ -108,7 +108,15 @@ int mcp2515_init(candev_mcp2515_t *dev, void (*irq_handler_cb)(void *))
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cmd = MCP2515_RXB0CTRL_MODE_RECV_ALL;
|
uint8_t cmd;
|
||||||
|
if (IS_ACTIVE(MCP2515_RECV_FILTER_EN)) {
|
||||||
|
DEBUG_PUTS("filtering enabled");
|
||||||
|
cmd = MCP2515_RXB0CTRL_MODE_RECV_FILTER;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG_PUTS("filtering disabled");
|
||||||
|
cmd = MCP2515_RXB0CTRL_MODE_RECV_ALL;
|
||||||
|
}
|
||||||
|
|
||||||
res = mcp2515_spi_write(dev, MCP2515_RXB0CTRL, &cmd, 1);
|
res = mcp2515_spi_write(dev, MCP2515_RXB0CTRL, &cmd, 1);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
@ -71,6 +71,11 @@ enum mcp2515_error {
|
|||||||
/** Wake up source */
|
/** Wake up source */
|
||||||
#define MCP2515_WKUP_SRC_INTERNAL 1
|
#define MCP2515_WKUP_SRC_INTERNAL 1
|
||||||
|
|
||||||
|
/** Acceptance mode (enable/disable filtering) */
|
||||||
|
#ifndef MCP2515_RECV_FILTER_EN
|
||||||
|
#define MCP2515_RECV_FILTER_EN 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize pins and SPI interface
|
* @brief Initialize pins and SPI interface
|
||||||
*
|
*
|
||||||
|
@ -300,6 +300,7 @@ extern "C" {
|
|||||||
#define MCP2515_RXB0CTRL_BUKT1 0x02
|
#define MCP2515_RXB0CTRL_BUKT1 0x02
|
||||||
#define MCP2515_RXB0CTRL_BUKT 0x04
|
#define MCP2515_RXB0CTRL_BUKT 0x04
|
||||||
#define MCP2515_RXB0CTRL_RXRTR 0x08
|
#define MCP2515_RXB0CTRL_RXRTR 0x08
|
||||||
|
#define MCP2515_RXB0CTRL_MODE_RECV_FILTER 0x00
|
||||||
#define MCP2515_RXB0CTRL_RXM0 0x20
|
#define MCP2515_RXB0CTRL_RXM0 0x20
|
||||||
#define MCP2515_RXB0CTRL_RXM1 0x40
|
#define MCP2515_RXB0CTRL_RXM1 0x40
|
||||||
#define MCP2515_RXB0CTRL_MODE_RECV_STD_OR_EXT 0x00
|
#define MCP2515_RXB0CTRL_MODE_RECV_STD_OR_EXT 0x00
|
||||||
@ -312,6 +313,7 @@ extern "C" {
|
|||||||
#define MCP2515_RXB1CTRL_FILHIT1 0x02
|
#define MCP2515_RXB1CTRL_FILHIT1 0x02
|
||||||
#define MCP2515_RXB1CTRL_FILHIT2 0x04
|
#define MCP2515_RXB1CTRL_FILHIT2 0x04
|
||||||
#define MCP2515_RXB1CTRL_RXRTR 0x08
|
#define MCP2515_RXB1CTRL_RXRTR 0x08
|
||||||
|
#define MCP2515_RXB1CTRL_MODE_RECV_FILTER 0x00
|
||||||
#define MCP2515_RXB1CTRL_RXM0 0x20
|
#define MCP2515_RXB1CTRL_RXM0 0x20
|
||||||
#define MCP2515_RXB1CTRL_RXM1 0x40
|
#define MCP2515_RXB1CTRL_RXM1 0x40
|
||||||
#define MCP2515_RXB1CTRL_MODE_RECV_STD_OR_EXT 0x00
|
#define MCP2515_RXB1CTRL_MODE_RECV_STD_OR_EXT 0x00
|
||||||
|
Loading…
Reference in New Issue
Block a user