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