drivers: can: set default initial bitrates via Kconfig

Set the default initial bitrates globally via Kconfig. The initial bitrates
can still be overridden using the "bus-speed" and "bus-speed-data"
devicetree properties.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2024-04-24 11:09:15 +02:00 committed by Alberto Escolar
commit 0f7cd6128e
5 changed files with 24 additions and 7 deletions

View file

@ -23,6 +23,21 @@ config CAN_INIT_PRIORITY
help
CAN driver device initialization priority.
config CAN_DEFAULT_BITRATE
int "Default CAN bitrate"
default 125000
help
Default initial CAN bitrate in bits/s. This can be overridden per CAN controller using the
"bus-speed" devicetree property.
config CAN_DEFAULT_BITRATE_DATA
int "Default CAN data phase bitrate"
default 1000000
depends on CAN_FD_MODE
help
Default initial CAN data phase bitrate in bits/s. This can be overridden per CAN controller
using the "bus-speed-data" devicetree property.
config CAN_SHELL
bool "CAN shell"
depends on SHELL

View file

@ -5,9 +5,9 @@ include: base.yaml
properties:
bus-speed:
type: int
required: true
description: |
Initial bitrate in bit/s.
Initial bitrate in bit/s. If this is unset, the initial bitrate is set to
CONFIG_CAN_DEFAULT_BITRATE.
sample-point:
type: int
description: |

View file

@ -5,9 +5,9 @@ include: can-controller.yaml
properties:
bus-speed-data:
type: int
required: true
description: |
Initial data phase bitrate in bit/s.
Initial data phase bitrate in bit/s. If this is unset, the initial data phase bitrate is set
to CONFIG_CAN_DEFAULT_BITRATE_DATA.
sample-point-data:
type: int
description: |

View file

@ -374,10 +374,11 @@ struct can_driver_config {
.phy = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, phys)), \
.min_bitrate = DT_CAN_TRANSCEIVER_MIN_BITRATE(node_id, _min_bitrate), \
.max_bitrate = DT_CAN_TRANSCEIVER_MAX_BITRATE(node_id, _max_bitrate), \
.bus_speed = DT_PROP(node_id, bus_speed), \
.bus_speed = DT_PROP_OR(node_id, bus_speed, CONFIG_CAN_DEFAULT_BITRATE), \
.sample_point = DT_PROP_OR(node_id, sample_point, 0), \
IF_ENABLED(CONFIG_CAN_FD_MODE, \
(.bus_speed_data = DT_PROP_OR(node_id, bus_speed_data, 0), \
(.bus_speed_data = DT_PROP_OR(node_id, bus_speed_data, \
CONFIG_CAN_DEFAULT_BITRATE_DATA), \
.sample_point_data = DT_PROP_OR(node_id, sample_point_data, 0),)) \
}

View file

@ -15,7 +15,8 @@
LOG_MODULE_REGISTER(app);
#define CAN_INTERFACE DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus))
#define CAN_BITRATE (DT_PROP(DT_CHOSEN(zephyr_canbus), bus_speed) / 1000)
#define CAN_BITRATE (DT_PROP_OR(DT_CHOSEN(zephyr_canbus), bus_speed, \
CONFIG_CAN_DEFAULT_BITRATE) / 1000)
static struct gpio_dt_spec led_green_gpio = GPIO_DT_SPEC_GET_OR(
DT_ALIAS(green_led), gpios, {0});