Back to home page

OSCL-LXR

 
 

    


0001 =================
0002 Triggered Buffers
0003 =================
0004 
0005 Now that we know what buffers and triggers are let's see how they work together.
0006 
0007 IIO triggered buffer setup
0008 ==========================
0009 
0010 * :c:func:`iio_triggered_buffer_setup` — Setup triggered buffer and pollfunc
0011 * :c:func:`iio_triggered_buffer_cleanup` — Free resources allocated by
0012   :c:func:`iio_triggered_buffer_setup`
0013 * struct iio_buffer_setup_ops — buffer setup related callbacks
0014 
0015 A typical triggered buffer setup looks like this::
0016 
0017     const struct iio_buffer_setup_ops sensor_buffer_setup_ops = {
0018       .preenable    = sensor_buffer_preenable,
0019       .postenable   = sensor_buffer_postenable,
0020       .postdisable  = sensor_buffer_postdisable,
0021       .predisable   = sensor_buffer_predisable,
0022     };
0023 
0024     irqreturn_t sensor_iio_pollfunc(int irq, void *p)
0025     {
0026         pf->timestamp = iio_get_time_ns((struct indio_dev *)p);
0027         return IRQ_WAKE_THREAD;
0028     }
0029 
0030     irqreturn_t sensor_trigger_handler(int irq, void *p)
0031     {
0032         u16 buf[8];
0033         int i = 0;
0034 
0035         /* read data for each active channel */
0036         for_each_set_bit(bit, active_scan_mask, masklength)
0037             buf[i++] = sensor_get_data(bit)
0038 
0039         iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp);
0040 
0041         iio_trigger_notify_done(trigger);
0042         return IRQ_HANDLED;
0043     }
0044 
0045     /* setup triggered buffer, usually in probe function */
0046     iio_triggered_buffer_setup(indio_dev, sensor_iio_polfunc,
0047                                sensor_trigger_handler,
0048                                sensor_buffer_setup_ops);
0049 
0050 The important things to notice here are:
0051 
0052 * :c:type:`iio_buffer_setup_ops`, the buffer setup functions to be called at
0053   predefined points in the buffer configuration sequence (e.g. before enable,
0054   after disable). If not specified, the IIO core uses the default
0055   iio_triggered_buffer_setup_ops.
0056 * **sensor_iio_pollfunc**, the function that will be used as top half of poll
0057   function. It should do as little processing as possible, because it runs in
0058   interrupt context. The most common operation is recording of the current
0059   timestamp and for this reason one can use the IIO core defined
0060   :c:func:`iio_pollfunc_store_time` function.
0061 * **sensor_trigger_handler**, the function that will be used as bottom half of
0062   the poll function. This runs in the context of a kernel thread and all the
0063   processing takes place here. It usually reads data from the device and
0064   stores it in the internal buffer together with the timestamp recorded in the
0065   top half.
0066 
0067 More details
0068 ============
0069 .. kernel-doc:: drivers/iio/buffer/industrialio-triggered-buffer.c