sl@0
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\realtime\d_latncy.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "platform.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
#if defined(__MEIG__)
|
sl@0
|
21 |
#include <cl7211.h>
|
sl@0
|
22 |
#elif defined(__MAWD__)
|
sl@0
|
23 |
#include <windermere.h>
|
sl@0
|
24 |
#elif defined(__MISA__)
|
sl@0
|
25 |
#include <sa1100.h>
|
sl@0
|
26 |
#elif defined(__MCOT__)
|
sl@0
|
27 |
#include <cotulla.h>
|
sl@0
|
28 |
#elif defined(__MI920__) || defined(__NI1136__)
|
sl@0
|
29 |
#include <integratorap.h>
|
sl@0
|
30 |
//#define FREE_RUNNING_MODE // runs the millisecond timer in free running mode
|
sl@0
|
31 |
#elif defined(__IS_OMAP1610__)
|
sl@0
|
32 |
#include <omap_timer.h>
|
sl@0
|
33 |
#include <omap_plat.h>
|
sl@0
|
34 |
#elif defined(__IS_OMAP2420__) || defined(__WAKEUP_3430__)
|
sl@0
|
35 |
#include <omap_hw.h>
|
sl@0
|
36 |
#include <shared_instrtimer.h>
|
sl@0
|
37 |
#elif defined(__EPOC32__) && defined(__CPU_X86)
|
sl@0
|
38 |
#include <x86.h>
|
sl@0
|
39 |
#include <x86pc.h>
|
sl@0
|
40 |
#elif defined(__RVEMUBOARD__)
|
sl@0
|
41 |
#include <rvemuboard.h>
|
sl@0
|
42 |
#elif defined(__NE1_TB__)
|
sl@0
|
43 |
#include <upd35001_timer.h>
|
sl@0
|
44 |
#endif
|
sl@0
|
45 |
|
sl@0
|
46 |
#ifdef __CPU_ARM
|
sl@0
|
47 |
#include <arm.h>
|
sl@0
|
48 |
#endif
|
sl@0
|
49 |
|
sl@0
|
50 |
#include <kernel/kern_priv.h> //temporary
|
sl@0
|
51 |
#include "d_latncy.h"
|
sl@0
|
52 |
|
sl@0
|
53 |
_LIT(KLddName,"Latency");
|
sl@0
|
54 |
_LIT(KThreadName,"LatencyThreadK");
|
sl@0
|
55 |
|
sl@0
|
56 |
#if defined(__MEIG__)
|
sl@0
|
57 |
const TInt KTickPeriodMs=2;
|
sl@0
|
58 |
const TInt KTicksPerMillisecond=512;
|
sl@0
|
59 |
#elif defined(__MAWD__)
|
sl@0
|
60 |
const TInt KTickPeriodMs=1;
|
sl@0
|
61 |
const TInt KTicksPerMillisecond=512;
|
sl@0
|
62 |
#elif defined(__MISA__) || defined(__MCOT__)
|
sl@0
|
63 |
const TInt KTicksPerMillisecond=3686;
|
sl@0
|
64 |
const TInt KOstTicks=3685; // not quite 1ms, so it goes in and out of phase with ms timer
|
sl@0
|
65 |
TUint TriggerTime;
|
sl@0
|
66 |
#elif defined(__MI920__) || defined(__NI1136__)
|
sl@0
|
67 |
const TInt KTickPeriodMs=1;
|
sl@0
|
68 |
#if defined(__MI920__) || defined(__NI1136__)
|
sl@0
|
69 |
#ifdef FREE_RUNNING_MODE
|
sl@0
|
70 |
const TInt KTicksPerMillisecond=1500;
|
sl@0
|
71 |
#else
|
sl@0
|
72 |
const TInt KTicksPerMillisecond=24000;
|
sl@0
|
73 |
#endif
|
sl@0
|
74 |
#endif
|
sl@0
|
75 |
#elif defined(__IS_OMAP1610__)
|
sl@0
|
76 |
const TInt KTickPeriodMs=1;
|
sl@0
|
77 |
TInt KTicksPerMillisecond = TOmapPlat::GetInputClk()/32000;
|
sl@0
|
78 |
#elif defined(__IS_OMAP2420__) || defined(__WAKEUP_3430__)
|
sl@0
|
79 |
const TInt KTickPeriodMs=1; // defined for compatibility but not used (ignored)
|
sl@0
|
80 |
const TInt KTicksPerMillisecond = 12000; // Hard coded (12Mhz)
|
sl@0
|
81 |
#elif defined(__EPOC32__) && defined(__CPU_X86)
|
sl@0
|
82 |
const TInt KTickPeriodMs=1;
|
sl@0
|
83 |
const TInt KTicksPerMillisecond=1193;
|
sl@0
|
84 |
#elif defined(__RVEMUBOARD__)
|
sl@0
|
85 |
const TInt KTickPeriodMs=1;
|
sl@0
|
86 |
const TInt KTicksPerMillisecond=1000;
|
sl@0
|
87 |
#elif defined(__NE1_TB__)
|
sl@0
|
88 |
const TInt KTickPeriodMs=1;
|
sl@0
|
89 |
const TInt KTicksPerMillisecond=66667;
|
sl@0
|
90 |
#endif
|
sl@0
|
91 |
|
sl@0
|
92 |
#ifdef _DEBUG
|
sl@0
|
93 |
const TInt KFudgeFactor=1;
|
sl@0
|
94 |
#else
|
sl@0
|
95 |
const TInt KFudgeFactor=1;
|
sl@0
|
96 |
#endif
|
sl@0
|
97 |
|
sl@0
|
98 |
class DDeviceLatency : public DLogicalDevice
|
sl@0
|
99 |
{
|
sl@0
|
100 |
public:
|
sl@0
|
101 |
DDeviceLatency();
|
sl@0
|
102 |
virtual TInt Install();
|
sl@0
|
103 |
virtual void GetCaps(TDes8& aDes) const;
|
sl@0
|
104 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
sl@0
|
105 |
};
|
sl@0
|
106 |
|
sl@0
|
107 |
class DLatencyPowerHandler : public DPowerHandler
|
sl@0
|
108 |
{
|
sl@0
|
109 |
public: // from DPOwerHandler
|
sl@0
|
110 |
void PowerUp();
|
sl@0
|
111 |
void PowerDown(TPowerState);
|
sl@0
|
112 |
public:
|
sl@0
|
113 |
DLatencyPowerHandler(DLatency* aChannel);
|
sl@0
|
114 |
public:
|
sl@0
|
115 |
DLatency* iChannel;
|
sl@0
|
116 |
};
|
sl@0
|
117 |
|
sl@0
|
118 |
|
sl@0
|
119 |
|
sl@0
|
120 |
inline TUint DLatency::Ticks()
|
sl@0
|
121 |
{
|
sl@0
|
122 |
#if defined(__MEIG__)
|
sl@0
|
123 |
return KTicksPerMillisecond-(*(volatile TUint*)(KEigerTimer2Data16+KEigerBaseAddress)&0xffff);
|
sl@0
|
124 |
#elif defined(__MAWD__)
|
sl@0
|
125 |
return KTicksPerMillisecond-(*(volatile TUint*)(KWindTimer2Value16+KWindBaseAddress)&0xffff);
|
sl@0
|
126 |
#elif defined(__MISA__) || defined(__MCOT__)
|
sl@0
|
127 |
return *(volatile TUint*)KHwRwOstOscr-iTriggerTime;
|
sl@0
|
128 |
#elif defined(__MI920__) || defined(__NI1136__)
|
sl@0
|
129 |
return KTicksPerMillisecond-(*(volatile TUint*)(KHwCounterTimer2+KHoTimerValue)&0xffff);
|
sl@0
|
130 |
#elif defined(__IS_OMAP1610__)
|
sl@0
|
131 |
return KTicksPerMillisecond - *(volatile TUint*)(KHwBaseOSTimer1Reg+KHoOSTimer_READ_TIM);
|
sl@0
|
132 |
#elif defined(__IS_OMAP2420__) || defined(__WAKEUP_3430__)
|
sl@0
|
133 |
return (*(volatile TUint*)(iTimerInfo.iAddress + KHoGpTimer_TCRR)) - iTimerLoadValue;
|
sl@0
|
134 |
#elif defined(__X86PC__)
|
sl@0
|
135 |
return 1194 - __HwTimer();
|
sl@0
|
136 |
#elif defined(__RVEMUBOARD__)
|
sl@0
|
137 |
return KTicksPerMillisecond-(*(volatile TUint*)(KHwCounterTimer1+KHoTimerValue)&0xffff);
|
sl@0
|
138 |
#elif defined(__NE1_TB__)
|
sl@0
|
139 |
return NETimer::Timer(0).iTimerCount; // counts up, reset timer + interrupt on match
|
sl@0
|
140 |
#endif
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
#if !defined(__SMP__)
|
sl@0
|
144 |
#if !defined(__EPOC32__) || !defined(__CPU_X86)
|
sl@0
|
145 |
extern TUint IntStackPtr();
|
sl@0
|
146 |
#endif
|
sl@0
|
147 |
#endif
|
sl@0
|
148 |
|
sl@0
|
149 |
DECLARE_STANDARD_LDD()
|
sl@0
|
150 |
{
|
sl@0
|
151 |
return new DDeviceLatency;
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
DDeviceLatency::DDeviceLatency()
|
sl@0
|
155 |
//
|
sl@0
|
156 |
// Constructor
|
sl@0
|
157 |
//
|
sl@0
|
158 |
{
|
sl@0
|
159 |
//iParseMask=0;
|
sl@0
|
160 |
//iUnitsMask=0;
|
sl@0
|
161 |
iVersion=TVersion(1,0,1);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
TInt DDeviceLatency::Install()
|
sl@0
|
165 |
//
|
sl@0
|
166 |
// Install the device driver.
|
sl@0
|
167 |
//
|
sl@0
|
168 |
{
|
sl@0
|
169 |
TInt r=SetName(&KLddName);
|
sl@0
|
170 |
return r;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
void DDeviceLatency::GetCaps(TDes8& aDes) const
|
sl@0
|
174 |
//
|
sl@0
|
175 |
// Return the Comm capabilities.
|
sl@0
|
176 |
//
|
sl@0
|
177 |
{
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
TInt DDeviceLatency::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
181 |
//
|
sl@0
|
182 |
// Create a channel on the device.
|
sl@0
|
183 |
//
|
sl@0
|
184 |
{
|
sl@0
|
185 |
aChannel=new DLatency;
|
sl@0
|
186 |
return aChannel?KErrNone:KErrNoMemory;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
DLatency::DLatency()
|
sl@0
|
190 |
: iMsCallBack(MsCallBack,this),
|
sl@0
|
191 |
iMsDfc(MsDfc,this,NULL,1)
|
sl@0
|
192 |
//
|
sl@0
|
193 |
// Constructor
|
sl@0
|
194 |
//
|
sl@0
|
195 |
{
|
sl@0
|
196 |
#if !defined(__SMP__)
|
sl@0
|
197 |
#if !defined(__EPOC32__) || !defined(__CPU_X86)
|
sl@0
|
198 |
iIntStackTop=(TUint*)IntStackPtr();
|
sl@0
|
199 |
#endif
|
sl@0
|
200 |
#endif
|
sl@0
|
201 |
#if defined(__MISA__) || defined(__MCOT__)
|
sl@0
|
202 |
iTickIncrement=KOstTicks*KFudgeFactor;
|
sl@0
|
203 |
#endif
|
sl@0
|
204 |
#if defined(__IS_OMAP2420__) || defined(__WAKEUP_3430__)
|
sl@0
|
205 |
iTimerInfo.iAddress = 0;
|
sl@0
|
206 |
#endif
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
DLatency::~DLatency()
|
sl@0
|
210 |
//
|
sl@0
|
211 |
// Destructor
|
sl@0
|
212 |
//
|
sl@0
|
213 |
{
|
sl@0
|
214 |
iOff = (TUint8)ETrue;
|
sl@0
|
215 |
StopTimer();
|
sl@0
|
216 |
iMsDfc.Cancel();
|
sl@0
|
217 |
|
sl@0
|
218 |
if (iRtDfcQ)
|
sl@0
|
219 |
iRtDfcQ->Destroy();
|
sl@0
|
220 |
|
sl@0
|
221 |
if (iPowerHandler)
|
sl@0
|
222 |
{
|
sl@0
|
223 |
iPowerHandler->Remove();
|
sl@0
|
224 |
delete iPowerHandler;
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@0
|
227 |
Kern::SafeClose((DObject*&)iClient, NULL);
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
TInt DLatency::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
|
sl@0
|
231 |
//
|
sl@0
|
232 |
// Create the channel from the passed info.
|
sl@0
|
233 |
//
|
sl@0
|
234 |
{
|
sl@0
|
235 |
if (!Kern::QueryVersionSupported(TVersion(1,0,1),aVer))
|
sl@0
|
236 |
return KErrNotSupported;
|
sl@0
|
237 |
|
sl@0
|
238 |
// create the power handler
|
sl@0
|
239 |
iPowerHandler = new DLatencyPowerHandler(this);
|
sl@0
|
240 |
if (!iPowerHandler)
|
sl@0
|
241 |
return KErrNoMemory;
|
sl@0
|
242 |
iPowerHandler->Add();
|
sl@0
|
243 |
|
sl@0
|
244 |
// Allocate a kernel thread to run the DFC
|
sl@0
|
245 |
TInt r = Kern::DynamicDfcQCreate(iRtDfcQ, KNumPriorities-1,KThreadName);
|
sl@0
|
246 |
|
sl@0
|
247 |
if (r != KErrNone)
|
sl@0
|
248 |
return r;
|
sl@0
|
249 |
|
sl@0
|
250 |
#ifdef CPU_AFFINITY_ANY
|
sl@0
|
251 |
NKern::ThreadSetCpuAffinity((NThread*)(iRtDfcQ->iThread), KCpuAffinityAny);
|
sl@0
|
252 |
#endif
|
sl@0
|
253 |
|
sl@0
|
254 |
iMsDfc.SetDfcQ(iRtDfcQ);
|
sl@0
|
255 |
iClient=&Kern::CurrentThread();
|
sl@0
|
256 |
iClient->Open();
|
sl@0
|
257 |
Kern::SetThreadPriority(KNumPriorities-2);
|
sl@0
|
258 |
return KErrNone;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
#if defined(__MISA__)
|
sl@0
|
262 |
// For SA1100/SA1110 use a separate timer on a FIQ interrupt (OST match 0)
|
sl@0
|
263 |
TInt DLatency::StartTimer()
|
sl@0
|
264 |
{
|
sl@0
|
265 |
TInt r=Interrupt::Bind(KIntIdOstMatchGeneral,MsCallBack,this);
|
sl@0
|
266 |
if (r==KErrNone)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
TSa1100::ModifyIntLevels(0,KHtIntsOstMatchGeneral); // route new timer interrupt to FIQ
|
sl@0
|
269 |
TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
|
sl@0
|
270 |
TUint oscr=TSa1100::OstData();
|
sl@0
|
271 |
iTriggerTime=oscr+KOstTicks*KFudgeFactor;
|
sl@0
|
272 |
TSa1100::SetOstMatch(KHwOstMatchGeneral,iTriggerTime);
|
sl@0
|
273 |
TSa1100::EnableOstInterrupt(KHwOstMatchGeneral);
|
sl@0
|
274 |
Interrupt::Enable(KIntIdOstMatchGeneral);
|
sl@0
|
275 |
}
|
sl@0
|
276 |
return r;
|
sl@0
|
277 |
}
|
sl@0
|
278 |
#elif defined(__MCOT__)
|
sl@0
|
279 |
// For Cotulla use a separate timer on a FIQ interrupt (OST match 0)
|
sl@0
|
280 |
TInt DLatency::StartTimer()
|
sl@0
|
281 |
{
|
sl@0
|
282 |
TInt r=Interrupt::Bind(KIntIdOstMatchGeneral,MsCallBack,this);
|
sl@0
|
283 |
if (r==KErrNone)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
TCotulla::ModifyIntLevels(0,KHtIntsOstMatchGeneral); // route new timer interrupt to FIQ
|
sl@0
|
286 |
TCotulla::SetOstMatchEOI(KHwOstMatchGeneral);
|
sl@0
|
287 |
TUint oscr=TCotulla::OstData();
|
sl@0
|
288 |
iTriggerTime=oscr+KOstTicks*KFudgeFactor;
|
sl@0
|
289 |
TCotulla::SetOstMatch(iTriggerTime,KHwOstMatchGeneral);
|
sl@0
|
290 |
TCotulla::EnableOstInterrupt(KHwOstMatchGeneral);
|
sl@0
|
291 |
Interrupt::Enable(KIntIdOstMatchGeneral);
|
sl@0
|
292 |
}
|
sl@0
|
293 |
return r;
|
sl@0
|
294 |
}
|
sl@0
|
295 |
#elif defined(__IS_OMAP2420__) || defined(__WAKEUP_3430__)
|
sl@0
|
296 |
TInt DLatency::StartTimer()
|
sl@0
|
297 |
/*
|
sl@0
|
298 |
* For OMAP2420 initialise a new timer to generate an interrupt every 1ms
|
sl@0
|
299 |
*/
|
sl@0
|
300 |
{
|
sl@0
|
301 |
__ASSERT_ALWAYS(!iTimerInfo.iAddress, Kern::Fault("D_Latncy: timer allocated twice.",
|
sl@0
|
302 |
iTimerInfo.iAddress));
|
sl@0
|
303 |
|
sl@0
|
304 |
// Get an available Timer from the system
|
sl@0
|
305 |
TInt r = OmapTimerMgr::GetTimer(iGPTimerId, iTimerInfo);
|
sl@0
|
306 |
if (KErrNone != r)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
return r;
|
sl@0
|
309 |
}
|
sl@0
|
310 |
|
sl@0
|
311 |
// Configure the timer
|
sl@0
|
312 |
r = ConfigureTimer();
|
sl@0
|
313 |
if (KErrNone != r)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
DisableTimer();
|
sl@0
|
316 |
return r;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
|
sl@0
|
319 |
// Bind to timer interrupt
|
sl@0
|
320 |
r = Interrupt::Bind(iTimerInfo.iInterruptId, MsCallBack, this);
|
sl@0
|
321 |
if (KErrNone != r)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
DisableTimer();
|
sl@0
|
324 |
return r;
|
sl@0
|
325 |
}
|
sl@0
|
326 |
|
sl@0
|
327 |
// Unmask timer IT in interrupt controller
|
sl@0
|
328 |
r = Interrupt::Enable(iTimerInfo.iInterruptId);
|
sl@0
|
329 |
if (KErrNone != r)
|
sl@0
|
330 |
{
|
sl@0
|
331 |
Interrupt::Unbind(iTimerInfo.iInterruptId);
|
sl@0
|
332 |
DisableTimer();
|
sl@0
|
333 |
return r;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
// Start timer
|
sl@0
|
337 |
TOmap::ModifyRegister32(iTimerInfo.iAddress + KHoGpTimer_TCLR, KClear32,
|
sl@0
|
338 |
KHtGpTimer_TCLR_St);
|
sl@0
|
339 |
|
sl@0
|
340 |
return KErrNone;
|
sl@0
|
341 |
}
|
sl@0
|
342 |
|
sl@0
|
343 |
void DLatency::DisableTimer()
|
sl@0
|
344 |
/*
|
sl@0
|
345 |
* Disable the interface and functional clock and mark the timer as available
|
sl@0
|
346 |
*/
|
sl@0
|
347 |
{
|
sl@0
|
348 |
// Stop timer
|
sl@0
|
349 |
TOmap::ModifyRegister32(iTimerInfo.iAddress + KHoGpTimer_TCLR,
|
sl@0
|
350 |
KHtGpTimer_TCLR_St, KClear32);
|
sl@0
|
351 |
|
sl@0
|
352 |
#if defined(__WAKEUP_3430__)
|
sl@0
|
353 |
// Disable Timer clocks using Timer framework instead of using TPRcm direct calls for 3430
|
sl@0
|
354 |
TInt r = OmapTimerMgr::DisableClocks(iGPTimerId);
|
sl@0
|
355 |
if (r != KErrNone)
|
sl@0
|
356 |
__ASSERT_ALWAYS(r, Kern::Fault("Timer clocks disable failed", 0)) ;
|
sl@0
|
357 |
#else
|
sl@0
|
358 |
// Disable timer interface clock in PRCM
|
sl@0
|
359 |
TPrcm::InterfaceClkCtrl(iTimerInfo.iPrcmDeviceId, EFalse);
|
sl@0
|
360 |
|
sl@0
|
361 |
// Disable timer functional clock in PRCM
|
sl@0
|
362 |
TPrcm::FunctionalClkCtrl(iTimerInfo.iPrcmDeviceId, EFalse);
|
sl@0
|
363 |
#endif
|
sl@0
|
364 |
|
sl@0
|
365 |
// Release the timer
|
sl@0
|
366 |
OmapTimerMgr::ReleaseTimer(iGPTimerId);
|
sl@0
|
367 |
|
sl@0
|
368 |
iTimerInfo.iAddress = 0;
|
sl@0
|
369 |
}
|
sl@0
|
370 |
|
sl@0
|
371 |
|
sl@0
|
372 |
TInt DLatency::ConfigureTimer()
|
sl@0
|
373 |
/*
|
sl@0
|
374 |
* This method will configure a timer to:
|
sl@0
|
375 |
* - run at the system clock (12Mhz)
|
sl@0
|
376 |
* - no prescaler (disable TCLR[PRE])
|
sl@0
|
377 |
* - autoreload and overflow interrupt enabled (TLDR will contain a
|
sl@0
|
378 |
* value to generate an interrupt every 1000microsec)
|
sl@0
|
379 |
*/
|
sl@0
|
380 |
{
|
sl@0
|
381 |
|
sl@0
|
382 |
#if defined(__WAKEUP_3430__)
|
sl@0
|
383 |
// Enable Timer clocks using timer framework instead of TPrcm direct calls for 3430
|
sl@0
|
384 |
TInt r = OmapTimerMgr::EnableClocks(iGPTimerId);
|
sl@0
|
385 |
if (r != KErrNone)
|
sl@0
|
386 |
__ASSERT_ALWAYS(r, Kern::Fault("Timer Clocks enable failed", 0)) ;
|
sl@0
|
387 |
|
sl@0
|
388 |
// Select the input clock to be system clock
|
sl@0
|
389 |
r = OmapTimerMgr::SetTimerClkSrc(iGPTimerId, ESysClk);
|
sl@0
|
390 |
#else
|
sl@0
|
391 |
// Enable timer interface clock in PRCM
|
sl@0
|
392 |
TPrcm::InterfaceClkCtrl(iTimerInfo.iPrcmDeviceId, ETrue, ETrue);
|
sl@0
|
393 |
// Enable timer functional clock in PRCM
|
sl@0
|
394 |
TPrcm::FunctionalClkCtrl(iTimerInfo.iPrcmDeviceId, ETrue, ETrue);
|
sl@0
|
395 |
|
sl@0
|
396 |
// Select the input clock to be system clock
|
sl@0
|
397 |
TInt r = OmapTimerMgr::SetTimerClkSrc(iGPTimerId, ESysClk);
|
sl@0
|
398 |
#endif
|
sl@0
|
399 |
|
sl@0
|
400 |
if (KErrNone != r)
|
sl@0
|
401 |
return r;
|
sl@0
|
402 |
|
sl@0
|
403 |
// Timer OCP configuration: - software reset
|
sl@0
|
404 |
TOmap::SetRegister32( iTimerInfo.iAddress + KHoGpTimerTIOCP_CFG,
|
sl@0
|
405 |
KHtGpTimer_TIOCP_CFG_SoftReset);
|
sl@0
|
406 |
|
sl@0
|
407 |
// Wait for reset to be complete
|
sl@0
|
408 |
TUint16 timeOut = 1000;
|
sl@0
|
409 |
while ( !(TOmap::Register32(iTimerInfo.iAddress + KHoGpTimer_TISTAT) &
|
sl@0
|
410 |
KHtGpTimer_TISTAT_ResetComplete)
|
sl@0
|
411 |
&& --timeOut);
|
sl@0
|
412 |
|
sl@0
|
413 |
// Check if the timer has been reset or we hit the timeout
|
sl@0
|
414 |
__ASSERT_ALWAYS((TOmap::Register32(iTimerInfo.iAddress + KHoGpTimer_TISTAT) &
|
sl@0
|
415 |
KHtGpTimer_TISTAT_ResetComplete), Kern::Fault("D_Latncy: failed to reset timer.",
|
sl@0
|
416 |
iGPTimerId));
|
sl@0
|
417 |
|
sl@0
|
418 |
// Set PRE to be 0, PTV value is ignored, AutoReload is enabled
|
sl@0
|
419 |
TOmap::SetRegister32(iTimerInfo.iAddress + KHoGpTimer_TCLR, KHtGpTimer_TCLR_AR );
|
sl@0
|
420 |
|
sl@0
|
421 |
//PTV argument is 0 because of TCLR[PRE] = 0 (prescaling disabled)
|
sl@0
|
422 |
TInt timerPTV = 0;
|
sl@0
|
423 |
|
sl@0
|
424 |
// Calculate clock frequence from the ticks per ms
|
sl@0
|
425 |
TInt timerClkSrcFreq = KTicksPerMillisecond * 1000;
|
sl@0
|
426 |
|
sl@0
|
427 |
iTimerLoadValue = OmapTimerMgr::TimerLoadValue(/*microsecs*/1000, timerClkSrcFreq, timerPTV);
|
sl@0
|
428 |
|
sl@0
|
429 |
// First, load value in TCRR and TLDR registers
|
sl@0
|
430 |
TOmap::SetRegister32(iTimerInfo.iAddress + KHoGpTimer_TCRR, iTimerLoadValue);
|
sl@0
|
431 |
TOmap::SetRegister32(iTimerInfo.iAddress + KHoGpTimer_TLDR, iTimerLoadValue);
|
sl@0
|
432 |
|
sl@0
|
433 |
// Enable overflow interrupt
|
sl@0
|
434 |
TOmap::SetRegister32(iTimerInfo.iAddress + KHoGpTimer_TIER,
|
sl@0
|
435 |
KHtGpTimer_TIER_OverFlow);
|
sl@0
|
436 |
|
sl@0
|
437 |
return KErrNone;
|
sl@0
|
438 |
}
|
sl@0
|
439 |
#else
|
sl@0
|
440 |
TInt DLatency::StartTimer()
|
sl@0
|
441 |
{
|
sl@0
|
442 |
iMsCallBack.OneShot(KTickPeriodMs*KFudgeFactor);
|
sl@0
|
443 |
return KErrNone;
|
sl@0
|
444 |
}
|
sl@0
|
445 |
#endif
|
sl@0
|
446 |
|
sl@0
|
447 |
#if defined(__MISA__)
|
sl@0
|
448 |
// For SA1100/SA1110 use a separate timer on a FIQ interrupt (OST match 0)
|
sl@0
|
449 |
void DLatency::StopTimer()
|
sl@0
|
450 |
{
|
sl@0
|
451 |
TSa1100::ModifyIntLevels(KHtIntsOstMatchGeneral,0);
|
sl@0
|
452 |
TSa1100::DisableOstInterrupt(KHwOstMatchGeneral);
|
sl@0
|
453 |
Interrupt::Disable(KIntIdOstMatchGeneral);
|
sl@0
|
454 |
Interrupt::Unbind(KIntIdOstMatchGeneral);
|
sl@0
|
455 |
TSa1100::SetOstMatchEOI(KHwOstMatchGeneral);
|
sl@0
|
456 |
}
|
sl@0
|
457 |
#elif defined(__MCOT__)
|
sl@0
|
458 |
// For Cotulla use a separate timer on a FIQ interrupt (OST match 0)
|
sl@0
|
459 |
void DLatency::StopTimer()
|
sl@0
|
460 |
{
|
sl@0
|
461 |
TCotulla::ModifyIntLevels(KHtIntsOstMatchGeneral,0);
|
sl@0
|
462 |
TCotulla::DisableOstInterrupt(KHwOstMatchGeneral);
|
sl@0
|
463 |
Interrupt::Disable(KIntIdOstMatchGeneral);
|
sl@0
|
464 |
Interrupt::Unbind(KIntIdOstMatchGeneral);
|
sl@0
|
465 |
TCotulla::SetOstMatchEOI(KHwOstMatchGeneral);
|
sl@0
|
466 |
}
|
sl@0
|
467 |
#elif defined(__IS_OMAP2420__) || defined(__WAKEUP_3430__)
|
sl@0
|
468 |
void DLatency::StopTimer()
|
sl@0
|
469 |
{
|
sl@0
|
470 |
Interrupt::Disable(iTimerInfo.iInterruptId);
|
sl@0
|
471 |
Interrupt::Unbind(iTimerInfo.iInterruptId);
|
sl@0
|
472 |
DisableTimer();
|
sl@0
|
473 |
}
|
sl@0
|
474 |
#else
|
sl@0
|
475 |
void DLatency::StopTimer()
|
sl@0
|
476 |
{
|
sl@0
|
477 |
iMsCallBack.Cancel();
|
sl@0
|
478 |
}
|
sl@0
|
479 |
#endif
|
sl@0
|
480 |
|
sl@0
|
481 |
TInt DLatency::Request(TInt aFunction, TAny* a1, TAny* a2)
|
sl@0
|
482 |
//
|
sl@0
|
483 |
// Client requests
|
sl@0
|
484 |
//
|
sl@0
|
485 |
{
|
sl@0
|
486 |
// Kern::Printf("DLatency::Request() 0x%x)\n", aFunction);
|
sl@0
|
487 |
TInt r=KErrNone;
|
sl@0
|
488 |
switch (aFunction)
|
sl@0
|
489 |
{
|
sl@0
|
490 |
case RLatency::EControlStart:
|
sl@0
|
491 |
iStarted = (TUint8)ETrue;
|
sl@0
|
492 |
StartTimer();
|
sl@0
|
493 |
break;
|
sl@0
|
494 |
case RLatency::EControlTicksPerMs:
|
sl@0
|
495 |
r=KTicksPerMillisecond;
|
sl@0
|
496 |
break;
|
sl@0
|
497 |
case RLatency::EControlGetResults:
|
sl@0
|
498 |
iResults.iUserThreadTicks = Ticks();
|
sl@0
|
499 |
kumemput32(a1, &iResults, sizeof(SLatencyResults));
|
sl@0
|
500 |
break;
|
sl@0
|
501 |
default:
|
sl@0
|
502 |
r = KErrNotSupported;
|
sl@0
|
503 |
break;
|
sl@0
|
504 |
}
|
sl@0
|
505 |
return(r);
|
sl@0
|
506 |
}
|
sl@0
|
507 |
|
sl@0
|
508 |
#ifdef __CAPTURE_EXTRAS
|
sl@0
|
509 |
extern void CaptureExtras(SLatencyResults&);
|
sl@0
|
510 |
#endif
|
sl@0
|
511 |
|
sl@0
|
512 |
#if !defined(__MISA__) && !defined(__MCOT__)
|
sl@0
|
513 |
void DLatency::MsCallBack(TAny* aPtr)
|
sl@0
|
514 |
{
|
sl@0
|
515 |
DLatency* pL = (DLatency*)aPtr;
|
sl@0
|
516 |
#if defined(__IS_OMAP2420__) || defined(__WAKEUP_3430__)
|
sl@0
|
517 |
pL->iResults.iIntTicks = pL->Ticks();
|
sl@0
|
518 |
TOmap::SetRegister32(pL->iTimerInfo.iAddress + KHoGpTimer_TISR, KHtGpTimer_TISR_OverFlow);
|
sl@0
|
519 |
#else
|
sl@0
|
520 |
pL->iResults.iIntTicks = Ticks();
|
sl@0
|
521 |
#endif
|
sl@0
|
522 |
#ifdef __CAPTURE_EXTRAS
|
sl@0
|
523 |
CaptureExtras(pL->iResults);
|
sl@0
|
524 |
#endif
|
sl@0
|
525 |
#if defined(__EPOC32__) && defined(__CPU_X86)
|
sl@0
|
526 |
pL->iResults.iIntRetAddr = X86::IrqReturnAddress();
|
sl@0
|
527 |
#elif defined(__CPU_ARM) && defined(__SMP__)
|
sl@0
|
528 |
pL->iResults.iIntRetAddr = Arm::IrqReturnAddress();
|
sl@0
|
529 |
#else
|
sl@0
|
530 |
pL->iResults.iIntRetAddr=(pL->iIntStackTop)[-1];
|
sl@0
|
531 |
#endif
|
sl@0
|
532 |
if (!pL->iOff)
|
sl@0
|
533 |
{
|
sl@0
|
534 |
pL->iMsCallBack.Again(KTickPeriodMs*KFudgeFactor);
|
sl@0
|
535 |
pL->iMsDfc.Add();
|
sl@0
|
536 |
}
|
sl@0
|
537 |
}
|
sl@0
|
538 |
#endif
|
sl@0
|
539 |
|
sl@0
|
540 |
void DLatency::MsDfc(TAny* aPtr)
|
sl@0
|
541 |
{
|
sl@0
|
542 |
DLatency* pL = (DLatency*)aPtr;
|
sl@0
|
543 |
pL->iResults.iKernThreadTicks=pL->Ticks();
|
sl@0
|
544 |
NKern::ThreadRequestSignal(&pL->iClient->iNThread);
|
sl@0
|
545 |
}
|
sl@0
|
546 |
|
sl@0
|
547 |
DLatencyPowerHandler::DLatencyPowerHandler(DLatency* aChannel)
|
sl@0
|
548 |
: DPowerHandler(KLddName),
|
sl@0
|
549 |
iChannel(aChannel)
|
sl@0
|
550 |
{
|
sl@0
|
551 |
}
|
sl@0
|
552 |
|
sl@0
|
553 |
void DLatencyPowerHandler::PowerUp()
|
sl@0
|
554 |
{
|
sl@0
|
555 |
iChannel->iOff = (TUint8)EFalse;
|
sl@0
|
556 |
if (iChannel->iStarted)
|
sl@0
|
557 |
iChannel->StartTimer();
|
sl@0
|
558 |
PowerUpDone();
|
sl@0
|
559 |
}
|
sl@0
|
560 |
|
sl@0
|
561 |
void DLatencyPowerHandler::PowerDown(TPowerState)
|
sl@0
|
562 |
{
|
sl@0
|
563 |
iChannel->iOff = (TUint8)ETrue;
|
sl@0
|
564 |
iChannel->StopTimer();
|
sl@0
|
565 |
PowerDownDone();
|
sl@0
|
566 |
}
|
sl@0
|
567 |
|
sl@0
|
568 |
|
sl@0
|
569 |
|