Time in the Uc/os-ii

Source: Internet
Author: User

Time is a very important concept, we go out to play with friends need to agree a time, do things also need to spend some time, in short, our life is inseparable from time. The operating system, too, requires a time to standardize the execution of its tasks.

Our life, the smallest unit of time is the second, the hardware circuit, the minimum time is the crystal oscillator frequency, in the operating system, its minimum unit of time is called the clock ticks (time Tick), it is a hardware timer generated by a period of milliseconds (ms), that is, when the timer reaches the specified time, Generates an interrupt (OSTICKISR ()), which is the time interval between two interrupts.

When the clock-beat interrupt function (OSTICKISR ()) is entered, it first saves the value of the CPU register, where is the value stored? When performing ISR and performing tasks, the place to save should be different Ah, when performing tasks, should be saved in the task stack, but when executing the ISR, where is saved? Add 1 to the terminal nesting layer (osintnesting), and then determine if it has no interrupt nesting, and if not, assign the stack pointer (SP) to the TCB member ostcbstkptr of the current task. Then call the clock beat function (Ostimetick ()), then clear the interrupt, and finally exit the interrupt (Osintexit ()), in the introduction of the interrupt function, will trigger a task scheduling.

In the clock beat function (Ostimetick ()), the main task has two, one is to record the time of the variable ostime+1, and the other is to traverse all the task control block linked list, to the task block to save the task delay time limit of OSTCBDly-1 (that is, to tell the task, Time is past a beat), if the deadline for suspending a task has arrived, make it into a task-ready state (note: A non-suspended task, a suspended task (Ostasksuspend ()), you must call the recovery task function (Ostaskresume ()) to restore its state).

Sometimes we want to do some work on every clock beat, like in real life, I let the phone lights flash every second. We can call the clock beat service function's hook function (Ostimetickhook ()) to complete this task. There are many kinds of hook functions, such as the work to be done when the task is switched (Ostaskswhook ()). There are a total of 10 such hook functions. Of course, if it is not necessary, it is advisable to use the hook function, because execution also takes time, which can result in inaccurate timing. (Does the hardware timer work when the hook function is executed?) When it reaches the time of timing, the same interruption will occur, which will cause the timing is inaccurate? )

In each task (in addition to the idle task), you must use the Delay function (ostimedly ()) to suspend the running of the current task for a period of time and perform a task schedule to allow the system to perform other high-priority ready tasks, or the task will always occupy the use of the CPU. A phenomenon that causes the exclusive CPU of the task.

The function of ostimedly () is to put the time-delay to the task to control the member ostcbdly of the TCB, and cancel the current task readiness State, and then perform a task scheduling, so that the system to perform the task of the highest priority of the ready task. ostimedly (int16u ticks) is a function that is timed with the number of ticks, and the system also defines another delay function int8u ostimedlyhmsm (int8u hours, int8u minutes, int8u seconds, int8u milli), i.e. the time, minutes, seconds, and milliseconds specified.

There are functions that make the task delay, naturally also need to make the task to cancel the delay function, Ostimediy (), whether the call is the delay function in the above, all by calling Ostimedlyresume () cancel the task delay to enter the ready state. The prototype of this function is int8u ostimedlyresume (int8u prio);

Finally, you can also call Ostimeget () and Ostimeset () to get or set the system time, which is the number of clock ticks that occur (the value of Ostime). Its function prototypes were asked int32u ostimeget (void) and void Ostimeset (int32u ticks).

Time in Uc/os-ii (ext.)

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.