HDMI CEC HAL 0.2.0
 
Loading...
Searching...
No Matches
hdmi_cec_driver.h
Go to the documentation of this file.
1/*
2 * If not stated otherwise in this file or this component's LICENSE 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 * @addtogroup HPK Hardware Porting Kit
23 * @{
24 * @par The Hardware Porting Kit
25 * HPK is the next evolution of the well-defined Hardware Abstraction Layer
26 * (HAL), but augmented with more comprehensive documentation and test suites
27 * that OEM or SOC vendors can use to self-certify their ports before taking
28 * them to RDKM for validation or to an operator for final integration and
29 * deployment. The Hardware Porting Kit effectively enables an OEM and/or SOC
30 * vendor to self-certify their own Video Accelerator devices, with minimal RDKM
31 * assistance.
32 *
33 */
34
35
36/**
37 * @defgroup HDMI_CEC HDMI CEC Module
38 * @{
39 * @par Application API Specification
40 * HDMI CEC HAL provides a set of APIs to communicate CEC messages with other
41 * CEC devices HDMI CEC HAL is to retrieve discovered logical and physical
42 * address of host device and to transmit and receive messages to and from the
43 * connected with HDMI cable. The purpose of the HAL is to retrieve discovered
44 * logical and physical address of the host device and to transmit and receive
45 * messages with the remote device synchronously / asynchronously.
46 *
47 */
48
49/**
50 * @defgroup HDMI_CEC_HAL HDMI CEC HAL
51 * @{
52 * @par Application API Specification
53 * HDMI CEC HAL provides a set of APIs to communicate CEC messages with other
54 * CEC devices HDMI CEC HAL is to retrieve discovered logical and physical
55 * address of host device and to transmit and receive messages to and from the
56 * connected with HDMI cable. The purpose of the HAL is to retrieve discovered
57 * logical and physical address of the host device and to transmit and receive
58 * messages with the remote device synchronously / asynchronously.
59 *
60 */
61
62/**
63 * @defgroup HDMI_CEC_DRIVER_H HDMI CEC Header
64 * @{
65 */
66
67/**
68 * @file hdmi_cec_driver.h
69 */
70
71#ifndef HDMI_CEC_DRIVER_H_
72#define HDMI_CEC_DRIVER_H_
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77/*
78 * Error Codes.
79 */
80enum {
81 HDMI_CEC_IO_SUCCESS = 0, ///< Input output operation is successful
82 HDMI_CEC_IO_SENT_AND_ACKD = 1, ///< Send and acknowledgement received
83 HDMI_CEC_IO_SENT_BUT_NOT_ACKD, ///< Sent but acknowledgement not received
84 HDMI_CEC_IO_SENT_FAILED, ///< Operation failed
86 HDMI_CEC_IO_INVALID_ARGUMENT, ///< Invalid argument is passed to the module
87 HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE, ///< Logical address is not available
88 HDMI_CEC_IO_GENERAL_ERROR, ///< Operation general error.
89};
90
91/**
92 * @brief Callback function triggered when a complete CEC packet is received
93 *
94 * Upon each callback, only 1 complete packet should be contained in the buffer.
95 *
96 * @param[in] handle - The handle used by application to uniquely identify the HAL instance. Non zero value
97 * @param[in] callbackData - Callback data for the receive callback
98 * @param[in] buf - Buffer passed in receive callback
99 * @param[in] len - Length of buffer passed in receive callback
100 */
101typedef void (*HdmiCecRxCallback_t)(int handle, void *callbackData, unsigned char *buf, int len);
102
103/**
104 * @brief Callback function triggered to report the status of the latest transmit message
105 *
106 * @param[in] handle - The handle used by application to uniquely identify the HAL instance. Non zero value
107 * @param[in] callbackData - Callback data for the transmit callback
108 * @param[in] result - Async transmit result from the platform implementation
109 */
110typedef void (*HdmiCecTxCallback_t)(int handle, void *callbackData, int result);
111
112/**
113 * @brief Initializes the HDMI CEC HAL
114 *
115 * This function is required to be called before the other APIs in this module.@n
116 * Subsequent calls to this API will return HDMI_CEC_IO_SUCCESS.
117 *
118 * @param [out] handle - The handle used by application to uniquely
119 * identify the HAL instance
120 *
121 * @return Error Code - Status
122 * @retval HDMI_CEC_IO_SUCCESS - Success
123 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - Parameter passed to this function is invalid
124 * @retval HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE - Logical address is not available for source devices.
125 *
126 * @note For sink devices logical address discovery will not happen in HdmiCecOpen()
127 *
128 * @warning This API is NOT thread safe.
129 *
130 * @see HdmiCecClose()
131 *
132 */
133int HdmiCecOpen(int *handle);
134
135/**
136 * @brief Closes an instance of HDMI CEC HAL
137 *
138 * This function will uninitialise the module.@n
139 * Close will clear up registered logical addresses.@n
140 * Subsequent calls to this API will return HDMI_CEC_IO_SUCCESS.
141 *
142 * @param[in] handle - The handle returned from the HdmiCecOpen(). Non zero value
143 *
144 * @return Error Code - Status
145 * @retval HDMI_CEC_IO_SUCCESS - Success
146 *
147 * @pre HdmiCecOpen() must be called before calling this API.
148 *
149 * @warning This API is NOT thread safe.
150 *
151 * @see HdmiCecOpen()
152 *
153 */
154int HdmiCecClose(int handle);
155
156/**
157 * @brief This API is **DEPRECATED** due to possible race conditions competing
158 * for a logical address.
159 *
160 * Set the Logical Addresses claimed by host device.
161 * This function sets multiple logical addresses used by the host. The host
162 * has claimed these logical address through the Discovery process. Once
163 * set, the host shall receive all CEC packets destined to these addresses.
164 *
165 * Once the driver is opened, the host shall receive all broadcast messages
166 * regardless the Logical addresses.
167 *
168 * when there is no logical address set, the host shall only receive broadcast messages.
169 *
170 * @param [in] handle - returned from the HdmiCecOpen() function.
171 * @param [in] logicalAddresses - set or replace addresses claimed by host.
172 * A null value clears the current list.
173 * @param [in] num - number of logical addresses. If any logical address in the list
174 * cannot be set, none of them should be set upon return. Success
175 * return indicates that all addresses in the list are set.
176 *
177 * @return Error Code - Status
178 * @retval HDMI_CEC_IO_SUCCESS - Success
179 *
180 * @pre HdmiCecOpen() must be called before calling this API.
181 *
182 * @warning This API is NOT thread safe.
183 *
184 */
185int HdmiCecSetLogicalAddress(int handle, int *logicalAddresses, int num);
186
187/**
188 * @brief Gets the Physical Address obtained by the module
189 *
190 * This function gets the Physical address for the specified device type.
191 *
192 * @param[in] handle - The handle returned from the HdmiCecOpen(). Non zero value
193 * @param[out] physicalAddress - Physical address acquired
194 * Max possible physical address is 4.4.4.4 and respective integer value is (((0x04 &0xF0 ) << 20)|( (0x04 &0x0F ) << 16) |((0x04 & 0xF0) << 4) | (0x04 & 0x0F))
195 * Min value for physicalAddress is 0
196 *
197 * @pre HdmiCecOpen() must be called before calling this API.
198 *
199 * @warning This API is NOT thread safe.
200 *
201 * @see HdmiCecGetLogicalAddress()
202 *
203 */
204void HdmiCecGetPhysicalAddress(int handle, unsigned int *physicalAddress);
205
206/**
207 * @brief Adds one Logical Addresses to be used by host device
208 *
209 * This function will block until the intended logical address is secured by the module.@n
210 * HAL will forward all received messages with destination being the acquired logical address.@n
211 * HAL should ACK all POLL messages destined to this logical address.@n
212 * This API is only applicable for sink devices. Supported logical address value must be 0x0.@n
213 * Invoking this API in source device must return HDMI_CEC_IO_INVALID_ARGUMENT@n@n
214 *
215 * In HAL implementation, this API would trigger HAL sending a POLL CEC packet to the CEC Bus:@n
216 * Packet::HeaderBlock::Initiator = Requested LogicalAddress@n
217 * Packet::HeaderBlock::Destination = Requested LogicalAddress@n
218 * Packet::DataBlock = Empty
219 *
220 * @param[in] handle - The handle returned from the HdmiCecOpen()
221 * function. Non zero value
222 * @param[in] logicalAddresses - The logical address to be acquired
223 *
224 * @return Error Code - Status
225 * @retval HDMI_CEC_IO_SUCCESS - POLL message is sent successfully and not ACK'd by any device on the bus
226 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - Parameter passed to this function is invalid
227 * i.e. be if any logical address other than 0x0 is given as argument
228 * @retval HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE - POLL message is sent and ACK'd by a device on the bus
229 * @retval HDMI_CEC_IO_SENT_FAILED - POLL message send failed.
230 *
231 * @pre HdmiCecOpen() must be called before calling this API.
232 *
233 * @warning This API is NOT thread safe.
234 *
235 * @see HdmiCecRemoveLogicalAddress(), HdmiCecGetLogicalAddress()
236 *
237 */
238int HdmiCecAddLogicalAddress(int handle, int logicalAddresses);
239
240/**
241 * @brief Clears the Logical Addresses claimed by the host device
242 *
243 * This function releases the previously acquired logical address.@n
244 * Once released, the module must not ACK any POLL message destined to the released address.@n
245 * Subsequent calls to this API will return HDMI_CEC_IO_SUCCESS.
246 * This API is only applicable for sink devices.
247 * Invoking this API in source device must return HDMI_CEC_IO_INVALID_ARGUMENT@n@n
248 *
249 *
250 * @param[in] handle - The handle returned from the HdmiCecOpen(). Non zero value
251 * @param[in] logicalAddresses - The logicalAddresses to be released
252 *
253 * @return Error Code - Status
254 * @retval HDMI_CEC_IO_SUCCESS - Success
255 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - Parameter passed to this function is invalid -
256 * i.e. if any logical address other than 0x0 is given as argument
257 *
258 * @pre HdmiCecOpen() must be called before calling this API.
259 *
260 * @warning This API is NOT thread safe.
261 *
262 * @see HdmiCecAddLogicalAddress(), HdmiCecGetLogicalAddress()
263 *
264 */
265int HdmiCecRemoveLogicalAddress(int handle, int logicalAddresses);
266
267/**
268 * @brief Gets the Logical Address obtained by the module
269 *
270 * This function gets the logical address for the specified device type. @n
271 * For sink devices, if logical address is not added or removed,
272 * the logical address returned will be 0x0F.
273 * For source devices, logical address returned must be in between 0x00 and 0x0F,
274 * excluding both the values.
275 *
276 * @param[in] handle - The handle returned from the HdmiCecOpen(). Non zero value
277 * @param [in] devType - device type (tuner, record, playback etc.).
278 * @param[out] logicalAddress - The logical address acquired
279 *
280 * @return Error Code - Status
281 * @retval HDMI_CEC_IO_SUCCESS - Success
282 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - Parameter passed to this function is invalid
283 *
284 * @pre HdmiCecOpen() must be called before calling this API.
285 *
286 * @warning This API is NOT thread safe.
287 *
288 * @note This API is not required if the SOC is performing the logical address discovery.
289 *
290 * @see HdmiCecAddLogicalAddress(), HdmiCecRemoveLogicalAddress()
291 *
292 */
293int HdmiCecGetLogicalAddress(int handle, int devType, int *logicalAddress);
294
295/**
296 * @brief Sets CEC packet receive callback
297 *
298 * This function sets the callback function to be invoked for each packet arrival@n
299 * The packet contained in the buffer will follow this format
300 * (ref <HDMI Specification 1-4> Section <CEC 6.1>) :
301 *
302 * complete packet = header block + data block@n
303 * header block = destination logical address (4-bit) + source address (4-bit)@n
304 * data block = opcode block (8-bit) + operand block (N-bytes)
305 *
306 * @code
307 * |------------------------------------------------
308 * | header block | data blocks |
309 * |------------------------------------------------
310 * |3|2|1|0|3|2|1|0|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
311 * |------------------------------------------------
312 * | Dest | src | opcode block | operand block |
313 * |------------------------------------------------
314 * @endcode
315 *
316 * When receiving, the returned buffer should not contain EOM and ACK bits. HAL internal logic.@n
317 * HAL implementation should remove the EOM and ACK bits in the returned buffer
318 *
319 * When transmitting, it is HAL's responsibility to insert EOM bit and ACK bit
320 * for each header or data block.
321 *
322 * When HdmiCecSetRxCallback() is called, it replaces the previous set cbfunc and data
323 * values. Setting a value of (cbfunc=null) disables the callback.
324 *
325 * This function will block if callback invocation is in progress.
326 *
327 * @param[in] handle - The handle returned from the HdmiCecOpen(() function. Non zero value
328 * @param[in] cbfunc - Function pointer to be invoked when a complete packet is received. Please refer ::HdmiCecRxCallback_t
329 * @param[in] data - Callback data
330 *
331 * @return Error Code - Status
332 * @retval HDMI_CEC_IO_SUCCESS - Success
333 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - An invalid argument has been passed
334 *
335 * @pre HdmiCecOpen() must be called before calling this API.
336 *
337 * @warning This API is NOT thread safe.
338 *
339 * @see HdmiCecTx(), HdmiCecTxAsync(), HdmiCecSetTxCallback()
340 *
341 */
342int HdmiCecSetRxCallback(int handle, HdmiCecRxCallback_t cbfunc, void *data);
343
344/**
345 * @brief Sets CEC packet transmit callback
346 *
347 * This function sets a callback which will be invoked once the async transmit
348 * result is available. This is only necessary if the caller chooses to transmit
349 * the packet asynchronously.
350 *
351 * This function will block if callback invocation is in progress.
352 *
353 * @param[in] handle - The handle returned from the HdmiCecOpen(). Non zero value.
354 * @param[in] cbfunc - Function pointer to be invoked when a complete packet is transmitted. Please refer ::HdmiCecTxCallback_t
355 * @param[in] data - Callback data
356 *
357 * @return Error Code - Status
358 * @retval HDMI_CEC_IO_SUCCESS - Success
359 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - An invalid argument has been passed
360 *
361 * @pre HdmiCecOpen() must be called before calling this API.
362 *
363 * @warning This API is NOT thread safe.
364 *
365 * @see HdmiCecTx(), HdmiCecTxAsync()
366 *
367 */
368int HdmiCecSetTxCallback(int handle, HdmiCecTxCallback_t cbfunc, void *data);
369
370/**
371 * @brief Synchronous transmit call
372 *
373 * This function writes a complete CEC packet onto the bus and waits for ACK.
374 *
375 * The packet contained in the buffer will follow the format detailed in HdmiCecSetRxCallback_t().
376 * (ref <HDMI Specification 1-4> Section <CEC 6.1>)
377 *
378 *
379 * @param[in] handle - The handle returned from the HdmiCecOpen() function. Non zero value
380 * @param[in] buf - The buffer contains a complete CEC packet to send.
381 * @param[in] len - Number of bytes in the packet.
382 * @param[out] result - send status buffer. Possible results are
383 * SENT_AND_ACKD,
384 * SENT_BUT_NOT_ACKD (e.g. no follower at the destination),
385 * SENT_FAILED (e.g. collision).
386 *
387 * @return Error Code - Status
388 * @retval HDMI_CEC_IO_SUCCESS - Success
389 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - Parameter passed to this function is invalid
390 * @retval HDMI_CEC_IO_SENT_AND_ACKD - Cec message is send and acknowledged.
391 * @retval HDMI_CEC_IO_SENT_BUT_NOT_ACKD - Message sent but not acknowledged by the receiver. Host device is trying to send an invalid logical address
392 * @retval HDMI_CEC_IO_SENT_FAILED - Send message failed
393 *
394 * @pre HdmiCecOpen(), HdmiCecSetRxCallback() should be called before calling this API.
395 *
396 * @warning This API is Not thread safe.
397 *
398 * @see HdmiCecTxAsync(), HdmiCecSetRxCallback()
399 *
400 */
401int HdmiCecTx(int handle, const unsigned char *buf, int len, int *result);
402
403/**
404 * @brief Writes CEC packet onto bus asynchronously.
405 *
406 * This function writes a complete CEC packet onto the bus but does not wait
407 * for ACK. The result will be reported via HdmiCecRxCallback_t()
408 *
409 * @param[in] handle - The handle returned from the HdmiCecOpen() function. Non zero value
410 * @param[in] buf - The buffer contains a complete CEC packet to send
411 * @param[in] len - Number of bytes in the packet
412 *
413 * @return Error Code - Status
414 * @retval HDMI_CEC_IO_SUCCESS - Success
415 * @retval HDMI_CEC_IO_INVALID_ARGUMENT - Parameter passed to this function is invalid
416 *
417 * @pre HdmiCecOpen(), HdmiCecSetRxCallback(), HdmiCecSetTxCallback() should be called before calling this API.
418 *
419 * @warning This API is Not thread safe.
420 *
421 * @see HdmiCecTx(), HdmiCecSetRxCallback()
422 *
423 */
424int HdmiCecTxAsync(int handle, const unsigned char *buf, int len);
425
426#ifdef __cplusplus
427}
428#endif
429#endif // End of HDMI_CEC_DRIVER_H__
430
431/** @} */ // End of HDMI_CEC_DRIVER_H
432/** @} */ // End of HDMI_CEC_HAL
433/** @} */ // End of HDMI_CEC
434/** @} */ // End of HPK
void HdmiCecGetPhysicalAddress(int handle, unsigned int *physicalAddress)
Gets the Physical Address obtained by the module.
int HdmiCecTxAsync(int handle, const unsigned char *buf, int len)
Writes CEC packet onto bus asynchronously.
int HdmiCecSetLogicalAddress(int handle, int *logicalAddresses, int num)
This API is DEPRECATED due to possible race conditions competing for a logical address.
void(* HdmiCecTxCallback_t)(int handle, void *callbackData, int result)
Callback function triggered to report the status of the latest transmit message.
Definition hdmi_cec_driver.h:110
int HdmiCecAddLogicalAddress(int handle, int logicalAddresses)
Adds one Logical Addresses to be used by host device.
int HdmiCecClose(int handle)
Closes an instance of HDMI CEC HAL.
int HdmiCecGetLogicalAddress(int handle, int devType, int *logicalAddress)
Gets the Logical Address obtained by the module.
int HdmiCecSetRxCallback(int handle, HdmiCecRxCallback_t cbfunc, void *data)
Sets CEC packet receive callback.
int HdmiCecSetTxCallback(int handle, HdmiCecTxCallback_t cbfunc, void *data)
Sets CEC packet transmit callback.
int HdmiCecOpen(int *handle)
Initializes the HDMI CEC HAL.
int HdmiCecRemoveLogicalAddress(int handle, int logicalAddresses)
Clears the Logical Addresses claimed by the host device.
int HdmiCecTx(int handle, const unsigned char *buf, int len, int *result)
Synchronous transmit call.
void(* HdmiCecRxCallback_t)(int handle, void *callbackData, unsigned char *buf, int len)
Callback function triggered when a complete CEC packet is received.
Definition hdmi_cec_driver.h:101
@ HDMI_CEC_IO_INVALID_STATE
Definition hdmi_cec_driver.h:85
@ HDMI_CEC_IO_SUCCESS
Input output operation is successful.
Definition hdmi_cec_driver.h:81
@ HDMI_CEC_IO_SENT_BUT_NOT_ACKD
Sent but acknowledgement not received.
Definition hdmi_cec_driver.h:83
@ HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE
Logical address is not available.
Definition hdmi_cec_driver.h:87
@ HDMI_CEC_IO_INVALID_ARGUMENT
Invalid argument is passed to the module.
Definition hdmi_cec_driver.h:86
@ HDMI_CEC_IO_SENT_FAILED
Operation failed.
Definition hdmi_cec_driver.h:84
@ HDMI_CEC_IO_SENT_AND_ACKD
Send and acknowledgement received.
Definition hdmi_cec_driver.h:82
@ HDMI_CEC_IO_GENERAL_ERROR
Operation general error.
Definition hdmi_cec_driver.h:88