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

📄 debugtimer.c

📁 CIRRUS 公司EP93XX系列CPU的WINCE下的BSP
💻 C
字号:
//************************************************************************
//                                                                      
// Filename: debugtimer.c
//                                                                      
// Description: Debugtimer routines.  Need to get this in a seperate file
//              from halether since halether cannont be included in the
//              release version of the code.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to 
// use this source code. For a copy of the EULA, please see the 
// LICENSE.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2002, All Rights Reserved                       
//                                                                      
//************************************************************************
#include <windows.h>
#include <hwdefs.h>
#include <clocks.h>
#include <debugtimer.h>




//****************************************************************************
// TimerInit
//****************************************************************************
// Initialize the timer.
//
void  DebugTimerInit(void)
{
    *TIM_DEBUGVALUEHIGH = 0;            
    *TIM_DEBUGVALUEHIGH = DEBUGVALUEHIGH_ENABLE;
}

//****************************************************************************
// GetSystemTimeInMsec
//****************************************************************************
// 
DWORD GetSystemTimeInMsec(void) 
{          
    DWORD dwValue;

    dwValue = *TIM_DEBUGVALUELOW;
    dwValue >>= 10;                 


    // div by 1024 to get msec from usec (should really use
    // 1000 instead of 1024, but it is close enough
    dwValue|= (*TIM_DEBUGVALUEHIGH & DEBUGVALUEHIGH_MASK)<<22;
    return dwValue;
}

//****************************************************************************
// GetSystemTimeInUSec
//****************************************************************************
// 
ULONGLONG GetSystemTimeInUSec(void) 
{          
    volatile LARGE_INTEGER liValue;
    
    //
    // Must read the low value first.
    //
    liValue.LowPart = (ULONG)*TIM_DEBUGVALUELOW;
    liValue.HighPart = (ULONG)(*TIM_DEBUGVALUEHIGH & DEBUGVALUEHIGH_MASK);

    return liValue.QuadPart;
}



//****************************************************************************
// DelayInMsec
//****************************************************************************
// Delay a certain number of milliseconds.
// 
//
//
void DelayInMsec(DWORD msec)
{
    DWORD passed, startTime;

    startTime=GetSystemTimeInMsec();
    passed=0;
    
    //
    // Get stuck in this loop until 
    //
    while ( passed < msec) 
    {
       passed = GetSystemTimeInMsec()-startTime;
    }
}

//****************************************************************************
// DelayInuSec
//****************************************************************************
// Delay a certain number of microseconds.
// 
//
//
void DelayInuSec(DWORD uS)
{
    DWORD passed, startTime;

    startTime= *TIM_DEBUGVALUELOW;
    passed=0;
    
    //
    // Get stuck in this loop until 
    //
    while ( passed < uS) 
    {
       passed = (*TIM_DEBUGVALUELOW - startTime);
    }
}


//------------------------------------------------------------------------------
//
//  OEMQueryPerformanceCounter
//  
//      The OEMQueryPerformanceCounter function retrieves the current value of 
//      the high-resolution performance counter, if one exists. 
//  
//  BOOL QueryPerformanceCounter(
//  
//      LARGE_INTEGER  *lpliPerformanceCount    // address of current counter value
//     );   
//  
//  Parameters
//  
//  lpliPerformanceCount
//  
//      Points to a variable that the function sets, in counts, to the current 
//      performance-counter value. If the installed hardware does not support 
//      a high-resolution performance counter, this parameter can be to zero. 
//  
//  Return Value
//  
//      If the installed hardware supports a high-resolution performance 
//      counter, the return value is TRUE.
//      If the installed hardware does not support a high-resolution 
//      performance counter, the return value is FALSE.   
//  
//  If this function is implemented by the OEM, the pointer pQueryPerformanceCounter
//  should be initialized as follows:
//  
//  BOOL (*pQueryPerformanceCounter)(LARGE_INTEGER *lpliPerformanceCount)=OEMQueryPerformanceCounter;
//
//------------------------------------------------------------------------------
BOOL 
OEMQueryPerformanceCounter(
    LARGE_INTEGER *lpliPerformanceCount
    )
{
    lpliPerformanceCount->QuadPart = (LONGLONG)GetSystemTimeInUSec();    
    return TRUE;
}



//------------------------------------------------------------------------------
//
//  OEMQueryPerformanceFrequency
//  
//      The OEMQueryPerformanceFrequency function retrieves the frequency of 
//      the high-resolution performance counter, if one exists. 
//  
//  BOOL OEMQueryPerformanceFrequency(
//  
//      LARGE_INTEGER  *lpliPerformanceFreq     // address of current frequency
//     );   
//  
//  Parameters
//  
//  lpliPerformanceFreq
//  
//      Points to a variable that the function sets, in counts per second, to 
//      the current performance-counter frequency. If the installed hardware 
//      does not support a high-resolution performance counter, this parameter
//      can be to zero. 
//  
//  Return Value
//  
//      If the installed hardware supports a high-resolution performance 
//      counter, the return value is TRUE.
//      If the installed hardware does not support a high-resolution 
//      performance counter, the return value is FALSE.
//  
//  If this function is implemented by the OEM, the pointer pQueryPerformanceFrequency
//  should be initialized as follows:
//  
//  BOOL (*pQueryPerformanceFrequency)(LARGE_INTEGER *lpPerformanceFrequency)=OEMQueryPerformanceFrequency;
//
//------------------------------------------------------------------------------
BOOL 
OEMQueryPerformanceFrequency(
    LARGE_INTEGER *lpliPerformanceFreq
    ) 
{
    lpliPerformanceFreq->HighPart = 0;
    lpliPerformanceFreq->LowPart  = TIMER_DEBUG_FREQ;
    return TRUE;
}

//
// set pointers to OEM functions
//
BOOL (*pQueryPerformanceCounter)(LARGE_INTEGER *lpliPerformanceCount)=OEMQueryPerformanceCounter;
BOOL (*pQueryPerformanceFrequency)(LARGE_INTEGER *lpliPerformanceFreq)=OEMQueryPerformanceFrequency;

⌨️ 快捷键说明

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