Merge pull request #14828 from wosym/candev_native_check

tests/candev: Prevent user from attempting to use native can interface on non-native board
This commit is contained in:
Leandro Lanzieri 2020-08-31 11:06:02 +02:00 committed by GitHub
commit 083b73d71b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -1,11 +1,21 @@
include ../Makefile.tests_common include ../Makefile.tests_common
BOARD_WHITELIST := native
USEMODULE += shell USEMODULE += shell
USEMODULE += can USEMODULE += can
USEMODULE += isrpipe USEMODULE += isrpipe
# define the CAN driver you want to use here # define the CAN driver you want to use here
CAN_DRIVER ?= native CAN_DRIVER ?= CAN_NATIVE
# prevent using native driver on non-native board
ifeq ($(CAN_DRIVER), CAN_NATIVE)
ifneq ($(BOARD), native)
$(error native can driver can only be used on native board!)
endif
endif
ifeq ($(CAN_DRIVER), PERIPH_CAN) ifeq ($(CAN_DRIVER), PERIPH_CAN)
# periph_can modules/variables go here # periph_can modules/variables go here
@ -15,6 +25,4 @@ else ifeq ($(CAN_DRIVER), CAN_NATIVE)
endif endif
CFLAGS += -DCAN_DRIVER_$(CAN_DRIVER)
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include

View File

@ -30,7 +30,7 @@
#include "shell.h" #include "shell.h"
#include "can/device.h" #include "can/device.h"
#ifdef BOARD_NATIVE #if IS_USED(MODULE_CAN_LINUX)
#include <candev_linux.h> #include <candev_linux.h>
@ -192,7 +192,7 @@ int main(void)
puts("candev test application\n"); puts("candev test application\n");
isrpipe_init(&rxbuf, (uint8_t *)rx_ringbuf, sizeof(rx_ringbuf)); isrpipe_init(&rxbuf, (uint8_t *)rx_ringbuf, sizeof(rx_ringbuf));
#ifdef BOARD_NATIVE #if IS_USED(MODULE_CAN_LINUX)
puts("Initializing Linux Can device"); puts("Initializing Linux Can device");
candev_linux_init( &linux_dev, &(candev_linux_conf[0])); /* vcan0 */ candev_linux_init( &linux_dev, &(candev_linux_conf[0])); /* vcan0 */
candev = (candev_t *)&linux_dev; candev = (candev_t *)&linux_dev;