#include "trace.h" #include #include "itoa.h" #include "lock.h" #include "uart.h" namespace tracing { namespace { constexpr size_t kTraceBufferSize = 256; std::array buffer; size_t write_ptr = 0; } // namespace void trace(int raw_event) { trace(static_cast(raw_event)); } void trace(TraceEvent event) { InterruptLock lock; buffer[write_ptr] = event; write_ptr = (write_ptr + 1) % buffer.size(); } void dump() { std::rotate(buffer.begin(), buffer.begin() + write_ptr, buffer.end()); char number[] = "00000000\r\n"; for (TraceEvent event : buffer) { itoa(static_cast(event), number); UartSendCrash(number); } } } // namespace tracing