PDK API Guide for J721E
I2C.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2018 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
39 /* @} */
40 
136 #ifndef I2C_H
137 #define I2C_H
138 
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142 
143 #include <stdint.h>
144 #include <stdbool.h>
145 #include <stddef.h>
157 #define I2C_CMD_RESERVED 32
158 
164 #define I2C_CMD_PROBE (0U)
165 
172 #define I2C_CMD_SET_BUS_FREQUENCY (1U)
173 
180 #define I2C_CMD_RECOVER_BUS (2U)
181 
189 #define I2C_CMD_SMBUS_TYPE (3U)
190 
203 #define I2C_STATUS_RESERVED (-((int32_t)32))
204 
211 #define I2C_STATUS_SUCCESS ((int32_t)(0))
212 
219 #define I2C_STATUS_ERROR (-((int32_t)1))
220 
228 #define I2C_STATUS_UNDEFINEDCMD (-((int32_t)2))
229 
230 
236 #define I2C_STS_SUCCESS ((int16_t)(1))
237 
244 #define I2C_STS_RESTART ((int16_t)(2))
245 
251 #define I2C_STS_ERR ((int16_t)(0))
252 
259 #define I2C_STS_ERR_TIMEOUT (-(int16_t)(1))
260 
263 #define I2C_STS_ERR_BUS_BUSY (-(int16_t)(2))
264 
267 #define I2C_STS_ERR_NO_ACK (-(int16_t)(3))
268 
271 #define I2C_STS_ERR_ARBITRATION_LOST (-(int16_t)(4))
272 
275 #define I2C_STS_ERR_ACCESS_ERROR (-(int16_t)(5))
276 
279 #define I2C_STS_ERR_COMMAND_FAILURE (-(int16_t)(6))
280 
283 #define I2C_STS_ERR_INVALID_COMMAND (-(int16_t)(7))
284 
288 typedef struct I2C_Config_s *I2C_Handle;
289 
299 #define I2C_TRANS_VALID_PARAM_MASTER_MODE (0x00000001U)
300 #define I2C_TRANS_VALID_PARAM_EXPAND_SA (0x00000002U)
301 
327 typedef struct I2C_Transaction_s {
328  uint32_t validParams;
332  void *writeBuf;
334  /* User input (requested write count) and output (actual write count) fields */
335  size_t writeCount;
338  void *readBuf;
340  /* User input (requested read count) and output (actual read count) fields */
341  size_t readCount;
344  uint32_t slaveAddress;
350  void *arg;
351  void *nextPtr;
352  uint32_t timeout;
354  bool masterMode;
355  bool expandSA;
358 
366 typedef enum I2C_TransferMode_e {
370 
389 typedef void (*I2C_CallbackFxn)(I2C_Handle handle, I2C_Transaction * msg, int16_t transferStatus);
390 
397 typedef enum I2C_BitRate_e {
402 } I2C_BitRate;
403 
424 typedef struct I2C_Params_s {
427  /* done to get rid of misra warning MISRA.CAST.FUNC_PTR, it complains later where the function address is assigned */
428  void (*transferCallbackFxn)(I2C_Handle i2cHnd, I2C_Transaction * msg, int16_t transferStatus);
429  /* I2C_CallbackFxn transferCallbackFxn; !< Callback function pointer */
431  void *custom;
433 } I2C_Params;
434 
438 #define I2C_WAIT_FOREVER (~((uint32_t)0U))
439 
444 typedef void (*I2C_CloseFxn) (I2C_Handle handle);
445 
450 typedef int32_t (*I2C_ControlFxn) (I2C_Handle handle,
451  uint32_t cmd,
452  void *arg);
453 
458 typedef void (*I2C_InitFxn) (I2C_Handle handle);
459 
464 typedef I2C_Handle (*I2C_OpenFxn) (I2C_Handle handle,
465  const I2C_Params *params);
466 
471 typedef int16_t (*I2C_TransferFxn) (I2C_Handle handle,
472  I2C_Transaction *transaction);
473 
479 typedef struct I2C_FxnTable_s {
482 
485 
488 
491 
494 } I2C_FxnTable;
495 
507 typedef struct I2C_Config_s {
510 
512  void *object;
513 
515  void const *hwAttrs;
516 } I2C_Config;
517 
518 #define I2C_MAX_CONFIG_CNT (14U)
520 
521 
531 extern void I2C_close(I2C_Handle i2cHnd);
532 
552 extern int32_t I2C_control(I2C_Handle i2cHnd, uint32_t cmd, void *arg);
553 
562 extern void I2C_init(void);
563 
584 extern I2C_Handle I2C_open(uint32_t idx, I2C_Params *params);
585 
597 extern void I2C_Params_init(I2C_Params *params);
598 
639 extern int16_t I2C_transfer(I2C_Handle i2cHnd, I2C_Transaction *transaction);
640 
660 extern void I2C_transactionInit(I2C_Transaction *transaction);
661 
662 #ifdef __cplusplus
663 }
664 #endif
665 
666 #endif /* _I2C_H_ */
667 
668 /* @} */
void * arg
Definition: I2C.h:350
I2C_InitFxn initFxn
Definition: I2C.h:487
void * custom
Definition: I2C.h:431
void I2C_close(I2C_Handle i2cHnd)
Function to close a I2C peripheral specified by the I2C handle.
I2C Parameters.
Definition: I2C.h:424
void I2C_init(void)
Function to initializes the I2C module.
void * nextPtr
Definition: I2C.h:351
I2C_TransferFxn transferFxn
Definition: I2C.h:493
I2C_Handle(* I2C_OpenFxn)(I2C_Handle handle, const I2C_Params *params)
A function pointer to a driver specific implementation of I2C_open().
Definition: I2C.h:464
Definition: I2C.h:399
int32_t I2C_control(I2C_Handle i2cHnd, uint32_t cmd, void *arg)
Function performs implementation specific features on a given I2C_Handle.
Definition: I2C.h:398
I2C_BitRate bitRate
Definition: I2C.h:430
I2C_Config I2C_config_list[I2C_MAX_CONFIG_CNT]
Definition: I2C.h:519
Definition: I2C.h:327
I2C_CloseFxn closeFxn
Definition: I2C.h:481
void * writeBuf
Definition: I2C.h:332
uint32_t validParams
Definition: I2C.h:328
I2C_TransferMode
I2C transfer mode.
Definition: I2C.h:366
Definition: I2C.h:400
void const * hwAttrs
Definition: I2C.h:515
void * object
Definition: I2C.h:512
uint32_t timeout
Definition: I2C.h:352
int16_t I2C_transfer(I2C_Handle i2cHnd, I2C_Transaction *transaction)
Function that handles the I2C transfer for SYS/BIOS.
uint32_t slaveAddress
Definition: I2C.h:344
int16_t(* I2C_TransferFxn)(I2C_Handle handle, I2C_Transaction *transaction)
A function pointer to a driver specific implementation of I2C_transfer().
Definition: I2C.h:471
void I2C_Params_init(I2C_Params *params)
Function to initialize the I2C_Params struct to its defaults.
I2C_Handle I2C_open(uint32_t idx, I2C_Params *params)
Function to initialize a given I2C peripheral specified by the particular index value....
bool expandSA
Definition: I2C.h:355
I2C Global configuration.
Definition: I2C.h:507
void(* I2C_InitFxn)(I2C_Handle handle)
A function pointer to a driver specific implementation of I2C_init().
Definition: I2C.h:458
gptp_ipc_command_t cmd
Definition: gptpipc.h:140
Definition: I2C.h:368
#define I2C_MAX_CONFIG_CNT
Definition: I2C.h:518
size_t readCount
Definition: I2C.h:341
size_t writeCount
Definition: I2C.h:335
struct I2C_Config_s * I2C_Handle
A handle that is returned from a I2C_open() call.
Definition: I2C.h:288
void * readBuf
Definition: I2C.h:338
bool masterMode
Definition: I2C.h:354
void(* I2C_CloseFxn)(I2C_Handle handle)
A function pointer to a driver specific implementation of I2C_close().
Definition: I2C.h:444
int32_t(* I2C_ControlFxn)(I2C_Handle handle, uint32_t cmd, void *arg)
A function pointer to a driver specific implementation of I2C_control().
Definition: I2C.h:450
void(* I2C_CallbackFxn)(I2C_Handle handle, I2C_Transaction *msg, int16_t transferStatus)
I2C callback function.
Definition: I2C.h:389
I2C_FxnTable const * fxnTablePtr
Definition: I2C.h:509
Definition: I2C.h:401
Definition: I2C.h:367
void I2C_transactionInit(I2C_Transaction *transaction)
I2C_TransferMode transferMode
Definition: I2C.h:425
I2C_BitRate
I2C bitRate.
Definition: I2C.h:397
I2C_OpenFxn openFxn
Definition: I2C.h:490
The definition of a I2C function table that contains the required set of functions to control a speci...
Definition: I2C.h:479
I2C_ControlFxn controlFxn
Definition: I2C.h:484