[Reading Notes] USOs-II -- Task Management

Source: Internet
Author: User

 

Task Management

Task Creation


You can create a task by passing the task address and other parameters to one of the following two functions: ostaskcreate ()
Or ostaskcreateext ().

Notes


A task can be created before the start of multi-task scheduling or during the execution of other tasks. Before you start multi-task scheduling (that is, calling osstart (), you must create at least one task. Tasks cannot be created by interrupt service programs (ISR.

Determine the task stack size


The stack capacity required by the task is specified by the application. When you specify the stack size, you must consider the nesting of all functions called by your task. The number of local variables allocated by all functions called by the task, and all stack requirements that may interrupt service routine nesting. In addition, your stack must be able to store all CPU registers.

Stack growth direction

The stack is decreased from top to bottom:
OS _stk_growth = 1

Stack increments from bottom to top:
OS _stk_growth = 0

Some members in the task control block:


. Ostcbstkbottom
Is a pointer to the bottom of the task stack. If the stack pointer of the microprocessor is decreasing, that is, the stack memory is allocated from the high address to the low address, the ostcbstkbottom points to the lowest address of the stack space used by the task. Similarly, if the microprocessor stack is incremental from a low address to a high address, ostcbstkbottom points to the highest address of the stack space that can be used by the task. The variable ostcbstkbottom is used for the function ostaskstkchk () to check the usage of the stack space during running. You can use it to determine the stack space required by the task. This function can be implemented only when you allow the ostaskcreateext () function when creating a task. This requires you to set OS _task_create_ext_en to 1 to allow this function.


. Ostcbx,. ostcby,. ostcbbitx and. ostcbbity
It is used to accelerate the process of entering the ready state or waiting for the event to take place (avoid calculating these values during running ). These values are calculated when the task is created or when the task priority is changed. For the algorithm of these values, see program list l3.4.

Program list
L 3.4
Algorithm of several Members in the task control block OS _tcb

Ostcby

= Priority> 3; // Group

Ostcbbity

= Osmaptbl [Priority> 3]; // group mask

Ostcbx

= Priority & 0x07; // bit

Ostcbbitx

= Osmaptbl [Priority & 0x07]; // bit mask

The priority table of a task is represented by a group ID. The higher three bits represent the group, and the lower three bits represent the bits.

 

 

Delete a task: ostaskdel


Make sure that the task you want to delete is not a idle task, because it is not allowed to delete the idle task. You can delete statistic tasks.


Make sure that you are not trying to delete a task in the ISR routine, because this is not allowed.


Ostaskdel () completes the removal task in two steps to reduce the interrupt response time: First, if the task is in the ready table, it will be directly removed [l4.11 (6)]. If the task is in the wait table of the mailbox, message queue, or semaphore, it will be removed from its own table [l4.11 (7)]. Then, ostaskdel () clears the number of clock latencies of the task to ensure that the ISR routine will not make the task ready when you allow the interruption again [l4.11 (8)]. Finally, ostaskdel () marks the. ostcbstat of the task as OS _stat_rdy. Note that ostaskdel () does not attempt to make the task ready, but stops other tasks or ISR routines from re-starting the task (that is, to avoid other tasks or ISR calls to ostaskresume () [l4.11 (9)]). Next, ostaskdel () re-allows the interrupt to reduce the response time of the interrupt [l4.11 (11)]. In this way, ostaskdel () can process the interrupted service. However, because oslocknesting is added to the service, after the ISR is executed, it will return to the interrupted task to continue the task deletion. Now, ostaskdel () can continue to perform the delete task operation. After ostaskdel () is disconnected again, it removes one by locking the nested counter (oslocknesting) to re-Allow task scheduling [l4.11 (13)]. Then, ostaskdel () calls the User-Defined ostaskdelhook () function [l4.11 (14)]. You can delete or release the custom TCB additional data domain here. Then, ostaskdel () reduces the task counter of µcos-ⅱ. Ostaskdel () simply points the OS _tcb pointer to the deleted task to null [l4.11 (15)] to remove OS _tcb from the priority table. Then, ostaskdel () removes the OS _tcb of the deleted task from the OS _tcb bidirectional linked list [l4.11 (16)]. Note: There is no need to check if ptcb-> ostcbnext = 0, because ostaskdel () cannot delete idle tasks, the idle task is at the end of the linked list (ptcb-> ostcbnext = 0 ). Next, OS _tcb returns to the idle OS _tcb table and allows other tasks to be created [l4.11 (17)]. Finally, call the task scheduler to check that when ostaskdel () permits interruption again [l4.11 (11)], whether the interrupt service subroutine has put a higher priority task in the ready state [l4.11 (18)].

 

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.