freeRTOS操作系统机器人实现
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.7 KiB

3 days ago
/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: rd_mempool.h
: 稿
: Radkil
: 2026310
:
: rd_mempool.c
:
1. : 2026310
: Radkil
:
******************************************************************************/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
#ifndef __RD_MEMPOOL_H__
#define __RD_MEMPOOL_H__
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */
/*==============================================*
* include header files *
*----------------------------------------------*/
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "common.h"
/*==============================================*
* constants or macros define *
*----------------------------------------------*/
// 【关键宏】使能此宏将把内存池分配到堆上,否则在全局区(类似栈/静态区)
// #define USE_HEAP_FOR_MEMPOOL
// 1. 内存池总大小
#ifndef MEM_POOL_TOTAL_SIZE
#define MEM_POOL_TOTAL_SIZE (800 * 1024)
#endif
// 2. 最小分配单元 (必须满足对齐要求,通常 8 或 16 字节)
// 包含 Header 的最小尺寸,防止切分出太小的碎片
#define MIN_ALLOC_UNIT 16
#ifdef __RTTHREAD__
#include <rtthread.h>
#define MP_MALLOC rt_malloc
#define MP_CALLOC rt_calloc
#define MP_REALLOC rt_realloc
#define MP_FREE rt_free
#define MP_MEMCPY rt_memcpy
#define MP_MEMSET rt_memset
// ... RT 实现
#else
#include <stdlib.h>
#define MP_MALLOC malloc
#define MP_CALLOC calloc
#define MP_REALLOC realloc
#define MP_FREE free
#include <string.h>
#define MP_MEMCPY memcpy
#define MP_MEMSET memset
// ... Linux 实现
#endif
/*==============================================*
* project-wide global variables *
*----------------------------------------------*/
/*==============================================*
* routines' or functions' implementations *
*----------------------------------------------*/
void Rd_MemDoInit(void);
void Rd_MemDoDeinit(void);
void* Rd_MemPoolMalloc(size_t size);
void Rd_MemPoolFree(void* ptr);
size_t Rd_MemPoolGetFreeCount(void);
void* Rd_MemPoolCalloc(size_t n, size_t size);
void* Rd_MemPoolRealloc(void* ptr, size_t new_size);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* __RD_MEMPOOL_H__ */