2022-01-24 19:08:33 +08:00
|
|
|
#include "pika_config_gtest.h"
|
2022-01-03 21:12:05 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-11-15 22:52:30 +08:00
|
|
|
#include "dataMemory.h"
|
|
|
|
|
2021-11-26 22:18:01 +08:00
|
|
|
#define use_const_pool 0
|
2022-03-09 13:22:55 +08:00
|
|
|
#define use_dynamic_pool 0
|
2021-11-20 09:56:30 +08:00
|
|
|
|
|
|
|
#define pika_aline 8
|
2021-11-27 19:00:17 +08:00
|
|
|
#define pika_pool_size 0x4000
|
2021-11-16 16:25:22 +08:00
|
|
|
|
2022-01-03 21:12:05 +08:00
|
|
|
char log_buff[LOG_BUFF_MAX][LOG_SIZE] = {0};
|
|
|
|
uint32_t log_index = 0;
|
|
|
|
|
|
|
|
/* save printf content to log_buff */
|
|
|
|
void __platform_printf(char* fmt, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
for (int i = LOG_BUFF_MAX - 2; i >= 0; i--) {
|
|
|
|
memcpy(log_buff[i + 1], log_buff[i], LOG_SIZE);
|
|
|
|
}
|
2022-01-03 21:51:42 +08:00
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(log_buff[0], LOG_SIZE - 1, fmt, args);
|
|
|
|
va_end(args);
|
2022-01-03 21:12:05 +08:00
|
|
|
}
|
|
|
|
|
2021-11-17 22:30:52 +08:00
|
|
|
/* quick_malloc is always open */
|
|
|
|
uint8_t __is_quick_malloc(void) {
|
|
|
|
// return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-11-16 16:25:22 +08:00
|
|
|
#if use_const_pool
|
2021-11-15 22:52:30 +08:00
|
|
|
uint8_t pika_bitmap[pika_pool_size / pika_aline / 8] = {0};
|
|
|
|
uint8_t pika_pool_mem[pika_pool_size] = {0};
|
|
|
|
Pool pikaPool = {.aline = pika_aline,
|
|
|
|
.bitmap = pika_bitmap,
|
|
|
|
.mem = pika_pool_mem,
|
|
|
|
.size = pika_pool_size};
|
|
|
|
void* __impl_pikaMalloc(size_t size) {
|
2021-11-20 10:04:12 +08:00
|
|
|
return pool_malloc(&pikaPool, size);
|
2021-11-15 22:52:30 +08:00
|
|
|
}
|
|
|
|
void __impl_pikaFree(void* ptrm, size_t size) {
|
|
|
|
pool_free(&pikaPool, ptrm, size);
|
2021-11-16 10:39:14 +08:00
|
|
|
}
|
2021-11-20 09:56:30 +08:00
|
|
|
#endif
|
2021-11-16 16:25:22 +08:00
|
|
|
|
2021-11-20 09:56:30 +08:00
|
|
|
#if use_dynamic_pool
|
|
|
|
Pool pikaPool;
|
|
|
|
void* __impl_pikaMalloc(size_t size) {
|
2021-11-20 09:58:10 +08:00
|
|
|
return pool_malloc(&pikaPool, size);
|
2021-11-20 09:56:30 +08:00
|
|
|
}
|
|
|
|
void __impl_pikaFree(void* ptrm, size_t size) {
|
|
|
|
pool_free(&pikaPool, ptrm, size);
|
|
|
|
}
|
2021-12-07 19:17:36 +08:00
|
|
|
void __platform_pool_init(void) {
|
2021-11-20 09:56:30 +08:00
|
|
|
pikaPool = pool_init(pika_pool_size, pika_aline);
|
|
|
|
}
|
|
|
|
#endif
|