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

📄 cotulla.c

📁 pxa27x下rtc程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under
**  license and may only be used or copied in accordance with the terms of the
**  license. The information in this file is furnished for informational use
**  only, is subject to change without notice, and should not be construed as
**  a commitment by Intel Corporation. Intel Corporation assumes no
**  responsibility or liability for any errors or inaccuracies that may appear
**  in this document or any software that may be provided in association with
**  this document.
**  Except as permitted by such license, no part of this document may be
**  reproduced, stored in a retrieval system, or transmitted in any form or by
**  any means without the express written consent of Intel Corporation.
**
**  FILENAME:       cotulla.c
**
**  PURPOSE:        <Module description here>
**
**  LAST MODIFIED:  01/12/2001
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/
#include <stdio.h>
#include "globals.h"
#include "systypes.h"
#include "menu.h"
#include "dm_errors.h"
#include "dm_dbghistory.h"
#include "xllp_defs.h"
#include "cotulla.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "xsffuart.h"
#include "xsbtuart.h"
#include "xsstuart.h"
#include "XsOst.h"
#include "XsIntCtrlApi.h"
#include "XsLcdController.h"
#include "XsGpioApi.h"
#include "XsDmaApi.h"
#include "XsClkMgr.h"
#include "Ac97MixerRegsApi.h"
#include "XsAc97CtrlApi.h"
#include "XsSsp.h"
#include "XsIcp.h"
#include "boardControl.h"
#include "xllp_udc.h"
#include "xsudc.h"
#include "MmcSd.h"
#include "XsPcmciaApi.h"
#include "XsMslDcs.h"
#include "XsUsbHostDrv.h"
#include "xllp_ost.h"
#include "xllp_rtc.h"

#include "xsrtc.h"


/*
*******************************************************************************
*
* FUNCTION:
*    SA_NonCacheableAddress()
*
* DESCRIPTION:
*    This really belongs in with the MMU code. Return a pointer to the
*    same memory location in non cacheable space. Use with care! Double mapped
*    memory location coresident in the cache are NOT automatically coherent.
*
* INPUT PARAMETERS:
*    PVOID vaP - Pointer to the Virtual Address.
*
* RETURNS:
*    PVOID - Physical address of specified Virtual Address.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    VirtualToPhysical
*
* CALLED BY:
*    DM device drivers and test code.
*
* PROTOTYPE:
*    PVOID SA_NonCacheableAddress (PVOID vaP);
*
*******************************************************************************
*/
PVOID SA_NonCacheableAddress (PVOID vaP)
{
    UINT  pa = 0;

    VirtualToPhysical(vaP, &pa);
    return ((PVOID)pa);
}


// wrapper for XsGetClockRate
void KXsGetClockRate(PVOID arg, PCHAR param)
{
    XsGetClockRate();
}


/*
*******************************************************************************
*
* FUNCTION:
*    XsGetClockRate()
*
* DESCRIPTION:
*    Return the current clock rate by using the computation in 
*	 XsGetClockRateString. However, we will try to infer what the 
*	 turbo frequency is too. This will also print instructions for 
*    where to put a scope probe to measure any real clocks. 
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    INT - Dummy return 
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    XsGetClockRateString.
*
* CALLED BY:
*    command prompt
*
* PROTOTYPE:
*    INT XsGetClockRate(VOID);
*
*******************************************************************************
*/
INT XsGetClockRate(void)
{
    UINT32 stopCount;
    UINT32 numLoops = 0;
    UINT32 i;
    
    //volatile P_XLLP_OST_T ostReg = (P_XLLP_OST_T ) OST_REGISTER_BASE;
	volatile P_XLLP_RTC_T RTCControlRegsP = (P_XLLP_RTC_T)RTC_REGISTER_BASE;
    
    XsGetClockRateString();
    
    printf("\r\nMeasure SDCLK at R2 on the PXA27x Processor Card. \r\n");
    printf("The frequency should be as listed above.\r\n");
    printf("Please wait for empirical Turbo frequency estimate....\r\n");
    
    // zero the count register
    //ostReg->oscr0 = 0;
    RTCControlRegsP->swcr = 0;	 // clear the stopwatch

    stopCount = RTCControlRegsP->swcr + 0x180; // about 3 seconds
    printf("register start = %x, register finish = %x\r\n", (UINT32)RTCControlRegsP->swcr, stopCount);
    RTCControlRegsP->rtsr |= XLLP_RTSR_SWCE; // enable the stopwatch

    do
    {
    	for(i = 0; i< 10000; i++)
    	{
    		numLoops++;    	
    	}
        
    } while (RTCControlRegsP->swcr < stopCount); 
    
    printf("\r\n Loop Count = %d, swcr register = %x\r\n", numLoops, (UINT32)RTCControlRegsP->swcr);
    
    return 0;
}

/*
*******************************************************************************
*
* FUNCTION:
*    XsGetClockRateString()
*
* DESCRIPTION:
*    Return the clock rate as a string for display
*
* INPUT PARAMETERS:
*    
*
* RETURNS:
*   .
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    
*
* CALLED BY:
* 
*
* PROTOTYPE:
*
*
*******************************************************************************
*/
VOID XsGetClockRateString ()
{     

    UINT currentFreqConfig;
    UINT32 crystalF = 13; //in MHz
    UINT32 coreFreq;
    UINT32 runFreq; 
    UINT32 sysBusFreq;
    UINT32 sdclkFreq;
    UINT32 lValue;
    UINT32 nValue;
    UINT32 memClkFreq;
    BOOL turboBit = FALSE;
    BOOL fbBit = FALSE;   // fast bus bit
    BOOL aBit = FALSE;    // A Bit
    BOOL sdBit = FALSE;   // SDClk bit

    UINT32 lValueMask = 0x1F;
    UINT32 nValueMask = 0x1E0;
    UINT32 turboMask = 0x200;
    UINT32 fbMask    = 0x400;
    UINT32 aBitMask  = 0x800;
    UINT32 sdMask    = 0x1000;
     

/*
 Call GetFreqConfig assembly routine to get the packed data which is packed as
 follows:
          bit 0-4    = value of L from the CCSR register
          bit 5-8    = value of N from the CCSR register (turbo multiplier)
          bit 9      = Turbo bit from the CLKCFG register
          bit 10      = Fast Bus bit from the CLKCFG register
          bit 11     = A bit from the CCCR register
          bit 12     = SDCLK from the MDREFR register
		
*/

    currentFreqConfig = xlli_getFreq();

    if (currentFreqConfig & turboMask) turboBit = TRUE;
    if (currentFreqConfig & fbMask) fbBit = TRUE;
    if (currentFreqConfig & aBitMask) aBit = TRUE;
    if (currentFreqConfig & sdMask) sdBit = TRUE;
    
    // compute the core frequency

    lValue = currentFreqConfig & lValueMask;
    nValue = (currentFreqConfig & nValueMask) >> 5;
    runFreq = lValue * crystalF;


    if (turboBit)
    {
        coreFreq = (runFreq * nValue)/2;
    }
    else
    {
        coreFreq = runFreq;
    }
    
   
    // compute the sdclk speed and the system bus
    
    if (aBit) // system bus tracks the run frequency
    {
        if (fbBit)
        {
            sysBusFreq = memClkFreq = runFreq;
        }
        else 
        {
            sysBusFreq = memClkFreq = runFreq/2;
        }   
   }
    else  // system bus has a disconnected ratio to the run frequency
    {
        if (fbBit)
        {
            if ((2 <= lValue) && (lValue <= 16)) sysBusFreq = runFreq;
            if ((17 <= lValue) && (lValue <= 31)) sysBusFreq = runFreq/2;
        }
        else
        {
            sysBusFreq = runFreq/2;
        }

        if ((2 <= lValue) && (lValue <= 10)) memClkFreq = sysBusFreq;
        if ((11 <= lValue) && (lValue <= 20)) memClkFreq = sysBusFreq/2;
        if ((21 <= lValue) && (lValue <= 31)) memClkFreq = sysBusFreq/4;
    }
    
    // Whatever the memclk frequency works out to, the sdbit set will halve it. 
    
    if (sdBit)
    {
        sdclkFreq = memClkFreq/2;
    }
    else
    {
        sdclkFreq = memClkFreq;
    }     

    printf("Speed:             Core=%d MHz, SDCLK=%d MHz, SysBus=%d MHz, MemBus=%d MHz\r\n",
            coreFreq, sdclkFreq, sysBusFreq, memClkFreq);

}

/*
*******************************************************************************
*
* FUNCTION:
*   XsGetCpuTrademark()
*
* DESCRIPTION:
*    Return the processor trademark
*
* INPUT PARAMETERS:
*    VOID
*
* RETURNS:
*    PCHAR - Pointer to string.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    GetCpuVersion
*
* CALLED BY:
*    DM_DisplayVersion
*
* PROTOTYPE:
*    PCHAR XsGetCpuTrademark(VOID);
*
*******************************************************************************
*/
PCHAR XsGetCpuTrademark()
{
    UINT CpuVersion = 0;

    // Retrieve the CPU version information
    CpuVersion = GetCpuVersion();

    switch (CPU_TRADEMARK(CpuVersion))
    {
        case 0x69:
            return "Intel Corporation";
        default:
            return "";
    }
}

/*
*******************************************************************************
*
* FUNCTION:
*    XsGetCpuArchitecture()
*
* DESCRIPTION:
*    Return the CPU architecture type
*
* INPUT PARAMETERS:
*    VOID
*
* RETURNS:
*    PCHAR - Pointer to string.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    GetCpuVersion
*
* CALLED BY:
*    DM_DisplayVersion
*
* PROTOTYPE:
*    PCHAR XsGetCpuArchitecture()
*
*******************************************************************************
*/
PCHAR XsGetCpuArchitecture()
{
    UINT CpuVersion = 0;

    // Retrieve the CPU version information
    CpuVersion = GetCpuVersion();

    switch (CPU_ARCH_VER(CpuVersion))
    {
        case 0x05:
            return "ARM Architecture version 5TE";
        default:
            return "";
    }
}

/*
*******************************************************************************
*
* FUNCTION:
*    XsGetCpuCoreGeneration()
*
* DESCRIPTION:
*    Return the CPU core generation
*
* INPUT PARAMETERS:
*    VOID
*
* RETURNS:
*    PCHAR - Pointer to string.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    GetCpuVersion
*
* CALLED BY:
*    DM_DisplayVersion
*
* PROTOTYPE:
*   PCHAR XsGetCpuCoreGeneration()
*
*******************************************************************************
*/
PCHAR XsGetCpuCoreGeneration()
{
    UINT CpuVersion = 0;

    // Retrieve the CPU version information
    CpuVersion = GetCpuVersion();
    switch (CPU_CORE_GEN(CpuVersion))
    {
        case 0x01:    // PXA2xx
            return "Intel(R) XScale(TM) microarchitecture 1st generation";
        case 0x02:    // Bulverde
            return "Intel(R) XScale(TM) microarchitecture 2nd generation";
        default:
            return "";
    }
}

/*
*******************************************************************************
*
* FUNCTION:
*    XsGetCpuCoreRevision()
*
* DESCRIPTION:
*    Return the CPU core revision
*
* INPUT PARAMETERS:
*    VOID
*
* RETURNS:
*    PCHAR - Pointer to string.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    GetCpuVersion
*
* CALLED BY:
*    DM_DisplayVersion
*
* PROTOTYPE:
*    PCHAR XsGetCpuCoreRevision()
*
*******************************************************************************
*/
PCHAR XsGetCpuCoreRevision()
{
    UINT CpuVersion = 0;

    // Retrieve the CPU version information
    CpuVersion = GetCpuVersion();
    // printf("CORE_REV %x\r\n", CPU_CORE_REV(CpuVersion));
    switch (CPU_CORE_REV(CpuVersion))
    {
        case 0x00:
            return "Revision 1";
        case 0x02:
            return "Revision 2";

        default:
            return "";
    }
}

/*
*******************************************************************************
*
* FUNCTION:
*   XsGetCpuProductNumber(BOOL flag)
*
* DESCRIPTION:
*    Return the CPU product number
*
* INPUT PARAMETERS:
*    VOID
*
* RETURNS:
*    PCHAR - Pointer to string.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.

⌨️ 快捷键说明

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