📄 ixp425timer.c
字号:
/* one frequency must be a multiple of the other */ return ERROR; } /* set the clock rate to the user auxClk rate */ ticksPerSecond = sysAuxClkTicksPerSecond; ixpAuxClkTicksPerFuncCall = sysAuxClkTicksPerSecond/ixpAuxClkTicksPerSecond; sysAuxClkTicksPerFuncCall = 1; } } else if (ixpAuxClkTicksPerSecond != 0) { /* set the clock rate to the BSP auxClk rate */ ticksPerSecond = ixpAuxClkTicksPerSecond; ixpAuxClkTicksPerFuncCall = 1; sysAuxClkTicksPerFuncCall = 0; /* disabled */ } else { /* set the clock rate to the user auxClk rate */ ticksPerSecond = sysAuxClkTicksPerSecond; ixpAuxClkTicksPerFuncCall = 0; /* disabled */ sysAuxClkTicksPerFuncCall = 1; } if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) return (ERROR); ixpSysAuxClkTicksPerSecond = ticksPerSecond; ixpSysAuxClkRollOver = ((TIMER_APB_CLOCK_MHZ * 0x100000) / ixpSysAuxClkTicksPerSecond); return (OK); }/***************************************************************************** ixpAuxClkConnect - connect this BSP's timer routine to the auxiliary* clock interrupt** The auxClk is shared between END driver polling and standard user auxClk* functionality.* This routine specifies the BSP routine that is called from the auxClk* interrupt service routine to be called at each* auxiliary clock interrupt. It does not enable auxiliary clock interrupts.** RETURNS: OK** SEE ALSO: intConnect(), ixpAuxClkEnable()*/STATUS ixpAuxClkConnect ( FUNCPTR routine, /* routine called during auxClk 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 */ ixpAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine; ixpAuxClkArg = arg; ixpAuxClkRoutine = routine; if(!ixpAuxClkConnected) { /* start the dispatch routine if not started */ ixpSysAuxClkConnect ((FUNCPTR)sysAuxClkDispatchRoutine, 0); ixpAuxClkConnected = TRUE; } return (OK); }/***************************************************************************** ixpAuxClkDisconnect - clear the BSP specific auxiliary clock routine** This routine unhooks the BSP specific callout function and* possibly disables the auxClk timer interrupt if noone else is using it.** RETURNS: N/A** SEE ALSO: ixpAuxClkConnect(), ixpAuxClkEnable()*/void ixpAuxClkDisconnect (void) { if (ixpAuxClkRunning) { /* disable the auxiliary clock interrupt */ ixpAuxClkDisable (); ixpAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine; ixpAuxClkRunning = FALSE; ixpSysAuxClkDisconnect (); /* stop clock for real, maybe */ } }/***************************************************************************** ixpAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: ixpAuxClkEnable()*/void ixpAuxClkDisable (void) { if (ixpAuxClkRunning) { ixpAuxClkRunning = FALSE; ixpSysAuxClkDisable (); } }/***************************************************************************** ixpAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: ixpAuxClkDisable()*/void ixpAuxClkEnable (void) { if (!ixpAuxClkRunning && ixpAuxClkConnected) { ixpAuxClkRunning = TRUE; ixpSysAuxClkDisable (); ixpSysAuxClkEnable (); /* enable the interrupt for real */ } }/***************************************************************************** ixpAuxClkRateGet - get the auxiliary clock rate** This routine returns the pseudo interrupt rate of the BSP auxiliary clock.** RETURNS: The number of ticks per second of the BSP auxiliary clock.** SEE ALSO: ixpAuxClkEnable(), ixpAuxClkRateSet()*/int ixpAuxClkRateGet (void) { if (ixpAuxClkTicksPerFuncCall != 0) { return (ixpSysAuxClkTicksPerSecond/ixpAuxClkTicksPerFuncCall); } else { return 0; } }/***************************************************************************** ixpAuxClkRateSet - set the BSP auxiliary pseudo clock rate** This routine sets the pseudo interrupt rate of the BSP 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: ixpAuxClkEnable(), ixpAuxClkRateGet()*/STATUS ixpAuxClkRateSet ( int ticksPerSecond /* number of clock interrupts per second */ ) { STATUS retval; if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) return (ERROR); ixpAuxClkTicksPerSecond = ticksPerSecond; retval = ixpSysAuxClkRateSet (); return (retval); }#ifdef INCLUDE_TIMESTAMP/********************************************************************************* sysTimestampInt - timestamp timer interrupt handler** This rountine handles the timestamp timer interrupt. A user routine is* called, if one was connected by sysTimestampConnect().** RETURNS: N/A** SEE ALSO: sysTimestampConnect()*/void sysTimestampInt (void) { /* Clear Pending Interrupt by writing '1' to it */ IXP425_REG_TIMER_WRITE(IXP425_OSST, IXP425_OSST_TIMER_TS_PEND); if (sysTimestampRunning && sysTimestampRoutine != NULL) (*sysTimestampRoutine)(sysTimestampArg); }/**************************************************************************** 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.** RETURNS: OK, or ERROR if sysTimestampInt() has not been used.** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampConnect ( FUNCPTR routine, /* routine called at each timestamp timer interrupt */ int arg /* argument with which to call routine */ ) { static BOOL connected = FALSE; sysTimestampRoutine = NULL; sysTimestampArg = arg; sysTimestampRoutine = routine; if (!connected) { (void)intConnect ((void *)INT_VEC_TIMESTAMP, sysTimestampInt, 0); connected = TRUE; } return OK; }/**************************************************************************** sysTimestampEnable - enable a timestamp timer interrupt** This routine enables timestamp timer interrupts and resets the counter.** RETURNS: OK, or ERROR if the timestamp timer cannot be enabled.** SEE ALSO: sysTimestampDisable()*/STATUS sysTimestampEnable(void) { if(!sysTimestampRunning) { sysTimestampRunning = TRUE; intEnable(INT_VEC_TIMESTAMP); } return (OK); }/**************************************************************************** sysTimestampDisable - disable a timestamp timer interrupt** This routine disables the timestamp timer. It does not directly disable* interrupts. However, the tick counter does not increment once the* timestamp timer is disabled, thus, interrupts are no longer generated.* This routine merely resets the timer counter.** RETURNS: OK, ERROR if the timestamp timer cannot be disabled.** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable (void) { if (sysTimestampRunning) { intDisable(INT_VEC_TIMESTAMP); sysTimestampRunning = FALSE; } return (OK); }/**************************************************************************** sysTimestampPeriod - get the period of a timestamp timer** This routine gets 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) { /* * Return the timestamp timer period here. * The highest period (maximum terminal count) should be used so * that rollover interrupts are kept to a minimum. * */ return (clkPeriod()); }/**************************************************************************** sysTimestampFreq - get a timestamp timer clock frequency** This routine gets the frequency of the timer clock, in ticks per* second. The rate of the timestamp timer is set explicitly by the* hardware and typically cannot be altered.** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq (void) { /* * 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. */ return (clkFreq()); }/**************************************************************************** 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 it 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) { UINT32 ticks = 0; if (sysTimestampRunning) { /* Read the timer counter register */ ticks = clkTimestamp(); } /* return the timestamp timer tick count here */ return (ticks); }/**************************************************************************** sysTimestampLock - lock interrupts and get the timestamp timer tick count** This routine locks interrupts when 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 it by the return of* sysTimestampFreq().** If interrupts are already locked, sysTimestamp() should be* used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestampFreq(), sysTimestamp()*/UINT32 sysTimestampLock (void) { int locKey; UINT32 ticks = 0; if (sysTimestampRunning) { /* Lock Interrupts */ locKey = intLock(); /* Read the timer counter register */ ticks = clkTimestamp(); /* UnLock Interrupts */ intUnlock (locKey); } /* return the timestamp timer tick count here */ return (ticks); }#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -