From 3d4f8ef67c834d72f3844a8c058e165798d35660 Mon Sep 17 00:00:00 2001 From: Mike Dunston Date: Sun, 10 Sep 2023 03:39:51 -0700 Subject: [PATCH 1/2] Esp32 TWAI updates based on comments (#720) Esp32HardwareTwai updates based on comments in #536. --- .../esp32/Esp32HardwareTwai.cxx | 25 ++++++++++--------- .../esp32/Esp32HardwareTwai.hxx | 4 +-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/freertos_drivers/esp32/Esp32HardwareTwai.cxx b/src/freertos_drivers/esp32/Esp32HardwareTwai.cxx index 2a1c62f20..029af31c0 100644 --- a/src/freertos_drivers/esp32/Esp32HardwareTwai.cxx +++ b/src/freertos_drivers/esp32/Esp32HardwareTwai.cxx @@ -68,6 +68,7 @@ #include #include #include +#include #include "can_frame.h" #include "can_ioctl.h" @@ -234,7 +235,7 @@ static inline void twai_purge_rx_queue() Notifiable* n = nullptr; { AtomicHolder h(&twai.buf_lock); - LOG(VERBOSE, "ESP-TWAI: puring RX-Q: %d", twai.rx_buf->pending()); + LOG(VERBOSE, "ESP-TWAI: purging RX-Q: %zu", twai.rx_buf->pending()); twai.stats.rx_missed += twai.rx_buf->pending(); twai.rx_buf->flush(); std::swap(n, twai.readable_notify); @@ -260,7 +261,7 @@ static inline void twai_purge_tx_queue() Notifiable* n = nullptr; { AtomicHolder h(&twai.buf_lock); - LOG(VERBOSE, "ESP-TWAI: puring TX-Q: %d", twai.tx_buf->pending()); + LOG(VERBOSE, "ESP-TWAI: purging TX-Q: %zu", twai.tx_buf->pending()); twai.stats.tx_failed += twai.tx_buf->pending(); twai.tx_buf->flush(); std::swap(n, twai.writable_notify); @@ -288,7 +289,7 @@ static inline void twai_purge_tx_queue() /// blocking operation. static ssize_t twai_vfs_write(int fd, const void *buf, size_t size) { - LOG(VERBOSE, "ESP-TWAI: write(%d, %p, %d)", fd, buf, size); + LOG(VERBOSE, "ESP-TWAI: write(%d, %p, %zu)", fd, buf, size); DASSERT(fd == TWAI_VFS_FD); ssize_t sent = 0; const struct can_frame *data = (const struct can_frame *)buf; @@ -307,7 +308,7 @@ static ssize_t twai_vfs_write(int fd, const void *buf, size_t size) else if (!is_twai_running()) { LOG_ERROR("ESP-TWAI: TWAI driver is not running, unable to write " - "%d frames.", size); + "%zu frames.", size); bus_error = true; break; } @@ -360,7 +361,7 @@ static ssize_t twai_vfs_write(int fd, const void *buf, size_t size) { errno = EWOULDBLOCK; } - LOG(VERBOSE, "ESP-TWAI: write() %d", sent * sizeof(struct can_frame)); + LOG(VERBOSE, "ESP-TWAI: write() %zu", sent * sizeof(struct can_frame)); return sent * sizeof(struct can_frame); } @@ -373,7 +374,7 @@ static ssize_t twai_vfs_write(int fd, const void *buf, size_t size) /// blocking operation. static ssize_t twai_vfs_read(int fd, void *buf, size_t size) { - LOG(VERBOSE, "ESP-TWAI: read(%d, %p, %d)", fd, buf, size); + LOG(VERBOSE, "ESP-TWAI: read(%d, %p, %zu)", fd, buf, size); DASSERT(fd == TWAI_VFS_FD); ssize_t received = 0; @@ -401,7 +402,7 @@ static ssize_t twai_vfs_read(int fd, void *buf, size_t size) return -1; } - LOG(VERBOSE, "ESP-TWAI: read() %d", received * sizeof(struct can_frame)); + LOG(VERBOSE, "ESP-TWAI: read() %zu", received * sizeof(struct can_frame)); return received * sizeof(struct can_frame); } @@ -715,7 +716,7 @@ static void twai_isr(void *arg) { BaseType_t wakeup = pdFALSE; uint32_t events = twai_hal_get_events(&twai.context); - ESP_EARLY_LOGV(TWAI_LOG_TAG, "events: %04x", events); + ESP_EARLY_LOGV(TWAI_LOG_TAG, "events: %08x", events); #if defined(CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID) || \ defined(CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT) @@ -793,8 +794,8 @@ static void twai_isr(void *arg) // Arbitration error detected if (events & TWAI_HAL_EVENT_ARB_LOST) { - twai.stats.arb_error++; - ESP_EARLY_LOGV(TWAI_LOG_TAG, "arb-lost:%d", twai.stats.arb_error); + twai.stats.arb_loss++; + ESP_EARLY_LOGV(TWAI_LOG_TAG, "arb-lost:%d", twai.stats.arb_loss); } if (wakeup == pdTRUE) @@ -877,13 +878,13 @@ void* twai_watchdog(void* param) "ESP-TWAI: " "RX:%d (pending:%zu,overrun:%d,discard:%d,missed:%d,lost:%d) " "TX:%d (pending:%zu,suc:%d,fail:%d) " - "Bus (arb-err:%d,err:%d,state:%s)", + "Bus (arb-loss:%d,err:%d,state:%s)", twai.stats.rx_processed, twai.rx_buf->pending(), twai.stats.rx_overrun, twai.stats.rx_discard, twai.stats.rx_missed, twai.stats.rx_lost, twai.stats.tx_processed, twai.tx_buf->pending(), twai.stats.tx_success, twai.stats.tx_failed, - twai.stats.arb_error, twai.stats.bus_error, + twai.stats.arb_loss, twai.stats.bus_error, is_twai_running() ? "Running" : is_twai_recovering() ? "Recovering" : is_twai_err_warn() ? "Err-Warn" : diff --git a/src/freertos_drivers/esp32/Esp32HardwareTwai.hxx b/src/freertos_drivers/esp32/Esp32HardwareTwai.hxx index c9f632fb0..b934d6125 100644 --- a/src/freertos_drivers/esp32/Esp32HardwareTwai.hxx +++ b/src/freertos_drivers/esp32/Esp32HardwareTwai.hxx @@ -87,8 +87,8 @@ typedef struct /// by the low-level TWAI driver. uint32_t tx_failed; - /// Number of arbitration errors that have been observed on the TWAI bus. - uint32_t arb_error; + /// Number of arbitration losses that have been observed on the TWAI bus. + uint32_t arb_loss; /// Number of general bus errors that have been observed on the TWAI bus. uint32_t bus_error; From 4bc7ab2f28bed3720391fcfbc7be930e5379a19e Mon Sep 17 00:00:00 2001 From: Mike Dunston Date: Sat, 23 Sep 2023 08:16:18 -0700 Subject: [PATCH 2/2] Fix MultiConfiguredPC.hxx compilation with C++20 (#737) Due to the C++20 standard removing the construct and destruct methods from std::allocator, it was necessary to adjust the code to use std::allocator_traits instead which has provided these methods since C++11. Fixes #711 === * Fix MultiConfiguredPC.hxx compilation with C++20 C++20 removed the construct / destruct methods from std::allocator with the replacement methods being part of std::allocator_traits intead. Fixes https://github.com/bakerstu/openmrn/issues/711 * Update MultiConfiguredPC.hxx Fix missing } * Update MultiConfiguredPC.hxx Due to the C++20 standard removing the construct and destruct methods from std::allocator, it was necessary to adjust the code to use std::allocator_traits instead which has provided these methods since C++11. --- src/openlcb/MultiConfiguredPC.hxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/openlcb/MultiConfiguredPC.hxx b/src/openlcb/MultiConfiguredPC.hxx index 707241209..dcb183f60 100644 --- a/src/openlcb/MultiConfiguredPC.hxx +++ b/src/openlcb/MultiConfiguredPC.hxx @@ -41,6 +41,7 @@ #include "openlcb/RefreshLoop.hxx" #include "utils/ConfigUpdateListener.hxx" #include "utils/ConfigUpdateService.hxx" +#include "utils/Debouncer.hxx" #include "utils/format_utils.hxx" namespace openlcb @@ -141,7 +142,7 @@ public: debouncers_ = alloc.allocate(size_); for (unsigned i = 0; i < size_; ++i) { - alloc.construct(debouncers_ + i, 3); + alloc_traits::construct(alloc, debouncers_ + i, 3); } } @@ -153,7 +154,7 @@ public: std::allocator alloc; for (unsigned i = 0; i < size_; ++i) { - alloc.destroy(debouncers_ + i); + alloc_traits::destroy(alloc, debouncers_ + i); } alloc.deallocate(debouncers_, size_); } @@ -336,6 +337,8 @@ public: } private: + using alloc_traits = std::allocator_traits>; + /// Removes registration of this event handler from the global event /// registry. void do_unregister()