📄 sa1501timer.c
字号:
* 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) { /* If any routine is 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 ((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: set limit register to 0 */ SA1501_TIMER_WRITE (AUX_TIMER_LIMIT (SA1501_TIMER_BASE), 0); /* Disable the timer interrupt in the Interrupt Controller */ SA1501_TIMER_INT_DISABLE (AUX_TIMER_INT_LVL); sysAuxClkRunning = FALSE; } }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable()*/void sysAuxClkEnable (void) { UINT32 tl; if (!sysAuxClkRunning) { /* * Calculate the timer limit value: * counter limit value = (clock rate / sysAuxClkTicksPerSecond) */ tl = (AUX_TIMER_CLK / sysAuxClkTicksPerSecond); /* Load Limit value into Timer registers */ SA1501_TIMER_WRITE (AUX_TIMER_LIMIT (SA1501_TIMER_BASE), tl); /* reset timer value to zero */ SA1501_TIMER_WRITE (AUX_TIMER_RESET (SA1501_TIMER_BASE), 0); /* enable clock interrupt in interrupt controller */ SA1501_TIMER_INT_ENABLE (AUX_TIMER_INT_LVL); 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. 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) { UINT32 t; SA1501_TIMER_READ (SYS_TIMER_VALUE (SA1501_TIMER_BASE), t);#if defined (SA1501_TIMER_VALUE_MASK) t &= SA1501_TIMER_VALUE_MASK;#endif return t; }/********************************************************************************* 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) { UINT32 t; SA1501_TIMER_READ (SYS_TIMER_VALUE (SA1501_TIMER_BASE), t);#if defined (SA1501_TIMER_VALUE_MASK) t &= SA1501_TIMER_VALUE_MASK;#endif return t; }#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -