Skip to content

Commit

Permalink
canbus: isotp: add _TIMEOUT_MS suffix to defines for timeouts
Browse files Browse the repository at this point in the history
The defines like ISOTP_A were obfuscating that this is actually a
timeout value.

(cherry picked from commit b82a447)

Original-Signed-off-by: Martin Jäger <martin@libre.solar>
GitOrigin-RevId: b82a447
Change-Id: I597fef4e040845a46e3b30446dadf20279761628
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4882966
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
Commit-Queue: Al Semjonovs <asemjonovs@google.com>
Tested-by: Al Semjonovs <asemjonovs@google.com>
  • Loading branch information
martinjaeger authored and Chromeos LUCI committed Sep 21, 2023
1 parent 0401e5f commit f995045
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
26 changes: 11 additions & 15 deletions subsys/canbus/isotp/isotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ static void receive_send_fc(struct isotp_recv_ctx *ctx, uint8_t fs)
frame.dlc = can_bytes_to_dlc(payload_len);
#endif

ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A),
receive_can_tx, ctx);
ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A_TIMEOUT_MS), receive_can_tx, ctx);
if (ret) {
LOG_ERR("Can't send FC, (%d)", ret);
receive_report_error(ctx, ISOTP_N_TIMEOUT_A);
Expand Down Expand Up @@ -238,7 +237,7 @@ static int receive_alloc_buffer(struct isotp_recv_ctx *ctx)
}

if (!buf) {
k_timer_start(&ctx->timer, K_MSEC(ISOTP_ALLOC_TIMEOUT), K_NO_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_ALLOC_TIMEOUT_MS), K_NO_WAIT);

if (ctx->wft == ISOTP_WFT_FIRST) {
LOG_DBG("Allocation failed. Append to alloc list");
Expand Down Expand Up @@ -328,15 +327,15 @@ static void receive_state_machine(struct isotp_recv_ctx *ctx)
case ISOTP_RX_STATE_SEND_FC:
LOG_DBG("SM send CTS FC frame");
receive_send_fc(ctx, ISOTP_PCI_FS_CTS);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_CR), K_NO_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_CR_TIMEOUT_MS), K_NO_WAIT);
ctx->state = ISOTP_RX_STATE_WAIT_CF;
break;

case ISOTP_RX_STATE_SEND_WAIT:
if (++ctx->wft < CONFIG_ISOTP_WFTMAX) {
LOG_DBG("Send wait frame number %d", ctx->wft);
receive_send_fc(ctx, ISOTP_PCI_FS_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_ALLOC_TIMEOUT), K_NO_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_ALLOC_TIMEOUT_MS), K_NO_WAIT);
ctx->state = ISOTP_RX_STATE_TRY_ALLOC;
break;
}
Expand Down Expand Up @@ -516,7 +515,7 @@ static void process_cf(struct isotp_recv_ctx *ctx, struct can_frame *frame)
return;
}

k_timer_start(&ctx->timer, K_MSEC(ISOTP_CR), K_NO_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_CR_TIMEOUT_MS), K_NO_WAIT);

if ((frame->data[index++] & ISOTP_PCI_SN_MASK) != ctx->sn_expected++) {
LOG_ERR("Sequence number mismatch");
Expand Down Expand Up @@ -842,7 +841,7 @@ static void send_process_fc(struct isotp_send_ctx *ctx,

case ISOTP_PCI_FS_WAIT:
LOG_DBG("Got WAIT frame");
k_timer_start(&ctx->timer, K_MSEC(ISOTP_BS), K_NO_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_BS_TIMEOUT_MS), K_NO_WAIT);
if (ctx->wft >= CONFIG_ISOTP_WFTMAX) {
LOG_INF("Got to many wait frames");
send_report_error(ctx, ISOTP_N_WFT_OVRN);
Expand Down Expand Up @@ -949,8 +948,7 @@ static inline int send_sf(struct isotp_send_ctx *ctx)
}

ctx->state = ISOTP_TX_SEND_SF;
ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A),
send_can_tx_cb, ctx);
ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A_TIMEOUT_MS), send_can_tx_cb, ctx);
return ret;
}

Expand Down Expand Up @@ -990,8 +988,7 @@ static inline int send_ff(struct isotp_send_ctx *ctx)
pull_send_ctx_data(ctx, ctx->tx_addr.dl - index);
memcpy(&frame.data[index], data, ctx->tx_addr.dl - index);

ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A),
send_can_tx_cb, ctx);
ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A_TIMEOUT_MS), send_can_tx_cb, ctx);
return ret;
}

Expand Down Expand Up @@ -1033,8 +1030,7 @@ static inline int send_cf(struct isotp_send_ctx *ctx)
frame.dlc = can_bytes_to_dlc(len + index);
}

ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A),
send_can_tx_cb, ctx);
ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A_TIMEOUT_MS), send_can_tx_cb, ctx);
if (ret == 0) {
ctx->sn++;
pull_send_ctx_data(ctx, len);
Expand Down Expand Up @@ -1099,7 +1095,7 @@ static void send_state_machine(struct isotp_send_ctx *ctx)

case ISOTP_TX_SEND_FF:
send_ff(ctx);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_BS), K_NO_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_BS_TIMEOUT_MS), K_NO_WAIT);
ctx->state = ISOTP_TX_WAIT_FC;
LOG_DBG("SM send FF");
break;
Expand All @@ -1123,7 +1119,7 @@ static void send_state_machine(struct isotp_send_ctx *ctx)
}

if (ctx->opts.bs && !ctx->bs) {
k_timer_start(&ctx->timer, K_MSEC(ISOTP_BS), K_NO_WAIT);
k_timer_start(&ctx->timer, K_MSEC(ISOTP_BS_TIMEOUT_MS), K_NO_WAIT);
ctx->state = ISOTP_TX_WAIT_FC;
LOG_DBG("BS reached. Wait for FC again");
break;
Expand Down
8 changes: 4 additions & 4 deletions subsys/canbus/isotp/isotp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@

#define ISOTP_4BIT_SF_MAX_CAN_DL 8

#define ISOTP_BS (CONFIG_ISOTP_BS_TIMEOUT)
#define ISOTP_A (CONFIG_ISOTP_A_TIMEOUT)
#define ISOTP_CR (CONFIG_ISOTP_CR_TIMEOUT)
#define ISOTP_BS_TIMEOUT_MS (CONFIG_ISOTP_BS_TIMEOUT)
#define ISOTP_A_TIMEOUT_MS (CONFIG_ISOTP_A_TIMEOUT)
#define ISOTP_CR_TIMEOUT_MS (CONFIG_ISOTP_CR_TIMEOUT)

/* Just before the sender would time out*/
#define ISOTP_ALLOC_TIMEOUT (CONFIG_ISOTP_A_TIMEOUT - 100)
#define ISOTP_ALLOC_TIMEOUT_MS (CONFIG_ISOTP_A_TIMEOUT - 100)

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit f995045

Please sign in to comment.