blob: ae5a39ade45ff588420bbd02c0325479f4dc82ff [file] [log] [blame]
Markus Heisere2460b12016-07-08 20:55:42 +02001.. -*- coding: utf-8; mode: rst -*-
2
Markus Heiser21c62692016-07-08 20:55:43 +02003.. _CEC_TRANSMIT:
4.. _CEC_RECEIVE:
Markus Heisere2460b12016-07-08 20:55:42 +02005
Hans Verkuil1267c602016-07-13 08:48:54 -03006***********************************
7ioctls CEC_RECEIVE and CEC_TRANSMIT
8***********************************
Markus Heisere2460b12016-07-08 20:55:42 +02009
Markus Heiser21c62692016-07-08 20:55:43 +020010Name
11====
Markus Heisere2460b12016-07-08 20:55:42 +020012
Markus Heiser21c62692016-07-08 20:55:43 +020013CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
Markus Heisere2460b12016-07-08 20:55:42 +020014
15
16Synopsis
17========
18
Markus Heiser21c62692016-07-08 20:55:43 +020019.. cpp:function:: int ioctl( int fd, int request, struct cec_msg *argp )
Markus Heisere2460b12016-07-08 20:55:42 +020020
21Arguments
22=========
23
24``fd``
25 File descriptor returned by :ref:`open() <cec-func-open>`.
26
27``request``
28 CEC_RECEIVE, CEC_TRANSMIT
29
30``argp``
31
32
33Description
34===========
35
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -030036.. note:: This documents the proposed CEC API. This API is not yet finalized
37 and is currently only available as a staging kernel module.
Markus Heisere2460b12016-07-08 20:55:42 +020038
39To receive a CEC message the application has to fill in the
Hans Verkuile5208ed2016-07-19 06:26:13 -030040``timeout`` field of :c:type:`struct cec_msg` and pass it to :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
Markus Heisere2460b12016-07-08 20:55:42 +020041If the file descriptor is in non-blocking mode and there are no received
Hans Verkuile5208ed2016-07-19 06:26:13 -030042messages pending, then it will return -1 and set errno to the ``EAGAIN``
Markus Heisere2460b12016-07-08 20:55:42 +020043error code. If the file descriptor is in blocking mode and ``timeout``
44is non-zero and no message arrived within ``timeout`` milliseconds, then
Hans Verkuile5208ed2016-07-19 06:26:13 -030045it will return -1 and set errno to the ``ETIMEDOUT`` error code.
46
47A received message can be:
48
491. a message received from another CEC device (the ``sequence`` field will
50 be 0).
512. the result of an earlier non-blocking transmit (the ``sequence`` field will
52 be non-zero).
Markus Heisere2460b12016-07-08 20:55:42 +020053
54To send a CEC message the application has to fill in the
Hans Verkuil1267c602016-07-13 08:48:54 -030055:c:type:`struct cec_msg` and pass it to
56:ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
Markus Heisere2460b12016-07-08 20:55:42 +020057``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
Hans Verkuile5208ed2016-07-19 06:26:13 -030058queue, then it will return -1 and set errno to the ``EBUSY`` error code.
59The transmit queue has enough room for 18 messages (about 1 second worth
60of 2-byte messages). Note that the CEC kernel framework will also reply
61to core messages (see :ref:cec-core-processing), so it is not a good
62idea to fully fill up the transmit queue.
63
64If the file descriptor is in non-blocking mode then the transmit will
65return 0 and the result of the transmit will be available via
66:ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished
67(including waiting for a reply, if requested).
68
69The ``sequence`` field is filled in for every transmit and this can be
70checked against the received messages to find the corresponding transmit
71result.
Markus Heisere2460b12016-07-08 20:55:42 +020072
73
74.. _cec-msg:
75
76.. flat-table:: struct cec_msg
77 :header-rows: 0
78 :stub-columns: 0
Mauro Carvalho Chehabb2a58432016-07-08 17:59:27 -030079 :widths: 1 1 16
Markus Heisere2460b12016-07-08 20:55:42 +020080
81
82 - .. row 1
83
84 - __u64
85
Hans Verkuild2cd6272016-07-12 15:07:44 -030086 - ``tx_ts``
Markus Heisere2460b12016-07-08 20:55:42 +020087
Hans Verkuild2cd6272016-07-12 15:07:44 -030088 - Timestamp in ns of when the last byte of the message was transmitted.
Hans Verkuile5208ed2016-07-19 06:26:13 -030089 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
90 the same clock from userspace use :c:func:`clock_gettime(2)`.
Markus Heisere2460b12016-07-08 20:55:42 +020091
92 - .. row 2
93
Hans Verkuild2cd6272016-07-12 15:07:44 -030094 - __u64
95
96 - ``rx_ts``
97
98 - Timestamp in ns of when the last byte of the message was received.
Hans Verkuile5208ed2016-07-19 06:26:13 -030099 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
100 the same clock from userspace use :c:func:`clock_gettime(2)`.
Hans Verkuild2cd6272016-07-12 15:07:44 -0300101
102 - .. row 3
103
Markus Heisere2460b12016-07-08 20:55:42 +0200104 - __u32
105
106 - ``len``
107
Hans Verkuil1267c602016-07-13 08:48:54 -0300108 - The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300109 by the application. The driver will fill this in for
Hans Verkuil1267c602016-07-13 08:48:54 -0300110 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
111 filled in by the driver with the length of the reply message if ``reply`` was set.
Markus Heisere2460b12016-07-08 20:55:42 +0200112
Hans Verkuild2cd6272016-07-12 15:07:44 -0300113 - .. row 4
Markus Heisere2460b12016-07-08 20:55:42 +0200114
115 - __u32
116
117 - ``timeout``
118
119 - The timeout in milliseconds. This is the time the device will wait
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300120 for a message to be received before timing out. If it is set to 0,
Hans Verkuil1267c602016-07-13 08:48:54 -0300121 then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
122 If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300123 then it will be replaced by 1000 if the ``reply`` is non-zero or
124 ignored if ``reply`` is 0.
Markus Heisere2460b12016-07-08 20:55:42 +0200125
Hans Verkuild2cd6272016-07-12 15:07:44 -0300126 - .. row 5
Markus Heisere2460b12016-07-08 20:55:42 +0200127
128 - __u32
129
130 - ``sequence``
131
Hans Verkuile5208ed2016-07-19 06:26:13 -0300132 - A non-zero sequence number is automatically assigned by the CEC framework
133 for all transmitted messages. It is used by the CEC framework when it queues
134 the transmit result (when transmit was called in non-blocking mode). This
135 allows the application to associate the received message with the original
136 transmit.
Markus Heisere2460b12016-07-08 20:55:42 +0200137
Hans Verkuild2cd6272016-07-12 15:07:44 -0300138 - .. row 6
Markus Heisere2460b12016-07-08 20:55:42 +0200139
140 - __u32
141
142 - ``flags``
143
144 - Flags. No flags are defined yet, so set this to 0.
145
Markus Heisere2460b12016-07-08 20:55:42 +0200146 - .. row 7
147
148 - __u8
149
150 - ``tx_status``
151
152 - The status bits of the transmitted message. See
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300153 :ref:`cec-tx-status` for the possible status values. It is 0 if
154 this messages was received, not transmitted.
Markus Heisere2460b12016-07-08 20:55:42 +0200155
156 - .. row 8
157
158 - __u8
159
Hans Verkuile5208ed2016-07-19 06:26:13 -0300160 - ``msg[16]``
Markus Heisere2460b12016-07-08 20:55:42 +0200161
Hans Verkuil1267c602016-07-13 08:48:54 -0300162 - The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
163 application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
164 For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
165 the payload of the reply message if ``timeout`` was set.
Markus Heisere2460b12016-07-08 20:55:42 +0200166
Hans Verkuild2cd6272016-07-12 15:07:44 -0300167 - .. row 8
Markus Heisere2460b12016-07-08 20:55:42 +0200168
169 - __u8
170
171 - ``reply``
172
173 - Wait until this message is replied. If ``reply`` is 0 and the
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300174 ``timeout`` is 0, then don't wait for a reply but return after
Hans Verkuile5208ed2016-07-19 06:26:13 -0300175 transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
176 The case where ``reply`` is 0 (this is the opcode for the Feature Abort
177 message) and ``timeout`` is non-zero is specifically allowed to make it
178 possible to send a message and wait up to ``timeout`` milliseconds for a
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300179 Feature Abort reply. In this case ``rx_status`` will either be set
Hans Verkuile5208ed2016-07-19 06:26:13 -0300180 to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
181 :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.
Markus Heisere2460b12016-07-08 20:55:42 +0200182
Hans Verkuild2cd6272016-07-12 15:07:44 -0300183 - .. row 9
184
185 - __u8
186
187 - ``rx_status``
188
189 - The status bits of the received message. See
190 :ref:`cec-rx-status` for the possible status values. It is 0 if
191 this message was transmitted, not received, unless this is the
192 reply to a transmitted message. In that case both ``rx_status``
193 and ``tx_status`` are set.
194
Markus Heisere2460b12016-07-08 20:55:42 +0200195 - .. row 10
196
197 - __u8
198
Hans Verkuild2cd6272016-07-12 15:07:44 -0300199 - ``tx_status``
200
201 - The status bits of the transmitted message. See
202 :ref:`cec-tx-status` for the possible status values. It is 0 if
203 this messages was received, not transmitted.
204
205 - .. row 11
206
207 - __u8
208
Markus Heisere2460b12016-07-08 20:55:42 +0200209 - ``tx_arb_lost_cnt``
210
211 - A counter of the number of transmit attempts that resulted in the
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300212 Arbitration Lost error. This is only set if the hardware supports
213 this, otherwise it is always 0. This counter is only valid if the
214 :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.
Markus Heisere2460b12016-07-08 20:55:42 +0200215
Hans Verkuild2cd6272016-07-12 15:07:44 -0300216 - .. row 12
Markus Heisere2460b12016-07-08 20:55:42 +0200217
218 - __u8
219
220 - ``tx_nack_cnt``
221
222 - A counter of the number of transmit attempts that resulted in the
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300223 Not Acknowledged error. This is only set if the hardware supports
224 this, otherwise it is always 0. This counter is only valid if the
225 :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.
Markus Heisere2460b12016-07-08 20:55:42 +0200226
Hans Verkuild2cd6272016-07-12 15:07:44 -0300227 - .. row 13
Markus Heisere2460b12016-07-08 20:55:42 +0200228
229 - __u8
230
231 - ``tx_low_drive_cnt``
232
233 - A counter of the number of transmit attempts that resulted in the
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300234 Arbitration Lost error. This is only set if the hardware supports
235 this, otherwise it is always 0. This counter is only valid if the
236 :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.
Markus Heisere2460b12016-07-08 20:55:42 +0200237
Hans Verkuild2cd6272016-07-12 15:07:44 -0300238 - .. row 14
Markus Heisere2460b12016-07-08 20:55:42 +0200239
240 - __u8
241
242 - ``tx_error_cnt``
243
244 - A counter of the number of transmit errors other than Arbitration
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300245 Lost or Not Acknowledged. This is only set if the hardware
246 supports this, otherwise it is always 0. This counter is only
247 valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.
Markus Heisere2460b12016-07-08 20:55:42 +0200248
249
250
251.. _cec-tx-status:
252
253.. flat-table:: CEC Transmit Status
254 :header-rows: 0
255 :stub-columns: 0
Mauro Carvalho Chehabb2a58432016-07-08 17:59:27 -0300256 :widths: 3 1 16
Markus Heisere2460b12016-07-08 20:55:42 +0200257
258
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300259 - .. _`CEC-TX-STATUS-OK`:
Markus Heisere2460b12016-07-08 20:55:42 +0200260
261 - ``CEC_TX_STATUS_OK``
262
263 - 0x01
264
265 - The message was transmitted successfully. This is mutually
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300266 exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`. Other bits can still
267 be set if earlier attempts met with failure before the transmit
268 was eventually successful.
Markus Heisere2460b12016-07-08 20:55:42 +0200269
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300270 - .. _`CEC-TX-STATUS-ARB-LOST`:
Markus Heisere2460b12016-07-08 20:55:42 +0200271
272 - ``CEC_TX_STATUS_ARB_LOST``
273
274 - 0x02
275
276 - CEC line arbitration was lost.
277
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300278 - .. _`CEC-TX-STATUS-NACK`:
Markus Heisere2460b12016-07-08 20:55:42 +0200279
280 - ``CEC_TX_STATUS_NACK``
281
282 - 0x04
283
284 - Message was not acknowledged.
285
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300286 - .. _`CEC-TX-STATUS-LOW-DRIVE`:
Markus Heisere2460b12016-07-08 20:55:42 +0200287
288 - ``CEC_TX_STATUS_LOW_DRIVE``
289
290 - 0x08
291
292 - Low drive was detected on the CEC bus. This indicates that a
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300293 follower detected an error on the bus and requests a
294 retransmission.
Markus Heisere2460b12016-07-08 20:55:42 +0200295
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300296 - .. _`CEC-TX-STATUS-ERROR`:
Markus Heisere2460b12016-07-08 20:55:42 +0200297
298 - ``CEC_TX_STATUS_ERROR``
299
300 - 0x10
301
302 - Some error occurred. This is used for any errors that do not fit
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300303 the previous two, either because the hardware could not tell which
304 error occurred, or because the hardware tested for other
305 conditions besides those two.
Markus Heisere2460b12016-07-08 20:55:42 +0200306
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300307 - .. _`CEC-TX-STATUS-MAX-RETRIES`:
Markus Heisere2460b12016-07-08 20:55:42 +0200308
309 - ``CEC_TX_STATUS_MAX_RETRIES``
310
311 - 0x20
312
313 - The transmit failed after one or more retries. This status bit is
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300314 mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`. Other bits can still
315 be set to explain which failures were seen.
Markus Heisere2460b12016-07-08 20:55:42 +0200316
317
318
319.. _cec-rx-status:
320
321.. flat-table:: CEC Receive Status
322 :header-rows: 0
323 :stub-columns: 0
Mauro Carvalho Chehabb2a58432016-07-08 17:59:27 -0300324 :widths: 3 1 16
Markus Heisere2460b12016-07-08 20:55:42 +0200325
326
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300327 - .. _`CEC-RX-STATUS-OK`:
Markus Heisere2460b12016-07-08 20:55:42 +0200328
329 - ``CEC_RX_STATUS_OK``
330
331 - 0x01
332
333 - The message was received successfully.
334
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300335 - .. _`CEC-RX-STATUS-TIMEOUT`:
Markus Heisere2460b12016-07-08 20:55:42 +0200336
337 - ``CEC_RX_STATUS_TIMEOUT``
338
339 - 0x02
340
341 - The reply to an earlier transmitted message timed out.
342
Mauro Carvalho Chehab96f69e02016-07-09 10:25:05 -0300343 - .. _`CEC-RX-STATUS-FEATURE-ABORT`:
Markus Heisere2460b12016-07-08 20:55:42 +0200344
345 - ``CEC_RX_STATUS_FEATURE_ABORT``
346
347 - 0x04
348
349 - The message was received successfully but the reply was
Mauro Carvalho Chehab706f8a92016-07-10 11:57:43 -0300350 ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
351 was the reply to an earlier transmitted message.
Markus Heisere2460b12016-07-08 20:55:42 +0200352
353
354
355Return Value
356============
357
358On success 0 is returned, on error -1 and the ``errno`` variable is set
359appropriately. The generic error codes are described at the
360:ref:`Generic Error Codes <gen-errors>` chapter.