0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\system\d_tick.cpp
|
|
15 |
// LDD for testing tick-based timers
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "platform.h"
|
|
20 |
#include <assp.h>
|
|
21 |
#if defined(__MEIG__)
|
|
22 |
#include <cl7211.h>
|
|
23 |
#elif defined(__MAWD__)
|
|
24 |
#include <windermere.h>
|
|
25 |
#elif defined(__MISA__)
|
|
26 |
#include <sa1100.h>
|
|
27 |
#elif defined(__MCOT__)
|
|
28 |
#include <cotulla.h>
|
|
29 |
#elif defined(__MI920__) || defined(__NI1136__)
|
|
30 |
#include <integratorap.h>
|
|
31 |
#elif defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__)
|
|
32 |
#include <omap.h>
|
|
33 |
#include <omap_timer.h>
|
|
34 |
#elif defined(__WINS__)
|
|
35 |
#include "nk_priv.h"
|
|
36 |
#elif defined(__RVEMUBOARD__)
|
|
37 |
#include <rvemuboard.h>
|
|
38 |
#elif defined(__NE1_TB__)
|
|
39 |
#include <upd35001_timer.h>
|
133
|
40 |
#elif defined(__MRAP__)
|
|
41 |
#include <rap.h>
|
0
|
42 |
#endif
|
|
43 |
#include <kernel/kern_priv.h>
|
|
44 |
#include "d_tick.h"
|
|
45 |
#include "../misc/prbs.h"
|
|
46 |
|
|
47 |
#if defined(__WINS__)
|
|
48 |
typedef Int64 TCounter;
|
|
49 |
typedef Int64 TDelta;
|
|
50 |
#else
|
|
51 |
typedef TUint TCounter;
|
|
52 |
typedef TInt TDelta;
|
|
53 |
#endif
|
|
54 |
|
|
55 |
#if defined(__MISA__)|| defined(__MCOT__)
|
|
56 |
inline TCounter TIMER()
|
|
57 |
{ return *(volatile TUint*)KHwRwOstOscr; }
|
|
58 |
#endif
|
|
59 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__)
|
|
60 |
inline TCounter TIMER()
|
|
61 |
{ return TOmapTimer::Timer3Value(); }
|
|
62 |
#endif
|
|
63 |
#ifdef __MAWD__
|
|
64 |
inline TCounter TIMER()
|
|
65 |
{ return *(volatile TUint*)(KWindBaseAddress+KWindTimer1Value16)&0xffff; }
|
|
66 |
#endif
|
|
67 |
#ifdef __MEIG__
|
|
68 |
inline TCounter TIMER()
|
|
69 |
{ return *(volatile TUint*)(KEigerBaseAddress+KEigerTimer1Data16)&0xffff; }
|
|
70 |
#endif
|
|
71 |
#if defined(__MI920__) || defined(__NI1136__)
|
|
72 |
inline TCounter TIMER()
|
|
73 |
{ return *(volatile TUint*)(KHwCounterTimer1+KHoTimerValue)&0xffff;}
|
|
74 |
#endif
|
|
75 |
#if defined(__RVEMUBOARD__)
|
|
76 |
inline TCounter TIMER()
|
|
77 |
{ return *(volatile TUint*)(KHwCounterTimer1+KHoTimerValue)&0xffff;}
|
|
78 |
#endif
|
|
79 |
#if defined(__NE1_TB__)
|
|
80 |
inline TCounter TIMER()
|
|
81 |
{ return NETimer::Timer(2).iTimerCount; }
|
|
82 |
#endif
|
133
|
83 |
#ifdef __MRAP__
|
|
84 |
inline TCounter TIMER()
|
|
85 |
{ TRap::SetRegister32(1, KRapRegRTC001_TRIGGER);
|
|
86 |
return TRap::Register32(KRapRegRTC001_LONGCOUNT); }
|
|
87 |
#endif
|
0
|
88 |
#if defined(__EPOC32__) && defined(__CPU_X86)
|
|
89 |
TCounter TIMER();
|
|
90 |
void SetUpTimerChannel2();
|
|
91 |
#endif
|
|
92 |
#ifdef __WINS__
|
|
93 |
inline TCounter TIMER()
|
|
94 |
{
|
|
95 |
LARGE_INTEGER c;
|
|
96 |
QueryPerformanceCounter(&c);
|
|
97 |
return c.QuadPart;
|
|
98 |
}
|
|
99 |
#endif
|
133
|
100 |
#if defined(__MRAP__)
|
|
101 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
102 |
{ return final-initial; } // RAP RTC timer counts up
|
|
103 |
inline TInt LongTimeDelta(TCounter initial, TCounter final, TUint, TUint)
|
|
104 |
{ return final-initial; } // RAP RTC timer counts up
|
|
105 |
#endif
|
0
|
106 |
|
|
107 |
#if defined(__MISA__) || defined(__MCOT__)
|
|
108 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
109 |
{ return final-initial; } // SA1100 timer counts up
|
|
110 |
inline TInt LongTimeDelta(TCounter initial, TCounter final, TUint, TUint)
|
|
111 |
{ return final-initial; } // SA1100 timer counts up
|
|
112 |
#endif
|
|
113 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__)
|
|
114 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
115 |
{ return initial-final; } // OMAP timer counts down
|
|
116 |
inline TInt LongTimeDelta(TCounter initial, TCounter final, TUint, TUint)
|
|
117 |
{ return initial-final; }
|
|
118 |
#endif
|
|
119 |
#if defined(__MI920__) || defined(__NI1136__)
|
|
120 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
121 |
{ return (initial-final)&0xffff; } // Integrator timer counts down
|
|
122 |
TInt LongTimeDelta(TCounter initial, TCounter final, TUint init_ms, TUint final_ms)
|
|
123 |
{
|
|
124 |
TUint r=(initial-final)&0xffff; // Integrator timer counts down
|
|
125 |
TUint ms=final_ms-init_ms;
|
|
126 |
ms=2*ms-r;
|
|
127 |
ms=(ms+32768)&~0xffff;
|
|
128 |
return r+ms;
|
|
129 |
}
|
|
130 |
#endif
|
|
131 |
#if defined(__RVEMUBOARD__)
|
|
132 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
133 |
{ return (initial-final)&0xffff; } // Timer counts down
|
|
134 |
TInt LongTimeDelta(TCounter initial, TCounter final, TUint init_ms, TUint final_ms)
|
|
135 |
{
|
|
136 |
TUint r=(initial-final)&0xffff; // Timer counts down
|
|
137 |
TUint ms=final_ms-init_ms;
|
|
138 |
ms=2*ms-r;
|
|
139 |
ms=(ms+32768)&~0xffff;
|
|
140 |
return r+ms;
|
|
141 |
}
|
|
142 |
#endif
|
|
143 |
#if defined(__NE1_TB__)
|
|
144 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
145 |
{ return final - initial; }
|
|
146 |
inline TDelta LongTimeDelta(TCounter initial, TCounter final, TUint, TUint)
|
|
147 |
{ return final - initial; }
|
|
148 |
#endif
|
|
149 |
#if defined(__MAWD__) || defined(__MEIG__)
|
|
150 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
151 |
{ return (initial-final)&0xffff; } // Eiger/Windermere timer counts down
|
|
152 |
TInt LongTimeDelta(TCounter initial, TCounter final, TUint init_ms, TUint final_ms)
|
|
153 |
{
|
|
154 |
TUint r=(initial-final)&0xffff; // Eiger/Windermere timer counts down
|
|
155 |
TUint ms=final_ms-init_ms;
|
|
156 |
ms=2*ms-r;
|
|
157 |
ms=(ms+32768)&~0xffff;
|
|
158 |
return r+ms;
|
|
159 |
}
|
|
160 |
#endif
|
|
161 |
#if defined(__EPOC32__) && defined(__CPU_X86)
|
|
162 |
TDelta TimeDelta(TUint initial, TUint final)
|
|
163 |
{
|
|
164 |
TUint tickdiff=(initial-final)&0xffff;
|
|
165 |
TUint msdiff=((final>>16)-(initial>>16))&0xffff;
|
|
166 |
msdiff=1193*msdiff-tickdiff;
|
|
167 |
msdiff=(msdiff+32768)&~0xffff;
|
|
168 |
return msdiff+tickdiff;
|
|
169 |
}
|
|
170 |
|
|
171 |
TInt LongTimeDelta(TUint initial, TUint final, TUint init_ms, TUint final_ms)
|
|
172 |
{
|
|
173 |
TUint r=(initial-final)&0xffff; // PC timer counts down
|
|
174 |
TUint ms=final_ms-init_ms;
|
|
175 |
ms=1193*ms-r;
|
|
176 |
ms=(ms+32768)&~0xffff;
|
|
177 |
return r+ms;
|
|
178 |
}
|
|
179 |
#endif
|
|
180 |
#ifdef __WINS__
|
|
181 |
inline TDelta TimeDelta(TCounter initial, TCounter final)
|
|
182 |
{ return final-initial; } // counts up
|
|
183 |
inline TDelta LongTimeDelta(TCounter initial, TCounter final, TUint, TUint)
|
|
184 |
{ return final-initial; } // counts up
|
|
185 |
#endif
|
|
186 |
|
|
187 |
const TInt KMajorVersionNumber=0;
|
|
188 |
const TInt KMinorVersionNumber=1;
|
|
189 |
const TInt KBuildVersionNumber=1;
|
|
190 |
|
|
191 |
const TInt KDaysFrom0ADTo2000AD=730497; // See US_TIME.CPP to verify this
|
|
192 |
const TInt KSecondsPerDay=86400;
|
|
193 |
|
|
194 |
TUint TicksToMicroseconds(TDelta aTicks)
|
|
195 |
{
|
|
196 |
#if defined(__MISA__) || defined(__MCOT__)
|
|
197 |
Int64 ticks(aTicks);
|
|
198 |
ticks*=(1000000);
|
|
199 |
ticks+=KHwOscFreqHz/2; // 3.6864MHz tick
|
|
200 |
ticks/=KHwOscFreqHz;
|
|
201 |
return (TUint)ticks;
|
|
202 |
#endif
|
|
203 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__)
|
|
204 |
// Timer runs at 12Mhz/32 = 375kHz. Each tick is 2.66...us which is 16/6us
|
|
205 |
aTicks<<=4; // * 16
|
|
206 |
aTicks+=3; // rounding to the closest number of us
|
|
207 |
return (TInt)(aTicks/6); // us = (ticks*16+3)/6
|
|
208 |
#endif
|
|
209 |
#if defined(__MI920__) || defined(__NI1136__)
|
|
210 |
aTicks<<=14; // 1 tick = 32/3 us
|
|
211 |
aTicks+=768; // round
|
|
212 |
return (TInt)(aTicks/1536);
|
|
213 |
#endif
|
|
214 |
#if defined(__RVEMUBOARD__)
|
|
215 |
return (TInt)(aTicks*256); // 1 tick = 256 us
|
|
216 |
#endif
|
|
217 |
#if defined(__NE1_TB__)
|
|
218 |
NETimer& T2 = NETimer::Timer(2);
|
|
219 |
TUint prescale = __e32_find_ms1_32(T2.iPrescaler & 0x3f);
|
|
220 |
TUint f = 66666667 >> prescale;
|
|
221 |
TUint64 x = I64LIT(1000000);
|
|
222 |
x *= TUint64(aTicks);
|
|
223 |
x += TUint64(f>>1);
|
|
224 |
x /= TUint64(f);
|
|
225 |
return (TUint)x;
|
|
226 |
#endif
|
133
|
227 |
#if defined(__MRAP__)
|
|
228 |
// RTC runs with 32.768 kHz -> one tick is
|
|
229 |
const TUint KRTCClockHz = 32768;
|
|
230 |
Int64 ticks(aTicks);
|
|
231 |
ticks*=(1000000);
|
|
232 |
ticks+=KRTCClockHz/2; // 32.768 kHz tick
|
|
233 |
ticks/=KRTCClockHz;
|
|
234 |
return (TInt)ticks;
|
|
235 |
#endif
|
0
|
236 |
#if defined(__MAWD__) || defined(__MEIG__)
|
|
237 |
return aTicks*500; // 2kHz tick
|
|
238 |
#endif
|
|
239 |
#if defined(__EPOC32__) && defined(__CPU_X86)
|
|
240 |
return (aTicks*8381+4190)/10000;
|
|
241 |
#endif
|
|
242 |
#ifdef __WINS__
|
|
243 |
LARGE_INTEGER f;
|
|
244 |
QueryPerformanceFrequency(&f);
|
|
245 |
aTicks*=1000000;
|
|
246 |
aTicks+=f.QuadPart/2;
|
|
247 |
aTicks/=f.QuadPart;
|
|
248 |
return (TUint)aTicks;
|
|
249 |
#endif
|
|
250 |
}
|
|
251 |
|
|
252 |
class DTick;
|
|
253 |
class TTickTimer
|
|
254 |
{
|
|
255 |
public:
|
|
256 |
enum TMode
|
|
257 |
{
|
|
258 |
EOneShot,
|
|
259 |
EPeriodic,
|
|
260 |
EAbsolute,
|
|
261 |
ETickDelay,
|
|
262 |
};
|
|
263 |
public:
|
|
264 |
TTickTimer();
|
|
265 |
TInt Start(TInt aMode, TUint aMin, TUint aRange, TInt aCount);
|
|
266 |
void Cancel();
|
|
267 |
void CompleteClient(TInt aValue);
|
|
268 |
static void TickCallBack(TAny* aPtr);
|
|
269 |
static void SecondCallBack(TAny* aPtr);
|
|
270 |
public:
|
|
271 |
TTickLink iTickLink;
|
|
272 |
TSecondLink iSecondLink;
|
|
273 |
TMode iMode;
|
|
274 |
TInt iInterval;
|
|
275 |
TTimeK iExpiryTime;
|
|
276 |
TUint iMin;
|
|
277 |
TUint iRange;
|
|
278 |
TInt iParam;
|
|
279 |
TCounter iStartTime0;
|
|
280 |
TUint iStartTime1;
|
|
281 |
TCounter iStartTime;
|
|
282 |
TInt iMinErr;
|
|
283 |
TInt iMaxErr;
|
|
284 |
Int64 iTotalErr;
|
|
285 |
TInt iCount;
|
|
286 |
TInt iRequestedCount;
|
|
287 |
TInt iIgnore;
|
|
288 |
DTick* iLdd;
|
|
289 |
TInt iId;
|
|
290 |
TClientRequest* iRequest;
|
|
291 |
};
|
|
292 |
|
|
293 |
class DTickFactory : public DLogicalDevice
|
|
294 |
//
|
|
295 |
// Tick timer LDD factory
|
|
296 |
//
|
|
297 |
{
|
|
298 |
public:
|
|
299 |
DTickFactory();
|
|
300 |
virtual TInt Install(); //overriding pure virtual
|
|
301 |
virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
|
|
302 |
virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
|
|
303 |
};
|
|
304 |
|
|
305 |
class DTick : public DLogicalChannelBase
|
|
306 |
//
|
|
307 |
// Tick timer LDD channel
|
|
308 |
//
|
|
309 |
{
|
|
310 |
public:
|
|
311 |
DTick();
|
|
312 |
~DTick();
|
|
313 |
protected:
|
|
314 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
|
315 |
virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
|
|
316 |
public:
|
|
317 |
void TimerExpired(TInt anId);
|
|
318 |
inline DThread* Client() { return iThread; }
|
|
319 |
public:
|
|
320 |
DThread* iThread;
|
|
321 |
TInt iTickPeriodUs;
|
|
322 |
TTimeK iYear2000;
|
|
323 |
TTickTimer iTickTimer[KMaxTimers];
|
|
324 |
TUint iSeed[2];
|
|
325 |
};
|
|
326 |
|
|
327 |
TTickTimer::TTickTimer()
|
|
328 |
: iMode(EOneShot),
|
|
329 |
iInterval(0),
|
|
330 |
iExpiryTime(0),
|
|
331 |
iMin(0),
|
|
332 |
iRange(1),
|
|
333 |
iParam(0),
|
|
334 |
iStartTime0(0),
|
|
335 |
iStartTime1(0),
|
|
336 |
iStartTime(0),
|
|
337 |
iMinErr(KMaxTInt),
|
|
338 |
iMaxErr(KMinTInt),
|
|
339 |
iTotalErr(0),
|
|
340 |
iCount(0),
|
|
341 |
iRequestedCount(0),
|
|
342 |
iIgnore(0),
|
|
343 |
iLdd(NULL),
|
|
344 |
iId(0),
|
|
345 |
iRequest(NULL)
|
|
346 |
{
|
|
347 |
}
|
|
348 |
|
|
349 |
void TTickTimer::TickCallBack(TAny* aPtr)
|
|
350 |
{
|
|
351 |
TCounter timer_val=TIMER();
|
|
352 |
TTickTimer& m=*(TTickTimer*)aPtr;
|
|
353 |
TDelta time=TimeDelta(m.iStartTime, timer_val);
|
|
354 |
TInt time_us=TicksToMicroseconds(time);
|
|
355 |
TInt rounded_interval=((m.iInterval+500)/1000)*1000;
|
|
356 |
TInt error=time_us-rounded_interval;
|
|
357 |
if (!m.iIgnore)
|
|
358 |
{
|
|
359 |
if (error<m.iMinErr)
|
|
360 |
m.iMinErr=error;
|
|
361 |
if (error>m.iMaxErr)
|
|
362 |
m.iMaxErr=error;
|
|
363 |
m.iTotalErr+=error;
|
|
364 |
}
|
|
365 |
if (m.iIgnore==1 && m.iMode==EPeriodic)
|
|
366 |
{
|
|
367 |
m.iStartTime0=timer_val;
|
|
368 |
m.iStartTime1=NKern::TickCount();
|
|
369 |
}
|
|
370 |
if ((m.iIgnore && m.iIgnore--) || (++m.iCount<m.iRequestedCount))
|
|
371 |
{
|
|
372 |
if (m.iMode==EOneShot)
|
|
373 |
{
|
|
374 |
TUint rnd=Random(m.iLdd->iSeed);
|
|
375 |
TUint ticks=(rnd%m.iRange)+m.iMin;
|
|
376 |
m.iInterval=ticks*m.iLdd->iTickPeriodUs;
|
|
377 |
m.iStartTime=TIMER();
|
|
378 |
m.iTickLink.OneShot(m.iInterval, TickCallBack, &m);
|
|
379 |
}
|
|
380 |
else if (m.iMode==ETickDelay)
|
|
381 |
{
|
|
382 |
m.iStartTime=TIMER();
|
|
383 |
m.iTickLink.OneShot(m.iInterval, TickCallBack, &m);
|
|
384 |
NKern::Sleep(m.iRange);
|
|
385 |
}
|
|
386 |
else
|
|
387 |
m.iStartTime=timer_val;
|
|
388 |
return;
|
|
389 |
}
|
|
390 |
m.CompleteClient(KErrNone);
|
|
391 |
if (m.iMode==EPeriodic)
|
|
392 |
{
|
|
393 |
m.iStartTime0=LongTimeDelta(m.iStartTime0, timer_val, m.iStartTime1, NKern::TickCount());
|
|
394 |
m.iTickLink.Cancel();
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
void TTickTimer::SecondCallBack(TAny* aPtr)
|
|
399 |
{
|
|
400 |
TTickTimer& m=*(TTickTimer*)aPtr;
|
|
401 |
TTimeK now=Kern::SystemTime();
|
|
402 |
Int64 error=now-m.iExpiryTime;
|
|
403 |
if (error>KMaxTInt)
|
|
404 |
error=KMaxTInt;
|
|
405 |
if (error<KMinTInt)
|
|
406 |
error=KMinTInt;
|
|
407 |
if (error<m.iMinErr)
|
|
408 |
m.iMinErr=(TInt)error;
|
|
409 |
if (error>m.iMaxErr)
|
|
410 |
m.iMaxErr=(TInt)error;
|
|
411 |
m.iTotalErr+=error;
|
|
412 |
if (++m.iCount<m.iRequestedCount)
|
|
413 |
{
|
|
414 |
TUint rnd=Random(m.iLdd->iSeed);
|
|
415 |
TUint secs=(rnd%m.iRange)+m.iMin;
|
|
416 |
m.iExpiryTime=now+secs*1000000+999999;
|
|
417 |
m.iExpiryTime/=1000000;
|
|
418 |
m.iExpiryTime*=1000000;
|
|
419 |
m.iSecondLink.At(m.iExpiryTime, SecondCallBack, &m);
|
|
420 |
return;
|
|
421 |
}
|
|
422 |
m.CompleteClient(KErrNone);
|
|
423 |
}
|
|
424 |
|
|
425 |
TInt TTickTimer::Start(TInt aMode, TUint a1, TUint a2, TInt aCount)
|
|
426 |
{
|
|
427 |
TInt r=KErrGeneral;
|
|
428 |
iMode=(TMode)aMode;
|
|
429 |
iMin=a1;
|
|
430 |
iRange=a2;
|
|
431 |
iMinErr=KMaxTInt;
|
|
432 |
iMaxErr=KMinTInt;
|
|
433 |
iTotalErr=0;
|
|
434 |
iCount=0;
|
|
435 |
iRequestedCount=aCount;
|
|
436 |
switch (aMode)
|
|
437 |
{
|
|
438 |
case EOneShot:
|
|
439 |
{
|
|
440 |
TUint rnd=Random(iLdd->iSeed);
|
|
441 |
TUint ticks=(rnd%iRange)+iMin;
|
|
442 |
iInterval=ticks*iLdd->iTickPeriodUs;
|
|
443 |
iStartTime=TIMER();
|
|
444 |
iStartTime0=0;
|
|
445 |
iStartTime1=0;
|
|
446 |
iTickLink.OneShot(iInterval, TickCallBack, this);
|
|
447 |
iIgnore=Min(aCount-1,1);
|
|
448 |
r=KErrNone;
|
|
449 |
break;
|
|
450 |
}
|
|
451 |
case EPeriodic:
|
|
452 |
{
|
|
453 |
iInterval=iMin*iLdd->iTickPeriodUs;
|
|
454 |
iStartTime=TIMER();
|
|
455 |
iStartTime0=iStartTime;
|
|
456 |
iStartTime1=NKern::TickCount();
|
|
457 |
iTickLink.Periodic(iInterval, TickCallBack, this);
|
|
458 |
iIgnore=Min(aCount-1,1);
|
|
459 |
r=KErrNone;
|
|
460 |
break;
|
|
461 |
}
|
|
462 |
case EAbsolute:
|
|
463 |
{
|
|
464 |
TUint rnd=Random(iLdd->iSeed);
|
|
465 |
TUint secs=(rnd%iRange)+iMin;
|
|
466 |
TTimeK now=Kern::SystemTime();
|
|
467 |
iExpiryTime=now+secs*1000000+999999;
|
|
468 |
iExpiryTime/=1000000;
|
|
469 |
iExpiryTime*=1000000;
|
|
470 |
iSecondLink.At(iExpiryTime, SecondCallBack, this);
|
|
471 |
iIgnore=0;
|
|
472 |
iStartTime0=0;
|
|
473 |
iStartTime1=0;
|
|
474 |
r=KErrNone;
|
|
475 |
break;
|
|
476 |
}
|
|
477 |
case ETickDelay:
|
|
478 |
{
|
|
479 |
iInterval=iMin*iLdd->iTickPeriodUs;
|
|
480 |
iStartTime=TIMER();
|
|
481 |
iStartTime0=0;
|
|
482 |
iStartTime1=0;
|
|
483 |
iTickLink.OneShot(iInterval, TickCallBack, this);
|
|
484 |
iIgnore=Min(aCount-1,1);
|
|
485 |
r=KErrNone;
|
|
486 |
break;
|
|
487 |
}
|
|
488 |
default:
|
|
489 |
break;
|
|
490 |
}
|
|
491 |
return r;
|
|
492 |
}
|
|
493 |
|
|
494 |
void TTickTimer::CompleteClient(TInt aValue)
|
|
495 |
{
|
|
496 |
Kern::QueueRequestComplete(iLdd->Client(),iRequest,aValue);
|
|
497 |
}
|
|
498 |
|
|
499 |
void TTickTimer::Cancel()
|
|
500 |
{
|
|
501 |
iTickLink.Cancel();
|
|
502 |
iSecondLink.Cancel();
|
|
503 |
CompleteClient(KErrCancel);
|
|
504 |
}
|
|
505 |
|
|
506 |
DECLARE_STANDARD_LDD()
|
|
507 |
{
|
|
508 |
return new DTickFactory;
|
|
509 |
}
|
|
510 |
|
|
511 |
DTickFactory::DTickFactory()
|
|
512 |
{
|
|
513 |
iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
|
|
514 |
//iParseMask=0;//No units, no info, no PDD
|
|
515 |
//iUnitsMask=0;//Only one thing
|
|
516 |
}
|
|
517 |
|
|
518 |
TInt DTickFactory::Create(DLogicalChannelBase*& aChannel)
|
|
519 |
//
|
|
520 |
// Create a new DTick on this logical device
|
|
521 |
//
|
|
522 |
{
|
|
523 |
aChannel=new DTick;
|
|
524 |
return aChannel?KErrNone:KErrNoMemory;
|
|
525 |
}
|
|
526 |
|
|
527 |
TInt DTickFactory::Install()
|
|
528 |
//
|
|
529 |
// Install the LDD - overriding pure virtual
|
|
530 |
//
|
|
531 |
{
|
|
532 |
return SetName(&KTickTestLddName);
|
|
533 |
}
|
|
534 |
|
|
535 |
void DTickFactory::GetCaps(TDes8& aDes) const
|
|
536 |
//
|
|
537 |
// Get capabilities - overriding pure virtual
|
|
538 |
//
|
|
539 |
{
|
|
540 |
TCapsTickTestV01 b;
|
|
541 |
b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
|
|
542 |
Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
|
|
543 |
}
|
|
544 |
|
|
545 |
DTick::DTick()
|
|
546 |
//
|
|
547 |
// Constructor
|
|
548 |
//
|
|
549 |
{
|
|
550 |
TInt i;
|
|
551 |
for (i=0; i<KMaxTimers; i++)
|
|
552 |
{
|
|
553 |
iTickTimer[i].iLdd=this;
|
|
554 |
iTickTimer[i].iId=i;
|
|
555 |
}
|
|
556 |
iSeed[0]=NKern::TickCount();
|
|
557 |
iSeed[1]=0;
|
|
558 |
iTickPeriodUs=Kern::TickPeriod();
|
|
559 |
|
|
560 |
// Careful with the constants here or GCC will get it wrong
|
|
561 |
iYear2000=Int64(KDaysFrom0ADTo2000AD)*Int64(KSecondsPerDay);
|
|
562 |
iYear2000*=1000000;
|
|
563 |
|
|
564 |
iThread=&Kern::CurrentThread();
|
|
565 |
iThread->Open();
|
|
566 |
}
|
|
567 |
|
|
568 |
TInt DTick::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
|
|
569 |
//
|
|
570 |
// Create channel
|
|
571 |
//
|
|
572 |
{
|
|
573 |
|
|
574 |
if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
|
|
575 |
return KErrNotSupported;
|
|
576 |
|
|
577 |
for (TInt i=0; i<KMaxTimers; i++)
|
|
578 |
{
|
|
579 |
TInt r = Kern::CreateClientRequest(iTickTimer[i].iRequest);
|
|
580 |
if (r != KErrNone)
|
|
581 |
return r;
|
|
582 |
}
|
|
583 |
|
|
584 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__)
|
|
585 |
// Set up Timer3 as a free-running timer at 12Mhz/32 = 375kHz
|
|
586 |
TOmapTimer::SetTimer3Ctrl( TOmapTimer::KHtOSTimer_Cntl_Ar
|
|
587 |
| TOmapTimer::KHtOSTimer_Cntl_Free
|
|
588 |
| TOmapTimer::KHtOSTimer_Cntl_ClkEnable );
|
|
589 |
TOmapTimer::SetTimer3Prescale( TOmapTimer::EPrescaleBy32 );
|
|
590 |
// Autoreload 0xFFFFFFFF to effectively wrap from zero back to 0xFFFFFFFF
|
|
591 |
TOmapTimer::SetTimer3LoadTim( 0xFFFFFFFF );
|
|
592 |
TOmapTimer::StartTimer3();
|
|
593 |
#endif
|
|
594 |
#if defined(__MI920__) || defined(__NI1136__)
|
|
595 |
// Set up timer 1 as free running 93.75KHz clock
|
|
596 |
TIntegratorAP::SetTimerLoad(TIntegratorAP::ECounterTimer1, 0); // start from 0xffff downwards
|
|
597 |
TIntegratorAP::SetTimerMode(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerModeFreeRunning);
|
|
598 |
TIntegratorAP::SetTimerPreScale(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerPreScaleDiv256); // 93.75kHz wrap 699ms
|
|
599 |
TIntegratorAP::EnableTimer(TIntegratorAP::ECounterTimer1, TIntegratorAP::EEnable);
|
|
600 |
TIntegratorAP::DisableIrq(TIntegratorAP::EIrqSet0,EIntIdTimer0); // make sure timer int is disabled
|
|
601 |
#endif
|
|
602 |
#if defined(__RVEMUBOARD__)
|
|
603 |
// Switch timer 1 to a 1MHz clock in the system controller Ctrl register
|
|
604 |
TRvEmuBoard::SetSCCtrl(KTimer1EnSel);
|
|
605 |
|
|
606 |
// Set up timer 1 as free running 3.90625kHz clock
|
|
607 |
TRvEmuBoard::SetTimerMode(KHwCounterTimer1, TRvEmuBoard::ETimerModeFreeRunning);
|
|
608 |
TRvEmuBoard::SetTimerPreScale(KHwCounterTimer1, TRvEmuBoard::ETimerPreScaleDiv256);// 3.90625kHz wrap 16.777s
|
|
609 |
TRvEmuBoard::EnableTimer(KHwCounterTimer1, TRvEmuBoard::EEnable);
|
|
610 |
#endif
|
|
611 |
#if defined(__NE1_TB__)
|
|
612 |
// nothing to do since we use fast counter
|
|
613 |
#endif
|
133
|
614 |
#if defined(__MRAP__)
|
|
615 |
// nothing to do here RTC runs with 32.768 kHz
|
|
616 |
#endif
|
0
|
617 |
#ifdef __MAWD__
|
|
618 |
// Set up timer 1 as free running 2kHz clock
|
|
619 |
TWind::SetBuzzerControl(0); // disable buzzer
|
|
620 |
TWind::SetTimer1Control(KWindTimer1ControlTimerEnable);
|
|
621 |
TWind::SetTimer1Load(0);
|
|
622 |
#endif
|
|
623 |
#ifdef __MEIG__
|
|
624 |
// Set up timer 1 as free running 2kHz clock
|
|
625 |
TEiger::ModifyControl21(KEigerControlTimer1PreOrFree|KEigerControlTimer1K512OrK2|
|
|
626 |
KEigerControlBuzzerToggle|KEigerControlBuzzerTimer1OrToggle,0);
|
|
627 |
TEiger::SetTimer1Data(0);
|
|
628 |
#endif
|
|
629 |
#if defined(__EPOC32__) && defined(__CPU_X86)
|
|
630 |
// Set up timer channel 2 as free running counter at 14318180/12 Hz
|
|
631 |
SetUpTimerChannel2();
|
|
632 |
#endif
|
|
633 |
return KErrNone;
|
|
634 |
}
|
|
635 |
|
|
636 |
DTick::~DTick()
|
|
637 |
//
|
|
638 |
// Destructor
|
|
639 |
//
|
|
640 |
{
|
|
641 |
TInt i;
|
|
642 |
for (i=0; i<KMaxTimers; i++)
|
|
643 |
{
|
|
644 |
iTickTimer[i].Cancel();
|
|
645 |
Kern::DestroyClientRequest(iTickTimer[i].iRequest);
|
|
646 |
}
|
|
647 |
Kern::SafeClose((DObject*&)iThread, NULL);
|
|
648 |
}
|
|
649 |
|
|
650 |
TInt DTick::Request(TInt aFunction, TAny* a1, TAny* a2)
|
|
651 |
//
|
|
652 |
// Runs in context of client thread, system unlocked on entry and exit
|
|
653 |
//
|
|
654 |
{
|
|
655 |
NKern::ThreadEnterCS(); // stop thread kills
|
|
656 |
TInt r=KErrNone;
|
|
657 |
TInt id=(TInt)a1;
|
|
658 |
TTickTimer& m=iTickTimer[id];
|
|
659 |
switch (aFunction)
|
|
660 |
{
|
|
661 |
case RTickTest::EControlStart:
|
|
662 |
{
|
|
663 |
STimerStartInfo info;
|
|
664 |
kumemget(&info,a2,sizeof(info));
|
|
665 |
r=m.iRequest->SetStatus(info.iStatus);
|
|
666 |
if (r==KErrNone)
|
|
667 |
r=m.Start(info.iMode, info.iMin, info.iRange, info.iCount);
|
|
668 |
break;
|
|
669 |
}
|
|
670 |
case RTickTest::EControlStop:
|
|
671 |
{
|
|
672 |
m.Cancel();
|
|
673 |
break;
|
|
674 |
}
|
|
675 |
case RTickTest::EControlGetInfo:
|
|
676 |
{
|
|
677 |
STickTestInfo info;
|
|
678 |
info.iMinErr=m.iMinErr;
|
|
679 |
info.iMaxErr=m.iMaxErr;
|
|
680 |
info.iCount=m.iCount;
|
|
681 |
info.iRequestedCount=m.iRequestedCount;
|
|
682 |
Int64 avg=m.iTotalErr/m.iCount;
|
|
683 |
info.iAvgErr=(TInt)avg;
|
|
684 |
info.iTotalTime=TicksToMicroseconds(m.iStartTime0);
|
|
685 |
kumemput(a2,&info,sizeof(info));
|
|
686 |
break;
|
|
687 |
}
|
|
688 |
case RTickTest::EControlReadRtc:
|
|
689 |
{
|
|
690 |
TInt hwrtc;
|
|
691 |
Arch::TheAsic()->SystemTimeInSecondsFrom2000(hwrtc);
|
|
692 |
*(TTimeK*)a1=Kern::SystemTime();
|
|
693 |
TTimeK hwtimeK=(TTimeK)hwrtc;
|
|
694 |
hwtimeK*=1000000;
|
|
695 |
hwtimeK+=iYear2000;
|
|
696 |
kumemput(a2,&hwtimeK,sizeof(hwtimeK));
|
|
697 |
break;
|
|
698 |
}
|
|
699 |
case RTickTest::EControlGetTickPeriod:
|
|
700 |
{
|
|
701 |
r=iTickPeriodUs;
|
|
702 |
break;
|
|
703 |
}
|
|
704 |
default:
|
|
705 |
r=KErrNotSupported;
|
|
706 |
break;
|
|
707 |
}
|
|
708 |
NKern::ThreadLeaveCS();
|
|
709 |
return r;
|
|
710 |
}
|
|
711 |
|