buffers.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. =======
  2. Buffers
  3. =======
  4. * struct iio_buffer — general buffer structure
  5. * :c:func:`iio_validate_scan_mask_onehot` — Validates that exactly one channel
  6. is selected
  7. * :c:func:`iio_buffer_get` — Grab a reference to the buffer
  8. * :c:func:`iio_buffer_put` — Release the reference to the buffer
  9. The Industrial I/O core offers a way for continuous data capture based on a
  10. trigger source. Multiple data channels can be read at once from
  11. :file:`/dev/iio:device{X}` character device node, thus reducing the CPU load.
  12. IIO buffer sysfs interface
  13. ==========================
  14. An IIO buffer has an associated attributes directory under
  15. :file:`/sys/bus/iio/iio:device{X}/buffer/*`. Here are some of the existing
  16. attributes:
  17. * :file:`length`, the total number of data samples (capacity) that can be
  18. stored by the buffer.
  19. * :file:`enable`, activate buffer capture.
  20. IIO buffer setup
  21. ================
  22. The meta information associated with a channel reading placed in a buffer is
  23. called a scan element. The important bits configuring scan elements are
  24. exposed to userspace applications via the
  25. :file:`/sys/bus/iio/iio:device{X}/scan_elements/` directory. This directory contains
  26. attributes of the following form:
  27. * :file:`enable`, used for enabling a channel. If and only if its attribute
  28. is non *zero*, then a triggered capture will contain data samples for this
  29. channel.
  30. * :file:`index`, the scan_index of the channel.
  31. * :file:`type`, description of the scan element data storage within the buffer
  32. and hence the form in which it is read from user space.
  33. Format is [be|le]:[s|u]bits/storagebits[Xrepeat][>>shift] .
  34. * *be* or *le*, specifies big or little endian.
  35. * *s* or *u*, specifies if signed (2's complement) or unsigned.
  36. * *bits*, is the number of valid data bits.
  37. * *storagebits*, is the number of bits (after padding) that it occupies in the
  38. buffer.
  39. * *repeat*, specifies the number of bits/storagebits repetitions. When the
  40. repeat element is 0 or 1, then the repeat value is omitted.
  41. * *shift*, if specified, is the shift that needs to be applied prior to
  42. masking out unused bits.
  43. For example, a driver for a 3-axis accelerometer with 12 bit resolution where
  44. data is stored in two 8-bits registers as follows::
  45. 7 6 5 4 3 2 1 0
  46. +---+---+---+---+---+---+---+---+
  47. |D3 |D2 |D1 |D0 | X | X | X | X | (LOW byte, address 0x06)
  48. +---+---+---+---+---+---+---+---+
  49. 7 6 5 4 3 2 1 0
  50. +---+---+---+---+---+---+---+---+
  51. |D11|D10|D9 |D8 |D7 |D6 |D5 |D4 | (HIGH byte, address 0x07)
  52. +---+---+---+---+---+---+---+---+
  53. will have the following scan element type for each axis::
  54. $ cat /sys/bus/iio/devices/iio:device0/scan_elements/in_accel_y_type
  55. le:s12/16>>4
  56. A user space application will interpret data samples read from the buffer as
  57. two byte little endian signed data, that needs a 4 bits right shift before
  58. masking out the 12 valid bits of data.
  59. For implementing buffer support a driver should initialize the following
  60. fields in iio_chan_spec definition::
  61. struct iio_chan_spec {
  62. /* other members */
  63. int scan_index
  64. struct {
  65. char sign;
  66. u8 realbits;
  67. u8 storagebits;
  68. u8 shift;
  69. u8 repeat;
  70. enum iio_endian endianness;
  71. } scan_type;
  72. };
  73. The driver implementing the accelerometer described above will have the
  74. following channel definition::
  75. struct iio_chan_spec accel_channels[] = {
  76. {
  77. .type = IIO_ACCEL,
  78. .modified = 1,
  79. .channel2 = IIO_MOD_X,
  80. /* other stuff here */
  81. .scan_index = 0,
  82. .scan_type = {
  83. .sign = 's',
  84. .realbits = 12,
  85. .storagebits = 16,
  86. .shift = 4,
  87. .endianness = IIO_LE,
  88. },
  89. }
  90. /* similar for Y (with channel2 = IIO_MOD_Y, scan_index = 1)
  91. * and Z (with channel2 = IIO_MOD_Z, scan_index = 2) axis
  92. */
  93. }
  94. Here **scan_index** defines the order in which the enabled channels are placed
  95. inside the buffer. Channels with a lower **scan_index** will be placed before
  96. channels with a higher index. Each channel needs to have a unique
  97. **scan_index**.
  98. Setting **scan_index** to -1 can be used to indicate that the specific channel
  99. does not support buffered capture. In this case no entries will be created for
  100. the channel in the scan_elements directory.
  101. More details
  102. ============
  103. .. kernel-doc:: include/linux/iio/buffer.h
  104. .. kernel-doc:: drivers/iio/industrialio-buffer.c
  105. :export: