?? timestamp.c
字號:
/***************************************************************************
*
* $RCSfile: timeStamp.c $
*
* Copyright 2002 by Dy 4 Systems, Inc. All Rights Reserved.
*
* $Revision: 1.5 $
*
* $Name: AV4-ISP-R1.2-1 AV4-ISP-R1.2-0 HMTST2 HMTST1 DVT_AV4_4.101 AV4-VSP-R1.0-2 AV4-VSP-R1.0 CT-ISP-1.1 AV4 ISP 1.1 CT_R0.1_AV4/CAV4 champtools2.22 CAV4_CP1 CHAMPtools FW 3.0 champtools2.21_1215 champtools2.21 champ221_build1 champtools2.2 CHAMPtools_2.1.1_AV3 CHAMPtools_2.1_106 CHAMPtools_2.0_AV3 $ $State: Developmental $ $Locker: $
*
* $Source: L:/SWRND/champAV2/src/vx/src/drv/timer/rcs/timeStamp.c $
*
* RCS Project Name:
*
* CSC:
*
* Target:
*
* Description:
*
* Usage:
*
* $Log: timeStamp.c $
* Revision 1.5 2003/08/05 20:04:36Z esaunder
* Modified to utilize AV3 timer resource allocation functions (bslTimerAlloc,
* bslTimerDealloc); timer allocated only while enabled.
* Revision 1.4 2002/07/27 11:32:07 coopertr
* The get frequency function now returns the timer's input frequency,
* per WRS specifications for a timestamp driver.
* Revision 1.3 2002/05/28 14:40:14 coopertr
* Revision 1.2 2002/05/24 22:00:34 coopertr
* Revision 1.1 2002/05/08 16:04:52 coopertr
* Initial revision
*
****************************************************************************/
/* Copyright 1994 Wind River Systems, Inc. */
#include "copyright_wrs.h"
/*
modification history
--------------------
01a,23mar94,dzb written.
*/
/*
DESCRIPTION
This library contains timestamp driver management routines using
one of the Galileo timers for the timestamp driver.
To include the timestamp timer facility, the macro INCLUDE_TIMESTAMP must be
defined.
*/
#ifdef INCLUDE_TIMESTAMP
#include "drv/timer/timestampDev.h"
#include "bsl.h"
#include "bslInt.h"
/* Locals */
LOCAL BOOL sysTimestampRunning = FALSE; /* running flag */
LOCAL long timestampTicks=0; /* ticks/interval */
LOCAL long timestampFreq=0; /* input freq */
LOCAL long timestampIntRate = 1; /* interrupts/sec */
char sysTimestampTimerName[] = "Timestamp Timer";
int sysTimestampTimerID = -1;
unsigned short initialized=0;
void timeStampNull (void)
{
}
/***************************************************************************
*
* sysTimestampConnect - connect a user routine to timestamp timer interrupt
*
* This routine connects the timestamp timer interrupt, enables the
* interrupt, and initializes the counter registers (rate).
* This routine specifies the user interrupt routine to be called at each
* timestamp timer interrupt. It does not enable the timestamp timer itself.
* Called from .../vx/proj/..../prjConfig.c
*
* If the timer already exists, the existing one is used.
*
* 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 */
)
{
STATUS status = OK;
if( bslTimerAlloc( sysTimestampTimerName, NON_EXCL, &sysTimestampTimerID ) != BSL_ERROR_NONE )
{
sysTimestampTimerID = -1;
status = ERROR;
}
else
{
bslTimerStop (sysTimestampTimerID);
intConnect ((void *)bslTimerToId (sysTimestampTimerID),
(void *)routine, arg);
timestampFreq = bslBoardGetBusSpeed ();
timestampTicks = timestampFreq/timestampIntRate;
bslTimerSetTicks (sysTimestampTimerID, timestampTicks);
bslTimerIntEnable (sysTimestampTimerID);
initialized = 1;
}
return( status );
}
/***************************************************************************
*
* sysTimestampEnable - enable the timestamp timer
*
* If the timestamp timer is already running, this routine
* merely resets the timer counter.
*
* This routine does not initialize the timer clock rate.
*
* RETURNS: OK, or ERROR if the timestamp timer cannot be enabled.
*/
STATUS sysTimestampEnable (void)
{
STATUS status = OK;
if( !initialized ) status = ERROR;
else
{
/** Note: NON_EXCL option tolerates multiple calls to sysTimestampEnable() w/o an
intervening sysTimestampDisable() **/
if( bslTimerAlloc( sysTimestampTimerName, NON_EXCL, &sysTimestampTimerID ) != BSL_ERROR_NONE )
{
status = ERROR;
}
else
{
sysTimestampRunning = TRUE;
bslTimerStart( sysTimestampTimerID );
}
}
return( status );
}
/***************************************************************************
* sysTimestampDisable - disable the timestamp timer
*
* This routine disables the timestamp timer & deallocates the timer
* resource. 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)
{
STATUS status = OK;
if( sysTimestampTimerID == -1 ) status = ERROR;
else
{
sysTimestampRunning = FALSE;
bslTimerStop (sysTimestampTimerID);
bslTimerDealloc( sysTimestampTimerName );
sysTimestampTimerID = -1;
}
return( status );
}
/***************************************************************************
*
* 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 (timestampTicks);
}
/***************************************************************************
*
* sysTimestampFreq - get the timestamp timer clock frequency
*
* This routine returns the frequency into the timer clock, in Hz.
*
* RETURNS: The timestamp timer clock input frequency, in Hz.
*/
UINT32 sysTimestampFreq (void)
{
return (timestampFreq);
}
/***************************************************************************
*
* sysTimestamp - get the timestamp timer tick count
*
* This routine returns the current value of the timestamp timer tick counter.
* Because the counter counts from timestampTicks down to zero, we
* return timestampTicks minus the register value to get the number
* of ticks elapsed since the last timestamp driver interrupt.
*
* RETURNS: The current timestamp timer tick count.
* SEE ALSO: sysTimestampLock()
*/
UINT32 sysTimestamp (void)
{
if( sysTimestampTimerID == -1 ) return 0;
else
return (timestampTicks - bslTimerRead (sysTimestampTimerID));
}
/***************************************************************************
*
* 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().
*
* RETURNS: The current timestamp timer tick count.
*
* SEE ALSO: sysTimestamp()
*/
UINT32 sysTimestampLock (void)
{
return (sysTimestamp ());
}
#endif /* INCLUDE_TIMESTAMP */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -