1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-04 22:53:08 +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 <stdio.h>
#include <unistd.h>
#include <string.h>
#include <strings.h> /* for strcasecmp, strncasecmp */
#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)
{
fprintf(stderr,
"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);
}
int main(int argc, char **argv)
{
int c;
int c, i;
while ((c = getopt(argc, argv, "")) != EOF)
switch (c) {
@ -76,14 +135,16 @@ int main(int argc, char **argv)
usage(*argv);
}
switch (argc-optind) {
case 0:
break;
default:
usage(*argv);
}
for (i = optind; i != argc; i++)
if (!setup_pin(argv[i], 0))
usage(*argv);
ubb_open(UBB_ALL);
show_pins();
if (argc == optind) {
show_pins();
} else {
for (i = optind; i != argc; i++)
setup_pin(argv[i], 1);
}
return 0;
}