blob: 3fd8f4e12e03d1c0ea0f038c4401d7e12a2c1e18 [file] [log] [blame]
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2001
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* uscounter.c
*
* Project:
* --------
* UMOLYA
*
* Description:
* ------------
* This function implements uscounter.
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
/*******************************************************************************
* Include header files
*******************************************************************************/
#include "kal_public_api.h"
#include "mips_ia_utils.h" /* need update makefle to include this header */
#include "reg_base.h"
#include "us_timer.h"
#include "md2g_drv.h"
//#include "kal_general_types.h"
#include "sleepdrv_interface.h"
#include "intrCtrl.h" /* for SaveAndSetIRQMask */
#include "kal_iram_section_defs.h" /* for section declaration */
#include "init_comm.h"
#if defined(__HW_US_TIMER_SUPPORT__)
/*************************************************************************
* FUNCTION
* USC_Start
*
* DESCRIPTION
* This function starts the uscounter.
*
* PARAMETERS
* none
*
* RETURNS
* none
*
*************************************************************************/
void USC_Start()
{
#ifdef ESIM_BUILD_CONFIG
HW_WRITE(USCNT_CON, 1);
#else /* ESIM_BUILD_CONFIG */
/* In real target, FRC is inited in "ENABLE_FRC" of bootarm_gcc.S, we don't re-init again here.
"ENABLE_FRC" is an assembly macro in MD_TOPSM_private.h */
//MD_TOPSM_EnableFRC();
#endif
}
/*************************************************************************
* FUNCTION
* USC_Stop
*
* DESCRIPTION
* This function stops the uscounter.
*
* PARAMETERS
* none
*
* RETURNS
* none
*
*************************************************************************/
void USC_Stop()
{
#ifdef ESIM_BUILD_CONFIG
HW_WRITE(USCNT_CON, 1);
#else
kal_uint32 SHOULD_NOT_STOP_US_COUNTER = 0;
ASSERT(SHOULD_NOT_STOP_US_COUNTER);
#endif
}
/*************************************************************************
* FUNCTION
* USC_Get_TimeStamp
*
* DESCRIPTION
* This function calculate the frame number.
*
* PARAMETERS
* none
*
* RETURNS
* Frame number since system power up
*
*************************************************************************/
kal_uint32 USC_Get_TimeStamp(void)
{
/* Get OS timer(unit: 1ms) from FMA or OSTD source */
return ust_get_os_timer();
}
#if defined(MT6297) || defined(MT6885) || defined(MT6873) || defined(MT6853) || defined(CHIP10992)/* APOLLO or PETRUS or MARGAUX or MOUTON or COLGIN */
void ust_us_busyloop(kal_uint32 us)
{
kal_uint32 t1, t2, t3, zerocount = 0xFFFFF;
if ((us) == 0) {return;}
t1 = ust_get_current_time_source();
do{
do {
t2 = ust_get_current_time();
if (t1 == t2) { zerocount--; }
else if (ust_us_duration(t1, t2) >= (us)) { break; }
else
{
#if defined(__MD93__)||defined(__MD95__)||defined(MT6297_IA)
/* IA keep old design. */
#else
miu_relinquish();/*Release Pipeline*/
#endif
}
} while (zerocount);
if(0==zerocount)
{
kal_uint32 FRC_IS_NOT_INIT = 0;
ASSERT(FRC_IS_NOT_INIT);
}
t3 = ust_get_current_time_source();
}while (ust_us_duration(t1, t3) < (us));
}
#else /* PALMER and later */
void ust_us_busyloop(kal_uint32 us)
{
kal_uint32 t1, t2, zerocount = 0xFFFFF;
if ((us) == 0) {return;}
t1 = ust_get_current_time();
do {
t2 = ust_get_current_time();
if (t1 == t2) { zerocount--; }
else if (ust_us_duration(t1, t2) >= (us)) { break; }
else
{
#if defined(__MD93__)||defined(__MD95__)||defined(MT6297_IA)
/* IA keep old design. */
#else
miu_relinquish();/*Release Pipeline*/
#endif
}
} while (zerocount);
if(0==zerocount)
{
kal_uint32 FRC_IS_NOT_INIT = 0;
ASSERT(FRC_IS_NOT_INIT);
}
}
#endif
#endif //__HW_US_TIMER_SUPPORT__