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 } |
55 |
97 |
56 void calcStats(TInt i) |
98 void calcStats(TInt i) |
57 { |
99 { |
58 TimeMin[i]=TimeRawMS[0]; |
100 TimeMin[i]=TimeRawMS[0]; |
59 TimeMax[i]=TimeRawMS[0]; |
101 TimeMax[i]=TimeRawMS[0]; |
64 } |
106 } |
65 } |
107 } |
66 |
108 |
67 void printStats() |
109 void printStats() |
68 { |
110 { |
69 test.Printf(_L("Value\tMin\tMax")); |
111 test.Printf(_L(" Value Min Max\n")); |
70 for (TInt i=0;i<KMaxTimeValues;++i) |
112 for (TInt i=0;i<KMaxTimeValues;++i) |
71 { |
113 { |
72 if (TimeValue[i]<0) break; |
114 if (TimeValue[i]<0) break; |
73 test.Printf(_L("%d\t%d\t%d"),TimeValue[i],TimeMin[i],TimeMax[i]); |
115 test.Printf(_L("%8d %8d %8d\n"),TimeValue[i],TimeMin[i],TimeMax[i]); |
74 } |
116 } |
75 } |
117 } |
76 |
118 |
77 #define __BEFORE_WAIT__ \ |
119 #define __BEFORE_WAIT__ \ |
78 test.Printf(_L("Measuring value(%d measurements at each value):"), MaxTimeMeasurements);\ |
120 test.Printf(_L("Measuring value(%d measurements at each value):\n"), MaxTimeMeasurements);\ |
79 for (i=0;i<KMaxTimeValues;++i)\ |
121 for (i=0;i<KMaxTimeValues;++i)\ |
80 {\ |
122 {\ |
81 if (TimeValue[i]<0) break;\ |
123 if (TimeValue[i]<0) break;\ |
82 test.Printf(_L("%d microseconds ..."),TimeValue[i]);\ |
124 test.Printf(_L("%8d microseconds ...\n"),TimeValue[i]);\ |
83 value = TimeValue[i];\ |
125 value = TimeValue[i];\ |
84 for (j=0; j<MaxTimeMeasurements; ++j)\ |
126 for (j=0; j<MaxTimeMeasurements; ++j)\ |
85 {\ |
127 {\ |
86 User::AfterHighRes((Math::Random()&0xf)*1000);\ |
128 User::AfterHighRes((Math::Random()&0xf)*1000);\ |
87 |
129 |
100 { |
142 { |
101 TInt i,j; |
143 TInt i,j; |
102 test.Title(); |
144 test.Title(); |
103 test.Start(_L("Timer resolution test")); |
145 test.Start(_L("Timer resolution test")); |
104 test.SetLogged(ETrue); |
146 test.SetLogged(ETrue); |
|
147 test(TheTimer.CreateLocal()==KErrNone); |
105 RThread This; |
148 RThread This; |
106 This.SetPriority(EPriorityRealTime); |
149 This.SetPriority(EPriorityRealTime); |
107 TUint tick1,tick2; |
150 TUint tick1,tick2; |
108 TInt value, tickPeriod; |
151 TInt value, tickPeriod; |
109 HAL::Get(HAL::ENanoTickPeriod, tickPeriod); |
152 HAL::Get(HAL::ENanoTickPeriod, tickPeriod); |
110 test.Printf(_L("tickPeriod=%d"),tickPeriod); |
153 test.Printf(_L("tickPeriod=%d\n"),tickPeriod); |
111 /////////////////////////////////////////// |
154 /////////////////////////////////////////// |
112 test.Next(_L("Calibrate")); |
155 test.Next(_L("Calibrate")); |
113 MaxTimeMeasurements = KMaxTimeMeasurements; |
156 MaxTimeMeasurements = KMaxTimeMeasurements; |
114 TInt TimeValues1[KMaxTimeValues]={0,-1}; |
157 TInt TimeValues1[KMaxTimeValues]={0,-1}; |
115 TimeValue = &TimeValues1[0]; |
158 TimeValue = &TimeValues1[0]; |
170 test(TimeValue[k] <= TimeMin[k]); |
213 test(TimeValue[k] <= TimeMin[k]); |
171 test((TimeValue[k] + 2*tickPeriod) >= TimeMax[k]); |
214 test((TimeValue[k] + 2*tickPeriod) >= TimeMax[k]); |
172 } |
215 } |
173 #endif |
216 #endif |
174 /////////////////////////////////////////// |
217 /////////////////////////////////////////// |
|
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(); |
175 test.End(); |
257 test.End(); |
176 return(KErrNone); |
258 return(KErrNone); |
177 } |
259 } |