Mechanical Engineering's Deane Blackman sponsored me in the writing of a driver for the Data Translation dt24 Analogue to Digital EISA Card. The code is GPLd.
Currently this driver provides support for double DMA transfer of any combination of the 16 channels and 4 gain levels. It supports wait on trigger, external clocking and arbitrary clock rates (for frequencies < 4MHz).
Planned features (if people want them):
Known bugs:
Thanks to Ken Sheridan for his invaluable assistance in tracing some bugs.
You will need to create a device file to talk to the driver. The major number is made up at module insertion time and is sent to /var/log/messages (actually, to KERN_INFO)
You will need to include dt24driver.h in any program which uses the driver to get the IOCTL numbers.
#include "dt24driver.h"
ioctl(fd, DT24_IOC_WAIT_TRIG));This function will block until an appropriate trigger signal arrives on the trigger pin. Note that it blocks, and that it is currently uninterruptable(meaning, if something bad happens, you will have to reboot the machine to get rid of the driver. This will be fixed in a later version.
ioctl(fd, DT24_IOC_SET_GAIN_CHAN(5), gainlist);This ioctl is responsible for programming in the channel and gain list for the card. the channel and gain list should consist of pairs of bytes, each of which starts with a byte for the channel number and ends with a byte containing the gain power(2^gain * the input signal). The number in brackets is the length of the gainlist, it can be a variable or a constant.
// tuples consisting of:
// 8 bits channel
// 8 bits gain
for(i = 0; i < 16; i++) {
gainlist[2*i + 0] = i;
gainlist[2*i + 1] = 0;
}
assert(0 <= ioctl(fd, DT24_IOC_SET_GAIN_CHAN(16), gainlist));
ioctl(fd, DT24_IOC_SET_RATE, 100000);This ioctl sets the rate of the clock which drives the DMA transfer of sample data. Each clock will produce one sample of data(2 bytes containing 12bits)
ioctl(fd, DT24_IOC_GROUND_PINS, 0xaa55);The GROUND_PINS ioctl is used to override the default setting of the grounding relays on the standard dt24 breakout box used by mechanical engineering. Ones in the arg word correspond to energized relays, which decouple the input and ground the multiplexer input.
ioctl(fd, DT24_IOC_START);When all the parameters have been configured the client can call the START ioctl and the DMA transfer will begin. Note that the driver has only limited space for storing data, so make sure the data reads occur as close to the START ioctl as possible, although this is not an issue for low speed conversions.
for(i = 0; i < 4096; i++) {
int j;
result_size = read(fd, sample_buffer, 2048*sizeof(short));
if(result_size < 0)
fprintf(stderr, "errno = %d\n", errno);
if(result_size < 2048*sizeof(short))
fprintf(stderr, "short buffer = %d\n", result_size);
fwrite(sample_buffer, result_size, 1, stdout);
}
read will return an even number, corresponding to the number of samples stored in sample_buffer (which needs to be at least 4096 bytes long in this case).
Don't forget to close the device file when you are not using it so that resources are returned to the system as soon as possible.
Nathan Hurst