From 6e6767175fb02f2f3e62f2e8c336c48a346c23d6 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 15 Jan 2013 14:08:38 -0300 Subject: [PATCH] ubb-patgen/ubb-patgen.c: clean up usage (-c selects clkout only; -C to monitor) ... and active_s is no longer used with a pattern. --- ubb-patgen/ubb-patgen.c | 64 ++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/ubb-patgen/ubb-patgen.c b/ubb-patgen/ubb-patgen.c index 361d214..618f545 100644 --- a/ubb-patgen/ubb-patgen.c +++ b/ubb-patgen/ubb-patgen.c @@ -275,13 +275,8 @@ static void mmc_buffer(const struct mmcclk *clk, * well-defined state. */ - MSC_STRPCL = 1 << 3; /* reset the MSC */ - - while (MSC_STAT & (1 << 15)); /* wait until reset finishes */ - dma_setup(buf, nibbles); - MSC_CLKRT = clk->clkrt; /* cleared by MSC reset */ MSC_STRPCL = 2; /* start the bus clock */ MSC_RESTO = 0xffff; /* maximum response time-out */ MSC_BLKLEN = 0xfff; /* never reach the end (with CRC) */ @@ -448,12 +443,15 @@ static void usage(const char *name) { fprintf(stderr, "usage: %s\n" -"usage: %s [-b freq_hz] [-f freq_hz] [-c] [-q] [pattern] active_s\n\n" +" %s [-b freq_hz] [-f freq_hz] -c [-q] [active_s]\n" +" %s [-b freq_hz] [-f freq_hz] [-C] [-q] pattern\n\n" " -b freq_hz set bus clock to the specified frequency (default: 1 MHz)\n" -" -c output bus clock on CLK\n" +" -c output bus clock on CLK without sending a pattern\n" +" -C temporarily output bus clock on CLK (for debugging)\n" " -f freq_hz set pattern rate (default: same as bus clock)\n" " -q quiet. Don't report clock differences.\n\n" " active_s keep running that many seconds after setting the clock\n" +" (default: exit immediately but leave the clock on)\n" " pattern send the specified pattern on DAT0 through DAT3\n\n" "Frequency: the frequency in Hz, optionally followed by \"M\" or \"k\",\n" " optionally followed by \"Hz\", optionally followed by \"+\" or \"-\".\n" @@ -461,7 +459,7 @@ static void usage(const char *name) " Without +/-, the closest available frequency is selected.\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" - , name, name); + , name, name, name); exit(1); } @@ -469,16 +467,17 @@ static void usage(const char *name) int main(int argc, char **argv) { struct mmcclk clk; - int bus_hz = 0, clkout = 0, bus_rel = 0; + int bus_hz = 0, clk_only = 0, clkout = 0, bus_rel = 0; int pattern_hz = 0, pattern_rel = 0; const char *pattern = NULL; int quiet = 0; - double active_s; + double active_s = 0; struct timespec active_ns; + int keep_clk = 1; char *end; int c; - while ((c = getopt(argc, argv, "b:cq")) != EOF) + while ((c = getopt(argc, argv, "b:cCq")) != EOF) switch (c) { case 'b': if (!frequency(optarg, &bus_hz, &bus_rel)) @@ -489,6 +488,9 @@ int main(int argc, char **argv) usage(*argv); break; case 'c': + clk_only = 1; + /* fall through */ + case 'C': clkout = 1; break; case 'q': @@ -500,20 +502,24 @@ int main(int argc, char **argv) switch (argc-optind) { case 0: - if (clkout || quiet) + if (clk_only) + break; + if (bus_hz || pattern_hz || clkout || quiet) usage(*argv); ubb_open(UBB_ALL); show_frequencies(); return 1; - case 2: - pattern = argv[optind]; - /* fall through */ case 1: - active_s = strtod(argv[argc-1], &end); - if (*end) - usage(*argv); - active_ns.tv_sec = (int) active_s; - active_ns.tv_nsec = (active_s-(int) active_s)*1e9; + if (clk_only) { + active_s = strtod(argv[argc-1], &end); + if (*end) + usage(*argv); + active_ns.tv_sec = (int) active_s; + active_ns.tv_nsec = (active_s-(int) active_s)*1e9; + keep_clk = 0; + } else { + pattern = argv[optind]; + } break; default: usage(*argv); @@ -550,12 +556,18 @@ int main(int argc, char **argv) dma_pattern(&clk, pattern, UBB_DAT0 | UBB_DAT1 | UBB_DAT2 | UBB_DAT3); - if (nanosleep(&active_ns, NULL)) - perror("nanosleep"); - - mmcclk_stop(); - - ubb_close(UBB_DAT0 | UBB_DAT1 | UBB_DAT2 | UBB_DAT3); + if (active_s) + if (nanosleep(&active_ns, NULL)) + perror("nanosleep"); + if (pattern) { + mmcclk_stop(); + ubb_close(UBB_DAT0 | UBB_DAT1 | UBB_DAT2 | UBB_DAT3); + } else if (keep_clk) { + ubb_close(UBB_CLK); + } else { + mmcclk_stop(); + ubb_close(0); + } return 0; }