📄 ppcz8536timer.c
字号:
void sysClkEnable (void) { volatile UINT8 *cioCtl; ULONG tc; /* time constant */ int lock; if (!sysClkRunning) { cioCtl = ZCIO_CNTRL_ADRS; /* set time constant */ tc = ZCIO_HZ / sysClkTicksPerSecond; lock = intLock (); *cioCtl = ZCIO_CT3TCMSB; /* C/T 3 Time Const (MS Byte) */ *cioCtl = (UINT8) MSB(tc); *cioCtl = ZCIO_CT3TCLSB; /* C/T 3 Time Const (LS Byte) */ *cioCtl = (UINT8) LSB(tc); /* clear and start timer */ *cioCtl = ZCIO_CT3CS; /* C/T 3 Command and Status */ *cioCtl = ZCIO_CS_CLIPIUS; /* Clear IP and IUS */ *cioCtl = ZCIO_CT3CS; /* C/T 3 Command and Status */ *cioCtl = ZCIO_CS_SIE /* Set Interrupt Enable */ | ZCIO_CS_GCB /* Gate Command Bit */ | ZCIO_CS_TCB; /* Trigger Command Bit */ intUnlock (lock); sysClkRunning = TRUE; } } /******************************************************************************* sysClkRateGet - get the system clock rate** This routine returns the system clock rate.** RETURNS: The number of ticks per second of the system clock.** SEE ALSO: sysClkEnable(), sysClkRateSet()*/int sysClkRateGet (void) { return (sysClkTicksPerSecond); } /******************************************************************************** sysClkRateSet - set the system clock rate** This routine sets the interrupt rate of the system clock. It is called by* usrRoot() in usrConfig.c.** NOTE: The valid range for the system clock is 38 to 10000* ticks per second.** RETURNS: OK, or ERROR if the tick rate is invalid.** SEE ALSO: sysClkEnable(), sysClkRateGet()*/ STATUS sysClkRateSet ( int ticksPerSecond /* number of clock interrupts per second */ ) { if (ticksPerSecond < SYS_CLK_RATE_MIN || ticksPerSecond > SYS_CLK_RATE_MAX) return (ERROR); sysClkTicksPerSecond = ticksPerSecond; if (sysClkRunning) { sysClkDisable (); sysClkEnable (); } return (OK); }/******************************************************************************** sysClkInt - handle a system clock interrupt** This routine handles a system clock interrupt. It acknowledges the* interrupt and calls the routine installed by sysClkConnect().*/ LOCAL void sysClkInt (void) { /* interrupt acknowledged - just call other attached routine */ if (sysClkRoutine != NULL) (*sysClkRoutine) (sysClkArg); /* call system clock service routine */ } #endif /* INCLUDE_Z8536_CLK */#ifdef INCLUDE_Z8536_AUXCLK /******************************************************************************** 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 with which to call routine */ ) { sysAuxClkRoutine = routine; sysAuxClkArg = arg; sysAuxClkConnected = TRUE; return (OK); } /******************************************************************************** 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*/ LOCAL void sysAuxClkInt (void) { /* acknowledge the interrupt */ /* call auxiliary clock service routine */ if (sysAuxClkRoutine != NULL) (*sysAuxClkRoutine) (sysAuxClkArg); } /******************************************************************************** sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/ void sysAuxClkDisable (void) { volatile UINT8 *cioCtl; int lock; if (sysAuxClkRunning) { cioCtl = ZCIO_CNTRL_ADRS; /* disable interrupts */ lock = intLock (); *cioCtl = ZCIO_CT2CS; /* C/T 2 Command and Status */ *cioCtl = ZCIO_CS_CLIE; /* Clear Interrupt Enable */ intUnlock (lock); 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) { volatile UINT8 *cioCtl; ULONG tc; /* time constant */ int lock; if (!sysAuxClkRunning) { cioCtl = ZCIO_CNTRL_ADRS; /* set time constant */ tc = ZCIO_HZ / sysAuxClkTicksPerSecond; lock = intLock (); *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 */ intUnlock (lock); 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_Z8536_AUXCLK */ #ifdef INCLUDE_Z8536_TIMESTAMP/**************************************************************************** sysTimestampInt - timestamp timer interrupt handler** This routine handles the timestamp timer interrupt. A user routine is* called, if one was connected by sysTimestampConnect().** RETURNS: N/A** SEE ALSO: sysTimestampConnect()*/LOCAL void sysTimestampInt (void) { if (sysTimestampRoutine != NULL) /* call user-connected routine */ (*sysTimestampRoutine) (sysTimestampArg); }/**************************************************************************** sysTimestampConnect - connect a user routine to a timestamp timer interrupt** This routine specifies the user interrupt routine to be called at each* timestamp timer interrupt. ** RETURNS: OK, always.*/STATUS sysTimestampConnect ( FUNCPTR routine, /* routine called at each timestamp timer interrupt */ int arg /* argument with which to call routine */ ) { sysTimestampConnected = TRUE; sysTimestampRoutine = routine; sysTimestampArg = arg; return (OK); }/**************************************************************************** sysTimestampEnable - enable a timestamp timer interrupt** This routine enables timestamp timer interrupts and resets the counter.** RETURNS: OK, always.** SEE ALSO: sysTimestampDisable()*/STATUS sysTimestampEnable(void) { volatile UINT8 *cioCtl; ULONG tc; /* time constant */ if (!sysTimestampRunning) { int oldLevel; cioCtl = ZCIO_CNTRL_ADRS; /* set time constant */ tc = ZCIO_HZ / sysTimestampTicksPerSecond; oldLevel = intLock (); *cioCtl = ZCIO_CT1TCMSB; /* C/T 1 Time Const (MS Byte) */ *cioCtl = (UINT8) MSB(tc); *cioCtl = ZCIO_CT1TCLSB; /* C/T 1 Time Const (LS Byte) */ *cioCtl = (UINT8) LSB(tc); /* 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 */ intUnlock (oldLevel); sysTimestampRunning = TRUE; } return (OK); }/**************************************************************************** sysTimestampDisable - disable a timestamp timer interrupt** This routine disables timestamp timer interrupts.** RETURNS: OK, always.** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable (void) { volatile UINT8 *cioCtl; if (sysTimestampRunning) { int oldLevel; cioCtl = ZCIO_CNTRL_ADRS; oldLevel = intLock (); *cioCtl = ZCIO_CT1CS; /* C/T 1 Command and Status */ *cioCtl = ZCIO_CS_CLIE; intUnlock (oldLevel); sysTimestampRunning = FALSE; } return (OK); }/**************************************************************************** sysTimestampPeriod - get the period of a timestamp timer ** This routine gets the period of the timestamp timer, in 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 timestamp timer in counter ticks.*/UINT32 sysTimestampPeriod (void) { /* * Return the timestamp timer period here. * The highest period (maximum terminal count) should be used so * that rollover interrupts are kept to a minimum. */ return (ZCIO_HZ / sysTimestampTicksPerSecond); }/**************************************************************************** sysTimestampFreq - get a timestamp timer clock frequency** This routine gets the frequency of the timer clock, in ticks per * second. The rate of the timestamp timer is set explicitly by the * hardware and typically cannot be altered.** 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. */ timerFreq = (ZCIO_HZ); return (timerFreq); }/**************************************************************************** sysTimestamp - get a 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 it by the return of* sysTimestampFreq().** This routine should be called with interrupts locked. If interrupts are* not locked, sysTimestampLock() should be used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestampFreq(), sysTimestampLock()*/UINT32 sysTimestamp (void) { volatile UINT8 *cioCtl; volatile UINT32 countValue; volatile UINT8 countValueMSB; volatile UINT8 countValueLSB; /* Read the timer counter register */ cioCtl = ZCIO_CNTRL_ADRS; *cioCtl = ZCIO_CT1CCMSB; /* C/T 1 Current Count MSB */ CACHE_PIPE_FLUSH(); countValueMSB = *cioCtl; /* Current Count MSB */ *cioCtl = ZCIO_CT1CCLSB; /* C/T 1 Current Count LSB */ CACHE_PIPE_FLUSH(); countValueLSB = *cioCtl; /* Current Count MSB */ countValue = (countValueMSB << 8); countValue |= (countValueLSB); /* return the timestamp timer tick count here */ return (countValue); }/**************************************************************************** sysTimestampLock - lock interrupts and get the timestamp timer tick count** This routine locks interrupts when the tick counter must be stopped * in order to read it or when two independent counters must be read. * It then returns the current value of the timestamp timer tick* counter.* * The tick count can be converted to seconds by dividing it by the return of* sysTimestampFreq().** If interrupts are already locked, sysTimestamp() should be* used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestampFreq(), sysTimestamp()*/UINT32 sysTimestampLock (void) { int lockKey; volatile UINT8 *cioCtl; volatile UINT32 countValue; volatile UINT8 countValueMSB; volatile UINT8 countValueLSB; lockKey = intLock (); /* Read the timer counter register */ cioCtl = ZCIO_CNTRL_ADRS; *cioCtl = ZCIO_CT1CCMSB; /* C/T 1 Current Count MSB */ CACHE_PIPE_FLUSH(); countValueMSB = *cioCtl; /* Current Count MSB */ *cioCtl = ZCIO_CT1CCLSB; /* C/T 1 Current Count LSB */ CACHE_PIPE_FLUSH(); countValueLSB = *cioCtl; /* Current Count MSB */ countValue = (((countValueMSB) << 8) | countValueLSB); intUnlock (lockKey); /* return the timestamp timer tick count here */ return (countValue); }#endif /* INCLUDE_Z8536_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -