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

📄 autimer.c

📁 au1500开发的应用程序
💻 C
📖 第 1 页 / 共 2 页
字号:
            {            if (count++ > OSC_TIMEOUT)                {                return (ERROR);                }             }        }    else if (pollvalue == 1)        {        while (!(AU_RTC_CONTROL_REG & bit)) /* wait for bit=1 */            {            if (count++ > OSC_TIMEOUT)                {                return (ERROR);                }             }        }    return (OK);    }/******************************************************************************* sysAuxClkConfig - Set up RTC device.** This routine enables auxiliary clock oscillator.* Set up oscillator divider (trim register), and initial value of auxiliary* clock counter (write register). At the end it enables RTC counter, but* leaves auxiliary clock disable.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkConfig (void)    {    /* configure RTC match2 interrupt as rising edge */    AU_INTC_CONFIG2_CLEAR(0) = (1 << 21);    AU_INTC_CONFIG1_CLEAR(0) = (1 << 21);    AU_INTC_CONFIG0_SET(0) = (1 << 21);    sysWbFlush();    /* set trim to 0(divider is 1) */    AU_RTC_CONTROL_REG |= AU_SYS_COUNTER_CONTROL_BRT;    sysWbFlush();    AU_RTC_TRIM_REG = 0;    sysWbFlush();    /* normal operation, using trim */    AU_RTC_CONTROL_REG &= ~AU_SYS_COUNTER_CONTROL_BRT;    sysWbFlush();    /* enable RTC block, query RTS bit before writing */    sysRtcControlPoll (AU_SYS_COUNTER_CONTROL_ERS, 0);    AU_RTC_CONTROL_REG |= AU_SYS_COUNTER_CONTROL_REN;    sysWbFlush();    /* initialize counter(write register) to 0, query RS before writing */    sysRtcControlPoll (AU_SYS_COUNTER_CONTROL_RS, 0);    AU_RTC_WRITE_REG = 0;    sysWbFlush();    sysRtcControlPoll (AU_SYS_COUNTER_CONTROL_RS, 0);    }/******************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void)    {    /* set RTC match2, query RM2 before writing */    sysRtcControlPoll (AU_SYS_COUNTER_CONTROL_RM2, 0);    AU_RTC_MATCH_2_REG = PERIOD(auxClkTicksPerSecond);    sysWbFlush();    /* adjust counter */    AU_RTC_WRITE_REG = TIMER_WRITE_DELAY;    sysWbFlush();    /* enable interrupts */    AU_INTC_MASK_SET(0) = (1 << 21);    sysWbFlush();        auxClkRunning = 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: 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.  Normally, it is called by usrRoot() in* usrConfig.c.** NOTE: The Au internal RTC timer is used to provide the auxiliary clock.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be* set.** SEE ALSO: sysAuxClkDisable(), sysAuxClkEnable(), sysAuxClkRateGet()*/STATUS sysAuxClkRateSet    (    int ticksPerSecond  /* number of clock interrupts per second */    )    {    /* parameter checking */    if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX)        return (ERROR);    auxClkTicksPerSecond = ticksPerSecond;    if (auxClkRunning)        {        sysAuxClkDisable ();        sysAuxClkEnable ();        }    return (OK);    }/******************************************************************************* sysAuxClkInt - handle a auxiliary clock interrupt** This routine handles a auxiliary clock interrupt.  It increments the value* on the front panel display and calls the routine installed by* sysAuxClkConnect().** RETURNS: N/A*/void sysAuxClkInt (void)    {    /* mask interrupt 21 */    AU_INTC_MASK_CLEAR(0) = (1 << 21);    sysWbFlush();    /* clear pending bit */    AU_INTC_RISING_EDGE_CLEAR (0) = (1 << 21);    sysWbFlush();    /* adjust counter */    AU_RTC_WRITE_REG = TIMER_WRITE_DELAY;    sysWbFlush();    sysRtcControlPoll (AU_SYS_COUNTER_CONTROL_RS, 0);    /* enable interrupt */    AU_INTC_MASK_SET(0) = (1 << 21);    sysWbFlush();    /* execute connected routine */    if (sysAuxClkRoutine != NULL)        {            (*sysAuxClkRoutine) (sysAuxClkArg);        }    }/******************************************************************************* sysAuxClkConnect - connect a routine to the auxiliary clock interrupt** This routine specifies the interrupt handler to be called at each auxiliary* clock interrupt.  It does not enable auxiliary clock interrupts. ** RETURN: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), sysAuxClkEnable*/STATUS sysAuxClkConnect    (    FUNCPTR routine,    /* routine called at each auxiliary clock interrupt */    int arg             /* argument with which to call routine           */    )    {    if (auxClkConnected == FALSE)        {        auxClkConnected = TRUE;        }    sysAuxClkRoutine   = routine;    sysAuxClkArg       = arg;    return (OK);    }/******************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()*/void sysAuxClkDisable (void)    {    if (auxClkRunning)        {        AU_INTC_MASK_CLEAR(0) = (1 << 21);        sysWbFlush();        auxClkRunning = FALSE;        }    }#endif  /* INCLUDE_AUX_CLK *//********************************************************************************* 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()*/LOCAL void sysTimestampInt (void)    {    sysCompareSet (0);    /* we cannot disable interrupts so we do this instead */    sysCountSet (1);    sysCompareSet (TIMER_ROLL_OVER);#ifdef INCLUDE_TIMESTAMP    if ((sysTimestampRunning == TRUE) & (sysTimestampRoutine != NULL))             (*sysTimestampRoutine) (sysTimestampArg);#endif    }#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.** RETURNS: OK, always.*/STATUS sysTimestampConnect    (    FUNCPTR routine,    /* routine called at each timestamp timer interrupt */    int arg             /* argument with which to call routine */    )    {    sysTimestampRoutine = routine;    sysTimestampArg = arg;    return (OK);    }/********************************************************************************* sysTimestampEnable - enable a timestamp timer interrupt** This routine enables timestamp timer interrupts and resets the counter.** RETURNS: OK, always.** SEE ALSO: sysTimestampDisable()*/STATUS sysTimestampEnable (void)   {   sysCompareSet (TIMER_ROLL_OVER);   sysCountSet (0);   sysTimestampRunning = TRUE;   return (OK);   }/********************************************************************************* sysTimestampDisable - disable a timestamp timer interrupt** This routine disables timestamp timer interrupts.** RETURNS: OK, always.** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable (void)    {    if (sysTimestampRunning)        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)    {    /*     * The period of the timestamp depends on the clock rate of the on-chip     * timer.     */    return (TIMER_ROLL_OVER);    }/********************************************************************************* 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 (CPU_CLOCK_RATE);    }/********************************************************************************* 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 (sysCountGet());    }/********************************************************************************* 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(sysCountGet());    }#endif  /* INCLUDE_TIMESTAMP */

⌨️ 快捷键说明

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