/* * @Description: * @Version: * @Author: Arnold * @Date: 2023-10-27 13:48:57 * @LastEditTime: 2024-01-08 23:11:25 */ #ifndef __MM_H__ #define __MM_H__ #include #include #include #include #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 4 * 1024 ) ) #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) #define portBYTE_ALIGNMENT 8 #define portNOP() __asm volatile ( "NOP" ) #define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" ) #define configTICK_RATE_HZ ( 1000 ) #if portBYTE_ALIGNMENT == 32 #define portBYTE_ALIGNMENT_MASK ( 0x001f ) #elif portBYTE_ALIGNMENT == 16 #define portBYTE_ALIGNMENT_MASK ( 0x000f ) #elif portBYTE_ALIGNMENT == 8 #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) #elif portBYTE_ALIGNMENT == 4 #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) #elif portBYTE_ALIGNMENT == 2 #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) #elif portBYTE_ALIGNMENT == 1 #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) #else /* if portBYTE_ALIGNMENT == 32 */ #error "Invalid portBYTE_ALIGNMENT definition" #endif /* if portBYTE_ALIGNMENT == 32 */ #if ( configUSE_16_BIT_TICKS == 1 ) typedef uint16_t TickType_t; #define portMAX_DELAY ( TickType_t ) 0xffff #else typedef uint32_t TickType_t; #define portMAX_DELAY ( TickType_t ) 0xffffffffUL #endif #define portPOINTER_SIZE_TYPE uint64_t /* It is a good idea to define configASSERT() while developing. configASSERT() * uses the same semantics as the standard C assert() macro. */ #define configASSERT( x ) \ do \ { \ if( x ) \ { \ vFakeAssert( true, __FILE__, __LINE__ ); \ } \ else \ { \ vFakeAssert( false, __FILE__, __LINE__ ); \ } \ } while( 0 ) void vFakeAssert( bool x, char * file, int line ); /* Used to pass information about the heap out of vPortGetHeapStats(). */ typedef struct xHeapStats { size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */ size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */ size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */ size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */ size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */ } HeapStats_t; #ifndef traceMALLOC #define traceMALLOC( pvAddress, uiSize ) #endif #ifndef traceFREE #define traceFREE( pvAddress, uiSize ) #endif /* #define vFakeAssert(x, file, line) if (!(x)) { \ LogError("Assertion failed in file %s at line %d", file, line); \ RecordAssertionFailure(); \ } */ #define vFakeAssert(x, file, line) if (!(x)) { } void * pvPortMalloc( size_t xWantedSize );//分配内存 void vPortFree( void * pv );//释放内存 size_t xPortGetFreeHeapSize( void );//获取当前可用堆内存的大小 size_t xPortGetMinimumEverFreeHeapSize( void );//用于获取系统运行的最小空闲大小!!!! void vPortInitialiseBlocks( void );//初始化任务控制块和任务堆栈内存,不需要显式调用 void * pvPortCalloc( size_t xNum, //分配一定数量和大小的内存卡 size_t xSize ); void vPortGetHeapStats( HeapStats_t * pxHeapStats );//统计当前堆的情况 #endif