System timer Analysis of Wince oal

Source: Internet
Author: User

Author: arm-WinCE

For any operating system, the system timer is like the heart of the OS. In essence, the operating system is interrupt-driven. In wince, the system timer will be implemented in OAL. Generally, it is initialized in the oeminit function and all is performed after interrupt initialization.

Generally, there are two implementation methods for the timer system of Wince: Fixed tick and variable tick. Fixed tick is usually used to generate a timer interrupt every 1 ms. When the interrupt occurs, we will check whether the current time has exceeded the dwreschedtime value, if the value exceeds, sysintr_resched is returned. Otherwise, sysintr_nop is returned. In fact, this method belongs to the polling mode. Variable tick is not commonly used. It mainly refers to timer interruption occurs when the scheduler of Wince needs to be scheduled. For fixed tick, if the system does not need to schedule, sysintr_nop is returned, however, this will cause an interruption every 1 ms, which is equivalent to awakening the system every 1 ms. When variable tick is used, the wince system will call the oemidle function if there is no thread to run, but before calling the function, it will call the oaltimerupdaterescheduletime function, which has been implemented in pqoal, oaltimerupdate will be further called to reset the timer cycle of the system timer. the preset clock cycle should be the next scheduled time of the system, so that variable tick is realized, it can be said that variable tick is more like interrupt mode.

Fixed tick is generally used, so the implementation of fixed tick's timer is mainly introduced. As mentioned above, Timer Initialization is also completed in the oeminit function, which is generally completed through the oaltimerinit function. It mainly initializes kernel variables related to timer and global variables of timer status g_oaltimer, and initialize the hardware timer.

1. g_oaltimer

G_oaltimer is a global variable used to describe the system timer information. It is defined as follows:

Oal_timer_state g_oaltimer;

The oal_timer_state structure is defined as follows:

Typedef struct

{

Uint32 countspermsec; // count in 1 ms

Uint32 countsmargin; // The Count required for changing the timer Value

Uint32 maxperiodmsec; // maximum Ms cycle supported by hardware Timer

Uint32 msecpersponick; // The number of milliseconds required for a system tick

Uint32 countspersponick; // The Count required by a system tick

Uint32 actualmsecpersponick; // the actual number of MS for a system tick

Uint32 actualcountspersponick; // The actual count of a system's tick

Volatile uint64 curcounts; // current count

} Oal_timer_state, * poal_timer_state;

2. bool oaltimerinit (uint32 msecper0000ick, uint32 countspermsec, uint32 countsmargin)

Msecpersystick: the number of Ms required by a system tick. The default value is 1 ms.

Countspermsec: How many count is contained in 1 ms

Countsmargin: The Count required when the hardware timer value is changed

This function is the initialization function of the system timer. the initialization process is as follows:

* Initialize the timer status variable g_oaltimer

* Initialize the global kernel variables curridlelow, curridlehigh, and idleconv.

* Initialize the high-precision timer function pointer pqueryperformancefrequency and pqueryperformancecounter

* The hardware interrupt of timer is statically mapped to obtain the system interrupt number.

* Initialize the hardware timer and enable timer interruption.

After the system timer runs, it will interrupt every 1 ms, and the interruption will be handled by oeminterrupthandler. In this function, if the system timer interrupt occurs, oaltimerintrhandler is called to handle the interrupt.

3. uint32 oaltimerintrhandler ()

This function processes timer interruptions and returns the corresponding sysintr value. The process is as follows:

* Clearing the pending bit of timer interruption

* Update the status information of kernel variables curmsec and timer g_oaltimer.curcounts

* Judge curmsec and dwreschedtime. If curmsec is greater than dwreschedtime, sysintr_resched is returned; otherwise, sysintr_nop is returned.

4. pqueryperformancefequency and pqueryperformancecounter

To implement a high-precision timer, You need to initialize two high-precision timer function pointers, as shown below:

Pqueryperformancefrequency = oaltimerqueryperformancefrequency;

Pqueryperformancecounter = oaltimerqueryperformancecounter;

These two functions have been implemented in pqoal. The two functions return the high-precision frequency and count, respectively. oaltimerqueryperformancecounter calls the oaltimercountssincesystick function to obtain the Count value in the current hardware timer.

5. uint32 oemgettickcount ()

This function returns the number of milliseconds since wince was started. This function has been implemented in pqoal. Generally, when the system tick is 1 ms, this function can directly return curmsec.

6. Void oalstall (uint32 usecs)

Usecs: the delay in microseconds

This function is a microsecond-level delay function, which is generally implemented through loops. In many cases, it is directly implemented using assembler.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/nanjianhui/archive/2009/03/20/4007259.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.