📄 pcctimer.c
字号:
} }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void) { if ((!sysAuxClkRunning) && (!sysTimestampRunning)) { /* preload the preload register */ *TIC_2_PRELOAD = (short) (65536 - (TICK_FREQ / auxClkTicksPerSecond)); /* enable the clock interrupt */ *TIC_2_CSR = TIC_2_CSR_STOP; /* load counter from preload reg */ /* clear overflow counter, enable & start counter */ *TIC_2_CSR = TIC_2_CSR_CLR_OVF | TIC_2_CSR_ENABLE; *TIC_2_INT_CTL = TIC_2_INT_CTL_CLEAR | TIC_2_INT_CTL_ENABLE | INT_LVL_TIC_2; /* reset&enable int, set level */ 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 (auxClkTicksPerSecond); }/********************************************************************************* 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 (sysTimestampRunning) return (ERROR); if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) return (ERROR); auxClkTicksPerSecond = ticksPerSecond; if (sysAuxClkRunning) { sysAuxClkDisable (); sysAuxClkEnable (); } return (OK); }#ifdef INCLUDE_TIMESTAMP/********************************************************************************* sysTimestampConnect - connect a user routine to the timestamp timer interrupt** This routine usually specifies the user interrupt routine to be called at* each timestamp timer interrupt. In this case, however, the timestamp timer* interrupt is not used since the timer is reset by the system clock before* an interrupt can be generated.** 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 */ ) { return (ERROR); }/********************************************************************************* sysTimestampEnable - initialize and enable the timestamp timer** This routine disables 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 the timestamp timer cannot be enabled.*/STATUS sysTimestampEnable (void) { if (sysTimestampRunning) { *TIC_2_CSR = TIC_2_CSR_STOP; /* clear the counter */ *TIC_2_CSR = TIC_2_CSR_ENABLE; /* enable the timer */ return (OK); } if ((sysAuxClkRunning) || (!sysClkRunning)) return (ERROR); sysTimestampRunning = TRUE; /* * Disable the timer interrupt. The timestamp timer is reset by the * system clock before rollover occurs. */ *TIC_2_INT_CTL = TIC_2_INT_CTL_DISABLE; *TIC_2_PRELOAD = 0x0; /* highest period -> freerunning */ *TIC_2_CSR = TIC_2_CSR_STOP; /* clear the counter */ *TIC_2_CSR = TIC_2_CSR_ENABLE; /* enable the timer */ 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 the timestamp timer cannot be disabled.*/STATUS sysTimestampDisable (void) { if (sysAuxClkRunning) return (ERROR); if (sysTimestampRunning) { sysTimestampRunning = FALSE; *TIC_2_CSR = TIC_2_CSR_DISABLE; /* disable the timer */ } 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) { return (TICK_FREQ / sysClkTicksPerSecond); }/********************************************************************************* sysTimestampFreq - get the timestamp timer clock frequency** This routine returns the frequency of the timer clock, in ticks per second.* The rate of the timestamp timer should be set explicitly within the BSP,* in the sysHwInit() routine.** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq (void) { UINT32 timerFreq; timerFreq = TICK_FREQ; return (timerFreq); }/********************************************************************************* 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 tick = 0; register short * pCounter; if (sysTimestampRunning) { pCounter = TIC_2_COUNTER; *TIC_2_CSR = TIC_2_CSR_DISABLE; /* disable the timer */ tick = *pCounter; /* read tick counter value */ *TIC_2_CSR = TIC_2_CSR_ENABLE; /* enable the timer */ tick &= 0x0000ffff; } return (tick); }/********************************************************************************* 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 tick = 0; register short * pCounter; int lockKey; if (sysTimestampRunning) { pCounter = TIC_2_COUNTER; lockKey = intLock (); /* LOCK INTERRUPTS */ *TIC_2_CSR = TIC_2_CSR_DISABLE; /* disable the timer */ tick = *pCounter; /* read tick counter value */ *TIC_2_CSR = TIC_2_CSR_ENABLE; /* enable the timer */ intUnlock (lockKey); /* UNLOCK INTERRUPTS */ tick &= 0x0000ffff; } return (tick); }#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -