diff --git a/inc/core/MicroBitHeapAllocator.h b/inc/core/MicroBitHeapAllocator.h index 10aa5c94..115a2511 100644 --- a/inc/core/MicroBitHeapAllocator.h +++ b/inc/core/MicroBitHeapAllocator.h @@ -52,6 +52,7 @@ DEALINGS IN THE SOFTWARE. #define MICROBIT_HEAP_ALLOCTOR_H #include "MicroBitConfig.h" +#include // The maximum number of heap segments that can be created. #define MICROBIT_MAXIMUM_HEAPS 2 @@ -85,4 +86,27 @@ struct HeapDefinition int microbit_create_heap(uint32_t start, uint32_t end); void microbit_heap_print(); +/** + * Attempt to allocate a given amount of memory from any of our configured heap areas. + * + * @param size The amount of memory, in bytes, to allocate. + * + * @return A pointer to the allocated memory, or NULL if insufficient memory is available. + */ +void *_microbit_malloc(size_t size); +void* _microbit_calloc (size_t num, size_t size); +void* _microbit_realloc (void* ptr, size_t size); + +/** + * Release a given area of memory from the heap. + * + * @param mem The memory area to release. + */ +void _microbit_free(void *mem); + +#define malloc _microbit_malloc +#define free _microbit_free +#define calloc _microbit_calloc +#define realloc _microbit_realloc + #endif diff --git a/inc/core/MicroBitUtil.h b/inc/core/MicroBitUtil.h index d9fc5f74..087cf8d4 100644 --- a/inc/core/MicroBitUtil.h +++ b/inc/core/MicroBitUtil.h @@ -32,7 +32,7 @@ DEALINGS IN THE SOFTWARE. #include "MicroBitConfig.h" -#define CREATE_KEY_VALUE_TABLE(NAME, PAIRS) const KeyValueTable NAME { PAIRS, sizeof(PAIRS) / sizeof(KeyValueTableEntry) }; +#define CREATE_KEY_VALUE_TABLE(NAME, PAIRS) const KeyValueTable NAME = { PAIRS, sizeof(PAIRS) / sizeof(KeyValueTableEntry) }; /** * Provides a simple key/value pair lookup table with range lookup support. diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index f98a2ec9..0932efb1 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -86,17 +86,15 @@ if (YOTTA_CFG_MICROBIT_CONFIGFILE) endif () if(CMAKE_COMPILER_IS_GNUCC) - file(REMOVE "asm/CortexContextSwitch.s") - configure_file("asm/CortexContextSwitch.s.gcc" "asm/CortexContextSwitch.s" COPYONLY) + set(YOTTA_AUTO_MICROBIT-DAL_S_FILES + "asm/TOOLCHAIN_GCC_ARM/CortexContextSwitch.s" + ) else() - file(REMOVE "asm/CortexContextSwitch.s") - configure_file("asm/CortexContextSwitch.s.armcc" "asm/CortexContextSwitch.s" COPYONLY) + set(YOTTA_AUTO_MICROBIT-DAL_S_FILES + "asm/TOOLCHAIN_ARM_STD/CortexContextSwitch.S" + ) endif() -set(YOTTA_AUTO_MICROBIT-DAL_S_FILES - "asm/CortexContextSwitch.s" -) - add_library(microbit-dal ${YOTTA_AUTO_MICROBIT-DAL_CPP_FILES} ${YOTTA_AUTO_MICROBIT-DAL_S_FILES} diff --git a/source/asm/CortexContextSwitch.s.armcc b/source/asm/TOOLCHAIN_ARM_STD/CortexContextSwitch.S similarity index 100% rename from source/asm/CortexContextSwitch.s.armcc rename to source/asm/TOOLCHAIN_ARM_STD/CortexContextSwitch.S diff --git a/source/asm/CortexContextSwitch.s.gcc b/source/asm/TOOLCHAIN_GCC_ARM/CortexContextSwitch.s similarity index 100% rename from source/asm/CortexContextSwitch.s.gcc rename to source/asm/TOOLCHAIN_GCC_ARM/CortexContextSwitch.s diff --git a/source/core/MicroBitHeapAllocator.cpp b/source/core/MicroBitHeapAllocator.cpp index c42b3daa..0fd0c6c1 100644 --- a/source/core/MicroBitHeapAllocator.cpp +++ b/source/core/MicroBitHeapAllocator.cpp @@ -59,7 +59,13 @@ DEALINGS IN THE SOFTWARE. // A list of all active heap regions, and their dimensions in memory. HeapDefinition heap[MICROBIT_MAXIMUM_HEAPS] = { }; uint8_t heap_count = 0; -extern "C" int __end__; +#if defined __CC_ARM || defined __ARMCC_VERSION +#define HEAP_START Image$$RW_IRAM1$$ZI$$Limit +#else +#define HEAP_START __end__ +#endif + +extern "C" int HEAP_START; #if CONFIG_ENABLED(MICROBIT_DBG) && CONFIG_ENABLED(MICROBIT_HEAP_DBG) // Diplays a usage summary about a given heap... @@ -271,7 +277,7 @@ void *microbit_malloc(size_t size, HeapDefinition &heap) * * @return A pointer to the allocated memory, or NULL if insufficient memory is available. */ -void *malloc(size_t size) +void *_microbit_malloc(size_t size) { static uint8_t initialised = 0; void *p; @@ -280,7 +286,7 @@ void *malloc(size_t size) { heap_count = 0; - if(microbit_create_heap((uint32_t)(&__end__), (uint32_t)(MICROBIT_HEAP_END)) == MICROBIT_INVALID_PARAMETER) + if(microbit_create_heap((uint32_t)(&HEAP_START), (uint32_t)(MICROBIT_HEAP_END)) == MICROBIT_INVALID_PARAMETER) microbit_panic(MICROBIT_HEAP_ERROR); initialised = 1; @@ -319,7 +325,7 @@ void *malloc(size_t size) * * @param mem The memory area to release. */ -void free(void *mem) +void _microbit_free(void *mem) { uint32_t *memory = (uint32_t *)mem; uint32_t *cb = memory-1; @@ -351,7 +357,7 @@ void free(void *mem) microbit_panic(MICROBIT_HEAP_ERROR); } -void* calloc (size_t num, size_t size) +void* _microbit_calloc (size_t num, size_t size) { void *mem = malloc(num*size); @@ -361,7 +367,7 @@ void* calloc (size_t num, size_t size) return mem; } -void* realloc (void* ptr, size_t size) +void* _microbit_realloc (void* ptr, size_t size) { void *mem = malloc(size); diff --git a/source/drivers/MicroBitCompassCalibrator.cpp b/source/drivers/MicroBitCompassCalibrator.cpp index 09f5f1b5..470c726f 100644 --- a/source/drivers/MicroBitCompassCalibrator.cpp +++ b/source/drivers/MicroBitCompassCalibrator.cpp @@ -226,8 +226,8 @@ CompassCalibration MicroBitCompassCalibrator::spherify(Sample3D centre, Sample3D Sample3D MicroBitCompassCalibrator::approximateCentre(Sample3D *data, int samples) { Sample3D c,t; - Sample3D centre = { 0,0,0 }; - Sample3D best = { 0,0,0 }; + Sample3D centre; + Sample3D best; float score;