Skip to content

Commit 555d7b4

Browse files
authored
Fix: ensure that there is space for enqueuing received CAN frames. (#56)
1 parent 4fad98a commit 555d7b4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/can_handler.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,12 @@ int can_handle_data()
150150

151151
if (can_1_rx_fifo_frames_available && can_1_should_enqueue)
152152
{
153-
for (rc_enq = 0; can_read(&fdcan_1, &can_id, &can_len, can_data); bytes_enqueued += rc_enq)
154-
{
155-
union x8h7_can_frame_message x8h7_msg;
153+
union x8h7_can_frame_message x8h7_msg;
156154

155+
for (rc_enq = 0;
156+
(get_available_enqueue() >= sizeof(x8h7_msg)) && can_read(&fdcan_1, &can_id, &can_len, can_data);
157+
bytes_enqueued += rc_enq)
158+
{
157159
x8h7_msg.field.id = can_id;
158160
x8h7_msg.field.len = can_len;
159161
memcpy(x8h7_msg.field.data, can_data, x8h7_msg.field.len);
@@ -173,10 +175,12 @@ int can_handle_data()
173175

174176
if (can_2_rx_fifo_frames_available && can_2_should_enqueue)
175177
{
176-
for (rc_enq = 0; can_read(&fdcan_2, &can_id, &can_len, can_data); bytes_enqueued += rc_enq)
177-
{
178-
union x8h7_can_frame_message x8h7_msg;
178+
union x8h7_can_frame_message x8h7_msg;
179179

180+
for (rc_enq = 0;
181+
(get_available_enqueue() >= sizeof(x8h7_msg)) && can_read(&fdcan_2, &can_id, &can_len, can_data);
182+
bytes_enqueued += rc_enq)
183+
{
180184
x8h7_msg.field.id = can_id;
181185
x8h7_msg.field.len = can_len;
182186
memcpy(x8h7_msg.field.data, can_data, x8h7_msg.field.len);

0 commit comments

Comments
 (0)