author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 31 Mar 2010 23:38:45 +0300 | |
branch | RCL_3 |
changeset 22 | 2f92ad2dc5db |
parent 0 | a41df078684a |
child 43 | c1f20ce4abcf |
permissions | -rw-r--r-- |
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> |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
#elif defined(__MRAP__) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
#ifdef __MRAP__ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
inline TCounter TIMER() |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
{ TRap::SetRegister32(1, KRapRegRTC001_TRIGGER); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
return TRap::Register32(KRapRegRTC001_LONGCOUNT); } |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
#if defined(__MRAP__) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
{ return final-initial; } // RAP RTC timer counts up |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
inline TInt LongTimeDelta(TCounter initial, TCounter final, TUint, TUint) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
{ return final-initial; } // RAP RTC timer counts up |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
|
227 |
#if defined(__MAWD__) || defined(__MEIG__) |
|
228 |
return aTicks*500; // 2kHz tick |
|
229 |
#endif |
|
230 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
|
231 |
return (aTicks*8381+4190)/10000; |
|
232 |
#endif |
|
233 |
#ifdef __WINS__ |
|
234 |
LARGE_INTEGER f; |
|
235 |
QueryPerformanceFrequency(&f); |
|
236 |
aTicks*=1000000; |
|
237 |
aTicks+=f.QuadPart/2; |
|
238 |
aTicks/=f.QuadPart; |
|
239 |
return (TUint)aTicks; |
|
240 |
#endif |
|
241 |
} |
|
242 |
||
243 |
class DTick; |
|
244 |
class TTickTimer |
|
245 |
{ |
|
246 |
public: |
|
247 |
enum TMode |
|
248 |
{ |
|
249 |
EOneShot, |
|
250 |
EPeriodic, |
|
251 |
EAbsolute, |
|
252 |
ETickDelay, |
|
253 |
}; |
|
254 |
public: |
|
255 |
TTickTimer(); |
|
256 |
TInt Start(TInt aMode, TUint aMin, TUint aRange, TInt aCount); |
|
257 |
void Cancel(); |
|
258 |
void CompleteClient(TInt aValue); |
|
259 |
static void TickCallBack(TAny* aPtr); |
|
260 |
static void SecondCallBack(TAny* aPtr); |
|
261 |
public: |
|
262 |
TTickLink iTickLink; |
|
263 |
TSecondLink iSecondLink; |
|
264 |
TMode iMode; |
|
265 |
TInt iInterval; |
|
266 |
TTimeK iExpiryTime; |
|
267 |
TUint iMin; |
|
268 |
TUint iRange; |
|
269 |
TInt iParam; |
|
270 |
TCounter iStartTime0; |
|
271 |
TUint iStartTime1; |
|
272 |
TCounter iStartTime; |
|
273 |
TInt iMinErr; |
|
274 |
TInt iMaxErr; |
|
275 |
Int64 iTotalErr; |
|
276 |
TInt iCount; |
|
277 |
TInt iRequestedCount; |
|
278 |
TInt iIgnore; |
|
279 |
DTick* iLdd; |
|
280 |
TInt iId; |
|
281 |
TClientRequest* iRequest; |
|
282 |
}; |
|
283 |
||
284 |
class DTickFactory : public DLogicalDevice |
|
285 |
// |
|
286 |
// Tick timer LDD factory |
|
287 |
// |
|
288 |
{ |
|
289 |
public: |
|
290 |
DTickFactory(); |
|
291 |
virtual TInt Install(); //overriding pure virtual |
|
292 |
virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual |
|
293 |
virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual |
|
294 |
}; |
|
295 |
||
296 |
class DTick : public DLogicalChannelBase |
|
297 |
// |
|
298 |
// Tick timer LDD channel |
|
299 |
// |
|
300 |
{ |
|
301 |
public: |
|
302 |
DTick(); |
|
303 |
~DTick(); |
|
304 |
protected: |
|
305 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
306 |
virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2); |
|
307 |
public: |
|
308 |
void TimerExpired(TInt anId); |
|
309 |
inline DThread* Client() { return iThread; } |
|
310 |
public: |
|
311 |
DThread* iThread; |
|
312 |
TInt iTickPeriodUs; |
|
313 |
TTimeK iYear2000; |
|
314 |
TTickTimer iTickTimer[KMaxTimers]; |
|
315 |
TUint iSeed[2]; |
|
316 |
}; |
|
317 |
||
318 |
TTickTimer::TTickTimer() |
|
319 |
: iMode(EOneShot), |
|
320 |
iInterval(0), |
|
321 |
iExpiryTime(0), |
|
322 |
iMin(0), |
|
323 |
iRange(1), |
|
324 |
iParam(0), |
|
325 |
iStartTime0(0), |
|
326 |
iStartTime1(0), |
|
327 |
iStartTime(0), |
|
328 |
iMinErr(KMaxTInt), |
|
329 |
iMaxErr(KMinTInt), |
|
330 |
iTotalErr(0), |
|
331 |
iCount(0), |
|
332 |
iRequestedCount(0), |
|
333 |
iIgnore(0), |
|
334 |
iLdd(NULL), |
|
335 |
iId(0), |
|
336 |
iRequest(NULL) |
|
337 |
{ |
|
338 |
} |
|
339 |
||
340 |
void TTickTimer::TickCallBack(TAny* aPtr) |
|
341 |
{ |
|
342 |
TCounter timer_val=TIMER(); |
|
343 |
TTickTimer& m=*(TTickTimer*)aPtr; |
|
344 |
TDelta time=TimeDelta(m.iStartTime, timer_val); |
|
345 |
TInt time_us=TicksToMicroseconds(time); |
|
346 |
TInt rounded_interval=((m.iInterval+500)/1000)*1000; |
|
347 |
TInt error=time_us-rounded_interval; |
|
348 |
if (!m.iIgnore) |
|
349 |
{ |
|
350 |
if (error<m.iMinErr) |
|
351 |
m.iMinErr=error; |
|
352 |
if (error>m.iMaxErr) |
|
353 |
m.iMaxErr=error; |
|
354 |
m.iTotalErr+=error; |
|
355 |
} |
|
356 |
if (m.iIgnore==1 && m.iMode==EPeriodic) |
|
357 |
{ |
|
358 |
m.iStartTime0=timer_val; |
|
359 |
m.iStartTime1=NKern::TickCount(); |
|
360 |
} |
|
361 |
if ((m.iIgnore && m.iIgnore--) || (++m.iCount<m.iRequestedCount)) |
|
362 |
{ |
|
363 |
if (m.iMode==EOneShot) |
|
364 |
{ |
|
365 |
TUint rnd=Random(m.iLdd->iSeed); |
|
366 |
TUint ticks=(rnd%m.iRange)+m.iMin; |
|
367 |
m.iInterval=ticks*m.iLdd->iTickPeriodUs; |
|
368 |
m.iStartTime=TIMER(); |
|
369 |
m.iTickLink.OneShot(m.iInterval, TickCallBack, &m); |
|
370 |
} |
|
371 |
else if (m.iMode==ETickDelay) |
|
372 |
{ |
|
373 |
m.iStartTime=TIMER(); |
|
374 |
m.iTickLink.OneShot(m.iInterval, TickCallBack, &m); |
|
375 |
NKern::Sleep(m.iRange); |
|
376 |
} |
|
377 |
else |
|
378 |
m.iStartTime=timer_val; |
|
379 |
return; |
|
380 |
} |
|
381 |
m.CompleteClient(KErrNone); |
|
382 |
if (m.iMode==EPeriodic) |
|
383 |
{ |
|
384 |
m.iStartTime0=LongTimeDelta(m.iStartTime0, timer_val, m.iStartTime1, NKern::TickCount()); |
|
385 |
m.iTickLink.Cancel(); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
void TTickTimer::SecondCallBack(TAny* aPtr) |
|
390 |
{ |
|
391 |
TTickTimer& m=*(TTickTimer*)aPtr; |
|
392 |
TTimeK now=Kern::SystemTime(); |
|
393 |
Int64 error=now-m.iExpiryTime; |
|
394 |
if (error>KMaxTInt) |
|
395 |
error=KMaxTInt; |
|
396 |
if (error<KMinTInt) |
|
397 |
error=KMinTInt; |
|
398 |
if (error<m.iMinErr) |
|
399 |
m.iMinErr=(TInt)error; |
|
400 |
if (error>m.iMaxErr) |
|
401 |
m.iMaxErr=(TInt)error; |
|
402 |
m.iTotalErr+=error; |
|
403 |
if (++m.iCount<m.iRequestedCount) |
|
404 |
{ |
|
405 |
TUint rnd=Random(m.iLdd->iSeed); |
|
406 |
TUint secs=(rnd%m.iRange)+m.iMin; |
|
407 |
m.iExpiryTime=now+secs*1000000+999999; |
|
408 |
m.iExpiryTime/=1000000; |
|
409 |
m.iExpiryTime*=1000000; |
|
410 |
m.iSecondLink.At(m.iExpiryTime, SecondCallBack, &m); |
|
411 |
return; |
|
412 |
} |
|
413 |
m.CompleteClient(KErrNone); |
|
414 |
} |
|
415 |
||
416 |
TInt TTickTimer::Start(TInt aMode, TUint a1, TUint a2, TInt aCount) |
|
417 |
{ |
|
418 |
TInt r=KErrGeneral; |
|
419 |
iMode=(TMode)aMode; |
|
420 |
iMin=a1; |
|
421 |
iRange=a2; |
|
422 |
iMinErr=KMaxTInt; |
|
423 |
iMaxErr=KMinTInt; |
|
424 |
iTotalErr=0; |
|
425 |
iCount=0; |
|
426 |
iRequestedCount=aCount; |
|
427 |
switch (aMode) |
|
428 |
{ |
|
429 |
case EOneShot: |
|
430 |
{ |
|
431 |
TUint rnd=Random(iLdd->iSeed); |
|
432 |
TUint ticks=(rnd%iRange)+iMin; |
|
433 |
iInterval=ticks*iLdd->iTickPeriodUs; |
|
434 |
iStartTime=TIMER(); |
|
435 |
iStartTime0=0; |
|
436 |
iStartTime1=0; |
|
437 |
iTickLink.OneShot(iInterval, TickCallBack, this); |
|
438 |
iIgnore=Min(aCount-1,1); |
|
439 |
r=KErrNone; |
|
440 |
break; |
|
441 |
} |
|
442 |
case EPeriodic: |
|
443 |
{ |
|
444 |
iInterval=iMin*iLdd->iTickPeriodUs; |
|
445 |
iStartTime=TIMER(); |
|
446 |
iStartTime0=iStartTime; |
|
447 |
iStartTime1=NKern::TickCount(); |
|
448 |
iTickLink.Periodic(iInterval, TickCallBack, this); |
|
449 |
iIgnore=Min(aCount-1,1); |
|
450 |
r=KErrNone; |
|
451 |
break; |
|
452 |
} |
|
453 |
case EAbsolute: |
|
454 |
{ |
|
455 |
TUint rnd=Random(iLdd->iSeed); |
|
456 |
TUint secs=(rnd%iRange)+iMin; |
|
457 |
TTimeK now=Kern::SystemTime(); |
|
458 |
iExpiryTime=now+secs*1000000+999999; |
|
459 |
iExpiryTime/=1000000; |
|
460 |
iExpiryTime*=1000000; |
|
461 |
iSecondLink.At(iExpiryTime, SecondCallBack, this); |
|
462 |
iIgnore=0; |
|
463 |
iStartTime0=0; |
|
464 |
iStartTime1=0; |
|
465 |
r=KErrNone; |
|
466 |
break; |
|
467 |
} |
|
468 |
case ETickDelay: |
|
469 |
{ |
|
470 |
iInterval=iMin*iLdd->iTickPeriodUs; |
|
471 |
iStartTime=TIMER(); |
|
472 |
iStartTime0=0; |
|
473 |
iStartTime1=0; |
|
474 |
iTickLink.OneShot(iInterval, TickCallBack, this); |
|
475 |
iIgnore=Min(aCount-1,1); |
|
476 |
r=KErrNone; |
|
477 |
break; |
|
478 |
} |
|
479 |
default: |
|
480 |
break; |
|
481 |
} |
|
482 |
return r; |
|
483 |
} |
|
484 |
||
485 |
void TTickTimer::CompleteClient(TInt aValue) |
|
486 |
{ |
|
487 |
Kern::QueueRequestComplete(iLdd->Client(),iRequest,aValue); |
|
488 |
} |
|
489 |
||
490 |
void TTickTimer::Cancel() |
|
491 |
{ |
|
492 |
iTickLink.Cancel(); |
|
493 |
iSecondLink.Cancel(); |
|
494 |
CompleteClient(KErrCancel); |
|
495 |
} |
|
496 |
||
497 |
DECLARE_STANDARD_LDD() |
|
498 |
{ |
|
499 |
return new DTickFactory; |
|
500 |
} |
|
501 |
||
502 |
DTickFactory::DTickFactory() |
|
503 |
{ |
|
504 |
iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
505 |
//iParseMask=0;//No units, no info, no PDD |
|
506 |
//iUnitsMask=0;//Only one thing |
|
507 |
} |
|
508 |
||
509 |
TInt DTickFactory::Create(DLogicalChannelBase*& aChannel) |
|
510 |
// |
|
511 |
// Create a new DTick on this logical device |
|
512 |
// |
|
513 |
{ |
|
514 |
aChannel=new DTick; |
|
515 |
return aChannel?KErrNone:KErrNoMemory; |
|
516 |
} |
|
517 |
||
518 |
TInt DTickFactory::Install() |
|
519 |
// |
|
520 |
// Install the LDD - overriding pure virtual |
|
521 |
// |
|
522 |
{ |
|
523 |
return SetName(&KTickTestLddName); |
|
524 |
} |
|
525 |
||
526 |
void DTickFactory::GetCaps(TDes8& aDes) const |
|
527 |
// |
|
528 |
// Get capabilities - overriding pure virtual |
|
529 |
// |
|
530 |
{ |
|
531 |
TCapsTickTestV01 b; |
|
532 |
b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
533 |
Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b)); |
|
534 |
} |
|
535 |
||
536 |
DTick::DTick() |
|
537 |
// |
|
538 |
// Constructor |
|
539 |
// |
|
540 |
{ |
|
541 |
TInt i; |
|
542 |
for (i=0; i<KMaxTimers; i++) |
|
543 |
{ |
|
544 |
iTickTimer[i].iLdd=this; |
|
545 |
iTickTimer[i].iId=i; |
|
546 |
} |
|
547 |
iSeed[0]=NKern::TickCount(); |
|
548 |
iSeed[1]=0; |
|
549 |
iTickPeriodUs=Kern::TickPeriod(); |
|
550 |
||
551 |
// Careful with the constants here or GCC will get it wrong |
|
552 |
iYear2000=Int64(KDaysFrom0ADTo2000AD)*Int64(KSecondsPerDay); |
|
553 |
iYear2000*=1000000; |
|
554 |
||
555 |
iThread=&Kern::CurrentThread(); |
|
556 |
iThread->Open(); |
|
557 |
} |
|
558 |
||
559 |
TInt DTick::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
560 |
// |
|
561 |
// Create channel |
|
562 |
// |
|
563 |
{ |
|
564 |
||
565 |
if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer)) |
|
566 |
return KErrNotSupported; |
|
567 |
||
568 |
for (TInt i=0; i<KMaxTimers; i++) |
|
569 |
{ |
|
570 |
TInt r = Kern::CreateClientRequest(iTickTimer[i].iRequest); |
|
571 |
if (r != KErrNone) |
|
572 |
return r; |
|
573 |
} |
|
574 |
||
575 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__) |
|
576 |
// Set up Timer3 as a free-running timer at 12Mhz/32 = 375kHz |
|
577 |
TOmapTimer::SetTimer3Ctrl( TOmapTimer::KHtOSTimer_Cntl_Ar |
|
578 |
| TOmapTimer::KHtOSTimer_Cntl_Free |
|
579 |
| TOmapTimer::KHtOSTimer_Cntl_ClkEnable ); |
|
580 |
TOmapTimer::SetTimer3Prescale( TOmapTimer::EPrescaleBy32 ); |
|
581 |
// Autoreload 0xFFFFFFFF to effectively wrap from zero back to 0xFFFFFFFF |
|
582 |
TOmapTimer::SetTimer3LoadTim( 0xFFFFFFFF ); |
|
583 |
TOmapTimer::StartTimer3(); |
|
584 |
#endif |
|
585 |
#if defined(__MI920__) || defined(__NI1136__) |
|
586 |
// Set up timer 1 as free running 93.75KHz clock |
|
587 |
TIntegratorAP::SetTimerLoad(TIntegratorAP::ECounterTimer1, 0); // start from 0xffff downwards |
|
588 |
TIntegratorAP::SetTimerMode(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerModeFreeRunning); |
|
589 |
TIntegratorAP::SetTimerPreScale(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerPreScaleDiv256); // 93.75kHz wrap 699ms |
|
590 |
TIntegratorAP::EnableTimer(TIntegratorAP::ECounterTimer1, TIntegratorAP::EEnable); |
|
591 |
TIntegratorAP::DisableIrq(TIntegratorAP::EIrqSet0,EIntIdTimer0); // make sure timer int is disabled |
|
592 |
#endif |
|
593 |
#if defined(__RVEMUBOARD__) |
|
594 |
// Switch timer 1 to a 1MHz clock in the system controller Ctrl register |
|
595 |
TRvEmuBoard::SetSCCtrl(KTimer1EnSel); |
|
596 |
||
597 |
// Set up timer 1 as free running 3.90625kHz clock |
|
598 |
TRvEmuBoard::SetTimerMode(KHwCounterTimer1, TRvEmuBoard::ETimerModeFreeRunning); |
|
599 |
TRvEmuBoard::SetTimerPreScale(KHwCounterTimer1, TRvEmuBoard::ETimerPreScaleDiv256);// 3.90625kHz wrap 16.777s |
|
600 |
TRvEmuBoard::EnableTimer(KHwCounterTimer1, TRvEmuBoard::EEnable); |
|
601 |
#endif |
|
602 |
#if defined(__NE1_TB__) |
|
603 |
// nothing to do since we use fast counter |
|
604 |
#endif |
|
605 |
#ifdef __MAWD__ |
|
606 |
// Set up timer 1 as free running 2kHz clock |
|
607 |
TWind::SetBuzzerControl(0); // disable buzzer |
|
608 |
TWind::SetTimer1Control(KWindTimer1ControlTimerEnable); |
|
609 |
TWind::SetTimer1Load(0); |
|
610 |
#endif |
|
611 |
#ifdef __MEIG__ |
|
612 |
// Set up timer 1 as free running 2kHz clock |
|
613 |
TEiger::ModifyControl21(KEigerControlTimer1PreOrFree|KEigerControlTimer1K512OrK2| |
|
614 |
KEigerControlBuzzerToggle|KEigerControlBuzzerTimer1OrToggle,0); |
|
615 |
TEiger::SetTimer1Data(0); |
|
616 |
#endif |
|
617 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
|
618 |
// Set up timer channel 2 as free running counter at 14318180/12 Hz |
|
619 |
SetUpTimerChannel2(); |
|
620 |
#endif |
|
621 |
return KErrNone; |
|
622 |
} |
|
623 |
||
624 |
DTick::~DTick() |
|
625 |
// |
|
626 |
// Destructor |
|
627 |
// |
|
628 |
{ |
|
629 |
TInt i; |
|
630 |
for (i=0; i<KMaxTimers; i++) |
|
631 |
{ |
|
632 |
iTickTimer[i].Cancel(); |
|
633 |
Kern::DestroyClientRequest(iTickTimer[i].iRequest); |
|
634 |
} |
|
635 |
Kern::SafeClose((DObject*&)iThread, NULL); |
|
636 |
} |
|
637 |
||
638 |
TInt DTick::Request(TInt aFunction, TAny* a1, TAny* a2) |
|
639 |
// |
|
640 |
// Runs in context of client thread, system unlocked on entry and exit |
|
641 |
// |
|
642 |
{ |
|
643 |
NKern::ThreadEnterCS(); // stop thread kills |
|
644 |
TInt r=KErrNone; |
|
645 |
TInt id=(TInt)a1; |
|
646 |
TTickTimer& m=iTickTimer[id]; |
|
647 |
switch (aFunction) |
|
648 |
{ |
|
649 |
case RTickTest::EControlStart: |
|
650 |
{ |
|
651 |
STimerStartInfo info; |
|
652 |
kumemget(&info,a2,sizeof(info)); |
|
653 |
r=m.iRequest->SetStatus(info.iStatus); |
|
654 |
if (r==KErrNone) |
|
655 |
r=m.Start(info.iMode, info.iMin, info.iRange, info.iCount); |
|
656 |
break; |
|
657 |
} |
|
658 |
case RTickTest::EControlStop: |
|
659 |
{ |
|
660 |
m.Cancel(); |
|
661 |
break; |
|
662 |
} |
|
663 |
case RTickTest::EControlGetInfo: |
|
664 |
{ |
|
665 |
STickTestInfo info; |
|
666 |
info.iMinErr=m.iMinErr; |
|
667 |
info.iMaxErr=m.iMaxErr; |
|
668 |
info.iCount=m.iCount; |
|
669 |
info.iRequestedCount=m.iRequestedCount; |
|
670 |
Int64 avg=m.iTotalErr/m.iCount; |
|
671 |
info.iAvgErr=(TInt)avg; |
|
672 |
info.iTotalTime=TicksToMicroseconds(m.iStartTime0); |
|
673 |
kumemput(a2,&info,sizeof(info)); |
|
674 |
break; |
|
675 |
} |
|
676 |
case RTickTest::EControlReadRtc: |
|
677 |
{ |
|
678 |
TInt hwrtc; |
|
679 |
Arch::TheAsic()->SystemTimeInSecondsFrom2000(hwrtc); |
|
680 |
*(TTimeK*)a1=Kern::SystemTime(); |
|
681 |
TTimeK hwtimeK=(TTimeK)hwrtc; |
|
682 |
hwtimeK*=1000000; |
|
683 |
hwtimeK+=iYear2000; |
|
684 |
kumemput(a2,&hwtimeK,sizeof(hwtimeK)); |
|
685 |
break; |
|
686 |
} |
|
687 |
case RTickTest::EControlGetTickPeriod: |
|
688 |
{ |
|
689 |
r=iTickPeriodUs; |
|
690 |
break; |
|
691 |
} |
|
692 |
default: |
|
693 |
r=KErrNotSupported; |
|
694 |
break; |
|
695 |
} |
|
696 |
NKern::ThreadLeaveCS(); |
|
697 |
return r; |
|
698 |
} |
|
699 |