gpio-lineevent-data-read.rst 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. _GPIO_LINEEVENT_DATA_READ:
  3. ************************
  4. GPIO_LINEEVENT_DATA_READ
  5. ************************
  6. .. warning::
  7. This ioctl is part of chardev_v1.rst and is obsoleted by
  8. gpio-v2-line-event-read.rst.
  9. Name
  10. ====
  11. GPIO_LINEEVENT_DATA_READ - Read edge detection events from a line event.
  12. Synopsis
  13. ========
  14. ``int read(int event_fd, void *buf, size_t count)``
  15. Arguments
  16. =========
  17. ``event_fd``
  18. The file descriptor of the GPIO character device, as returned in the
  19. :c:type:`request.fd<gpioevent_request>` by gpio-get-lineevent-ioctl.rst.
  20. ``buf``
  21. The buffer to contain the :c:type:`events<gpioevent_data>`.
  22. ``count``
  23. The number of bytes available in ``buf``, which must be at
  24. least the size of a :c:type:`gpioevent_data`.
  25. Description
  26. ===========
  27. Read edge detection events for a line from a line event.
  28. Edge detection must be enabled for the input line using either
  29. ``GPIOEVENT_REQUEST_RISING_EDGE`` or ``GPIOEVENT_REQUEST_FALLING_EDGE``, or
  30. both. Edge events are then generated whenever edge interrupts are detected on
  31. the input line.
  32. Edges are defined in terms of changes to the logical line value, so an inactive
  33. to active transition is a rising edge. If ``GPIOHANDLE_REQUEST_ACTIVE_LOW`` is
  34. set then logical polarity is the opposite of physical polarity, and
  35. ``GPIOEVENT_REQUEST_RISING_EDGE`` then corresponds to a falling physical edge.
  36. The kernel captures and timestamps edge events as close as possible to their
  37. occurrence and stores them in a buffer from where they can be read by
  38. userspace at its convenience using `read()`.
  39. The source of the clock for :c:type:`event.timestamp<gpioevent_data>` is
  40. ``CLOCK_MONOTONIC``, except for kernels earlier than Linux 5.7 when it was
  41. ``CLOCK_REALTIME``. There is no indication in the :c:type:`gpioevent_data`
  42. as to which clock source is used, it must be determined from either the kernel
  43. version or sanity checks on the timestamp itself.
  44. Events read from the buffer are always in the same order that they were
  45. detected by the kernel.
  46. The size of the kernel event buffer is fixed at 16 events.
  47. The buffer may overflow if bursts of events occur quicker than they are read
  48. by userspace. If an overflow occurs then the most recent event is discarded.
  49. Overflow cannot be detected from userspace.
  50. To minimize the number of calls required to copy events from the kernel to
  51. userspace, `read()` supports copying multiple events. The number of events
  52. copied is the lower of the number available in the kernel buffer and the
  53. number that will fit in the userspace buffer (``buf``).
  54. The `read()` will block if no event is available and the ``event_fd`` has not
  55. been set **O_NONBLOCK**.
  56. The presence of an event can be tested for by checking that the ``event_fd`` is
  57. readable using `poll()` or an equivalent.
  58. Return Value
  59. ============
  60. On success the number of bytes read, which will be a multiple of the size of
  61. a :c:type:`gpio_lineevent_data` event.
  62. On error -1 and the ``errno`` variable is set appropriately.
  63. Common error codes are described in error-codes.rst.