mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
增加PIKA_WEAK宏用于适应不同编译链;增加pika_free/malloc/printf
This commit is contained in:
parent
c2cc4349de
commit
a53e916506
@ -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;
|
||||
}
|
||||
|
@ -10,6 +10,16 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user