From 9930ae6576b7f4d8c01fbf8dad259ef081f4aa1c Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 15 Jan 2013 23:48:57 -0300 Subject: [PATCH] ubb-patgen/ubb-patgen.c: move frequency difference warning into select_freq This way, all frequency selections print a warning when there's a difference. --- ubb-patgen/README | 16 ++++++++-------- ubb-patgen/ubb-patgen.c | 32 ++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/ubb-patgen/README b/ubb-patgen/README index 37faba9..00e7ac3 100644 --- a/ubb-patgen/README +++ b/ubb-patgen/README @@ -55,6 +55,14 @@ frequencies that don't exceed the specified value. Examples: Note that this form of invocation only searches the frequency table but does not produce any output on UBB. +ubb-patgen warns if the selected frequency does not match the +requested frequency, e.g., + +# ubb-patgen -f 100kHz +bus clk = 100.962 kHz (+0.96%) + +This warning can be suppressed with the option -q. + Clock output ------------ @@ -73,14 +81,6 @@ To stop the MMC bus clock, run # ubb-patgen -c 0 -ubb-patgen warns if the selected frequency does not match the -requested frequency, e.g., - -# ubb-patgen -f 100kHz -c -bus clk = 100.962 kHz (+0.96%) - -This warning can be suppressed with the option -q. - Pattern output -------------- diff --git a/ubb-patgen/ubb-patgen.c b/ubb-patgen/ubb-patgen.c index 0febacf..d445430 100644 --- a/ubb-patgen/ubb-patgen.c +++ b/ubb-patgen/ubb-patgen.c @@ -112,11 +112,12 @@ static void show_frequencies(int quiet) } -static int select_freq(struct mmcclk *res, int hz, int rel) +static int select_freq(struct mmcclk *res, int hz, int rel, int quiet) { const struct mmcclk *clks, *p, *best = NULL; double d, best_d = 0; int n; + double err; clks = frequencies(&n); for (p = clks; p != clks+n; p++) { @@ -134,6 +135,20 @@ static int select_freq(struct mmcclk *res, int hz, int rel) return 0; *res = *best; free((void *) clks); + + if (quiet) + return 1; + + if (res->bus_clk_hz != hz) { + fprintf(stderr, "bus clk = "); + print_freq(stderr, res->bus_clk_hz); + err = (res->bus_clk_hz-hz)/hz; + if (err <= -0.0001 || err >= 0.0001) + fprintf(stderr, " (%+.2g%%)\n", err*100); + else + fprintf(stderr, " (%+d ppm)\n", (int) (err*1000000)); + } + return 1; } @@ -588,7 +603,7 @@ int main(int argc, char **argv) ubb_open(UBB_ALL); if (bus_hz) { - if (!select_freq(&clk, bus_hz, bus_rel)) { + if (!select_freq(&clk, bus_hz, bus_rel, quiet)) { fprintf(stderr, "no suitable frequency found\n"); exit(1); @@ -626,21 +641,10 @@ int main(int argc, char **argv) if (!bus_hz) bus_hz = 1000000; - if (!select_freq(&clk, bus_hz, bus_rel)) { + if (!select_freq(&clk, bus_hz, bus_rel, quiet)) { fprintf(stderr, "no suitable frequency found\n"); exit(1); } - if (clk.bus_clk_hz != bus_hz && !quiet) { - double err; - - fprintf(stderr, "bus clk = "); - print_freq(stderr, clk.bus_clk_hz); - err = (clk.bus_clk_hz-bus_hz)/bus_hz; - if (err <= -0.0001 || err >= 0.0001) - fprintf(stderr, " (%+.2g%%)\n", err*100); - else - fprintf(stderr, " (%+d ppm)\n", (int) (err*1000000)); - } if (clkout || clk_only) PDFUNS = UBB_CLK;