cec-ioc-receive.rst 11 KB

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