RDK Documentation (Open Sourced RDK Components)
hdmi_cec_driver.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @defgroup HDMI_CEC RDK HDMI-CEC
22  * @par Application API Specification
23  * In general, the RDK CEC Library offers three categories of Application APIs:
24  * @par HDMI-CEC Connection
25  * The Connection APIs allows application to transmit and receive raw data bytes
26  * (a.k.a. CEC Frame) that conforms to the HDMI-CEC specification.
27  * This is the only interface that the application can use to access CEC Bus.
28  * @par HDMI-CEC Message and Frame Constructs
29  * The Messages APIs allows application to encode high-level message constructs into @b CECFrame raw bytes,
30  * or decode @b CECFrame raw bytes into high-level message constructs.
31  *
32  * @image html hdmicec_api.png
33  *
34  * @par Host Interface
35  * The @b Host interface allows libCEC implementation to interact with the host environment
36  * Such interaction includes monitoring of the Power State change, the HDMI HotPlug events, or APIs to change the Host States.
37  * This allows the CEC stack to run in any devices that implements the Host Interface.
38  * @par Driver Component
39  * The @b Driver component access the HDMI-CEC SoC Driver via the CEC HAL API.
40  * The Vendors are responsible in delivering a SoC Driver that conforms to the HAL API (see hdmi_cec_driver.h"
41  *
42  * @defgroup HDMI_CEC_APPLICATION HDMI-CEC Applications
43  * The relation between Application, Connection and CEC-Bus is described in the figure.
44  *
45  * @image html hdmicec_applications.png
46  *
47  * @par CEC Daemon
48  * This daemon receives Raw Bytes from the SoC Driver and dispatches them into IARM Bus via CecIARMMgr,
49  * it also receives Raw Bytes from IARM Bus and send to the SoC Driver. It controls
50  * the only access point to the physical HDMI CEC Bus.
51  *
52  * @par Receiver
53  * This application receives Raw Bytes from IARM Bus and dispatch to Service Manager (which in turn may dispatch
54  * the bytes to Guide Application). It also receives Raw bytes from Service Manager and send to the IARM-Bus.
55  *
56  * @par CECDevMgr
57  * This application is a "sniffer" on the CEC Bus. It monitors all messages on the bus and construct a Device Map,
58  * which depicts the topology of all connected devices on the CEC Bus. Other applications can be developed similar
59  * to Receiver or CECDevMgr where the CEC Raw bytes (in form of CECFrame) are send/receive to/from IARM Bus.
60  * This pseudo CEC Driver implemented on IARM Bus is called CEC IARM Adapter in the diagram.
61  * @note CECDevMgr binary is not currently being copied to the box as it is not being used in box.
62  * @ingroup HDMI_CEC
63  *
64  * @defgroup HDMI_CEC_CONNECTION HDMI-CEC Connection
65  * The connection API allows the application to access CEC Bus. A connection is a tap into the CEC bus.
66  * The application can use a connection to send raw bytes (in form of CECFrame) onto CEC bus or receive raw bytes from it.
67  * @n @n
68  * Each connection must have one and only one logical address. When application sends a CEC frame onto the connection,
69  * the connection's logical address will be used as the source address. On such connection, the application can only
70  * receive broadcast messages or unicast messages destined to the logical address of the connection.
71  * @n @n
72  * The application can open multiple connections, with one connection dedicated to each Role of the application.
73  * For example, a Set-top Box of three roles (Record, Playback, and Tuner) can open three connections, with each connection
74  * used to send/receive messages of the relevant role. Such Role-Connection mapping is transparent to the devices on the CEC bus.
75  * The external devices will not be able to tell if the CEC messages come from connections of a same or different physical device.
76  * @n @n
77  * All incoming CEEFrame arrived at the Physical CEC bus will be dispatched to all opened connections, based on the filtering
78  * criteria of the connection. By default, a connection with a given logical address filters out messages destined
79  * to other logical addresses.
80  * @n @n
81  * When a connection is opened without a given logical address, this connection will pick up all messages destined
82  * to the host device, regardless what roles the device has. This is useful if the application wants to sniff all
83  * available CEC packets from the bus.
84  * @ingroup HDMI_CEC
85  *
86  * @defgroup HDMI_CEC_DRIVER HDMI-CEC Driver APIs
87  * The Driver component access the HDMI-CEC SoC Driver via the CEC HAL API. Vendors are responsible in delivering
88  * a SoC Driver that conforms to the HAL API (see hdmi_cec_driver.h)
89  * @ingroup HDMI_CEC
90  *
91  * @defgroup HDMI_CEC_MULTI_APP Multi-App Support
92  *
93  * Often , the application functionality (Record, Tune and Playback) is distributed across
94  * multiple components. In order for any component to have equivalent access to the HDMI-CEC bus,
95  * the library offers Multi-App support via IARM-Bus. This support is enabled by default, and can be disabled if desired.
96  * @n @n
97  * In essence, there is only one physical CEC bus on asystem. However, with the help of Connection, Logical CEC-Bus,
98  * and IARM-Bus, the CEC library can converge the CEC traffic from different Connections and Logical Buses before
99  * forwarding them to the single physical bus. This is illustrated by the diagram below.
100  *
101  * @image html hdmicec_multiapp.png
102  *
103  * In this diagram there are two applications (Receiver and CECDevMgr). Since both applications can only access the
104  * underlying physical CEC Bus via Connection API, they have no knowledge how the message are eventually delivered
105  * to the Physical Bus.
106  * @n @n
107  * For both applications, its CEC messages flows from,
108  *
109  * @code
110  * Connection --> Logical Bus--> CEC IARM Apaper--> IARM Bus---> (CECDaemonMain)
111  * @endcode
112  *
113  * For CECDaemonMain, its CEC messages flows from,
114  *
115  * @code
116  * IARM Bus --> CecIARMMgr --> Connection --> Logical Bus --> CEC Driver --> (Physical Bus)
117  * @endcode
118  *
119  * The message flow on Connections and Logical Buses are full duplex.
120  * @ingroup HDMI_CEC
121  */
122 
123 /**
124 * @defgroup hdmicec
125 * @{
126 * @defgroup ccec
127 * @{
128 **/
129 
130 #ifndef HDMI_CEC_DRIVER_H_
131 #define HDMI_CEC_DRIVER_H_
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135 /*
136  * Error Codes.
137  */
138 enum {
139  HDMI_CEC_IO_SUCCESS = 0,
140  HDMI_CEC_IO_SENT_AND_ACKD = 1,
141  HDMI_CEC_IO_SENT_BUT_NOT_ACKD,
142  HDMI_CEC_IO_SENT_FAILED,
143  HDMI_CEC_IO_INVALID_STATE,
144  HDMI_CEC_IO_INVALID_ARGUMENT,
145  HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE,
146  HDMI_CEC_IO_GENERAL_ERROR,
147 };
148 
149 /**
150  * @addtogroup HDMI_CEC_DRIVER
151  * @{
152  */
153 /**
154  * CEC Driver should call this function whenever there is a complete CEC packet received.
155  * Upon each callback, only 1 complete CEC packet should be contained in the buffer.
156  */
157 
158 typedef void (*HdmiCecRxCallback_t)(int handle, void *callbackData, unsigned char *buf, int len);
159 
160 /**
161  * CEC Driver should call this function to report the status of the latest transmit.
162  */
163 
164 typedef void (*HdmiCecTxCallback_t)(int handle, void *callbackData, int result);
165 /**
166  * @brief opens an instance of CEC driver.
167  * This function should be call once before the functions in this API can be used.
168  *
169  * @param [in] : None.
170  * @param [out] : handle used by application to uniquely identify the driver instance.
171  *
172  * @return Error Code: If error code is returned, the open is failed.
173  */
174 int HdmiCecOpen(int *handle);
175 
176 /**
177  * @brief close an instance of CEC driver.
178  * This function should close the currently opened driver instance.
179  *
180  * @param [in] : handle returned from the HdmiCecOpen() function.
181  * @param [out] : None
182  *
183  * @return Error Code: If error code is returned, the open is failed.
184  */
185 int HdmiCecClose(int handle);
186 
187 /**
188  * @brief This API is **DEPRECATED** due to possible race conditions competing
189  * for a logical address.
190  *
191  * Set the Logical Addresses claimed by host device.
192  * This function sets multiple logical addresses used by the host. The host
193  * has claimed these logical address through the Discovery process. Once
194  * set, the host shall receive all CEC packets destined to these addresses.
195  *
196  * Once the driver is opened, the host shall receive all broadcast messages
197  * regardless the Logical addresses.
198  *
199  * when there is no logical address set, the host shall only receive broadcast
200  * messages.
201  *
202  * @param [in] : handle returned from the HdmiCecOpen() function.
203  * @param [in] : logicalAddresses set or replace addresses claimed by host.
204  * A null value clears the current list.
205  * @param [in] : number of logical addresses. If any logical address in the list
206  * cannot be set, none of them should be set upon return. Success
207  * return indicates that all addresses in the list are set.
208  * @param [out] : None
209  *
210  * @return Error Code: If error code is returned, the set is failed.
211  */
212 int HdmiCecSetLogicalAddress(int handle, int *logicalAddresses, int num);
213 
214 /**
215  * @brief Add one Logical Addresses to be used by host device.
216  *
217  * This function can block until the intended logical address is secured by
218  * the driver.
219  *
220  * In driver implementation, this API would trigger driver sending a POLL
221  * CEC packet to the CEC Bus,
222  *
223  * Packet::HeaderBlock::Initiator = Requested LogicalAddress.
224  * Packet::HeaderBlock::Destination = Requested LogicalAddress.
225  * Packet::DataBlock = Empty.
226  *
227  * The function shall return HDMI_CEC_IO_SUCCESS if the POLL message is sent
228  * successfully and not ACK'd by any device on the bus. From this point on the
229  * driver shall forward all received messages with destination being the acquired
230  * logical address. Driver should ACK all POLL messages destined to this logical
231  * address.
232  *
233  * The function shall return HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE if the POLL
234  * message is sent and ACK'd by a device on the bus.
235  *
236  * The function shall return relevant error code if the POLL message is not sent
237  * successfully.
238  *
239  *
240  * @param [in] : handle returned from the HdmiCecOpen() function.
241  * @param [in] : logicalAddresses to be acquired.
242  * @param [out] : None
243  *
244  * @return Error Code: See above.
245  */
246 int HdmiCecAddLogicalAddress(int handle, int logicalAddresses);
247 
248 /**
249  * @brief Clear the Logical Addresses claimed by host device.
250  *
251  * This function releases the previously acquired logical address. Once
252  * released, driver should not ACK any POLL message destined to the
253  * released address.
254  *
255  * @param [in] : handle returned from the HdmiCecOpen() function.
256  * @param [in] : logicalAddresses to be released.
257  * @param [out] : None
258  *
259  * @return Error Code: see above.
260  */
261 int HdmiCecRemoveLogicalAddress(int handle, int logicalAddresses);
262 
263 /**
264  * @brief Get the Logical Addresses claimed by host device.
265  *
266  * This function gets multiple logical addresses set by the host. It also means
267  * that the driver is actively pick up unicast messages destined to the set of
268  * logical addresses returned.
269  *
270  * @param [in] : handle returned from the HdmiCecOpen() function.
271  * @param [out] : logicalAddresses list of addresses currently set.
272  * @param [in/out] : size of the logicalAddress list. Returned number is the total
273  * number of addresses currently set. This can be larger than the
274  * input value. An returned value 0 indicate that no address is set.
275  *
276  * @return Error Code: If error code is returned, the get is failed.
277  */
278 /*int HdmiCecGetLogicalAddress(int handle, int *logicalAddresses, int *num);*/
279 
280 /**
281  * @brief Get the Logical Address obtained by the driver.
282  *
283  * This function get the logical address for the specified device type.
284  *
285  * @param [in] : handle returned from the HdmiCecOpen() function.
286  * @param [in] : device type (tuner, record, playback etc.).
287  * @param [out] : logical address acquired
288  *
289  * @return Error Code: If error code is returned, the get is failed.
290  */
291 int HdmiCecGetLogicalAddress(int handle, int devType, int *logicalAddress);
292 
293 /**
294  * @brief Get the Physical Address obtained by the driver.
295  *
296  * This function get the Physical address for the specified device type.
297  *
298  * @param [in] : handle returned from the HdmiCecOpen() function.
299  * @param [out] : physical address acquired
300  *
301  * @return None.
302  */
303 void HdmiCecGetPhysicalAddress(int handle,unsigned int *physicalAddress);
304 
305 /**
306  * @brief Sets CEC packet Receive callback.
307  *
308  * This function sets a callback function to be invoked for each packet arrival.
309  * The packet contained in the buffer is expected to follow this format:
310  *
311  * (ref <HDMI Specification 1-4> Section <CEC 6.1>)
312  *
313  * complete packet = header block + data block;
314  * header block = destination logical address (4-bit) + source address (4-bit)
315  * data block = opcode block (8-bit) + operand block (N-bytes)
316  *
317  * @code
318  * |------------------------------------------------
319  * | header block | data blocks |
320  * |------------------------------------------------
321  * |3|2|1|0|3|2|1|0|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
322  * |------------------------------------------------
323  * | Dest | src | opcode block | operand block |
324  * |------------------------------------------------
325  * @endcode
326  *
327  * when receiving, the returned buffer should not contain EOM and ACK bits.
328  *
329  * When transmitting, it is driver's responsibility to insert EOM bit and ACK bit
330  * for each header or data block
331  *
332  * When HdmiCecSetRxCallback is called, it replaces the previous set cbfunc and data
333  * values. Setting a value of (cbfunc=null) turns off the callback.
334  *
335  * This function should block if callback invocation is in progress.
336  *
337  * @param[in] handle Handle returned from the HdmiCecOpen(() function.
338  * @param[in] cbfunc A callback function to be invoked when a complete packet is received.
339  * @param[in] data It is used when invoking callback function.
340  *
341  * @return Error Code: If error code is returned, the set is failed.
342  */
343 int HdmiCecSetRxCallback(int handle, HdmiCecRxCallback_t cbfunc, void *data);
344 
345 /**
346  * @brief Sets CEC packet Transmit callback.
347  *
348  * This function sets a callback function to be invoked once the async transmit
349  * result is available. This is only necessary if application choose to transmit
350  * the packet asynchronously.
351  *
352  * This function should block if callback invocation is in progress.
353  *
354  * @param[in] handle Returned from the HdmiCecOpen(() function.
355  * @param[in] cbfunc Function pointer to be invoked when a complete packet is received.
356  * @param[in] data It is used when invoking callback function.
357  *
358  * @return Error Code: If error code is returned, the set is failed.
359  */
360 int HdmiCecSetTxCallback(int handle, HdmiCecTxCallback_t cbfunc, void *data);
361 
362 /**
363  * @brief Writes CEC packet onto bus.
364  *
365  * This function writes a complete CEC packet onto the CEC bus and wait for ACK.
366  * application should check for result when return value of the function is 0;
367  *
368  * The bytes in @param buf that is to be transmitted should follow the buffer
369  * byte format required for receiving buffer. (See detailed description from
370  * HdmiCecSetRxCallback)
371  *
372  * @param[in] handle Returned from the HdmiCecOpen(() function.
373  * @param[in] buf Buffer contains a complete CEC packet.
374  * @param[in] len Number of bytes in the packet.
375  * @param[out] result Output of the send. Possible results are SENT_AND_ACKD,
376  * SENT_BUT_NOT_ACKD (e.g. no follower at the destination),
377  * SENT_FAILED (e.g. collision).
378  *
379  * @return Error Code: If error code is returned, the transmit did not happen.
380  */
381 int HdmiCecTx(int handle, const unsigned char *buf, int len, int *result);
382 
383 /**
384  * @brief Writes CEC packet onto bus asynchronously.
385  *
386  * This function writes a complete CEC packet onto the CEC bus but does not wait
387  * for ACK. The result will be reported via HdmiCecRxCallback_t if return value
388  * of this function is 0.
389  *
390  * @param[in] handle Handle returned from the HdmiCecOpen(() function.
391  * @param[in] buf Buffer contains a complete CEC packet.
392  * @param[in] len Number of bytes in the packet.
393  *
394  * @return Error Code: If error code is returned, the transmit did not happen.
395  */
396 int HdmiCecTxAsync(int handle, const unsigned char *buf, int len);
397 
398 /** @} */
399 
400 #ifdef __cplusplus
401 }
402 #endif
403 #endif
404 
405 
406 /** @} */
407 /** @} */
HdmiCecTxCallback_t
void(* HdmiCecTxCallback_t)(int handle, void *callbackData, int result)
Definition: hdmi_cec_driver.h:164
HdmiCecTxAsync
int HdmiCecTxAsync(int handle, const unsigned char *buf, int len)
Writes CEC packet onto bus asynchronously.
Definition: hdmi_cec_driver.c:268
HdmiCecRxCallback_t
void(* HdmiCecRxCallback_t)(int handle, void *callbackData, unsigned char *buf, int len)
Definition: hdmi_cec_driver.h:158
HdmiCecClose
int HdmiCecClose(int handle)
close an instance of CEC driver. This function should close the currently opened driver instance.
Definition: hdmi_cec_driver.c:106
HdmiCecGetPhysicalAddress
void HdmiCecGetPhysicalAddress(int handle, unsigned int *physicalAddress)
Get the Physical Address obtained by the driver.
Definition: hdmi_cec_driver.c:211
HdmiCecTx
int HdmiCecTx(int handle, const unsigned char *buf, int len, int *result)
Writes CEC packet onto bus.
Definition: hdmi_cec_driver.c:284
HdmiCecSetRxCallback
int HdmiCecSetRxCallback(int handle, HdmiCecRxCallback_t cbfunc, void *data)
Sets CEC packet Receive callback.
Definition: hdmi_cec_driver.c:242
HdmiCecSetLogicalAddress
int HdmiCecSetLogicalAddress(int handle, int *logicalAddresses, int num)
This API is DEPRECATED due to possible race conditions competing for a logical address.
Definition: hdmi_cec_driver.c:324
HdmiCecRemoveLogicalAddress
int HdmiCecRemoveLogicalAddress(int handle, int logicalAddresses)
Clear the Logical Addresses claimed by host device.
Definition: hdmi_cec_driver.c:172
HdmiCecSetTxCallback
int HdmiCecSetTxCallback(int handle, HdmiCecTxCallback_t cbfunc, void *data)
Sets CEC packet Transmit callback.
Definition: hdmi_cec_driver.c:255
HdmiCecOpen
int HdmiCecOpen(int *handle)
opens an instance of CEC driver. This function should be call once before the functions in this API...
Definition: hdmi_cec_driver.c:68
HdmiCecGetLogicalAddress
int HdmiCecGetLogicalAddress(int handle, int devType, int *logicalAddress)
Get the Logical Addresses claimed by host device.
Definition: hdmi_cec_driver.c:179
HdmiCecAddLogicalAddress
int HdmiCecAddLogicalAddress(int handle, int logicalAddresses)
Add one Logical Addresses to be used by host device.
Definition: hdmi_cec_driver.c:146