ChibiOS memory helper functions.

This commit is contained in:
Jared Boone 2016-02-12 13:52:22 -08:00
parent c72a443738
commit 4321deee1e
2 changed files with 27 additions and 0 deletions

View File

@ -21,6 +21,8 @@
#include "chibios_cpp.hpp" #include "chibios_cpp.hpp"
#include <cstdint>
#include <ch.h> #include <ch.h>
void* operator new(size_t size) { void* operator new(size_t size) {
@ -38,3 +40,21 @@ void operator delete(void* p) noexcept {
void operator delete[](void* p) noexcept { void operator delete[](void* p) noexcept {
chHeapFree(p); chHeapFree(p);
} }
extern uint8_t __heap_base__[];
extern uint8_t __heap_end__[];
namespace chibios {
size_t heap_size() {
return __heap_end__ - __heap_base__;
}
size_t heap_used() {
const auto core_free = chCoreStatus();
size_t heap_free = 0;
chHeapStatus(NULL, &heap_free);
return heap_size() - (core_free + heap_free);
}
} /* namespace chibios */

View File

@ -31,4 +31,11 @@ void* operator new[](size_t size);
void operator delete(void* p); void operator delete(void* p);
void operator delete[](void* p); void operator delete[](void* p);
namespace chibios {
size_t heap_size();
size_t heap_used();
} /* namespace chibios */
#endif/*__CHIBIOS_CPP_H__*/ #endif/*__CHIBIOS_CPP_H__*/