UCOS Time Management Mechanism) favorites

Source: Internet
Author: User

UCOS Time Management Mechanism (to) favorites
I. Time management mechanism

The latency provided by UCOS is based on the system clock. During system initialization, the system clock is initialized. A system clock is generally provided by a hardware clock, which is periodically interrupted and called a tick. When each tick occurs, the system enters the clock interrupt ISR. ISR calls ostimetick (). ostimetick () to delay processing of each task in the ostcblist linked list, that is,. ostimedly -- In the TCB of the task --. If ostimedly = 0, if the task is not suspended, the task is ready and waiting for scheduling. Ostcblist contains all the tasks created in the system.

Task latency: Delete the task from the ready table and set ostimedly to an appropriate value. Wait until ostimedly = 0 and then set it to ready for scheduling.

Therefore, the latency of a task is not based on the duration of the delayed task. Ideally, it is always n times the interval of tick interruption.

UCOS can also count the system clock tick to calculate the number of tick since the system.

Ii. UCOS interface functions

Void ostimedly (int16u ticks ).

Function: delay ticks system tick duration. After the delay is successful, the task is scheduled.

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

Function: provides easy user interfaces based on milliseconds and seconds.

Int8u ostimedlyresume (int8u PRIO );

Function: resumes a delayed task.

Int32u ostimeget (void );

Void ostimeset (int32u ticks );

Function: return, set the tick count of the system clock.

Iii. usage of the latency Function

Although UCOS provides a latency function, because it is based on the system clock interruption, all the latencies less than the clock interruption interval are not provided; only the software delay can be used.

In many cases, latency can be replaced by semaphores, mailboxes, and other methods.

Note that in the multi-task running environment, even if the task delay is completed, the task still cannot run due to the high-priority task running. When the task can run, the actual latency has exceeded the expected latency.

 

Appendix: describes the specific program of the ostimetick () function.

Void ostimetick (void) // This beat service function is called in the ostickisr function to check the task control block of each task when the clock beats arrive. whether it is 0 after the OSTCBDly-1, if yes, it indicates that this task was just suspended state, at this time should change to ready state
{
OS _tcb * ptcb;

Ostimetickhook ();//
Ptcb = ostcblist; // when the clock beats arrive, extract the first control block of the two-way linked list (not the task running before the beats)
While (ptcb-> ostcbprio! = OS _idle_prio) {// The idle task is at the end of the two-way linked list of the control block. If the retrieved control block is the control block of the idle task, the last one has been obtained and ends.

// OS _enter_critical ();
If (ptcb-> ostcbdly! = 0 ){//
If (-- ptcb-> ostcbdly = 0 ){//

If (! (Ptcb-> ostcbstat & OS _stat_suspend) {// check whether the task is forced to be suspended. If yes, then stop a clock cycle. Otherwise, it will be ready.

Osrdygrp | = ptcb-> ostcbbity;

Osrdytbl [ptcb-> ostcby] | = ptcb-> ostcbbitx;
} Else {//
Ptcb-> ostcbdly = 1 ;//

}//
}
}
Ptcb = ptcb-> ostcbnext; // The next task control block
// OS _exit_critical ();
}
// OS _enter_critical ();//
Ostime ++; // beat counter + 1
// OS _exit_critical ();
}

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zhouyujia/archive/2009/11/03/4756626.aspx

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.