freertos--Task Management

Source: Internet
Author: User

1. The FreeRTOS task is not allowed to be returned in any way from the implementation function-they must never have a "return" statement, nor can it be executed at the end of the function. If a function is not required, you can delete it, such as using the function vtaskdelete (NULL) in the task to delete the current task.

2. Before starting the Task Scheduler (Oskernelstart () ) , it is best to create only one starting task , after starting the Task Scheduler (Oskernelstart () ), To create additional tasks in the start task, it is recommended that you turn off interrupts. such as taskenter_critical () , ... "Create a task" ... taskexit_critical () .

3. The maximum value of the priority number, which is the value of configmax_priorities in FreeRTOSConfig.h . The FreeRTOS itself does not qualify this maximum, but the larger the value, the greater the memory the kernel spends. It is recommended that you try to set this constant to the minimum acceptable value.

4. The effective range for defining task priorities inFreeRTOS V8.2.1is from 3 to configmax_priorities-3-1 . It is important to note that ① multiple tasks can share one priority , and the smaller the ② priority number, the lower the priority of the task, such as priority number 3, which is the lowest priority. Note that the smaller the priority number of arm, the higher the priority.

5. FreeRTOS When a task is scheduled, if more than one priority and the highest tasks are in the ready state, the scheduler will let these tasks rotate, that is, time slice rotation scheduling.

6. Blocking status : If a task is waiting for an event to occur, the task is said to be in "blocking state (blocked)". A task can enter a blocking state to wait for two different types of events:

1) Timing (time-dependent) time-this type of event can be either a late expiry or an absolute time. For example, a task can enter a blocking state to delay 10ms.

2) Synchronization time--originating from other tasks or interrupt events. For example, a task enters a blocking state to wait for data to arrive in the queue. Synchronization Time covers the event types for all board-level scopes.

7. Pending state : A task in the suspended state is not visible to the scheduler. Of course, most applications do not suspend a task.

1) Suspend task: The only way to do this is to call the vtasksuspend () API function.

2) Restore task: The only way is to call the Vtaskresume () or Vtaskresumefromisr () API function.

8. Complete task state machine as shown.

9. When you start the Task Scheduler, the system automatically creates idle tasks (with the lowest priority) to ensure that at least one task can run at any one time.

10. The hook function of the idle task (or the return function, Hook,or call-back) allows the user to add the relevant functions of the application directly to the hook function of the idle task. The idle task invokes the hook function once every time it is run. If you use the Idle task hook function, the Configuse_idle_hook must be defined as 1 in FreeRTOSConfig.h .

1) The function of the idle task hook function:

A) Perform low-priority, background, or function code that needs to be processed continuously.

b) The processing margin of the test system: The idle task will only run when all other tasks are not running, so it is clear how much richer processing time the system has to measure the processing time occupied by the idle task.

c) Configuring the processor to a low-power mode-provides an automatic power-down method that automatically enters power-saving mode when no application functions are required to be processed.

2) Restrictions on the implementation of the idle task hook function

A) must not be blocked or suspended. Idle tasks are performed only when other tasks are not running (unless there is an app task sharing an idle task priority). Blocking idle tasks in any way can cause no tasks to enter the running state.

b) If the application uses the vtaskdelete () AP function, the hook function for the idle task must be returned as soon as possible because the idle task is responsible for reclaiming the kernel resources after the task is deleted. If the idle task is always in the hook function, it cannot be retracted.

11. When you create a task, you define the priority of the task, and when you start the scheduler, you can use vtaskpriofityset () to change the priority of any task.

12. Tasks can use the vtaskdelete () API to remove themselves or other tasks. When a task is deleted, it is no longer present and does not enter a running state. Once the task is deleted, the idle task frees the memory of the deleted task, so you cannot starve the idle task of its execution time. Note: only the memory space allocated by the kernel for a task is automatically retracted after the task is deleted, and the memory or resource that the task consumes itself needs to be released by the referencing program itself.

The common task scheduling scheme of FreeRTOS is called "Fixed priority preemptive scheduling".

" fixed priority" means that each task is given a priority, which cannot be changed by the kernel itself, but only by the task.

" preemptive " means that when a task enters a ready state or a change in priority, if the priority of the running state is lower, the task will always preempt the currently running task.

FreeRTOS can also employ collaborative scheduling.

With a purely collaborative scheduler, context switches are only possible when a running state task enters a blocking state or a run-state task displays a call to Taskyield () . Tasks are never preempted, and tasks with the same priority do not automatically share processor time. This way of working with collaborative scheduling is relatively simple, but may cause the system to respond quickly enough.

The FreeRTOS can also adopt a hybrid scheduling scheme, which requires context switches to be displayed in the interrupt service routine, allowing synchronous events to produce preemptive behavior, but not time. The result is a preemptive system that has no time-slice mechanism. This is also a common scheduler configuration.

14. How do I set task priorities?

As a general rule, the task of completing hard real-time functions takes precedence over the completion of soft real-time tasks. But other factors, such as execution time and processor utilization, also need to be taken into account to ensure that the application does not exceed the hard-to-reach demand limit.

(Ratemonotonic scheduling,rms): One of the most common priority allocation techniques. It assigns a unique priority based on the rate at which the task is periodically executed. The task with the highest cycle execution frequency is given the highest priority, and the task with the lowest execution frequency is given the lowest priority.

This prioritization is proven to maximize the scalability of the entire application (schedulability), but the running time and not all tasks are cyclical, which complicates the overall calculation of this approach.

freertos--Task Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.