Ucos ii kernel 4: Task latency Function

Source: Internet
Author: User

 

Ucos ii Task latency Function

All those who have compiled MCU programs know that latency functions are often used.

In ucos ii, the system also provides such a delay function. One is the public version of ostimedly (), and the other is the refined version of ostimedlyhmsm (). Radish and vegetables, each with love, as you choose.

The difference between the two is that the delay time of ostimedly () is measured by the number of beats, and the delay time of ostimedlyhmsm () is measured by the specific time.

These two functions play an important role, that is, when you call these two functions, ucos ii will schedule a task. Therefore, the CPU can be switched between tasks, thanks to these two functions.

When you call these two delay functions, the current task will be suspended, and the CPU will execute the task with the highest priority in the ready table.

One thing to note is that after a task calls ostimedly (), once the specified time expires or another task cancels the delay by calling ostimedlyresume (), it will immediately enter the ready state, this is not the execution status, that is, the task may not be executed immediately after the delay ends.

Assume that the latency of calling the latency function is 0.001 seconds during task execution. The latency may be greater than this value. This depends on your task schedule.

Let's take a look at the specific implementation of these two functions.

 

Program list l 5.1 ostimedly ().

Void ostimedly (int16u ticks)

{

If (ticks> 0) {(1)

OS _enter_critical ();

If (osrdytbl [ostcbcur-> ostcby] & = ~ Ostcbcur-> ostcbbitx) = 0) {(2)

Osrdygrp & = ~ Ostcbcur-> ostcbbity;

}

Ostcbcur-> ostcbdly = ticks; (3)

OS _exit_critical ();

Ossched (); (4)

}

}

In fact, the program has done the following:

1. Delete this task from the task readiness table

2. Keep the latency value in the task control block, and use ostimetick () to reduce the number of latencies at every clock cycle.

3. Call the task scheduling function to switch tasks.

 

Int8u ostimedlyhmsm (int8u hours, int8u minutes, int8u seconds, int16u Milli)

{

Int32u ticks;

Int16u loops;

 

 

If (hours> 0 | minutes> 0 | seconds> 0 | Milli> 0) {(1)

If (minutes> 59 ){

Return (OS _time_invalid_minutes );

}

If (seconds> 59 ){

Return (OS _time_invalid_seconds );

}

If (Milli> 999 ){

Return (OS _time_invalid_milli );

}

Ticks = (int32u) hours * 3600l * OS _ticks_per_sec (2)

+ (Int32u) minutes * 60l * OS _ticks_per_sec

+ (Int32u) seconds * OS _ticks_per_sec

+ OS _ticks_per_sec * (int32u) Milli

+ 500l/OS _ticks_per_sec)/1000l; (3)

Loops = ticks/65536l; (4)

Ticks = ticks % 65536l; (5)

Ostimedly (ticks); (6)

While (loops> 0) {(7)

Ostimedly (32768); (8)

Ostimedly (32768 );

Loops --;

}

Return (OS _no_err );

} Else {

Return (OS _time_zero_dly); (9)

}

}

 

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.