1<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Industrial I/O triggered buffers</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Industrial I/O driver developer's guide"><link rel="up" href="iiosubsys.html" title="Chapter 2. Industrial I/O core"><link rel="prev" href="API-struct-iio-trigger-ops.html" title="struct iio_trigger_ops"><link rel="next" href="API-iio-triggered-buffer-setup.html" title="iio_triggered_buffer_setup"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"> Industrial I/O triggered buffers </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-struct-iio-trigger-ops.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Industrial I/O core</th><td width="20%" align="right"> <a accesskey="n" href="API-iio-triggered-buffer-setup.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="iiotriggered_buffer"></a> Industrial I/O triggered buffers </h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="iiotriggered_buffer.html#iiotrigbufsetup"> IIO triggered buffer setup</a></span></dt></dl></div><p> 2 Now that we know what buffers and triggers are let's see how they 3 work together. 4 </p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="iiotrigbufsetup"></a> IIO triggered buffer setup</h3></div></div></div><div class="toc"><dl class="toc"><dt><span class="refentrytitle"><a href="API-iio-triggered-buffer-setup.html"><span class="phrase">iio_triggered_buffer_setup</span></a></span><span class="refpurpose"> — 5 Setup triggered buffer and pollfunc 6 </span></dt><dt><span class="refentrytitle"><a href="API-iio-triggered-buffer-cleanup.html"><span class="phrase">iio_triggered_buffer_cleanup</span></a></span><span class="refpurpose"> 7 Free resources allocated by iio_triggered_buffer_setup 8 </span></dt><dt><span class="refentrytitle"><a href="API-struct-iio-buffer-setup-ops.html"><span class="phrase">struct iio_buffer_setup_ops</span></a></span><span class="refpurpose"> — 9 buffer setup related callbacks 10 </span></dt></dl></div><p> 11 A typical triggered buffer setup looks like this: 12 </p><pre class="programlisting"> 13 const struct iio_buffer_setup_ops sensor_buffer_setup_ops = { 14 .preenable = sensor_buffer_preenable, 15 .postenable = sensor_buffer_postenable, 16 .postdisable = sensor_buffer_postdisable, 17 .predisable = sensor_buffer_predisable, 18 }; 19 20 irqreturn_t sensor_iio_pollfunc(int irq, void *p) 21 { 22 pf->timestamp = iio_get_time_ns(); 23 return IRQ_WAKE_THREAD; 24 } 25 26 irqreturn_t sensor_trigger_handler(int irq, void *p) 27 { 28 u16 buf[8]; 29 int i = 0; 30 31 /* read data for each active channel */ 32 for_each_set_bit(bit, active_scan_mask, masklength) 33 buf[i++] = sensor_get_data(bit) 34 35 iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp); 36 37 iio_trigger_notify_done(trigger); 38 return IRQ_HANDLED; 39 } 40 41 /* setup triggered buffer, usually in probe function */ 42 iio_triggered_buffer_setup(indio_dev, sensor_iio_polfunc, 43 sensor_trigger_handler, 44 sensor_buffer_setup_ops); 45 </pre><p> 46 </p> 47 The important things to notice here are: 48 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="function"> iio_buffer_setup_ops</code>, the buffer setup 49 functions to be called at predefined points in the buffer configuration 50 sequence (e.g. before enable, after disable). If not specified, the 51 IIO core uses the default <span class="type">iio_triggered_buffer_setup_ops</span>. 52 </li><li class="listitem"><code class="function">sensor_iio_pollfunc</code>, the function that 53 will be used as top half of poll function. It should do as little 54 processing as possible, because it runs in interrupt context. The most 55 common operation is recording of the current timestamp and for this reason 56 one can use the IIO core defined <code class="function">iio_pollfunc_store_time 57 </code> function. 58 </li><li class="listitem"><code class="function">sensor_trigger_handler</code>, the function that 59 will be used as bottom half of the poll function. This runs in the 60 context of a kernel thread and all the processing takes place here. 61 It usually reads data from the device and stores it in the internal 62 buffer together with the timestamp recorded in the top half. 63 </li></ul></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-struct-iio-trigger-ops.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="iiosubsys.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-iio-triggered-buffer-setup.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">struct iio_trigger_ops</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">iio_triggered_buffer_setup</span></td></tr></table></div></body></html> 64