The system configuration file of FreeRTOS is , in which FreeRTOS can be cropped and configured.
1. Documents
FreeRTOS configuration is basically implemented by using statements like "#define" to define macro definitions. In the official FreeRTOS demo, each project has a file. We can refer to this file when using it, and even copy and paste it directly.
2. INCLUDE_ Starting macro
The macros starting with "INCLUDE_" are used to indicate that the corresponding API functions in FreeRTOS are enabled or disabled. The purpose is to configure optional API functions in FreeRTOS. For example, when the macro INCLUDE_vTaskPrioritySet is set to 0, it means that the function vTaskPrioritySet() cannot be used, and when it is set to 1, it means that the function vTaskPrioritySet() can be used. This function is actually conditional compilation. The advantage of conditional compilation is that it saves space and does not need to be compiled without the need for functions. In this way, the ROM and RAM size occupied by the system can be reduced according to actual needs, and the system consumption can be adjusted according to the MCU you use to reduce costs.
The start of macro
The macros starting with "config" are the same as those starting with "INCLUDE_", and are used to complete the configuration and cropping of FreeRTOS.
If you want to fully understand the macro definition in a file, you must have a certain understanding of the FreeRTOS code, so I will not list the macro definitions one by one here, just attach the files I have used and commented.
#ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H //Call different files for different compilers// Make sure that stdint is only used by the compiler and not by the assembler#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include <> extern uint32_t SystemCoreClock; #endif /***********************************************************************************************************************/ /* FreeRTOS basic configuration configuration options */ /**********************************************************************************************************************/ //#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1 //Use non-systick interrupts as the scheduling clock#define configUSE_PREEMPTION 1 // Set 1: RTOS uses preemptive scheduler; Set 0: RTOS uses collaborative scheduler (time slice)/* Note: * In terms of multi-task management mechanism, the operating system can be divided into preemptive and collaborative. * Preemptive: Obtain the CPU usage rights based on the priority of the task. * Collaborative: After the task actively releases the CPU, switch to the next task. */ #define configUSE_TIME_SLICING 1 //1: Enable time slice scheduling (it is enabled by default)/* Note: * In order to realize time slice rotation scheduling, the system arranges all ready processes into a queue according to the first-in-first-out principle. The new process is added to the end of the ready queue. * Whenever a process scheduling is executed, the process scheduler always selects the queue header process of the ready queue and lets it run a time slice on the CPU. * When the process uses up the time slice allocated to it, the system's timer issues a clock interrupt, and the scheduler stops the process's running and puts it at the end of the ready queue; * Then, assign the CPU to the queue header process of the ready queue, and also let it run a time slice, repeating over and over again. */ #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 //1: Use a special method to select the next task to be executed (hardware support)/* Note: * Some hardware running FreeRTOS has two ways to choose the next task to be performed: general methods and hardware-specific methods (hereinafter referred to as "special methods"). * General method: * 1.configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 or the hardware does not support this special method. * 2. Can be used for all FreeRTOS-supported hardware * 3. Completely implemented with C, with a slightly lower efficiency than that of special methods. * 4. No mandatory limit on the maximum available priority number * Special method: * 1. The configUSE_PORT_OPTIMISED_TASK_SELECTION must be set to 1. * 2. Assembly instructions that rely on one or more specific architectures (usually similar to calculating leading zeros [CLZ] instructions). * 3. More efficient than general methods * 4. Generally, the maximum number of available priority levels is 32 * Generally, hardware calculation leading zero instructions. If the MCU does not have these hardware instructions, this macro should be set to 0! */ #define configUSE_TICKLESS_IDLE 0 //0: Low power tickless mode is not enabled/* Note: * Set 1: Enable low-power tickless mode; Set 0: Keep the system beat (tick) interrupted and run continuously * * If the low power consumption is turned on, it may cause download problems, because the program is sleeping, the following methods can be solved * Download method: * 1. Connect the development version normally * 2. Press and hold the reset button, click Download and release the reset button instantly * * 1. Connect BOOT 0 to high level (3.3V) through the jumper cap * 2. Power on again and download * * 1. Use FlyMcu to erase the chip and download it * STMISP -> Clear chip (z) */ #define configUSE_QUEUE_SETS 1 //1: Enable queue collection/* Note: * Queue collection: used to "listen" multiple queues and semaphores. * As long as any message comes, the task can be exited from the blocking state. */ #define configCPU_CLOCK_HZ (SystemCoreClock) //CPU frequency/* Note: * Write to the actual CPU core clock frequency, that is, the CPU instruction execution frequency, usually called Fclk * Fclk is the clock signal that supplies the CPU core. The CPU main frequency we call is XX MHz. * refers to this clock signal. Correspondingly, 1/Fclk is the CPU clock cycle; */ #define configTICK_RATE_HZ (( TickType_t )1000) //The clock beat frequency is 1000HZ, and the cycle is 1ms/* Note: * Frequency of beat interruption in RTOS system. * That is, the number of interrupts in one second, each time RTOS is interrupted, task schedule will be performed */ #define configMAX_PRIORITIES (32) //The maximum priority available/* Note: * When setting task priority, the smaller the number, the higher the priority */ #define configMINIMAL_STACK_SIZE ((unsigned short)128) //Stack size used by idle tasks/* Note: * Idle task is a task that the operating system forces the CPU to do in order to prevent the CPU from being idle. * Idle tasks are an indispensable task for FreeRTOS, because the FreeRTOS design requires that at least one task must be in operation. */ #define configMAX_TASK_NAME_LEN (16) //Length of task name string#define configUSE_16_BIT_TICKS 0 //The data type of the system beat counter variable,//1 represents 16-bit unsigned shaping, and 0 represents 32-bit unsigned shaping#define configIDLE_SHOULD_YIELD 1 //1: Idle tasks give up CPU usage rights to other user tasks with the same priority#define configUSE_TASK_NOTIFICATIONS 1 //1: Turn on the task notification function, and turn on by default#define configUSE_MUTEXES 1 //1: Use mutually exclusive semaphores#define configQUEUE_REGISTRY_SIZE 8 //Set the semaphore and message queues that can be registered#define configCHECK_FOR_STACK_OVERFLOW 0 //Not using stack overflow detection function/* Note: * Enable stack overflow detection if it is greater than 0. If this function is used * The user must provide a stack overflow hook function, if used * This value can be 1 or 2, because there are two stack overflow detection methods */ #define configUSE_RECURSIVE_MUTEXES 1 //1: Use recursive mutex semaphores#define configUSE_COUNTING_SEMAPHORES 1 //1: Use count semaphores#define configUSE_APPLICATION_TASK_TAG 0 //No tags to tasks (default not)/***************************************************************** FreeRTOS and memory application related configuration options ********************************************************************* #define configSUPPORT_DYNAMIC_ALLOCATION 1 //Support dynamic memory application#define configTOTAL_HEAP_SIZE ((size_t)(32*1024)) //All total heap sizes of the system/*************************************************************** FreeRTOS configuration options related to hook functions ****************************************************************** #define configUSE_IDLE_HOOK 0 // Set 1: Use the idle hook; Set 0: Ignore the idle hook/* Note: * The idle task hook is a function, which is implemented by the user. * FreeRTOS specifies the name and parameters of the function: void vApplicationIdleHook(void), * This function will be called in every idle task cycle * For RTOS tasks that have been deleted, idle tasks can free up the stack memory allocated to them. * Therefore, it is necessary to ensure that idle tasks can be executed by the CPU * It is very common to use the idle hook function to set the CPU into power saving mode * Cannot call API functions that cause idle tasks to block */ #define configUSE_TICK_HOOK 0 // Set 1: Use the time slice hook; Set 0: ignore the time slice hook/* Note: * The time slice hook is a function, which is implemented by the user. * FreeRTOS specifies the name and parameters of the function: void vApplicationTickHook(void) * Time slice interrupts can be called periodically * Functions must be very short and cannot use a large amount of stacks. * API functions ending with "FromISR" or "FROM_ISR" cannot be called */ /*xTaskIncrementTick function is called in the xPortSysTickHandler interrupt function. Therefore, the execution time of the vApplicationTickHook() function must be very short*/ //Use memory application failed hook function#define configUSE_MALLOC_FAILED_HOOK 0 //No memory application failed hook function/******************************************************************** FreeRTOS configuration options related to runtime and task status collection ************************************************************************ #define configGENERATE_RUN_TIME_STATS 0 //Not enabled runtime statistics function (used for general debugging)#define configUSE_TRACE_FACILITY 1 //Enable visual tracking debugging#define configUSE_STATS_FORMATTING_FUNCTIONS 1 /* When the following three functions are 1 at the same time as the macro configUSE_TRACE_FACILITY, the following three functions will be compiled. * prvWriteNameToBuffer() * vTaskList(), * vTaskGetRunTimeStats() */ /******************************************************************** FreeRTOS coroutine-related configuration options ************************************************************************ #define configUSE_CO_ROUTINES 0 //1: Enable coroutines, files must be added after enabling coroutines#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) //Number of effective priority for coroutines/*********************************************************************** FreeRTOS configuration options related to software timer ************************************************************************ #define configUSE_TIMERS 1 //1: Enable the software timer#define configTIMER_TASK_PRIORITY ( 2 ) //Set software timer priority#define configTIMER_QUEUE_LENGTH 10 //Software timer queue length#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE*2) //Software timer task stack size/************************************************************ FreeRTOS optional function configuration options ****************************************************************** #define INCLUDE_xTaskGetSchedulerState 1 #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_eTaskGetState 1 #define INCLUDE_xTimerPendFunctionCall 1 #define INCLUDE_uxTaskGetStackHighWaterMark 1 #define INCLUDE_xTaskGetHandle 1 /****************************************************************** FreeRTOS configuration options related to interrupts ********************************************************************* #ifdef __NVIC_PRIO_BITS #define configPRIO_BITS __NVIC_PRIO_BITS #else #define configPRIO_BITS 4 #endif //STM32 is a 4-bit interrupt priority control, so here is 4 (different MCUs are different)#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15 //Interrupt minimum priority//All 4-bit priority groups are given to the main priority, so there are 16-bit priority configurations in total: 0-15--The lowest priority is 15// Different MCUs are different#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) /* 240 */ //Set the kernel interrupt priority. This macro is used to set the interrupt priority of PendSV and tick timer.//The reason for the left shift of four bits here is: STM32 uses the high four bits starting from MSB as the priority configuration//In fact, this macro definition can be simplified to: #define configKERNEL_INTERRUPT_PRIORITY 0xF0#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 //Set the maximum priority that the system can manage//This is the threshold priority mentioned by the BASEPRI register, which I set to 5 here.//That is, the priority level higher than 5 (priority level less than 5) is not managed by FreeRTOS!//This is for people to see, the following macro is for the system to see#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) //The reason why four bits need to be shifted left here: Same as above//Interrupts below this priority can safely call FreeRTOS's API functions, and interrupts above this priority cannot be prohibited.//The interrupt service function cannot call FreeRTOS's API functions!//That is: #define configMAX_SYSCALL_INTERRUPT_PRIORITY 0x50/* * The result of the above configuration is: * Interrupts with priority 0-4 will not be prohibited by FreeRTOS, and will not be delayed by executing the FreeRTOS kernel. Interrupts cannot be called. * Interrupts with priority 5-15 can be disabled by FreeRTOS, FreeRTOS API functions ending with FromISR can be called, and they can interrupt nesting * So: interrupts without using any FreeRTOS API can use all interrupt priority and they can interrupt nesting * Those tasks that require strict real-time performance can use 0-4 priority, such as barrier detection in quadcopters */ /**************************************************************** FreeRTOS configuration options related to interrupt service functions ********************************************************************* #define xPortPendSVHandler PendSV_Handler #define vPortSVCHandler SVC_Handler //#define xPortSysTickHandler SysTickHandler implements it in the function itself#endif /* FREERTOS_CONFIG_H */
The above is the detailed content of the FreeRTOS operating system configuration example analysis. For more information about FreeRTOS operating system configuration, please follow my other related articles!