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

📄 syslib.c

📁 au1500开发的应用程序
💻 C
📖 第 1 页 / 共 3 页
字号:
* This routine returns the frequency of the BRG clock.
*
* NOTE:
* - See page 9-5 in Rev0 of 8260 book
* - BRG_CLK = 2 * CPM_CLK /{2^[2*(DFBRG+1)]}
*
* RETURNS: Frequence in HZ
*
*/

int sysBaudClkFreq
    (
    void
    )
    {

    UINT32 cpmFreq;
    UINT32 sccrDfbrg;

    /* Get the physical location of the IMMR register */

    UINT32 immrVal = vxImmrGet ();

    /* SCCR was init in romInit.s */

    sccrDfbrg  = (UINT32)(*(M8260_SCCR(immrVal)));

    /* M8260_SCCR_RES_MSK should be 0xFFFFFFFC
     * but it was defined in m8260Clock.h as 0xFFFFFFF8
     * so I change it here.
     */
#ifdef M8260_SCCR_RES_MSK
# undef M8260_SCCR_RES_MSK
# define M8260_SCCR_RES_MSK	0xFFFFFFFC
#endif
    
    sccrDfbrg &= (~M8260_SCCR_RES_MSK);

    cpmFreq = sysCpmFreqGet ();

    if (ERROR == cpmFreq)
        return ERROR;
    else
	{
	switch (sccrDfbrg)
            {
            case M8260_SCCR_DFBRG_4:
		return cpmFreq*2/4;
            case M8260_SCCR_DFBRG_16:
		return cpmFreq*2/16;
            case M8260_SCCR_DFBRG_64:
 		return cpmFreq*2/64;
	    case M8260_SCCR_DFBRG_128:
		return cpmFreq*2/128;
            default:
		return cpmFreq*2/16;
            }
        }
    }

/***********************************************************************
*
* sysClkRateAdjust - calculates proper decrementer frequency for a cpu frequency
*
* This routine calculates proper decrementer frequency for a cpu frequency
*
* RETURNS: Speed in Hz
* ??
*/

void sysClkRateAdjust 
    (
    int * sysDecClkFrequency
    )
    {

    *sysDecClkFrequency = sysInputFreqGet () / DEC_ADJUSTMENT;

    return;
    }

/***********************************************************************
*
* sysInputFreqGet - determines the Input Oscillator clock frequency
*
* This routine determines the Input Oscillator clock frequency
*
* NOTE: See page 9-2 in Rev0 of 8260 manual
*
* RETURNS: Input frequency in HZ
*
*/

UINT32 sysInputFreqGet 
    (
    void
    )
    {
#ifdef HARDCODED_FREQ_PARMS
    return INPUT_FREQUENCY;
#else  
    UINT8  *pModck_H = (UINT8 *)HRDW_CONFIG_BYTE4;

    /* get MODCK_H from hard configuration word */

    *pModck_H &= MODCK_H_MASK;               /* Mask the uper 4 bit */

    /* deduce the input frequency */

    switch ( *pModck_H )
        {
        case 1: case 2: case 3: case 4:
            return FREQ_33MHZ;
        case 5: case 6: case 7: case 8:
            return FREQ_66MHZ;
        default:
            return ERROR;
        }
#endif /* HARDCODED_FREQ_PARMS */
    }

/***********************************************************************
*
* sysCpmFreqGet - determines the CPM operating frequency
*
* This routine determines the CPM operating frequency
*
* NOTE: See page 9-2 in Rev0 of 8260 book
*
* RETURNS: CPM frequency in HZ
*
*/

UINT32 sysCpmFreqGet
    (
    void
    )
    {
#ifdef HARDCODED_FREQ_PARMS
    return CPM_FREQUENCY;
#else
    UINT   n;
    UINT32 modck_H = sysModckHGet ();
    UINT32 modck13 = sysModck13Get ();

    for (n=0; modckH_modck13[n].coreFreq != END_OF_TABLE ;n++)
        {
        if ((modckH_modck13[n].modck_h == modck_H) && 
            (modckH_modck13[n].modck13 == modck13))
            {
            return  modckH_modck13[n].cpmFreq;
            }
        }

    return ERROR;
#endif /* HARDCODED_FREQ_PARMS */
    }

/***********************************************************************
*
* sysCoreFreqGet - determines the Core operating frequency
*
* This routine determines the Core operating frequency.It use MODCK_H
* and MODCK[1-3] to match the entry in the modckH_modck13 table.
*
* NOTE: See page 9-2 in Rev0 of 8260 book
*
* RETURNS:
* - Core frequency in HZ
* - ERROR only if modckH_modck13 table has something wrong.
*
*/

UINT32 sysCoreFreqGet 
    (
    void
    )
    {
#ifdef HARDCODED_FREQ_PARMS
    return CORE_FREQUENCY;
#else   
    UINT   n;
    UINT32 modck_H = sysModckHGet ();
    UINT32 modck13 = sysModck13Get ();

    for (n=0; modckH_modck13[n].coreFreq != END_OF_TABLE ;n++)
        {
        if ((modckH_modck13[n].modck_h == modck_H) && 
            (modckH_modck13[n].modck13 == modck13))
            {
            return  modckH_modck13[n].coreFreq;
            }
        }

    return ERROR;
#endif /* HARDCODED_FREQ_PARMS */
    }

/***********************************************************************
*
* sysModckHGet - determines the value of MODCK_H reset configuration value
*
* This routine determines the value of MODCK_H reset configuration value
*
* NOTE: See page 9-2 in Rev0 of 8260 book
*
* RETURNS: MODCK_H value
*
*/

UINT8 sysModckHGet 
    (
    void
    )
    {
#if 0
    UINT8  *pModck_H = (UINT8 *)HRDW_CONFIG_BYTE4;

    *pModck_H &= MODCK_H_MASK;               /* Mask the uper 4 bit */

    return *pModck_H;
#endif

    return (0x06);
    
    }

/***********************************************************************
*
* sysModck13Get - determines the value of MODCK[1-3] reset configuration value
*
* This routine determines the value of MODCK[1-3] reset configuration value
*
* NOTE:
* - see 'Clock Configuration Modes' 8260 Manual
* - SCB do not support this routine, so return fix value.
*
* RETURNS: MODCK[1-3] value
*
*/

UINT8 sysModck13Get 
    (
    void
    )
    {
    return (0x05);		
    }

/***********************************************************************
*
* sysChipRev - determines revision of Chip installed
*
* This routine determines revision of Chip installed
*
* RETURNS: Chip revision
*
*/

UINT32 sysChipRev
    (
    void
    )
    {
    UINT32  immrRegAddr = vxImmrGet ();
    UINT32  immrValue;

    immrRegAddr += 0x101A8;
    immrValue = *(UINT32 *)immrRegAddr;
    immrValue &= MASKNUM_MASK;

    return (immrValue);    
    }

/***********************************************************************   
*
* sysCpmReset - issues a CPM reset command
*
* This routine issues a CPM reset command
*
* RETURNS: N/A
*
*/

void sysCpmReset
    (
    void
    )
    {
    /* Get the location of the IMMR register.*/

    int immrVal = vxImmrGet();

    /* Wait for any previous commands to finish */

    while(*M8260_CPCR(immrVal) & M8260_CPCR_FLG)
	{
        ;
	}

    *M8260_CPCR(immrVal) =  M8260_CPCR_RESET | M8260_CPCR_FLG;

    /* See if the command has been accepted.*/

    while(*M8260_CPCR(immrVal) & M8260_CPCR_FLG)
	{
        ;
	}

    return;
    }

#if defined(INCLUDE_TIMESTAMP)

/***********************************************************************   
*
* sysMicroDelay - delay specific time in microsecond 
*
* This routine delay <us> microsecond. It can be called in any routine
* in non multi-tasking environment. This routine depend on timestamp.
*
* NOTE: 
* - in V100R001SCB board, the <us> must be in the range of (1us, 65s).
*
* RETURNS: OK, or ERROR if parameter out of range.
*
*/

STATUS sysMicroDelay
    (
     UINT32 us         /* micro second to delay */
    )
    {
    UINT32 tsTicksPerUs; 
    UINT32 tsPeriod; 
    long delayTicks = 0;
    UINT32 oldMark;
    UINT32 newMark;
    
    long temp = 0;

    /* const */

    tsTicksPerUs = sysTimestampFreq()/1000000;
    tsPeriod = sysTimestampPeriod();
    
    /* get start timestamp, mark it */

    oldMark = newMark = sysTimestampLock();
    
    /* check parameter */
    
    if(us > tsPeriod / tsTicksPerUs)
        return (ERROR);

    /* get delay counting ticks */

    delayTicks = us * tsTicksPerUs;

    /* polling and consuming time */

    while(delayTicks > 0)
        {

        /* get new timestamp */

        newMark = sysTimestampLock();

        /* decrement counting ticks */

	temp = (newMark > oldMark) ? (newMark - oldMark) :
                         (tsPeriod - oldMark + newMark);

        delayTicks -= temp;
        
        /* update old mark */

        oldMark = newMark;
        }

    return OK;
    }

#endif  /* INCLUDE_TIMESTAMP */


⌨️ 快捷键说明

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