blob: 3fd8f4e12e03d1c0ea0f038c4401d7e12a2c1e18 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2001
8*
9*****************************************************************************/
10
11/*****************************************************************************
12 *
13 * Filename:
14 * ---------
15 * uscounter.c
16 *
17 * Project:
18 * --------
19 * UMOLYA
20 *
21 * Description:
22 * ------------
23 * This function implements uscounter.
24 *
25 * Author:
26 * -------
27 * -------
28 *
29 *============================================================================
30 * HISTORY
31 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
32 *------------------------------------------------------------------------------
33 * removed!
34 * removed!
35 * removed!
36 *
37 * removed!
38 * removed!
39 * removed!
40 *
41 * removed!
42 * removed!
43 * removed!
44 *
45 * removed!
46 * removed!
47 * removed!
48 *
49 * removed!
50 * removed!
51 * removed!
52 *
53 * removed!
54 * removed!
55 * removed!
56 *
57 * removed!
58 * removed!
59 * removed!
60 *
61 * removed!
62 * removed!
63 * removed!
64 *
65 * removed!
66 * removed!
67 * removed!
68 *
69 * removed!
70 * removed!
71 * removed!
72 *
73 * removed!
74 * removed!
75 * removed!
76 *
77 * removed!
78 * removed!
79 * removed!
80 *
81 * removed!
82 * removed!
83 * removed!
84 *
85 *
86 *------------------------------------------------------------------------------
87 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
88 *============================================================================
89 ****************************************************************************/
90
91/*******************************************************************************
92 * Include header files
93 *******************************************************************************/
94
95#include "kal_public_api.h"
96#include "mips_ia_utils.h" /* need update makefle to include this header */
97#include "reg_base.h"
98#include "us_timer.h"
99#include "md2g_drv.h"
100//#include "kal_general_types.h"
101#include "sleepdrv_interface.h"
102#include "intrCtrl.h" /* for SaveAndSetIRQMask */
103#include "kal_iram_section_defs.h" /* for section declaration */
104#include "init_comm.h"
105
106#if defined(__HW_US_TIMER_SUPPORT__)
107
108/*************************************************************************
109* FUNCTION
110* USC_Start
111*
112* DESCRIPTION
113* This function starts the uscounter.
114*
115* PARAMETERS
116* none
117*
118* RETURNS
119* none
120*
121*************************************************************************/
122void USC_Start()
123{
124
125#ifdef ESIM_BUILD_CONFIG
126 HW_WRITE(USCNT_CON, 1);
127#else /* ESIM_BUILD_CONFIG */
128 /* In real target, FRC is inited in "ENABLE_FRC" of bootarm_gcc.S, we don't re-init again here.
129 "ENABLE_FRC" is an assembly macro in MD_TOPSM_private.h */
130 //MD_TOPSM_EnableFRC();
131#endif
132
133}
134
135/*************************************************************************
136* FUNCTION
137* USC_Stop
138*
139* DESCRIPTION
140* This function stops the uscounter.
141*
142* PARAMETERS
143* none
144*
145* RETURNS
146* none
147*
148*************************************************************************/
149void USC_Stop()
150{
151#ifdef ESIM_BUILD_CONFIG
152 HW_WRITE(USCNT_CON, 1);
153#else
154 kal_uint32 SHOULD_NOT_STOP_US_COUNTER = 0;
155 ASSERT(SHOULD_NOT_STOP_US_COUNTER);
156
157#endif
158}
159
160/*************************************************************************
161* FUNCTION
162* USC_Get_TimeStamp
163*
164* DESCRIPTION
165* This function calculate the frame number.
166*
167* PARAMETERS
168* none
169*
170* RETURNS
171* Frame number since system power up
172*
173*************************************************************************/
174kal_uint32 USC_Get_TimeStamp(void)
175{
176 /* Get OS timer(unit: 1ms) from FMA or OSTD source */
177 return ust_get_os_timer();
178}
179
180#if defined(MT6297) || defined(MT6885) || defined(MT6873) || defined(MT6853) || defined(CHIP10992)/* APOLLO or PETRUS or MARGAUX or MOUTON or COLGIN */
181void ust_us_busyloop(kal_uint32 us)
182{
183 kal_uint32 t1, t2, t3, zerocount = 0xFFFFF;
184
185 if ((us) == 0) {return;}
186
187 t1 = ust_get_current_time_source();
188
189 do{
190 do {
191 t2 = ust_get_current_time();
192 if (t1 == t2) { zerocount--; }
193 else if (ust_us_duration(t1, t2) >= (us)) { break; }
194 else
195 {
196 #if defined(__MD93__)||defined(__MD95__)||defined(MT6297_IA)
197 /* IA keep old design. */
198 #else
199 miu_relinquish();/*Release Pipeline*/
200 #endif
201 }
202 } while (zerocount);
203
204 if(0==zerocount)
205 {
206 kal_uint32 FRC_IS_NOT_INIT = 0;
207 ASSERT(FRC_IS_NOT_INIT);
208 }
209
210 t3 = ust_get_current_time_source();
211 }while (ust_us_duration(t1, t3) < (us));
212
213}
214#else /* PALMER and later */
215void ust_us_busyloop(kal_uint32 us)
216{
217 kal_uint32 t1, t2, zerocount = 0xFFFFF;
218
219 if ((us) == 0) {return;}
220
221 t1 = ust_get_current_time();
222
223 do {
224 t2 = ust_get_current_time();
225 if (t1 == t2) { zerocount--; }
226 else if (ust_us_duration(t1, t2) >= (us)) { break; }
227 else
228 {
229 #if defined(__MD93__)||defined(__MD95__)||defined(MT6297_IA)
230 /* IA keep old design. */
231 #else
232 miu_relinquish();/*Release Pipeline*/
233 #endif
234 }
235 } while (zerocount);
236
237 if(0==zerocount)
238 {
239 kal_uint32 FRC_IS_NOT_INIT = 0;
240 ASSERT(FRC_IS_NOT_INIT);
241 }
242}
243#endif
244
245#endif //__HW_US_TIMER_SUPPORT__
246