Skip to content

Commit 1f57e73

Browse files
henrikbrixandersennashif
authored andcommitted
canbus: isotp: ensure consecutive frames are sent in FIFO order
Ensure that ISO-TP Consecutive Frames (CF) are sent in FIFO/chronological order. In order to ensure this, we can only have one CF queued in the CAN controller TX mailboxes at a time, since transmit order for mailboxes with the same CAN-ID (priority) is hardware specific. Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent fc5f792 commit 1f57e73

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/canbus/isotp.h

+1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ struct isotp_send_ctx {
391391
struct isotp_fc_opts opts;
392392
uint8_t state;
393393
uint8_t tx_backlog;
394+
struct k_sem tx_sem;
394395
struct isotp_msg_id rx_addr;
395396
struct isotp_msg_id tx_addr;
396397
uint8_t wft;

subsys/canbus/isotp/isotp.c

+6
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ static void send_can_tx_cb(int error, void *arg)
728728
struct isotp_send_ctx *ctx = (struct isotp_send_ctx *)arg;
729729

730730
ctx->tx_backlog--;
731+
k_sem_give(&ctx->tx_sem);
731732

732733
if (ctx->state == ISOTP_TX_WAIT_BACKLOG) {
733734
if (ctx->tx_backlog > 0) {
@@ -784,6 +785,7 @@ static void send_process_fc(struct isotp_send_ctx *ctx,
784785
ctx->state = ISOTP_TX_SEND_CF;
785786
ctx->wft = 0;
786787
ctx->tx_backlog = 0;
788+
k_sem_reset(&ctx->tx_sem);
787789
ctx->opts.bs = *data++;
788790
ctx->opts.stmin = *data++;
789791
ctx->bs = ctx->opts.bs;
@@ -1068,6 +1070,9 @@ static void send_state_machine(struct isotp_send_ctx *ctx)
10681070
ctx->state = ISOTP_TX_WAIT_ST;
10691071
break;
10701072
}
1073+
1074+
/* Ensure FIFO style transmission of CF */
1075+
k_sem_take(&ctx->tx_sem, K_FOREVER);
10711076
} while (ret > 0);
10721077

10731078
break;
@@ -1154,6 +1159,7 @@ static int send(struct isotp_send_ctx *ctx, const struct device *can_dev,
11541159
ctx->has_callback = 0;
11551160
}
11561161

1162+
k_sem_init(&ctx->tx_sem, 0, 1);
11571163
ctx->can_dev = can_dev;
11581164
ctx->tx_addr = *tx_addr;
11591165
ctx->rx_addr = *rx_addr;

0 commit comments

Comments
 (0)