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

📄 auxclock.c

📁 VxWorks下 Spruce的BSP源代码
💻 C
字号:
/* auxClock.c - Auxiliary clock library that uses an IBM CPC700 timer *//*******************************************************************************   This source and object code has been made available to you by IBM on an   AS-IS basis.   IT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING THE WARRANTIES OF   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR OF   NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO EVENT SHALL IBM OR ITS   LICENSORS BE LIABLE FOR INCIDENTAL, CONSEQUENTIAL OR PUNITIVE DAMAGES.   IBM'S OR ITS LICENSOR'S DAMAGES FOR ANY CAUSE OF ACTION, WHETHER IN   CONTRACT OR IN TORT, AT LAW OR AT EQUITY, SHALL BE LIMITED TO A MAXIMUM   OF $1,000 PER LICENSE.  Anyone receiving this source or object code is   licensed under IBM copyrights to use it in any way he or she deems fit,   including copying it, modifying it, compiling it, and redistributing it   either with or without modifications.  No license under IBM patents or   patent applications is to be implied by the copyright license.   Any user of this software should understand that neither IBM nor its   licensors will be responsible for any consequences resulting from the   use of this software.   Any person who transfers this object code or any derivative work must   include the IBM copyright notice in the transferred software.   COPYRIGHT   I B M   CORPORATION 1999   LICENSED MATERIAL  -  PROGRAM PROPERTY OF  I B M"*******************************************************************************//* Copyright 1984-1997 Wind River Systems, Inc. *//*modification history--------------------01c,25mar02,pch  fix compiler warnings01b,27mar01,kab  Removed IBM support info per request01a,12may99,mcg  created from templateTimer.c auxiliary timer functions*//*DESCRIPTIONThis auxiliary clock driver uses one of the capture timers found in theIBM CPC700 embedded chipset.  The CPC700 has a 32 bit time base counter(TBC) that is used by all of its 5 compare and 5 capture timers.Each compare timer consist of two registers; the compare timer value register,and the compare mask register.  A compare timer causes an interrupt when thecontents of the compare register match the contents of the CPC700 TBC register.Bits set to 1 in the mask register are ignored when the comparison betweenthe TBC and compare register are done.By setting the mask register n most significant bits to 1, a fixed intervalrecurring timer with a period of 2**(31-n) Time Base Counter ticks iscreated.  This method is used for this auxiliary clock driver.  The advantageof this is that the other timers in the CPC700 are unaffected by thisdriver.  The downside is that the number of auxiliary clock frequencies possibleis limited.  The auxiliary clock frequency is equal to(TBC frequency)/(2**(31-n)) where n is the number of consecutive, mostsignifcant bits set to 1 in the compare timer mask register.If the other timers in the CPC700 are not required in a design, an alternativemethod can be used that provides more flexibility in auxiliary clock frequency.In this method, all bits of the compare timer mask register are zero.  Thecompare timer is loaded with the number of TBC ticks to achieve the desiredauxiliary clock frequency.  Each time the auxiliary clock interrupt occurs, theinterrupt handler just resets the TBC to zero and returns.  If other CPC700compare or capture timers were in use, repeatedly setting the TBC to zero wouldaffect their operation.INCLUDES:*//* includes */#include "drv/timer/timerDev.h"LOCAL FUNCPTR sysAuxClkRoutine  = NULL;LOCAL int sysAuxClkArg          = 0;LOCAL int sysAuxClkRunning      = FALSE;LOCAL int sysAuxClkTicksPerSecond = AUX_CLK_RATE_MAX;/********************************************************************************* sysAuxClkInt - handle an auxiliary clock interrupt** This routine handles an auxiliary clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysAuxClkConnect().** RETURNS: N/A** SEE ALSO: sysAuxClkConnect()*/void sysAuxClkInt (void)    {    /*     * Clear the interrupt status in the Timer Interrupt Status reg     */    sysOutLong(GPTISC, sysInLong(GPTISC) & INT_GPT_COMPARE_0);    /*     * Call the auxiliary clock service routine     */    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 does not enable auxiliary clock interrupts.** 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 to auxiliary clock interrupt routine */    )    {    sysAuxClkRoutine    = NULL;    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)    {    if (sysAuxClkRunning)        {        /*         * Disable Compare Timer 0 interrupts         */        intDisable(INT_LVL_GPT_COMP0);        sysAuxClkRunning = FALSE;        }    }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void)    {    static BOOL connected = FALSE;    if (!connected)        {        /*         * Connect sysAuxClkInt to the Compare Timer 0 interrupt         */        (void) intConnect(INUM_TO_IVEC(INT_VEC_GPT_COMP0), sysAuxClkInt, 0);        connected = TRUE;        }    if (!sysAuxClkRunning)        {        /*         * Set up the compare mask register with the appropriate         * bits for the comparison with the TBC register.         * The mask register specifies which bits to ignore in         * the comparison.         */        if (sysAuxClkTicksPerSecond == (CPC700_TIME_BASE_FREQ / AUX_CLK_PERIOD_1))            {            sysOutLong(GPTMASK0, AUX_CLK_PERIOD_MASK_1);            }        else            {            sysOutLong(GPTMASK0, AUX_CLK_PERIOD_MASK_2);            }        /*         * Read the current contents of the time base counter to get the         * compare value and write it to the compare timer register.         * When enabled, the timer will cause an interrupt every time the         * the bits in the compare register corresponding to the bits in         * the mask register that are 0, match the same bits in the time         * base counter.         */        sysOutLong(GPTCOMP0, sysInLong(GPTTBC));        /*         * Clear  the Compare Timer 0 interrupt status.         * Enable the Compare Timer 0 interrupts in the timer int regs         * Enable the Compare Timer 0 interrupt in the UIC.         */        sysOutLong(GPTISC, sysInLong(GPTISC) & INT_GPT_COMPARE_0);        sysOutLong(GPTIM, sysInLong(GPTIM) & ~INT_GPT_COMPARE_0);        sysOutLong(GPTIE, sysInLong(GPTIE) | INT_GPT_COMPARE_0);        intEnable(INT_LVL_GPT_COMP0);        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.  In order to allow the use of the other* capture and compare timers in the CPC700, only two auxiliary clock rates are* supported.  One is greater than 100 Hz, the other less than 100Hz.* Since the CPC700 timer time base is based off the CPU bus clock, the timer* frequency is slightly different if the CPU bus speed is 66MHz or 60MHz.* The caller should follow a call to this function with a call to* sysAuxClkRateGet() to find out what the auxiliary clock rate was set to.* This driver could be modified to support many more auxiliary clock frequencies* if the use of the other timers in the CPC700 is not required.** RETURNS: OK, or ERROR if the tick rate is invalid.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet(), config.h*/STATUS sysAuxClkRateSet    (    int ticksPerSecond  /* number of clock interrupts per second */    )    {    if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX)        return (ERROR);    /*     * Only two Aux clock rates are supported. (More could be added).     * Pick one of the two.  One is greater than 100Hz the other is less.     */    if (ticksPerSecond > 100)        sysAuxClkTicksPerSecond = (CPC700_TIME_BASE_FREQ / AUX_CLK_PERIOD_2);    else        sysAuxClkTicksPerSecond = (CPC700_TIME_BASE_FREQ / AUX_CLK_PERIOD_1);    if (sysAuxClkRunning)        {        sysAuxClkDisable ();        sysAuxClkEnable ();        }    return (OK);    }

⌨️ 快捷键说明

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