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

📄 z8536timer.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    ULONG  tc;             /* time constant */    if (!sysAuxClkRunning)        {	cioCtl = ZCIO_CNTRL_ADRS;	/* set time constant */	tc = ZCIO_HZ / sysAuxClkTicksPerSecond;	*cioCtl = ZCIO_CT2TCMSB;             /* C/T 2 Time Const (MS Byte) */        *cioCtl = (UINT8) MSB(tc);	*cioCtl = ZCIO_CT2TCLSB;             /* C/T 2 Time Const (LS Byte) */        *cioCtl = (UINT8) LSB(tc);	/* clear and start timer */	*cioCtl = ZCIO_CT2CS;                /* C/T 2 Command and Status */	*cioCtl = ZCIO_CS_CLIPIUS;           /* Clear IP and IUS */	*cioCtl = ZCIO_CT2CS;                /* C/T 2 Command and Status */	*cioCtl = ZCIO_CS_SIE                /* Set Interrupt Enable */		| ZCIO_CS_GCB                /* Gate Command Bit */		| ZCIO_CS_TCB;               /* Trigger Command Bit */	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);    }/********************************************************************************* sysClkErrInt - handle a clock error interrupt** An error interrupt occurs because a timer interrupt* was not serviced before the next interrupt from the same timer* occurred.  One or more clock ticks have been lost.* An error interrupt is treated as a regular timer interrupt.** NOTE:* The system clock is the ZCIO counter/timer 3.* The auxiliary clock is the ZCIO counter/timer 2.* The timestamp clock is the ZCIO counter/timer 1.*/LOCAL void sysClkErrInt (void)    {    FAST UINT8  ctcs;           /* C/T Command and Status */    FAST volatile UINT8 *cioCtl = ZCIO_CNTRL_ADRS;    /* check if counter/timer 3 error set */    *cioCtl = ZCIO_CT3CS;    ctcs    = *cioCtl;    if (ctcs & (ZCIO_CS_IP | ZCIO_CS_ERR))	sysClkInt ();    /* check if counter/timer 2 error set */    *cioCtl = ZCIO_CT2CS;    ctcs    = *cioCtl;    if (ctcs & (ZCIO_CS_IP | ZCIO_CS_ERR))	sysAuxClkInt ();    /* check if counter/timer 1 error set */    *cioCtl = ZCIO_CT1CS;    ctcs    = *cioCtl;    if (ctcs & (ZCIO_CS_IP | ZCIO_CS_ERR))	{#ifdef INCLUDE_TIMESTAMP	sysTimestampInt ();#else	/* acknowledge the clock interrupt */	*cioCtl = ZCIO_CT1CS;             /* C/T 1 Command and Status */	*cioCtl = ZCIO_CS_CLIPIUS         /* Clear IP and IUS */		| ZCIO_CS_GCB;            /* Gate Command Bit */	logMsg ("counter/timer 1 interrupt\n", 0, 0, 0, 0, 0, 0);#endif	}    }#ifdef INCLUDE_TIMESTAMP/********************************************************************************* sysTimestampConnect - connect a routine to the stamp clock interrupt** This routine specifies the interrupt service routine to be called at each* timestamp clock rollover interrupt.  It is also called from clock error* interrupt service routine.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), sysTimestampEnable()*/STATUS sysTimestampConnect    (    FUNCPTR routine,    /* routine called at each system clock interrupt */    int arg             /* argument with which to call routine           */    )    {    sysTimestampRoutine	= routine;    sysTimestampArg	= arg;    sysTimestampConnected = TRUE;    return (OK);    }/********************************************************************************* sysTimestampInt - handle a timestamp clock interrupt** This routine handles a rollover timer interrupt.  It acknowledges the* interrupt and calls the routine installed by sysTimestampConnect().*/LOCAL void sysTimestampInt (void)    {    /* acknowledge the interrupt */    *ZCIO_CNTRL_ADRS = ZCIO_CT1CS;		/* C/T 3 Command and Status */    *ZCIO_CNTRL_ADRS = ZCIO_CS_CLIPIUS |	/* Clear IP and IUS */		       ZCIO_CS_GCB ;		/* Gate Command Bit */    /* call system clock service routine */    if (sysTimestampRoutine != NULL)	(*sysTimestampRoutine) (sysTimestampArg);    }/********************************************************************************* sysTimestampDisable - turn off timestamp clock without disabling interrupts** This routine disables timestamp clock(it actually stops the counting* sequence).** RETURNS: N/A** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable (void)    {    volatile UINT8 *cioCtl = ZCIO_CNTRL_ADRS;    FAST UINT8 temp;    if (sysTimestampRunning)        {	/* Stop counting  sequence */        *cioCtl = ZCIO_MCC;              /* Master Configuration Cntrl     */        temp = *cioCtl;                  /* get the configuration          */        *cioCtl = ZCIO_MCC;              /* Master Configuration Cntrl     */        *cioCtl = temp&(~ZCIO_MCC_CT1E); /* Disable the timer/count 1      */	*cioCtl = ZCIO_CT1CS;   	 /* C/T 1 Command and Status */	*cioCtl = ZCIO_CS_CLIPIUS;       /* CLear IP and IUS,  */	sysTimestampRunning = FALSE;        }    return (OK);    }/********************************************************************************* sysTimestampEnable - turn on Timestamp clock** This routine enables timer/count1 which used as Timestamp clock. It also* enables the interrupt for this timer/count.** RETURNS: OK** SEE ALSO: sysTimestampConnect(), sysTimestampDisable(),sysTimestampRateSet()*/STATUS sysTimestampEnable (void)    {    volatile UINT8 *cioCtl = ZCIO_CNTRL_ADRS;    UINT8 temp;    if (!sysTimestampRunning)	{        *cioCtl = ZCIO_MCC;              /* Master Configuration Cntrl     */        temp = *cioCtl;                  /* read the master configuration  */        *cioCtl = ZCIO_MCC;              /* Master Configuration Cntrl     */        *cioCtl = temp|ZCIO_MCC_CT1E;    /* enables the timer/count 1      */	/* set time constant, zero constant equal to 0x10000 */        *cioCtl = ZCIO_CT1TCMSB;             /* C/T 1 Time Const (MS Byte) */	*cioCtl = (UINT8) 0;	*cioCtl = ZCIO_CT1TCLSB;             /* C/T 1 Time Const (LS Byte) */	*cioCtl = (UINT8) 0;	/* clear and start timer */	*cioCtl = ZCIO_CT1CS;                /* C/T 1 Command and Status */	*cioCtl = ZCIO_CS_CLIPIUS;           /* Clear IP and IUS */	*cioCtl = ZCIO_CT1CS;                /* C/T 1 Command and Status */	*cioCtl = ZCIO_CS_SIE                /* Set Interrupt Enable */		| ZCIO_CS_GCB                /* Gate Command Bit */		| ZCIO_CS_TCB;               /* Trigger Command Bit */	sysTimestampRunning = TRUE;	}    return (OK);    }/********************************************************************************* sysTimestampPeriod - get the period of the timer** This routine returns the period of the timer in timestamp ticks** RETURNS: The period of the timer.** SEE ALSO: sysTimestampEnable(), sysTimestampFreq()*/UINT32 sysTimestampPeriod (void)    {    return (ZCIO_MAX_TIME_CNST);    }/********************************************************************************* sysTimestampFreq - get the Timestamp clock output frequence** This routine returns the output frequency of the timer, in timestamp ticks** RETURNS: The number of ticks per second of the timestamp clock.** SEE ALSO: sysTimestampEnable(), sysTimestampFreq()*/UINT32 sysTimestampFreq (void)    {    return (ZCIO_HZ);  /* the frequency */    } /********************************************************************************* sysTimestamp - get the current value of the timestamp counter** This routine returns the current value of the timestamp counter.** RETURNS: The current timestamp counter value.** SEE ALSO: sysTimestampEnable(), sysTimestampFreq()*/UINT32 sysTimestamp (void)    {    volatile UINT8 *cioCtl;    FAST UINT16 temp=0;    /* freeze and read current counter value */    cioCtl = ZCIO_CNTRL_ADRS;    *cioCtl = ZCIO_CT1CS;                /* C/T 1 Command and Status */    *cioCtl = ZCIO_CS_RCC |              /* freeze the counter value */              ZCIO_CS_GCB;               /* do not reset the Gate bit */     *cioCtl = ZCIO_CT1CCMSB;             /* C/T 1 Current Count (MS Byte) */    temp = *cioCtl;    temp <<= 8;                       *cioCtl = ZCIO_CT1CCLSB;            /* C/T 1 Current Count (LS Byte) */    temp |= *cioCtl;                   /* it also reset the ZCIO_CS_RCC bit*/    return (ZCIO_MAX_TIME_CNST-temp);  /* This is a count down timer */    }/********************************************************************************* sysTimestampLock - get the current value of the timestamp counter** This routine returns the current value of the timestamp counter.** RETURNS: The current timestamp counter value.** SEE ALSO: sysTimestampEnable(), sysTimestampFreq()*/UINT32 sysTimestampLock (void)    {    int lvl;    UINT32 result;    lvl = intLock ();    result = sysTimestamp ();    intUnlock (lvl);    return result;    }#endif

⌨️ 快捷键说明

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