ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
adi_i2c_def.h
1 
43 #ifndef ADI_I2C_DEF_H
44 #define ADI_I2C_DEF_H
45 
48 #include <drivers/i2c/adi_i2c.h>
49 
50 #define ADI_I2C_NUM_INSTANCES (1u)
51 #define ADI_I2C_STATUS_ERROR_MASK ( (1u << BITP_I2C_MSTAT_NACKADDR) \
52  | (1u << BITP_I2C_MSTAT_NACKDATA) \
53  | (1u << BITP_I2C_MSTAT_ALOST) )
54 
55 /* Internal Actions */
56 static void submitTransaction (ADI_I2C_HANDLE const hDevice, ADI_I2C_TRANSACTION* const pTransaction);
57 static void commenceTransmit (ADI_I2C_HANDLE const hDevice);
58 static void commenceReceive (ADI_I2C_HANDLE const hDevice);
59 static ADI_I2C_RESULT i2cReset (ADI_I2C_HANDLE const hDevice);
60 
61 /* interrupt event handlers */
62 static void transmitHandler (ADI_I2C_HANDLE const hDevice);
63 static void receiveHandler (ADI_I2C_HANDLE const hDevice);
64 static void completeHandler (ADI_I2C_HANDLE const hDevice);
65 static void errorHandler (ADI_I2C_HANDLE const hDevice);
66 
67 #if defined(__ADUCM302x__)
68 /*
69  * SYS Device Structure
70  */
71 typedef struct _ADI_SYS_STRUCT
72 {
73  ADI_SYS_TypeDef *pReg; /* Pointer to register base */
74 } ADI_SYS_STRUCT;
75 
76 /* alias for the actual device structure */
77 typedef struct _ADI_SYS_STRUCT ADI_SYS_REGISTERS;
78 
79 #endif
80 /*
81  *****************************************************************************
82  * I2C Configuration structure.
83  *****************************************************************************/
84 typedef struct __ADI_I2C_CONFIG {
85  uint16_t MasterControlRegister; /* I2C_MCTL register configuration. */
86  uint16_t ClockDividerRegister; /* I2C_DIV register. */
87  uint16_t SharedControlRegister; /* I2C_DIV register. */
88  uint16_t TimingControlRegister; /* I2C_TCTL register. */
89  uint16_t ClockStretchRegister; /* I2C_ASTRETCH register. */
90  uint16_t TargetSlaveAddress; /* slave address value (not a register). */
91 } ADI_I2C_CONFIG;
92 
93 
94 /* I2C physical device instance data */
95 typedef struct __ADI_I2C_DEVICE_INFO {
96  IRQn_Type pioIRQn; /* PIO interrupt number */
97  ADI_I2C_TypeDef *pDev; /* pointer to i2c controller */
98  ADI_I2C_CONFIG *pConfig; /* pointer to user config info */
99  ADI_I2C_HANDLE hDevice; /* I2C handle or NULL if uninitialized */
100 } ADI_I2C_DEVICE_INFO;
101 
102 /* I2C driver instance data structure */
103 typedef struct __ADI_I2C_DEV_DATA_TYPE {
104 
105  /* make sure to synchronize ANY size changes with ADI_I2C_MEMORY_SIZE macro in adi_i2c.h */
106 
107  /* device attributes */
108  ADI_I2C_TypeDef *pDev;
109  ADI_I2C_DEVICE_INFO *pDevInfo;
110 
111 
112  /* driver state */
113  uint16_t hwStatus;
114  bool bRepeatStart;
115  uint16_t i2cDeviceAddress;
116  uint16_t i2cEncodedDeviceAddress; /* encoded as 7-bit device address + r/w LSB */
117  bool bSubmitCalled;
118 
119  /* prologue data */
120  volatile uint8_t *pNextPrologueByte;
121  volatile uint16_t remainingPrologueCount;
122 
123  /* write data */
124  volatile uint8_t *pNextWriteByte;
125  volatile uint16_t remainingWriteCount;
126 
127  /* read data */
128  volatile uint8_t *pNextReadByte;
129  volatile uint16_t remainingReadCount;
130 
131  ADI_I2C_RESULT result; /* collector for return status */
132  ADI_I2C_HW_ERRORS hwErrors; /* collector for error status */
133 
134  SEM_VAR_DECLR /* blocking object: "Semaphore" for rtos, "nLowPowerExitFlag" for non-rtos */
135 
136 } ADI_I2C_DEV_DATA_TYPE;
137 
140 #endif /* end of ifndef ADI_I2C_DEF_H */
141 
struct __ADI_I2C_DEV_DATA_TYPE * ADI_I2C_HANDLE
Definition: adi_i2c.h:127
ADI_I2C_HW_ERRORS
Definition: adi_i2c.h:115
ADI_I2C_RESULT
Definition: adi_i2c.h:86