📄 x-timestamp6.html
字号:
/* wait for preload to take effect here */ intUnlock (lockKey); /* UNLOCK INTERRUPTS */ return (OK); } /* connect interrupt handler for the correction timer */ (void) intConnect (INUM_TO_IVEC (XXX), sysTimestampInt, NULL); /* set the correction timer's interrupt vector to XXX (if necessary) */ sysTimestampRunning = TRUE; /* set the period of the correction timer (see sysTimestampPeriod()) */ /* set the period of the counting timer = reset count */ /* enable the counting timer here */ /* enable the correction timer here */ /* wait for preload to take effect on both timers here */ return (OK); } /*************************************************************************** * * sysTimestampDisable - disable the timestamp timer * * This routine disables the timestamp timer. Interrupts are not disabled. * However, the tick counter will not decrement after the timestamp timer * is disabled, ensuring that interrupts are no longer generated. * * RETURNS: OK, or ERROR if the timestamp timer cannot be disabled. */ STATUS sysTimestampDisable (void) { if (sysTimestampRunning) { sysTimestampRunning = FALSE; /* disable the correction timer here */ /* disable the counting timer here */ } return (OK); } /*************************************************************************** * sysTimestampPeriod - get the timestamp timer period * * This routine returns the period of the timer in timestamp ticks. * The period, or terminal count, is the number of ticks to which the * timestamp timer counts before rolling over and restarting the counting * process. * * RETURNS: The period of the timer in timestamp ticks. */ UINT32 sysTimestampPeriod (void) { /* * Return the correction timer period here. * A reasonable correction period should be chosen. A short period * causes increased CPU overhead due to correction timer interrupts. * A long period allows for a large accumulation of time skew * due to sysTimestamp() calls stopping the counting timer. */ return (TS_CORRECTION_PERIOD); } /*************************************************************************** * sysTimestampFreq - get the timestamp timer clock frequency * * This routine returns the frequency of the timer clock, in ticks per second. * The rate of the timestamp timer should be set explicitly in the BSP, * in the sysHwInit() routine. * * RETURNS: The timestamp timer clock frequency, in ticks per second. */ UINT32 sysTimestampFreq (void) { UINT32 timerFreq; /* * Return the timestamp tick output frequency here. * This value can be determined from the following equation: * timerFreq = clock input frequency / prescaler * * When possible, read the clock input frequency and prescaler values * directly from chip registers. */ return (timerFreq); } /*************************************************************************** * * sysTimestamp - get the timestamp timer tick count * * This routine returns the current value of the timestamp timer tick counter. * The tick count can be converted to seconds by dividing by the return of * sysTimestampFreq(). * * Call this routine with interrupts locked. If interrupts are * not already locked, use sysTimestampLock() instead. * * RETURNS: The current timestamp timer tick count. * * SEE ALSO: sysTimestampLock() */ UINT32 sysTimestamp (void) { UINT32 tick = 0; register UINT32 * pTick; register UINT32 * pPreload; if (sysTimestampRunning) { /* pTick = counter read register location */ /* pPreload = counter preload register location */ /* disable counting timer here */ tick = *pTick; /* read counter value */ *pPreload = tick - TS_SKEW; /* set preload value (with time-skew adjustment) */ /* enable counting timer here */ tick -= (0xfff...); /* adjust to incrementing value */ } return (tick); } /*************************************************************************** * sysTimestampLock - get the timestamp timer tick count * * This routine returns the current value of the timestamp timer tick counter. * The tick count can be converted to seconds by dividing by the return of * sysTimestampFreq(). * * This routine locks interrupts for cases where it is necessary to stop the * tick counter before reading it, or when two independent counters must * be read. If interrupts are already locked, use sysTimestamp() instead. * * RETURNS: The current timestamp timer tick count. * SEE ALSO: sysTimestamp() */ UINT32 sysTimestampLock (void) { UINT32 tick = 0; register UINT32 * pTick; register UINT32 * pPreload; int lockKey; if (sysTimestampRunning) { lockKey = intLock (); /* LOCK INTERRUPTS */ /* pTick = counter read register location */ /* pPreload = counter preload register location */ /* disable counting timer here */ tick = *pTick; /* read counter value */ *pPreload = tick - TS_SKEW; /* set preload value */ /* (with time-skew adjustment) */ /* enable counting timer here */ intUnlock (lockKey); /* UNLOCK INTERRUPTS */ tick -= (0xfff...); /* adjust to incrementing value */ } return (tick); } #endif /* INCLUDE_TIMESTAMP */</a></b></pre></dl></dl><h4 class="EntityTitle"><a name="86024"><font face="Helvetica, sans-serif" size="-1" class="sans">Example G-3: Timestamp Drivers for the VxWorks System Clock Timer</font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86098"> </a>This example shows a skeleton timestamp driver for systems that have no suitable spare timers, so that timestamps must be derived from the VxWorks system clock timer. See <a href="x-timestamp4.html#85777"><i class="title">Using the VxWorks System Clock Timer</i></a>, for a discussion of the most important details involved in writing this kind of driver.</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="86284">/* sampleCTimer.c - sample C timer library */ /* Copyright 1994 Wind River Systems, Inc. */ #include "copyright_wrs.h" /* modification history -------------------- 01a,23mar94,dzb written. */ /* DESCRIPTION This library contains sample routines to manipulate the timer functions on the sample C chip with a board-independent interface. This library handles the timestamp timer facility. To include the timestamp timer facility, the macro INCLUDE_TIMESTAMP must be defined.</a></b><dd> <b><a name="87767">NOTE: This module provides an example of a VxWorks timestamp timer driver implemented by reading the system clock timer counter. It illustrates the structures and routines discussed in the Appendix, "Creating a VxWorks Timestamp Driver." This module is only a template. In its current form, it will not compile. */ #ifdef INCLUDE_TIMESTAMP #include "drv/timer/timestampDev.h" #include "drv/timer/sampleCTimer.h" /* Locals */ LOCAL BOOL sysTimestampRunning = FALSE; /* running flag */ /*************************************************************************** * * sysTimestampConnect - connect a user routine to the timestamp timer * interrupt * * This routine specifies the user interrupt routine to be called at each * timestamp timer interrupt. It does not enable the timestamp timer itself. * * RETURNS: OK, or ERROR if sysTimestampInt() interrupt handler is not used. */ STATUS sysTimestampConnect ( FUNCPTR routine, /* routine called at each timestamp timer interrupt */ int arg /* argument with which to call routine */ ) { /* ERROR indicates that the system clock tick specifies a rollover event */ return (ERROR); } /*************************************************************************** * * sysTimestampEnable - initialize and enable the timestamp timer * * This routine connects the timestamp timer interrupt and initializes the * counter registers. If the timestamp timer is already running, this routine * merely resets the timer counter. * * Set the rate of the timestamp timer input clock explicitly within the * BSP, in the sysHwInit() routine. This routine does not initialize * the timer clock rate. * * RETURNS: OK, or ERROR if the timestamp timer cannot be enabled. */</a></b><dd> <b><a name="87768">STATUS sysTimestampEnable (void) { if (sysTimestampRunning) return (OK); sysTimestampRunning = TRUE; sysClkEnable (); /* ensure the system clock is running */ return (OK); } /*************************************************************************** * sysTimestampDisable - disable the timestamp timer * * This routine disables the timestamp timer. Interrupts are not disabled. * However, the tick counter does not increment after the timestamp timer * is disabled, ensuring that interrupts are no longer generated. * * RETURNS: OK, or ERROR if the timestamp timer cannot be disabled. */ STATUS sysTimestampDisable (void) { sysTimestampRunning = FALSE; return (ERROR); } /*************************************************************************** * * sysTimestampPeriod - get the timestamp timer period * * This routine returns the period of the timer in timestamp ticks. * The period, or terminal count, is the number of ticks to which the * timestamp timer counts before rolling over and restarting the counting * process. * * RETURNS: The period of the timer in timestamp ticks. */ UINT32 sysTimestampPeriod (void) { /* return the system clock period in timestamp ticks */ return (sysTimestampFreq ()/sysClkRateGet ()) } /*************************************************************************** * * sysTimestampFreq - get the timestamp timer clock frequency * * This routine returns the frequency of the timer clock, in ticks per second. * The rate of the timestamp timer should be set explicitly in the BSP, * in the sysHwInit() routine. * * RETURNS: The timestamp timer clock frequency, in ticks per second. */ UINT32 sysTimestampFreq (void) { UINT32 timerFreq; /* * Return the timestamp tick output frequency here. * This value can be determined from the following equation: * timerFreq = clock input frequency / prescaler * * When possible, read the clock input frequency and prescaler values * directly from chip registers. */ return (timerFreq); } /*************************************************************************** * * sysTimestamp - get the timestamp timer tick count * * This routine returns the current value of the timestamp timer tick counter. * The tick count can be converted to seconds by dividing by the return of * sysTimestampFreq(). * * Call this routine with interrupts locked. If interrupts are * not already locked, use sysTimestampLock() instead. * * RETURNS: The current timestamp timer tick count. * SEE ALSO: sysTimestampLock() */ UINT32 sysTimestamp (void) { /* return the system clock timer tick count here */ } /*************************************************************************** * * sysTimestampLock - get the timestamp timer tick count * * This routine returns the current value of the timestamp timer tick counter. * The tick count can be converted to seconds by dividing by the return of * sysTimestampFreq(). * * This routine locks interrupts for cases where it is necessary to stop the * tick counter before reading it, or when two independent counters must * be read. If interrupts are already locked, use sysTimestamp() instead. * * RETURNS: The current timestamp timer tick count. * * SEE ALSO: sysTimestamp() */ UINT32 sysTimestampLock (void) { /* * Return the system clock timer tick count here. * Interrupts do *not* need to be locked in this routine if * the counter does not need to be stopped to be read. */ } #endif /* INCLUDE_TIMESTAMP */</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="86286"> </a></p><dd><p class="Body"><a name="85959"> </a></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-timestamp5.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="x-glossary.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 + -