From a53e9165068e9fe8d0ebfa6e0bc5566a7de32753 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 5 Oct 2021 00:16:11 -0400 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0PIKA=5FWEAK=E5=AE=8F=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E9=80=82=E5=BA=94=E4=B8=8D=E5=90=8C=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=93=BE;=E5=A2=9E=E5=8A=A0pika=5Ffree/malloc/printf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dataMemory.c | 18 ++++++++++++++---- src/dataMemory.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) 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;