Commit 84750ca9 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: add fmc-fdelay-term

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 6c67531f
...@@ -944,6 +944,22 @@ boards in the current system: ...@@ -944,6 +944,22 @@ boards in the current system:
dev_id 0200, /dev/zio/zio-fd-0200, /sys/bus/zio/devices/zio-fd-0200 dev_id 0200, /dev/zio/zio-fd-0200, /sys/bus/zio/devices/zio-fd-0200
@end smallexample @end smallexample
@c ==========================================================================
@node fmc-fdelay-term
@section fmc-fdelay-term
The command can be used to activate or deactivate the 50 ohm
termination resistor. In addition to the @t{-i} or @t{-d}
arguments, mandatory if more than one board is found on the
host system, the command receives one mandatory argument, either
@t{1} (activate termination) or @t{0} (deactivate termination).
@smallexample
spusa# ./tools/fmc-fdelay-term 1
./tools/fmc-fdelay-term: termination is on
@end smallexample
@c ########################################################################## @c ##########################################################################
@node Troubleshooting @node Troubleshooting
@appendix Troubleshooting @appendix Troubleshooting
......
*.a *.a
.depend .depend
fdelay-board-time fdelay-board-time
fdelay-term
fdelay-read fdelay-read
fdelay-fread fdelay-fread
fdelay-pulse fdelay-pulse
......
...@@ -11,7 +11,6 @@ LDFLAGS = -L. -lfdelay ...@@ -11,7 +11,6 @@ LDFLAGS = -L. -lfdelay
DEMOSRC := DEMOSRC :=
DEMOSRC += fdelay-board-time.c DEMOSRC += fdelay-board-time.c
DEMOSRC += fdelay-term.c
DEMOSRC += fdelay-read.c DEMOSRC += fdelay-read.c
DEMOSRC += fdelay-fread.c DEMOSRC += fdelay-fread.c
DEMOSRC += fdelay-pulse.c DEMOSRC += fdelay-pulse.c
......
fmc-fdelay-list fmc-fdelay-list
fmc-fdelay-term
...@@ -7,6 +7,7 @@ HOST_EXTRACFLAGS += -I$(M) -I../lib -I../zio/include -Wno-trigraphs -Wall -ggdb ...@@ -7,6 +7,7 @@ HOST_EXTRACFLAGS += -I$(M) -I../lib -I../zio/include -Wno-trigraphs -Wall -ggdb
HOSTCC ?= gcc HOSTCC ?= gcc
hostprogs-y := fmc-fdelay-list hostprogs-y := fmc-fdelay-list
hostprogs-y += fmc-fdelay-term
# we are not in the kernel, so we need to piggy-back on "make modules" # we are not in the kernel, so we need to piggy-back on "make modules"
all modules: $(hostprogs-y) all modules: $(hostprogs-y)
......
...@@ -2,57 +2,67 @@ ...@@ -2,57 +2,67 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <getopt.h>
#include <errno.h> #include <errno.h>
#include "fdelay-lib.h" #include "fdelay-lib.h"
#include "tools-common.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct fdelay_board *b; struct fdelay_board *b;
int i, hwval, newval; int nboards, hwval, newval;
int dev = 0; int index = -1, dev = -1;
if (argc < 2) {
fprintf(stderr, "%s: Use %s <dev> 1|0\n", argv[0], argv[0]);
exit(1);
}
newval = -1;
if (argc > 2) {
dev = strtol(argv[1], NULL, 0);
if (!strcmp(argv[2], "0"))
newval = 0;
else if (!strcmp(argv[2], "1"))
newval = 1;
else {
fprintf(stderr, "%s: arg \"%s\" is not 0 nor 1\n",
argv[0], argv[2]);
exit(1);
}
}
i = fdelay_init(); /* Standard part of the file (repeated code) */
if (i < 0) { nboards = fdelay_init();
if (nboards < 0) {
fprintf(stderr, "%s: fdelay_init(): %s\n", argv[0], fprintf(stderr, "%s: fdelay_init(): %s\n", argv[0],
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
if (i == 0) { if (nboards == 0) {
fprintf(stderr, "%s: no boards found\n", argv[0]); fprintf(stderr, "%s: no boards found\n", argv[0]);
exit(1); exit(1);
} }
if (i != 1) { if (nboards == 1)
fprintf(stderr, "%s: found %i boards\n", index = 0; /* so it works with no arguments */
argv[0], i);
tools_getopt_d_i(argc, argv, &dev, &index);
if (index < 0 && dev < 0) {
fprintf(stderr, "%s: several boards, please pass -i or -d\n",
argv[0]);
exit(1);
}
/* Parse the mandatory extra argument */
if (optind != argc - 1) {
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] 1|0\n",
argv[0], argv[0]);
exit(1);
}
newval = -1;
if (!strcmp(argv[optind], "0"))
newval = 0;
else if (!strcmp(argv[optind], "1"))
newval = 1;
else {
fprintf(stderr, "%s: arg \"%s\" is not 0 nor 1\n",
argv[0], argv[optind]);
exit(1);
} }
b = fdelay_open(dev, -1); /* Finally work */
b = fdelay_open(index, dev);
if (!b) { if (!b) {
fprintf(stderr, "%s: fdelay_open(): %s\n", argv[0], fprintf(stderr, "%s: fdelay_open(): %s\n", argv[0],
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
fprintf(stderr, "%s: using board %d\n", argv[0], dev);
hwval = fdelay_get_config_tdc(b); hwval = fdelay_get_config_tdc(b);
switch(newval) { switch(newval) {
case 1: case 1:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment