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

📄 m68681timer.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    }/********************************************************************** m68681ClkDisable - turn off clock interrupts** This routine disables clock interrupts generated by the Motorola MC68681* timer.** RETURNS: N/A** SEE ALSO: m68681ClkEnable()*/void m68681ClkDisable     (    M68681_CLK *pClk	/* clock to be disabled */    )    {    if (pClk->running)	{	int level = intLock ();	/* Disable the timer interrupt */	m68681ImrSetClr (pClk->pDuart, 0, M68681_ISR_CTR_RDY_INT);	/* stop clock */	M68681_READ (pClk->pDuart->ctroff);        pClk->running = FALSE;	intUnlock (level);	}    }/********************************************************************** m68681ClkEnable - turn on clock interrupts** This routine enables clock interrupts generated by the Motorola MC68681* timer.** RETURNS: N/A** SEE ALSO: m68681ClkConnect(), m68681ClkDisable(), m68681ClkRateSet()*/void m68681ClkEnable     (    M68681_CLK * pClk 	/* clock to be enabled */    )    {    if (!pClk->running)	{	int level;	int temp;	char startTimer;	M68681_DUART *pDuart = pClk->pDuart;	/* calculate the preload value */	temp = (pClk->hertz) / M68681_PRESCALER / pClk->rate; 	/* min is 2, max is 0xffff, per m68681 users manual */	if (temp < MIN_CTR_VALUE)	    temp = MIN_CTR_VALUE;	else if (temp > MAX_CTR_VALUE)	    temp = MAX_CTR_VALUE;	pClk->preload = temp;	level = intLock ();	M68681_WRITE (pDuart->ctlr, LSB (temp));	M68681_WRITE (pDuart->ctur, MSB (temp));	/* Counter mode */	m68681AcrSetClr (pDuart, M68681_ACR_CTR_EXT_CLK_16, 0);	/* Enable the timer interrupt */	m68681ImrSetClr (pDuart, M68681_ISR_CTR_RDY_INT, 0);	/* Initialize the timer */	startTimer = M68681_READ (pDuart->ctron);	intUnlock (level);        pClk->running = TRUE;	}    }/******************************************************************* m68681ClkRateGet - get the clock rate** This routine returns the interrupt rate of the MC68681 clock.** RETURNS: The number of ticks per second of the MC68681 clock.** SEE ALSO: m68681ClkEnable(), m68681ClkRateSet()*/int m68681ClkRateGet    (    M68681_CLK * pClk	/* clock to be read */    )    {    return (pClk->rate);    }/******************************************************************* m68681ClkRateSet - set the clock rate** This routine sets the interrupt rate of the MC68681 clock.  It does not* enable clock interrupts.** In addition to checking against the user-specified min/max rates, this* routine also checks against the hardware limits for min/max rates.  These * limits cannot be exceeded.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.** SEE ALSO:* m68681ClkEnable(), m68681ClkRateGet()*/STATUS m68681ClkRateSet    (    M68681_CLK *pClk,	/* clock to be set */    int rate      /* number of clock interrupts per second */    )    {    if (rate < pClk->min     || rate > pClk->max)        return (ERROR);    pClk->rate = rate;    if (pClk->running)        {        m68681ClkDisable (pClk);        m68681ClkEnable  (pClk);        }    return (OK);    }/******************************************************************* m68681ClkReadOnFly - read the clock internal counter** This routine reads the counter/timer value on the fly when receiving* normal oscillator input.  The lowest 8 bits of the counter roll over every* 140 microseconds.  A standard hi/low/hi read sequence ensures a consistent* value from the pair of registers, assuming that the two 8-bit values are* individually latched and there is no problem with ripple in either* register.** RETURNS: The current countdown counter value, or ERROR if* there is a hardware error.*/int m68681ClkReadOnFly    (    M68681_CLK * pClk	/* clock to be read */    )    {    volatile UCHAR *pLow = pClk->pDuart->ctlr;    volatile UCHAR *pHi = pClk->pDuart->ctur;    UCHAR low;    UCHAR hi1;    UCHAR hi2;    int level;    level = intLock ();    /* usual hi/low/hi sequence */    hi1 = M68681_READ (pHi);    low = M68681_READ (pLow);    hi2 = M68681_READ (pHi);    if (hi1 != hi2)	low = M68681_READ (pLow);    intUnlock (level);    return (int)((hi2 << 8) + low);    }IMPORT M68681_CLK * pSysClk;/********************************************************************************* sysClkConnect - connect a routine to the system clock interrupt** This routine specifies the interrupt service routine to be called at each* clock interrupt.  Normally, it is called from usrRoot() in usrConfig.c to* connect usrClock() to the system clock interrupt.  ** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), usrClock(), sysClkEnable()*/STATUS sysClkConnect    (    FUNCPTR routine,	/* routine called at each system clock interrupt */    int     arg		/* argument with which to call routine           */    )    {    sysHwInit2 ();    return (m68681ClkConnect (pSysClk, (VOIDFUNCPTR) routine, (void *) arg));     }/********************************************************************************* sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet()*/void  sysClkEnable (void)    {    m68681ClkEnable (pSysClk);     }/********************************************************************************* sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/void sysClkDisable (void)    {    m68681ClkDisable (pSysClk);     }/********************************************************************************* sysClkRateGet - get the system clock rate** This routine returns the interrupt rate of the system clock.** RETURNS: The number of ticks per second of the system clock.** SEE ALSO: sysClkRateSet()*/int sysClkRateGet ()    {    return m68681ClkRateGet (pSysClk);     }/********************************************************************************* sysClkRateSet - set the system clock rate** This routine sets the interrupt rate of the system clock.  It does not* enable system clock interrupts.  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)    {    return m68681ClkRateSet (pSysClk, ticksPerSecond);    }#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: ERROR, always.*/STATUS sysTimestampConnect    (    FUNCPTR routine,    /* routine called at each timestamp timer interrupt */    int arg             /* argument with which to call routine */    )    {    return (ERROR);    }/********************************************************************************* 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)   {   return (OK);   }/********************************************************************************* sysTimestampDisable - disable a timestamp timer interrupt** This routine disables timestamp timer interrupts.** RETURNS: OK, always.** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable (void)    {    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 (pSysClk->preload);    }/********************************************************************************* 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 (pSysClk->hertz / M68681_PRESCALER);    }/********************************************************************************* 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)    {    /* timer is decrementing */    return (pSysClk->preload - m68681ClkReadOnFly(pSysClk));    }/********************************************************************************* 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)    {    /* same as sysTimestamp() */    return (pSysClk->preload - m68681ClkReadOnFly(pSysClk));    }#endif  /* INCLUDE_TIMESTAMP */#endif	/* INCLUDE_TYCODRV_5_2 */

⌨️ 快捷键说明

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