Skip to content

Commit 500809f

Browse files
benjaminbjornssonstephanosio
authored andcommitted
drivers: can: can_loopback: Abort pending messages when stopped
This commit aims at updating the drivers stop function to better follow the CAN header file which specifiec that stopping the CAN controller should "abort any pending CAN frame transmissions". Signed-off-by: Benjamin Björnsson <[email protected]>
1 parent 03fd995 commit 500809f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/can/can_loopback.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,17 @@ static void tx_thread(void *arg1, void *arg2, void *arg3)
6666
struct can_loopback_data *data = dev->data;
6767
struct can_loopback_frame frame;
6868
struct can_loopback_filter *filter;
69+
int ret;
6970

7071
ARG_UNUSED(arg2);
7172
ARG_UNUSED(arg3);
7273

7374
while (1) {
74-
k_msgq_get(&data->tx_msgq, &frame, K_FOREVER);
75+
ret = k_msgq_get(&data->tx_msgq, &frame, K_FOREVER);
76+
if (ret < 0) {
77+
LOG_DBG("Pend on TX queue returned without valid frame (err %d)", ret);
78+
continue;
79+
}
7580
frame.cb(dev, 0, frame.cb_arg);
7681

7782
if (!data->loopback) {
@@ -255,6 +260,8 @@ static int can_loopback_stop(const struct device *dev)
255260

256261
data->started = false;
257262

263+
k_msgq_purge(&data->tx_msgq);
264+
258265
return 0;
259266
}
260267

0 commit comments

Comments
 (0)