Skip to content

Commit 6cf34d0

Browse files
henrikbrixandersenfabiobaltieri
authored andcommitted
drivers: can: mcan: notify of aborted transmission on can_stop()
Notify of any aborted transmission when entering init mode via can_stop(). Fixes: #50545 Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent b8eb11d commit 6cf34d0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/can/can_mcan.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,15 @@ int can_mcan_stop(const struct device *dev)
257257
const struct can_mcan_config *cfg = dev->config;
258258
struct can_mcan_data *data = dev->data;
259259
struct can_mcan_reg *can = cfg->can;
260+
can_tx_callback_t tx_cb;
261+
uint32_t tx_idx;
260262
int ret;
261263

262264
if (!data->started) {
263265
return -EALREADY;
264266
}
265267

268+
/* CAN transmissions are automatically stopped when entering init mode */
266269
ret = can_enter_init_mode(can, K_MSEC(CAN_INIT_TIMEOUT));
267270
if (ret != 0) {
268271
LOG_ERR("Failed to enter init mode");
@@ -281,6 +284,16 @@ int can_mcan_stop(const struct device *dev)
281284

282285
data->started = false;
283286

287+
for (tx_idx = 0; tx_idx < ARRAY_SIZE(data->tx_fin_cb); tx_idx++) {
288+
tx_cb = data->tx_fin_cb[tx_idx];
289+
290+
if (tx_cb != NULL) {
291+
data->tx_fin_cb[tx_idx] = NULL;
292+
tx_cb(dev, -ENETDOWN, data->tx_fin_cb_arg[tx_idx]);
293+
k_sem_give(&data->tx_sem);
294+
}
295+
}
296+
284297
return 0;
285298
}
286299

@@ -554,6 +567,7 @@ static void can_mcan_tc_event_handler(const struct device *dev)
554567
k_sem_give(&data->tx_sem);
555568

556569
tx_cb = data->tx_fin_cb[tx_idx];
570+
data->tx_fin_cb[tx_idx] = NULL;
557571
tx_cb(dev, 0, data->tx_fin_cb_arg[tx_idx]);
558572
}
559573
}

0 commit comments

Comments
 (0)