cec-ioc-receive.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. .. -*- coding: utf-8; mode: rst -*-
  2. .. _CEC_TRANSMIT:
  3. .. _CEC_RECEIVE:
  4. ***********************************
  5. ioctls CEC_RECEIVE and CEC_TRANSMIT
  6. ***********************************
  7. Name
  8. ====
  9. CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
  10. Synopsis
  11. ========
  12. .. c:function:: int ioctl( int fd, CEC_RECEIVE, struct cec_msg *argp )
  13. :name: CEC_RECEIVE
  14. .. c:function:: int ioctl( int fd, CEC_TRANSMIT, struct cec_msg *argp )
  15. :name: CEC_TRANSMIT
  16. Arguments
  17. =========
  18. ``fd``
  19. File descriptor returned by :c:func:`open() <cec-open>`.
  20. ``argp``
  21. Pointer to struct cec_msg.
  22. Description
  23. ===========
  24. .. note::
  25. This documents the proposed CEC API. This API is not yet finalized
  26. and is currently only available as a staging kernel module.
  27. To receive a CEC message the application has to fill in the
  28. ``timeout`` field of struct :c:type:`cec_msg` and pass it to
  29. :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  30. If the file descriptor is in non-blocking mode and there are no received
  31. messages pending, then it will return -1 and set errno to the ``EAGAIN``
  32. error code. If the file descriptor is in blocking mode and ``timeout``
  33. is non-zero and no message arrived within ``timeout`` milliseconds, then
  34. it will return -1 and set errno to the ``ETIMEDOUT`` error code.
  35. A received message can be:
  36. 1. a message received from another CEC device (the ``sequence`` field will
  37. be 0).
  38. 2. the result of an earlier non-blocking transmit (the ``sequence`` field will
  39. be non-zero).
  40. To send a CEC message the application has to fill in the struct
  41. :c:type:` cec_msg` and pass it to :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
  42. The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
  43. ``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
  44. queue, then it will return -1 and set errno to the ``EBUSY`` error code.
  45. The transmit queue has enough room for 18 messages (about 1 second worth
  46. of 2-byte messages). Note that the CEC kernel framework will also reply
  47. to core messages (see :ref:cec-core-processing), so it is not a good
  48. idea to fully fill up the transmit queue.
  49. If the file descriptor is in non-blocking mode then the transmit will
  50. return 0 and the result of the transmit will be available via
  51. :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished
  52. (including waiting for a reply, if requested).
  53. The ``sequence`` field is filled in for every transmit and this can be
  54. checked against the received messages to find the corresponding transmit
  55. result.
  56. .. tabularcolumns:: |p{1.0cm}|p{3.5cm}|p{13.0cm}|
  57. .. c:type:: cec_msg
  58. .. cssclass:: longtable
  59. .. flat-table:: struct cec_msg
  60. :header-rows: 0
  61. :stub-columns: 0
  62. :widths: 1 1 16
  63. - .. row 1
  64. - __u64
  65. - ``tx_ts``
  66. - Timestamp in ns of when the last byte of the message was transmitted.
  67. The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
  68. the same clock from userspace use :c:func:`clock_gettime`.
  69. - .. row 2
  70. - __u64
  71. - ``rx_ts``
  72. - Timestamp in ns of when the last byte of the message was received.
  73. The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
  74. the same clock from userspace use :c:func:`clock_gettime`.
  75. - .. row 3
  76. - __u32
  77. - ``len``
  78. - The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
  79. by the application. The driver will fill this in for
  80. :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
  81. filled in by the driver with the length of the reply message if ``reply`` was set.
  82. - .. row 4
  83. - __u32
  84. - ``timeout``
  85. - The timeout in milliseconds. This is the time the device will wait
  86. for a message to be received before timing out. If it is set to 0,
  87. then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  88. If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
  89. then it will be replaced by 1000 if the ``reply`` is non-zero or
  90. ignored if ``reply`` is 0.
  91. - .. row 5
  92. - __u32
  93. - ``sequence``
  94. - A non-zero sequence number is automatically assigned by the CEC framework
  95. for all transmitted messages. It is used by the CEC framework when it queues
  96. the transmit result (when transmit was called in non-blocking mode). This
  97. allows the application to associate the received message with the original
  98. transmit.
  99. - .. row 6
  100. - __u32
  101. - ``flags``
  102. - Flags. No flags are defined yet, so set this to 0.
  103. - .. row 7
  104. - __u8
  105. - ``tx_status``
  106. - The status bits of the transmitted message. See
  107. :ref:`cec-tx-status` for the possible status values. It is 0 if
  108. this messages was received, not transmitted.
  109. - .. row 8
  110. - __u8
  111. - ``msg[16]``
  112. - The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
  113. application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  114. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
  115. the payload of the reply message if ``timeout`` was set.
  116. - .. row 8
  117. - __u8
  118. - ``reply``
  119. - Wait until this message is replied. If ``reply`` is 0 and the
  120. ``timeout`` is 0, then don't wait for a reply but return after
  121. transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  122. The case where ``reply`` is 0 (this is the opcode for the Feature Abort
  123. message) and ``timeout`` is non-zero is specifically allowed to make it
  124. possible to send a message and wait up to ``timeout`` milliseconds for a
  125. Feature Abort reply. In this case ``rx_status`` will either be set
  126. to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
  127. :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.
  128. - .. row 9
  129. - __u8
  130. - ``rx_status``
  131. - The status bits of the received message. See
  132. :ref:`cec-rx-status` for the possible status values. It is 0 if
  133. this message was transmitted, not received, unless this is the
  134. reply to a transmitted message. In that case both ``rx_status``
  135. and ``tx_status`` are set.
  136. - .. row 10
  137. - __u8
  138. - ``tx_status``
  139. - The status bits of the transmitted message. See
  140. :ref:`cec-tx-status` for the possible status values. It is 0 if
  141. this messages was received, not transmitted.
  142. - .. row 11
  143. - __u8
  144. - ``tx_arb_lost_cnt``
  145. - A counter of the number of transmit attempts that resulted in the
  146. Arbitration Lost error. This is only set if the hardware supports
  147. this, otherwise it is always 0. This counter is only valid if the
  148. :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.
  149. - .. row 12
  150. - __u8
  151. - ``tx_nack_cnt``
  152. - A counter of the number of transmit attempts that resulted in the
  153. Not Acknowledged error. This is only set if the hardware supports
  154. this, otherwise it is always 0. This counter is only valid if the
  155. :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.
  156. - .. row 13
  157. - __u8
  158. - ``tx_low_drive_cnt``
  159. - A counter of the number of transmit attempts that resulted in the
  160. Arbitration Lost error. This is only set if the hardware supports
  161. this, otherwise it is always 0. This counter is only valid if the
  162. :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.
  163. - .. row 14
  164. - __u8
  165. - ``tx_error_cnt``
  166. - A counter of the number of transmit errors other than Arbitration
  167. Lost or Not Acknowledged. This is only set if the hardware
  168. supports this, otherwise it is always 0. This counter is only
  169. valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.
  170. .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
  171. .. _cec-tx-status:
  172. .. flat-table:: CEC Transmit Status
  173. :header-rows: 0
  174. :stub-columns: 0
  175. :widths: 3 1 16
  176. - .. _`CEC-TX-STATUS-OK`:
  177. - ``CEC_TX_STATUS_OK``
  178. - 0x01
  179. - The message was transmitted successfully. This is mutually
  180. exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`. Other bits can still
  181. be set if earlier attempts met with failure before the transmit
  182. was eventually successful.
  183. - .. _`CEC-TX-STATUS-ARB-LOST`:
  184. - ``CEC_TX_STATUS_ARB_LOST``
  185. - 0x02
  186. - CEC line arbitration was lost.
  187. - .. _`CEC-TX-STATUS-NACK`:
  188. - ``CEC_TX_STATUS_NACK``
  189. - 0x04
  190. - Message was not acknowledged.
  191. - .. _`CEC-TX-STATUS-LOW-DRIVE`:
  192. - ``CEC_TX_STATUS_LOW_DRIVE``
  193. - 0x08
  194. - Low drive was detected on the CEC bus. This indicates that a
  195. follower detected an error on the bus and requests a
  196. retransmission.
  197. - .. _`CEC-TX-STATUS-ERROR`:
  198. - ``CEC_TX_STATUS_ERROR``
  199. - 0x10
  200. - Some error occurred. This is used for any errors that do not fit
  201. the previous two, either because the hardware could not tell which
  202. error occurred, or because the hardware tested for other
  203. conditions besides those two.
  204. - .. _`CEC-TX-STATUS-MAX-RETRIES`:
  205. - ``CEC_TX_STATUS_MAX_RETRIES``
  206. - 0x20
  207. - The transmit failed after one or more retries. This status bit is
  208. mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`. Other bits can still
  209. be set to explain which failures were seen.
  210. .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
  211. .. _cec-rx-status:
  212. .. flat-table:: CEC Receive Status
  213. :header-rows: 0
  214. :stub-columns: 0
  215. :widths: 3 1 16
  216. - .. _`CEC-RX-STATUS-OK`:
  217. - ``CEC_RX_STATUS_OK``
  218. - 0x01
  219. - The message was received successfully.
  220. - .. _`CEC-RX-STATUS-TIMEOUT`:
  221. - ``CEC_RX_STATUS_TIMEOUT``
  222. - 0x02
  223. - The reply to an earlier transmitted message timed out.
  224. - .. _`CEC-RX-STATUS-FEATURE-ABORT`:
  225. - ``CEC_RX_STATUS_FEATURE_ABORT``
  226. - 0x04
  227. - The message was received successfully but the reply was
  228. ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
  229. was the reply to an earlier transmitted message.
  230. Return Value
  231. ============
  232. On success 0 is returned, on error -1 and the ``errno`` variable is set
  233. appropriately. The generic error codes are described at the
  234. :ref:`Generic Error Codes <gen-errors>` chapter.