本帖最后由 奔波儿熊 于 2019-6-13 14:41 编辑
这一篇主要分析一下FreeRTOSConfig.h中的重要的宏定义, 通常使用这些宏定义来完成FreeRTOS的配置和裁剪.
"INCLUDE_"开头的宏: 表示使能或禁能相应的FreeRTOS API函数, 如果需要使用某API函数则设为1,如果不需要使用某API函数则设为0. 比如#define INCLUDE_vTaskPrioritySet 0 表示不能使用函数vTaskPrioritySet(),该函数也不会被编译; #define INCLUDE_vTaskPrioritySet 1 表示可以使用函数vTaskPrioritySet(),该函数会被编译.
"config"开头的宏, 用处各不相同,下面是FreeRTOSConfig.h的源码, 我会将一些重要的宏加以中文注释来说明其作用.
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*
* #define TCB_t to avoid conflicts between the
* FreeRTOS task control block type (TCB_t) and the
* AVR Timer Counter B type (TCB_t)
*/
#define TCB_t avrTCB_t
#include <avr/io.h>
#undef TCB_t
#define configUSE_PREEMPTION 1<font color="#9acd32">//使用抢占式的任务调度机制</font>
#define configCPU_CLOCK_HZ (20e6 / 2)<font color="#9acd32">//CPU的时钟频率,准确的来说是FreeRTOS使用的硬件Timer的计数时钟频率</font>
#define configTICK_RATE_HZ 1000<font color="#9acd32">//FreeRTOS使用的硬件Timer的中断频率</font>
#define configMAX_PRIORITIES 4<font color="#9acd32">//最大优先级,实际可用的优先级是0~3.理论上最大优先级没有限制,根据实际需要设置</font>
#define configMINIMAL_STACK_SIZE 115<font color="#9acd32">//最小堆栈大小,事实上只有空闲任务使用了这个值作为堆栈大小</font>
#define configMAX_TASK_NAME_LEN 8<font color="#9acd32">//任务名字长度,根据需要设置</font>
#define configUSE_16_BIT_TICKS 1<font color="#9acd32">//1:设置TickType_t为16位;0:设置TickType_t为32位</font>
#define configIDLE_SHOULD_YIELD 1<font color="#9acd32">//1:空闲任务会为处于同等优先级的任务让出CPU 0:空闲任务不会为处于同等优先级的任务让出CPU</font>
#define configUSE_TASK_NOTIFICATIONS 1<font color="#9acd32">//启用任务通知功能</font>
#define configUSE_MUTEXES 1<font color="#9acd32">//启用互斥信号量</font>
#define configUSE_RECURSIVE_MUTEXES 0<font color="#9acd32">//禁用递归互斥信号量</font>
#define configUSE_COUNTING_SEMAPHORES 0<font color="#9acd32">//禁用计数型信号量</font>
#define configQUEUE_REGISTRY_SIZE 0
#define configUSE_QUEUE_SETS 0<font color="#9acd32">//禁用队列集</font>
#define configUSE_TIME_SLICING 1<font color="#9acd32">//使能时间片调度, 同优先级任务基于时间片调度,即使这里不定义为1, FreeRTOS.h中也会将其定义为1</font>
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1<font color="#9acd32">//动态内存分配</font>
#define configTOTAL_HEAP_SIZE 0x800<font color="#9acd32">//设置堆大小</font>
#define configAPPLICATION_ALLOCATED_HEAP 0
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1
/* Software timer related definitions. */
#define configUSE_TIMERS 0
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
/* Define to trap errors during development. */
//#define configASSERT( x ) if( ( x ) == 0 ) { asm volatile ("cli"); while(1){ asm volatile ("BREAK"); } }
/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 0
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 0
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 0
#define INCLUDE_xTaskGetCurrentTaskHandle 0
#define INCLUDE_uxTaskGetStackHighWaterMark 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
#define INCLUDE_eTaskGetState 0
#define INCLUDE_xEventGroupSetBitFromISR 0
#define INCLUDE_xTimerPendFunctionCall 0
#define INCLUDE_xTaskAbortDelay 0
#define INCLUDE_xTaskGetHandle 0
#define INCLUDE_xTaskResumeFromISR 0
#define pdMS_TO_TICKS(xTimeInMs) ((TickType_t)(((uint32_t)(xTimeInMs) * (uint32_t)configTICK_RATE_HZ) / (uint32_t)1000))
#endif /* FREERTOS_CONFIG_H */
|