Commit 3be0244b authored by Benoit Rat's avatar Benoit Rat Committed by Alessandro Rubini

dio: add warning/error messages when trying to access bad channel/mode

* D/d,0,1 modes can not be used by the first channel (ch0)
* C/c mode is only useful for the last channel (ch4)

* wr-pps can not be used for channel 0
parent 37ecaba6
......@@ -1024,14 +1024,6 @@ This is the list of supported modes for channels:
signal to drive the input). Termination is 50 Ohm. Pulses on
an input channel are timestamped.
@item C c
``Clock'' input. This mode (with or without termination) is
used to feed a clock to the White Rabbit core (currently the
WR core supports a 10MHz input on channel 4 (the last one).
For other channel, the mode is just like @t{I} or @t{i} but
without timestamping (and thus without a software interrupt).
@item 0 1
Digital output mode, from the GPIO logic core, resp. low and high.
......@@ -1047,16 +1039,32 @@ This is the list of supported modes for channels:
command. The termination resistor doesn't make much sense for
output, but the code is provided for consistency with input modes.
@item P p
@item P p (Channel 0)
Pulse per second output from the White Rabbit core. This
@i{pps} is sharper in its absolute time than the one that can be
Pulse per second output from the White Rabbit core that can be used
only for the first channel (ch0). This @i{pps} is sharper in its absolute
time than the one that can be
generated by software using DIO pulses. Again, upper case
selects the termination, for symmetry with input modes.
@item C c (Channel 4)
``Clock'' input. This mode (with or without termination) is
used to feed a clock to the White Rabbit core (currently the
WR core supports a 10MHz input on channel 4 (the last one).
For other channel, the mode is just like @t{I} or @t{i} but
without timestamping (and thus without a software interrupt).
@end table
@b{Note}: The first channel (channel 0) has been modified and now support only the
@t{P}/@t{p} as output mode. You will not be able to use @t{D},@t{d},@t{1},@t{0} modes.
@b{Note}: At startup, the DIO channels are configured by default as:
@code{wr-dio-cmd mode p00ic}.
Generation of a pulse train is performed by
software running at interrupt time,
because the @i{simple DIO} card and gateware can only emit a single pulse at
......@@ -1134,8 +1142,8 @@ file.
The program is meant as a source code example, more than a real PPS
signal. If you need a real WR-driven pulse-per-second, you should
configure the channel accordingly, with ``@t{wr-dio-cmd mode <ch>
p}''.
use the channel0 wich is "hard-wired" to the PTP core and can be configured by
executing: ``@t{wr-dio-cmd mode 0 p}''.
The program just fires a 1ms-long @i{pps} pulse on one of the output
channels. The device name defaults to @i{wr0} but can specify a different one;
......
......@@ -203,6 +203,13 @@ static int one_mode(int c, int index)
return 0;
cmd->channel |= 1 << index;
//Add error message for channel 0
if(index==0 && strchr("dD01",c))
{
fprintf(stderr, "Error: Only p/P modes are available as ouput mode for channel 0\n");
return -1;
}
switch(c) {
case 'D':
cmd->value |= WR_DIO_INOUT_TERM << index;
......@@ -216,6 +223,9 @@ static int one_mode(int c, int index)
case 'c':
cmd->value |= WR_DIO_INOUT_DIO << index;
cmd->value |= WR_DIO_INOUT_VALUE << index;
if(index!=4)
fprintf(stdout, "Warning: Clock mode is only available for last channel (ch4)\n,"
"(on other channel it corresponds to input mode without interruptions)\n");
break;
case 'P':
......
......@@ -23,7 +23,13 @@
#include "wr_nic/wr-nic.h"
#include "wr-dio.h"
/* This takes two arguments: interface name and channel number */
/**
* This takes two arguments: interface name and channel number
*
* This simple tools just show an example of how to program with wr-nic/dio.
* If you want to measure WR timing we suggest to use the hardwire PPS on channel 0
* that gives a more accurate precision.
**/
int main(int argc, char **argv)
{
......@@ -49,7 +55,7 @@ int main(int argc, char **argv)
prgname, argv[charg]);
exit(1);
}
if (ch < 0 || ch > 4) {
if (ch < 1 || ch > 4) {
fprintf(stderr, "%s: Out of range channel number \"%s\"\n",
prgname, argv[charg]);
exit(1);
......@@ -83,11 +89,15 @@ int main(int argc, char **argv)
memset(cmd, 0, sizeof(*cmd));
cmd->command = WR_DIO_CMD_PULSE;
cmd->channel = ch;
cmd->flags = WR_DIO_F_REL | WR_DIO_F_LOOP;
/* Number of loops: -1 <=> Inf */
cmd->value = -1;
cmd->channel = ch;
/* 2s delay to have time to send and process this command */
cmd->t[0].tv_sec = 2;
cmd->t[1].tv_nsec = 1000 * 1000; /* 1ms */
/* 1ms pulse width */
cmd->t[1].tv_nsec = 1000 * 1000;
/* Loop period */
cmd->t[2].tv_sec = 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