drivers: can: remove DT_CHOSEN_ZEPHYR_CANBUS_LABEL macro
Remove the DT_CHOSEN_ZEPHYR_CANBUS_LABEL macro and replace it with DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus)) were possible. Where both devicetree CAN controllers and Kconfig specified CAN loopback controllers are supported, the macro is replaced with DT_LABEL(DT_CHOSEN(zephyr_canbus)) for now. This is the first pass for removing the requirement for devicetree labels for CAN controllers. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
e489bb18a4
commit
5bc0451f72
10 changed files with 18 additions and 36 deletions
|
@ -377,21 +377,18 @@ static struct net_can_api net_can_api_inst = {
|
||||||
|
|
||||||
static int net_can_init(const struct device *dev)
|
static int net_can_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct device *can_dev;
|
const struct device *can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
|
||||||
struct net_can_context *ctx = dev->data;
|
struct net_can_context *ctx = dev->data;
|
||||||
|
|
||||||
can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CANBUS_LABEL);
|
|
||||||
|
|
||||||
ctx->recv_filter_id = CAN_NET_FILTER_NOT_SET;
|
ctx->recv_filter_id = CAN_NET_FILTER_NOT_SET;
|
||||||
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
|
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
|
||||||
ctx->eth_bridge_filter_id = CAN_NET_FILTER_NOT_SET;
|
ctx->eth_bridge_filter_id = CAN_NET_FILTER_NOT_SET;
|
||||||
ctx->all_mcast_filter_id = CAN_NET_FILTER_NOT_SET;
|
ctx->all_mcast_filter_id = CAN_NET_FILTER_NOT_SET;
|
||||||
#endif /*CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR*/
|
#endif /*CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR*/
|
||||||
|
|
||||||
if (!can_dev) {
|
if (!device_is_ready(can_dev)) {
|
||||||
NET_ERR("Can't get binding to CAN device %s",
|
NET_ERR("CAN device not ready");
|
||||||
DT_CHOSEN_ZEPHYR_CANBUS_LABEL);
|
return -ENODEV;
|
||||||
return -EIO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NET_DBG("Init net CAN device %p (%s) for dev %p (%s)",
|
NET_DBG("Init net CAN device %p (%s) for dev %p (%s)",
|
||||||
|
|
|
@ -45,14 +45,6 @@
|
||||||
*/
|
*/
|
||||||
#define DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL ""
|
#define DT_CHOSEN_ZEPHYR_FLASH_CONTROLLER_LABEL ""
|
||||||
|
|
||||||
/**
|
|
||||||
* @def DT_CHOSEN_ZEPHYR_CANBUS_LABEL
|
|
||||||
*
|
|
||||||
* @brief If there is a chosen node zephyr,canbus property which has
|
|
||||||
* a label property, that property's value. Undefined otherwise.
|
|
||||||
*/
|
|
||||||
#define DT_CHOSEN_ZEPHYR_CANBUS_LABEL ""
|
|
||||||
|
|
||||||
#endif /* DT_DOXYGEN */
|
#endif /* DT_DOXYGEN */
|
||||||
|
|
||||||
#if DT_NODE_HAS_PROP(DT_CHOSEN(zephyr_entropy), label)
|
#if DT_NODE_HAS_PROP(DT_CHOSEN(zephyr_entropy), label)
|
||||||
|
@ -64,10 +56,6 @@
|
||||||
DT_LABEL(DT_CHOSEN(zephyr_flash_controller))
|
DT_LABEL(DT_CHOSEN(zephyr_flash_controller))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DT_NODE_HAS_PROP(DT_CHOSEN(zephyr_canbus), label)
|
|
||||||
#define DT_CHOSEN_ZEPHYR_CANBUS_LABEL \
|
|
||||||
DT_LABEL(DT_CHOSEN(zephyr_canbus))
|
|
||||||
#endif
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -14,12 +14,8 @@
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_REGISTER(app);
|
LOG_MODULE_REGISTER(app);
|
||||||
|
|
||||||
|
#define CAN_INTERFACE DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus))
|
||||||
#define CAN_INTERFACE DT_CHOSEN_ZEPHYR_CANBUS_LABEL
|
|
||||||
#define CAN_BITRATE (DT_PROP(DT_CHOSEN(zephyr_canbus), bus_speed) / 1000)
|
#define CAN_BITRATE (DT_PROP(DT_CHOSEN(zephyr_canbus), bus_speed) / 1000)
|
||||||
#if !defined(DT_CHOSEN_ZEPHYR_CANBUS_LABEL)
|
|
||||||
#error CANopen CAN interface not set
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_NODE_HAS_PROP(DT_ALIAS(green_led), gpios)
|
#if DT_NODE_HAS_PROP(DT_ALIAS(green_led), gpios)
|
||||||
#define LED_GREEN_PORT DT_GPIO_LABEL(DT_ALIAS(green_led), gpios)
|
#define LED_GREEN_PORT DT_GPIO_LABEL(DT_ALIAS(green_led), gpios)
|
||||||
|
@ -210,9 +206,9 @@ void main(void)
|
||||||
int ret;
|
int ret;
|
||||||
#endif /* CONFIG_CANOPENNODE_STORAGE */
|
#endif /* CONFIG_CANOPENNODE_STORAGE */
|
||||||
|
|
||||||
can.dev = device_get_binding(CAN_INTERFACE);
|
can.dev = CAN_INTERFACE;
|
||||||
if (!can.dev) {
|
if (!device_is_ready(can.dev)) {
|
||||||
LOG_ERR("CAN interface not found");
|
LOG_ERR("CAN interface not ready");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,9 +148,9 @@ void main(void)
|
||||||
static struct isotp_send_ctx send_ctx_0_5;
|
static struct isotp_send_ctx send_ctx_0_5;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CANBUS_LABEL);
|
can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
|
||||||
if (!can_dev) {
|
if (!device_is_ready(can_dev)) {
|
||||||
printk("CAN: Device driver not found.\n");
|
printk("CAN: Device driver not ready.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
||||||
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
||||||
#else
|
#else
|
||||||
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CANBUS_LABEL
|
#define CAN_DEVICE_NAME DT_LABEL(DT_CHOSEN(zephyr_canbus))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CAN_DEFINE_MSGQ(can_msgq, 5);
|
CAN_DEFINE_MSGQ(can_msgq, 5);
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
||||||
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
||||||
#else
|
#else
|
||||||
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CANBUS_LABEL
|
#define CAN_DEVICE_NAME DT_LABEL(DT_CHOSEN(zephyr_canbus))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CAN_DEFINE_MSGQ(can_msgq, 5);
|
CAN_DEFINE_MSGQ(can_msgq, 5);
|
||||||
|
|
|
@ -125,7 +125,8 @@ static void test_filter_handling(void)
|
||||||
int ret, filter_id_1, filter_id_2;
|
int ret, filter_id_1, filter_id_2;
|
||||||
struct zcan_frame msg_buffer;
|
struct zcan_frame msg_buffer;
|
||||||
|
|
||||||
can_dev = device_get_binding(DT_CHOSEN_ZEPHYR_CANBUS_LABEL);
|
can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
|
||||||
|
zassert_true(device_is_ready(can_dev), "CAN device ready");
|
||||||
|
|
||||||
ret = can_set_mode(can_dev, CAN_LOOPBACK_MODE);
|
ret = can_set_mode(can_dev, CAN_LOOPBACK_MODE);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
||||||
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
||||||
#else
|
#else
|
||||||
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CANBUS_LABEL
|
#define CAN_DEVICE_NAME DT_LABEL(DT_CHOSEN(zephyr_canbus))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const struct device *can_dev;
|
const struct device *can_dev;
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
||||||
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
||||||
#else
|
#else
|
||||||
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CANBUS_LABEL
|
#define CAN_DEVICE_NAME DT_LABEL(DT_CHOSEN(zephyr_canbus))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
#if defined(CONFIG_CAN_LOOPBACK_DEV_NAME)
|
||||||
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
#define CAN_DEVICE_NAME CONFIG_CAN_LOOPBACK_DEV_NAME
|
||||||
#else
|
#else
|
||||||
#define CAN_DEVICE_NAME DT_CHOSEN_ZEPHYR_CANBUS_LABEL
|
#define CAN_DEVICE_NAME DT_LABEL(DT_CHOSEN(zephyr_canbus))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue