1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-12-03 21:12:48 +02:00

ubbctl/ubbctl.c: add setting of UBB signals (DAT0=1, etc.)

This commit is contained in:
Werner Almesberger 2013-01-06 11:30:48 -03:00
parent 5297de4d83
commit 246a8a0a5f

View File

@ -15,6 +15,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <strings.h> /* for strcasecmp, strncasecmp */
#include <ubb/ubb.h> #include <ubb/ubb.h>
@ -58,17 +60,74 @@ static void show_pins(void)
} }
/*
* The order of the IO operations below is important to avoid glitches.
*/
static int setup_pin(const char *s, int doit)
{
const struct pin *p;
const char *eq;
eq = strchr(s, '=');
if (!eq)
return 0;
for (p = pins; p->name; p++)
if (strlen(p->name) == eq-s && !strncasecmp(p->name, s, eq-s))
break;
if (!p->name)
return 0;
if (!strcasecmp(eq+1, "f")) {
if (doit)
PDFUNS = p->mask;
} else if (!strcmp(eq+1, "0")) {
if (doit) {
PDDATC = p->mask;
PDDIRS = p->mask;
PDFUNC = p->mask;
}
} else if (!strcmp(eq+1, "1")) {
if (doit) {
PDDATS = p->mask;
PDDIRS = p->mask;
PDFUNC = p->mask;
}
} else if (!strcasecmp(eq+1, "r")) {
if (doit) {
PDPULLC = p->mask;
PDDIRC = p->mask;
PDFUNC = p->mask;
}
} else if (!strcasecmp(eq+1, "z")) {
if (doit) {
PDPULLS = p->mask;
PDDIRC = p->mask;
PDFUNC = p->mask;
}
} else {
return 0;
}
return 1;
}
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s\n" "usage: %s\n"
, name); " %s name=value ...\n\n"
"Names: nPWR, CMD, CLK, DAT0, DAT1, DAT2, DAT3\n"
"Values: F, 0, 1, Z, R\n"
, name, name);
exit(1); exit(1);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int c; int c, i;
while ((c = getopt(argc, argv, "")) != EOF) while ((c = getopt(argc, argv, "")) != EOF)
switch (c) { switch (c) {
@ -76,14 +135,16 @@ int main(int argc, char **argv)
usage(*argv); usage(*argv);
} }
switch (argc-optind) { for (i = optind; i != argc; i++)
case 0: if (!setup_pin(argv[i], 0))
break;
default:
usage(*argv); usage(*argv);
}
ubb_open(UBB_ALL); ubb_open(UBB_ALL);
if (argc == optind) {
show_pins(); show_pins();
} else {
for (i = optind; i != argc; i++)
setup_pin(argv[i], 1);
}
return 0; return 0;
} }