50 TInt TimeRawMS[KMaxTimeMeasurements];//Holds the ROW time in Kernel ticks |
50 TInt TimeRawMS[KMaxTimeMeasurements];//Holds the ROW time in Kernel ticks |
51 |
51 |
52 TInt* TimeValue; |
52 TInt* TimeValue; |
53 TInt TimeMin[KMaxTimeValues]; |
53 TInt TimeMin[KMaxTimeValues]; |
54 TInt TimeMax[KMaxTimeValues]; |
54 TInt TimeMax[KMaxTimeValues]; |
55 |
|
56 RTimer TheTimer; |
|
57 |
|
58 void After(TInt aTime) |
|
59 { |
|
60 TRequestStatus s; |
|
61 TheTimer.HighRes(s, aTime); |
|
62 User::WaitForRequest(s); |
|
63 } |
|
64 |
|
65 TInt Again(TInt aTime) |
|
66 { |
|
67 TRequestStatus s; |
|
68 TheTimer.AgainHighRes(s, aTime); |
|
69 User::WaitForRequest(s); |
|
70 return s.Int(); |
|
71 } |
|
72 |
|
73 void WaitInSteps(TUint aWait, TUint aPeriod, TUint aSteps) |
|
74 { |
|
75 TUint total_ticks = aWait / aPeriod; |
|
76 TUint remain = total_ticks; |
|
77 TUint steps = aSteps > remain ? remain : aSteps; |
|
78 TUint carry = 0; |
|
79 TUint step = 0; |
|
80 while (remain) |
|
81 { |
|
82 TUint stepLength = remain / steps; |
|
83 carry += stepLength; |
|
84 TUint us = carry * aPeriod; |
|
85 TInt r = KErrNone; |
|
86 if (step==0) |
|
87 After(us); |
|
88 else |
|
89 r = Again(us); |
|
90 if (r==KErrNone) |
|
91 carry = 0; |
|
92 ++step; |
|
93 --steps; |
|
94 remain -= stepLength; |
|
95 } |
|
96 } |
|
97 |
55 |
98 void calcStats(TInt i) |
56 void calcStats(TInt i) |
99 { |
57 { |
100 TimeMin[i]=TimeRawMS[0]; |
58 TimeMin[i]=TimeRawMS[0]; |
101 TimeMax[i]=TimeRawMS[0]; |
59 TimeMax[i]=TimeRawMS[0]; |
106 } |
64 } |
107 } |
65 } |
108 |
66 |
109 void printStats() |
67 void printStats() |
110 { |
68 { |
111 test.Printf(_L(" Value Min Max\n")); |
69 test.Printf(_L("Value\tMin\tMax")); |
112 for (TInt i=0;i<KMaxTimeValues;++i) |
70 for (TInt i=0;i<KMaxTimeValues;++i) |
113 { |
71 { |
114 if (TimeValue[i]<0) break; |
72 if (TimeValue[i]<0) break; |
115 test.Printf(_L("%8d %8d %8d\n"),TimeValue[i],TimeMin[i],TimeMax[i]); |
73 test.Printf(_L("%d\t%d\t%d"),TimeValue[i],TimeMin[i],TimeMax[i]); |
116 } |
74 } |
117 } |
75 } |
118 |
76 |
119 #define __BEFORE_WAIT__ \ |
77 #define __BEFORE_WAIT__ \ |
120 test.Printf(_L("Measuring value(%d measurements at each value):\n"), MaxTimeMeasurements);\ |
78 test.Printf(_L("Measuring value(%d measurements at each value):"), MaxTimeMeasurements);\ |
121 for (i=0;i<KMaxTimeValues;++i)\ |
79 for (i=0;i<KMaxTimeValues;++i)\ |
122 {\ |
80 {\ |
123 if (TimeValue[i]<0) break;\ |
81 if (TimeValue[i]<0) break;\ |
124 test.Printf(_L("%8d microseconds ...\n"),TimeValue[i]);\ |
82 test.Printf(_L("%d microseconds ..."),TimeValue[i]);\ |
125 value = TimeValue[i];\ |
83 value = TimeValue[i];\ |
126 for (j=0; j<MaxTimeMeasurements; ++j)\ |
84 for (j=0; j<MaxTimeMeasurements; ++j)\ |
127 {\ |
85 {\ |
128 User::AfterHighRes((Math::Random()&0xf)*1000);\ |
86 User::AfterHighRes((Math::Random()&0xf)*1000);\ |
129 |
87 |
142 { |
100 { |
143 TInt i,j; |
101 TInt i,j; |
144 test.Title(); |
102 test.Title(); |
145 test.Start(_L("Timer resolution test")); |
103 test.Start(_L("Timer resolution test")); |
146 test.SetLogged(ETrue); |
104 test.SetLogged(ETrue); |
147 test(TheTimer.CreateLocal()==KErrNone); |
|
148 RThread This; |
105 RThread This; |
149 This.SetPriority(EPriorityRealTime); |
106 This.SetPriority(EPriorityRealTime); |
150 TUint tick1,tick2; |
107 TUint tick1,tick2; |
151 TInt value, tickPeriod; |
108 TInt value, tickPeriod; |
152 HAL::Get(HAL::ENanoTickPeriod, tickPeriod); |
109 HAL::Get(HAL::ENanoTickPeriod, tickPeriod); |
153 test.Printf(_L("tickPeriod=%d\n"),tickPeriod); |
110 test.Printf(_L("tickPeriod=%d"),tickPeriod); |
154 /////////////////////////////////////////// |
111 /////////////////////////////////////////// |
155 test.Next(_L("Calibrate")); |
112 test.Next(_L("Calibrate")); |
156 MaxTimeMeasurements = KMaxTimeMeasurements; |
113 MaxTimeMeasurements = KMaxTimeMeasurements; |
157 TInt TimeValues1[KMaxTimeValues]={0,-1}; |
114 TInt TimeValues1[KMaxTimeValues]={0,-1}; |
158 TimeValue = &TimeValues1[0]; |
115 TimeValue = &TimeValues1[0]; |
213 test(TimeValue[k] <= TimeMin[k]); |
170 test(TimeValue[k] <= TimeMin[k]); |
214 test((TimeValue[k] + 2*tickPeriod) >= TimeMax[k]); |
171 test((TimeValue[k] + 2*tickPeriod) >= TimeMax[k]); |
215 } |
172 } |
216 #endif |
173 #endif |
217 /////////////////////////////////////////// |
174 /////////////////////////////////////////// |
218 test.Next(_L("RTimer::AgainHighRes (2 steps)")); |
|
219 MaxTimeMeasurements = KMaxTimeMeasurements; |
|
220 TInt TimeValues5[KMaxTimeValues]={2000,4000,8000,16000,32000,64000,128000,-1}; |
|
221 TimeValue = &TimeValues5[0]; |
|
222 __BEFORE_WAIT__ |
|
223 __MEASURE1__ |
|
224 WaitInSteps(value, tickPeriod, 2); |
|
225 __MEASURE2__ |
|
226 __AFTER_WAIT__ |
|
227 #if defined(__EPOC32__) |
|
228 //Check that RTimer::AgainHighRes() calls completed within boundaries |
|
229 for (k = 0; k<KMaxTimeValues; k++) |
|
230 { |
|
231 if (TimeValue[k] == -1) break; |
|
232 test(TimeValue[k] <= TimeMin[k]); |
|
233 test((TimeValue[k] + 2*tickPeriod) >= TimeMax[k]); |
|
234 } |
|
235 #endif |
|
236 /////////////////////////////////////////// |
|
237 test.Next(_L("RTimer::AgainHighRes (5 steps)")); |
|
238 MaxTimeMeasurements = KMaxTimeMeasurements; |
|
239 TInt TimeValues6[KMaxTimeValues]={4000,8000,16000,32000,64000,128000,-1}; |
|
240 TimeValue = &TimeValues6[0]; |
|
241 __BEFORE_WAIT__ |
|
242 __MEASURE1__ |
|
243 WaitInSteps(value, tickPeriod, 5); |
|
244 __MEASURE2__ |
|
245 __AFTER_WAIT__ |
|
246 #if defined(__EPOC32__) |
|
247 //Check that RTimer::AgainHighRes() calls completed within boundaries |
|
248 for (k = 0; k<KMaxTimeValues; k++) |
|
249 { |
|
250 if (TimeValue[k] == -1) break; |
|
251 test(TimeValue[k] <= TimeMin[k]); |
|
252 test((TimeValue[k] + 2*tickPeriod) >= TimeMax[k]); |
|
253 } |
|
254 #endif |
|
255 /////////////////////////////////////////// |
|
256 TheTimer.Close(); |
|
257 test.End(); |
175 test.End(); |
258 return(KErrNone); |
176 return(KErrNone); |
259 } |
177 } |