Commit 46d05c91 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: add fmc-fdelay-board-time

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 6b40ded5
......@@ -952,7 +952,9 @@ boards in the current system:
@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}
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).
......@@ -962,6 +964,49 @@ host system, the command receives one mandatory argument, either
./tools/fmc-fdelay-term: termination is on
@end smallexample
@c ==========================================================================
@node fmc-fdelay-board-time
@section fmc-fdelay-board-time
The command is used to act on the time notion of the @sc{fine-delay} card.
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, that is
either a command or a floating point number. The number is the
time, in seconds, to be set in the card; the command is one of
the following ones:
@table @code
@item get
Read board time and print to @i{stdout}.
@item host
Set board time from host time
@item wr
Lock the boards to White Rabbit time. It may block if no White
Rabbit is there. No timeout is currently available.
@item local
Detach the board from White Rabbit, and run local time instead.
@end table
Examples:
@smallexample
spusa# ./lib/fdelay-board-time 25.5; ./lib/fdelay-board-time get
25.504007360
spusa# ./lib/fdelay-board-time get
34.111048968
spusa# ./lib/fdelay-board-time host
spusa# ./lib/fdelay-board-time get
1335974946.493415600
@end smallexample
@c ##########################################################################
@node Troubleshooting
......
*.a
.depend
fdelay-board-time
fdelay-read
fdelay-fread
fdelay-pulse
......
......@@ -10,7 +10,6 @@ CFLAGS = -Wall -ggdb -O2 -I../kernel -I../zio/include
LDFLAGS = -L. -lfdelay
DEMOSRC :=
DEMOSRC += fdelay-board-time.c
DEMOSRC += fdelay-read.c
DEMOSRC += fdelay-fread.c
DEMOSRC += fdelay-pulse.c
......
......@@ -5,4 +5,5 @@ fd-raw-settime
fd-raw-output
fd-raw-perf
fdelay-list
fdelay-term
\ No newline at end of file
fdelay-term
fdelay-board-time
......@@ -16,6 +16,7 @@ hostprogs-y += fd-raw-perf
# programs that used to live in lib/
hostprogs-y += fdelay-list
hostprogs-y += fdelay-term
hostprogs-y += fdelay-board-time
# we are not in the kernel, so we need to piggy-back on "make modules"
......
fmc-fdelay-list
fmc-fdelay-term
fmc-fdelay-board-time
......@@ -8,6 +8,7 @@ HOSTCC ?= gcc
hostprogs-y := fmc-fdelay-list
hostprogs-y += fmc-fdelay-term
hostprogs-y += fmc-fdelay-board-time
# we are not in the kernel, so we need to piggy-back on "make modules"
all modules: $(hostprogs-y)
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "fdelay-lib.h"
#include "tools-common.h"
int main(int argc, char **argv)
{
struct fdelay_board *b;
struct fdelay_time t;
int nboards, i, get = 0, host = 0, wr_on = 0, wr_off = 0;
int index = -1, dev = -1;
char *s;
/* Standard part of the file (repeated code) */
nboards = fdelay_init();
if (nboards < 0) {
fprintf(stderr, "%s: fdelay_init(): %s\n", argv[0],
strerror(errno));
exit(1);
}
if (nboards == 0) {
fprintf(stderr, "%s: no boards found\n", argv[0]);
exit(1);
}
if (nboards == 1)
index = 0; /* so it works with no arguments */
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>] <cmd>\"\n",
argv[0], argv[0]);
fprintf(stderr, " cmd is one of \"get\", \"host\", "
"\"local\", \"wr\" or a floating point time in secs\n");
exit(1);
}
s = argv[optind];
/* Crappy parser */
if (!strcmp(s, "get"))
get = 1;
else if (!strcmp(s, "host"))
host = 1;
else if (!strcmp(s, "wr"))
wr_on = 1;
else if (!strcmp(s, "local"))
wr_off = 1;
else {
double nano;
long long sec;
memset(&t, 0, sizeof(t));
i = sscanf(s, "%lli%lf\n", &sec, &nano);
if (i < 1) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], s);
exit(1);
}
t.utc = sec;
t.coarse = nano * 1000 * 1000 * 1000 / 8;
}
b = fdelay_open(index, dev);
if (!b) {
fprintf(stderr, "%s: fdelay_open(): %s\n", argv[0],
strerror(errno));
exit(1);
}
if (get) {
if (fdelay_get_time(b, &t) < 0) {
fprintf(stderr, "%s: fdelay_get_time(): %s\n", argv[0],
strerror(errno));
exit(1);
}
printf("%lli.%09li\n", (long long)t.utc, (long)t.coarse * 8);
fdelay_close(b);
fdelay_exit();
return 0;
}
if (host) {
if (fdelay_set_host_time(b) < 0) {
fprintf(stderr, "%s: fdelay_set_host_time(): %s\n",
argv[0], strerror(errno));
exit(1);
}
fdelay_close(b);
fdelay_exit();
return 0;
}
if (wr_on) {
setbuf(stdout, NULL);
printf("Locking the card to WR: ");
if (fdelay_wr_mode(b, 1) < 0) {
fprintf(stderr, "%s: fdelay_wr_mode(): %s\n",
argv[0], strerror(errno));
exit(1);
}
while (fdelay_check_wr_mode(b) != 0) {
printf(".");
sleep(1);
}
printf(" locked!\n");
fdelay_close(b);
fdelay_exit();
return 0;
}
if (wr_off) {
if (fdelay_wr_mode(b, 0) < 0) {
fprintf(stderr, "%s: fdelay_wr_mode(): %s\n",
argv[0], strerror(errno));
exit(1);
}
fdelay_close(b);
fdelay_exit();
return 0;
}
if (fdelay_set_time(b, &t) < 0) {
fprintf(stderr, "%s: fdelay_set_host_time(): %s\n",
argv[0], strerror(errno));
exit(1);
}
fdelay_close(b);
fdelay_exit();
return 0;
}
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