Warning gets printed if alloc/free was called from an IRQ

This commit is contained in:
Wiesner András 2023-10-31 12:02:40 +01:00
parent 754b43c51a
commit b8e1a4fe57

View File

@ -6,6 +6,10 @@
#include "memory_pool.h" #include "memory_pool.h"
#include "utils.h" #include "utils.h"
#ifdef OS
#include <cmsis_gcc.h>
#endif
MP *mp_init(uint8_t *p, uint32_t size) { MP *mp_init(uint8_t *p, uint32_t size) {
ASSERT_BAD_ALIGN(p); // check for alignment ASSERT_BAD_ALIGN(p); // check for alignment
size = FLOOR_TO_4(size); // force alignment on size size = FLOOR_TO_4(size); // force alignment on size
@ -60,6 +64,13 @@ uint8_t *mp_alloc(MP *mp, uint32_t size) {
// make the allocation from the beginning of the smallest suitable (large enough) // make the allocation from the beginning of the smallest suitable (large enough)
// contiguous block // contiguous block
#ifdef OS
// warn if allocation is made from an IRQ
if (__get_IPSR()) {
MSG("Alloc from IRQ!\n");
}
#endif
// round size to make it divisible by 4 // round size to make it divisible by 4
size = CEIL_TO_4(size); size = CEIL_TO_4(size);
@ -141,6 +152,13 @@ void mp_free(MP *mp, const uint8_t *p) {
return; return;
} }
#ifdef OS
// warn if memory block is getting released from an IRQ
if (__get_IPSR()) {
MSG("Free from IRQ!\n");
}
#endif
// look for registry record // look for registry record
bool success = false; bool success = false;
MPAllocRecord *recIter = mp->blockRegistry; MPAllocRecord *recIter = mp->blockRegistry;