Debug log with dlog_if_slow, MACRAW ping working, wfi disabled
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
@@ -13,7 +14,15 @@ struct log_entry {
|
||||
inline ring_buffer<log_entry, 32> g_debug_log;
|
||||
|
||||
inline void dlog(std::string_view msg) {
|
||||
g_debug_log.push(log_entry{static_cast<uint32_t>(time_us_32()), std::string(msg)});
|
||||
g_debug_log.push_overwrite(log_entry{static_cast<uint32_t>(time_us_32()), std::string(msg)});
|
||||
}
|
||||
|
||||
inline void dlog_if_slow(std::string_view label, uint32_t threshold_us, std::function<void()> fn) {
|
||||
uint32_t t0 = time_us_32();
|
||||
fn();
|
||||
uint32_t elapsed = time_us_32() - t0;
|
||||
if (elapsed > threshold_us)
|
||||
dlog(std::string(label) + " " + std::to_string(elapsed) + "us");
|
||||
}
|
||||
|
||||
inline std::vector<log_entry> dlog_drain() {
|
||||
|
||||
@@ -24,6 +24,11 @@ struct ring_buffer {
|
||||
data[(tail++) % N] = v;
|
||||
}
|
||||
|
||||
void push_overwrite(const T& v) {
|
||||
if (free() == 0) head++;
|
||||
data[(tail++) % N] = v;
|
||||
}
|
||||
|
||||
uint16_t peek(std::span<T> dst) const {
|
||||
uint16_t len = dst.size() < used() ? dst.size() : used();
|
||||
for (uint16_t i = 0; i < len; i++)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "ring_buffer.h"
|
||||
|
||||
struct usb_cdc {
|
||||
ring_buffer<uint8_t, 512> tx;
|
||||
ring_buffer<uint8_t, 8192> tx;
|
||||
|
||||
void send(std::span<const uint8_t> data) {
|
||||
tx.push(data);
|
||||
|
||||
Reference in New Issue
Block a user