📄 m85xxtimer.c
字号:
* sysWdtConnect - connect a routine to the watchdog interrupt** This routine specifies the interrupt service routine to be called at* each watchdog interrupt. It does not enable watchdog interrupts.** RETURNS: OK, or ERROR if the routine cannot be connected to the* watchdog* interrupt.** SEE ALSO: excIntCrtConnect(), sysWdtEnable()*/STATUS sysWdtConnect ( FUNCPTR routine, /* routine called at each watchdog interrupt */ int arg /* argument with which to call routine */ ) { /* connect the routine to the WDT vector */ excIntCrtConnect ((VOIDFUNCPTR *) _EXC_OFF_WD, (VOIDFUNCPTR) sysWdtInt); sysWdtRoutine = routine; sysWdtArg = arg; return (OK); }/***************************************************************************** sysWdtEnable - turn on watchdog interrupts** This routine enables watchdog interrupts.** RETURNS: N/A** SEE ALSO: sysWdtConnect(), sysWdtDisable(), sysWdtRateSet()*/void sysWdtEnable (void) { if (!sysWdtRunning) { /* clear the pending WDT interrupt */ vxTsrSet (TSR_WIS); /* program TCR with the WDT period */ vxTcrSet ((vxTcrGet() & ~(TCR_WP|TCR_WP_EXT)) | wdtPeriodMask); /* Enable the WDT interrupt */ vxTcrSet (vxTcrGet() | TCR_WIE); /* Enable critical interrupt */ vxMsrSet (vxMsrGet() | _PPC_MSR_CE); /* set the running flag */ sysWdtRunning = TRUE; } }/***************************************************************************** sysWdtDisable - turn off watchdog interrupts** This routine disables watchdog interrupts. This routine does not* disable critical interrupts.** RETURNS: N/A** SEE ALSO: sysWdtEnable()*/void sysWdtDisable (void) { if (sysWdtRunning) { /* disable the WDT interrupt */ vxTcrSet (vxTcrGet() & ~ (TCR_WIE)); /* clear the pending WDT interrupt */ vxTsrSet (TSR_WIS); /* reset the running flag */ sysWdtRunning = FALSE; } }/***************************************************************************** sysWdtRateGet - get the watchdog timer rate** This routine returns the interrupt rate of the watchdog timer.** RETURNS: The number of watchdog interrupts per second.** SEE ALSO: sysWdtEnable(), sysWdtRateSet()*/int sysWdtRateGet (void) { return (sysWdtTicksPerSecond); }/***************************************************************************** sysWdtRateSet - set the watchdog timer rate** This routine sets the interrupt rate of the watchdog timer. It does* not enable watchdog interrupts.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot* be set.** SEE ALSO: sysWdtEnable(), sysWdtRateGet()*/STATUS sysWdtRateSet ( int ticksPerSecond /* number of clock interrupts per second */ ) { int ix; int jx = 0; unsigned long long wdtPeriod; /* * compute the WDT period. * only 4 values are possible (cf wdtTable[]). The closest value to * <ticksPerSecond> is being used. */ if ((ticksPerSecond < (int) WDT_RATE_MIN) || (ticksPerSecond > (int) WDT_RATE_MAX)) return (ERROR); wdtPeriod = (sysTimerClkFreq >> 1) / ticksPerSecond; /* get the closest value to ticksPerSecond supported by the WDT */ for (ix = 0; ix < (int) NELEMENTS (wdtTable); ix++) { if (wdtPeriod <= wdtTable [ix].wdtPeriod) { if (ix != 0) if ( wdtPeriod < ((wdtTable [ix].wdtPeriod + wdtTable [ix-1].wdtPeriod)/2)) jx = ix-1; else jx = ix; else jx = ix; break; } if (ix == NELEMENTS (wdtTable) - 1) jx = ix; } wdtPeriod = wdtTable [jx].wdtPeriod; /* actual period of the WDT */ wdtPeriodMask = wdtTable [jx].fpMask; /* Mask to program TCR with */ /* save the clock speed */ sysWdtTicksPerSecond = (sysTimerClkFreq >> 1) / wdtPeriod; 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. In this case, however, the timestamp timer* interrupt is not used since the on-chip timer is also used by the* system clock.** 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 a timestamp timer** This routine disables the timestamp timer interrupt and initializes* the counter registers. If the timestamp timer is already running, this* routine merely resets the timer counter.** This routine does not initialize the timer rate. The rate of the* timestamp timer should be set explicitly in the BSP by sysHwInit().** RETURNS: OK, or ERROR if the timestamp timer cannot be enabled.*/STATUS sysTimestampEnable (void) { if (sysTimestampRunning) { return (OK); } if (!sysClkRunning) return (ERROR); sysTimestampRunning = TRUE; return (OK); }/********************************************************************************* sysTimestampDisable - disable a timestamp timer** This routine disables the timestamp timer. Interrupts are not* disabled; however, because the tick counter does not increment after* the timestamp timer is disabled, interrupts no longer are generated.** RETURNS: OK, or ERROR if the timestamp timer cannot be disabled.*/STATUS sysTimestampDisable (void) { if (sysTimestampRunning) sysTimestampRunning = FALSE; return (OK); }/********************************************************************************* sysTimestampPeriod - get a timestamp timer period** This routine specifies 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 (ie the Decrementer reload value). */ return (decCountVal); }/********************************************************************************* sysTimestampFreq - get a timestamp timer clock frequency** This routine specifies the frequency of the timer clock, in ticks per* second. The rate of the timestamp timer should be set explicitly in* the BSP by sysHwInit().** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq (void) { return (sysTimerClkFreq); }/********************************************************************************* 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 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 (decCountVal - (UINT32) vxDecGet()); }/***************************************************************************** sysTimestampLock - lock an interrupt and get a timestamp timer tick count** This routine locks interrupts when stop 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 by the return* of sysTimestampFreq().** If interrupts are already locked, sysTimestamp() should be used* instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestamp()*/UINT32 sysTimestampLock (void) { UINT32 currentDecValue; int oldLevel; oldLevel = intLock (); /* LOCK INTERRUPT */ currentDecValue = vxDecGet(); intUnlock (oldLevel); /* UNLOCK INTERRUPT */ return (decCountVal - currentDecValue); }#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -