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 
22 /**
23 * @defgroup hdmicec
24 * @{
25 * @defgroup ccec
26 * @{
27 **/
28 
29 
30 #ifndef HDMI_CEC_DRIVER_H_
31 #define HDMI_CEC_DRIVER_H_
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 /*
36  * Error Codes.
37  */
38 enum {
39  HDMI_CEC_IO_SUCCESS = 0,
40  HDMI_CEC_IO_SENT_AND_ACKD = 1,
41  HDMI_CEC_IO_SENT_BUT_NOT_ACKD,
42  HDMI_CEC_IO_SENT_FAILED,
43  HDMI_CEC_IO_INVALID_STATE,
44  HDMI_CEC_IO_INVALID_ARGUMENT,
45  HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE,
46  HDMI_CEC_IO_GENERAL_ERROR,
47 };
48 
49 /*
50  * CEC Driver should call this function whenever this is a complete CEC packet received.
51  * Upon each callback, only 1 complete CEC packet should be contained in the buffer.
52  */
53 
54 typedef void (*HdmiCecRxCallback_t)(int handle, void *callbackData, unsigned char *buf, int len);
55 
56 /*
57  * CEC Driver should call this function to report the staus of the latest transmit.
58  */
59 
60 typedef void (*HdmiCecTxCallback_t)(int handle, void *callbackData, int result);
61 /**
62  * @brief opens an instance of CEC driver.
63  * This function should be call once before the functions in this API can be used.
64  *
65  * @param [in] : None.
66  * @param [out] : handle used by application to uniquely identify the driver instance.
67  *
68  * @return Error Code: If error code is returned, the open is failed.
69  */
70 int HdmiCecOpen(int *handle);
71 
72 /**
73  * @brief close an instance of CEC driver.
74  * This function should close the currently opened driver instance.
75  *
76  * @param [in] : handle returned from the HdmiCecOpen() function.
77  * @param [out] : None
78  *
79  * @return Error Code: If error code is returned, the open is failed.
80  */
81 int HdmiCecClose(int handle);
82 
83 /**
84  * @brief This API is **DEPRECATED** due to possible race conditions competing
85  * for a logical address.
86  *
87  * Set the Logical Addresses claimed by host device.
88  * This function sets multiple logical addresses used by the host. The host
89  * has claimed these logical address through the Discovery process. Once
90  * set, the host shall receive all CEC packets destined to these addresses.
91  *
92  * Once the driver is opened, the host shall receive all broadcast messages
93  * regardless the Logical addresses.
94  *
95  * when there is no logical address set, the host shall only receive broadcast
96  * messages.
97  *
98  * @param [in] : handle returned from the HdmiCecOpen() function.
99  * @param [in] : logicalAddresses set or replace addresses claimed by host.
100  * A null value clears the current list.
101  * @param [in] : number of logical addresses. If any logical address in the list
102  * cannot be set, none of them should be set upon return. Success
103  * return indicates that all addresses in the list are set.
104  * @param [out] : None
105  *
106  * @return Error Code: If error code is returned, the set is failed.
107  */
108 int HdmiCecSetLogicalAddress(int handle, int *logicalAddresses, int num);
109 
110 /**
111  * @brief Get the Physical Address obtained by the driver.
112  *
113  * This function get the Physical address for the specified device type.
114  *
115  * @param [in] : handle returned from the HdmiCecOpen() function.
116  * @param [out] : physical address acquired
117  *
118  * @return None.
119  */
120 void HdmiCecGetPhysicalAddress(int handle, unsigned int *physicalAddress);
121 /**
122  * @brief Add one Logical Addresses to be used by host device.
123  *
124  * This function can block until the intended logical address is secured by
125  * the driver.
126  *
127  * In driver implementation, this API would trigger driver sending a POLL
128  * CEC packet to the CEC Bus,
129  *
130  * Packet::HeaderBlock::Initiator = Requested LogicalAddress.
131  * Packet::HeaderBlock::Destination = Requested LogicalAddress.
132  * Packet::DataBlock = Empty.
133  *
134  * The function shall return HDMI_CEC_IO_SUCCESS if the POLL message is sent
135  * successfully and not ACK'd by any device on the bus. From this point on the
136  * driver shall forward all received messages with destination being the acquired
137  * logical address. Driver should ACK all POLL messsges destined to this logical
138  * address.
139  *
140  * The function shall return HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE if the POLL
141  * message is sent and ACK'd by a device on the bus.
142  *
143  * The function shall return relevant error code if the POLL message is not sent
144  * successfully.
145  *
146  *
147  * @param [in] : handle returned from the HdmiCecOpen() function.
148  * @param [in] : logicalAddresses to be acquired.
149  * @param [out] : None
150  *
151  * @return Error Code: See above.
152  */
153 int HdmiCecAddLogicalAddress(int handle, int logicalAddresses);
154 
155 /**
156  * @brief Clear the Logical Addresses claimed by host device.
157  *
158  * This function release the previously acquired logical address. Once
159  * released, driver should not ACK any POLL message destined to the
160  * released address.
161  *
162  * @param [in] : handle returned from the HdmiCecOpen() function.
163  * @param [in] : logicalAddresses to be released.
164  * @param [out] : None
165  *
166  * @return Error Code: see above.
167  */
168 int HdmiCecRemoveLogicalAddress(int handle, int logicalAddresses);
169 
170 /**
171  * @brief Get the Logical Addresses claimed by host device.
172  *
173  * This function gets multiple logical addresses set by the host. It also means
174  * that the driver is actively pick up unicast messages destined to the set of
175  * logical addresses returned.
176  *
177  * @param [in] : handle returned from the HdmiCecOpen() function.
178  * @param [out] : logicalAddresses list of addresses currently set.
179  * @param [in/out] : size of the logicalAddress list. Returned number is the total
180  * number of addresses currently set. This can be larger than the
181  * input value. An returned value 0 indicate that no address is set.
182  *
183  * @return Error Code: If error code is returned, the get is failed.
184  */
185 /*int HdmiCecGetLogicalAddress(int handle, int *logicalAddresses, int *num);*/
186 
187 /**
188  * @brief Get the Logical Address obtained by the driver.
189  *
190  * This function get the logical address for the specified device type.
191  *
192  * @param [in] : handle returned from the HdmiCecOpen() function.
193  * @param [in] : device type (tuner, record, playback etc.).
194  * @param [out] : logical address acquired
195  *
196  * @return Error Code: If error code is returned, the get is failed.
197  */
198 int HdmiCecGetLogicalAddress(int handle, int devType, int *logicalAddress);
199 
200 /**
201  * @brief Sets CEC packet Receive callback.
202  *
203  * This function sets a callback function to be invoked for each packet arrival.
204  * The packet contained in the buffer is expected to follow this format:
205  *
206  * (ref <HDMI Specification 1-4> Section <CEC 6.1>)
207  *
208  * complete packet = header block + data block;
209  * header block = destination logical address (4-bit) + source address (4-bit)
210  * data block = opcode block (8-bit) + oprand block (N-bytes)
211  *
212  * |------------------------------------------------
213  * | header block | data blocks |
214  * |------------------------------------------------
215  * |3|2|1|0|3|2|1|0|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
216  * |------------------------------------------------
217  * | Dest | src | opcode block | operand block |
218  * |------------------------------------------------
219  *
220  * when receiving, the returned buffer should not contain EOM and ACK bits.
221  *
222  * When transmitting, it is driver's responsibility to insert EOM bit and ACK bit
223  * for each header or data block
224  *
225  * When HdmiCecSetRxCallback is called, it replaces the previous set cbfunc and data
226  * values. Setting a value of (cbfunc=null) turns off the callback.
227  *
228  * This function should block if callback invocation is in progress.
229  *
230  * @param [in] : handle returned from the HdmiCecOpen(() function.
231  * @param [in] : cbfunc to be invoked when a complete packet is received.
232  * @param [in] : data, used when invoking callback function.
233  *
234  * @return Error Code: If error code is returned, the set is failed.
235  */
236 int HdmiCecSetRxCallback(int handle, HdmiCecRxCallback_t cbfunc, void *data);
237 
238 /**
239  * @brief Sets CEC packet Transmit callback.
240  *
241  * This function sets a callback function to be invoked once the async tranmit
242  * result is available. This is only necessary if application choose to transmit
243  * the packet asynchronously.
244  *
245  * This function should block if callback invocation is in progress.
246  *
247  * @param [in] : handle returned from the HdmiCecOpen(() function.
248  * @param [in] : cbfunc to be invoked when a complete packet is received.
249  * @param [in] : data, used when invoking callback function.
250  *
251  * @return Error Code: If error code is returned, the set is failed.
252  */
253 int HdmiCecSetTxCallback(int handle, HdmiCecTxCallback_t cbfunc, void *data);
254 
255 /**
256  * @brief Writes CEC packet onto bus.
257  *
258  * This function writes a complete CEC packet onto the CEC bus and wait for ACK.
259  * application should check for result when return value of the function is 0;
260  *
261  * The bytes in @param buf that is to be transmitted should follow the buffer
262  * byte format required for receiving buffer. (See detailed description from
263  * HdmiCecSetRxCallback)
264  *
265  * @param [in] : handle returned from the HdmiCecOpen(() function.
266  * @param [in] : buf contains a complete CEC packet.
267  * @param [in] : len number of bytes in the packet.
268  * @param [out] : result of the send. Possbile results are SENT_AND_ACKD,
269  * SENT_BUT_NOT_ACKD (e.g. no follower at the destionation),
270  * SENT_FAILED (e.g. collision).
271  *
272  * @return Error Code: If error code is returned, the transmit did not happen.
273  */
274 int HdmiCecTx(int handle, const unsigned char *buf, int len, int *result);
275 
276 /**
277  * @brief Writes CEC packet onto bus asynchronously.
278  *
279  * This function writes a complete CEC packet onto the CEC bus but does not wait
280  * for ACK. The result will be reported via HdmiCecRxCallback_t if return value
281  * of this function is 0.
282  *
283  * @param [in] : handle returned from the HdmiCecOpen(() function.
284  * @param [in] : buf contains a complete CEC packet.
285  * @param [in] : len number of bytes in the packet.
286  *
287  * @return Error Code: If error code is returned, the transmit did not happen.
288  */
289 int HdmiCecTxAsync(int handle, const unsigned char *buf, int len);
290 #ifdef __cplusplus
291 }
292 #endif
293 #endif
294 
295 
296 /** @} */
297 /** @} */
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