1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-19 06:56:16 +02:00

ubb-patgen/ubb-patgen.c: "ubb-patgen -f FREQ" calculates the frequency

This can then be used by generators to generate an oversampled pattern.
This commit is contained in:
Werner Almesberger 2013-01-15 14:42:00 -03:00
parent 1111156a97
commit eedb0f0106

View File

@ -443,8 +443,9 @@ static void usage(const char *name)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s\n" "usage: %s\n"
" %s [-f freq_hz] -c [-q] [active_s]\n" " %s -f freq_hz\n"
" %s [-f freq_hz] [-C] [-q] pattern\n\n" " %s [-f freq_hz] [-q] -c [active_s]\n"
" %s [-f freq_hz] [-q] [-C] pattern\n\n"
" -c output bus clock on CLK without sending a pattern\n" " -c output bus clock on CLK without sending a pattern\n"
" -C temporarily output bus clock on CLK (for debugging)\n" " -C temporarily output bus clock on CLK (for debugging)\n"
" -f freq_hz set bus clock to the specified frequency (default: 1 MHz)\n" " -f freq_hz set bus clock to the specified frequency (default: 1 MHz)\n"
@ -458,7 +459,7 @@ static void usage(const char *name)
" Without +/-, the closest available frequency is selected.\n" " Without +/-, the closest available frequency is selected.\n"
"Pattern: hex digits corresponding to 1 for DAT0, 2 for DAT1, etc.\n" "Pattern: hex digits corresponding to 1 for DAT0, 2 for DAT1, etc.\n"
" {n} repeats the preceding digit n times, e.g., 1{3} is equivalent to 111.\n" " {n} repeats the preceding digit n times, e.g., 1{3} is equivalent to 111.\n"
, name, name, name); , name, name, name, name);
exit(1); exit(1);
} }
@ -483,7 +484,7 @@ int main(int argc, char **argv)
break; break;
case 'c': case 'c':
clk_only = 1; clk_only = 1;
/* fall through */ break;
case 'C': case 'C':
clkout = 1; clkout = 1;
break; break;
@ -494,15 +495,28 @@ int main(int argc, char **argv)
usage(*argv); usage(*argv);
} }
if (clkout && clk_only)
usage(*argv);
switch (argc-optind) { switch (argc-optind) {
case 0: case 0:
if (clk_only) if (clk_only)
break; break;
if (bus_hz || clkout || quiet) if (clkout || quiet)
usage(*argv); usage(*argv);
ubb_open(UBB_ALL); ubb_open(UBB_ALL);
if (bus_hz) {
if (!select_freq(&clk, bus_hz, bus_rel)) {
fprintf(stderr,
"no suitable frequency found\n");
exit(1);
}
printf("%f\n", clk.bus_clk_hz);
} else {
show_frequencies(); show_frequencies();
return 1; }
return 0;
case 1: case 1:
if (clk_only) { if (clk_only) {
active_s = strtod(argv[argc-1], &end); active_s = strtod(argv[argc-1], &end);
@ -542,7 +556,7 @@ int main(int argc, char **argv)
fprintf(stderr, " (%+d ppm)\n", (int) (err*1000000)); fprintf(stderr, " (%+d ppm)\n", (int) (err*1000000));
} }
if (clkout) if (clkout || clk_only)
PDFUNS = UBB_CLK; PDFUNS = UBB_CLK;
mmcclk_start(&clk); mmcclk_start(&clk);