In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the kernel control of the FreeRTOS real-time operating system". In the daily operation, I believe that many people have doubts about the kernel control of the FreeRTOS real-time operating system. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the kernel control of the FreeRTOS real-time operating system?" Next, please follow the editor to study!
Preface
Some functions of kernel control need to be provided by the porting layer. In order to facilitate migration, these API functions are implemented with macros, such as context switching, entering and exiting critical areas, disabling and enabling shielding interrupts. The kernel control function also includes starting and stopping the scheduler, suspending and resuming the scheduler, and adjusting the system beat function for low power mode.
1. Force context switch macros
TaskYIELD: the macro used to force context switching. The equivalent version in the interrupt service program is portYIELD_FROM_ISR, which is also a macro, and its implementation depends on the migration layer.
The actual code for context switching is provided by the migration layer. For Cortex-M3 hardware, this macro causes PendSV interrupts.
two。 Enter the critical zone macro
TaskENTER_CRITICAL: the macro used to enter the critical section. Context switching does not occur in the critical area.
The actual code to enter the critical area is provided by the migration layer. For Cortex-M3 hardware, all RTOS masking interrupts are disabled first, which can be achieved by writing configMAX_SYSCALL_INTERRUPT_PRIORITY to the basepri register. When the basepri register is set to a certain value, all interrupts with priority numbers greater than or equal to this value are disabled, but if set to 0, no interrupts are turned off, and 0 is the default value. Then the nested counter in the critical area is increased by 1.
3. Exit the critical zone macro
TaskEXIT_CRITICAL: the macro used to exit the critical section.
The actual code for exiting the critical section is provided by the porting layer. For Cortex-M3 hardware, the critical area nested counter is subtracted by 1. If the critical section counter is zero, all RTOS shielded interrupts are enabled, which can be achieved by writing 0 to the basepri register.
4. Disable masked interrupt macros
TaskDISABLE_INTERRUPTS: disable all RTOS masking interrupts. When the macro taskENTER _ CRITICAL is called to enter the critical section, the macro is also indirectly called to prohibit all RTOS masking interrupts.
5. Enable masking interrupt macros
TaskENABLE_INTERRUPTS: enables all RTOS to mask interrupts. When the macro taskEXIT _ CRITICAL is called to exit the critical section, the macro is also called indirectly to enable all RTOS shielded interrupts.
6. Startup Scheduler 6.1 function description
Void vTaskStartScheduler (void)
Start the RTOS scheduler, after which the RTOS kernel controls which task is executed and when.
When vTaskStartScheduler () is called, the idle task is created automatically. If configUSE_TIMERS is set to 1, the timer background task will also be created.
If vTaskStartScheduler () executes successfully, the function does not return until a task calls vTaskEndScheduler (). If the idle task cannot be created because of insufficient RAM, the function may also fail and return to the call immediately.
7. Stop Scheduler 7.1 function description
Void vTaskEndScheduler (void)
Used only in x86 hardware architecture.
Stop the RTOS kernel system beat clock. All created tasks are automatically deleted and multitasking is stopped.
8. Suspend Scheduler 8.1 function description
Void vTaskSuspendAll (void)
Suspend the scheduler, but do not prohibit interrupts. When the scheduler hangs, no context switch occurs. After the scheduler hangs, the executing task continues to execute, and the kernel is no longer scheduled (meaning that the current task will not be switched out) until the task calls the xTaskResumeAll () function.
API functions that can cause context switching (such as vTaskDelayUntil (), xQueueSend (), and so on) should never be used during a kernel scheduler hang.
9. Restore the pending scheduler 9.1 function description
BaseType_t xTaskResumeAll (void)
Restores the real-time kernel scheduler that was suspended by calling the vTaskSuspendAll () function. XTaskResumeAll () restores only the scheduler, not those tasks that are suspended by the vTaskSuspend () function.
9.2 return value
Returning pdTRUE indicates that the recovery scheduler caused a context switch, otherwise, pdFALSE is returned.
9.3 usage examples voidvTask1 (void * pvParameters) {for ( ) {/ * the task code is written here * / / *. * / / * sometimes, a task wants to run continuously for a long time, but the method of taskENTER_CRITICAL () / taskEXIT_CRITICAL () cannot be used at this time, which will shield the interrupt and cause interrupt loss, including the system beat clock. You can use vTaskSuspendAll () to stop RTOS kernel scheduling: * / xTaskSuspendAll (); / * put the execution code here. In this way, it can be executed continuously for a long time without entering the critical area. In the meantime, the interrupt will still be responded to, and the RTOS kernel system beat clock will continue to operate * /. * / * the operation ends and the RTOS kernel is restarted. We want to force a context switch, but if a context switch has already been performed when the scheduler is restored, there is no point in performing it again, so a judgment will be made. * / if (! xTaskResumeAll ()) {taskYIELD ();} 10. Function description of adjusting system beat 10.1
Void vTaskStepTick (TickType_txTicksToJump)
If RTOS enables the tickless idle function, whenever only idle tasks are executed, the system beat clock interrupt will stop and the microcontroller will enter low power mode. When the microcontroller exits the low power consumption, the system beat counter must be adjusted to make up for the time of low power consumption.
If the macro portSUPPRESS _ TICKS_AND_SLEEP () entity is defined in the FreeRTOS migration file, the function vTaskStepTick is used to adjust the system beat counter inside the macro subpress _ TICKS_AND_SLEEP () entity. The function vTaskStepTick is a global function, so you can also override it in the macro portSUPPRESS _ TICKS_AND_SLEEP () entity.
In the file FreeRTOSConfig.h, the macro configUSE _ TICKLESS_IDLE must be set to 1 for this function to be valid.
10.2 Parameter description
XTickToJump: the time value, in units of the system beat cycle, indicates the time when the microprocessor enters low power consumption. The function adjusts the value of the system beat counter according to this value.
10.3 usage example / * first define the macro portSUPPRESS _ TICKS_AND_SLEEP (). The macro parameter specifies the time to enter low power consumption (sleep), in units of the system beat cycle. * / # defineportSUPPRESS_TICKS_AND_SLEEP (xIdleTime) vApplicationSleep (xIdleTime) / * defines the function * / void vApplicationSleep (TickType_t xExpectedIdleTime) {unsigned long ulLowPowerTimeBeforeSleep,ulLowPowerTimeAfterSleep; / * that is called by the macroportSUPPRESS _ TICKS_AND_SLEEP () to get the current time from the clock source, which must be running * / ulLowPowerTimeBeforeSleep = ulGetExternalTime () when the microcontroller enters low power consumption; / * stop the system beat clock interrupt. * / prvStopTickInterruptTimer (); / * configure an interrupt to wake the processor from low power consumption when the specified sleep time is reached. This interrupt source must also work when the microcontroller enters low power consumption. * / vSetWakeTimeInterrupt (xExpectedIdleTime); / * enter the low power consumption * / prvSleep (); / * determine the true duration of the microcontroller entering the low power mode. Because other interrupts may also cause the microprocessor to exit low-power mode. Note: the scheduler should be suspended before calling the macro subpress _ TICKS_AND_SLEEP (), and the scheduler should be restored after portSUPPRESS_TICKS_AND_SLEEP () returns. Therefore, no other tasks are performed until this function is completed. * / ulLowPowerTimeAfterSleep = ulGetExternalTime (); / * adjust the kernel system beat counter. * / vTaskStepTick (ulLowPowerTimeAfterSleep-ulLowPowerTimeBeforeSleep); / * restart the system beat clock interrupt. * / prvStartTickInterruptTimer ();} / * first define the macro TICKS_AND_SLEEP _ TICKS_AND_SLEEP (). The macro parameter specifies the time to enter low power consumption (sleep), in units of the system beat cycle. * / # defineportSUPPRESS_TICKS_AND_SLEEP (xIdleTime) vApplicationSleep (xIdleTime) / * defines the function * / void vApplicationSleep (TickType_t xExpectedIdleTime) {unsigned long ulLowPowerTimeBeforeSleep,ulLowPowerTimeAfterSleep; / * that is called by the macroportSUPPRESS _ TICKS_AND_SLEEP () to get the current time from the clock source, which must be running * / ulLowPowerTimeBeforeSleep = ulGetExternalTime () when the microcontroller enters low power consumption; / * stop the system beat clock interrupt. * / prvStopTickInterruptTimer (); / * configure an interrupt to wake the processor from low power consumption when the specified sleep time is reached. This interrupt source must also work when the microcontroller enters low power consumption. * / vSetWakeTimeInterrupt (xExpectedIdleTime); / * enter the low power consumption * / prvSleep (); / * determine the true duration of the microcontroller entering the low power mode. Because other interrupts may also cause the microprocessor to exit low-power mode. Note: the scheduler should be suspended before calling the macro subpress _ TICKS_AND_SLEEP (), and the scheduler should be restored after portSUPPRESS_TICKS_AND_SLEEP () returns. Therefore, no other tasks are performed until this function is completed. * / ulLowPowerTimeAfterSleep = ulGetExternalTime (); / * adjust the kernel system beat counter. * / vTaskStepTick (ulLowPowerTimeAfterSleep-ulLowPowerTimeBeforeSleep); / * restart the system beat clock interrupt. * / prvStartTickInterruptTimer ();} at this point, the study of "what is the kernel control of the FreeRTOS real-time operating system" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.