diff --git a/src/dataMemory.c b/src/dataMemory.c index 7b4e6ea9e..771d7deb1 100644 --- a/src/dataMemory.c +++ b/src/dataMemory.c @@ -9,19 +9,29 @@ PikaMemInfo pikaMemInfo = {0}; -__attribute__((weak)) void __pikaDisableIrqHandle(){ +PIKA_WEAK void __pikaDisableIrqHandle(){ /* disable irq to support thread */ } -__attribute__((weak)) void __pikaEnableIrqHandle(){ + +PIKA_WEAK void __pikaEnableIrqHandle(){ /* disable irq to support thread */ } + +PIKA_WEAK void *pika_malloc(size_t size){ + return malloc(size); +} + +PIKA_WEAK void pika_free(void *ptr){ + return free(ptr); +} + void* pikaMalloc(uint32_t size) { pikaMemInfo.heapUsed += size; if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) { pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed; } __pikaDisableIrqHandle(); - void* mem = malloc(size); + void* mem = pika_malloc(size); __pikaEnableIrqHandle(); if (NULL == mem) { printf("[error]: No heap space! Please reset the device.\r\n"); @@ -33,7 +43,7 @@ void* pikaMalloc(uint32_t size) { void pikaFree(void* mem, uint32_t size) { __pikaDisableIrqHandle(); - free(mem); + pika_free(mem); __pikaEnableIrqHandle(); pikaMemInfo.heapUsed -= size; } diff --git a/src/dataMemory.h b/src/dataMemory.h index 16938a727..2515c7d32 100644 --- a/src/dataMemory.h +++ b/src/dataMemory.h @@ -10,6 +10,16 @@ #include #include +#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */ +#define PIKA_WEAK __attribute__((weak)) +#elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */ +#define PIKA_WEAK __weak +#elif defined (__GNUC__) /* GNU GCC Compiler */ +#define PIKA_WEAK __attribute__((weak)) +#endif + +#define pika_printf(...) printf(__VA_ARGS__) + typedef struct { uint32_t heapUsed; uint32_t heapUsedMax;