第 三 章 FreeRTOSConfig.h 配置文件解读

FreeRTOSConfig.h 配置文件作用:对FreeRTOS的功能进行配置和裁剪,以及API函数的使能等。

官网中文说明:https://www.freertos.org/zh-cn-cmn-s/a00110.html

整体的配置项可以分为三类:

  • INCLUDE开头:一般是“INCLUDE_函数名”,函数的使能,1表示可用,0表示禁用
  • config开头:FreeRTOS的一些功能配置,比如基本配置、内存配置、钩子配置、中断配置等。

其他配置:PendSV宏定义、SVC宏定义

/*
 * FreeRTOS V202212.01
 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * https://www.FreeRTOS.org
 * https://github.com/FreeRTOS
 *
 */

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
 /*-----------------------------------------------------------
  * 调度器基础配置
  *----------------------------------------------------------*/
#include "gd32f30x.h"
extern uint32_t SystemCoreClock;



/* 1: 抢占式调度器, 0: 协程式调度器*/
#define configUSE_PREEMPTION		1
/* 1: 使用硬件计算下一个要运行的任务(硬件) 0:使用软件算法计算下一个要运行的任务(通用的方式) - 效率较低  */
#define configUSE_PORT_OPTIMISED_TASK_SELECTION         1

/* 是否使用空闲任务钩子函数(空闲任务循环中执行的用户代码) */
#define configUSE_IDLE_HOOK			0
/* 是否使用滴答定时器钩子函数(每个滴答中断中执行的用户代码) */
#define configUSE_TICK_HOOK			0
/* CPU时钟频率(Hz),直接使用系统时钟变量 */
#define configCPU_CLOCK_HZ			SystemCoreClock

/* 定义SysTick时钟频率,只有当SysTick时钟频率与内核时钟频率不同时才可以定义,单位: Hz, 默认: 不定义 */
//#define configSYSTICK_CLOCK_HZ    (configCPU_CLOCK_HZ / 8)

/* 滴答定时器的中断频率(Hz),决定了系统时钟精度 */
#define configTICK_RATE_HZ			( ( TickType_t ) 1000 )
/*
定义任务优先级的最大值  ARM32的最大优先级为32  0-32 值越大优先级越大
每个可用优先级都会占用 RTOS 内核中的一些 RAM,因此不应将此值设置得高于应用程序 实际需要的数量。
*/
#define configMAX_PRIORITIES		( 6 )

/*
空闲任务的栈空间大小 以字为单位 而不是字节
针对 Cortex-M3/M4 内核(32 位架构) 1 个字 = 32 位 = 4 字节
这里的 128 表示 128 个字(Word),每个字占 4 字节,因此实际栈空间为 512 字节。
设置空闲任务的任务栈的作用?
    处理上下文切换、中断嵌套等内核操作
    若应用中使用 vTaskDelete(),被删除任务的清理工作也在空闲任务中执行
*/
#define configMINIMAL_STACK_SIZE	( ( unsigned short ) 128 )


/* FreeRTOS堆内存大小(17KB),用于动态创建任务、队列等 */
#define configTOTAL_HEAP_SIZE		( ( size_t ) ( 17 * 1024 ) )
/* 定义任务名最大字符数, 默认: 16 */
#define configMAX_TASK_NAME_LEN		( 16 )
/* 是否启用可视化跟踪调试功能 */
#define configUSE_TRACE_FACILITY	0

/* 1:使用16位滴答定时器 0: 使用32位滴答定时器  */
#define configUSE_16_BIT_TICKS		0
/*当宏 configIDLE_SHOULD_YIELD 设置为 1 时,在抢占调度下,同等优先级的任务可抢占 空闲任务,并延用空闲任务剩余的时间片。 */
#define configIDLE_SHOULD_YIELD		1

/*
1: 使能任务间直接的消息传递,包括信号量、事件标志组和消息邮箱  默认: 0
 当开启任务通 知功能后,每个任务将多占用 8 字节的内存空间。
*/
#define configUSE_TASK_NOTIFICATIONS                    0
 /* 1: 使能互斥信号量, 默认: 0 */
#define configUSE_MUTEXES                               0
/* 1: 使能递归互斥信号量, 默认: 0 */
#define configUSE_RECURSIVE_MUTEXES                     0
/* 1: 使能计数信号量, 默认: 0 */
#define configUSE_COUNTING_SEMAPHORES                   0
/* 1: 使能队列集, 默认: 0 */
#define configUSE_QUEUE_SETS                            1
/* 1: 使能时间片调度, 默认: 1 */
#define configUSE_TIME_SLICING                          1
/* 定义任务堆栈深度的数据类型, 默认: uint16_t */
#define configSTACK_DEPTH_TYPE                          uint16_t
/* 1: 使能软件定时器, 默认: 0 */
#define configUSE_TIMERS                                1
/* 定义软件定时器任务的优先级, 无默认configUSE_TIMERS为1时需定义 */
#define configTIMER_TASK_PRIORITY                       ( configMAX_PRIORITIES - 1 )
/*设置软件定时器命令队列的长度*/
#define configTIMER_QUEUE_LENGTH                            10
/*设置分配给软件定时器服务/守护进程任务的堆栈深度*/
#define configTIMER_TASK_STACK_DEPTH                        configMINIMAL_STACK_SIZE
/*-----------------------------------------------------------
 * API函数包含配置
 * 控制哪些FreeRTOS API函数会被编译进最终代码
 *----------------------------------------------------------*/

#define INCLUDE_vTaskPrioritySet		1  /* 包含vTaskPrioritySet()函数 */
#define INCLUDE_uxTaskPriorityGet		1  /* 包含uxTaskPriorityGet()函数 */
#define INCLUDE_vTaskDelete				1  /* 包含vTaskDelete()函数 */
#define INCLUDE_vTaskCleanUpResources	0  /* 包含vTaskCleanUpResources()函数 */
#define INCLUDE_vTaskSuspend			1  /* 包含vTaskSuspend()函数 */
#define INCLUDE_vTaskDelayUntil			1  /* 包含vTaskDelayUntil()函数 */
#define INCLUDE_vTaskDelay				1  /* 包含vTaskDelay()函数 */

 /*-----------------------------------------------------------
  * 中断优先级配置
  * 注意: Cortex-M3/M4内核使用4位中断优先级,数值越小优先级越高
  *----------------------------------------------------------*/

#ifdef __NVIC_PRIO_BITS
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4
#endif

/* 中断最低优先级 */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY       15   
/* FreeRTOS可管理的最高中断优先级 */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY  5 
//  将中断优先级值转换为NVIC原始值(8位)  计算公式:优先级值 << (8 - 有效位数)
#define configKERNEL_INTERRUPT_PRIORITY         						( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
#define configMAX_SYSCALL_INTERRUPT_PRIORITY      				  ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )


#ifdef SYS_SUPPORT_OS
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
#endif
#endif /* FREERTOS_CONFIG_H */

#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) void vTaskGetRunTimeStats( char *pcWriteBuffer ) { TaskStatus_t *pxTaskStatusArray; volatile UBaseType_t uxArraySize, x; uint32_t ulTotalTime, ulStatsAsPercentage; #if( configUSE_TRACE_FACILITY != 1 ) { #error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats(). } #endif /* * PLEASE NOTE: * * This function is provided for convenience only, and is used by many * of the demo applications. Do not consider it to be part of the * scheduler. * * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part * of the uxTaskGetSystemState() output into a human readable table that * displays the amount of time each task has spent in the Running state * in both absolute and percentage terms. * * vTaskGetRunTimeStats() has a dependency on the sprintf() C library * function that might bloat the code size, use a lot of stack, and * provide different results on different platforms. An alternative, * tiny, third party, and limited functionality implementation of * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in * a file called printf-stdarg.c (note printf-stdarg.c does not provide * a full snprintf() implementation!). * * It is recommended that production systems call uxTaskGetSystemState() * directly to get access to raw stats data, rather than indirectly * through a call to vTaskGetRunTimeStats(). */ /* Make sure the write buffer does not contain a string. */ *pcWriteBuffer = 0x00; /* Take a snapshot of the number of tasks in case it changes while this function is executing. */ uxArraySize = uxCurrentNumberOfTasks; /* Allocate an array index for each task. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION is set to 0 then pvPortMalloc() will equate to NULL. */ pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) ); if( pxTaskStatusArray != NULL ) { /* Generate the (binary) data. */ uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime ); /* For percentage calculations. */ ulTotalTime /= 100UL; /* Avoid divide by zero errors. */ if( ulTotalTime > 0 ) { /* Create a human readable table from the binary data. */ for( x = 0; x < uxArraySize; x++ ) { /* What percentage of the total run time has the task used? This will always be rounded down to the nearest integer. ulTotalRunTimeDiv100 has already been divided by 100. */ ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime; /* Write the task name to the string, padding with spaces so it can be printed in tabular form more easily. */ pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName ); if( ulStatsAsPercentage > 0UL ) { #ifdef portLU_PRINTF_SPECIFIER_REQUIRED { sprintf( pcWriteBuffer, "\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage ); } #else { /* sizeof( int ) == sizeof( long ) so a smaller printf() library can be used. */ sprintf( pcWriteBuffer, "\t%u\t\t%u%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage ); } #endif } else { /* If the percentage is zero here then the task has consumed less than 1% of the total run time. */ #ifdef portLU_PRINTF_SPECIFIER_REQUIRED { sprintf( pcWriteBuffer, "\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].ulRunTimeCounter ); } #else { /* sizeof( int ) == sizeof( long ) so a smaller printf() library can be used. */ sprintf( pcWriteBuffer, "\t%u\t\t<1%%\r\n", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter ); } #endif } pcWriteBuffer += strlen( pcWriteBuffer ); } } else { mtCOVERAGE_TEST_MARKER(); } /* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION is 0 then vPortFree() will be #defined to nothing. */ vPortFree( pxTaskStatusArray ); } else { mtCOVERAGE_TEST_MARKER(); } } 解释一下
06-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值