📄 s3c2410timer.c
字号:
*/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;}/********************************************************************************* 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 interrupt: any write to Clear Register clears interrupt */ /*AMBA_TIMER_WRITE (AUX_TIMER_CLEAR (AMBA_TIMER_BASE), 0);*/ /* If any routine attached via sysAuxClkConnect(), call it */ 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 also connects the clock error interrupt* service routine.** 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 = NULL; /* ensure routine not called with wrong arg */ sysAuxClkArg = arg; if (routine == NULL) return OK;#if ((CPU_FAMILY == ARM) && ARM_THUMB) /* set b0 so that sysAuxClkConnect() can be used from shell */ sysAuxClkRoutine = (FUNCPTR)((UINT32)routine | 1);#else sysAuxClkRoutine = routine;#endif /* CPU_FAMILY == ARM */ 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 itself. Might as well leave it configured for * Periodic mode, divided by 16. */ /*AMBA_TIMER_WRITE( AUX_TIMER_CTRL (AMBA_TIMER_BASE), AMBA_TIMER_AUX_TC_DISABLE);*/ /* Disable the timer interrupt in the Interrupt Controller */ /*AMBA_TIMER_INT_DISABLE (AUX_TIMER_INT_LVL);*/ rTCON = ((rTCON&0xfff0ffff)|0xa0000); rINTMSK |= BIT_TIMER3; sysAuxClkRunning = FALSE; }}/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable()*/void sysAuxClkEnable (void){ if (!sysAuxClkRunning) { /* Set up in periodic mode, divide clock input by 16, enable timer */ /*AMBA_TIMER_WRITE( AUX_TIMER_CTRL (AMBA_TIMER_BASE), AMBA_TIMER_AUX_TC_ENABLE);*/ /* * Calculate the timer value * Note that it may take some ticks to reload the counter * so counter value = (clock rate / sysAuxClkTicksPerSecond) - num_ticks */ /*tc = (AUX_TIMER_CLK / sysAuxClkTicksPerSecond) - AMBA_RELOAD_TICKS;*/ /* Load Timer Reload value into Timer registers */ /*AMBA_TIMER_WRITE (AUX_TIMER_LOAD (AMBA_TIMER_BASE), tc);*/ /* enable clock interrupt in interrupt controller */ /*AMBA_TIMER_INT_ENABLE (AUX_TIMER_INT_LVL);*/ rTCNTB3 = ( rTCNTB3 & ~(0xffff) ) | ((PCLK/(TIMER_PRESCALER+1)/TIMER_DIVIDER)/sysAuxClkTicksPerSecond); rTCON = ((rTCON&0xfff0ffff)|0xa0000); rTCON = ((rTCON&0xfff0ffff)|0X90000); rINTMSK &= (~BIT_TIMER3); 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 unilaterally, but if the* auxiliary clock is currently enabled, the clock is disabled and then* re-enabled with the new rate.** RETURNS: OK or ERROR.** 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;}#ifdef INCLUDE_TIMESTAMP/********************************************************************************* 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: ERROR, always.*/STATUS sysTimestampConnect(FUNCPTR routine, /* routine called at each timestamp timer interrupt */ int arg /* argument with which to call routine */){ return ERROR;}/********************************************************************************* 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){ if (sysTimestampRunning) { return OK; } if (!sysClkRunning) /* timestamp timer is derived from the sysClk */ return ERROR; 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){ if (sysTimestampRunning) 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){ /* * The period of the timestamp depends on the clock rate of the system * clock. */ return ((UINT32)(SYS_TIMER_CLK / sysClkTicksPerSecond));}/********************************************************************************* 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.** NOTE: Because the system clock serves as the timestamp timer,* the system clock frequency is also the timestamp timer frequency.** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq (void){ return ((UINT32)SYS_TIMER_CLK);}/********************************************************************************* 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){ /*AMBA_TIMER_READ (SYS_TIMER_VALUE (AMBA_TIMER_BASE), t);*/ return (sysTimestampPeriod() );}/********************************************************************************* 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){ /*AMBA_TIMER_READ (SYS_TIMER_VALUE (AMBA_TIMER_BASE), t);*/ return (sysTimestampPeriod() );}#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -