author | hgs |
Wed, 12 May 2010 10:34:10 +0100 | |
changeset 133 | 2a0ada0a1bf8 |
parent 90 | 947f0dc9f7a8 |
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_mstim.cpp |
|
15 |
// LDD for testing millisecond timer |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#include "plat_priv.h" |
|
20 |
#if defined(__MEIG__) |
|
21 |
#include <cl7211.h> |
|
22 |
#elif defined(__MAWD__) |
|
23 |
#include <windermere.h> |
|
24 |
#elif defined(__MISA__) |
|
25 |
#include <sa1100.h> |
|
26 |
#elif defined(__MCOT__) |
|
27 |
#include <cotulla.h> |
|
28 |
#elif defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__) |
|
29 |
#include <omap.h> |
|
30 |
#include <omap_timer.h> |
|
31 |
#elif defined(__MI920__) || defined(__NI1136__) |
|
32 |
#ifdef __MI920__ |
|
33 |
#define USE_CM920_FRC |
|
34 |
#endif |
|
35 |
#ifdef USE_CM920_FRC |
|
36 |
#include <iolines.h> |
|
37 |
#else |
|
38 |
#include <integratorap.h> |
|
39 |
#endif |
|
40 |
#elif defined(__RVEMUBOARD__) |
|
41 |
#include <rvemuboard.h> |
|
42 |
#elif defined(__NE1_TB__) |
|
43 |
#include <upd35001_timer.h> |
|
133 | 44 |
#elif defined(__MRAP__) |
45 |
#include <rap.h> |
|
0 | 46 |
#endif |
47 |
#include "d_mstim.h" |
|
48 |
#include "../misc/prbs.h" |
|
49 |
||
50 |
#if defined(__WINS__) |
|
51 |
typedef Int64 TCounter; |
|
52 |
typedef Int64 TDelta; |
|
53 |
const TDelta KMaxDelta = 0x7fffffffffffffff; |
|
54 |
const TDelta KMinDelta = 0x8000000000000000; |
|
55 |
#else |
|
56 |
typedef TUint TCounter; |
|
57 |
typedef TInt TDelta; |
|
58 |
const TDelta KMaxDelta = KMaxTInt; |
|
59 |
const TDelta KMinDelta = KMinTInt; |
|
60 |
#endif |
|
61 |
||
62 |
#ifdef __MISA__ |
|
63 |
inline TCounter TIMER() |
|
64 |
{ return *(volatile TUint*)KHwRwOstOscr; } |
|
65 |
#endif |
|
66 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__) |
|
67 |
inline TCounter TIMER() |
|
68 |
{ return TOmapTimer::Timer3Value(); } |
|
69 |
#endif |
|
70 |
#ifdef __MCOT__ |
|
71 |
inline TCounter TIMER() |
|
72 |
{ return *(volatile TUint*)KHwRwOstOscr; } |
|
73 |
#endif |
|
74 |
#ifdef __MAWD__ |
|
75 |
inline TCounter TIMER() |
|
76 |
{ return *(volatile TUint*)(KWindBaseAddress+KWindTimer1Value16)&0xffff; } |
|
77 |
#endif |
|
78 |
#ifdef __MEIG__ |
|
79 |
inline TCounter TIMER() |
|
80 |
{ return *(volatile TUint*)(KEigerBaseAddress+KEigerTimer1Data16)&0xffff;} |
|
81 |
#endif |
|
82 |
#if defined(__MI920__) || defined(__NI1136__) |
|
83 |
inline TCounter TIMER() |
|
84 |
#ifdef USE_CM920_FRC |
|
85 |
{ return *(volatile TUint*)(KHwRwCoreClkCounter);} // 32-bit Core module counter inc's at 24MHz |
|
86 |
#else |
|
87 |
{ return *(volatile TUint*)(KHwCounterTimer1+KHoTimerValue)&0xffff;} |
|
88 |
#endif |
|
89 |
#endif |
|
90 |
#if defined(__RVEMUBOARD__) |
|
91 |
inline TCounter TIMER() |
|
92 |
{ return *(volatile TUint*)(KHwCounterTimer1+KHoTimerValue)&0xffff;} |
|
93 |
#endif |
|
94 |
#ifdef __NE1_TB__ |
|
95 |
inline TCounter TIMER() |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
96 |
{ return NETimer::Timer(5).iTimerCount; } |
0 | 97 |
#endif |
133 | 98 |
#ifdef __MRAP__ |
99 |
inline TCounter TIMER() |
|
100 |
{ TRap::SetRegister32(1, KRapRegRTC001_TRIGGER); |
|
101 |
return TRap::Register32(KRapRegRTC001_LONGCOUNT); } |
|
102 |
#endif |
|
0 | 103 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
104 |
TCounter TIMER(); |
|
105 |
void SetUpTimerChannel2(); |
|
106 |
#endif |
|
107 |
||
108 |
#ifdef __WINS__ |
|
109 |
inline TCounter TIMER() |
|
110 |
{ |
|
111 |
LARGE_INTEGER c; |
|
112 |
QueryPerformanceCounter(&c); |
|
113 |
return c.QuadPart; |
|
114 |
} |
|
115 |
#endif |
|
116 |
||
117 |
#if defined(__MISA__) || (defined(USE_CM920_FRC) && (defined(__MI920__) || defined(__NI1136__))) |
|
118 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
119 |
{ return final-initial; } // SA1100 timer counts up |
|
120 |
#endif |
|
121 |
#if defined(__MCOT__) |
|
122 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
123 |
{ return final-initial; } // Cotulla timer counts up |
|
124 |
#endif |
|
125 |
#if defined(__MAWD__) || defined(__MEIG__) || (!defined(USE_CM920_FRC) && (defined(__MI920__) || defined(__NI1136__))) |
|
126 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
127 |
{ return (initial-final)&0xffff; } // Eiger/Windermere/Integrator timer counts down |
|
128 |
#endif |
|
129 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__) |
|
130 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
131 |
{ return (initial-final);} // OMAP timer counts down |
|
132 |
#endif |
|
133 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
|
134 |
TDelta TimeDelta(TUint initial, TUint final) |
|
135 |
{ |
|
136 |
TUint tickdiff=(initial-final)&0xffff; |
|
137 |
TUint msdiff=((final>>16)-(initial>>16))&0xffff; |
|
138 |
msdiff=1193*msdiff-tickdiff; |
|
139 |
msdiff=(msdiff+32768)&~0xffff; |
|
140 |
return msdiff+tickdiff; |
|
141 |
} |
|
142 |
#endif |
|
143 |
#ifdef __NE1_TB__ |
|
144 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
145 |
{ return final - initial; } |
|
146 |
#endif |
|
133 | 147 |
#if defined(__MRAP__) |
148 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
149 |
{ return final-initial; } // RAP RTC timer counts up |
|
150 |
#endif |
|
0 | 151 |
#ifdef __WINS__ |
152 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
153 |
{ return final-initial; } // counts up |
|
154 |
#endif |
|
155 |
#if defined(__RVEMUBOARD__) |
|
156 |
inline TDelta TimeDelta(TCounter initial, TCounter final) |
|
157 |
{ return (initial-final)&0xffff; } // Timer counts down |
|
158 |
#endif |
|
159 |
||
160 |
const TInt KMajorVersionNumber=0; |
|
161 |
const TInt KMinorVersionNumber=1; |
|
162 |
const TInt KBuildVersionNumber=1; |
|
163 |
||
164 |
const TInt KMaxMsTim=9; |
|
165 |
const TInt KMaxMsTimR=9; |
|
166 |
||
167 |
TInt TicksToMicroseconds(TDelta aTicks) |
|
168 |
{ |
|
169 |
#if defined(__MISA__) || defined(__MCOT__) |
|
170 |
Int64 ticks(aTicks); |
|
171 |
ticks*=(1000000); |
|
172 |
ticks+=KHwOscFreqHz/2; // 3.6864MHz tick |
|
173 |
ticks/=KHwOscFreqHz; |
|
174 |
return (TInt)ticks; |
|
175 |
#endif |
|
176 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__) |
|
177 |
// Timer runs at 12Mhz/32 = 375kHz. Each tick is 2.66...us which is 16/6us |
|
178 |
aTicks<<=4; // * 16 |
|
179 |
aTicks+=3; // rounding to the closest number of us |
|
180 |
return (TInt)(aTicks/6); // us = (ticks*16+3)/6 |
|
181 |
#endif |
|
182 |
#if defined(__MI920__) || defined(__NI1136__) |
|
183 |
#if defined(USE_CM920_FRC) |
|
184 |
Int64 ticks(aTicks); |
|
185 |
ticks*=(1000000); |
|
186 |
ticks+=24000000/2; |
|
187 |
ticks/=24000000; |
|
188 |
return (TInt)ticks; |
|
189 |
#else |
|
190 |
aTicks<<=14; // 1 tick = 32/3 us |
|
191 |
aTicks+=768; // round |
|
192 |
return (TInt)(aTicks/1536); |
|
193 |
#endif |
|
194 |
#endif |
|
195 |
#if defined(__RVEMUBOARD__) |
|
196 |
return (TInt)(aTicks*256); // 1 tick = 256 us |
|
197 |
#endif |
|
198 |
#if defined(__MAWD__) || defined(__MEIG__) |
|
199 |
return aTicks*500; // 2kHz tick |
|
200 |
#endif |
|
201 |
#if defined(__NE1_TB__) |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
202 |
NETimer& T5 = NETimer::Timer(5); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
203 |
TUint prescale = __e32_find_ms1_32(T5.iPrescaler & 0x3f); |
0 | 204 |
TInt f = 66666667 >> prescale; |
205 |
TInt64 x = I64LIT(1000000); |
|
206 |
x *= TInt64(aTicks); |
|
207 |
x += TInt64(f>>1); |
|
208 |
x /= TInt64(f); |
|
209 |
return (TInt)x; |
|
210 |
#endif |
|
133 | 211 |
#if defined(__MRAP__) |
212 |
// RTC runs with 32.768 kHz -> one tick is |
|
213 |
const TUint KRTCClockHz = 32768; |
|
214 |
Int64 ticks(aTicks); |
|
215 |
ticks*=(1000000); |
|
216 |
ticks+=KRTCClockHz/2; // 32.768 kHz tick |
|
217 |
ticks/=KRTCClockHz; |
|
218 |
return (TInt)ticks; |
|
219 |
#endif |
|
0 | 220 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
221 |
TInt x = aTicks; |
|
222 |
TInt y = x; |
|
223 |
y -= ((3*x)>>4); // * 0.D |
|
224 |
y += (aTicks>>12); // * 0.D00D |
|
225 |
TInt z = (6*x)>>8; // * 0.06 |
|
226 |
y += z; // * 0.D60D |
|
227 |
y += (x>>9); // * 0.D68D |
|
228 |
y += (z>>16); // * 0.D68D6 |
|
229 |
y += (z>>20); // * 0.D68D66 |
|
230 |
return y; |
|
231 |
#endif |
|
232 |
#ifdef __WINS__ |
|
233 |
LARGE_INTEGER f; |
|
234 |
QueryPerformanceFrequency(&f); |
|
235 |
aTicks*=1000000; |
|
236 |
aTicks+=f.QuadPart-1; |
|
237 |
aTicks/=f.QuadPart; |
|
238 |
return (TInt)aTicks; |
|
239 |
#endif |
|
240 |
} |
|
241 |
||
242 |
||
243 |
void InitTimer() |
|
244 |
{ |
|
245 |
#ifdef __MAWD__ |
|
246 |
// Set up timer 1 as free running 2kHz clock |
|
247 |
TWind::SetBuzzerControl(0); // disable buzzer |
|
248 |
TWind::SetTimer1Control(KWindTimer1ControlTimerEnable); |
|
249 |
TWind::SetTimer1Load(0); |
|
250 |
#endif |
|
251 |
#ifdef __MEIG__ |
|
252 |
// Set up timer 1 as free running 2kHz clock |
|
253 |
TEiger::ModifyControl21(KEigerControlTimer1PreOrFree|KEigerControlTimer1K512OrK2| |
|
254 |
KEigerControlBuzzerToggle|KEigerControlBuzzerTimer1OrToggle,0); |
|
255 |
TEiger::SetTimer1Data(0); |
|
256 |
#endif |
|
257 |
#if defined(__MISA__) |
|
258 |
// MISA free running counter is always active - no initialisation required |
|
259 |
#endif |
|
260 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__) |
|
261 |
// Set up Timer3 as a free-running timer at 12Mhz/32 = 375kHz |
|
262 |
TOmapTimer::SetTimer3Ctrl( TOmapTimer::KHtOSTimer_Cntl_Ar |
|
263 |
| TOmapTimer::KHtOSTimer_Cntl_Free |
|
264 |
| TOmapTimer::KHtOSTimer_Cntl_ClkEnable ); |
|
265 |
TOmapTimer::SetTimer3Prescale( TOmapTimer::EPrescaleBy32 ); |
|
266 |
// Autoreload 0xFFFFFFFF to effectively wrap from zero back to 0xFFFFFFFF |
|
267 |
TOmapTimer::SetTimer3LoadTim( 0xFFFFFFFF ); |
|
268 |
TOmapTimer::StartTimer3(); |
|
269 |
#endif |
|
270 |
#if defined(__MI920__) || defined(__NI1136__) |
|
271 |
#if !defined(USE_CM920_FRC) |
|
272 |
TIntegratorAP::SetTimerMode(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerModeFreeRunning); |
|
273 |
TIntegratorAP::SetTimerPreScale(TIntegratorAP::ECounterTimer1, TIntegratorAP::ETimerPreScaleDiv256); // 93.75kHz wrap 699ms |
|
274 |
TIntegratorAP::EnableTimer(TIntegratorAP::ECounterTimer1, TIntegratorAP::EEnable); |
|
275 |
#endif |
|
276 |
#endif |
|
277 |
#if defined(__RVEMUBOARD__) |
|
278 |
// Switch timer 1 to a 1MHz clock in the system controller Ctrl register |
|
279 |
TRvEmuBoard::SetSCCtrl(KTimer1EnSel); |
|
280 |
||
281 |
// Set up timer 1 as free running 3.90625kHz clock |
|
282 |
TRvEmuBoard::SetTimerMode(KHwCounterTimer1, TRvEmuBoard::ETimerModeFreeRunning); |
|
283 |
TRvEmuBoard::SetTimerPreScale(KHwCounterTimer1, TRvEmuBoard::ETimerPreScaleDiv256);// 3.90625kHz wrap 16.777s |
|
284 |
TRvEmuBoard::EnableTimer(KHwCounterTimer1, TRvEmuBoard::EEnable); |
|
285 |
#endif |
|
286 |
#if defined(__NE1_TB__) |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
287 |
// set up timer 5 |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
288 |
NETimer& T5 = NETimer::Timer(5); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
289 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
290 |
T5.iTimerCtrl = 0; // stop and reset timer 5 |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
291 |
T5.iGTICtrl = 0; // disable timer 5 capture modes |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
292 |
__e32_io_completion_barrier(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
293 |
T5.iPrescaler = KNETimerPrescaleBy32; // Timer 5 prescaled by 32 (=2.0833MHz) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
294 |
__e32_io_completion_barrier(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
295 |
T5.iGTInterruptEnable = 0; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
296 |
__e32_io_completion_barrier(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
297 |
T5.iGTInterrupt = KNETimerGTIInt_All; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
298 |
__e32_io_completion_barrier(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
299 |
T5.iTimerCtrl = KNETimerCtrl_CE; // deassert reset for timer 5, count still stopped |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
300 |
__e32_io_completion_barrier(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
301 |
T5.iTimerReset = 0xffffffffu; // timer 5 wraps after 2^32 counts |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
302 |
__e32_io_completion_barrier(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
303 |
T5.iTimerCtrl = KNETimerCtrl_CE | KNETimerCtrl_CAE; // start timer 5 |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
304 |
__e32_io_completion_barrier(); |
0 | 305 |
#endif |
306 |
#if defined(__EPOC32__) && defined(__CPU_X86) |
|
307 |
// Set up timer channel 2 as free running counter at 14318180/12 Hz |
|
308 |
SetUpTimerChannel2(); |
|
309 |
#endif |
|
310 |
} |
|
311 |
||
312 |
// global Dfc Que |
|
313 |
TDynamicDfcQue* gDfcQ; |
|
314 |
||
315 |
class NTimerQTest |
|
316 |
{ |
|
317 |
public: |
|
318 |
static inline NTimerQ& Timer() |
|
319 |
{ return *(NTimerQ*)NTimerQ::TimerAddress(); } |
|
320 |
static inline TUint32 MsCount() |
|
321 |
{ return Timer().iMsCount; } |
|
322 |
static inline void Setup(TAny* aPtr) |
|
323 |
{ NTimerQ& m=Timer(); m.iDebugFn=Test; m.iDebugPtr=aPtr; } |
|
324 |
static inline void Stop() |
|
325 |
{ NTimerQ& m=Timer(); m.iDebugFn=NULL; m.iDebugPtr=NULL; } |
|
326 |
static inline TBool XferC() |
|
327 |
{ return Timer().iTransferringCancelled; } |
|
328 |
static inline TBool CritC() |
|
329 |
{ return Timer().iCriticalCancelled; } |
|
330 |
static void Test(TAny* aPtr, TInt aPos); |
|
331 |
}; |
|
332 |
||
333 |
class DMsTim; |
|
334 |
||
335 |
class TMsTim : public NTimer |
|
336 |
{ |
|
337 |
public: |
|
338 |
enum TMode |
|
339 |
{ |
|
340 |
EIntAfter, |
|
341 |
EDfcAfter, |
|
342 |
EIntAgain, |
|
343 |
EDfcAgain, |
|
344 |
EIntCancel, |
|
345 |
EDfcCancel, |
|
346 |
EUserDfcAfter |
|
347 |
}; |
|
348 |
||
349 |
enum TModeX |
|
350 |
{ |
|
351 |
EIntAgainOnce=7, |
|
352 |
EUserDfcAgainOnce |
|
353 |
}; |
|
354 |
public: |
|
355 |
TMsTim(); |
|
356 |
~TMsTim(); |
|
357 |
TInt Create(); |
|
358 |
TInt Start(TInt aMode, TInt aInterval, TInt aParam); |
|
359 |
static void MsCallBack(TAny* aPtr); |
|
360 |
static void IDfcFn(TAny* aPtr); |
|
361 |
static void DfcFn(TAny* aPtr); |
|
362 |
void CompleteClient(TInt aValue); |
|
363 |
public: |
|
364 |
TMode iMode; |
|
365 |
TInt iInterval; |
|
366 |
TInt iParam; |
|
367 |
TCounter iStartTime; |
|
368 |
TDelta iMin; |
|
369 |
TDelta iMax; |
|
370 |
Int64 iTotal; |
|
371 |
TInt iCount; |
|
372 |
DMsTim* iLdd; |
|
373 |
TInt iId; |
|
374 |
TClientRequest* iRequest; |
|
375 |
TDfc iIDfc; |
|
376 |
TDfc iCompletionDfc; |
|
377 |
}; |
|
378 |
||
379 |
class TMsTimRand : public NTimer |
|
380 |
{ |
|
381 |
public: |
|
382 |
TMsTimRand(); |
|
383 |
#ifdef __SMP__ |
|
384 |
~TMsTimRand(); |
|
385 |
#endif |
|
386 |
TInt Start(TInt aInterval, DMsTim* aLdd, TInt aPos); |
|
387 |
static void MsCallBack(TAny* aPtr); |
|
388 |
void FillWithGarbage(TUint aFillValue); |
|
389 |
public: |
|
390 |
TInt iInterval; |
|
391 |
TCounter iStartTime; |
|
392 |
DMsTim* iLdd; |
|
393 |
}; |
|
394 |
||
395 |
class DMsTimFactory : public DLogicalDevice |
|
396 |
// |
|
397 |
// Millisecond timer LDD factory |
|
398 |
// |
|
399 |
{ |
|
400 |
public: |
|
401 |
DMsTimFactory(); |
|
402 |
~DMsTimFactory(); |
|
403 |
virtual TInt Install(); //overriding pure virtual |
|
404 |
virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual |
|
405 |
virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual |
|
406 |
}; |
|
407 |
||
408 |
class DMsTim : public DLogicalChannel |
|
409 |
// |
|
410 |
// Millisecond timer LDD channel |
|
411 |
// |
|
412 |
{ |
|
413 |
public: |
|
414 |
DMsTim(); |
|
415 |
~DMsTim(); |
|
416 |
protected: |
|
417 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
418 |
TInt DoControl(TInt aFunction, TAny* a1, TAny* a2); |
|
419 |
TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2); |
|
420 |
virtual void HandleMsg(TMessageBase* aMsg); |
|
421 |
public: |
|
422 |
void TimerExpired(TInt anId); |
|
423 |
inline DThread* Client() { return iThread; } |
|
424 |
public: |
|
425 |
DThread* iThread; |
|
426 |
TMsTim iMsTim[KMaxMsTim]; |
|
427 |
TMsTimRand iMsTimR[KMaxMsTimR]; |
|
428 |
TInt iRandMin; |
|
429 |
TInt iRandMax; |
|
430 |
TInt iXferC; |
|
431 |
TInt iCritC; |
|
432 |
TInt iStartFail; |
|
433 |
TInt iCallBacks; |
|
434 |
TInt iCompletions; |
|
435 |
TUint iSeed[2]; |
|
436 |
}; |
|
437 |
||
438 |
TMsTim::TMsTim() |
|
439 |
: NTimer(MsCallBack,this), |
|
440 |
iMode(EIntAfter), |
|
441 |
iInterval(0), |
|
442 |
iParam(0), |
|
443 |
iStartTime(0), |
|
444 |
iMin(KMaxDelta), |
|
445 |
iMax(KMinDelta), |
|
446 |
iTotal(0), |
|
447 |
iCount(0), |
|
448 |
iRequest(NULL), |
|
449 |
iIDfc(IDfcFn,this), |
|
450 |
iCompletionDfc(DfcFn,this,gDfcQ,1) |
|
451 |
{ |
|
452 |
} |
|
453 |
||
454 |
TMsTim::~TMsTim() |
|
455 |
{ |
|
456 |
Kern::DestroyClientRequest(iRequest); |
|
457 |
#ifdef __SMP__ |
|
458 |
NTimer* nt = STATIC_CAST(NTimer*,this); |
|
459 |
new (nt) NTimer(&MsCallBack, this); // so NTimer destructor doesn't kill us |
|
460 |
#endif |
|
461 |
} |
|
462 |
||
463 |
TInt TMsTim::Create() |
|
464 |
{ |
|
465 |
return Kern::CreateClientRequest(iRequest); |
|
466 |
} |
|
467 |
||
468 |
void TMsTim::IDfcFn(TAny* aPtr) |
|
469 |
{ |
|
470 |
TMsTim& m=*(TMsTim*)aPtr; |
|
471 |
TInt c = NKern::CurrentContext(); |
|
472 |
__NK_ASSERT_ALWAYS(c == NKern::EIDFC); |
|
473 |
__NK_ASSERT_ALWAYS(NKern::KernelLocked(1)); |
|
474 |
m.iCompletionDfc.DoEnque(); |
|
475 |
} |
|
476 |
||
477 |
void TMsTim::DfcFn(TAny* aPtr) |
|
478 |
{ |
|
479 |
TMsTim& m=*(TMsTim*)aPtr; |
|
480 |
if (m.iMode==EUserDfcAfter) |
|
481 |
{ |
|
482 |
TCounter timer_val=TIMER(); |
|
483 |
TDelta time=TimeDelta(m.iStartTime, timer_val); |
|
484 |
++m.iCount; |
|
485 |
if (time<m.iMin) |
|
486 |
m.iMin=time; |
|
487 |
if (time>m.iMax) |
|
488 |
m.iMax=time; |
|
489 |
m.iTotal+=time; |
|
490 |
} |
|
491 |
m.iLdd->TimerExpired(m.iId); |
|
492 |
} |
|
493 |
||
494 |
void TestThreadContext() |
|
495 |
{ |
|
496 |
TInt c1 = NKern::CurrentContext(); |
|
497 |
NKern::Lock(); |
|
498 |
TInt c2 = NKern::CurrentContext(); |
|
499 |
NKern::Unlock(); |
|
500 |
__NK_ASSERT_ALWAYS((c1 == NKern::EThread) && (c2 == NKern::EThread)); |
|
501 |
} |
|
502 |
||
503 |
void TMsTim::MsCallBack(TAny* aPtr) |
|
504 |
{ |
|
505 |
TInt c = NKern::CurrentContext(); |
|
506 |
TCounter timer_val=TIMER(); |
|
507 |
TMsTim& m=*(TMsTim*)aPtr; |
|
508 |
TDelta time=TimeDelta(m.iStartTime, timer_val); |
|
509 |
if (++m.iCount>0 || (m.iMode!=EIntAgain && m.iMode!=EDfcAgain)) |
|
510 |
{ |
|
511 |
if (time<m.iMin) |
|
512 |
m.iMin=time; |
|
513 |
if (time>m.iMax) |
|
514 |
m.iMax=time; |
|
515 |
m.iTotal+=time; |
|
516 |
} |
|
517 |
switch (m.iMode) |
|
518 |
{ |
|
519 |
case EIntAfter: |
|
520 |
__NK_ASSERT_ALWAYS(c == NKern::EInterrupt); |
|
521 |
m.iIDfc.Add(); |
|
522 |
break; |
|
523 |
case EDfcAfter: |
|
524 |
TestThreadContext(); |
|
525 |
m.iCompletionDfc.Enque(); |
|
526 |
break; |
|
527 |
case EIntAgain: |
|
528 |
__NK_ASSERT_ALWAYS(c == NKern::EInterrupt); |
|
529 |
m.iStartTime=TIMER(); |
|
530 |
m.Again(m.iInterval); |
|
531 |
break; |
|
532 |
case EDfcAgain: |
|
533 |
TestThreadContext(); |
|
534 |
m.iStartTime=TIMER(); |
|
535 |
m.Again(m.iInterval); |
|
536 |
break; |
|
537 |
case EIntCancel: |
|
538 |
__NK_ASSERT_ALWAYS(c == NKern::EInterrupt); |
|
539 |
m.iLdd->iMsTim[m.iParam].Cancel(); |
|
540 |
m.iIDfc.Add(); |
|
541 |
break; |
|
542 |
case EDfcCancel: |
|
543 |
TestThreadContext(); |
|
544 |
m.iLdd->iMsTim[m.iParam].Cancel(); |
|
545 |
m.iCompletionDfc.Enque(); |
|
546 |
break; |
|
547 |
case EUserDfcAfter: |
|
548 |
__NK_ASSERT_ALWAYS(EFalse); |
|
549 |
break; |
|
550 |
} |
|
551 |
} |
|
552 |
||
553 |
TInt TMsTim::Start(TInt aMode, TInt aInterval, TInt aParam) |
|
554 |
{ |
|
555 |
TInt r=KErrGeneral; |
|
556 |
TInt c=0; |
|
557 |
TCounter holder=TIMER(); // holds the start value of timer |
|
558 |
switch (aMode) |
|
559 |
{ |
|
560 |
case EIntAgain: |
|
561 |
c=-1; |
|
562 |
case EIntAfter: |
|
563 |
case EIntCancel: |
|
564 |
r=OneShot(aInterval); |
|
565 |
break; |
|
566 |
case EDfcAgain: |
|
567 |
c=-1; |
|
568 |
case EDfcAfter: |
|
569 |
case EDfcCancel: |
|
570 |
r=OneShot(aInterval,ETrue); |
|
571 |
break; |
|
572 |
case EIntAgainOnce: |
|
573 |
case EUserDfcAgainOnce: |
|
574 |
#ifdef __SMP__ |
|
575 |
i8888.iHState2=FALSE; |
|
576 |
#else |
|
577 |
iCompleteInDfc=FALSE; |
|
578 |
#endif |
|
579 |
r=Again(aInterval); |
|
580 |
if (aMode==EUserDfcAgainOnce) |
|
581 |
aMode=EUserDfcAfter; |
|
582 |
else |
|
583 |
aMode=EIntAfter; |
|
584 |
break; |
|
585 |
case EUserDfcAfter: |
|
586 |
r=OneShot(aInterval, iCompletionDfc); |
|
587 |
break; |
|
588 |
} |
|
589 |
if (r!=KErrNone) |
|
590 |
return r; |
|
591 |
iStartTime=holder; |
|
592 |
iMode=TMode(aMode); |
|
593 |
iInterval=aInterval; |
|
594 |
iParam=aParam; |
|
595 |
iMin=KMaxDelta; |
|
596 |
iMax=KMinDelta; |
|
597 |
iTotal=0; |
|
598 |
iCount=c; |
|
599 |
return KErrNone; |
|
600 |
} |
|
601 |
||
602 |
void TMsTim::CompleteClient(TInt aValue) |
|
603 |
{ |
|
604 |
Kern::QueueRequestComplete(iLdd->Client(),iRequest,aValue); |
|
605 |
} |
|
606 |
||
607 |
TMsTimRand::TMsTimRand() |
|
608 |
: NTimer(&MsCallBack,this) |
|
609 |
{ |
|
610 |
memset(this,0,sizeof(TMsTimRand)); |
|
611 |
#ifdef __SMP__ |
|
612 |
NTimer* nt = STATIC_CAST(NTimer*,this); |
|
613 |
new (nt) NTimer(&MsCallBack,this); |
|
614 |
#else |
|
615 |
iFunction=MsCallBack; // avoid triggering assertion in NTimer::OneShot() |
|
616 |
#endif |
|
617 |
} |
|
618 |
||
619 |
#ifdef __SMP__ |
|
620 |
TMsTimRand::~TMsTimRand() |
|
621 |
{ |
|
622 |
NTimer* nt = STATIC_CAST(NTimer*,this); |
|
623 |
new (nt) NTimer(&MsCallBack, this); // so NTimer destructor doesn't kill us |
|
624 |
} |
|
625 |
#endif |
|
626 |
||
627 |
void TMsTimRand::FillWithGarbage(TUint aFill) |
|
628 |
{ |
|
629 |
#ifdef __SMP__ |
|
630 |
TUint32 f = aFill; |
|
631 |
f |= (f<<8); |
|
632 |
f |= (f<<16); |
|
633 |
iNext = (SDblQueLink*)f; |
|
634 |
iPrev = (SDblQueLink*)f; |
|
635 |
iDfcQ = (TDfcQue*)f; |
|
636 |
iPtr = (TAny*)f; |
|
637 |
iFn = (NEventFn)f; |
|
638 |
iTiedLink.iNext = (SDblQueLink*)f; |
|
639 |
iTiedLink.iPrev = (SDblQueLink*)f; |
|
640 |
#else |
|
641 |
memset(this, (TUint8)aFill, 16); |
|
642 |
#endif |
|
643 |
} |
|
644 |
||
645 |
TInt TMsTimRand::Start(TInt aInterval, DMsTim* aLdd, TInt aPos) |
|
646 |
{ |
|
647 |
iLdd=aLdd; |
|
648 |
#ifdef __SMP__ |
|
649 |
TUint fill=(aPos<<5)|(i8888.iHState1<<2)|3; |
|
650 |
#else |
|
651 |
TUint fill=(aPos<<5)|(iState<<2)|3; |
|
652 |
iPad1 = (TUint8)fill; |
|
653 |
#endif |
|
654 |
TInt r=OneShot(aInterval,ETrue); |
|
655 |
if (r==KErrNone) |
|
656 |
{ |
|
657 |
iPtr=this; |
|
658 |
iInterval=aInterval; |
|
659 |
iStartTime=TIMER(); |
|
660 |
#ifdef __SMP__ |
|
661 |
iFn=MsCallBack; |
|
662 |
i8888.iHState0 = (TUint8)fill; |
|
663 |
if (i8888.iHState1!=EHolding) |
|
664 |
*(TUint*)0xfcd1fcd1=i8888.iHState1; |
|
665 |
#else |
|
666 |
iFunction=MsCallBack; |
|
667 |
iUserFlags = (TUint8)fill; |
|
668 |
if (iState!=EHolding) |
|
669 |
*(TUint*)0xfcd1fcd1=iState; |
|
670 |
#endif |
|
671 |
} |
|
672 |
return r; |
|
673 |
} |
|
674 |
||
675 |
void TMsTimRand::MsCallBack(TAny* aPtr) |
|
676 |
{ |
|
677 |
TMsTimRand& m=*(TMsTimRand*)aPtr; |
|
678 |
TCounter time=TIMER(); |
|
679 |
TDelta elapsed=TimeDelta(m.iStartTime,time); |
|
680 |
TInt error=TicksToMicroseconds(elapsed)-m.iInterval*1000; |
|
681 |
if (error<m.iLdd->iRandMin) |
|
682 |
m.iLdd->iRandMin=error; |
|
683 |
if (error>m.iLdd->iRandMax) |
|
684 |
m.iLdd->iRandMax=error; |
|
685 |
++m.iLdd->iCompletions; |
|
686 |
m.FillWithGarbage(0xd9); |
|
687 |
} |
|
688 |
||
689 |
void NTimerQTest::Test(TAny* aPtr, TInt aPos) |
|
690 |
{ |
|
691 |
DMsTim& ldd=*(DMsTim*)aPtr; |
|
692 |
++ldd.iCallBacks; |
|
693 |
if (aPos==7) |
|
694 |
return; |
|
695 |
TUint action=Random(ldd.iSeed)&31; |
|
696 |
TMsTimRand& m=ldd.iMsTimR[action&7]; |
|
697 |
if (action<8) |
|
698 |
{ |
|
699 |
#ifdef __SMP__ |
|
700 |
TUint fill=(aPos<<5)|(m.i8888.iHState1<<2)|3; |
|
701 |
#else |
|
702 |
TUint fill=(aPos<<5)|(m.iState<<2)|3; |
|
703 |
#endif |
|
704 |
m.Cancel(); |
|
705 |
m.FillWithGarbage(fill); |
|
706 |
} |
|
707 |
else if (action<16) |
|
708 |
{ |
|
709 |
TUint iv=(Random(ldd.iSeed)&31)+32; |
|
710 |
TInt r=m.Start(iv,&ldd,aPos); |
|
711 |
if (r!=KErrNone) |
|
712 |
++ldd.iStartFail; |
|
713 |
} |
|
714 |
if (XferC()) |
|
715 |
++ldd.iXferC; |
|
716 |
if (CritC()) |
|
717 |
++ldd.iCritC; |
|
718 |
} |
|
719 |
||
720 |
DECLARE_STANDARD_LDD() |
|
721 |
{ |
|
722 |
return new DMsTimFactory; |
|
723 |
} |
|
724 |
||
725 |
DMsTimFactory::DMsTimFactory() |
|
726 |
// |
|
727 |
// Constructor |
|
728 |
// |
|
729 |
{ |
|
730 |
iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
731 |
//iParseMask=0;//No units, no info, no PDD |
|
732 |
//iUnitsMask=0;//Only one thing |
|
733 |
} |
|
734 |
||
735 |
TInt DMsTimFactory::Create(DLogicalChannelBase*& aChannel) |
|
736 |
// |
|
737 |
// Create a new DMsTim on this logical device |
|
738 |
// |
|
739 |
{ |
|
740 |
aChannel=new DMsTim; |
|
741 |
return aChannel?KErrNone:KErrNoMemory; |
|
742 |
} |
|
743 |
||
744 |
const TInt KDMsTimThreadPriority = 27; |
|
745 |
_LIT(KDMsTimThread,"DMsTimThread"); |
|
746 |
||
747 |
TInt DMsTimFactory::Install() |
|
748 |
// |
|
749 |
// Install the LDD - overriding pure virtual |
|
750 |
// |
|
751 |
{ |
|
752 |
// Allocate a kernel thread to run the DFC |
|
753 |
TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDMsTimThreadPriority, KDMsTimThread); |
|
754 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
#ifdef CPU_AFFINITY_ANY |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
NKern::ThreadSetCpuAffinity((NThread*)(gDfcQ->iThread), KCpuAffinityAny); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
#endif |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
|
0 | 759 |
if (r != KErrNone) |
760 |
return r; |
|
761 |
||
762 |
return SetName(&KMsTimerLddName); |
|
763 |
} |
|
764 |
||
765 |
void DMsTimFactory::GetCaps(TDes8& aDes) const |
|
766 |
// |
|
767 |
// Get capabilities - overriding pure virtual |
|
768 |
// |
|
769 |
{ |
|
770 |
TCapsMsTimV01 b; |
|
771 |
b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
772 |
Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b)); |
|
773 |
} |
|
774 |
||
775 |
/** |
|
776 |
Destructor |
|
777 |
*/ |
|
778 |
DMsTimFactory::~DMsTimFactory() |
|
779 |
{ |
|
780 |
if (gDfcQ) |
|
781 |
gDfcQ->Destroy(); |
|
782 |
} |
|
783 |
||
784 |
DMsTim::DMsTim() |
|
785 |
// |
|
786 |
// Constructor |
|
787 |
// |
|
788 |
{ |
|
789 |
iThread=&Kern::CurrentThread(); |
|
790 |
iThread->Open(); |
|
791 |
TInt i; |
|
792 |
for (i=0; i<KMaxMsTim; i++) |
|
793 |
{ |
|
794 |
iMsTim[i].iLdd=this; |
|
795 |
iMsTim[i].iId=i; |
|
796 |
} |
|
797 |
for (i=0; i<KMaxMsTimR; i++) |
|
798 |
{ |
|
799 |
iMsTimR[i].iLdd=this; |
|
800 |
} |
|
801 |
iSeed[0]=NTimerQTest::MsCount(); |
|
802 |
iSeed[1]=0; |
|
803 |
} |
|
804 |
||
805 |
TInt DMsTim::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer) |
|
806 |
// |
|
807 |
// Create channel |
|
808 |
// |
|
809 |
{ |
|
810 |
if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer)) |
|
811 |
return KErrNotSupported; |
|
812 |
InitTimer(); |
|
813 |
SetDfcQ(gDfcQ); |
|
814 |
for (TInt i = 0 ; i < KMaxMsTim ; ++i) |
|
815 |
{ |
|
816 |
TInt r = iMsTim[i].Create(); |
|
817 |
if (r != KErrNone) |
|
818 |
return r; |
|
819 |
} |
|
820 |
iMsgQ.Receive(); |
|
821 |
#ifdef __SMP__ |
|
822 |
NKern::ThreadSetCpuAffinity(NKern::CurrentThread(), NKern::NumberOfCpus() - 1); // Try and avoid the cpu the test app is running on |
|
823 |
#endif |
|
824 |
return KErrNone; |
|
825 |
} |
|
826 |
||
827 |
DMsTim::~DMsTim() |
|
828 |
// |
|
829 |
// Destructor |
|
830 |
// |
|
831 |
{ |
|
832 |
#if defined(__MI920__) || defined(__NI1136__) |
|
833 |
#if !defined(USE_CM920_FRC) |
|
834 |
TIntegratorAP::EnableTimer(TIntegratorAP::ECounterTimer1, TIntegratorAP::EDisable); |
|
835 |
#endif |
|
836 |
#endif |
|
837 |
#if defined(__IS_OMAP1510__) || defined(__IS_OMAP1610__) |
|
838 |
TOmapTimer::SetTimer3Ctrl( 0 ); // disable the timer |
|
839 |
#endif |
|
840 |
Kern::SafeClose((DObject*&)iThread, NULL); |
|
841 |
} |
|
842 |
||
843 |
void DMsTim::HandleMsg(TMessageBase* aMsg) |
|
844 |
{ |
|
845 |
TInt r=KErrNone; |
|
846 |
TThreadMessage& m=*(TThreadMessage*)aMsg; |
|
847 |
TInt id=m.iValue; |
|
848 |
if (id==(TInt)ECloseMsg) |
|
849 |
{ |
|
850 |
NTimerQTest::Stop(); |
|
851 |
TInt i; |
|
852 |
for (i=0; i<KMaxMsTim; i++) |
|
853 |
{ |
|
854 |
iMsTim[i].Cancel(); |
|
855 |
iMsTim[i].iCompletionDfc.Cancel(); |
|
856 |
iMsTim[i].CompleteClient(KErrCancel); |
|
857 |
} |
|
858 |
for (i=0; i<KMaxMsTimR; i++) |
|
859 |
{ |
|
860 |
iMsTimR[i].Cancel(); |
|
861 |
iMsTimR[i].FillWithGarbage(0x01); |
|
862 |
} |
|
863 |
m.Complete(KErrNone,EFalse); |
|
864 |
iMsgQ.CompleteAll(KErrServerTerminated); |
|
865 |
return; |
|
866 |
} |
|
867 |
else if (id<0) |
|
868 |
{ |
|
869 |
TRequestStatus* pS=(TRequestStatus*)m.Ptr0(); |
|
870 |
r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2()); |
|
871 |
} |
|
872 |
else |
|
873 |
{ |
|
874 |
r=DoControl(id,m.Ptr0(),m.Ptr1()); |
|
875 |
} |
|
876 |
m.Complete(r,ETrue); |
|
877 |
} |
|
878 |
||
879 |
TInt DMsTim::DoControl(TInt aFunction, TAny* a1, TAny* a2) |
|
880 |
{ |
|
881 |
TInt r=KErrNone; |
|
882 |
TInt id=(TInt)a1; |
|
883 |
TMsTim& m=iMsTim[id]; |
|
884 |
TInt interval=(TInt)a2; |
|
885 |
switch (aFunction) |
|
886 |
{ |
|
887 |
case RMsTim::EControlStartPeriodicInt: |
|
888 |
r=m.Start(TMsTim::EIntAgain,interval,0); |
|
889 |
break; |
|
890 |
case RMsTim::EControlStartPeriodicDfc: |
|
891 |
r=m.Start(TMsTim::EDfcAgain,interval,0); |
|
892 |
break; |
|
893 |
case RMsTim::EControlStopPeriodic: |
|
894 |
m.Cancel(); |
|
895 |
m.iCompletionDfc.Cancel(); |
|
896 |
break; |
|
897 |
case RMsTim::EControlGetInfo: |
|
898 |
{ |
|
899 |
SMsTimerInfo info; |
|
900 |
info.iCount=m.iCount; |
|
901 |
Int64 avg=m.iTotal/m.iCount; |
|
902 |
info.iAvg=TicksToMicroseconds((TInt)avg); |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
903 |
#ifdef __SMP__ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
904 |
info.iMin=info.iAvg; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
905 |
info.iMax=info.iAvg; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
906 |
#else |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
907 |
info.iMin=TicksToMicroseconds(m.iMin); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
908 |
info.iMax=TicksToMicroseconds(m.iMax); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
909 |
#endif |
0 | 910 |
|
911 |
r=Kern::ThreadRawWrite(iThread,a2,&info,sizeof(info)); |
|
912 |
break; |
|
913 |
} |
|
914 |
case RMsTim::EControlBeginRandomTest: |
|
915 |
{ |
|
916 |
iRandMin=KMaxTInt; |
|
917 |
iRandMax=KMinTInt; |
|
918 |
iXferC=0; |
|
919 |
iCritC=0; |
|
920 |
iStartFail=0; |
|
921 |
iCallBacks=0; |
|
922 |
iCompletions=0; |
|
923 |
NTimerQTest::Setup(this); |
|
924 |
break; |
|
925 |
} |
|
926 |
case RMsTim::EControlEndRandomTest: |
|
927 |
{ |
|
928 |
NTimerQTest::Stop(); |
|
929 |
TInt i; |
|
930 |
for (i=0; i<KMaxMsTimR; i++) |
|
931 |
{ |
|
932 |
iMsTimR[i].Cancel(); |
|
933 |
iMsTimR[i].FillWithGarbage(0x35); |
|
934 |
} |
|
935 |
break; |
|
936 |
} |
|
937 |
case RMsTim::EControlGetRandomTestInfo: |
|
938 |
{ |
|
939 |
SRandomTestInfo info; |
|
940 |
info.iMin=iRandMin; |
|
941 |
info.iMax=iRandMax; |
|
942 |
info.iXferC=iXferC; |
|
943 |
info.iCritC=iCritC; |
|
944 |
info.iStartFail=iStartFail; |
|
945 |
info.iCallBacks=iCallBacks; |
|
946 |
info.iCompletions=iCompletions; |
|
947 |
r=Kern::ThreadRawWrite(iThread,a1,&info,sizeof(info)); |
|
948 |
break; |
|
949 |
} |
|
950 |
case RMsTim::EControlGetIdleTime: |
|
951 |
{ |
|
952 |
TInt irq=NKern::DisableAllInterrupts(); |
|
953 |
r=NTimerQ::IdleTime(); |
|
954 |
NKern::RestoreInterrupts(irq); |
|
955 |
break; |
|
956 |
} |
|
957 |
default: |
|
958 |
r=KErrNotSupported; |
|
959 |
break; |
|
960 |
} |
|
961 |
return r; |
|
962 |
} |
|
963 |
||
964 |
TInt DMsTim::DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2) |
|
965 |
{ |
|
966 |
TInt id=(TInt)a1; |
|
967 |
TMsTim& m=iMsTim[aFunction == RMsTim::ERequestIntCancel ? 7 : id]; |
|
968 |
TInt interval=(TInt)a2; |
|
969 |
TInt r=KErrNone; |
|
970 |
switch (aFunction) |
|
971 |
{ |
|
972 |
case RMsTim::ERequestOneShotInt: |
|
973 |
r=m.Start(TMsTim::EIntAfter,interval,0); |
|
974 |
break; |
|
975 |
case RMsTim::ERequestOneShotDfc: |
|
976 |
r=m.Start(TMsTim::EDfcAfter,interval,0); |
|
977 |
break; |
|
978 |
case RMsTim::ERequestIntCancel: |
|
979 |
r=m.Start(TMsTim::EIntCancel,interval,id); |
|
980 |
break; |
|
981 |
case RMsTim::ERequestOneShotIntAgain: |
|
982 |
r=m.Start(TMsTim::EIntAgainOnce,interval,0); |
|
983 |
break; |
|
984 |
case RMsTim::ERequestOneShotUserDfc: |
|
985 |
r=m.Start(TMsTim::EUserDfcAfter,interval,0); |
|
986 |
break; |
|
987 |
case RMsTim::ERequestOneShotUserDfcAgain: |
|
988 |
r=m.Start(TMsTim::EUserDfcAgainOnce,interval,0); |
|
989 |
break; |
|
990 |
default: |
|
991 |
r=KErrNotSupported; |
|
992 |
break; |
|
993 |
} |
|
994 |
m.iRequest->SetStatus(aStatus); |
|
995 |
if (r!=KErrNone) |
|
996 |
Kern::QueueRequestComplete(iThread,m.iRequest,r); |
|
997 |
return r; |
|
998 |
} |
|
999 |
||
1000 |
void DMsTim::TimerExpired(TInt anId) |
|
1001 |
{ |
|
1002 |
TMsTim& m=iMsTim[anId]; |
|
1003 |
switch (m.iMode) |
|
1004 |
{ |
|
1005 |
case TMsTim::EIntAfter: |
|
1006 |
case TMsTim::EDfcAfter: |
|
1007 |
case TMsTim::EUserDfcAfter: |
|
1008 |
m.CompleteClient(KErrNone); |
|
1009 |
break; |
|
1010 |
case TMsTim::EIntAgain: |
|
1011 |
case TMsTim::EDfcAgain: |
|
1012 |
break; |
|
1013 |
case TMsTim::EIntCancel: |
|
1014 |
case TMsTim::EDfcCancel: |
|
1015 |
{ |
|
1016 |
TMsTim& cancelled=iMsTim[m.iParam]; |
|
1017 |
cancelled.CompleteClient(KErrAbort); |
|
1018 |
m.CompleteClient(KErrNone); |
|
1019 |
break; |
|
1020 |
} |
|
1021 |
} |
|
1022 |
} |
|
1023 |