📄 ppc405timer.c
字号:
** 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 */ ) { int ix; int jx = 0; UINT32 fitPeriod; /* * compute the FIT period. * only 4 values are possible (cf fitTable[]). The closest value to * <ticksPerSecond> is being used. */ if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) return (ERROR); fitPeriod = sysTimerClkFreq / ticksPerSecond; /* get the closest value to ticksPerSecond supported by the FIT */ for (ix = 0; ix < NELEMENTS (fitTable); ix++) { if (fitPeriod <= fitTable [ix].fitPeriod) { if (ix == 0) jx = 0; else { if ( (fitPeriod/fitTable [ix-1].fitPeriod ) < ( fitTable [ix].fitPeriod/fitPeriod) ) jx=ix-1; else jx=ix; } break; } if (ix == NELEMENTS (fitTable) - 1) jx = ix; } fitPeriod = fitTable [jx].fitPeriod; /* actual period of the FIT */ fitPeriodMask = fitTable [jx].fpMask; /* Mask to program TCR with */ /* save the clock speed */ sysAuxClkTicksPerSecond = sysTimerClkFreq / fitPeriod; return (OK); }#endif /* INCLUDE_AUX_CLK *//************************************************************************* sysWdtInt - watchdog interrupt handler.** This routine handles the watchdog interrupt on the PowerPC 405* architecture. It is attached to the watchdog timer vector by the routine* sysWdtConnect().** RETURNS : N/A*/LOCAL void sysWdtInt (void) { /* acknowledge WDT interrupt */ vxTsrSet (_PPC403_TSR_WIS); /* execute the watchdog clock routine */ if (sysWdtRoutine != NULL) (*(FUNCPTR) sysWdtRoutine) (sysWdtArg); }/************************************************************************* 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 (_PPC403_TSR_WIS); /* program TCR with the WDT period */ vxTcrSet ((vxTcrGet() & ~_PPC403_TCR_WP) | wdtPeriodMask); /* Enable the WDT interrupt */ vxTcrSet (vxTcrGet() | _PPC403_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() & ~ (_PPC403_TCR_WIE)); /* clear the pending WDT interrupt */ vxTsrSet (_PPC403_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; UINT32 wdtPeriod; /* * compute the WDT period. * only 4 values are possible (cf wdtTable[]). The closest value to * <ticksPerSecond> is being used. */ if (ticksPerSecond < WDT_RATE_MIN || ticksPerSecond > WDT_RATE_MAX) return (ERROR); wdtPeriod = sysTimerClkFreq / ticksPerSecond; /* get the closest value to ticksPerSecond supported by the WDT */ for (ix = 0; ix < 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 / 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 intialize 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 (pitCountVal); }/************************************************************************* 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 (pitCountVal - (UINT32) vxPitGet()); }/************************************************************************* 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 currentPitValue; int oldLevel; oldLevel = intLock (); /* LOCK INTERRUPT */ currentPitValue = vxPitGet(); intUnlock (oldLevel); /* UNLOCK INTERRUPT */ return (pitCountVal - currentPitValue); }#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -