aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/media/uapi/cec/cec-ioc-receive.rst
blob: d585b1bba6ac4313850000707959508c9ab648bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
.. -*- coding: utf-8; mode: rst -*-

.. _CEC_TRANSMIT:
.. _CEC_RECEIVE:

***********************************
ioctls CEC_RECEIVE and CEC_TRANSMIT
***********************************

Name
====

CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message


Synopsis
========

.. c:function:: int ioctl( int fd, CEC_RECEIVE, struct cec_msg *argp )
    :name: CEC_RECEIVE

.. c:function:: int ioctl( int fd, CEC_TRANSMIT, struct cec_msg *argp )
    :name: CEC_TRANSMIT

Arguments
=========

``fd``
    File descriptor returned by :c:func:`open() <cec-open>`.

``argp``
    Pointer to struct cec_msg.

Description
===========

.. note::

   This documents the proposed CEC API. This API is not yet finalized
   and is currently only available as a staging kernel module.

To receive a CEC message the application has to fill in the
``timeout`` field of struct :c:type:`cec_msg` and pass it to
:ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
If the file descriptor is in non-blocking mode and there are no received
messages pending, then it will return -1 and set errno to the ``EAGAIN``
error code. If the file descriptor is in blocking mode and ``timeout``
is non-zero and no message arrived within ``timeout`` milliseconds, then
it will return -1 and set errno to the ``ETIMEDOUT`` error code.

A received message can be:

1. a message received from another CEC device (the ``sequence`` field will
   be 0).
2. the result of an earlier non-blocking transmit (the ``sequence`` field will
   be non-zero).

To send a CEC message the application has to fill in the struct
:c:type:` cec_msg` and pass it to :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
queue, then it will return -1 and set errno to the ``EBUSY`` error code.
The transmit queue has enough room for 18 messages (about 1 second worth
of 2-byte messages). Note that the CEC kernel framework will also reply
to core messages (see :ref:cec-core-processing), so it is not a good
idea to fully fill up the transmit queue.

If the file descriptor is in non-blocking mode then the transmit will
return 0 and the result of the transmit will be available via
:ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished
(including waiting for a reply, if requested).

The ``sequence`` field is filled in for every transmit and this can be
checked against the received messages to find the corresponding transmit
result.


.. tabularcolumns:: |p{1.0cm}|p{3.5cm}|p{13.0cm}|

.. c:type:: cec_msg

.. cssclass:: longtable

.. flat-table:: struct cec_msg
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 16


    -  .. row 1

       -  __u64

       -  ``tx_ts``

       -  Timestamp in ns of when the last byte of the message was transmitted.
	  The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
	  the same clock from userspace use :c:func:`clock_gettime`.

    -  .. row 2

       -  __u64

       -  ``rx_ts``

       -  Timestamp in ns of when the last byte of the message was received.
	  The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
	  the same clock from userspace use :c:func:`clock_gettime`.

    -  .. row 3

       -  __u32

       -  ``len``

       -  The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
	  by the application. The driver will fill this in for
	  :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
	  filled in by the driver with the length of the reply message if ``reply`` was set.

    -  .. row 4

       -  __u32

       -  ``timeout``

       -  The timeout in milliseconds. This is the time the device will wait
	  for a message to be received before timing out. If it is set to 0,
	  then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
	  If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
	  then it will be replaced by 1000 if the ``reply`` is non-zero or
	  ignored if ``reply`` is 0.

    -  .. row 5

       -  __u32

       -  ``sequence``

       -  A non-zero sequence number is automatically assigned by the CEC framework
	  for all transmitted messages. It is used by the CEC framework when it queues
	  the transmit result (when transmit was called in non-blocking mode). This
	  allows the application to associate the received message with the original
	  transmit.

    -  .. row 6

       -  __u32

       -  ``flags``

       -  Flags. No flags are defined yet, so set this to 0.

    -  .. row 7

       -  __u8

       -  ``tx_status``

       -  The status bits of the transmitted message. See
	  :ref:`cec-tx-status` for the possible status values. It is 0 if
	  this messages was received, not transmitted.

    -  .. row 8

       -  __u8

       -  ``msg[16]``

       -  The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
	  application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
	  For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
	  the payload of the reply message if ``timeout`` was set.

    -  .. row 8

       -  __u8

       -  ``reply``

       -  Wait until this message is replied. If ``reply`` is 0 and the
	  ``timeout`` is 0, then don't wait for a reply but return after
	  transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
	  The case where ``reply`` is 0 (this is the opcode for the Feature Abort
	  message) and ``timeout`` is non-zero is specifically allowed to make it
	  possible to send a message and wait up to ``timeout`` milliseconds for a
	  Feature Abort reply. In this case ``rx_status`` will either be set
	  to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
	  :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.

    -  .. row 9

       -  __u8

       -  ``rx_status``

       -  The status bits of the received message. See
	  :ref:`cec-rx-status` for the possible status values. It is 0 if
	  this message was transmitted, not received, unless this is the
	  reply to a transmitted message. In that case both ``rx_status``
	  and ``tx_status`` are set.

    -  .. row 10

       -  __u8

       -  ``tx_status``

       -  The status bits of the transmitted message. See
	  :ref:`cec-tx-status` for the possible status values. It is 0 if
	  this messages was received, not transmitted.

    -  .. row 11

       -  __u8

       -  ``tx_arb_lost_cnt``

       -  A counter of the number of transmit attempts that resulted in the
	  Arbitration Lost error. This is only set if the hardware supports
	  this, otherwise it is always 0. This counter is only valid if the
	  :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.

    -  .. row 12

       -  __u8

       -  ``tx_nack_cnt``

       -  A counter of the number of transmit attempts that resulted in the
	  Not Acknowledged error. This is only set if the hardware supports
	  this, otherwise it is always 0. This counter is only valid if the
	  :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.

    -  .. row 13

       -  __u8

       -  ``tx_low_drive_cnt``

       -  A counter of the number of transmit attempts that resulted in the
	  Arbitration Lost error. This is only set if the hardware supports
	  this, otherwise it is always 0. This counter is only valid if the
	  :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.

    -  .. row 14

       -  __u8

       -  ``tx_error_cnt``

       -  A counter of the number of transmit errors other than Arbitration
	  Lost or Not Acknowledged. This is only set if the hardware
	  supports this, otherwise it is always 0. This counter is only
	  valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.


.. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|

.. _cec-tx-status:

.. flat-table:: CEC Transmit Status
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 16


    -  .. _`CEC-TX-STATUS-OK`:

       -  ``CEC_TX_STATUS_OK``

       -  0x01

       -  The message was transmitted successfully. This is mutually
	  exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`. Other bits can still
	  be set if earlier attempts met with failure before the transmit
	  was eventually successful.

    -  .. _`CEC-TX-STATUS-ARB-LOST`:

       -  ``CEC_TX_STATUS_ARB_LOST``

       -  0x02

       -  CEC line arbitration was lost.

    -  .. _`CEC-TX-STATUS-NACK`:

       -  ``CEC_TX_STATUS_NACK``

       -  0x04

       -  Message was not acknowledged.

    -  .. _`CEC-TX-STATUS-LOW-DRIVE`:

       -  ``CEC_TX_STATUS_LOW_DRIVE``

       -  0x08

       -  Low drive was detected on the CEC bus. This indicates that a
	  follower detected an error on the bus and requests a
	  retransmission.

    -  .. _`CEC-TX-STATUS-ERROR`:

       -  ``CEC_TX_STATUS_ERROR``

       -  0x10

       -  Some error occurred. This is used for any errors that do not fit
	  the previous two, either because the hardware could not tell which
	  error occurred, or because the hardware tested for other
	  conditions besides those two.

    -  .. _`CEC-TX-STATUS-MAX-RETRIES`:

       -  ``CEC_TX_STATUS_MAX_RETRIES``

       -  0x20

       -  The transmit failed after one or more retries. This status bit is
	  mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`. Other bits can still
	  be set to explain which failures were seen.


.. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|

.. _cec-rx-status:

.. flat-table:: CEC Receive Status
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 16


    -  .. _`CEC-RX-STATUS-OK`:

       -  ``CEC_RX_STATUS_OK``

       -  0x01

       -  The message was received successfully.

    -  .. _`CEC-RX-STATUS-TIMEOUT`:

       -  ``CEC_RX_STATUS_TIMEOUT``

       -  0x02

       -  The reply to an earlier transmitted message timed out.

    -  .. _`CEC-RX-STATUS-FEATURE-ABORT`:

       -  ``CEC_RX_STATUS_FEATURE_ABORT``

       -  0x04

       -  The message was received successfully but the reply was
	  ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
	  was the reply to an earlier transmitted message.



Return Value
============

On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.