Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bakerstu/openmrn
Browse files Browse the repository at this point in the history
* 'master' of github.com:bakerstu/openmrn:
  Fix MultiConfiguredPC.hxx compilation with C++20 (#737)
  Esp32 TWAI updates based on comments (#720)
  • Loading branch information
balazsracz committed Sep 23, 2023
2 parents 32a2abc + 4bc7ab2 commit 03af22a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
25 changes: 13 additions & 12 deletions src/freertos_drivers/esp32/Esp32HardwareTwai.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include <hal/twai_types.h>
#include <hal/twai_hal.h>
#include <soc/gpio_sig_map.h>
#include <stdint.h>

#include "can_frame.h"
#include "can_ioctl.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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" :
Expand Down
4 changes: 2 additions & 2 deletions src/freertos_drivers/esp32/Esp32HardwareTwai.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/openlcb/MultiConfiguredPC.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -153,7 +154,7 @@ public:
std::allocator<debouncer_type> alloc;
for (unsigned i = 0; i < size_; ++i)
{
alloc.destroy(debouncers_ + i);
alloc_traits::destroy(alloc, debouncers_ + i);
}
alloc.deallocate(debouncers_, size_);
}
Expand Down Expand Up @@ -336,6 +337,8 @@ public:
}

private:
using alloc_traits = std::allocator_traits<std::allocator<debouncer_type>>;

/// Removes registration of this event handler from the global event
/// registry.
void do_unregister()
Expand Down

0 comments on commit 03af22a

Please sign in to comment.