Commit b0bd99ad authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

lib/fdelay-pulse-tom: shortcuts for PPS and 10 MHz output

parent 9d860129
......@@ -12,37 +12,49 @@ static void help(int argc, char *argv[])
{
fprintf(stderr, "%s: Use \"%s [options]\n", argv[0], argv[0]);
fprintf(stderr, "\t Options are: \n");
fprintf(stderr, "\t -d device : specify device index of hex busid (default: first card available)\n");
fprintf(stderr, "\t -m mode : the mode: disable, pulse or delay (mandatory)\n");
fprintf(stderr, "\t -o channel : the output channel, 1..4 (mandatory) \n");
fprintf(stderr, "\t -a time : specify trigger absolute time (default: none)\n");
fprintf(stderr, "\t -s time : specify trigger relative time (default: 1s in pulse generator mode and 0.5 us in delay mode).\n");
fprintf(stderr, "\t -w time : specify output pulse width (default: 200 ns). \n");
fprintf(stderr,
"\t -d device : specify device index of hex busid (default: first card available)\n");
fprintf(stderr,
"\t -m mode : the mode: disable, pulse or delay (mandatory)\n");
fprintf(stderr,
"\t -o channel : the output channel, 1..4 (mandatory) \n");
fprintf(stderr,
"\t -a time : specify trigger absolute time (default: none)\n");
fprintf(stderr,
"\t -s time : specify trigger relative time (default: 1s in pulse generator mode and 0.5 us in delay mode).\n");
fprintf(stderr,
"\t -w time : specify output pulse width (default: 200 ns). \n");
fprintf(stderr, "\t -g time : specify output pulse spacing. \n");
fprintf(stderr, "\t -t : wait for trigger before exiting (default: on) \n");
fprintf(stderr, "\t -q count : number of pulses to generate (default: 1)\n");
fprintf(stderr, "\t -c : generate infinite number of pulses (default: off)\n");
fprintf(stderr, "Time format is a sum of times expressed in (full, milli, micro, nano, pico)seconds, for example:\n");
fprintf(stderr, "1s+20u-100n is 1 sec, 19.9 us. Fractional numbers are NOT allowed.\n\n");
fprintf(stderr,
"\t -t : wait for trigger before exiting (default: on) \n");
fprintf(stderr,
"\t -q count : number of pulses to generate (default: 1)\n");
fprintf(stderr,
"\t -c : generate infinite number of pulses (default: off)\n");
fprintf(stderr, "\t -p : generate PPS\n");
fprintf(stderr, "\t -1 : generate 10 MHz\n");
fprintf(stderr,
"Time format is a sum of times expressed in (full, milli, micro, nano, pico)seconds, for example:\n");
fprintf(stderr,
"1s+20u-100n is 1 sec, 19.9 us. Fractional numbers are NOT allowed.\n\n");
}
static struct fdelay_time ts_add(struct fdelay_time a, struct fdelay_time b)
{
a.frac += b.frac;
if(a.frac >= 4096)
{
if (a.frac >= 4096) {
a.frac -= 4096;
a.coarse++;
}
a.coarse += b.coarse;
if(a.coarse >= 125000000)
{
if (a.coarse >= 125000000) {
a.coarse -= 125000000;
a.utc ++;
a.utc++;
}
a.utc += b.utc;
return a; }
return a;
}
static void parse_time(char *s, struct fdelay_time *t)
{
......@@ -56,12 +68,10 @@ static void parse_time(char *s, struct fdelay_time *t)
char c, *buf = s;
while((c = *buf++) != 0)
{
switch(c)
{
while ((c = *buf++) != 0) {
switch (c) {
case '+':
if(scale == one_second)
if (scale == one_second)
extra_seconds += sign * term;
else
time_ps += sign * term * scale;
......@@ -70,7 +80,7 @@ static void parse_time(char *s, struct fdelay_time *t)
sign = 1;
break;
case '-':
if(scale == one_second)
if (scale == one_second)
extra_seconds += sign * term;
else
time_ps += sign * term * scale;
......@@ -95,31 +105,30 @@ static void parse_time(char *s, struct fdelay_time *t)
scale = 1LL;
break;
default:
if(isdigit(c))
{
if (isdigit(c)) {
term *= 10LL;
term += (int64_t) (c - '0');
break;
} else {
fprintf(stderr, "Error while parsing time string '%s'\n", s);
fprintf(stderr,
"Error while parsing time string '%s'\n",
s);
exit(-1);
}
}
}
if(scale == one_second)
if (scale == one_second)
extra_seconds += sign * term;
else
time_ps += sign * term * scale;
while(time_ps < 0)
{
while (time_ps < 0) {
time_ps += one_second;
extra_seconds--;
}
fdelay_pico_to_time((uint64_t *) &time_ps, t);
fdelay_pico_to_time((uint64_t *) & time_ps, t);
t->utc += extra_seconds;
......@@ -128,7 +137,8 @@ static void parse_time(char *s, struct fdelay_time *t)
void dump_ts(char *title, struct fdelay_time t)
{
printf("%s: secs %lld coarse %d frac %d\n", title, t.utc, t.coarse, t.frac);
printf("%s: secs %lld coarse %d frac %d\n", title, t.utc, t.coarse,
t.frac);
}
int main(int argc, char **argv)
......@@ -142,13 +152,13 @@ int main(int argc, char **argv)
int relative = 1;
int devid = 0;
int do_pps = 0, do_10m = 0;
uint64_t default_width = 250000;
fdelay_pico_to_time(&default_width, &t_width);
while ((opt = getopt(argc, argv, "hctd:m:o:a:s:w:g:q:")) != -1) {
switch(opt)
{
while ((opt = getopt(argc, argv, "p1hctd:m:o:a:s:w:g:q:")) != -1) {
switch (opt) {
case 'h':
help(argc, argv);
break;
......@@ -178,19 +188,18 @@ int main(int argc, char **argv)
break;
case 'o':
channel = atoi(optarg);
if(channel < 1 || channel > 4)
{
if (channel < 1 || channel > 4) {
fprintf(stderr, "Invalid output channel.\n");
exit(1);
}
break;
case 'm':
if(!strcmp(optarg, "pulse"))
if (!strcmp(optarg, "pulse"))
mode = FD_OUT_MODE_PULSE;
else if(!strcmp(optarg, "delay"))
else if (!strcmp(optarg, "delay"))
mode = FD_OUT_MODE_DELAY;
else if(!strcmp(optarg, "disable"))
else if (!strcmp(optarg, "disable"))
mode = FD_OUT_MODE_DISABLED;
else {
fprintf(stderr, "Invalid output mode.\n");
......@@ -201,6 +210,12 @@ int main(int argc, char **argv)
case 'd':
sscanf(optarg, "%i", &devid);
break;
case 'p':
do_pps = 1;
break;
case '1':
do_10m = 1;
break;
}
}
......@@ -228,13 +243,13 @@ int main(int argc, char **argv)
exit(1);
}
if(mode <0 || channel < 0)
{
fprintf(stderr,"You must specify the mode and the channel to generate pulses\n");
if ((mode < 0 || channel < 0) && !do_pps && !do_10m) {
fprintf(stderr,
"You must specify the mode and the channel to generate pulses\n");
exit(1);
}
if(mode == FD_OUT_MODE_PULSE && relative)
{
if (mode == FD_OUT_MODE_PULSE && relative) {
fdelay_get_time(b, &p.start);
p.start = ts_add(p.start, t_start);
} else {
......@@ -246,12 +261,24 @@ int main(int argc, char **argv)
p.rep = count;
p.mode = mode;
dump_ts("Start", p.start);
dump_ts("End", p.end);
dump_ts("Delta", p.loop);
if (do_pps || do_10m) {
uint64_t width = do_pps ? 1000000 : 48000;
uint64_t delta = do_pps ? 1000000000000ULL : 100000ULL;
fdelay_pico_to_time(&width, &t_width);
printf("mode %d channel %d count %d\n", mode, channel, count);
fdelay_get_time(b, &p.start);
p.start.utc += 2;
p.start.coarse = 0;
p.start.frac = 0;
p.end = ts_add(p.start, t_width);
fdelay_pico_to_time(&delta, &p.loop);
p.rep = -1;
p.mode = FD_OUT_MODE_PULSE;
}
/* And finally work */
if (fdelay_config_pulse(b, channel - 1, &p) < 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