1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-23 23:35:00 +02:00

ubb-patgen/ubb-patgen.c: new option -F freq_Hz to select "unsafe" frequencies

This commit is contained in:
Werner Almesberger 2013-01-28 21:14:53 -03:00
parent f862a82a2d
commit 04b235cedf
2 changed files with 23 additions and 12 deletions

View File

@ -63,6 +63,10 @@ bus clk = 100.962 kHz (+0.96%)
This warning can be suppressed with the option -q. This warning can be suppressed with the option -q.
The option -F works like -f but also allows frequencies that may
exceed the hardware's capabilities. As a consequence, the MMC
controller may hang.
The frequency can also be specified as the cycle time with the The frequency can also be specified as the cycle time with the
option -i: option -i:

View File

@ -46,7 +46,7 @@ static int cmp(const void *a, const void *b)
} }
static struct mmcclk *frequencies(int *n) static struct mmcclk *frequencies(int *n, int all)
{ {
struct mmcclk mmc; struct mmcclk mmc;
struct mmcclk *clks = malloc(sizeof(struct mmcclk)); struct mmcclk *clks = malloc(sizeof(struct mmcclk));
@ -57,7 +57,8 @@ static struct mmcclk *frequencies(int *n)
exit(1); exit(1);
} }
mmcclk_first(&mmc, 0, MMCCLK_FLAG_WR_ONLY); mmcclk_first(&mmc, 0,
MMCCLK_FLAG_WR_ONLY | (all ? MMCCLK_FLAG_ALL : 0));
clks[0] = mmc; clks[0] = mmc;
while (mmcclk_next(&mmc)) { while (mmcclk_next(&mmc)) {
clks = realloc(clks, sizeof(struct mmcclk)*(n_clks+1)); clks = realloc(clks, sizeof(struct mmcclk)*(n_clks+1));
@ -96,7 +97,7 @@ static void show_frequencies(int quiet)
int n, i; int n, i;
double last = 0; double last = 0;
clks = frequencies(&n); clks = frequencies(&n, 0);
for (i = 0; i != n; i++) { for (i = 0; i != n; i++) {
if (quiet) { if (quiet) {
if (clks[i].bus_clk_hz != last) if (clks[i].bus_clk_hz != last)
@ -113,14 +114,14 @@ static void show_frequencies(int quiet)
} }
static int select_freq(struct mmcclk *res, int hz, int rel, int quiet) static int select_freq(struct mmcclk *res, int hz, int rel, int quiet, int all)
{ {
const struct mmcclk *clks, *p, *best = NULL; const struct mmcclk *clks, *p, *best = NULL;
double d, best_d = 0; double d, best_d = 0;
int n; int n;
double err; double err;
clks = frequencies(&n); clks = frequencies(&n, all);
for (p = clks; p != clks+n; p++) { for (p = clks; p != clks+n; p++) {
if (rel > 0 && p->bus_clk_hz < hz) if (rel > 0 && p->bus_clk_hz < hz)
continue; continue;
@ -690,14 +691,16 @@ static void usage(const char *name)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s\n" "usage: %s\n"
" %s [-q] -f freq_hz|-i interval_s\n" " %s [-q] (-f|-F) freq_hz|-i interval_s\n"
" %s [-q] [-f freq_hz|-i interval_s] -c [active_s]\n" " %s [-q] [(-f|-F) freq_hz|-i interval_s] -c [active_s]\n"
" %s [-q] [-f freq_hz|-i interval_s] [-C|-t 0|1... [-d debounce_s]]\n" " %s [-q] [(-f|-F) freq_hz|-i interval_s]\n"
" [-w wait_s] [-m mask] [-p] file|pattern\n\n" " [-C|-t 0|1... [-d debounce_s]] [-w wait_s] [-m mask] [-p]\n"
" file|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"
" -d deb_s trigger debounce time (default: no debouncing)\n" " -d deb_s trigger debounce time (default: no debouncing)\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"
" -F freq_hz like -f, but also allow \"overclocking\"\n"
" -i inter_s set bus clock such that one cycle equals the specified " " -i inter_s set bus clock such that one cycle equals the specified "
"interval\n" "interval\n"
" -m mask use only the DATx lines specified in the mask (default: 0xf)\n" " -m mask use only the DATx lines specified in the mask (default: 0xf)\n"
@ -728,6 +731,7 @@ static void usage(const char *name)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct mmcclk clk; struct mmcclk clk;
int all = 0;
int bus_hz = 0, clk_only = 0, clkout = 0, bus_rel = 0; int bus_hz = 0, clk_only = 0, clkout = 0, bus_rel = 0;
const char *pattern = NULL; const char *pattern = NULL;
int quiet = 0, force_pattern = 0; int quiet = 0, force_pattern = 0;
@ -745,7 +749,7 @@ int main(int argc, char **argv)
unsigned long tmp; unsigned long tmp;
const char *p; const char *p;
while ((c = getopt(argc, argv, "cCd:f:i:m:pqt:w:")) != EOF) while ((c = getopt(argc, argv, "cCd:f:F:i:m:pqt:w:")) != EOF)
switch (c) { switch (c) {
case 'c': case 'c':
clk_only = 1; clk_only = 1;
@ -761,6 +765,9 @@ int main(int argc, char **argv)
usage(*argv); usage(*argv);
debounce = 1; debounce = 1;
break; break;
case 'F':
all = 1;
/* fall through */
case 'f': case 'f':
if (!frequency(optarg, &bus_hz, &bus_rel)) if (!frequency(optarg, &bus_hz, &bus_rel))
usage(*argv); usage(*argv);
@ -818,7 +825,7 @@ int main(int argc, char **argv)
ubb_open(UBB_ALL); ubb_open(UBB_ALL);
if (bus_hz) { if (bus_hz) {
if (!select_freq(&clk, bus_hz, bus_rel, quiet)) { if (!select_freq(&clk, bus_hz, bus_rel, quiet, all)) {
fprintf(stderr, fprintf(stderr,
"no suitable frequency found\n"); "no suitable frequency found\n");
exit(1); exit(1);
@ -856,7 +863,7 @@ int main(int argc, char **argv)
if (!bus_hz) if (!bus_hz)
bus_hz = 1000000; bus_hz = 1000000;
if (!select_freq(&clk, bus_hz, bus_rel, quiet)) { if (!select_freq(&clk, bus_hz, bus_rel, quiet, all)) {
fprintf(stderr, "no suitable frequency found\n"); fprintf(stderr, "no suitable frequency found\n");
exit(1); exit(1);
} }