#ifndef __F_MALLOC_H #define __F_MALLOC_H #ifdef MY_F_MALLOC_GLOBALS #define MY_F_MALLOC_EXT #else #define MY_F_MALLOC_EXT extern #endif /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx.h" #include /*内存分配配置*/ #define EN_SRAM_IN (1) #define EN_SRAM_EX (1) #define EN_SRAM_CCM (1) #ifndef EN_SRAM_IN #define EN_SRAM_IN (1) #endif #ifndef EN_SRAM_EX #define EN_SRAM_EX (1) #endif #ifndef EN_SRAM_CCM #define EN_SRAM_CCM (1) #endif #define COUT_OF_MEM (3) //有多少块内存 //内存种类 typedef enum { SRAM_NONE = (uint8_t)0, #if (EN_SRAM_IN == 1) SRAM_IN, //内部内存池 #endif #if (EN_SRAM_EX == 1) SRAM_EX, //外部内存池 #endif #if (EN_SRAM_CCM == 1) SRAM_CCM, //CCM 内存池(此部分 SRAM 仅仅 CPU 可以访问!!!) #endif }E_MemType; #ifndef configUSE_MALLOC_FAILED_HOOK #define configUSE_MALLOC_FAILED_HOOK 0 //内存分配失败钩子函数 #endif #ifndef configAPPLICATION_ALLOCATED_HEAP #define configAPPLICATION_ALLOCATED_HEAP 0 //内存池在外部文件定义还是在fMalloc.c中定义 #endif #define configTOTAL_HEAP_SIZE1 ( ( size_t ) ( 10 * 1024 ) )//内部内存池大小 #define configTOTAL_HEAP_SIZE2 ( ( size_t ) ( 900 * 1024 ) )//外部内存池大小 #define configTOTAL_HEAP_SIZE3 ( ( size_t ) ( 60 * 1024 ) )//CCM内存池大小 #define portBYTE_ALIGNMENT (8) //字节对齐 /* Allocate the memory for the heap. */ #if( configAPPLICATION_ALLOCATED_HEAP == 1 ) /* The application writer has already defined the array used for the RTOS heap - probably so it can be placed in a special segment or address. */ extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; #endif /* configAPPLICATION_ALLOCATED_HEAP */ #ifndef mtCOVERAGE_TEST_MARKER #define mtCOVERAGE_TEST_MARKER() #endif #define configASSERT( x ) assert_param(x) //断言 /* Define the linked list structure. This is used to link free blocks in order of their memory address. */ typedef struct A_BLOCK_LINK { struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */ size_t xBlockSize; /*<< The size of the free block. */ } BlockLink_t; extern size_t configTOTAL_HEAP_SIZE[]; //E_MemType-1才是数组编号 #define fMalloc(xWantedSize,eMemType) pvPortMalloc(xWantedSize,eMemType-1) #define fFree(pv,eMemType) do{vPortFree(pv,eMemType-1);pv = NULL;}while(0) #define fGetFreeSize(eMemType) xPortGetFreeHeapSize(eMemType-1) void *pvPortMalloc( size_t xWantedSize,uint8_t eMemType ); void vPortFree( void *pv,uint8_t eMemType ); size_t xPortGetFreeHeapSize( uint8_t eMemType ); #endif /* __F_MALLOC_H */