brintos

brintos / linux-shallow public Read only

0
0
Text · 5.7 KiB · 9919e47 Raw
153 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3=============================4Industrial IIO device buffers5=============================6 71. Overview8===========9 10The Industrial I/O core offers a way for continuous data capture based on a11trigger source. Multiple data channels can be read at once from12``/dev/iio:deviceX`` character device node, thus reducing the CPU load.13 14Devices with buffer support feature an additional sub-directory in the15``/sys/bus/iio/devices/iio:deviceX/`` directory hierarchy, called bufferY, where16Y defaults to 0, for devices with a single buffer.17 182. Buffer attributes19====================20 21An IIO buffer has an associated attributes directory under22``/sys/bus/iio/iio:deviceX/bufferY/``. The attributes are described below.23 24``length``25----------26 27Read / Write attribute which states the total number of data samples (capacity)28that can be stored by the buffer.29 30``enable``31----------32 33Read / Write attribute which starts / stops the buffer capture. This file should34be written last, after length and selection of scan elements. Writing a non-zero35value may result in an error, such as EINVAL, if, for example, an unsupported36combination of channels is given.37 38``watermark``39-------------40 41Read / Write positive integer attribute specifying the maximum number of scan42elements to wait for.43 44Poll will block until the watermark is reached.45 46Blocking read will wait until the minimum between the requested read amount or47the low watermark is available.48 49Non-blocking read will retrieve the available samples from the buffer even if50there are less samples than the watermark level. This allows the application to51block on poll with a timeout and read the available samples after the timeout52expires and thus have a maximum delay guarantee.53 54Data available55--------------56 57Read-only attribute indicating the bytes of data available in the buffer. In the58case of an output buffer, this indicates the amount of empty space available to59write data to. In the case of an input buffer, this indicates the amount of data60available for reading.61 62Scan elements63-------------64 65The meta information associated with a channel data placed in a buffer is called66a scan element. The scan elements attributes are presented below.67 68**_en**69 70Read / Write attribute used for enabling a channel. If and only if its value71is non-zero, then a triggered capture will contain data samples for this72channel.73 74**_index**75 76Read-only unsigned integer attribute specifying the position of the channel in77the buffer. Note these are not dependent on what is enabled and may not be78contiguous. Thus for userspace to establish the full layout these must be used79in conjunction with all _en attributes to establish which channels are present,80and the relevant _type attributes to establish the data storage format.81 82**_type**83 84Read-only attribute containing the description of the scan element data storage85within the buffer and hence the form in which it is read from userspace. Format86is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift], where:87 88- **be** or **le** specifies big or little-endian.89- **s** or **u** specifies if signed (2's complement) or unsigned.90- **bits** is the number of valid data bits.91- **storagebits** is the number of bits (after padding) that it occupies in the92  buffer.93- **repeat** specifies the number of bits/storagebits repetitions. When the94  repeat element is 0 or 1, then the repeat value is omitted.95- **shift** if specified, is the shift that needs to be applied prior to96  masking out unused bits.97 98For example, a driver for a 3-axis accelerometer with 12-bit resolution where99data is stored in two 8-bit registers is as follows::100 101          7   6   5   4   3   2   1   0102        +---+---+---+---+---+---+---+---+103        |D3 |D2 |D1 |D0 | X | X | X | X | (LOW byte, address 0x06)104        +---+---+---+---+---+---+---+---+105 106          7   6   5   4   3   2   1   0107        +---+---+---+---+---+---+---+---+108        |D11|D10|D9 |D8 |D7 |D6 |D5 |D4 | (HIGH byte, address 0x07)109        +---+---+---+---+---+---+---+---+110 111will have the following scan element type for each axis:112 113.. code-block:: bash114 115        $ cat /sys/bus/iio/devices/iio:device0/buffer0/in_accel_y_type116        le:s12/16>>4117 118A userspace application will interpret data samples read from the buffer as119two-byte little-endian signed data, that needs a 4 bits right shift before120masking out the 12 valid bits of data.121 122It is also worth mentioning that the data in the buffer will be naturally123aligned, so the userspace application has to handle the buffers accordingly.124 125Take for example, a driver with four channels with the following description:126- channel0: index: 0, type: be:u16/16>>0127- channel1: index: 1, type: be:u32/32>>0128- channel2: index: 2, type: be:u32/32>>0129- channel3: index: 3, type: be:u64/64>>0130 131If all channels are enabled, the data will be aligned in the buffer as follows::132 133          0-1   2   3   4-7  8-11  12  13  14  15  16-23   -> buffer byte number134        +-----+---+---+-----+-----+---+---+---+---+-----+135        |CHN_0|PAD|PAD|CHN_1|CHN_2|PAD|PAD|PAD|PAD|CHN_3|  -> buffer content136        +-----+---+---+-----+-----+---+---+---+---+-----+137 138If only channel0 and channel3 are enabled, the data will be aligned in the139buffer as follows::140 141          0-1   2   3   4   5   6   7  8-15    -> buffer byte number142        +-----+---+---+---+---+---+---+-----+143        |CHN_0|PAD|PAD|PAD|PAD|PAD|PAD|CHN_3|  -> buffer content144        +-----+---+---+---+---+---+---+-----+145 146Typically the buffered data is found in raw format (unscaled with no offset147applied), however there are corner cases in which the buffered data may be found148in a processed form. Please note that these corner cases are not addressed by149this documentation.150 151Please see ``Documentation/ABI/testing/sysfs-bus-iio`` for a complete152description of the attributes.153