50 Trace(
const char*
const* names,
const uint8_t num) : _names{names}, _num{num}
60 void record(
const uint8_t ev,
const uint32_t irq = 0,
const uint8_t detail = 0)
62#if defined(M5_UNIT_NFC_EMULATION_TRACE)
63 const uint32_t now = m5::utility::millis();
69 const uint16_t look = (_count < LOOKBACK) ? _count : LOOKBACK;
70 for (uint_fast16_t back = 1; back <= look; ++back) {
71 auto& e = _entry[(_head + _count - back) % MAX];
72 if (e.ev == ev && e.detail == detail) {
73 if (e.count < 0xFFFF) {
77 const uint32_t span = now - e.ms;
78 e.span = (span > 0xFFFF) ? 0xFFFF : (uint16_t)span;
84 _entry[(_head + _count++) % MAX] = Entry{now, irq, 1, 0, ev, detail};
87 _entry[_head] = Entry{now, irq, 1, 0, ev, detail};
88 _head = (_head + 1) % MAX;
104#if defined(M5_UNIT_NFC_EMULATION_TRACE)
108 printf(
"---- emulation trace %u", _count);
110 printf(
" (%u older dropped)", _dropped);
114 for (uint_fast16_t i = 0; i < _count; ++i) {
115 const auto& e = _entry[(_head + i) % MAX];
116 printf(
"T[%03u] %7u %-9s irq:%08X detail:%02X", (
unsigned)i, (
unsigned)e.ms,
117 (e.ev < _num) ? _names[e.ev] :
"?", (unsigned)e.irq, e.detail);
119 printf(
" x%u (%u ms)", e.count, e.span);
130#if defined(M5_UNIT_NFC_EMULATION_TRACE)
138#if defined(M5_UNIT_NFC_EMULATION_TRACE)
147 static constexpr uint16_t MAX{M5_UNIT_NFC_EMULATION_TRACE_MAX};
149 static constexpr uint16_t LOOKBACK{2};
151 uint16_t _head{}, _count{}, _dropped{};
153 const char*
const* _names{};