背景:
FreeRTOSConfig.h文件是FreeRTOS的關(guān)鍵配置文件,需要搞懂里面參數(shù)的設(shè)置,下面分析各參數(shù)的含義。
內(nèi)容:
宏定義命名的前面小寫config表明該定義是在config文件,名字后面部分均大寫,表明宏定義的含義。
#define configUSE_PREEMPTION 1 //1是使用搶占式內(nèi)核,0是使用協(xié)程式內(nèi)核
#define configUSE_TIME_SLICING1 //1是使能時間片調(diào)度,默認(rèn)使能
#define configSUPPORT_STATIC_ALLOCATION 0 //靜態(tài)內(nèi)存分配申請,0是不支持
#define configSUPPORT_DYNAMIC_ALLOCATION 1//動態(tài)內(nèi)存分配申請,1是支持
#define configUSE_IDLE_HOOK 0//空閑鉤子,0是不使用
#define configUSE_TICK_HOOK 0//時間鉤子,0是不使用
#define configCPU_CLOCK_HZ ( SystemCoreClock )//CPU時鐘頻率
#define configTICK_RATE_HZ ((TickType_t)1000)//時鐘節(jié)拍頻率,設(shè)置1000,周期就是1ms,更高的Tick Rate 會導(dǎo)致任務(wù)的時間片“time
slice”變短
#define configMAX_PRIORITIES ( 7 )//最大優(yōu)先級,用多少設(shè)置為多少,FreeRTOS 會為每個優(yōu)先級建立一個鏈表,因此每多一個優(yōu)先級都會增加些RAM
的開銷。
#define configMINIMAL_STACK_SIZE ((uint16_t)128)//空閑任務(wù)的堆棧大小
#define configTOTAL_HEAP_SIZE ((size_t)30720)//總的堆棧大小30k
#define configMAX_TASK_NAME_LEN ( 16 )//任務(wù)名字的最大長度
#define configUSE_16_BIT_TICKS 0
//將 configUSE_16_BIT_TICKS設(shè)為 1后portTickType將被定義為無符號的16位整形類型,
configUSE_16_BIT_TICKS 設(shè)為0 后portTickType則被定義為無符號的32位整型。
#define configUSE_MUTEXES 1//使用互斥量代碼
#define configQUEUE_REGISTRY_SIZE 8//不為0表示啟用列隊記錄,不用設(shè)為0,節(jié)省RAM空間
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1//1是啟用特殊方法來選擇下一個要運(yùn)行的任務(wù)
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
// 0不啟用協(xié)程代碼
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )//協(xié)程優(yōu)先級數(shù)目
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
//可選函數(shù)配置,用設(shè)為1,不用設(shè)為0
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 //中斷的最低優(yōu)先級
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5//系統(tǒng)可管理的中斷最高優(yōu)先級
另外,補(bǔ)充下portmacro.h文件中的一些宏定義;
/* Type definitions. */
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE uint32_t
#define portBASE_TYPE long
typedef portSTACK_TYPE StackType_t;//uint32_t
typedef long BaseType_t;
typedef unsigned long UBaseType_t;
#if( configUSE_16_BIT_TICKS == 1 ) typedef uint16_t TickType_t; #define portMAX_DELAY ( TickType_t ) 0xffff //16位最大延遲數(shù)
#else typedef uint32_t TickType_t; #define portMAX_DELAY ( TickType_t ) 0xffffffffUL //32 位最大延遲數(shù) /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do not need to be guarded with a critical section. */ #define portTICK_TYPE_IS_ATOMIC 1
#endif
/*-----------------------------------------------------------*/
/* Architecture specifics. */
#define portSTACK_GROWTH ( -1 ) // 堆棧生長方向,-1為向下生長
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
//
portTICK_RATE_MS表示的是Tick 間間隔多少ms,只在應(yīng)用代碼中可能會用到。如使用vTaskDelay延時函數(shù)可實現(xiàn)任務(wù)定時間間隔地執(zhí)行,調(diào)用方法如下:要延時250,調(diào)用 vTaskDelay( 250 /portTICK_RATE_MS );
#define portBYTE_ALIGNMENT 8//這個常量指示字節(jié)對齊數(shù),其默認(rèn)值為8,即默認(rèn)以8個字節(jié)進(jìn)行內(nèi)存對齊
|