2013-01-06 13:57:12 +02:00
|
|
|
/*
|
|
|
|
* ubbctl.c - Set and query UBB signals
|
|
|
|
*
|
|
|
|
* Written 2013 by Werner Almesberger
|
|
|
|
* Copyright 2013 Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2013-01-04 10:40:19 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2013-01-06 14:54:54 +02:00
|
|
|
#include <stdlib.h>
|
2013-01-04 10:40:19 +02:00
|
|
|
#include <stdio.h>
|
2013-01-06 14:54:54 +02:00
|
|
|
#include <unistd.h>
|
2013-01-04 10:40:19 +02:00
|
|
|
|
|
|
|
#include <ubb/ubb.h>
|
|
|
|
|
|
|
|
|
|
|
|
static struct pin {
|
|
|
|
const char *name;
|
|
|
|
uint32_t mask;
|
|
|
|
} pins[] = {
|
|
|
|
{ "nPWR", UBB_nPWR },
|
|
|
|
{ "DAT2", UBB_DAT2 },
|
|
|
|
{ "DAT3", UBB_DAT3 },
|
|
|
|
{ "CMD", UBB_CMD },
|
|
|
|
{ "CLK", UBB_CLK },
|
|
|
|
{ "DAT0", UBB_DAT0 },
|
|
|
|
{ "DAT1", UBB_DAT1 },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-06 14:07:16 +02:00
|
|
|
static void show_pins(void)
|
2013-01-04 10:40:19 +02:00
|
|
|
{
|
|
|
|
const struct pin *p;
|
|
|
|
|
|
|
|
for (p = pins; p->name; p++) {
|
|
|
|
printf("%s%s=", p == pins ? "" : " ", p->name);
|
|
|
|
if (PDFUN & p->mask)
|
|
|
|
printf("FN");
|
|
|
|
else if (PDDIR & p->mask)
|
|
|
|
printf("%d", !!(PDDAT & p->mask));
|
|
|
|
else
|
|
|
|
putchar(PDPULL & p->mask ? 'Z' : 'R');
|
|
|
|
}
|
|
|
|
printf("\n");
|
2013-01-06 14:07:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-06 14:54:54 +02:00
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"usage: %s\n"
|
|
|
|
, name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-01-06 14:07:16 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2013-01-06 14:54:54 +02:00
|
|
|
int c;
|
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, "")) != EOF)
|
|
|
|
switch (c) {
|
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (argc-optind) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
|
|
|
|
2013-01-06 14:07:16 +02:00
|
|
|
ubb_open(UBB_ALL);
|
|
|
|
show_pins();
|
2013-01-04 10:40:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|