📄 timestamp.c
字号:
/********************************************************************** * * Copyright (c) 2003-2004, Dy 4 Systems All rights reserved. * This Source Code is the Property of Dy 4 Systems Inc. and can * only be used in accordance with Source Code License * Agreement of Dy 4 Systems Inc. dba (doing business as) * CURTISS-WRIGHT CONTROLS EMBEDDED COMPUTING, "CWCEC". * **********************************************************************//***************************************************************************** Filename: timeStamp.c ** Copyright 2004 by DY4 Systems. All Rights Reserved.** Project Name: 182 BSP ** Target: 182 ** Description: Standard VxWorks timestamp driver** Usage: ** Log: * Initial revision *****************************************************************************//* Copyright 1994 Wind River Systems, Inc. */ #include "copyright_wrs.h" /* modification history -------------------- 01b,02nov04,tis - added support for CCA-14501a,23mar94,dzb written. */ /* DESCRIPTION This library contains timestamp driver management routines usingone 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 "h/drv/timer/fpgaTimer.h"#ifdef VME_182#include "fpga182_dy4.h"#include "intCtrl182_dy4.h"#include "dy4182.h"#endif#ifdef CCA_145#include "fpga145.h"#include "intCtrl145.h"#include "cca145.h"#endif#ifdef VME_183#include "fpga183.h"#include "intCtrl183.h"#include "cwv183.h"#endif/* Locals */ LOCAL FUNCPTR sysTimestampRoutine = NULL;LOCAL int sysTimestampArg = 0;LOCAL BOOL sysTimestampRunning = FALSE; /* running flag */ LOCAL int timestampId;void timeStampNull (void){}/*************************************************************************** * * sysTimestampHwInit - Initialize timestamp timer at HW init level * * This routine initializes the timestamp timer id depending upon the CPU* It has to be called in sysHwInit before timestamp timer is used* * RETURNS: none */ void sysTimestampHwInit(void) { if (sysProcId == CPU_ID_0) { timestampId = IOFPGA_TIMER0_1; } else { timestampId = IOFPGA_TIMER1_1; } fpgaTimerStop(timestampId); fpgaTimerIntClear(timestampId);} /*************************************************************************** * * sysTimestampConnect - connect a user routine to 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 */ ) {#if defined (CCA_145) || defined (VME_183) int timerCause; sysTimestampRoutine = routine; sysTimestampArg = arg; if (sysProcId == CPU_ID_0) { timerCause = FPGA_TIMER0_1 ; } else { timerCause = FPGA_TIMER1_1 ; } intConnect((void *)(timerCause), (void *)routine, arg); intEnable(timerCause);#else sysTimestampRoutine = routine; sysTimestampArg = arg; intConnect((void *)(FPGA_TIMER0_0 + timestampId), (void *)routine, arg); intEnable(FPGA_TIMER0_0 + timestampId);#endif return (OK);} /*************************************************************************** * * 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. */STATUS sysTimestampEnable (void) { if (sysTimestampRunning) return (OK); fpgaTimerIntClear(timestampId); fpgaTimerLoad(timestampId, TIMESTAMP_PERIOD); fpgaTimerStart(timestampId); sysTimestampRunning = TRUE; 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; fpgaTimerStop(timestampId); 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 system clock period in timestamp ticks */ return (TIMESTAMP_PERIOD);} /*************************************************************************** * * 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 (FPGA_TIMER_FREQ); } /*************************************************************************** * * sysTimestamp - get the timestamp timer tick count * * This routine returns the current value of the timestamp timer tick counter.* Because the counter counts from TIMESTAMP_PERIOD down to zero, we* return TIMESTAMP_PERIOD 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) { unsigned int count; fpgaTimerRead(timestampId, &count); return (TIMESTAMP_PERIOD - count);} /*************************************************************************** * * 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 + -