IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2010-11-05 14:14:26 (13 years 4 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 9361f148759a47820beb0eb04cfc5c587f966df6 |
Message: | Print a frequency estimate after each burst. - tools/cntr/cntr.c (measure, print_f): moved pretty-printing of the frequency to a separate function - tools/cntr/cntr.c (count_bursts): print a frequency estimate after each burst - tools/cntr/cntr.c (count_bursts): added comment explaining when and where we take the various samples |
Files: |
cntr/tools/cntr/cntr.c (4 diffs) |
Change Details
cntr/tools/cntr/cntr.c | ||
---|---|---|
174 | 174 | } |
175 | 175 | |
176 | 176 | |
177 | /* ---- output ------------------------------------------------------------- */ | |
178 | ||
179 | ||
180 | static void print_f(double f, int digits) | |
181 | { | |
182 | char *f_exp; | |
183 | ||
184 | if (f > 1000000.0) { | |
185 | f /= 1000000.0; | |
186 | f_exp = "M"; | |
187 | } else if (f > 1000.0) { | |
188 | f /= 1000.0; | |
189 | f_exp = "k"; | |
190 | } else { | |
191 | f_exp = ""; | |
192 | } | |
193 | printf("%1.*f %sHz", digits, f, f_exp); | |
194 | } | |
195 | ||
196 | ||
177 | 197 | /* ---- burst counter ------------------------------------------------------ */ |
178 | 198 | |
179 | 199 | |
200 | /* | |
201 | * Here is when the various samples are taken: | |
202 | * | |
203 | * Activity --------XXXXXXXXXXXXX------------- | |
204 | * ^ ^ ^^ | |
205 | * | | last|| | |
206 | * start stable now | |
207 | * |<-t(idle)->| | |
208 | * | |
209 | * "start" is the sample before counter activity | |
210 | * "stable" is the first sample after counter activity | |
211 | * "last" is the sample immediately preceding "now" | |
212 | * "now" is the sample currently being processed | |
213 | * | |
214 | * The count is printed if t(idle) >= timeout. | |
215 | */ | |
216 | ||
180 | 217 | static void count_bursts(usb_dev_handle *dev, double timeout) |
181 | 218 | { |
182 | struct sample start, stable, now; | |
183 | ||
219 | struct sample start, stable, now, last; | |
220 | uint64_t dc, delta_n = 0; | |
221 | double delta_sum = 0, dt; | |
184 | 222 | arm_stop(); |
185 | 223 | |
186 | 224 | while (!get_sample(dev, &start)); |
187 | stable = start; | |
225 | stable = last = start; | |
188 | 226 | while (!stop) { |
189 | 227 | while (!get_sample(dev, &now)) |
190 | 228 | if (stop) |
191 | 229 | break; |
230 | delta_sum += now.t1-last.t1; | |
231 | delta_n++; | |
232 | last = now; | |
192 | 233 | if (stable.cntr != now.cntr) { |
193 | 234 | stable = now; |
194 | 235 | continue; |
195 | 236 | } |
196 | 237 | if (now.t0-stable.t1 < timeout) |
197 | 238 | continue; |
198 | if (now.cntr == start.cntr) | |
199 | continue; | |
200 | printf("%llu\n", (unsigned long long) now.cntr-start.cntr); | |
239 | if (now.cntr != start.cntr) { | |
240 | dc = now.cntr-start.cntr; | |
241 | dt = stable.t1-start.t1-delta_sum/delta_n; | |
242 | printf("%llu ~ ", (unsigned long long) dc); | |
243 | if (dt > 0) | |
244 | print_f(dc/dt, 3); | |
245 | printf("\n"); | |
246 | fflush(stdout); | |
247 | } | |
201 | 248 | start = now; |
202 | 249 | } |
203 | 250 | } |
... | ... | |
211 | 258 | struct sample start, now; |
212 | 259 | uint64_t dc; |
213 | 260 | double dt, f, error; |
214 | char *f_exp, *error_exp; | |
261 | char *error_exp; | |
215 | 262 | int i; |
216 | 263 | |
217 | 264 | arm_stop(); |
... | ... | |
239 | 286 | dc = now.cntr-start.cntr; |
240 | 287 | dt = (now.t0+now.t1)/2.0-(start.t0+start.t1)/2.0; |
241 | 288 | f = dc/dt; |
242 | if (f > 1000000.0) { | |
243 | f /= 1000000.0; | |
244 | f_exp = "M"; | |
245 | } else if (f > 1000.0) { | |
246 | f /= 1000.0; | |
247 | f_exp = "k"; | |
248 | } else { | |
249 | f_exp = ""; | |
250 | } | |
251 | 289 | if (dc) |
252 | 290 | error = 1.0/dc; /* one count */ |
253 | 291 | else |
... | ... | |
274 | 312 | } |
275 | 313 | } |
276 | 314 | |
277 | printf("\r%6.1f %1.9f %sHz %3.3f%s ", | |
278 | dt, f, f_exp, error, error_exp); | |
315 | printf("\r%6.1f ", dt); | |
316 | print_f(f, 9); | |
317 | printf(" %3.3f%s ", error, error_exp); | |
279 | 318 | fflush(stdout); |
280 | 319 | } |
281 | 320 | printf( |