Skip to content

Commit 6f89259

Browse files
committed
canbus: isotp: prevent race-condition during debugging
During debugging I got "Got unexpected PDU" errors because a new CF was received before the state was set to ISOTP_TX_WAIT_FC in the send state machine. Setting the state before printing the debug information fixes the issue. Signed-off-by: Martin Jäger <[email protected]>
1 parent ca9d271 commit 6f89259

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

subsys/canbus/isotp/isotp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,11 +1068,11 @@ static void send_state_machine(struct isotp_send_ctx *ctx)
10681068
switch (ctx->state) {
10691069

10701070
case ISOTP_TX_SEND_FF:
1071-
LOG_DBG("SM send FF");
10721071
send_ff(ctx);
10731072
z_add_timeout(&ctx->timeout, send_timeout_handler,
10741073
K_MSEC(ISOTP_BS));
10751074
ctx->state = ISOTP_TX_WAIT_FC;
1075+
LOG_DBG("SM send FF");
10761076
break;
10771077

10781078
case ISOTP_TX_SEND_CF:
@@ -1094,11 +1094,11 @@ static void send_state_machine(struct isotp_send_ctx *ctx)
10941094
}
10951095

10961096
if (ctx->opts.bs && !ctx->bs) {
1097-
LOG_DBG("BS reached. Wait for FC again");
1098-
ctx->state = ISOTP_TX_WAIT_FC;
10991097
z_add_timeout(&ctx->timeout,
11001098
send_timeout_handler,
11011099
K_MSEC(ISOTP_BS));
1100+
ctx->state = ISOTP_TX_WAIT_FC;
1101+
LOG_DBG("BS reached. Wait for FC again");
11021102
break;
11031103
} else if (ctx->opts.stmin) {
11041104
ctx->state = ISOTP_TX_WAIT_ST;
@@ -1109,10 +1109,10 @@ static void send_state_machine(struct isotp_send_ctx *ctx)
11091109
break;
11101110

11111111
case ISOTP_TX_WAIT_ST:
1112-
LOG_DBG("SM wait ST");
11131112
z_add_timeout(&ctx->timeout, send_timeout_handler,
11141113
stmin_to_ticks(ctx->opts.stmin));
11151114
ctx->state = ISOTP_TX_SEND_CF;
1115+
LOG_DBG("SM wait ST");
11161116
break;
11171117

11181118
case ISOTP_TX_ERR:

0 commit comments

Comments
 (0)