Skip to content

Commit

Permalink
test/drivers/candev: update test application
Browse files Browse the repository at this point in the history
  • Loading branch information
firas-hamdi committed Jun 21, 2023
1 parent 7ba75da commit 0bc7c21
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 186 deletions.
16 changes: 0 additions & 16 deletions tests/can_samd5x/Makefile

This file was deleted.

167 changes: 0 additions & 167 deletions tests/can_samd5x/main.c

This file was deleted.

4 changes: 4 additions & 0 deletions tests/drivers/candev/Makefile.board.dep
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ CAN_DRIVER ?= MCP2515

ifeq ($(CAN_DRIVER), PERIPH_CAN)
FEATURES_REQUIRED += periph_can
ifeq ($(BOARD), same54-xpro)
CFLAGS += "-DCANDEV_SAMD5X_DEFAULT_STD_FILTER_NUM=5"
CFLAGS += "-DCANDEV_SAMD5X_DEFAULT_EXT_FILTER_NUM=5"
endif
else ifeq ($(CAN_DRIVER), MCP2515)
USEMODULE += mcp2515
# Uncomment to enable MCP2515 reception filtering
Expand Down
43 changes: 40 additions & 3 deletions tests/drivers/candev/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "can/device.h"

#if IS_USED(MODULE_PERIPH_CAN)

#if defined(MCU_SAMD5X)
#include "periph/gpio.h"
#endif
#include "periph/can.h"
#include "can_params.h"

Expand Down Expand Up @@ -196,6 +198,10 @@ int main(void)
isrpipe_init(&rxbuf, (uint8_t *)rx_ringbuf, sizeof(rx_ringbuf));
#if IS_USED(MODULE_PERIPH_CAN)
puts("Initializing CAN periph device");
#if defined(MCU_SAMD5X)
/* Standby pin of the CAN transceiver. Must be low */
gpio_init(GPIO_PIN(PC, 13), GPIO_IN);
#endif
can_init(&periph_dev, &(candev_conf[0])); /* vcan0 on native */
candev = (candev_t *)&periph_dev;
#elif defined(MODULE_MCP2515)
Expand All @@ -220,36 +226,67 @@ if (IS_ACTIVE(CONFIG_USE_LOOPBACK_MODE)) {
canopt_state_t mode = CANOPT_STATE_LOOPBACK;
candev->driver->set(candev, CANOPT_STATE, &mode, sizeof(mode));
}

#if defined(MODULE_MCP2515)
if (IS_ACTIVE(MCP2515_RECV_FILTER_EN)) {
#endif
/* CAN filters examples */
struct can_filter filter[4];
filter[0].can_mask = 0x7FF;
filter[0].can_id = 0x001;
#if defined(MODULE_MCP2515)
filter[0].target_mailbox = 0; /* messages with CAN ID 0x001 will be received in mailbox 0 */
#elif defined(MCU_SAMD5X)
filter[0].can_filter_type = CAN_FILTER_TYPE_CLASSIC;
filter[0].can_filter_conf = CAN_FILTER_RX_FIFO_0; /* meassages with CAN ID 0x001 will be received in Rx FIFO 0 */
#endif
filter[1].can_mask = 0x7FF;
filter[1].can_id = 0x002;
#if defined(MODULE_MCP2515)
filter[1].target_mailbox = 1; /* messages with CAN ID 0x002 will be received in mailbox 1 */
#elif defined(MCU_SAMD5X)
filter[1].can_filter_type = CAN_FILTER_TYPE_CLASSIC;
filter[1].can_filter_conf = CAN_FILTER_RX_FIFO_1; /* messages with CAN ID 0x002 will be received in Rx FIFO 1 */
#endif
filter[2].can_mask = 0x7FF;
filter[2].can_id = 0x003;
#if defined(MODULE_MCP2515)
filter[2].target_mailbox = 0; /* messages with CAN ID 0x003 will be received in mailbox 0 */
#elif defined(MCU_SAMD5X)
filter[2].can_filter_type = CAN_FILTER_TYPE_CLASSIC;
filter[2].can_filter_conf = CAN_FILTER_RX_REJECT; /* messages with CAN ID 0x003 will be rejected */
#endif
filter[3].can_mask = 0x7FF;
filter[3].can_id = 0x004;
#if defined(MODULE_MCP2515)
filter[3].target_mailbox = 0; /* this filter won't be applied. Reason is no space found in the first mailbox as it supports only two filters */
#elif defined(MCU_SAMD5X)
filter[3].can_filter_type = CAN_FILTER_TYPE_CLASSIC;
filter[3].can_filter_conf = CAN_FILTER_RX_FIFO_1; /* messages with CAN ID 0x004 will be received in Rx FIFO 1 */
#endif
for (uint8_t i = 0; i < 4; i++) {
candev->driver->set_filter(candev, &filter[i]);
}
#if defined(MCU_SAMD5X)
struct can_filter range_filter = {
.can_filter_type = CAN_FILTER_TYPE_RANGE,
.can_filter_conf = CAN_FILTER_RX_FIFO_0,
.can_id = 0x8C000000,
.can_mask = 0x8C000006,
};
candev->driver->set_filter(candev, &range_filter); /* messages with CAN ID from 0C000000 to 0C000006 will be received in Rx FIFO 0 */

struct can_filter dual_filter = {
.can_filter_type = CAN_FILTER_TYPE_DUAL,
.can_filter_conf = CAN_FILTER_RX_FIFO_1,
.can_id = 0x0A0,
.can_mask = 0x0B0,
};
candev->driver->set_filter(candev, &dual_filter); /* messages with CAN ID 0x0A0 or 0X0B0 will be received in Rx FIFO 1 */
#endif
/* All other messages won't be received */
#if defined(MODULE_MCP2515)
}

#endif
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

Expand Down

0 comments on commit 0bc7c21

Please sign in to comment.