arm: move trace dump to crash handler

This commit is contained in:
2022-06-19 09:48:28 +02:00
parent ec024adfff
commit 02fbb1c671
3 changed files with 14 additions and 7 deletions

View File

@@ -7,14 +7,19 @@
#include "timer.h"
#include "uart.h"
#ifndef SBRK_STATS
#define SBRK_STATS 0
#endif
extern unsigned char _heap_begin, _heap_end;
namespace {
[[maybe_unused]]
void LogStats(unsigned char* heap) {
char number[] = "00000000\r\n";
UartWriteBlocking("Program break now at 0x");
UartWriteCrash("Program break now at 0x");
itoa(reinterpret_cast<int>(heap), number);
UartWriteBlocking(number);
UartWriteCrash(number);
}
} // namespace
@@ -22,11 +27,13 @@ extern "C" void* _sbrk(int increment) {
static unsigned char* heap = &_heap_begin;
unsigned char* prev_heap = heap;
if (heap + increment >= &_heap_end) {
UartWriteBlocking("Heap overflow!\r\n");
UartWriteCrash("Heap overflow!\r\n");
return reinterpret_cast<void*>(-1);
}
heap += increment;
#if SBRK_STATS
LogStats(heap);
#endif
return prev_heap;
}