⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sysgt64260timer.c

📁 WINDRIVER SBC7410 BSP
💻 C
字号:
/* sysGt64260AuxTimer.c - NetFires auxiliary timer library *//* Copyright 1984-2002 Wind River Systems, Inc. *//*modification history--------------------01a,26mar02,gtf		Written from template*//*DESCRIPTIONThis driver provides auxiliary clock support.  The macros AUX_CLK_RATE_MIN, and AUX_CLK_RATE_MAX must be defined to provide parameter checking for the sysAuxClkRateSet() routines.NOTE: aux clock routines can only be used from processor A as   this interrupt is directed to A only!!!    Aux clock uses timer 7.Timestamp timer uses timer 6.   INCLUDES:*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#include "sysGt64260IntrCtl.h"#include "intLib.h"/* defines */#ifdef INCLUDE_GT64260TIMER_TIMESTAMP#ifdef INCLUDE_TIMESTAMP#define TIMESTAMP_HZ	1000000			 /* timestamp counter freq */#endif#endif/* locals */LOCAL FUNCPTR sysAuxClkRoutine  = NULL;LOCAL int sysAuxClkArg      = (int)NULL;LOCAL int sysAuxClkRunning  = (int)FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;#ifdef INCLUDE_GT64260TIMER_TIMESTAMP#ifdef INCLUDE_TIMESTAMPLOCAL BOOL  sysTimestampRunning = FALSE; /* running flag */LOCAL int   sysTimestampPeriodValue = 0;     /* Max counter value */LOCAL FUNCPTR   sysTimestampRoutine = NULL;  /* routine to call on intr */LOCAL int   sysTimestampArg     = 0;     /* arg for routine */void  sysTimestampInt (void);      /* forward declaration */#endif  /* INCLUDE_TIMESTAMP */#endif#ifdef INCLUDE_AUXCLK/********************************************************************************* sysAuxClkInt - handle an auxiliary clock interrupt** This routine handles an auxiliary clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysAuxClkConnect().** RETURNS: N/A*/void sysAuxClkInt (void)    {    if ( sysAuxClkRoutine != NULL )        (*sysAuxClkRoutine) (sysAuxClkArg);    }/********************************************************************************* sysAuxClkConnect - connect a routine to the auxiliary clock interrupt** This routine specifies the interrupt service routine to be called at each* auxiliary clock interrupt.  It does not enable auxiliary clock interrupts.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), sysAuxClkEnable()*/STATUS sysAuxClkConnect    (    FUNCPTR routine,    /* routine called at each aux clock interrupt */    int arg             /* argument to auxiliary clock interrupt routine */    )    {    sysAuxClkRoutine    = NULL;    sysAuxClkArg    = arg;    sysAuxClkRoutine    = routine;    return(OK);    }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void)    {    if ( sysAuxClkRunning )        {        UINT32 temp ;        /* stop counting */        GT64260_REG_RD(TMR4_7_CTRL, &temp);        temp &= ~0x03000000 ;        GT64260_REG_WR(TMR4_7_CTRL, temp) ;        sysGt64260MuxedIntDisable(TMR_INT_TYPE, 7);        sysAuxClkRunning = FALSE;        }    }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void)    {    static int connected = FALSE;    UINT32 temp ;    if ( !connected )        {        intConnect((VOIDFUNCPTR *)INUM_TO_IVEC(INT_VEC_TMR6_7),(VOIDFUNCPTR)sysAuxClkInt,0);        connected = TRUE;        }    if ( !sysAuxClkRunning )        {        /* GT64260 timers count down at TCLK which is 100MHz on this board -> need a constant. */        GT64260_REG_WR(TMR_CTR_7,(TCLK_FREQ/sysAuxClkTicksPerSecond));        /* start in timer mode */        GT64260_REG_RD(TMR4_7_CTRL, &temp);        temp |= 0x03000000 ;        GT64260_REG_WR(TMR4_7_CTRL, temp) ;        sysGt64260MuxedIntEnable(TMR_INT_TYPE, 7);        sysAuxClkRunning = TRUE;        }    }/********************************************************************************* sysAuxClkRateGet - get the auxiliary clock rate** This routine returns the interrupt rate of the auxiliary clock.** RETURNS: The number of ticks per second of the auxiliary clock.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()*/int sysAuxClkRateGet (void)    {    return(sysAuxClkTicksPerSecond);    }/********************************************************************************* sysAuxClkRateSet - set the auxiliary clock rate** This routine sets the interrupt rate of the auxiliary clock.  It does not* enable auxiliary clock interrupts.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet()*/STATUS sysAuxClkRateSet    (    int ticksPerSecond  /* number of clock interrupts per second */    )    {    if ( ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX )        return(ERROR);    sysAuxClkTicksPerSecond = ticksPerSecond ;    if ( sysAuxClkRunning )        {        sysAuxClkDisable ();        sysAuxClkEnable ();        }    return(OK);    }#endif /* INCLUDE_AUXCLK */#ifdef  INCLUDE_TIMESTAMP#ifdef INCLUDE_GT64260TIMER_TIMESTAMP/********************************************************************************* sysTimestampInt - timestamp timer interrupt handler** This rountine handles the timestamp timer interrupt.  A user routine is* called, if one was connected by sysTimestampConnect().** RETURNS: N/A** SEE ALSO: sysTimestampConnect()*/void sysTimestampInt (void)    {    if ( sysTimestampRunning && sysTimestampRoutine != NULL )        (*sysTimestampRoutine)(sysTimestampArg);    }/********************************************************************************* 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 */    )    {    sysTimestampRoutine = NULL;    sysTimestampArg = arg;    sysTimestampRoutine = routine;    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.** The rate of the timestamp timer should be set explicitly within the BSP,* in the sysHwInit() routine.  This routine does not intialize the timer* rate.** RETURNS: OK, or ERROR if hardware cannot be enabled.*/STATUS sysTimestampEnable (void)    {    static BOOL connected = FALSE;    UINT32 temp ;    if ( !connected )        {        intConnect((VOIDFUNCPTR *)INUM_TO_IVEC(INT_VEC_TMR2_3),(VOIDFUNCPTR)sysTimestampInt,0);        connected = TRUE;        }    if ( !sysTimestampRunning )        {        /* GT64260 timers count down at TCLK which is 100MHz on this board -> need a constant. */        GT64260_REG_WR(TMR_CTR_3,TCLK_FREQ);        /* start in timer mode */        GT64260_REG_RD(TMR0_3_CTRL, &temp);        temp |= 0x03000000 ;        GT64260_REG_WR(TMR0_3_CTRL, temp) ;        sysGt64260MuxedIntEnable(TMR_INT_TYPE, 3);        sysTimestampRunning = TRUE;        }    return(OK);    }/********************************************************************************* sysTimestampDisable - disable the timestamp timer** This routine disables the timestamp timer.  Interrupts are not disabled,* although the tick counter will not increment after the timestamp timer* is disabled, thus interrupts will no longer be generated.** RETURNS: OK, or ERROR if timer cannot be disabled.*/STATUS sysTimestampDisable (void)    {    UINT32 temp ;    if ( sysTimestampRunning )        {        sysTimestampRunning = FALSE;        GT64260_REG_RD(TMR0_3_CTRL, &temp);        temp &= ~0x03000000 ; /* timer 3 */        GT64260_REG_WR(TMR0_3_CTRL, temp) ;        sysGt64260MuxedIntDisable(TMR_INT_TYPE, 3);        }    return(OK);    }/********************************************************************************* sysTimestampPeriod - get the timestamp timer period** This routine returns the period of the timestamp timer in ticks.* The period, or terminal count, is the number of ticks to which the timestamp* timer will count before rolling over and restarting the counting process.** RETURNS: The period of the timestamp timer in counter ticks.*/UINT32 sysTimestampPeriod (void)    {    sysTimestampPeriodValue = TCLK_FREQ ;    return(sysTimestampPeriodValue);    }/********************************************************************************* sysTimestampFreq - get the timestamp timer clock frequency** This routine returns the frequency of the timer clock, in ticks per second.** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq (void)    {    UINT32 adjustedFreq ;    adjustedFreq = (TCLK_FREQ - 1000000); /* ZZZZZZZZZZ - need adjust constant */    return(adjustedFreq);    }/********************************************************************************* 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().** This routine should be called with interrupts locked.  If interrupts are* not already locked, sysTimestampLock() should be used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestampLock()*/UINT32 sysTimestamp (void)    {    UINT32 count = 0;    GT64260_REG_RD(TMR_CTR_3, &count);    count = TCLK_FREQ - count ;    return(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().** This routine locks interrupts for cases where it is necessary to stop the* tick counter in order to read it, or when two independent counters must* be read.  If interrupts are already locked, sysTimestamp() should be* used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestamp()*/UINT32 sysTimestampLock (void)    {    UINT32 result;    int oldLevel;    oldLevel = intLock ();    result = sysTimestamp ();    intUnlock (oldLevel);    return(result);    }#endif#endif  /* INCLUDE_TIMESTAMP */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -