Commit dc471ac5 authored by Federico Vaga's avatar Federico Vaga

Merge branch 'release/v3.0.7' into master

parents 71ab61ce 21a30311
......@@ -6,6 +6,19 @@
Changelog
=========
3.0.7 - 2021-02-24
==================
Added
-----
- sw: show the input status from the fmc-fdelay-status tool
- sw: use the fmc-fdelay-input tool to change the input status
Fixed
-----
- sw: make clear in the tools' help message that the device ID is an
hexadecimal number
3.0.6 - 2021-01-20
==================
Fixed
......
......@@ -22,7 +22,8 @@ void help(char *name)
" wr - sets the time source to White Rabbit.\n"
" host - sets the time source to local oscillator and coarsely\n"
" synchronizes the card to the system clock.\n"
" seconds:[nanoseconds]: - sets local time to the given value.\n");
" seconds:[nanoseconds]: - sets local time to the given value.\n"
" and <dev> is the device ID (hexadecimal)\n");
exit(1);
}
......
......@@ -42,7 +42,7 @@ static const char help_msg[] =
"-f Source file where to read calibration data from\n"
"-o Offset in bytes within the file (default 0)\n"
"Write options:\n"
"-D FMC FDelay Target Device ID\n"
"-D FMC FDelay Target Device ID (hexadecimal)\n"
"\n";
static inline void fmc_fdelay_calibration_version(void)
......
......@@ -12,16 +12,23 @@
#include "tools-common.h"
char git_version[] = "git version: " GIT_VERSION;
char *prog;
void help(char *name)
{
fprintf(stderr, "%s: Use \"%s [-V] [-d <dev>] [<opts>]\n",
name, name);
fprintf(stderr, " options:\n"
" -d <dev> device ID (hexadecimal)\n"
"Configuration:\n"
" -e (0|1) disable or enable the channel\n"
" -t (0|1) disable or enable pulse timestamping\n"
"Timestamp:"
" -c <count> default is 0 and means forever\n"
" -n nonblocking: only empty buffer\n"
" -r raw mode: show hex timestamps\n"
" -f floating point (default): sec.nsec\n");
fprintf(stderr, "Note that the tool does not enforce any default configuration. Therefore, if not explicitly set, it will continue by using the current configuration.\n");
exit(1);
}
......@@ -35,16 +42,106 @@ void dump_input(struct fdelay_time *t, int np, int umode)
}
}
/**
* Configure the input channel
* @param[in] b device token
* @param[in] enable channel enable status: -1 unchanged, 0 disabled, 1 enabled
* @param[in] timestamp pulse timestamping: -1 unchanged, 0 disabled, 1 enable
* @return 0 on success, otherwise -1 and errno is appropriately set
*/
int input_config(struct fdelay_board *b, int enable, int timestamp)
{
int flags;
int err;
flags = fdelay_get_config_tdc(b);
if (flags < 0) {
fprintf(stderr, "%s: failed to get TDC status: %s\n", prog,
fdelay_strerror(errno));
return flags;
}
if (enable >= 0) {
if (enable)
flags &= ~FD_TDCF_DISABLE_INPUT;
else
flags |= FD_TDCF_DISABLE_INPUT;
}
if (timestamp >= 0) {
if (timestamp)
flags &= ~FD_TDCF_DISABLE_TSTAMP;
else
flags |= FD_TDCF_DISABLE_TSTAMP;
}
err = fdelay_set_config_tdc(b, flags);
if (err) {
fprintf(stderr, "%s: failed to set TDC status: %s\n", prog,
fdelay_strerror(errno));
return err;
}
return 0;
}
int input_timestamp(struct fdelay_board *b, int count, int umode, int nonblock)
{
int flags;
int err;
flags = fdelay_get_config_tdc(b);
if (flags < 0)
return flags;
if (flags & (FD_TDCF_DISABLE_INPUT | FD_TDCF_DISABLE_TSTAMP)) {
fputs("Can't show timestamps: channel and timestamping must be enabled\n",
stderr);
errno = ENODEV;
return -1;
}
err = 0;
/* now read pulses, "np" at a time */
while (1) {
struct fdelay_time pdata[16];
int ret, np = 16;
if (count && count < np)
np = count;
ret = fdelay_read(b, pdata, np, nonblock);
if (ret < 0) {
err = ret;
fprintf(stderr, "%s: fdelay_read: %s\n", prog,
strerror(errno));
break;
}
if (!ret)
continue;
dump_input(pdata, ret, umode);
if (nonblock) /* non blocking: nothing more to do */
break;
if (!count) /* no count: forever */
continue;
count -= ret;
if (!count) /* asked that many, we are done */
break;
}
return err;
}
int main(int argc, char **argv)
{
struct fdelay_board *b;
int opt, err, dev = -1;
int nonblock = 0, count = 0;
int umode = TOOLS_UMODE_USER, flags;
int umode = TOOLS_UMODE_USER;
int enable = -1, timestamp = -1;
int config = 0;
prog = argv[0];
/* Standard part of the file (repeated code) */
if (tools_need_help(argc, argv))
......@@ -60,7 +157,7 @@ int main(int argc, char **argv)
}
/* Parse our specific arguments, starting back from argv[1] */
while ((opt = getopt(argc, argv, "d:hc:nrf")) != -1) {
while ((opt = getopt(argc, argv, "d:hc:nrfe:t:")) != -1) {
switch (opt) {
char *rest;
case 'd':
......@@ -94,6 +191,34 @@ int main(int argc, char **argv)
case 'f':
umode = TOOLS_UMODE_FLOAT;
break;
case 'e':
enable = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
if (enable > 1) {
fprintf(stderr, "%s: invalid enable value \"%s\"\n",
argv[0], optarg);
exit(1);
}
config = 1;
break;
case 't':
timestamp = strtol(optarg, &rest, 0);
if (rest && *rest) {
fprintf(stderr, "%s: Not a number \"%s\"\n",
argv[0], optarg);
exit(1);
}
if (timestamp > 1) {
fprintf(stderr, "%s: invalid enable value \"%s\"\n",
argv[0], optarg);
exit(1);
}
config = 1;
break;
}
}
if (optind != argc)
......@@ -112,48 +237,13 @@ int main(int argc, char **argv)
exit(1);
}
flags = fdelay_get_config_tdc(b);
if (flags < 0) {
err = flags;
if (config) {
err = input_config(b, enable, timestamp);
if (err)
goto out;
}
flags &= ~(FD_TDCF_DISABLE_INPUT | FD_TDCF_DISABLE_TSTAMP);
err = fdelay_set_config_tdc(b, flags);
if (err) {
fprintf(stderr, "%s: failed to configure TDC: %s\n", argv[0],
fdelay_strerror(errno));
goto out;
}
/* now read pulses, "np" at a time */
while (1) {
struct fdelay_time pdata[16];
int ret, np = 16;
if (count && count < np)
np = count;
ret = fdelay_read(b, pdata, np, nonblock);
if (ret < 0) {
err = ret;
fprintf(stderr, "%s: fdelay_read: %s\n", argv[0],
strerror(errno));
break;
}
if (!ret)
continue;
dump_input(pdata, ret, umode);
if (nonblock) /* non blocking: nothing more to do */
break;
if (!count) /* no count: forever */
continue;
count -= ret;
if (!count) /* asked that many, we are done */
break;
}
err = input_timestamp(b, count, umode, nonblock);
out:
fdelay_close(b);
fdelay_exit();
......
......@@ -20,6 +20,7 @@ void help(char *name)
fprintf(stderr, "%s: Use \"%s [-V] [-d <dev>] [<opts>]\n",
name, name);
fprintf(stderr, " options:\n"
" -d <dev> device ID (hexadecimal)\n"
" -o <output> ouput channel: 1..4 (default 1)\n"
" -c <count> default is 0 and means forever\n"
" -m <mode> \"pulse\" (default), \"delay\", \"disable\"\n"
......
......@@ -3,6 +3,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include "fdelay-lib.h"
......@@ -15,15 +16,37 @@ void help(char *name)
fprintf(stderr, "fmc-fdelay-status: reports channel programming\n");
fprintf(stderr, "Use: \"%s [-V] [-d <dev>] [-r]\"\n", name);
fprintf(stderr, " -r: display raw hardware configuration");
fprintf(stderr, " -d <dev>: device ID (hexadecimal)\n");
fprintf(stderr, " -r : display raw hardware configuration\n");
exit(1);
}
void print_intput_raw(int flags)
{
fprintf(stdout, "Input, flags 0x%x\n", flags);
}
void print_intput_human(int flags)
{
bool disabled = flags & FD_TDCF_DISABLE_INPUT;
fprintf(stdout, "Input : %s\n",
disabled ? "disabled" : "enabled");
if (!disabled) {
disabled = flags & FD_TDCF_DISABLE_TSTAMP;
fprintf(stdout, " timestamping: %s\n",
disabled ? "disabled" : "enabled");
disabled = !(flags & FD_TDCF_TERM_50);
fprintf(stdout, " 50 Ohm termination: %s\n",
disabled ? "disabled" : "enabled");
}
}
int main(int argc, char **argv)
{
struct fdelay_board *b;
struct fdelay_pulse p;
int ch, err, dev = -1, raw = 0, opt;
int ch, err, dev = -1, raw = 0, opt, flags;
/* Standard part of the file (repeated code) */
if (tools_need_help(argc, argv))
......@@ -71,6 +94,16 @@ int main(int argc, char **argv)
exit(1);
}
flags = fdelay_get_config_tdc(b);
if (flags < 0) {
fputs("Input : failed to get status\n", stdout);
} else {
if (raw)
print_intput_raw(flags);
else
print_intput_human(flags);
}
for (ch = 1; ch <= 4; ch++) {
if (fdelay_get_config_pulse(b, FDELAY_OUTPUT_USER_TO_HW(ch),
&p) < 0) {
......
......@@ -14,6 +14,7 @@ void help(char *name)
{
fprintf(stderr, "%s: Use \"%s [-V] [-d <dev>] [on|off]\n",
name, name);
fprintf(stderr, " -d <dev>: device ID (hexadecimal)\n");
exit(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