Skip to content

Commit b8eb11d

Browse files
henrikbrixandersenfabiobaltieri
authored andcommitted
drivers: can: mcux: flexcan: abort transfers before entering freeze mode
Abort any pending transmissions before entering freeze mode and notify the senders. Fixes: #50545 Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 94d4638 commit b8eb11d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

drivers/can/can_mcux_flexcan.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,31 @@ static int mcux_flexcan_stop(const struct device *dev)
220220
{
221221
const struct mcux_flexcan_config *config = dev->config;
222222
struct mcux_flexcan_data *data = dev->data;
223+
can_tx_callback_t function;
224+
void *arg;
225+
int alloc;
223226
int err;
224227

225228
if (!data->started) {
226229
return -EALREADY;
227230
}
228231

232+
data->started = false;
233+
234+
/* Abort any pending TX frames before entering freeze mode */
235+
for (alloc = 0; alloc < MCUX_FLEXCAN_MAX_TX; alloc++) {
236+
function = data->tx_cbs[alloc].function;
237+
arg = data->tx_cbs[alloc].arg;
238+
239+
if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) {
240+
FLEXCAN_TransferAbortSend(config->base, &data->handle,
241+
ALLOC_IDX_TO_TXMB_IDX(alloc));
242+
243+
function(dev, -ENETDOWN, arg);
244+
k_sem_give(&data->tx_allocs_sem);
245+
}
246+
}
247+
229248
FLEXCAN_EnterFreezeMode(config->base);
230249

231250
if (config->phy != NULL) {
@@ -236,8 +255,6 @@ static int mcux_flexcan_stop(const struct device *dev)
236255
}
237256
}
238257

239-
data->started = false;
240-
241258
return 0;
242259
}
243260

0 commit comments

Comments
 (0)