📄 sun4timer.c
字号:
** sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void) { if (sysAuxClkRunning) { *SUN_IR &= ~IR_ALL; /* turn off interrupts */ *SUN_IR &= ~IR_CLOCK14; /* turn off lvl 14 */ *SUN_IR |= IR_ALL; /* turn on interrupts */ sysAuxClkRunning = FALSE; } }/***************************************************************************** sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts. ** NOTE: The auxilliary clock and the timestamp clock are mutually* exclusive. The timestamp clock cannot be used if the auxilliary clock* is running.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable()*/void sysAuxClkEnable (void) { unsigned int intRegister; if (! sysAuxClkRunning && ! sysTimestampRunning) { *SUN_IR &= ~IR_ALL; /* turn off interrupts */ intRegister = *SUN_LIMIT_1; /* Clear interrupt at clock */ *SUN_IR &= ~IR_CLOCK14; /* Clear interrupt pending */ *SUN_IR |= IR_CLOCK14; /* turn on lvl 14 */ *SUN_IR |= IR_ALL; /* turn on interrupts */ sysAuxClkRunning = TRUE; } }/***************************************************************************** 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) { return (auxClkTicksPerSecond); }/***************************************************************************** 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 */ ) { if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) return (ERROR); auxClkTicksPerSecond = ticksPerSecond; *SUN_COUNTER_1 = 0; *SUN_LIMIT_1 = (1000000 / ticksPerSecond) << 10; *SUN_COUNTER_1 = 0; 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. ** NOTE: The auxilliary clock and the timestamp clock are mutually* exclusive. The timestamp clock cannot be used if the auxilliary clock* is running.** RETURNS: OK, or ERROR if the auxiliary clock is in use.** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampConnect ( FUNCPTR routine, /* routine called at each timestamp timer interrupt */ int arg /* argument with which to call routine */ ) { if (sysAuxClkRunning) return ERROR; sysTimestampRoutine = routine; sysTimestampArg = arg; return (OK); }/********************************************************************************* sysTimestampEnable - enable a timestamp timer interrupt** This routine enables timestamp timer interrupts and resets the counter.** NOTE: The auxilliary clock and the timestamp clock are mutually* exclusive. The timestamp clock cannot be used if the auxilliary clock* is running.** RETURNS: OK, or ERROR if the timestamp timer cannot be enabled.** SEE ALSO: sysTimestampDisable()*/STATUS sysTimestampEnable (void) { unsigned int intRegister; if (sysAuxClkRunning) return (ERROR); if (! sysTimestampRunning) { *SUN_IR &= ~IR_ALL; /* turn off interrupts */ *SUN_COUNTER_1 = 0; *SUN_LIMIT_1 = 0x1fffff << 10; /* 0 limit means free running */ *SUN_COUNTER_1 = 0; intRegister = *SUN_LIMIT_1; /* Clear interrupt at clock */ *SUN_IR &= ~IR_CLOCK14; /* Clear interrupt pending */ *SUN_IR |= IR_CLOCK14; /* turn on lvl 14 */ *SUN_IR |= IR_ALL; /* turn on interrupts */ *SUN_COUNTER_1 = 0; *SUN_LIMIT_1 = 0x1fffff << 10; /* 0 limit means free running */ *SUN_COUNTER_1 = 0; sysTimestampRunning = TRUE; } 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, always.** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable (void) { if (sysTimestampRunning) { *SUN_LIMIT_1 = 0x80000000 ; /* 0 limit means free running */ *SUN_IR &= ~IR_ALL; /* turn off interrupts */ *SUN_IR &= ~IR_CLOCK14; /* turn off lvl 14 */ *SUN_IR |= IR_ALL; /* turn on interrupts */ 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 (0x1fffff); /* highest period -> freerunning */ }/********************************************************************************* 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 ((UINT32) 1000000); }/********************************************************************************* 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) { return (*((UINT32 *) SUN_COUNTER_1) >> 10); }/********************************************************************************* 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) { return (*((UINT32 *) SUN_COUNTER_1) >> 10); }#endif /* INCLUDE_TIMESTAMP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -