Skip to content

Commit

Permalink
fixup: set a default transceiver loop delay value for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
gdoffe committed Oct 7, 2024
1 parent 51e6ddf commit fb3b9b0
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
1 change: 1 addition & 0 deletions sys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
menu "System"

rsource "auto_init/Kconfig"
rsource "can/Kconfig"
rsource "chunked_ringbuffer/Kconfig"
rsource "congure/Kconfig"
rsource "debug_irq_disable/Kconfig"
Expand Down
36 changes: 36 additions & 0 deletions sys/can/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
menu "CAN"
depends on USEMODULE_CAN || USEMODULE_FDCAN

menu "FD CAN"

config FDCAN_DEVICE_SET_TRANSCEIVER_LOOP_DELAY
depends on USEMODULE_FDCAN
bool "FD CAN transceiver loop delay"
default n
help
Allow to set FD CAN Transceiver loop delay.

config FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY
depends on FDCAN_DEVICE_SET_TRANSCEIVER_LOOP_DELAY
int "FD CAN transceiver loop delay value"
range 0 1000
default 0
help
This parameter defines the loop delay introduced by the CAN transceiver
during transmission. The loop delay represents the time taken for the
transmitted signal to be looped back to the CAN controller. This delay
is introduced by the physical transceiver circuitry and may vary
depending on the transceiver model and other physical factors.

The value is typically measured in nanoseconds and should be set
according to the specifications provided by the transceiver manufacturer.
A higher loop delay can affect the timing of CAN message transmissions
and may need to be adjusted in systems with tight timing requirements.

If unsure, leave this value as 0 or refer to the hardware documentation
for the correct delay value.


endmenu # FD CAN

endmenu # CAN
8 changes: 4 additions & 4 deletions sys/can/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
* The loop delay in CAN, especially in CAN FD with bitrate switching, affects synchronization due to increased data rates.

Check warning on line 40 in sys/can/device.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
* The unit is nanoseconds.
*/
#ifndef CAN_DEVICE_DEFAULT_LOOP_DELAY
#error "CAN_DEVICE_DEFAULT_LOOP_DELAY must be defined in the application's Makefile. This property can be found in the datasheet of the CAN transceiver in use. The unit is nanoseconds."
#endif /* CAN_DEVICE_DEFAULT_LOOP_DELAY */
#ifndef CONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY
#error "CONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY must be defined. This property can be found in the datasheet of the CAN transceiver in use. The unit is nanoseconds."

Check warning on line 44 in sys/can/device.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#endif /* CONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY */
#endif /* MODULE_FDCAN */

#ifndef CAN_DEVICE_MSG_QUEUE_SIZE
Expand Down Expand Up @@ -248,7 +248,7 @@ static void *_can_device_thread(void *args)

#if defined(MODULE_FDCAN)
if (candev_dev->loop_delay == 0) {
candev_dev->loop_delay = CAN_DEVICE_DEFAULT_LOOP_DELAY;
candev_dev->loop_delay = CONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY;
}
dev->loop_delay = candev_dev->loop_delay;
#endif
Expand Down
14 changes: 14 additions & 0 deletions tests/sys/conn_can/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ ifneq (,$(filter native native64,$(BOARD)))
else
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2048
endif

# Loop delay
ifneq (,$(filter fdcan,$(USEMODULE)))
ifneq (1,$(RIOT_CI_BUILD))
# Check your CAN transceiver datasheet to apply the good loop delay in nanoseconds.
# This configuration is mandatory if you are using CAN FD with bitrate switching.
# Can be configured here or through Kconfig
#CFLAGS += -DCONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY=0

# Allow only a default value for CI
else
KCONFIG_ADD_CONFIG += $(CURDIR)/fdcan-ci.config
endif
endif
2 changes: 2 additions & 0 deletions tests/sys/conn_can/fdcan-ci.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_FDCAN_DEVICE_SET_TRANSCEIVER_LOOP_DELAY=y
CONFIG_FDCAN_DEVICE_TRANSCEIVER_LOOP_DELAY=0

0 comments on commit fb3b9b0

Please sign in to comment.