mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-04 23:23:43 +02:00
tools/atrf-xtal/: new option -b for relative result; -p for pass/fail
- atrf-xtal.c (eval): return the value instead of printing it - atrf-xtal.c (usage, main): new option -b for reporting the deviation from a base count - atrf-xtal.c (eval): new option -p to report an error for deviations outside the specified bound
This commit is contained in:
parent
558017e34d
commit
ff6c8340c8
@ -37,6 +37,7 @@ MAIN = atrf-xtal
|
|||||||
|
|
||||||
include ../Makefile.common
|
include ../Makefile.common
|
||||||
|
|
||||||
|
LDLIBS += -lm
|
||||||
CFLAGS += -O9
|
CFLAGS += -O9
|
||||||
|
|
||||||
OBJS_$(TARGET) = atben.o
|
OBJS_$(TARGET) = atben.o
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "atrf.h"
|
#include "atrf.h"
|
||||||
|
|
||||||
@ -61,35 +63,37 @@ static int cmp(const void *a, const void *b)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void eval(unsigned *res, int rep)
|
static double eval(unsigned *res, int rep)
|
||||||
{
|
{
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
qsort(res, rep, sizeof(*res), cmp);
|
qsort(res, rep, sizeof(*res), cmp);
|
||||||
if (rep < 8) {
|
if (rep < 8)
|
||||||
printf("%u\n", res[rep >> 1]);
|
return res[rep >> 1];
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (i = rep/8; i != rep-rep/8; i++) {
|
for (i = rep/8; i != rep-rep/8; i++) {
|
||||||
sum += res[i];
|
sum += res[i];
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
printf("%f\n", (double) sum/n);
|
return (double) sum/n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void usage(const char *name)
|
static void usage(const char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s [-d driver[:arg]] [-r] [-s size] [-t trim] [repetitions]\n\n"
|
"usage: %s [-b count [-p ppm]] [-d driver[:arg]] [-r] [-s size] [-t trim]\n"
|
||||||
|
" %*s [repetitions]\n\n"
|
||||||
|
" -b count base count for relative result\n"
|
||||||
" -d driver[:arg] use the specified driver (default: %s)\n"
|
" -d driver[:arg] use the specified driver (default: %s)\n"
|
||||||
|
" -p ppm maximum deviation from base count\n"
|
||||||
" -r instead of printing a mean value, dump the raw samples\n"
|
" -r instead of printing a mean value, dump the raw samples\n"
|
||||||
" -s size payload size in bytes, 0-127 (default: %d bytes)\n"
|
" -s size payload size in bytes, 0-127 (default: %d bytes)\n"
|
||||||
" -t trim trim capacitor setting, 0-15 (default: %d)\n"
|
" -t trim trim capacitor setting, 0-15 (default: %d)\n"
|
||||||
" repetitions number of measurements (default: 1)\n"
|
" repetitions number of measurements (default: 1)\n"
|
||||||
, name, atrf_default_driver_name(), DEFAULT_SIZE, DEFAULT_TRIM);
|
, name, strlen(name), "",
|
||||||
|
atrf_default_driver_name(), DEFAULT_SIZE, DEFAULT_TRIM);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,17 +104,29 @@ int main(int argc, char *const *argv)
|
|||||||
struct atrf_dsc *dsc;
|
struct atrf_dsc *dsc;
|
||||||
int size = DEFAULT_SIZE;
|
int size = DEFAULT_SIZE;
|
||||||
int trim = DEFAULT_TRIM;
|
int trim = DEFAULT_TRIM;
|
||||||
|
double base = 0, ppm = 0;
|
||||||
|
double avg, rel;
|
||||||
int rep = 1;
|
int rep = 1;
|
||||||
int dump_raw = 0;
|
int dump_raw = 0;
|
||||||
char *end;
|
char *end;
|
||||||
unsigned *res;
|
unsigned *res;
|
||||||
int c, i;
|
int c, i;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "d:rs:t:")) != EOF)
|
while ((c = getopt(argc, argv, "b:d:p:rs:t:")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 'b':
|
||||||
|
base = strtof(optarg, &end);
|
||||||
|
if (*end)
|
||||||
|
usage(*argv);
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
driver = optarg;
|
driver = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
ppm = strtof(optarg, &end);
|
||||||
|
if (*end)
|
||||||
|
usage(*argv);
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
dump_raw = 1;
|
dump_raw = 1;
|
||||||
break;
|
break;
|
||||||
@ -132,6 +148,9 @@ int main(int argc, char *const *argv)
|
|||||||
usage(*argv);
|
usage(*argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ppm && !base)
|
||||||
|
usage(*argv);
|
||||||
|
|
||||||
switch (argc-optind) {
|
switch (argc-optind) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
@ -169,7 +188,18 @@ int main(int argc, char *const *argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
eval(res, rep);
|
avg = eval(res, rep);
|
||||||
|
if (!base)
|
||||||
|
printf("%f\n", avg);
|
||||||
|
else {
|
||||||
|
rel = (avg/base-1)*1000000;
|
||||||
|
printf("%+f ppm", rel);
|
||||||
|
if (ppm && fabs(rel) > ppm) {
|
||||||
|
printf(" (outside bounds)\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user