From 3adcfb04445df43bf0ec7c342c5dbef859283839 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Oct 2023 13:02:03 +1100 Subject: [PATCH] CAN: handle higher packet rate don't get stuck in rx at very high packet rates --- RemoteIDModule/CANDriver.cpp | 2 +- RemoteIDModule/DroneCAN.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RemoteIDModule/CANDriver.cpp b/RemoteIDModule/CANDriver.cpp index 46cd647..fb431f6 100644 --- a/RemoteIDModule/CANDriver.cpp +++ b/RemoteIDModule/CANDriver.cpp @@ -46,7 +46,7 @@ void CANDriver::init(uint32_t bitrate, uint32_t acceptance_code, uint32_t accept static const twai_general_config_t g_config = {.mode = TWAI_MODE_NORMAL, .tx_io = PIN_CAN_TX, .rx_io = PIN_CAN_RX, \ .clkout_io = TWAI_IO_UNUSED, .bus_off_io = TWAI_IO_UNUSED, \ - .tx_queue_len = 5, .rx_queue_len = 5, \ + .tx_queue_len = 5, .rx_queue_len = 50, \ .alerts_enabled = TWAI_ALERT_NONE, .clkout_divider = 0, \ .intr_flags = ESP_INTR_FLAG_LEVEL2 }; diff --git a/RemoteIDModule/DroneCAN.cpp b/RemoteIDModule/DroneCAN.cpp index b0f358d..63c82c3 100644 --- a/RemoteIDModule/DroneCAN.cpp +++ b/RemoteIDModule/DroneCAN.cpp @@ -267,7 +267,8 @@ void DroneCAN::processTx(void) void DroneCAN::processRx(void) { CANFrame rxmsg; - while (can_driver.receive(rxmsg)) { + uint8_t count = 60; + while (count-- && can_driver.receive(rxmsg)) { CanardCANFrame rx_frame {}; uint64_t timestamp = micros64(); rx_frame.data_len = CANFrame::dlcToDataLength(rxmsg.dlc);