📄 sh7700timer.c
字号:
connected = TRUE; } sysAuxClkRoutine = NULL; 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) { /* stop timer */#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR &= ~TSTR_STR1;#else sysTstrReg &= ~TSTR_STR1; *TMU_TSTR = sysTstrReg;#endif /* disable interrupts */ *TMU_TCR1 &= ~(TCR_UNF | TCR_UNIE); 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) { UINT32 tmp32; if (!sysAuxClkRunning) { /* stop timer */#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR &= ~TSTR_STR1;#else sysTstrReg &= ~TSTR_STR1; *TMU_TSTR = sysTstrReg;#endif /* disable interrupts */ *TMU_TCR1 &= ~(TCR_UNF | TCR_UNIE); /* load const register with the number of micro seconds */ tmp32 = (UINT32)(TICK_FREQ / sysAuxClkTicksPerSecond - 1); *TMU_TCOR1 = tmp32; *TMU_TCNT1 = tmp32; /* enable clock interrupt */ *TMU_TCR1 |= TCR_UNIE; /* start timer */#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR |= TSTR_STR1;#else sysTstrReg |= TSTR_STR1; *TMU_TSTR = sysTstrReg;#endif 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); } #ifdef INCLUDE_TIMESTAMP/********************************************************************************* sysTimestampInt - timestamp timer interrupt handler** This rountine handles the timestamp timer underflow interrupt. A user* routine is called, if one was connected by sysTimestampConnect().** RETURNS: N/A** SEE ALSO: sysTimestampConnect()*/LOCAL void sysTimestampInt (void) { volatile UINT16 stat; if ((stat = *TMU_TCR2) & TCR_UNF) { *TMU_TCR2 = (UINT16)(stat & (~TCR_UNF)); /* acknowledge int */ if (sysTimestampRoutine != NULL) (*sysTimestampRoutine) (sysTimestampArg); /* call user routine */ } }/********************************************************************************* 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 with which to call routine */ ) { static BOOL connected = FALSE; if (!connected) { /* connect sysTimestampInt to the appropriate interrupt vector */ if (intConnect (INUM_TO_IVEC(INUM_TMU2_UNDERFLOW), sysTimestampInt, 0) != OK) return (ERROR); /* set timer interrupt priority */#ifdef SYS_TMU2_INT_ENABLE SYS_TMU2_INT_ENABLE (INT_LVL_TSTAMP);#else /* for backward compatible BSPs */ *INTC_IPRA = (UINT16)((*INTC_IPRA & 0xff0f) | ((INT_LVL_TSTAMP & 0xf)<<4));#endif connected = TRUE; } sysTimestampRoutine = NULL; sysTimestampRoutine = routine; sysTimestampArg = arg; return (OK); }/********************************************************************************* sysTimestampEnable - initialize and enable the timestamp timer** This routine connects 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) { UINT32 tmp32 = sysTimestampPeriod (); if (sysTimestampRunning) {#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR &= ~TSTR_STR2; /* stop timer */#else sysTstrReg &= ~TSTR_STR2; *TMU_TSTR = sysTstrReg;#endif *TMU_TCOR2 = tmp32; /* reset auto-reload count */ *TMU_TCNT2 = tmp32; /* reset counter */#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR |= TSTR_STR2; /* restart timer */#else sysTstrReg |= TSTR_STR2; *TMU_TSTR = sysTstrReg;#endif return (OK); }#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR &= ~TSTR_STR2; /* stop timer */#else sysTstrReg &= ~TSTR_STR2; *TMU_TSTR = sysTstrReg;#endif *TMU_TCR2 = TCR_TPSC_VALUE; *TMU_TCOR2 = tmp32; /* reset auto-reload count */ *TMU_TCNT2 = tmp32; /* reset counter */ *TMU_TCR2 |= TCR_UNIE; /* enable underflow interrupt */#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR |= TSTR_STR2; /* start timer */#else sysTstrReg |= TSTR_STR2; *TMU_TSTR = sysTstrReg;#endif sysTimestampRunning = TRUE; 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 (sysTimestampRunning) { *TMU_TCR2 &= ~(TCR_ICPE1 | TCR_ICPE0 | TCR_UNIE); /* disable ints */#if (TMU_BUG_FIXED == TRUE) *TMU_TSTR &= ~TSTR_STR2; /* stop timer */#else sysTstrReg &= ~TSTR_STR2; *TMU_TSTR = sysTstrReg;#endif *TMU_TCR2 &= ~(TCR_ICPF | TCR_UNF); /* clear pending ints */ sysTimestampRunning = FALSE; } 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 (UINT32)(0xffffffff); /* highest period -> freerunning */ }/********************************************************************************* 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) { return (UINT32) TICK_FREQ; }/******************************************************************************** * 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) { return (sysTimestampPeriod() - *TMU_TCNT2); /* 32bit down counter */ }/********************************************************************************* 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) { return (sysTimestampPeriod() - *TMU_TCNT2); /* 32bit down counter */ }#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -