From ac72e272ee0ba6295250f66f8885929229729382 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Mar 2023 13:25:37 +0100 Subject: [PATCH] Fix rp2040 build. --- components/truma_inetbox/LinBusListener.cpp | 6 +++--- components/truma_inetbox/LinBusListener.h | 12 ++++++------ .../truma_inetbox/LinBusListener_esp32_arduino.cpp | 6 +++++- components/truma_inetbox/LinBusListener_esp_idf.cpp | 8 ++++++-- components/truma_inetbox/LinBusListener_rp2040.cpp | 8 ++++++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/components/truma_inetbox/LinBusListener.cpp b/components/truma_inetbox/LinBusListener.cpp index 04fb06a..b0c1ca7 100644 --- a/components/truma_inetbox/LinBusListener.cpp +++ b/components/truma_inetbox/LinBusListener.cpp @@ -65,7 +65,7 @@ void LinBusListener::setup() { } // Register interval to submit log messages - this->set_interval("logmsg", 50, [this]() { this->process_log_queue_(QUEUE_WAIT_DONT_BLOCK); }); + this->set_interval("logmsg", 50, [this]() { this->process_log_queue(QUEUE_WAIT_DONT_BLOCK); }); } void LinBusListener::update() { this->check_for_lin_fault_(); } @@ -323,14 +323,14 @@ void LinBusListener::clear_uart_buffer_() { } } -void LinBusListener::process_lin_msg_queue_(TickType_t xTicksToWait) { +void LinBusListener::process_lin_msg_queue(TickType_t xTicksToWait) { QUEUE_LIN_MSG lin_msg; while (xQueueReceive(this->lin_msg_queue_, &lin_msg, xTicksToWait) == pdPASS) { this->lin_message_recieved_(lin_msg.current_PID, lin_msg.data, lin_msg.len); } } -void LinBusListener::process_log_queue_(TickType_t xTicksToWait) { +void LinBusListener::process_log_queue(TickType_t xTicksToWait) { QUEUE_LOG_MSG log_msg; while (xQueueReceive(this->log_queue_, &log_msg, xTicksToWait) == pdPASS) { auto current_PID = log_msg.current_PID; diff --git a/components/truma_inetbox/LinBusListener.h b/components/truma_inetbox/LinBusListener.h index a7ed684..742c284 100644 --- a/components/truma_inetbox/LinBusListener.h +++ b/components/truma_inetbox/LinBusListener.h @@ -7,12 +7,11 @@ #include #include #endif // USE_ESP32 -#ifdef USE_ESP32_FRAMEWORK_ESP_IDF -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#endif // USE_ESP32_FRAMEWORK_ESP_IDF #ifdef USE_RP2040 #include +#include +#include +#include #endif // USE_RP2040 namespace esphome { @@ -78,6 +77,9 @@ class LinBusListener : public PollingComponent, public uart::UARTDevice { void set_observer_mode(bool val) { this->observer_mode_ = val; } bool get_lin_bus_fault() { return fault_on_lin_bus_reported_ > 3; } + void process_lin_msg_queue(TickType_t xTicksToWait); + void process_log_queue(TickType_t xTicksToWait); + #ifdef USE_RP2040 // Return is the expected wait time till next data check is recommended. u_int32_t onSerialEvent(); @@ -143,8 +145,6 @@ class LinBusListener : public PollingComponent, public uart::UARTDevice { void read_lin_frame_(); void clear_uart_buffer_(); void setup_framework(); - void process_lin_msg_queue_(TickType_t xTicksToWait); - void process_log_queue_(TickType_t xTicksToWait); uint8_t lin_msg_static_queue_storage[6 * sizeof(QUEUE_LIN_MSG)]; StaticQueue_t lin_msg_static_queue_; diff --git a/components/truma_inetbox/LinBusListener_esp32_arduino.cpp b/components/truma_inetbox/LinBusListener_esp32_arduino.cpp index 9e38f58..4dd33cd 100644 --- a/components/truma_inetbox/LinBusListener_esp32_arduino.cpp +++ b/components/truma_inetbox/LinBusListener_esp32_arduino.cpp @@ -12,6 +12,8 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.LinBusListener"; +#define QUEUE_WAIT_BLOCKING (portTickType) portMAX_DELAY + void LinBusListener::setup_framework() { auto uartComp = static_cast(this->parent_); @@ -66,11 +68,13 @@ void LinBusListener::setup_framework() { void LinBusListener::eventTask_(void *args) { LinBusListener *instance = (LinBusListener *) args; for (;;) { - instance->process_lin_msg_queue_((portTickType) portMAX_DELAY); + instance->process_lin_msg_queue(QUEUE_WAIT_BLOCKING); } } } // namespace truma_inetbox } // namespace esphome +#undef QUEUE_WAIT_BLOCKING + #endif // USE_ESP32_FRAMEWORK_ARDUINO \ No newline at end of file diff --git a/components/truma_inetbox/LinBusListener_esp_idf.cpp b/components/truma_inetbox/LinBusListener_esp_idf.cpp index 5a1b5ad..c3ab886 100644 --- a/components/truma_inetbox/LinBusListener_esp_idf.cpp +++ b/components/truma_inetbox/LinBusListener_esp_idf.cpp @@ -10,6 +10,8 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.LinBusListener"; +#define QUEUE_WAIT_BLOCKING (portTickType) portMAX_DELAY + void LinBusListener::setup_framework() { // uartSetFastReading auto uartComp = static_cast(this->parent_); @@ -64,7 +66,7 @@ void LinBusListener::uartEventTask_(void *args) { uart_event_t event; for (;;) { // Waiting for UART event. - if (xQueueReceive(*uartEventQueue, (void *) &event, (portTickType) portMAX_DELAY)) { + if (xQueueReceive(*uartEventQueue, (void *) &event, QUEUE_WAIT_BLOCKING)) { if (event.type == UART_DATA && instance->available() > 0) { instance->onReceive_(); } else if (event.type == UART_BREAK) { @@ -82,11 +84,13 @@ void LinBusListener::uartEventTask_(void *args) { void LinBusListener::eventTask_(void *args) { LinBusListener *instance = (LinBusListener *) args; for (;;) { - instance->process_lin_msg_queue_((portTickType) portMAX_DELAY); + instance->process_lin_msg_queue(QUEUE_WAIT_BLOCKING); } } } // namespace truma_inetbox } // namespace esphome +#undef QUEUE_WAIT_BLOCKING + #endif // USE_ESP32_FRAMEWORK_ESP_IDF \ No newline at end of file diff --git a/components/truma_inetbox/LinBusListener_rp2040.cpp b/components/truma_inetbox/LinBusListener_rp2040.cpp index 51472b6..a6def53 100644 --- a/components/truma_inetbox/LinBusListener_rp2040.cpp +++ b/components/truma_inetbox/LinBusListener_rp2040.cpp @@ -15,6 +15,8 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.LinBusListener"; +#define QUEUE_WAIT_DONT_BLOCK (TickType_t) 0 + void LinBusListener::setup_framework() { auto uartComp = static_cast(this->parent_); auto is_hw_serial = uartComp->is_hw_serial(); @@ -101,13 +103,15 @@ extern void loop1() { // TODO: Reconsider processing lin messages here. // They contain blocking log messages. if (LIN_BUS_LISTENER_INSTANCE_1 != nullptr) { - LIN_BUS_LISTENER_INSTANCE_1->process_lin_msg_queue_((portTickType) 0 /* No blocking*/); + LIN_BUS_LISTENER_INSTANCE_1->process_lin_msg_queue(QUEUE_WAIT_DONT_BLOCK); } if (LIN_BUS_LISTENER_INSTANCE_2 != nullptr) { - LIN_BUS_LISTENER_INSTANCE_2->process_lin_msg_queue_((portTickType) 0 /* No blocking*/); + LIN_BUS_LISTENER_INSTANCE_2->process_lin_msg_queue(QUEUE_WAIT_DONT_BLOCK); } delay(sleep1 > sleep2 ? sleep2 : sleep1); } } +#undef QUEUE_WAIT_DONT_BLOCK + #endif // USE_RP2040