Task Management (UC/OS-II)

Source: Internet
Author: User

A task can be an infinite loop, or it can be deleted after a single execution. The return type of a task must be defined as void, except that it never returns. The task must be one of the following two structures:

void Yourtask (void *pdata) {    for  (;;)    {        /* user code */    }} void Yourtask (void *pdata) {    /* user code */    Ostaskdel (os_prio_self);}

I. Establishment of tasks

Ostaskcreate () or Ostaskcreateext () to set up a task. Tasks can be established before the start of a multi-tasking schedule or during the execution of other tasks. You must establish at least one task before you start a multitasking schedule (call Osstart ()). A task cannot be established by an Interrupt service program (ISR).

Attention:

(1) ostaskcreate () or ostaskcreateext () must ensure that the defined priority is not occupied by other tasks. In Uc/os-ii, each task must have a different priority.

(2) if the Ostaskcreate () function is called during the execution of a task (osrunning = = TRUE), the Task Scheduler function is called to determine whether the newly created task has a higher priority than the original task. If the new task has a higher priority, the kernel makes a task transition from the old task to the new task. If the task was established before the start of a multitasking schedule, the Task Scheduler function does not work.

(3) ostaskctr is used to track the number of established tasks.

Second, the task stack

The stack must be declared as a OS_STK type and consists of contiguous memory space. Stack space can be allocated statically (compile-time allocation), or stack space can be allocated dynamically (run-time allocations).

typedef int32u         OS_STK;

Note: in dynamic allocation, always be aware of memory fragmentation issues. In particular, when a task is repeatedly created and deleted, a large amount of memory fragmentation can occur in the memory heap, resulting in not having a large enough contiguous area of memory to be used as a task stack.

When os_stk_growth = = 1 o'clock, the stack is decremented from the top down, and the highest memory address of the stack is passed to the task creation function.

When os_stk_growth = = 0 o'clock, the stack is incremented from bottom to top, and the lowest memory address of the stack is passed to the task creation function.

Iii. Deleting tasks

Deleting a task means that the task will be returned and dormant, not that the code of the task is deleted, but that the code of the task is no longer called by Uc/os-ii.

Task management (UC/OS-II)

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.