Skip to content

Commit 98623d9

Browse files
committed
fix(isotp): add delay for flow-control frame
the remote (in our case the Nvidia Jetson) seems to have trouble sending messages over iso-tp in specific cases using candump, we can see that the flow-control (FC) frame is received before the last frame from the block (bs=8) is sent, which is not expected. A dump: ``` can0 3F2 [8] 27 2C 2D 2E 2F 30 31 32 <- frame zephyrproject-rtos#27 = 7/8 can0 1F2 [3] 30 08 00 <- FC frame can0 3F2 [8] 28 33 34 35 36 37 38 39 <- frame zephyrproject-rtos#28 = 8/8 ``` Probing the can bus, we can see that frame zephyrproject-rtos#28 is sent before the FC frame is responded to the Jetson (as per iso-tp protocol). But the Jetson doesn't seem to correctly order these frames and each time it happens, transmission stalls. Adding some delay for the FC response on the mcu side seems to fix the issue as the Jetson now has more time to set up the reception of the FC frame. Signed-off-by: Cyril Fougeray <[email protected]>
1 parent 2ade888 commit 98623d9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

subsys/canbus/isotp/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ config ISOTP_WFTMAX
2626
This value defines the maximum number of WAIT frames before the transmission
2727
is aborted.
2828

29+
config ISOTP_FC_DELAY_US
30+
int "Delay in microseconds before sending the FC frame"
31+
default 0
32+
range 0 10000
33+
help
34+
The sender might need time to set up reception of the FC frame. This config allows such case.
35+
Resolution of that timer might not be ensured because the lower bound on the duration of a sleep is
36+
the duration of a tick.
37+
2938
config ISOTP_BS_TIMEOUT
3039
int "Bs timeout [ms] (timeout for receiving the frame control)"
3140
default 1000

subsys/canbus/isotp/isotp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ static void receive_send_fc(struct isotp_recv_ctx *rctx, uint8_t fs)
161161
frame.dlc = can_bytes_to_dlc(payload_len);
162162
#endif
163163

164+
#if defined(CONFIG_ISOTP_FC_DELAY_US) && CONFIG_ISOTP_FC_DELAY_US != 0
165+
// @fouge
166+
// Remote might need some time to set up reception of the FC frame.
167+
// As seen on Jetson, the last CF of the block was seen after
168+
// the FC frame by candump on the Jetson 🤯. Each time, it leads
169+
// to error during transmission of the message of iso-tp.
170+
k_usleep(CONFIG_ISOTP_FC_DELAY_US);
171+
#endif
172+
164173
ret = can_send(rctx->can_dev, &frame, K_MSEC(ISOTP_A_TIMEOUT_MS), receive_can_tx, rctx);
165174
if (ret) {
166175
LOG_ERR("Can't send FC, (%d)", ret);

0 commit comments

Comments
 (0)