mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
ChibiOS memory helper functions.
This commit is contained in:
parent
c72a443738
commit
4321deee1e
@ -21,6 +21,8 @@
|
||||
|
||||
#include "chibios_cpp.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <ch.h>
|
||||
|
||||
void* operator new(size_t size) {
|
||||
@ -38,3 +40,21 @@ void operator delete(void* p) noexcept {
|
||||
void operator delete[](void* p) noexcept {
|
||||
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 */
|
||||
|
@ -31,4 +31,11 @@ void* operator new[](size_t size);
|
||||
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__*/
|
||||
|
Loading…
Reference in New Issue
Block a user