From b8e1a4fe57806521a25d910fbec0e0535b82a4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiesner=20Andr=C3=A1s?= Date: Tue, 31 Oct 2023 12:02:40 +0100 Subject: [PATCH] Warning gets printed if alloc/free was called from an IRQ --- memory_pool.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/memory_pool.c b/memory_pool.c index c402324..dc941d3 100644 --- a/memory_pool.c +++ b/memory_pool.c @@ -6,6 +6,10 @@ #include "memory_pool.h" #include "utils.h" +#ifdef OS +#include +#endif + MP *mp_init(uint8_t *p, uint32_t size) { ASSERT_BAD_ALIGN(p); // check for alignment 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) // 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 size = CEIL_TO_4(size); @@ -141,6 +152,13 @@ void mp_free(MP *mp, const uint8_t *p) { 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 bool success = false; MPAllocRecord *recIter = mp->blockRegistry;