⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sa1100timer.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    int key;    /* clear interrupt */    SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSSR, 1 << 1);    /*     * Load the match register with a new value calculated by     * adding the ticks per interrupt to the current value of the     * counter register.  Note that this may wraparound to a value     * less than the current counter value but that's OK.     */    key = intLock ();    SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OSCR, tc);    tc += sysAuxClkTicks;    SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSMR_1, tc);    intUnlock (key);    /* If any routine attached via sysAuxClkConnect(), call it */    if (sysAuxClkRoutine != NULL)	(*sysAuxClkRoutine) (sysAuxClkArg);    }/********************************************************************************* 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 also connects the clock error interrupt* service routine.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), sysAuxClkEnable()*/STATUS sysAuxClkConnect    (    FUNCPTR routine,    /* routine called at each aux clock interrupt */    int arg             /* argument with which to call routine        */    )    {    sysAuxClkRoutine = NULL;	/* ensure routine not called with wrong arg */    sysAuxClkArg	= arg;    sysAuxClkRoutine	= routine;    return OK;    }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void)    {    UINT32 oier;    int key;    if (sysAuxClkRunning)        {	/* disable timer interrupt in the timer */	key = intLock ();	SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OIER, oier);	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OIER, oier & ~(1 << 1));	intUnlock (key);	/* clear any pending interrupt */	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSSR, 1 << 1);	/* disable timer interrupt in the interrupt controller */	SA1100_TIMER_INT_DISABLE (AUX_TIMER_INT_LVL);	sysAuxClkRunning = FALSE;        }    }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable()*/void sysAuxClkEnable (void)    {    UINT32 tc, oier;    int key;    if (!sysAuxClkRunning)	{	/*	 * Calculate the number of ticks of the timer clock that this	 * period requires.  Do this once, here, so that the timer interrupt	 * routine does not need to perform a division.	 */	sysAuxClkTicks = (AUX_TIMER_CLK / sysAuxClkTicksPerSecond) -					    SA1100_TIMER_RELOAD_CORRECTION;	/* clear any pending interrupt */	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSSR, 1 << 1);	/*	 * Load the match register with a new value calculated by	 * adding the ticks per interrupt to the current value of the	 * counter register.  Note that this may wraparound to a value	 * less than the current counter value but that's OK.	 */	key = intLock ();	SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OSCR, tc);	tc += sysAuxClkTicks;	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSMR_1, tc);	/* enable interrupt in timer */	SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OIER, oier);	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OIER, oier | (1 << 1));	intUnlock (key);	/* enable clock interrupt in interrupt controller */	SA1100_TIMER_INT_ENABLE (AUX_TIMER_INT_LVL);	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 sysAuxClkTicksPerSecond;    }/********************************************************************************* sysAuxClkRateSet - set the auxiliary clock rate** This routine sets the interrupt rate of the auxiliary clock.  It does* not enable auxiliary clock interrupts unilaterally, but if the* auxiliary clock is currently enabled, the clock is disabled and then* re-enabled with the new rate.** RETURNS: OK or ERROR.** 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;    sysAuxClkTicksPerSecond = ticksPerSecond;    if (sysAuxClkRunning)	{	sysAuxClkDisable ();	sysAuxClkEnable ();	}    return OK;    }#endif /* INCLUDE_AUX_CLK */#ifdef  INCLUDE_TIMESTAMP/********************************************************************************* sysTimestampInt - timestamp timer interrupt handler** This routine 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 interrupt */    SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSSR, 1 << 2);    /*     * do not reload the match register - another interrupt will be     * generated next time the counter hits the current value     *     * If any routine attached via sysTimestampConnect(), call it     */    if (sysTimestampRunning && sysTimestampRoutine != NULL)	(*sysTimestampRoutine)(sysTimestampArg);    }/********************************************************************************* sysTimestampConnect - connect a user routine to the timestamp timer interrupt** This routine specifies the user interrupt routine to be called at each* timestamp timer interrupt.  It does not enable the timestamp timer itself.** 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 */    )    {    sysTimestampRoutine = NULL;    sysTimestampArg = arg;    sysTimestampRoutine = routine;    return OK;    }/********************************************************************************* sysTimestampEnable - initialize and enable the timestamp timer** This routine connects the timestamp timer interrupt and initializes the* counter registers.  If the timestamp timer is already running, this routine* merely resets the timer counter.** The rate of the timestamp timer should be set explicitly within the BSP,* in the sysHwInit() routine.  This routine does not intialize the timer* rate.** RETURNS: OK, or ERROR if hardware cannot be enabled.*/STATUS sysTimestampEnable (void)    {    static BOOL connected = FALSE;    UINT32 tc, oier;    int key;    if (!connected)	{	/* connect sysTimestampInt to the appropriate interrupt */	intConnect (INUM_TO_IVEC (INT_LVL_TIMER_2), sysTimestampInt, 0);	connected = TRUE;	}    if (!sysTimestampRunning)	{	/*	 * Set match register (OSMR) to (current counter value) (OSCR)	 * minus one so that an interrupt will be generated when the	 * counter wraps around to that value but there will not be an	 * immediate interrupt. This means that the first interrupt will	 * arrive one tick too soon but this inaccuracy should be	 * tolerable.	 */	key = intLock();	SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OSCR, tc);	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSMR_2, tc - 1);	/* clear any pending interrupt */	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSSR, 1 << 2);	/* enable interrupt in timer */	SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OIER, oier);	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OIER, oier | (1 << 2));	intUnlock (key);	/* enable clock interrupt in interrupt controller */	SA1100_TIMER_INT_ENABLE (TIMESTAMP_TIMER_INT_LVL);	sysTimestampRunning = TRUE;	}    return OK;    }/********************************************************************************* sysTimestampDisable - disable the timestamp timer** This routine disables the timestamp timer.  Interrupts are not disabled,* although the tick counter will not increment after the timestamp timer* is disabled, thus interrupts will no longer be generated.** RETURNS: OK, or ERROR if timer cannot be disabled.*/STATUS sysTimestampDisable (void)    {    UINT32 oier;    int key;    if (sysTimestampRunning)	{	/* disable timer interrupt in the timer */	key = intLock ();	SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OIER, oier);	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OIER, oier & ~(1 << 2));	intUnlock (key);	/* clear any pending interrupt */	SA1100_TIMER_REG_WRITE (SA1100_TIMER_CSR_OSSR, 1 << 2);	/* disable timer interrupt in the interrupt controller */	SA1100_TIMER_INT_DISABLE (TIMESTAMP_TIMER_INT_LVL);        sysTimestampRunning = FALSE;	}    return OK;    }/********************************************************************************* sysTimestampPeriod - get the timestamp timer period** This routine returns the period of the timestamp timer in ticks.* The period, or terminal count, is the number of ticks to which the timestamp* timer will count before rolling over and restarting the counting process.** RETURNS: The period of the timestamp timer in counter ticks.*/UINT32 sysTimestampPeriod (void)    {    return 0xFFFFFFFF;		/* max value of 32-bit counter */    }/********************************************************************************* sysTimestampFreq - get the timestamp timer clock frequency** This routine returns the frequency of the timer clock, in ticks per second.** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq (void)    {    return TIMESTAMP_TIMER_CLK;    }/********************************************************************************* sysTimestamp - get the 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 already locked, sysTimestampLock() should be used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestampLock()*/UINT32 sysTimestamp (void)    {    UINT32 count, match;    /*     * read count and match registers - this is effectively atomic     * (since the match register is not reloaded on interrupt) so there is     * no need to disable interrupts around this.     */    SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OSCR, count);    SA1100_TIMER_REG_READ (SA1100_TIMER_CSR_OSMR_2, match);    /*     * When the timer was enabled, the match register (OSMR) was     * initialised to the current value of the count register (OSCR) and     * then generates an interrupt every time the two registers match.     * The ticks since the last interrupt are thus (OSCR - OSMR).     */    return count - match;    }/********************************************************************************* sysTimestampLock - get the 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 locks interrupts for cases where it is necessary to stop the* tick counter in order to read it, or when two independent counters must* be read.  If interrupts are already locked, sysTimestamp() should be* used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestamp()*/UINT32 sysTimestampLock (void)    {    /* no need to disable interrupts - see sysTimestamp() */    return sysTimestamp ();    }#endif  /* INCLUDE_TIMESTAMP */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -