FreeRTOS系统的头函数配置文件(必须)
搞了很久都一直报错,报各种错误,有时候文件不要随便包含,会报改不掉的错,首先注意屏蔽stm32f...it.h文件里的svchandle,systick_handle,pendsv_handle.最后发现是这个头函数配置的不对,在此分享一下,希望对大家有所帮助。
/* FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. All rights reserved 1 tab == 4 spaces! */ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H /** *条件编译: FreeRTOS 中的裁剪和配置就是这种用条件编译的方法来实现的,不止 FreeRTOS 这么干, 很多的协议栈、RTOS 系统和 GUI 库等都是使用条件编译的方法来完成配置和裁剪的。条件编 译的好处就是节省空间,不需要的功能就不用编译,这样就可以根据实际需求来减少系统占用 的 ROM 和 RAM 大小,根据自己所使用的 MCU 来调整系统消耗,降低成本。 * */ #if 0 /*----------------------------------------------------------- * Application specific definitions. * * These definitions should be adjusted for your particular hardware and * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. * * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ ( ( unsigned long ) 72000000 ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMAX_PRIORITIES ( 5 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 64 ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 100* 1024 ) ) #define configMAX_TASK_NAME_LEN ( 16 ) #define configUSE_TRACE_FACILITY 0 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 /* Co-routine definitions. */ #define configUSE_CO_ROUTINES 0 #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* 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 0 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 /* This is the raw value as per the Cortex-M3 NVIC. Values can be 255 (lowest) to 0 (1?) (highest). */ #define configKERNEL_INTERRUPT_PRIORITY 255 /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ #define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xb0, or priority 11. */ /* This is the value being used as per the ST library which permits 16 priority values, 0 to 15. This must correspond to the configKERNEL_INTERRUPT_PRIORITY setting. Here 15 corresponds to the lowest NVIC value of 255. */ #define configLIBRARY_KERNEL_INTERRUPT_PRIORITY 15 #endif #if 1 /* 1 tab == 4 spaces! */ #include "sys.h" //#include "timers.h" //针对不同的编译器调用不同的stdint.h文件 #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include <stdint.h> extern uint32_t SystemCoreClock; #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif //断言 #define vAssertCalled(char,int) printf("Error:%s,%d\r\n",char,int) #define configASSERT(x) if((x)==0) vAssertCalled(__FILE__,__LINE__) // 参数检查 /***************************************************************************************************************/ /* FreeRTOS基础配置配置选项 */ /***************************************************************************************************************/ #define configUSE_PREEMPTION 1 //1使用抢占式内核,0使用协程 #define configUSE_TIME_SLICING 1 //1使能时间片调度(默认式使能的) #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 //1启用特殊方法来选择下一个要运行的任务 //一般是硬件计算前导零指令,如果所使用的 //MCU没有这些硬件指令的话此宏应该设置为0! #define configUSE_TICKLESS_IDLE 1 //1启用低功耗tickless模式 #define configUSE_QUEUE_SETS 1 //为1时启用队列 #define configCPU_CLOCK_HZ (SystemCoreClock) //CPU频率 #define configTICK_RATE_HZ (1000) //时钟节拍频率,这里设置为1000,周期就是1ms #define configMAX_PRIORITIES (32) //可使用的最大优先级 #define configMINIMAL_STACK_SIZE ((unsigned short)130) //空闲任务使用的堆栈大小 #define configMAX_TASK_NAME_LEN (20) //任务名字字符串长度 //设置系统节拍计数器变量数据类型,系统节拍计数器变量类型为 TickType_t #define configUSE_16_BIT_TICKS 0 //系统节拍计数器变量数据类型,为0则为32,否则为16位 //1表示为16位无符号整形,0表示为32位无符号整形 #define configIDLE_SHOULD_YIELD 1 //为1时空闲任务放弃CPU使用权给其他同优先级的用户任务 此宏定义了与空闲任务(idle Task)处于同等优先级的其他用户任务的行为 #define configUSE_TASK_NOTIFICATIONS 1 //为1时开启任务通知功能,默认开启 #define configUSE_MUTEXES 1 //为1时使用互斥信号量 #define configQUEUE_REGISTRY_SIZE 8 //不为0时表示启用队列记录,具体的值是可以 //记录的队列和信号量最大数目。 #define configCHECK_FOR_STACK_OVERFLOW 0 //大于0时启用堆栈溢出检测功能,如果使用此功能 //用户必须提供一个栈溢出钩子函数,如果使用的话 //此值可以为1或者2,因为有两种栈溢出检测方法。 #define configUSE_RECURSIVE_MUTEXES 1 //为1时使用递归互斥信号量 #define configUSE_MALLOC_FAILED_HOOK 0 //1使用内存申请失败钩子函数 #define configUSE_APPLICATION_TASK_TAG 0 //应用标识,设置为 1 的 话 函 数 configUSE_APPLICATION_TASK_TAGF(),xTaskCallApplicationTaskHook()就会被编译 #define configUSE_COUNTING_SEMAPHORES 1 //为1时使用计数信号量 /***************************************************************************************************************/ /* FreeRTOS与内存申请有关配置选项 */ /***************************************************************************************************************/ #define configSUPPORT_DYNAMIC_ALLOCATION 1 //支持动态内存申请 #define configTOTAL_HEAP_SIZE ((size_t)(32*1024)) //系统所有总的堆大小 /***************************************************************************************************************/ /* FreeRTOS与钩子函数有关的配置选项 */ /***************************************************************************************************************/ #define configUSE_IDLE_HOOK 0 //1,使用空闲钩子;0,不使用 #define configUSE_TICK_HOOK 0 //1,使用时间片钩子;0,不使用 /***************************************************************************************************************/ /* FreeRTOS与运行时间和任务状态收集有关的配置选项 */ /***************************************************************************************************************/ #define configGENERATE_RUN_TIME_STATS 0 //为1时启用运行时间统计功能 //#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() ConfigureTimeForRunTimeStats()//定时器3提供时间统计的时基,频率为10K,即周期为100us //#define portGET_RUN_TIME_COUNTER_VALUE() FreeRTOSRunTimeTicks //获取时间统计时间值 #define configUSE_TRACE_FACILITY 1 //为1启用可视化跟踪调试 #define configUSE_STATS_FORMATTING_FUNCTIONS 1 //与宏configUSE_TRACE_FACILITY同时为1时会编译下面3个函数 //prvWriteNameToBuffer(),vTaskList(), //vTaskGetRunTimeStats() /***************************************************************************************************************/ /* FreeRTOS与协程有关的配置选项 */ /***************************************************************************************************************/ #define configUSE_CO_ROUTINES 0 //为1时启用协程,启用协程以后必须添加文件croutine.c #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) //协程的有效优先级数目 /***************************************************************************************************************/ /* FreeRTOS与软件定时器有关的配置选项 */ /***************************************************************************************************************/ #define configUSE_TIMERS 1 //为1时启用软件定时器 #define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES-1) //软件定时器优先级 #define configTIMER_QUEUE_LENGTH 5 //软件定时器队列长度 #define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE*2) //软件定时器任务堆栈大小 /***************************************************************************************************************/ /* FreeRTOS可选函数配置选项 */ /***************************************************************************************************************/ #define INCLUDE_xTaskGetSchedulerState 1 #define INCLUDE_vTaskPrioritySet 1 //条件编译当 设置为 1 的时候 就表 示可以 使用 函数vTaskPrioritySet()。 #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_eTaskGetState 1 #define INCLUDE_xTimerPendFunctionCall 1 /***************************************************************************************************************/ /* FreeRTOS与中断有关的配置选项 */ /***************************************************************************************************************/ #ifdef __NVIC_PRIO_BITS #define configPRIO_BITS __NVIC_PRIO_BITS #else #define configPRIO_BITS 4 #endif #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 //中断最低优先级 #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 //系统可管理的最高中断优先级 #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) /***************************************************************************************************************/ /* FreeRTOS与中断服务函数有关的配置选项 */ /***************************************************************************************************************/ #define xPortPendSVHandler PendSV_Handler #define vPortSVCHandler SVC_Handler extern void PreSleepProcessing(uint32_t xExpectedIdleTime); extern void PostSleepProcessing(uint32_t xExpectedIdleTime); //低功耗Tickless模式 #define configPRE_SLEEP_PROCESSING PreSleepProcessing #define configPOST_SLEEP_PROCESSING PostSleepProcessing #endif #endif /* FREERTOS_CONFIG_H */