1 简介
FreeRTOS中的FreeRTOSConfig.h文件使用#define
来定义宏定义实现的。使用时可以直接复制,再根据自己的需要修改。
2”INCLUDE_”开始的宏
使用”INCLUDE_”开始的宏使能或除能FreeRTOS中相应的API函数。
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#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 INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 1``
这些宏定义为1时,才会触发条件编译,从而将你想要使用函数使能。
3”config”开始的宏
使用”config”开始的宏和使用”INCLUDE_”开始的宏一样,都是用来完成FreeRTOS的配置和裁剪的。
如configCPU_CLOCK_HZ
表示,配置CPU频率。
/* Notes: We use 5 task priorities */
#define configCPU_CLOCK_HZ (SYSCLK_FREQ) // really the NVIC clock ...
#define configTICK_RATE_HZ ((portTickType)1000) // 时钟节拍频率1000
#define configMAX_PRIORITIES ((unsigned portBASE_TYPE)5) //可使用的最大优先级
#define configMINIMAL_STACK_SIZE ((unsigned short)512) //空闲任务使用的堆栈大小
#define configTOTAL_HEAP_SIZE ((size_t)(180 * 1024)) //系统所有总的堆大小
#define configMAX_TASK_NAME_LEN (16) //任务名称最大字符串长度
#define configUSE_PREEMPTION 1 //1使用抢占式内核,0使用协程
#define configUSE_TIME_SLICING 1 //1使能时间片调度
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 //1启用特殊方法(硬件前导零指令)选择下一个要运行的任务 0使用软件方法
#define configUSE_TICKLESS_IDLE 0 //1启用tickless低功耗模式
#define configUSE_QUEUE_SETS 0 //1启用队列表集
#define configUSE_IDLE_HOOK 1 //1启用空闲钩子
#define configUSE_TICK_HOOK 0 //使用时间片钩子
#define configUSE_TRACE_FACILITY 0 //1启用可视化跟踪调试
#define configUSE_16_BIT_TICKS 0 //1表示使用16位无符号整形,0表示32位无符号整形
#define configIDLE_SHOULD_YIELD 0 //1空闲任务放弃CPU使用权给其他同优先级的用户任务
#define configUSE_MUTEXES 1 //1使用互斥型号量
#define configUSE_RECURSIVE_MUTEXES 1 //1使用递归互斥量
#define configUSE_COUNTING_SEMAPHORES 0 //1使用计数信号量
#define configUSE_ALTERNATIVE_API 0
#define configCHECK_FOR_STACK_OVERFLOW 2 //大于0启用堆栈检测功能,用户必须自己实现栈溢出钩子函数 值为1或2,因为有两种检测方法
#define configQUEUE_REGISTRY_SIZE 10 //记录队列和信号量的最大数目
#define configUSE_TIMERS 1 //1启用软件定时器
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) //软件定时器最大优先级
#define configTIMER_QUEUE_LENGTH 10 //软件定时器队列长度
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE //软件定时器堆栈大小
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0 //1启用协程
#define configMAX_CO_ROUTINE_PRIORITIES (2) //协程有效优先级
注意:#define configUSE_PREEMPTION 1 //使用抢占式内核,0使用协程
官网保留协程,但是已经不再维护,在工作中我们最常用还是使用抢占式内核,因此该宏设置为1。
工程中搜索#configUSE_TIME_SLICING
会发现在FreeRTOS.h文件中会有这段代码:
#ifndef configUSE_TIME_SLICING
#define configUSE_TIME_SLICING 1
#endif
如果未定义,则定义为1,即默认使用时间片调度。