In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of what the task of the FreeRTOS real-time operating system is, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on the task of the FreeRTOS real-time operating system. Let's take a look.
1. Tasks and collaborations (Co-routines)
Applications can use tasks or collaborators, or a combination of both, but tasks and collaborators use different API functions, so the same queue or semaphore cannot be used to pass data between tasks and collaborators.
In general, co-programming is only used in microprocessors with very few resources, especially when RAM is very scarce. Currently, the collaborative program is rarely used, so the author of the collaborative program FreeRTOS has neither removed it nor further developed it.
Therefore, this series of articles will not describe the collaborative program too much, including its API function.
1.1 characteristics of the task
In short: real-time applications that use RTOS can be thought of as a collection of independent tasks. Each task runs in its own environment and does not depend on other tasks in the system or the RTOS scheduler. Only one task is run at any one time, and the RTOS scheduler decides which task to run. The scheduler constantly starts and stops each task, making it look as if the entire application is executing. As a task, you do not need to know anything about the activities of the scheduler, and it is the main responsibility of the scheduler to save the context (register values, stack contents) when the task is cut in and out. To achieve this, each task needs its own stack. When a task is cut out, its execution environment is saved in the stack of the task, so that when it is run again, the last running environment can be correctly restored from the stack.
1.2 Task Summary
simple
There are no restrictions on use
Support full preemption
Support priority
Each task has its own stack and consumes a lot of RAM
If preemption is used, the reentrant problem must be carefully considered.
two。 Task status
A task can be one of the following:
Run: if a task is being executed, then the task is running. At this point, it takes up the processor.
Ready: a ready task already has the ability to execute (unlike blocking and suspending), but it hasn't really been executed because a task with the same or higher priority is running.
Blocking: if a task is currently waiting for some timing or external interrupt, we say that the task is in a blocking state. For example, a task that calls vTaskDelay () will block until the delay period expires. Tasks may also block queues or semaphore events. Tasks that enter the blocking state usually have a "timeout" period that unblocks when the event times out.
Pending: a task in a pending state is also not valid for the scheduler. The task enters or exits the pending state only after explicitly calling the vTaskSuspend () and xTaskResume () API functions, respectively. You cannot specify a timeout period event (you cannot exit the pending state by setting a timeout event)
3. Task priority
Each task is assigned a priority, which is defined in FreeRTOSConfig.h from 0 percent configMAXordered PRIORITIES.
If a certain architecture hardware supports CLZ (or similar) instructions (counting the number of leading zeros, Cortex-M3 supports this instruction, but only from ARMv6T2), and you plan to use this feature in the migration layer to optimize the task scheduling mechanism, you need to take some steps: first, set the configUSE_PORT_OPTIMISED_TASK_SELECTION in FreeRTOSConfig.h to 1, and the maximum priority number configMAX_PRIORITIES cannot be greater than 32. In addition, configMAX_PRIORITIES can be set to any value, but considering that the larger the configMAX_PRIORITIES setting, the greater the RAM consumption, which is generally set to meet the minimum value used.
A low priority value represents a low priority. The priority of the idle task (idle task) is 0 (tskIDLE_PRIORITY).
The FreeRTOS scheduler ensures that the ready or running task with the highest priority gets the processor; in other words, only the highest priority task will run for the task that is running.
Any number of tasks can share the same priority. If the macro configUSE _ TIME_SLICING is not defined or if the macro configUSE _ TIME_SLICING is defined as 1, multiple tasks of the same priority in the ready state will share the processor in a time slice switch.
4. Accomplish a task
A task has the following structure:
Void vATaskFunction (void * pvParameters) {for (;;) {/ *-- the application code is placed here. -- * /} / * tasks cannot return or exit from this function. In newer FreeRTOS migration packages, if you try to return from a task, configASSERT () will be called (if defined). If a task does exit the function, the task should call the vTaskDelete (NULL) function to handle some cleanup. * / vTaskDelete (NULL);}
The task function returns void, and the parameter has only one pointer of type void. All task functions should be like this. The void type pointer can pass any type of information to the task.
Task functions should never be returned, so task functions are usually an endless loop.
The task is created by the xTaskCreate () function and deleted by the vTaskDelete () function.
5. Idle tasks and idle task hooks (idle task and Idle Task hook) 5.1 Idle tasks
Idle tasks are tasks that are automatically created by the kernel when you start RTOS Scheduler, which ensures that at least one task is running. Idle tasks have the lowest task priority, so that if other higher priority tasks enter the ready state, you can immediately give up the CPU.
After the task is deleted, the idle task is used to free the memory allocated by RTOS to the deleted task. Therefore, it is important to ensure that idle tasks get processor time after using the vTaskDelete () function in your application. In addition, idle tasks have no other effective functions, so they can be reasonably deprived of processor time, and its priority is the lowest.
It is also possible for application tasks to share idle task priorities (tskIDLE_PRIORITY). For more information on how to configure this situation, please refer to the configIDLE_SHOULE_YIELD configuration parameter class.
5.2 idle task hook
The idle task hook is a function that is called once for each idle task cycle. If you want to run the task program function on an idle priority, you have two options:
Implement this in an idle task hook: because FreeRTOS must have at least one task ready or running, hook functions cannot call API functions (such as vTaskDelay () or queues or semaphores with timeout events) that may cause idle task blocking.
Create a task with idle priority to implement this function: this is a more flexible solution, but will incur more RAM overhead.
The steps to create an idle hook are as follows:
Set configUSE_IDLE_HOOK to 1 in the FreeRTOS configuration. H header file.
Define a function with the name and parameter prototype as follows:
Void vApplicationIdleHook (void)
Typically, you use this idle hook function to set CPU into low-power mode.
This is the end of the article on "what are the tasks of the FreeRTOS real-time operating system?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what is the task of the FreeRTOS real-time operating system". If you want to learn more, you are welcome to follow the industry information channel.
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.