Goal:
Perform simultaneous, finite, buffered analog input/output.
I see people doing simultaneous AIO in kernel space with callbacks and
single point AO writes[1,2], but
(1) there are no callbacks in user space, and
(2) I don't have feedback, so I don't want the kernel in the loop.
Since I know my output beforehand, I want to write it to the card
before generation/aquisition begins.
Byran Cole seems to have gotten this working back in 2004 [3], but I
haven't found any explicit examples...
System:
Comedi: Comedi 0.7.75 (patched), Comedilib 0.8.1
Card: NI PCI 6052E
OS: Ubuntu 7.10
Kernel (from uname -a): 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12
GMT 2007 i686 GNU/Linux
Since Comedi didn't have support for simultaneous buffered commands, I
went digging in the NI DAQ-STC manual and found that I could trigger
the analog output start with the analog input start trigger
(AI_START1).
I made the adjustments to ni_mio_common.c listed in ni_mio_common-
patch.
I also applied (by hand) the patch suggested in [4], since I was
having the same problem (No lockups since patching).
Results:
Everything seems to work as expected 80% of the time, but ~ 20% of the
time simult_aio produces no analog output at all (verified with a
scope).
Using test.py, the failures seem to be randomly distributed (no more
likely to fail immediately after another failure), but I haven't done
any rigorous analysis.
I added some debugging 'printk's to ni_mio_common.c to check, and the
AO and AI subdevices are getting restarted after every program call,
so that's not it...
As far as I can tell, the registers should be identically set up for
each run, how can some attempts succeed while others fail?
I also tried inserting some waits (the usleeps) in simult_aio.c to
ensure that the problem wasn't some sort of timing issue, and still
got a 20% failure rate even with 1 second usleeps.
With my debugging printks, the output to dmesg for a single simult_aio
call is
"
[ 5795.131608] AO trigger on external signal
[ 5795.132755] trigger AI
[ 5795.133125] ni_event called
[ 5795.133135] Not an error, overflow, or eoa (0x4)
[ 5795.133807] ni_event called
[ 5795.133817] AI reset event
[ 5795.133819] resetting AI
[ 5795.133828] ni_event called
[ 5795.133830] AO reset event
[ 5795.133832] resetting AO
"
Any ideas?
Thanks,
Trevor
Contents of tar file:
simult_aio.c My simultaneous AIO test function
int16s_to_ascii_array.c Read int16 files and write the
corresponding ASCII array to stdout
stem_leaf.c Create an ASCII histogram of ASCII data
read in from stdin
test.py Test simult_aio using input channel 0 to
read output channel 0 (you must physically wire the two channels
together)
Makefile Run `make check` to compile the C source
and run test.py (after patching and recompiling comedi and
reconfiguring your board)
ni_mio_common-patch My alterations to ni_mio_common from
comedi-0.7.75
README This file.
References:
[1] 'comedi command structure',
https://mail.comedi.org/pipermail/comedi/2001-May/001368.html
[2] 'simultaneous analog input/output',
https://mail.comedi.org/pipermail/comedi/2007-April/008446.html
[2] 'DMA on simultaneous AI & AO ?',
http://osdir.com/ml/linux.comedi/2004-04/msg00127.html
[3] 'hard crash of kubuntu 7.10 on second run of simple program',
this group.