[Jack-Devel] [PATCH 02/16] For the IIO driver : * Implemented the following functions - untested will contain bugs : iio_driver_attach, iio_driver_detach, iio_driver_start, iio_driver_stop, iio_driver_wait, iio_driver_run_cycle, iio_driver_delete, driver_get_descriptor * The function iio_driver_bufsize now checks that the requested buffer size is safe w.r.t. the iio subsystem. It also checks that the iio required read buffer is resized successfully. * driver_initialize : The driver now allows the period size option to be specified on the command line. Checks for acceptable period size and creates the required iio read buffer.

PrevNext  Index
DateFri, 14 Feb 2014 08:18:27 +1100
From Matt Flax <[hidden] at flatmax dot org>
To[hidden] at lists dot jackaudio dot org
In-Reply-ToMatt Flax [Jack-Devel] [PATCH 00/16] IIO driver for jack1
---
 codeBlocks/jack1.cbp     |  77 ++++++++++++++++-
 codeBlocks/jack1.layout  | 192 +++++++++++++++++++++++++++-------------
 drivers/iio/iio_driver.C | 221 ++++++++++++++++++++++++++++++++++++++++++++---
 drivers/iio/iio_driver.h |  12 ++-
 tools                    |   2 +-
 5 files changed, 429 insertions(+), 75 deletions(-)

diff --git a/codeBlocks/jack1.cbp b/codeBlocks/jack1.cbp
index 5f799df..c1edce0 100644
--- a/codeBlocks/jack1.cbp
+++ b/codeBlocks/jack1.cbp
@@ -211,7 +211,7 @@
 		</Unit>
 		<Unit filename="../drivers/freebob/freebob_driver.h" />
 		<Unit filename="../drivers/iio/Makefile.am" />
-		<Unit filename="../drivers/iio/iio_driver.c">
+		<Unit filename="../drivers/iio/iio_driver.C">
 			<Option compilerVar="CC" />
 		</Unit>
 		<Unit filename="../drivers/iio/iio_driver.h" />
@@ -353,6 +353,81 @@
 			<Option compilerVar="CC" />
 		</Unit>
 		<Unit filename="../python/Makefile.am" />
+		<Unit filename="../tools/Makefile.am" />
+		<Unit filename="../tools/alias.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/alsa_in.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/alsa_out.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/bufsize.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/connect.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/evmon.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/freewheel.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/iodelay.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/ipload.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/ipunload.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/load_test.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/lsp.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/midi_dump.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/monitor_client.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/netsource.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/property.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/samplerate.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/session_notify.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/transport.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/tw.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/wait.c">
+			<Option compilerVar="CC" />
+		</Unit>
+		<Unit filename="../tools/zalsa/Makefile.am" />
+		<Unit filename="../tools/zalsa/alsathread.cc" />
+		<Unit filename="../tools/zalsa/alsathread.h" />
+		<Unit filename="../tools/zalsa/jackclient.cc" />
+		<Unit filename="../tools/zalsa/jackclient.h" />
+		<Unit filename="../tools/zalsa/lfqueue.cc" />
+		<Unit filename="../tools/zalsa/lfqueue.h" />
+		<Unit filename="../tools/zalsa/pxthread.cc" />
+		<Unit filename="../tools/zalsa/pxthread.h" />
+		<Unit filename="../tools/zalsa/zita-a2j.cc" />
+		<Unit filename="../tools/zalsa/zita-j2a.cc" />
 		<Extensions>
 			<envvars />
 			<code_completion />
diff --git a/codeBlocks/jack1.layout b/codeBlocks/jack1.layout
index b1fd9cc..b6060c6 100644
--- a/codeBlocks/jack1.layout
+++ b/codeBlocks/jack1.layout
@@ -1,24 +1,49 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 <CodeBlocks_layout_file>
 	<ActiveTarget name="Debug" />
+	<File name="../drivers/netjack/net_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="1587" topLine="51" />
+		</Cursor>
+	</File>
+	<File name="../README.developers" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="818" topLine="0" />
+		</Cursor>
+	</File>
+	<File name="../jackd/engine.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="47427" topLine="1776" />
+		</Cursor>
+	</File>
+	<File name="../libjack/driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="3008" topLine="90" />
+		</Cursor>
+	</File>
+	<File name="../config/cpu/m68k/atomicity.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="3797" topLine="92" />
+		</Cursor>
+	</File>
 	<File name="../config/os/macosx/README" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="5518" topLine="135" />
+			<Cursor1 position="877" topLine="13" />
 		</Cursor>
 	</File>
-	<File name="../drivers/coreaudio/coreaudio_driver.c" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../config/cpu/ia64/ia64intrin.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="21968" topLine="579" />
+			<Cursor1 position="172" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="../include/driver.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/oss/oss_driver.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="9697" topLine="252" />
+			<Cursor1 position="4593" topLine="193" />
 		</Cursor>
 	</File>
-	<File name="../libjack/thread.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../jackd/controlapi.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="6722" topLine="268" />
+			<Cursor1 position="8637" topLine="300" />
 		</Cursor>
 	</File>
 	<File name="../drivers/sun/sun_driver.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@@ -26,49 +51,59 @@
 			<Cursor1 position="0" topLine="32" />
 		</Cursor>
 	</File>
-	<File name="../include/engine.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../Makefile.am" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1373" topLine="40" />
+			<Cursor1 position="308" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="../drivers/sun/Makefile.am" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../jackd/jackstart.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="246" topLine="0" />
+			<Cursor1 position="1384" topLine="61" />
+		</Cursor>
+	</File>
+	<File name="../drivers/alsa/hammerfall.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="7560" topLine="262" />
 		</Cursor>
 	</File>
-	<File name="../drivers/iio/iio_driver.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../include/port.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="4431" topLine="93" />
+			<Cursor1 position="5953" topLine="148" />
 		</Cursor>
 	</File>
-	<File name="../jackd/engine.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../tools/Makefile.am" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="64641" topLine="2403" />
+			<Cursor1 position="4777" topLine="138" />
 		</Cursor>
 	</File>
-	<File name="../drivers/portaudio/portaudio_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../libjack/port.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="0" topLine="30" />
+			<Cursor1 position="15137" topLine="574" />
 		</Cursor>
 	</File>
-	<File name="../jackd/jackd.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../include/driver.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="19263" topLine="728" />
+			<Cursor1 position="9531" topLine="136" />
 		</Cursor>
 	</File>
-	<File name="../drivers/am/alsa_seqmidi.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../jackd/transengine.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="15067" topLine="601" />
+			<Cursor1 position="14333" topLine="499" />
 		</Cursor>
 	</File>
-	<File name="../drivers/alsa_midi/alsa_midi.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/dummy/Makefile.am" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="18572" topLine="644" />
+			<Cursor1 position="321" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="../drivers/firewire/ffado_driver.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/iio/iio_driver.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="26116" topLine="765" />
+			<Cursor1 position="1042" topLine="28" />
+		</Cursor>
+	</File>
+	<File name="../config/os/generic/time.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="967" topLine="2" />
 		</Cursor>
 	</File>
 	<File name="../config/cpu/alpha/atomicity.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@@ -76,64 +111,89 @@
 			<Cursor1 position="2222" topLine="33" />
 		</Cursor>
 	</File>
-	<File name="../drivers/iio/iio_driver.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../configure.ac" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1385" topLine="23" />
+			<Cursor1 position="24477" topLine="755" />
 		</Cursor>
 	</File>
-	<File name="../README" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/sun/sun_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="118" topLine="0" />
+			<Cursor1 position="5219" topLine="1318" />
 		</Cursor>
 	</File>
-	<File name="../configure.ac" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/alsa/alsa_driver.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="6664" topLine="208" />
+			<Cursor1 position="36028" topLine="1226" />
 		</Cursor>
 	</File>
-	<File name="../libjack/port.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../AUTHORS" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="15137" topLine="574" />
+			<Cursor1 position="2313" topLine="53" />
 		</Cursor>
 	</File>
-	<File name="../drivers/sun/sun_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../include/engine.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="33274" topLine="447" />
+			<Cursor1 position="1373" topLine="40" />
 		</Cursor>
 	</File>
-	<File name="../include/port.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/iio/iio_driver.C" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="5953" topLine="148" />
+			<Cursor1 position="4056" topLine="121" />
 		</Cursor>
 	</File>
-	<File name="../README.developers" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/firewire/ffado_driver.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="4198" topLine="110" />
+			<Cursor1 position="20699" topLine="570" />
 		</Cursor>
 	</File>
-	<File name="../drivers/freebob/freebob_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/am/alsa_rawmidi.c" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="29992" topLine="1037" />
+			<Cursor1 position="7736" topLine="334" />
 		</Cursor>
 	</File>
-	<File name="../drivers/dummy/dummy_driver.c" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../libjack/client.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="11059" topLine="367" />
+			<Cursor1 position="6596" topLine="284" />
 		</Cursor>
 	</File>
-	<File name="../drivers/alsa/hammerfall.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/am/alsa_midi_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="7560" topLine="262" />
+			<Cursor1 position="2611" topLine="68" />
 		</Cursor>
 	</File>
-	<File name="../config/cpu/ia64/ia64intrin.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../libjack/time.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="172" topLine="0" />
+			<Cursor1 position="1648" topLine="49" />
 		</Cursor>
 	</File>
-	<File name="../libjack/driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/iio/Makefile.am" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="3008" topLine="90" />
+			<Cursor1 position="246" topLine="0" />
+		</Cursor>
+	</File>
+	<File name="../drivers/coreaudio/coreaudio_driver.c" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="11306" topLine="627" />
+		</Cursor>
+	</File>
+	<File name="../drivers/alsa_midi/a2j.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="2337" topLine="56" />
+		</Cursor>
+	</File>
+	<File name="../drivers/firewire/ffado_driver.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="5805" topLine="176" />
+		</Cursor>
+	</File>
+	<File name="../drivers/dummy/dummy_driver.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="6236" topLine="184" />
+		</Cursor>
+	</File>
+	<File name="../README" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="118" topLine="0" />
 		</Cursor>
 	</File>
 	<File name="../drivers/portaudio/portaudio_driver.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@@ -141,34 +201,44 @@
 			<Cursor1 position="1626" topLine="24" />
 		</Cursor>
 	</File>
-	<File name="../drivers/alsa/alsa_driver.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/portaudio/portaudio_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="57783" topLine="2122" />
+			<Cursor1 position="18461" topLine="558" />
 		</Cursor>
 	</File>
-	<File name="../drivers/oss/oss_driver.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/sun/Makefile.am" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="17712" topLine="444" />
+			<Cursor1 position="246" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="../drivers/alsa_midi/a2j.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/alsa_midi/alsa_midi.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2337" topLine="56" />
+			<Cursor1 position="23463" topLine="810" />
 		</Cursor>
 	</File>
-	<File name="../drivers/am/alsa_rawmidi.c" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../jackd/jackd.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="7736" topLine="334" />
+			<Cursor1 position="10847" topLine="351" />
 		</Cursor>
 	</File>
-	<File name="../AUTHORS" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../drivers/freebob/freebob_driver.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2313" topLine="53" />
+			<Cursor1 position="29992" topLine="1037" />
+		</Cursor>
+	</File>
+	<File name="../drivers/dummy/dummy_driver.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="398" topLine="8" />
 		</Cursor>
 	</File>
-	<File name="../drivers/dummy/dummy_driver.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="../libjack/thread.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1252" topLine="21" />
+			<Cursor1 position="6722" topLine="268" />
+		</Cursor>
+	</File>
+	<File name="../drivers/am/alsa_seqmidi.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="15067" topLine="601" />
 		</Cursor>
 	</File>
 </CodeBlocks_layout_file>
diff --git a/drivers/iio/iio_driver.C b/drivers/iio/iio_driver.C
index fda1db6..05800f3 100644
--- a/drivers/iio/iio_driver.C
+++ b/drivers/iio/iio_driver.C
@@ -24,6 +24,7 @@
 #include <IIO/IIO.H>
 
 #include <values.h>
+#define __STDC_FORMAT_MACROS
 #include <inttypes.h>
 extern "C" {
 #include "iio_driver.h"
@@ -33,6 +34,8 @@ extern "C" {
 #define IIO_DEFAULT_CHIP "AD7476A" ///< The default IIO recording chip to look for.
 #define IIO_DEFAULT_READ_FS 1.e6 ///< The default IIO sample rate for the default chip.
 #define IIO_DEFAULT_PERIOD_SIZE 3000 ///< The default period size is in the ms range
+#define IIO_DEFAULT_CAPUTURE_PORT_COUNT MAXINT ///< The default number of capture ports is exceedingly big, trimmed down to a realistic size in driver_initialize
+#define IIO_SAFETY_FACTOR 2./3. ///< The default safety factor, allow consumption of this fraction of the available DMA buffer before we don't allow the driver to continue.
 
 //#define IIO_DRIVER_N_PARAMS	2
 //const static jack_driver_param_desc_t iio_params[IIO_DRIVER_N_PARAMS] = {
@@ -57,19 +60,54 @@ extern "C" {
 //};
 
 static int iio_driver_attach (iio_driver_t *driver, jack_engine_t *engine) {
-    //return jack_activate (driver->client);
-    return 0;
+    IIO *iio = static_cast<IIO *>(driver->IIO_devices);
+    int ret=iio->open(); // try to open all IIO devices
+    if (ret!=NO_ERROR)
+        return ret;
+
+    return jack_activate (driver->client);
 }
 
 static int iio_driver_detach (iio_driver_t *driver, jack_engine_t *engine) {
+    static_cast<IIO *>(driver->IIO_devices)->close(); // close the IIO system
+
+    if (driver->engine == 0) {
+		return -1;
+    }
+
+    for (JSList *node = driver->capture_ports; node; node = jack_slist_next(node)) {
+		jack_port_unregister(driver->client, ((jack_port_t *) node->data));
+    }
+
+    jack_slist_free(driver->capture_ports);
+    driver->capture_ports = 0;
+
+    for (JSList *node = driver->playback_ports; node; node = jack_slist_next(node)) {
+		jack_port_unregister(driver->client, ((jack_port_t *) node->data));
+    }
+
+    jack_slist_free(driver->playback_ports);
+    driver->playback_ports = 0;
+
+    driver->engine = 0;
     return 0;
 }
 
 static int iio_driver_start (iio_driver_t *driver) {
+    cout<<"iio_driver_start::   enabling IIO : enable(true)"<<endl;
+    static_cast<IIO *>(driver->IIO_devices)->enable(true); // start the DMA
+
+#ifdef HAVE_CLOCK_GETTIME
+	driver->next_wakeup.tv_sec = 0;
+#else
+	driver->next_time = 0;
+#endif
     return 0;
 }
 
 static int iio_driver_stop (iio_driver_t *driver) {
+    cout<<"iio_driver_start:: disabling IIO : enable(false)"<<endl;
+    static_cast<IIO *>(driver->IIO_devices)->enable(false); // stop the DMA
     return 0;
 }
 
@@ -88,7 +126,55 @@ static int iio_driver_null_cycle (iio_driver_t *driver, jack_nframes_t nframes)
     return 0;
 }
 
+/** The driver_wait function to work out if we have used more time then available to process one cycle.
+*/
+static jack_nframes_t iio_driver_wait(iio_driver_t *driver, int extra_fd, int *status, float *delayed_usecs){
+    float maxDelayTime=(IIO_SAFETY_FACTOR*driver->maxDelayUSecs); // this driver can handle this much delay between reads.
+	*status = 0;
+
+	jack_time_t now = driver->engine->get_microseconds();
+
+	if (driver->next_time < now)
+		if (driver->next_time == 0) /* first time through */
+			driver->next_time = now + driver->wait_time;
+		else
+            if ((now - driver->last_wait_ust) > maxDelayTime) { /* xrun */
+                jack_error("**** iio: xrun of %ju usec", (uintmax_t)now - driver->next_time);
+                driver->next_time = now + driver->wait_time;
+                *status=-1; // xruns are fatal
+            } else /* late, but handled by our "buffer" */
+                driver->next_time += driver->wait_time;
+	else {
+		jack_time_t wait = driver->next_time - now;
+		struct timespec ts = { .tv_sec = (time_t)wait / (time_t)1000000, .tv_nsec = ((time_t)wait % (time_t)1000000) * 1000 };
+		nanosleep(&ts,NULL);
+		driver->next_time += driver->wait_time;
+	}
+
+    driver->last_wait_ust = driver->engine->get_microseconds(); // remember the time now
+	driver->engine->transport_cycle_start (driver->engine, driver->last_wait_ust);
+
+	*delayed_usecs = 0;
+	return driver->period_size;
+}
+
 static int iio_driver_run_cycle (iio_driver_t *driver) {
+	int wait_status;
+	float delayed_usecs;
+
+	jack_nframes_t nframes = iio_driver_wait(driver, -1, &wait_status, &delayed_usecs);
+	if (nframes == 0) {
+		/* we detected an xrun and restarted: notify clients about the delay. */
+		driver->engine->delay(driver->engine, delayed_usecs);
+		return 0;
+	}
+
+	if (wait_status == 0)
+		return driver->engine->run_cycle(driver->engine, nframes, delayed_usecs);
+
+	if (wait_status < 0)
+		return -1;
+	else
 		return 0;
 }
 
@@ -101,7 +187,29 @@ jack_time_t getUSecs(jack_nframes_t nframes, jack_nframes_t fs) {
     return (jack_time_t) floor((((float) nframes) / fs) * 1000000.0f);
 }
 
+/**
+*/
 static int iio_driver_bufsize (iio_driver_t *driver, jack_nframes_t nframes) {
+    // Check we aren't exceeding the safety margin for the available DMA buffer ...
+    float requestedUS=(float)nframes*(float)driver->sample_rate/1.e6;
+    if (requestedUS>(IIO_SAFETY_FACTOR*driver->maxDelayUSecs)){
+        jack_info("Bufsize requested of duration %.3f us which is larger the the plausible buffer size of %.3f us.", requestedUS, (IIO_SAFETY_FACTOR*driver->maxDelayUSecs));
+        return -1;
+    }
+
+    // Check that the read array is large enough to handle nframes and if not, then resize ...
+    Eigen::Array<unsigned short int, Eigen::Dynamic, Eigen::Dynamic> *data = static_cast<Eigen::Array<unsigned short int, Eigen::Dynamic, Eigen::Dynamic> *>(driver->data);
+    IIO *iio = static_cast<IIO *>(driver->IIO_devices);
+    int N=iio->getReadArraySampleCount(*data);
+    if (N<nframes){ // if it is smaller then nframes then resize
+        int ret=iio->getReadArray(driver->period_size, *data); // resize the array to be able to read enough memory
+        if (ret!=NO_ERROR) {
+            jack_info("iio::getReadArray couldn't extend the data buffer, indicating the problem.");
+            return -1;
+        }
+    }
+
+    // all good, adjust the new variables...
     driver->period_size = nframes;
     driver->period_usecs = driver->wait_time = getUSecs(nframes, driver->sample_rate);
 
@@ -114,9 +222,25 @@ static int iio_driver_bufsize (iio_driver_t *driver, jack_nframes_t nframes) {
     return 0;
 }
 
+/** free all memory allocated by a driver instance
+*/
+static void iio_driver_delete(iio_driver_t * driver){
+    IIO *iio = static_cast<IIO *>(driver->IIO_devices);
+    if (iio)
+        delete iio;
+    driver->IIO_devices=NULL;
+    Eigen::Array<unsigned short int, Eigen::Dynamic, Eigen::Dynamic> *data = static_cast<Eigen::Array<unsigned short int, Eigen::Dynamic, Eigen::Dynamic> *>(driver->data);
+    if (data)
+        delete data;
+    driver->data=NULL;
+    free(driver);
+}
+
 jack_driver_t *driver_initialize (jack_client_t *client, const JSList * params) {
     IIO *iio = NULL;
     iio_driver_t *driver = (iio_driver_t *) calloc (1, sizeof (iio_driver_t));
+    driver->IIO_devices=NULL; // indicate that the iio class hasn't been created yet
+    driver->data=NULL; // indicate that the iio data matrix hasn't been created yet.
 
     if (driver) {
         jack_driver_nt_init((jack_driver_nt_t *) driver);
@@ -138,9 +262,7 @@ jack_driver_t *driver_initialize (jack_client_t *client, const JSList * params)
         driver->sample_rate = IIO_DEFAULT_READ_FS; // IIO sample rate is fixed.
         driver->period_size = IIO_DEFAULT_PERIOD_SIZE;
 
-        driver->period_usecs = driver->wait_time = getUSecs(driver->period_size, driver->sample_rate);
-
-        driver->capture_channels  = MAXINT; // The default number of physical input channels - a very large number, to be reduced.
+        driver->capture_channels  = IIO_DEFAULT_CAPUTURE_PORT_COUNT; // The default number of physical input channels - a very large number, to be reduced.
         driver->capture_ports     = NULL;
         driver->playback_channels = 0; // currently doesn't support playback.
         driver->playback_ports    = NULL;
@@ -162,6 +284,10 @@ jack_driver_t *driver_initialize (jack_client_t *client, const JSList * params)
                 case 'i': // we are specifying the number of capture channels
                     driver->capture_channels = param->value.ui;
                     break;
+                case 'p':
+                  driver->period_size = param->value.ui;
+                  break;
+
                 }
                 pnode = jack_slist_next(pnode);
             }
@@ -170,23 +296,96 @@ jack_driver_t *driver_initialize (jack_client_t *client, const JSList * params)
 
             iio->printInfo(); // print out detail about the devices which were found ...
 
+            // Find the maximum allowable delay and check whether the desired period is within the limit, otherwise report the error.
+            driver->period_usecs = driver->wait_time = getUSecs(driver->period_size, driver->sample_rate);
+            driver->maxDelayUSecs=(double)iio->getChannelBufferCnt()*driver->sample_rate/1.e6; // find the duration (in us) each channel can buffer
+
+            bool bufferSizeOK=true;
+            if (driver->period_usecs>(IIO_SAFETY_FACTOR*driver->maxDelayUSecs)){
+                jack_info("iio driver requires a wait time/period of %.3f us, however the maximum buffer is %.3f us, which is more then the safety factor of %.2f.\nIndicating the problem.", driver->wait_time, driver->maxDelayUSecs, IIO_SAFETY_FACTOR);
+                bufferSizeOK=false; // indicate the error
+            }
+
+            // Try to create the data buffer and store it in the driver, if a problem is encountered, then report the error.
+            bool dataCreationOK=true;
+            Eigen::Array<unsigned short int, Eigen::Dynamic, Eigen::Dynamic> *data = new Eigen::Array<unsigned short int, Eigen::Dynamic, Eigen::Dynamic>;
+            if (data)
+                driver->data=data;
+                int ret=iio->getReadArray(driver->period_size, *data); // resize the array to be able to read enough memory
+                if (ret!=NO_ERROR) {
+                    jack_info("iio::getReadArray couldn't create the data buffer, indicating the problem.");
+                    dataCreationOK=false;
+                }
+
+            else {
+                jack_info("iio driver couldn't create the data buffer, indicating the problem.");
+                dataCreationOK=false;
+            }
+
             // if the available number of ports is less then the requested number, then restrict to the number of physical ports.
             if (iio->getChCnt()<driver->capture_channels)
                 driver->capture_channels=iio->getChCnt();
 
             string name("iio_pcm");
-            //jack_info("created iio driver ... %s|%" PRIu32 "|%" PRIu32 "|%lu|%u|%u", name.c_str(), driver->sample_rate, driver->period_size, driver->wait_time, driver->capture_channels, driver->playback_channels);
-
+            if ((driver->capture_channels!=0 || driver->playback_channels!=0) && bufferSizeOK){
+                jack_info("created iio driver ... %s|%" PRIu32 "|%" PRIu32 "|%lu|%u|%u", name.c_str(), driver->sample_rate, driver->period_size, driver->wait_time, driver->capture_channels, driver->playback_channels);
                 return (jack_driver_t *) driver;
+            }
+            // if we get here without returning we have a problem ...
+            if (bufferSizeOK && dataCreationOK) // if the buffer size and the data malloc aren't the problem, then we can't find any devices.
+                jack_info("couldn't find any iio devices with the chip name : %s", chipName.c_str());
         } else
             jack_error("iio driver_initialise: new IIO failed: %s: %s@%i", strerror(errno), __FILE__, __LINE__);
     } else
         jack_error("iio driver_initialise: iio_driver_t malloc() failed: %s: %s@%i", strerror(errno), __FILE__, __LINE__);
 
     // if we get here, there was a problem.
-    if (driver)
-        free(driver);
-    if (iio)
-        delete iio;
+    iio_driver_delete((iio_driver_t *) driver);
     return NULL;
 }
+
+jack_driver_desc_t *driver_get_descriptor () {
+	jack_driver_desc_t * desc;
+	jack_driver_param_desc_t * params;
+	unsigned int i;
+
+	desc = calloc (1, sizeof (jack_driver_desc_t));
+	strcpy (desc->name, "iio");
+	desc->nparams = 3;
+
+	params = calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
+
+	i = 0;
+	strcpy (params[i].name, "chip");
+	params[i].character  = 'C';
+	params[i].type       = JackDriverParamString;
+	strcpy (params[i].value.str, IIO_DEFAULT_CHIP);
+	strcpy (params[i].short_desc, "The name of the chip to search for in the IIO devices");
+	strcpy (params[i].long_desc, params[i].short_desc);
+
+	i++;
+	strcpy (params[i].name, "capture");
+	params[i].character  = 'i';
+	params[i].type       = JackDriverParamUInt;
+	params[i].value.ui   = IIO_DEFAULT_CAPUTURE_PORT_COUNT;
+	strcpy (params[i].short_desc, "Provide capture ports.");
+	strcpy (params[i].long_desc, params[i].short_desc);
+
+	i++;
+	strcpy (params[i].name, "period");
+	params[i].character  = 'p';
+	params[i].type       = JackDriverParamUInt;
+	params[i].value.ui   = 1024U;
+	strcpy (params[i].short_desc, "Frames per period");
+	strcpy (params[i].long_desc, params[i].short_desc);
+
+	desc->params = params;
+
+	return desc;
+}
+
+void driver_finish (jack_driver_t *driver){
+    iio_driver_delete((iio_driver_t *) driver);
+}
+
+const char driver_client_name[] = "iio_pcm";
diff --git a/drivers/iio/iio_driver.h b/drivers/iio/iio_driver.h
index 9bf2aea..d067c76 100644
--- a/drivers/iio/iio_driver.h
+++ b/drivers/iio/iio_driver.h
@@ -38,7 +38,7 @@ typedef struct _iio_driver {
 //	unsigned int nperiods;
 	unsigned int capture_channels;
 	unsigned int playback_channels;
-//
+
 //	char *indev;
 //	char *outdev;
 //	int infd;
@@ -55,12 +55,22 @@ typedef struct _iio_driver {
 
     jack_nframes_t  sample_rate; ///< The sample rate of the IIO chip.
     unsigned long   wait_time; ///< The time to wait between calls.
+#ifdef HAVE_CLOCK_GETTIME
+    struct timespec next_wakeup;
+#else
+    jack_time_t     next_time;
+#endif
 
     void *IIO_devices; ///< The IIO C++ class maintaining all devices with a particular chip name.
+    float maxDelayUSecs; ///< The maximum number of micro seconds the buffer can hold
+    void *data; ///< The data read in from the IIO devices is stored here.
 } iio_driver_t;
 
 /** Function called by jack to init. the IIO driver, possibly passing in variables.
 */
 jack_driver_t *driver_initialize (jack_client_t *client, const JSList * params);
+jack_driver_desc_t *driver_get_descriptor();
+void driver_finish (jack_driver_t *driver);
+extern const char driver_client_name[];
 #endif
 
diff --git a/tools b/tools
index 8461ac0..ff8fdb5 160000
--- a/tools
+++ b/tools
@@ -1 +1 @@
-Subproject commit 8461ac0d4da80037f855956d39527d2976ed363c
+Subproject commit ff8fdb5af5f2761443498caa338700e64b4e781b
-- 
1.8.3.2
PrevNext  Index

1392326362.13769_0.ltw:2,a <1392326321-3699-3-git-send-email-flatmax at flatmax dot org>