"The FreeRTOS kernel is highly customizable and can be customized using the configuration file freertosconfig. H. Each FreeRTOS application must contain this header file. Users can tailor and customize the FreeRTOS kernel according to the actual application. This configuration file is for the user program, not the kernel, so the configuration file is generally placed in the application directory, not in the RTOS kernel source directory. In the downloaded FreeRTOS package, each demo routine has a freertosconfig. H file. Some routines have older profiles and may not contain all valid options. If an option is not specified in the configuration file, the RTOS kernel uses the default value. A typical freertosconfig. H configuration file is defined as follows, and each parameter in it will be described later.
#ifndef FREERTOS_ CONFIG_ H
#define FREERTOS_ CONFIG_ H
/*Here is a good place to include header files that are required across
yourapplication. */
#include “something.h”
#define configUSE_ PREEMPTION 1
#define configUSE_ PORT_ OPTIMISED_ TASK_ SELECTION 0
#define configUSE_ TICKLESS_ IDLE 0
#define configCPU_ CLOCK_ HZ 60000000
#define configTICK_ RATE_ HZ 250
#define configMAX_ PRIORITIES 5
#define configMINIMAL_ STACK_ SIZE 128
#define configTOTAL_ HEAP_ SIZE 10240
#define configMAX_ TASK_ NAME_ LEN 16
#define configUSE_ 16_ BIT_ TICKS 0
#define configIDLE_ SHOULD_ YIELD 1
#define configUSE_ TASK_ NOTIFICATIONS 1
#define configUSE_ MUTEXES 0
#define configUSE_ RECURSIVE_ MUTEXES 0
#define configUSE_ COUNTING_ SEMAPHORES 0
#define configUSE_ ALTERNATIVE_ API 0/* Deprecated! */
#define configQUEUE_ REGISTRY_ SIZE 10
#define configUSE_ QUEUE_ SETS 0
#define configUSE_ TIME_ SLICING 0
#define configUSE_ NEWLIB_ REENTRANT 0
#define configENABLE_ BACKWARD_ COMPATIBILITY 0
#define configNUM_ THREAD_ LOCAL_ STORAGE_ POINTERS 5
/*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
/*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 1
#define configTIMER_ TASK_ PRIORITY 3
#define configTIMER_ QUEUE_ LENGTH 10
#define configTIMER_ TASK_ STACK_ DEPTH configMINIMAL_ STACK_ SIZE
/*Interrupt nesting behaviour configuration. */
#define configKERNEL_ INTERRUPT_ PRIORITY [dependent of processor]
#define configMAX_ SYSCALL_ INTERRUPT_ PRIORITY [dependent on processor and application]
#define configMAX_ API_ CALL_ INTERRUPT_ PRIORITY [dependent on processor and application]
/*Define to trap errors during development. */
#define configASSERT( ( x ) ) if( ( x ) == 0) vAssertCalled( __ FILE__, __ LINE__ )
/*FreeRTOS MPU specific definitions. */
#define configINCLUDE_ APPLICATION_ DEFINED_ PRIVILEGED_ FUNCTIONS 0
/*Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_ vTaskPrioritySet 1
#define INCLUDE_ uxTaskPriorityGet 1
#define INCLUDE_ vTaskDelete 1
#define INCLUDE_ vTaskSuspend 1
#define INCLUDE_ xResumeFromISR 1
#define INCLUDE_ vTaskDelayUntil 1
#define INCLUDE_ vTaskDelay 1
#define INCLUDE_ xTaskGetSchedulerState 1
#define INCLUDE_ xTaskGetCurrentTaskHandle 1
#define INCLUDE_ uxTaskGetStackHighWaterMark 0
#define INCLUDE_ xTaskGetIdleTaskHandle 0
#define INCLUDE_ xTimerGetTimerDaemonTaskHandle 0
#define INCLUDE_ pcTaskGetTaskName 0
#define INCLUDE_ eTaskGetState 0
#define INCLUDE_ xEventGroupSetBitFromISR 1
#define INCLUDE_ xTimerPendFunctionCall 0
/* Aheader file that defines trace macro can be included here. */
#end if/* FREERTOS_ CONFIG_ H*/
1.configUSE_ PREEMPTION
When it is 1, RTOS uses preemptive scheduler, and when it is 0, RTOS uses cooperative scheduler (time slice).
Note: in terms of multi task management mechanism, the operating system can be divided into preemptive and cooperative. Cooperative operating system is a task that actively releases the CPU and switches to the next task. The timing of task switching depends entirely on the running task.
2.configUSE_ PORT_ OPTIMISED_ TASK_ SELECTION
Some hardware running FreeRTOS has two methods to select the next task to perform: general method and hardware specific method (hereinafter referred to as "special method").
General method:
configUSE_ PORT_ OPTIMISED_ TASK_ Selection is set to 0 or the hardware does not support this special method.
Can be used on all FreeRTOS supported hardware.
It is completely implemented in C, and the efficiency is slightly lower than that of the special method.
It is not mandatory to limit the maximum number of available priorities
Special methods:
Not all hardware supports.
Configure must be_ PORT_ OPTIMISED_ TASK_ Selection is set to 1.
Assembly instructions that depend on one or more specific architectures (generally similar to calculating leading zeros [CLZ] instructions).
More efficient than general methods.
Generally, the maximum number of available priorities is forced to be 32.
3.configUSE_ TICKLESS_ IDLE
Set configure_ TICKLESS_ Idle is 1 to enable low-power tickless mode, and 0 to keep the system tick interrupt running all the time.
Usually, FreeRTOS calls back the idle task hook function (which needs to be implemented by the designer), and sets the microprocessor to enter the low-power mode in the idle task hook function to save power. Because the system needs to respond to the system beat interrupt event, using this method will exit periodically and enter the low-power state again. If the system beat interrupt frequency is too fast, most of the power and CPU time will be consumed in entering and exiting the low-power state.
The tickless idle mode of FreeRTOS stops periodic system beat interrupts during idle cycles. Stopping the periodic system beat interrupt can make the microcontroller in low power consumption mode for a long time. The transplantation layer needs to configure an external wake-up interrupt to wake up the microcontroller from the low-power mode when the wake-up event comes. After the microcontroller wakes up, it will re enable the system beat interrupt. Since the system beat counter stops after the microcontroller enters low power consumption, but we need to know how many system beat interrupt cycles can be converted into this period of time, there needs to be an external clock source that is not affected by low power consumption, that is, when the microprocessor is in low power consumption mode, it is also timing, In this way, when restarting the system beat interrupt, an adjustment value can be calculated according to the external timer and written into the RTOS system beat counter variable.
4.configUSE_ IDLE_ HOOK
Set to 1 to use free hooks (idle hook is similar to callback function), and 0 to ignore free hooks.
After the RTOS scheduler starts working, in order to ensure that at least one task is running, idle tasks are automatically created and occupy the lowest priority (priority 0). For RTOS tasks that have been deleted, idle tasks can free the stack memory allocated to them. Therefore, in the application, it should be noted that when using vtask delete() function, it is necessary to ensure that idle tasks get a certain processor time. In addition, idle tasks have no other special functions, so they can arbitrarily deprive the processor time of idle tasks.
Applications may also share the same priority as idle tasks.
Idle task hook is a function implemented by the user. RTOS specifies the name and parameters of the function. This function will be called in each idle task cycle.
To create a free hook:
1. Set configure in the freertosconfig. H file_ IDLE_ Hook is 1;
2. Define a function. The function name and parameters are as follows:
void vApplicationIdleHook(void );
This hook function cannot call API functions that will cause idle task blocking (e.g. vtask delay(), queue with blocking time and semaphore function). It is allowed to use coroutines inside the hook function.
It is common to use the idle hook function to set the CPU to enter the power saving mode
Our other product: