Ucos-ii suspend and resume of tasks

Source: Internet
Author: User

Function description

ostasksuspend ()
Function Description: Suspends a task unconditionally. The task calling this function can also pass the parameter os_prio_self, suspending the calling task itself.
Function prototype: int8u ostasksuspend (int8u prio);
Parameter Description: PRIO Specifies that you want to get a pending task priority, or you can specify a parameter os_prio_self to suspend the task itself. At this point, the next highest-priority ready task will run.
return value:
The return value of Ostasksuspend () is one of the following:
? Os_no_err: The function call succeeded.
? Os_task_ Suspend_idle: Attempted to suspend idle task in μc/Os. This is an illegal operation.
? Os_prio_invalid: The parameter specifies a value that is greater than Os_lowest_prio or not set os_prio_self.
? Os_task_ SUSPEND _prio: The task to suspend does not exist.


Ostaskresume ()
Function Description: Wakes up a task that is suspended with the Ostasksuspend () function. Ostaskresume () is also the only function that can "hang" suspended tasks.
Function prototypes: nt8u ostaskresume (int8u prio)
Parameter Description: Prio Specifies the priority to wake the task
return value:
The return value of Ostaskresume () is one of the following:
? Os_no_err: The function call succeeded.
? Os_task_resume_prio: The task to be awakened does not exist.
? Os_task_not_suspended: The task to wake is not in a pending state.
? Os_prio_invalid: The parameter specifies a priority greater than or equal to Os_lowest_prio.

Use note

After the current task is suspended, only other tasks can wake up the suspended task. Once the task is suspended, the system will reschedule the task and run the next highest-priority ready task. The wake-up suspend task requires calling the function Ostaskresume (). The suspend of a task can be superimposed on other operations. For example, when a task is suspended while a delay operation is in progress, the wake of the task requires two conditions: the end of the delay and the wake-up action of the other task. As another example, when a task is suspended, it waits for a semaphore, and when the task is purged from the semaphore's waiting column, it cannot run immediately, but must wait until it wakes up.

A test example

Test platform: STM32

Test code:

#defineStarttaskprio 4#defineTask1_prio 5#defineTask2_prio 6intMainvoid) {usart1_config ();    Osinit (); Ostaskcreate (StartTask, (void*)0, &starttaskstk[starttaskstklength-1], Starttaskprio);    Osstart (); return 0; }voidStartTask (void*P_arg) {    (void) P_arg;
usart1_printf ("\nstarttask has been running!"); Systick_config (Systemcoreclock/os_ticks_per_sec); Ostaskcreate (Task1, (void*)0, &task1_stk[task1_stk_size-1], Task1_prio); Ostaskcreate (Task2, (void*)0, &task2_stk[task2_stk_size-1], Task2_prio); Ostasksuspend (Starttaskprio);}voidTask1 (void*P_arg) { (void) P_arg; while(1) {usart1_printf ("\ntask1 has been running!"); Ostasksuspend (Task1_prio); }}voidTask2 (void*P_arg) { (void) P_arg; while(1{usart1_printf ("\n\ntask2 start running!");Ostaskresume (Task1_prio);
usart1_printf ("\ntask2 has been running!"); ostimedly (2*os_ticks_per_sec); }}

Program execution Sequence Flow:

Operation Result:

Reference: "Hangzhou Electric ucos-ii-arm7 Experiment Instruction book"

Ucos-ii tasks for suspend and resume

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.