2022-05-17 03:56:25 +00:00
|
|
|
#include "trace.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "itoa.h"
|
|
|
|
#include "lock.h"
|
|
|
|
#include "uart.h"
|
|
|
|
|
|
|
|
namespace tracing {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr size_t kTraceBufferSize = 256;
|
|
|
|
std::array<TraceEvent, kTraceBufferSize> buffer;
|
|
|
|
size_t write_ptr = 0;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void trace(int raw_event) { trace(static_cast<TraceEvent>(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<int>(event), number);
|
2022-05-17 17:17:56 +00:00
|
|
|
UartWriteCrash(number);
|
2022-05-17 03:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace tracing
|