diff --git a/tests/can_samd5x/Makefile b/tests/can_samd5x/Makefile deleted file mode 100644 index 86603342b4079..0000000000000 --- a/tests/can_samd5x/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -include ../Makefile.tests_common - -FEATURES_REQUIRED += periph_can - -BOARD = same54-xpro - -USEMODULE += can -USEMODULE += ztimer_sec - -CFLAGS += -DISR_STACKSIZE="(1024)" -CFLAGS += -DCANDEV_SAMD5X_DEFAULT_TX_EVT_FIFO_ELTS_NUM=5 -CFLAGS += -DCANDEV_SAMD5X_DEFAULT_TX_BUFFER_FIFO_QUEUE_NUM=10 - -DEVELHELP ?= 1 - -include $(RIOTBASE)/Makefile.include \ No newline at end of file diff --git a/tests/can_samd5x/main.c b/tests/can_samd5x/main.c deleted file mode 100644 index e45e7685af5f7..0000000000000 --- a/tests/can_samd5x/main.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup tests - * @{ - * - * @file - * @brief Test application for the candev abstraction - * - * - * @} - */ - -#include - -#include "periph/gpio.h" -#include "periph/can.h" - -static can_t can_samd5x; -candev_t *candev = NULL; - -#ifndef SAMD5X_CAN_TEST_MODE -#define SAMD5X_CAN_TEST_MODE 0 -#endif - -#define ENABLE_DEBUG 0 -#include - -struct can_frame frame_1 = { - .can_dlc = 5, - .can_id = 0x8C000001, - .data = { - 4, - 1, - 2, - 3, - 0xF - } - }; - -static void _can_event_callback(candev_t *dev, candev_event_t event, void *arg) -{ - (void)dev; - struct can_frame *frame = arg; - - switch (event) { - case CANDEV_EVENT_ISR: - DEBUG("_can_event: CANDEV_EVENT_ISR\n"); - dev->driver->isr(candev); - break; - case CANDEV_EVENT_WAKE_UP: - DEBUG("_can_event: CANDEV_EVENT_WAKE_UP\n"); - break; - case CANDEV_EVENT_TX_CONFIRMATION: - DEBUG("_can_event: CANDEV_EVENT_TX_CONFIRMATION\n"); - break; - case CANDEV_EVENT_TX_ERROR: - DEBUG("_can_event: CANDEV_EVENT_TX_ERROR\n"); - break; - case CANDEV_EVENT_RX_INDICATION: - DEBUG("_can_event: CANDEV_EVENT_RX_INDICATION\n"); - DEBUG("frame ID = 0x%08lx\n", frame->can_id); - DEBUG("frame data = 0x"); - for (uint8_t i = 0; i < frame->can_dlc; i++) { - DEBUG("%02x", frame->data[i]); - } - DEBUG("\n"); - dev->driver->send(candev, &frame_1); - break; - case CANDEV_EVENT_RX_ERROR: - DEBUG("_can_event: CANDEV_EVENT_RX_ERROR\n"); - break; - default: - DEBUG("_can_event: unknown event\n"); - break; - } -} - -int main(void) -{ - puts("candev test application\n"); - - gpio_init(GPIO_PIN(PC, 13), GPIO_IN); - can_init(&can_samd5x, &candev_conf[0]); - - candev = &(can_samd5x.candev); - candev->event_callback = _can_event_callback; - candev->isr_arg = NULL; - - candev->driver->init(candev); - - struct can_filter filter = {0}; - filter.can_filter_conf = CAN_FILTER_RX_FIFO_1; - filter.can_filter_type = CAN_FILTER_TYPE_CLASSIC; - filter.can_id = 0x0111; - filter.can_mask = 0x7FF; - candev->driver->set_filter(candev, &filter); - candev->driver->remove_filter(candev, &filter); - - filter.can_filter_conf = CAN_FILTER_RX_FIFO_1; - filter.can_filter_type = CAN_FILTER_TYPE_CLASSIC; - filter.can_id = 0x113; - filter.can_mask = 0x7FF; - candev->driver->set_filter(candev, &filter); - - filter.can_filter_conf = CAN_FILTER_RX_FIFO_0; - filter.can_filter_type = CAN_FILTER_TYPE_CLASSIC; - filter.can_id = 0x8C000001; - filter.can_mask = 0x9FFFFFFE; - candev->driver->set_filter(candev, &filter); - - filter.can_filter_conf = CAN_FILTER_RX_FIFO_0; - filter.can_filter_type = CAN_FILTER_TYPE_CLASSIC; - filter.can_id = 0x112; - filter.can_mask = 0x7FF; - candev->driver->set_filter(candev, &filter); - - /* Removing a non existing filter returns an error */ - struct can_filter filter_to_remove = {0}; - filter_to_remove.can_id = 0x114; - filter_to_remove.can_mask = 0x7FF; - candev->driver->remove_filter(candev, &filter_to_remove); - -#if IS_ACTIVE(SAMD5X_CAN_TEST_MODE) - candev_samd5x_enter_test_mode(candev); -#endif - - struct can_frame frame_1 = { - .can_dlc = 5, - .can_id = 0x8C122330, - .data = { - 0, - 1, - 2, - 3, - 0xF - } - }; - - struct can_frame frame_2 = { - .can_dlc = 5, - .can_id = 0x9B001122, - .data = { - 4, - 5, - 6, - 7, - 0xE - } - }; - -#if IS_ACTIVE(TEST_MODE) - candev_samd5x_enter_test_mode(candev); -#endif - - candev->driver->send(candev, &frame_1); - candev->driver->send(candev, &frame_2); - - while(1); - - return 0; -} diff --git a/tests/drivers/candev/Makefile.board.dep b/tests/drivers/candev/Makefile.board.dep index 305c2a40a51ae..38e3000f324e2 100644 --- a/tests/drivers/candev/Makefile.board.dep +++ b/tests/drivers/candev/Makefile.board.dep @@ -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 diff --git a/tests/drivers/candev/main.c b/tests/drivers/candev/main.c index e9f7f417372f5..157a087dbf83e 100644 --- a/tests/drivers/candev/main.c +++ b/tests/drivers/candev/main.c @@ -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" @@ -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) @@ -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);