mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-23 21:14:04 +02:00
ubb-patgen/ubb-patgen.c: new option -F freq_Hz to select "unsafe" frequencies
This commit is contained in:
parent
f862a82a2d
commit
04b235cedf
@ -63,6 +63,10 @@ bus clk = 100.962 kHz (+0.96%)
|
||||
|
||||
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
|
||||
option -i:
|
||||
|
||||
|
@ -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 *clks = malloc(sizeof(struct mmcclk));
|
||||
@ -57,7 +57,8 @@ static struct mmcclk *frequencies(int *n)
|
||||
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;
|
||||
while (mmcclk_next(&mmc)) {
|
||||
clks = realloc(clks, sizeof(struct mmcclk)*(n_clks+1));
|
||||
@ -96,7 +97,7 @@ static void show_frequencies(int quiet)
|
||||
int n, i;
|
||||
double last = 0;
|
||||
|
||||
clks = frequencies(&n);
|
||||
clks = frequencies(&n, 0);
|
||||
for (i = 0; i != n; i++) {
|
||||
if (quiet) {
|
||||
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;
|
||||
double d, best_d = 0;
|
||||
int n;
|
||||
double err;
|
||||
|
||||
clks = frequencies(&n);
|
||||
clks = frequencies(&n, all);
|
||||
for (p = clks; p != clks+n; p++) {
|
||||
if (rel > 0 && p->bus_clk_hz < hz)
|
||||
continue;
|
||||
@ -690,14 +691,16 @@ static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s\n"
|
||||
" %s [-q] -f freq_hz|-i interval_s\n"
|
||||
" %s [-q] [-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"
|
||||
" [-w wait_s] [-m mask] [-p] file|pattern\n\n"
|
||||
" %s [-q] (-f|-F) freq_hz|-i interval_s\n"
|
||||
" %s [-q] [(-f|-F) freq_hz|-i interval_s] -c [active_s]\n"
|
||||
" %s [-q] [(-f|-F) freq_hz|-i interval_s]\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 temporarily output bus clock on CLK (for debugging)\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 like -f, but also allow \"overclocking\"\n"
|
||||
" -i inter_s set bus clock such that one cycle equals the specified "
|
||||
"interval\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)
|
||||
{
|
||||
struct mmcclk clk;
|
||||
int all = 0;
|
||||
int bus_hz = 0, clk_only = 0, clkout = 0, bus_rel = 0;
|
||||
const char *pattern = NULL;
|
||||
int quiet = 0, force_pattern = 0;
|
||||
@ -745,7 +749,7 @@ int main(int argc, char **argv)
|
||||
unsigned long tmp;
|
||||
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) {
|
||||
case 'c':
|
||||
clk_only = 1;
|
||||
@ -761,6 +765,9 @@ int main(int argc, char **argv)
|
||||
usage(*argv);
|
||||
debounce = 1;
|
||||
break;
|
||||
case 'F':
|
||||
all = 1;
|
||||
/* fall through */
|
||||
case 'f':
|
||||
if (!frequency(optarg, &bus_hz, &bus_rel))
|
||||
usage(*argv);
|
||||
@ -818,7 +825,7 @@ int main(int argc, char **argv)
|
||||
|
||||
ubb_open(UBB_ALL);
|
||||
if (bus_hz) {
|
||||
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");
|
||||
exit(1);
|
||||
@ -856,7 +863,7 @@ int main(int argc, char **argv)
|
||||
if (!bus_hz)
|
||||
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");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user