📄 x-timestamp2.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Creating a VxWorks Timestamp Driver </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="x-timestamp.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="x-timestamp.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="x-timestamp1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="x-timestamp3.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="85559">G.2 Hardware Overview</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85560"> </a>This section discusses typical hardware timer modes of operation and characteristics, and defines the VxWorks requirements for timestamp drivers.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85561">Modes of Operation</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85562"> </a>Most target boards have multiple hardware timers available for operating system and application use. The characteristics of timers vary widely due to evolving hardware technology. Generally, timers on older target boards are not as easy to work with as timers on newer, more refined hardware. However, many different types of timers are suitable for use with VxWorks.</p><dd><p class="Body"><a name="85563"> </a>In its most basic form (shown in <a href="x-timestamp2.html#85870">Figure G-1</a>), a timer is simply a timing source (that is, a clock) used as input to a counter. The counter counts up or down as the associated clock transitions. <div class="frame"><h4 class="EntityTitle"><a name="85870"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure G-1: Basic Form of Timer</font></a></h4><dl class="margin"><div class="Anchor"><a name="85872"> </a><img class="figure" border="0" src="images/x-timestampa3.gif"></div></dl></div></p><dd><p class="Body"><a name="85579"> </a>There are three common modes in which timers operate: <i class="term">periodic</i>, <i class="term">one-shot</i>, and <i class="term">timestamp</i>. Many newer timers are versatile, and can be used in any one of these modes, depending on how they are configured. The characteristics of each mode are as follows: </p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85580">Periodic Interrupt Timer</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85581"> </a>The timer counts up or down to a programmed value (called the terminal count), at which point it generates a hardware interrupt. The counter is reset (either by hardware or software), and begins to count up or down again towards the terminal count. The interrupt is the sole output of a periodic interrupt timer. After acknowledging the interrupt, an interrupt service routine (ISR) usually calls an operating system facility to log the interrupt as a <i class="term">clock tick</i>. In some cases, the ISR calls an application-specific routine instead. </p><dd><p class="Body"><a name="85582"> </a>The terminal count may be adjusted so that an interrupt is generated at a specified time interval. For instance, if the terminal count is set such that an interrupt occurs every 10 msec, 100 ticks per second are generated (100Hz). The VxWorks system and auxiliary clocks use the underlying hardware timers in periodic interrupt mode.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85583">One-Shot Timer</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85584"> </a>The timer counts up or down to a programmed terminal count, at which point it generates a hardware interrupt. The counter is then disabled (either by hardware or software). An ISR acknowledges the interrupt, and then calls a user-specified routine.</p><dd><p class="Body"><a name="85585"> </a>Currently, VxWorks does not provide a one-shot timer facility, although this type of timer may be simulated by having a periodic interrupt timer disable the counter in the ISR.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85586">Timestamp Timer</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85587"> </a>The timer counts up or down to its maximum count (0 or 0xfff) at which point it generates a hardware interrupt. The counter rolls over and begins to count again towards the maximum value. After acknowledging the interrupt, an ISR calls an operating system facility or application-specific routine to log the counter rollover. At any time, the operating system or application may read the counter value to obtain high-resolution timing information in <i class="term">timestamp tick</i> units.</p><dd><p class="Body"><a name="85588"> </a>This mode of operation differs from a periodic interrupt timer in that the counter is usually allowed to count to its maximum value (that is, the terminal count is set to 0 or 0xfff). Additionally, the counter value is the primary output of the timestamp timer, and the interrupt is only used to announce a counter rollover. Timestamp timer components are typically similar to <a href="x-timestamp2.html#85892">Figure G-2</a>. <div class="frame"><h4 class="EntityTitle"><a name="85892"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure G-2: Components of a Timestamp Timer</font></a></h4><dl class="margin"><div class="Anchor"><a name="85894"> </a><img class="figure" border="0" src="images/x-timestamp0.gif"></div></dl></div></p><dd><p class="Body"><a name="85622"> </a>The remainder of this document deals only with timers operating in timestamp mode.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85623">Characteristics of Hardware Timers</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85624"> </a>Several factors determine how suitable a particular hardware timer may be for a timestamp driver. This information may help to choose an appropriate timer, if several are available.</p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85625">Read While Enabled </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85626"> </a>The most important characteristic of a good timestamp timer is the ability to read the counter's value without having to stop the timer from counting. If the timer must be disabled to read the timestamp value accurately, the time spent without the timer running is not recorded, although the system is actually doing work and other timers are continuing to run (the system clock, for instance). This situation is commonly called <i class="term">time skew</i>. As time skew accumulates, the timestamp values become more and more removed from the absolute time of the system, as kept by the system clock. Additionally, interrupts must be locked out while the timer is stopped. Both of these effects are detrimental to real-time systems.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85627">Prescaler Counter</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85628"> </a>The input clock is often passed through a prescaler counter to divide the input clock frequency, thereby producing a lower frequency input for the timestamp counter. Although a prescaler is not always present (and need not be used) it can be a useful way of tuning timer devices that have an unusually high input clock frequency.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85629">Counter Width </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85630"> </a>The timer's counter should be at least 16 bits wide, although a 24- or 32-bit counter is preferable. The wider a counter, the less often it must roll over, and therefore the less system overhead its ISR incurs. The input frequency can also be higher with a wide counter, which yields more accurate timing information.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85631">Preload After Disable </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85632"> </a>Some timers require that the counter be preloaded with a value before counting resumes. This is an issue only for timers that cannot be read while enabled. This characteristic adds to the time spent with the timer disabled, thereby increasing time-skew problems. The preload mechanism itself provides a way to correct skew, but determining the amount of the correction is difficult; see the discussion of counter preloading in <a href="x-timestamp4.html#85750"><i class="title">Working Around Deficiencies in Hardware Timers</i></a>.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85636">Cache Coherency </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85637"> </a>As with all hardware devices, the locations of timer device registers must be cache coherent. This ensures that reads and writes to timer registers are actually accessing the register locations themselves, and not CPU data cache locations. If data cache memory exists, and there is no hardware mechanism (such as an MMU) to guarantee data cache coherency for register locations, the timestamp timer driver must make explicit calls to flush and invalidate the CPU's data cache. This adds to the overhead of reading the timestamp tick value. For more information, see the <i class="title">VxWorks BSP Porting Kit</i>: <i class="title">Cache and Virtual Memory Library Support</i>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85638">VxWorks Requirements for Timestamp Timers</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85639"> </a>The VxWorks kernel instrumentation uses a timestamp timer, when available, to log timing information for selected operating system events--for example, semaphore gives and takes, task spawns and deletions, system clock ticks, and interrupts.</p><dd><p class="Body"><a name="85640"> </a>VxWorks requires that timestamp timers provide these features:</p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85641">Rollover Interrupt </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85642"> </a>The timestamp timer must be able to generate a hardware interrupt once the maximum (or terminal) count is reached. An interrupt is needed to avoid aliasing, by announcing the rollover event. Without the interrupt, timestamps are ambiguous, since there is no way to distinguish two timestamps separated by the timer's period.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85643">Fine Resolution </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85644"> </a>The timestamp tick <i class="term">resolution</i> is calculated as follows:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85648"><img class="figure" border="0" src="images/x-timestampa1.gif"></pre> <br></a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85649"> </a>To be effective, the resolution should be 10 µsec or less (that is, a timestamp tick frequency of at least 100KHz). Although this is not a strict requirement, it is consistent with timing limitations within the VxWorks kernel. If the timestamp timer output is slower than 100KHz, some instrumented kernel events may not have distinguishable timing information.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="85650">Sizable Period </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85651"> </a>The time between timestamp rollovers is the timestamp timer's <i class="term">period</i>. The period is defined as the product of the timer resolution and the timer's maximum count:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="85655"><img class="figure" border="0" src="images/x-timestampa2.gif"></pre></a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="85656"> </a>To be effective, the period should be at least 10 msec. If rollovers are more frequent, the overhead of servicing the rollover interrupt may be too intrusive. The greater the period, the better.</p></dl></dl><a name="foot"><hr></a><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="x-timestamp.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="x-timestamp.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="x-timestamp1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="x-timestamp3.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc. conversion tool: Quadralay WebWorks Publisher 4.0.11 template: CSS Template, Jan 1998 - Jefro --->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -