📄 m5206timer.c
字号:
sysAuxClkRoutine = routine; sysAuxClkArg = arg; sysAuxClkConnected = TRUE; return (OK); }/******************************************************************************* sysAuxClkDisable - turn off aux clock interrupts** This routine disables auxilliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void) { if (sysAuxClkRunning && sysAuxClkConnected) {#if (AUX_CLK_TIMER == 1) *M5206_SIM_IMR(SIM_BASE) |= M5206_IMR_TIMER1;#else /* (AUX_CLK_TIMER == 1) */ *M5206_SIM_IMR(SIM_BASE) |= M5206_IMR_TIMER2;#endif /* (AUX_CLK_TIMER == 1) */ /* Clear CLK1-CLK0 to stop timer. */ *M5206_TIMER_TMR(SIM_BASE, AUX_CLK_TIMER) = 0x00; sysAuxClkRunning = FALSE; } }/******************************************************************************* sysAuxClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void) { if (!sysAuxClkRunning && sysAuxClkConnected) { /* Disable timer */ *M5206_TIMER_TMR(SIM_BASE, AUX_CLK_TIMER) = 0x00; /* Reset timer count */ *M5206_TIMER_TCN(SIM_BASE, AUX_CLK_TIMER) = 0x00; sysAuxClkPrescale = (MASTER_CLOCK / sysAuxClkTicksPerSecond) >> 16; sysAuxClkCount = ((MASTER_CLOCK / (sysAuxClkPrescale + 1)) / sysAuxClkTicksPerSecond); /* Set reference register */ *M5206_TIMER_TRR(SIM_BASE, AUX_CLK_TIMER) = sysAuxClkCount; /* Start timer */ *M5206_TIMER_TMR(SIM_BASE, AUX_CLK_TIMER) = 0x1b | (sysAuxClkPrescale<<8); #if (AUX_CLK_TIMER == 1) *M5206_SIM_IMR(SIM_BASE) &= ~M5206_IMR_TIMER1;#else /* (AUX_CLK_TIMER == 1) */ *M5206_SIM_IMR(SIM_BASE) &= ~M5206_IMR_TIMER2;#endif /* (AUX_CLK_TIMER == 1) */ sysAuxClkRunning = TRUE; } }/******************************************************************************* sysAuxClkRateGet - get the system clock rate** This routine returns the system clock rate.** RETURNS: The number of ticks per second of the system clock.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()*/int sysAuxClkRateGet (void) { return (sysAuxClkTicksPerSecond); }/******************************************************************************* sysAuxClkRateSet - set the system clock rate** This routine sets the interrupt rate of the system clock.* It is called by usrRoot() in usrConfig.c.** 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 */ ) { UINT count, prescale; if (ticksPerSecond > AUX_CLK_RATE_MAX || ticksPerSecond < AUX_CLK_RATE_MIN) return (ERROR); prescale = (MASTER_CLOCK / ticksPerSecond) >> 16; if (prescale & ~0x00ff) return (ERROR); count = (MASTER_CLOCK / (prescale + 1)) / ticksPerSecond; if (count & 0xffff0000) return (ERROR); sysAuxClkTicksPerSecond = ticksPerSecond; if (sysAuxClkRunning) { sysAuxClkDisable (); sysAuxClkEnable (); } return (OK); }#endif /* INCLUDE_M5206_AUX_CLK */#ifdef INCLUDE_M5206_TIMESTAMP/**************************************************************************** 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 */ ) { return (ERROR); }/**************************************************************************** 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.** Set the rate of the timestamp timer input clock explicitly within the * BSP, in the sysHwInit() routine. This routine does not initialize * the timer clock rate.** RETURNS: OK, or ERROR if the timestamp timer cannot be enabled.*/STATUS sysTimestampEnable(void) { if (sysTimestampRunning) return (OK); sysTimestampRunning = TRUE; sysClkEnable (); /* ensure the system clock is running */ return (OK); }/**************************************************************************** sysTimestampDisable - disable the timestamp timer** This routine disables the timestamp timer. Interrupts are not disabled.* However, the tick counter will not increment after the timestamp timer* is disabled, ensuring that interrupts are no longer generated.* routine merely resets the timer counter.** RETURNS: OK, or ERROR if the timestamp timer cannot be disabled.*/STATUS sysTimestampDisable (void) { sysTimestampRunning = FALSE; return (ERROR); }/**************************************************************************** sysTimestampPeriod - get the timestamp timer period** This routine returns the period of the timer in timestamp 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 timer in timestamp ticks.*/UINT32 sysTimestampPeriod (void) { /* Return the system clock period in timestamp ticks */ return (sysTimestampFreq () / sysClkRateGet ()); }/**************************************************************************** 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 in the * BSP, in the sysHwInit() routine.** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq (void) { UINT32 prescale; /* * Return the timestamp tick output frequency here. * This value can be determined from the following equation: * timerFreq = clock input frequency / prescaler * * When possible, read the clock input frequency and prescaler values * directly from chip registers. */ prescale = ((*M5206_TIMER_TMR(SIM_BASE, SYS_CLK_TIMER) >> 8) + 1); return (MASTER_CLOCK / prescale); }/**************************************************************************** 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().** Call this routine with interrupts locked. If interrupts are * not already locked, use sysTimestampLock() instead.** RETURNS: The current timestamp timer tick count.* SEE ALSO: sysTimestampLock()*/UINT32 sysTimestamp (void) { return (*M5206_TIMER_TCN(SIM_BASE, SYS_CLK_TIMER)); }/**************************************************************************** sysTimestampLock - lock interrupts for reading the timer** 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().** Call this routine with interrupts locked. If interrupts are * not already locked, use sysTimestampLock() instead.** RETURNS: The current timestamp timer tick count.* SEE ALSO: sysTimestampLock()*/UINT32 sysTimestampLock (void) { int lockKey; UINT32 value; lockKey = intLock(); value = sysTimestamp (); intUnlock (lockKey); return (value); }#endif /* INCLUDE_M5206_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -