Added choose_clock and choose_routing demo programs. Synced comedi.h

with comedi.  Made dio demo simply configure the line direction based
on the command line argument.
This commit is contained in:
Frank Mori Hess 2006-10-23 19:35:24 +00:00
parent 34b9800e40
commit 4cdf1b09a9
6 changed files with 209 additions and 73 deletions

View file

@ -1,6 +1,7 @@
noinst_PROGRAMS = \
antialias ao_waveform ao_mmap apply_cal cmd dio eeprom_dump board_info \
antialias ao_waveform ao_mmap apply_cal choose_clock \
choose_routing cmd dio eeprom_dump board_info \
inp inpn insn ledclock mmap outp poll receiver select \
sender sigio sv tut1 tut2
@ -22,6 +23,14 @@ apply_cal_SOURCES = apply_cal.c common.c
apply_cal_CFLAGS = $(COMEDILIB_CFLAGS)
apply_cal_LDADD = $(COMEDILIB_LIBS)
choose_clock_SOURCES = choose_clock.c common.c
choose_clock_CFLAGS = $(COMEDILIB_CFLAGS)
choose_clock_LDADD = $(COMEDILIB_LIBS)
choose_routing_SOURCES = choose_routing.c common.c
choose_routing_CFLAGS = $(COMEDILIB_CFLAGS)
choose_routing_LDADD = $(COMEDILIB_LIBS)
cmd_SOURCES = cmd.c common.c
cmd_CFLAGS = $(COMEDILIB_CFLAGS)
cmd_LDADD = $(COMEDILIB_LIBS)

View file

@ -25,29 +25,39 @@ ao_waveform:
which currently is some of the members of the NI AT-MIO and PCI-MIO
E series. Creates a sine wave on an analog output channel.
board_info:
Displays some information that Comedi knows about a device.
choose_clock:
Selects a master clock source. The subdevice must support
INSN_CONFIG_CLOCK_SRC. The command-line argument specifies
the clock source, and the optional -F option specifies the clock's
frequency.
common:
This is not an example. The file common.c just contains some code
that is common to many of the examples.
cmd:
cmd:
An example for directly using Comedi commands. Comedi commands
are used for asynchronous acquisition, with the timing controlled
by on-board timers or external events. If this demo doesn't work
with your hardware, read the comments in the source. Hint: data
is written to stdout, comments to stderr.
dio:
Requirements: A board with a digital I/O subdevice. Not just
a 'digital input' or 'digital output' subdevice, but one in
which the channels can be configured between input and output.
Configures the specified channel as an output if passed a
nonzero argument. Otherwise, the channel is configured as
an input. Once the channel's direction has been configured,
you can read/write to it with the inp/outp demo programs.
eeprom_dump:
Dumps the EEPROM of a card, if it has one. Useful for debugging
devices/drivers.
board_info:
Displays some information that Comedi knows about a device.
inp:
Simple input: Reads one sample from one channel on one subdevice.
@ -60,8 +70,8 @@ insn:
Example showing how to use instructions directly. Not
recommended for beginners: use higher-level functions such
as comedi_data_read(), comedi_data_write(), etc., as demonstrated
in the inp, outp, and dio examples.
in the inp, outp, and dio examples.
ledclock:
This demo requires a Fantazein clock modified to be directly
controlled by the parallel port on a computer. The original
@ -84,7 +94,7 @@ receiver:
requires a digital output subdevice. When the clock and data
pins are connected between the sending and receiving devices,
one should be able to send bits over the link.
select:
An example for using select() with asynchronous input. This
example requires an asynchronous input subdevice that can

70
demo/choose_clock.c Normal file
View file

@ -0,0 +1,70 @@
/*
* Digital I/O example
* Part of Comedilib
*
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
*
* This file may be freely modified, distributed, and combined with
* other software, as long as proper attribution is given in the
* source code.
*/
/*
* Requirements: A board with a subdevice that supports
* INSN_CONFIG_CLOCK_SRC
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include "examples.h"
comedi_t *device;
int main(int argc, char *argv[])
{
freq = 0.;
parse_options(argc,argv);
device=comedi_open(filename);
if(!device){
comedi_perror(filename);
exit(0);
}
unsigned period_ns;
if(freq > 0.)
period_ns = 1e9 / freq;
else
period_ns = 0;
printf("Selecting master clock %d on subdevice %d.\n", value, subdevice);
if(period_ns)
{
printf("Clock period = %d nanoseconds.\n", period_ns);
}else
{
printf("Clock period unspecified.\n");
}
comedi_insn insn;
lsampl_t data[3];
memset(&insn, 0, sizeof(comedi_insn));
insn.insn = INSN_CONFIG;
insn.subdev = subdevice;
insn.data = data;
insn.n = sizeof(data) / sizeof(data[0]);
data[0] = INSN_CONFIG_SET_CLOCK_SRC;
data[1] = value;
data[2] = period_ns;
int retval = comedi_do_insn(device, &insn);
if(retval < 0) comedi_perror("comedi_do_insn");
return retval;
}

63
demo/choose_routing.c Normal file
View file

@ -0,0 +1,63 @@
/*
* Digital I/O example
* Part of Comedilib
*
* Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
*
* This file may be freely modified, distributed, and combined with
* other software, as long as proper attribution is given in the
* source code.
*/
/*
* Requirements: A board with a subdevice that supports
* INSN_CONFIG_SET_ROUTING
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include "examples.h"
comedi_t *device;
int main(int argc, char *argv[])
{
freq = 0.;
parse_options(argc,argv);
device=comedi_open(filename);
if(!device){
comedi_perror(filename);
exit(0);
}
unsigned period_ns;
if(freq > 0.)
period_ns = 1e9 / freq;
else
period_ns = 0;
printf("Selecting routing %d for channel %d on subdevice %d.\n", value, channel, subdevice);
comedi_insn insn;
lsampl_t data[2];
memset(&insn, 0, sizeof(comedi_insn));
insn.insn = INSN_CONFIG;
insn.subdev = subdevice;
insn.chanspec = channel;
insn.data = data;
insn.n = sizeof(data) / sizeof(data[0]);
data[0] = INSN_CONFIG_SET_ROUTING;
data[1] = value;
int retval = comedi_do_insn(device, &insn);
if(retval < 0) comedi_perror("comedi_do_insn");
return retval;
}

View file

@ -46,41 +46,16 @@ int main(int argc, char *argv[])
exit(0);
}
printf("configuring pin %d for output...\n",channel);
ret=comedi_dio_config(device,subdevice,channel,COMEDI_OUTPUT);
printf("toggling pin %d rapidly...\n",channel);
comedi_dio_write(device,subdevice,channel,1);
#if 0
for(i=0;i<10000;i++){
usleep(1000000);
comedi_dio_write(device,subdevice,channel,1);
printf("1\n");
usleep(1000000);
comedi_dio_write(device,subdevice,channel,0);
printf("0\n");
}
#endif
#if 0
printf("configuring pin %d or subdevice %d ", channel, subdevice);
if(value)
{
unsigned int mask;
unsigned int data;
printf("toggling pin %d rapidly (using bitfield)...\n",channel);
mask = 1<<channel;
for(i=0;i<10000;i++){
data = mask;
comedi_dio_bitfield(device,subdevice,mask,&data);
data = 0;
comedi_dio_bitfield(device,subdevice,mask,&data);
printf("for output.\n");
ret=comedi_dio_config(device,subdevice,channel, COMEDI_OUTPUT);
}else
{
printf("for input.\n");
ret=comedi_dio_config(device,subdevice,channel, COMEDI_INPUT);
}
}
#endif
return 0;
}

View file

@ -243,13 +243,14 @@ enum configuration_ids
INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR = 1001, // Use CTR as single pulsegenerator
INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR = 1002, // Use CTR as pulsetraingenerator
INSN_CONFIG_GPCT_QUADRATURE_ENCODER = 1003, // Use the counter as encoder
INSN_CONFIG_SET_GATE_SRC = 2001, // Set CTR gate source
INSN_CONFIG_GET_GATE_SRC = 2002, // Get CTR gate source
INSN_CONFIG_SET_CLOCK_SRC = 2003, // Set CTR clock source
INSN_CONFIG_GET_CLOCK_SRC = 2004, // Get CTR clock source
INSN_CONFIG_SET_GATE_SRC = 2001, // Set gate source
INSN_CONFIG_GET_GATE_SRC = 2002, // Get gate source
INSN_CONFIG_SET_CLOCK_SRC = 2003, // Set master clock source
INSN_CONFIG_GET_CLOCK_SRC = 2004, // Get master clock source
INSN_CONFIG_8254_SET_MODE = 4097,
INSN_CONFIG_8254_READ_STATUS = 4098,
INSN_CONFIG_SET_RTSI_CLOCK_MODE = 5000 // Set RTSI bus clock mode
INSN_CONFIG_SET_ROUTING = 4099,
INSN_CONFIG_GET_ROUTING = 4109,
};
@ -521,33 +522,41 @@ enum i8254_mode
I8254_BINARY = 0
};
/* RTSI Clock mode */
#define COMEDI_RTSI_CLOCK_MODE_INTERNAL 0x00 // Internal clock mode
#define COMEDI_RTSI_CLOCK_MODE_OUTPUT 0x01 // Outputs clock to RTSI
#define COMEDI_RTSI_CLOCK_MODE_SLAVE 0x02 // Runs from RTSI clock
#define COMEDI_RTSI_CLOCK_MODE_MASTER 0x03 // Outputs clock to RTSI and runs from this external clock
/* clock sources for ni mio boards and INSN_CONFIG_SET_CLOCK_SRC */
enum ni_mio_clock_source
{
NI_MIO_INTERNAL_CLOCK = 0,
NI_MIO_RTSI_CLOCK = 1, /* doesn't work for m-series, use NI_MIO_PLL_RTSI_CLOCK() */
/* the NI_MIO_PLL_* sources are m-series only */
NI_MIO_PLL_PXI_STAR_TRIGGER_CLOCK = 2,
NI_MIO_PLL_PXI10_CLOCK = 3,
NI_MIO_PLL_RTSI0_CLOCK = 4
};
static inline unsigned NI_MIO_PLL_RTSI_CLOCK(unsigned rtsi_channel)
{
return NI_MIO_PLL_RTSI0_CLOCK + rtsi_channel;
}
/* RTSI BUS pins */
#define NI_RTSI_0 0
#define NI_RTSI_1 1
#define NI_RTSI_2 2
#define NI_RTSI_3 3
#define NI_RTSI_4 4
#define NI_RTSI_5 5
#define NI_RTSI_6 6
#define NI_RTSI_7 7
/* RTSI BUS pin usage in standard configuration */
#define NI_RTSI_STD_AI_START1 0
#define NI_RTSI_STD_AI_START2 1
#define NI_RTSI_STD_AI_CONV 2
#define NI_RTSI_STD_CT1_SRC 3
#define NI_RTSI_STD_CT1_GATE 4
#define NI_RTSI_STD_AO_SAMP_CLOCK 5
#define NI_RTSI_STD_AO_START_TRIG 6
#define NI_RTSI_STD_AI_SAMP_CLOCK 7
#define NI_RTSI_STD_CTR0_SRC 8
#define NI_RTSI_STD_CTR0_GATE 9
/* Signals which can be routed to an NI RTSI pin with INSN_CONFIG_SET_ROUTING.
The numbers are assigned are not arbitrary, they correspond to the bits required
to program the board. */
enum ni_rtsi_output
{
NI_RTSI_OUTPUT_ADR_START1 = 0,
NI_RTSI_OUTPUT_ADR_START2 = 1,
NI_RTSI_OUTPUT_SCLKG = 2,
NI_RTSI_OUTPUT_DACUPDN = 3,
NI_RTSI_OUTPUT_DA_START1 = 4,
NI_RTSI_OUTPUT_G_SRC_0 = 5,
NI_RTSI_OUTPUT_G_GATE_0 = 6,
NI_RTSI_OUTPUT_RGOUT0 = 7,
NI_RTSI_OUTPUT_RTSI_BRD_0 = 8,
NI_RTSI_OUTPUT_RTSI_OSC = 12 /* m-series only */
};
static inline unsigned NI_RTSI_OUTPUT_RTSI_BRD(unsigned n)
{
return NI_RTSI_OUTPUT_RTSI_BRD_0 + n;
}
/* NI External Trigger lines */
#define NI_EXT_PFI_0 0