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};
|
PikaMemInfo pikaMemInfo = {0};
|
||||||
|
|
||||||
__attribute__((weak)) void __pikaDisableIrqHandle(){
|
PIKA_WEAK void __pikaDisableIrqHandle(){
|
||||||
/* disable irq to support thread */
|
/* disable irq to support thread */
|
||||||
}
|
}
|
||||||
__attribute__((weak)) void __pikaEnableIrqHandle(){
|
|
||||||
|
PIKA_WEAK void __pikaEnableIrqHandle(){
|
||||||
/* disable irq to support thread */
|
/* 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) {
|
void* pikaMalloc(uint32_t size) {
|
||||||
pikaMemInfo.heapUsed += size;
|
pikaMemInfo.heapUsed += size;
|
||||||
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
||||||
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
||||||
}
|
}
|
||||||
__pikaDisableIrqHandle();
|
__pikaDisableIrqHandle();
|
||||||
void* mem = malloc(size);
|
void* mem = pika_malloc(size);
|
||||||
__pikaEnableIrqHandle();
|
__pikaEnableIrqHandle();
|
||||||
if (NULL == mem) {
|
if (NULL == mem) {
|
||||||
printf("[error]: No heap space! Please reset the device.\r\n");
|
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) {
|
void pikaFree(void* mem, uint32_t size) {
|
||||||
__pikaDisableIrqHandle();
|
__pikaDisableIrqHandle();
|
||||||
free(mem);
|
pika_free(mem);
|
||||||
__pikaEnableIrqHandle();
|
__pikaEnableIrqHandle();
|
||||||
pikaMemInfo.heapUsed -= size;
|
pikaMemInfo.heapUsed -= size;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,16 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.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 {
|
typedef struct {
|
||||||
uint32_t heapUsed;
|
uint32_t heapUsed;
|
||||||
uint32_t heapUsedMax;
|
uint32_t heapUsedMax;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user