📄 ixp425timer.c
字号:
*/int sysClkRateGet (void) { return(clkRateGet()); }/***************************************************************************** sysClkRateSet - 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: sysClkEnable(), sysClkRateGet()*/STATUS sysClkRateSet ( int ticksPerSecond /* number of clock interrupts per second */ ) { if (ticksPerSecond < SYS_CLK_RATE_MIN || ticksPerSecond > SYS_CLK_RATE_MAX) return (ERROR); clockTicksPerSecond = ticksPerSecond; clockTimerRollOver = ((TIMER_APB_CLOCK_MHZ * 0x100000) / clockTicksPerSecond); if (sysClkRunning) { sysClkDisable (); sysClkEnable (); } return (OK); }/********************************************************************************* 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*/void sysAuxClkInt (void) { WV_EVENT(IXP425TIMER_EVT_AUXINTERRUPT); /* Clear Pending Interrupt by writing '1' to it */ IXP425_REG_TIMER_WRITE(IXP425_OSST, IXP425_OSST_TIMER_2_PEND); /* And again to avoid another interrupt */ IXP425_REG_TIMER_WRITE(IXP425_OSST, IXP425_OSST_TIMER_2_PEND); /* call dispatcher for the auxiliary clock service routine */ (*ixpSysAuxClkRoutine) (ixpSysAuxClkArg); }/********************************************************************************* sysAuxClkDispatchRoutine - dispatch to callout functions during* auxiliary clock interrupt** This is called from auxiliary clock interrupt handler. It calls appropriate* callout functions depending on the frequency required. One of these functions* is installed by sysAuxClkConnect() as specified by the auxClk interface* specification guidelines. The other routine is installed via ixpAuxClkConnect()* which is specific to this BSP.** RETURNS: N/A*/void sysAuxClkDispatchRoutine (void) { if (sysAuxClkTicksPerFuncCall != 0 && sysAuxClkTicksCount++ >= sysAuxClkTicksPerFuncCall) { /* call auxiliary clock service routine */ sysAuxClkTicksCount = 1; WV_EVENT(IXP425TIMER_EVT_SYSAUXCLKROUTINE); (*sysAuxClkRoutine) (sysAuxClkArg); } if (ixpAuxClkTicksPerFuncCall != 0 && ixpAuxClkTicksCount++ >= ixpAuxClkTicksPerFuncCall) { /* call the BSP auxiliary clock service routine */ ixpAuxClkTicksCount = 1; WV_EVENT(IXP425TIMER_EVT_IXPAUXCLKROUTINE); (*ixpAuxClkRoutine) (ixpAuxClkArg); } }/***************************************************************************** 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 does not enable auxiliary clock interrupts.** RETURNS: OK** SEE ALSO: intConnect(), sysAuxClkEnable()*/STATUS sysAuxClkConnect ( FUNCPTR routine, /* routine called at each aux. clock interrupt */ int arg /* argument with which to call routine */ ) { /* temporarily set to dummy function so old routine is not accidently called * with the new argument while we are in the process of reconnecting */ sysAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine; sysAuxClkArg = arg; sysAuxClkRoutine = routine; if(!sysAuxClkConnected) { /* start the dispatch routine if not started */ ixpSysAuxClkConnect ((FUNCPTR)sysAuxClkDispatchRoutine, 0); sysAuxClkConnected = TRUE; } return (OK); }/***************************************************************************** sysAuxClkDisconnect - clear the auxiliary clock routine** This routine disables the auxiliary clock interrupt, stops the timer,* and disconnects the routine currently connected to the auxiliary clock* interrupt.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkEnable()*/void sysAuxClkDisconnect (void) { if (sysAuxClkRunning) { /* disable the auxiliary clock interrupt */ sysAuxClkDisable (); sysAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine; sysAuxClkRunning = FALSE; ixpSysAuxClkDisconnect (); /* stop clock for real, maybe */ } }/***************************************************************************** sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void) { if (sysAuxClkRunning) { sysAuxClkRunning = FALSE; ixpSysAuxClkDisable (); } }/***************************************************************************** sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable()*/void sysAuxClkEnable (void) { if (!sysAuxClkRunning && sysAuxClkConnected) { sysAuxClkRunning = TRUE; ixpSysAuxClkDisable (); ixpSysAuxClkEnable (); /* enable the interrupt for real */ } }/***************************************************************************** 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) { if (sysAuxClkTicksPerFuncCall != 0) { return (ixpSysAuxClkTicksPerSecond/sysAuxClkTicksPerFuncCall); } else { return 0; } }/***************************************************************************** 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 */ ) { STATUS retval; if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) return (ERROR); sysAuxClkTicksPerSecond = ticksPerSecond; retval = ixpSysAuxClkRateSet (); return (retval); }/***************************************************************************** ixpSysAuxClkConnect - connect a routine to the auxiliary clock interrupt** This routine specifies the interrupt service routine to be called at each* auxiliary clock interrupt. It does not enable auxiliary clock interrupts.** RETURNS: OK** SEE ALSO: intConnect(), ixpSysAuxClkEnable()*/LOCAL STATUS ixpSysAuxClkConnect ( FUNCPTR routine, /* routine called at each aux. clock interrupt */ int arg /* argument with which to call routine */ ) { ixpSysAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine; ixpSysAuxClkArg = arg; ixpSysAuxClkRoutine = routine; if(!ixpSysAuxClkConnected) { (void)intConnect ((void *)INT_VEC_TIMER2, sysAuxClkInt, 0); ixpSysAuxClkConnected = TRUE; } return (OK); }/***************************************************************************** ixpSysAuxClkDisconnect - clear the auxiliary clock routine** This routine disables the auxiliary clock interrupt, stops the timer,* and disconnects the routine currently connected to the auxiliary clock* interrupt.** RETURNS: N/A** SEE ALSO: ixpSysAuxClkConnect(), ixpSysAuxClkEnable()*/LOCAL void ixpSysAuxClkDisconnect (void) { if (!ixpAuxClkRunning && !sysAuxClkRunning) /* stop the interrupts only if both dispatch routines are stopped */ { if (ixpSysAuxClkRunning) { /* disable the auxiliary clock interrupt */ ixpSysAuxClkDisable (); ixpSysAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine; ixpSysAuxClkRunning = FALSE; } } }/***************************************************************************** ixpSysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: ixpSysAuxClkEnable()*/LOCAL void ixpSysAuxClkDisable (void) { if (!ixpAuxClkRunning && !sysAuxClkRunning) /* stop the interrupts only if both dispatch routines are stopped */ { if (sysAuxClkRunning) { IXP425_REG_TIMER_WRITE( IXP425_OSRT2 , IXP425_OST_DISABLED ); intDisable(INT_VEC_TIMER2); sysAuxClkRunning = FALSE; } } }/***************************************************************************** ixpSysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: ixpSysAuxClkDisable()*/LOCAL void ixpSysAuxClkEnable (void) { if (!ixpSysAuxClkRunning && ixpSysAuxClkConnected) { ixpSysAuxClkRunning = TRUE; IXP425_REG_TIMER_WRITE( IXP425_OSRT2 , ((ixpSysAuxClkRollOver & ~IXP425_OST_RELOAD_MASK) | IXP425_OST_ENABLE ) ); intEnable(INT_VEC_TIMER2); } }/***************************************************************************** ixpSysAuxClkRateGet - 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: ixpSysAuxClkEnable(), ixpSysAuxClkRateSet()*/LOCAL int ixpSysAuxClkRateGet (void) { return (ixpSysAuxClkTicksPerSecond); }/***************************************************************************** ixpSysAuxClkRateSet - 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.* If one frequency is not a multiple of the other, ERROR is returned.** SEE ALSO: ixpSysAuxClkEnable(), ixpSysAuxClkRateGet()*/LOCAL STATUS ixpSysAuxClkRateSet (void) { int ticksPerSecond; /* number of clock interrupts per second */ if (ixpAuxClkTicksPerSecond != 0 && sysAuxClkTicksPerSecond != 0) { if (ixpAuxClkTicksPerSecond > sysAuxClkTicksPerSecond) { /* ixpAuxClk is a higher frequency */ if ((ixpAuxClkTicksPerSecond*100)/sysAuxClkTicksPerSecond != (ixpAuxClkTicksPerSecond/sysAuxClkTicksPerSecond)*100) { /* one frequency must be a multiple of the other */ return ERROR; } /* set the clock rate to the BSP auxClk rate */ ticksPerSecond = ixpAuxClkTicksPerSecond; ixpAuxClkTicksPerFuncCall = 1; sysAuxClkTicksPerFuncCall = ixpAuxClkTicksPerSecond/sysAuxClkTicksPerSecond; } else { /* sysAuxClk is a higher frequency */ if ((sysAuxClkTicksPerSecond*100)/ixpAuxClkTicksPerSecond != (sysAuxClkTicksPerSecond/ixpAuxClkTicksPerSecond)*100) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -