📄 at91timer.c
字号:
/* Connect and enable interrupt. */ intConnect(INT_VEC_TC0, (VOIDFUNCPTR)sysAuxClkInt, 0); intEnable(INT_LVL_TC4); sysAuxClkConnectFirstTime = FALSE; } sysAuxClkRoutine = routine; sysAuxClkArg = arg; 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) { /* Disable timer. */ /* *S3C2510_TMOD &= ~S3C2510_TMOD_TE4;*/ AT91PS_TC tc = (AT91PS_TC) AT91C_BASE_TC0 ; tc->TC_CCR |= AT91C_TC_CLKDIS ; sysAuxClkRunning = FALSE; }}/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts. The timer is used in* "reference mode" i.e. a value is programmed into the reference register and an* interrupt occurs when the timer reaches that value. ** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable(void){ if (!sysAuxClkRunning) { /* Calculate the timer interval. */ /* *S3C2510_TDATA4 = SPLL_FREQ * 1000 * 1000 / sysAuxClkTicksPerSecond - 1;*/ /* Enable timer. */ /* *S3C2510_TMOD |= S3C2510_TMOD_TE4;*/ AT91PS_TC tc = (AT91PS_TC) AT91C_BASE_TC0 ; tc->TC_CCR |= AT91C_TC_CLKEN ; 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 < SYS_CLK_RATE_MIN) || (ticksPerSecond > SYS_CLK_RATE_MAX)) { return ERROR; } sysAuxClkTicksPerSecond = ticksPerSecond; if (sysAuxClkRunning) { sysAuxClkDisable(); sysAuxClkEnable(); } return OK;}#ifdef INCLUDE_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){ /* Clear interrupt. */ *S3C2510_TIC |= S3C2510_TIC_T3; /* Call timestamp timer service routine. */ if (sysTimestampRoutine && sysTimestampRunning) { (*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 to timestamp timer interrupt routine */ ){ if (sysTimestampConnectFirstTime) { /* Enable peripheral clock. */ *S3C2510_PCLKDIS &= ~S3C2510_PCLKDIS_TIMER3; /* Interval mode. */ *S3C2510_TMOD &= ~S3C2510_TMOD_TMD3; /* Connect and enable interrupt. */ intConnect(INT_VEC_TIMER3, (VOIDFUNCPTR)sysTimestampInt, 0); intEnable(INT_LVL_TIMER3); sysTimestampConnectFirstTime = FALSE; } sysTimestampRoutine = routine; sysTimestampArg = arg; return OK;}/********************************************************************************* sysTimestampDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: OK, always** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable(void){ if (sysTimestampRunning) { /* Disable timer. */ *S3C2510_TMOD &= ~S3C2510_TMOD_TE3; sysTimestampRunning = FALSE; } return OK;}/********************************************************************************* sysTimestampEnable - initialize and enable the timestamp timer** This routine connects interrupts, and enables the timer device** RETURNS: TRUE always*/STATUS sysTimestampEnable(void){ if (!sysTimestampRunning) { /* Calculate the timer interval. */ *S3C2510_TDATA3 = SPLL_FREQ * 1000 * 1000 / DEF_SYS_TIMESTAMP_TICKS - 1; /* Enable timer. */ *S3C2510_TMOD |= S3C2510_TMOD_TE3; sysTimestampRunning = TRUE; } 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){ /* The period of the timestamp depends on the clock rate of the on-chip timer. */ return (*S3C2510_TDATA3);}/********************************************************************************* 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){ return (SPLL_FREQ * 1000 * 1000);}/********************************************************************************* 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){ return (*S3C2510_TCNT3);}/********************************************************************************* 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){ return (*S3C2510_TCNT3);}#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -