Introduce CONFIG option to enable/disable microbit heap allocator

- Add CONFIG option to MicroBitConfig.h
  - Add YOTTA glue for config.json mapping
  - Introduce conditional compilation into MicroBitHeapAllocator.cpp
This commit is contained in:
Joe Finney 2018-09-07 17:41:49 +01:00
parent 4dda6ef298
commit 1a4d5abd7b
3 changed files with 27 additions and 0 deletions

View file

@ -109,6 +109,15 @@ extern uint32_t __etext;
#define FLASH_PROGRAM_END (uint32_t) (&__etext)
#endif
//
// If set to '1', this option enables the microbit heap allocator. This supports multiple heaps and interrupt safe operation.
// If set to '0', the standard GCC libc heap allocator is used, which restricts available memory in BLE scenarios, and MessageBus operations
// in ISR contexts will no longer be safe.
//
#ifndef MICROBIT_HEAP_ENABLED
#define MICROBIT_HEAP_ENABLED 1
#endif
// Block size used by the allocator in bytes.
// n.b. Currently only 32 bits (4 bytes) is supported.

View file

@ -71,6 +71,10 @@
#define MICROBIT_DEFAULT_PULLMODE YOTTA_CFG_MICROBIT_DAL_DEFAULT_PULLMODE
#endif
#ifdef YOTTA_CFG_MICROBIT_DAL_HEAP_ENABLED
#define MICROBIT_HEAP_ENABLED YOTTA_CFG_MICROBIT_DAL_HEAP_ENABLED
#endif
#ifdef YOTTA_CFG_MICROBIT_DAL_PANIC_ON_HEAP_FULL
#define MICROBIT_PANIC_HEAP_FULL YOTTA_CFG_MICROBIT_DAL_PANIC_ON_HEAP_FULL
#endif

View file

@ -54,6 +54,8 @@ DEALINGS IN THE SOFTWARE.
#include "MicroBitCompat.h"
#include "ErrorNo.h"
#if CONFIG_ENABLED(MICROBIT_HEAP_ENABLED)
// A list of all active heap regions, and their dimensions in memory.
HeapDefinition heap[MICROBIT_MAXIMUM_HEAPS] = { };
uint8_t heap_count = 0;
@ -395,3 +397,15 @@ _realloc_r (struct _reent *ptr, void *old, size_t newlen)
(void) ptr;
return realloc (old, newlen);
}
#else
int microbit_create_heap(uint32_t start, uint32_t end)
{
(void) start;
(void) end;
return MICROBIT_OK;
}
#endif