ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
adi_i2c_def.h
1 
13 #ifndef ADI_I2C_DEF_H
14 #define ADI_I2C_DEF_H
15 
18 #include <drivers/i2c/adi_i2c.h>
19 
20 #define ADI_I2C_NUM_INSTANCES (1u)
21 #define ADI_I2C_STATUS_ERROR_MASK ( (1u << BITP_I2C_MSTAT_NACKADDR) \
22  | (1u << BITP_I2C_MSTAT_NACKDATA) \
23  | (1u << BITP_I2C_MSTAT_MRXOVR) \
24  | (1u << BITP_I2C_MSTAT_MTXUNDR) \
25  | (1u << BITP_I2C_MSTAT_ALOST) )
26 
27 /* Internal Actions */
28 static void submitTransaction (ADI_I2C_HANDLE const hDevice, ADI_I2C_TRANSACTION* const pTransaction);
29 static void commenceTransmit (ADI_I2C_HANDLE const hDevice);
30 static void commenceReceive (ADI_I2C_HANDLE const hDevice);
31 static ADI_I2C_RESULT i2cReset (ADI_I2C_HANDLE const hDevice);
32 
33 /* interrupt event handlers */
34 static void transmitHandler (ADI_I2C_HANDLE const hDevice);
35 static void receiveHandler (ADI_I2C_HANDLE const hDevice);
36 static void completeHandler (ADI_I2C_HANDLE const hDevice);
37 static void errorHandler (ADI_I2C_HANDLE const hDevice);
38 
39 #if defined(__ADUCM302x__)
40 /*
41  * SYS Device Structure
42  */
43 typedef struct _ADI_SYS_STRUCT
44 {
45  ADI_SYS_TypeDef *pReg; /* Pointer to register base */
46 } ADI_SYS_STRUCT;
47 
48 /* alias for the actual device structure */
49 typedef struct _ADI_SYS_STRUCT ADI_SYS_REGISTERS;
50 
51 #endif
52 /*
53  *****************************************************************************
54  * I2C Configuration structure.
55  *****************************************************************************/
56 typedef struct __ADI_I2C_CONFIG {
57  uint16_t MasterControlRegister; /* I2C_MCTL register configuration. */
58  uint16_t ClockDividerRegister; /* I2C_DIV register. */
59  uint16_t SharedControlRegister; /* I2C_DIV register. */
60  uint16_t TimingControlRegister; /* I2C_TCTL register. */
61  uint16_t ClockStretchRegister; /* I2C_ASTRETCH register. */
62  uint16_t TargetSlaveAddress; /* slave address value (not a register). */
63 } ADI_I2C_CONFIG;
64 
65 
66 /* I2C physical device instance data */
67 typedef struct __ADI_I2C_DEVICE_INFO {
68  IRQn_Type pioIRQn; /* PIO interrupt number */
69  ADI_I2C_TypeDef *pDev; /* pointer to i2c controller */
70  ADI_I2C_CONFIG *pConfig; /* pointer to user config info */
71  ADI_I2C_HANDLE hDevice; /* I2C handle or NULL if uninitialized */
72 } ADI_I2C_DEVICE_INFO;
73 
74 /* I2C driver instance data structure */
75 typedef struct __ADI_I2C_DEV_DATA_TYPE {
76 
77  /* make sure to synchronize ANY size changes with ADI_I2C_MEMORY_SIZE macro in adi_i2c.h */
78 
79  /* device attributes */
80  ADI_I2C_TypeDef *pDev;
81  ADI_I2C_DEVICE_INFO *pDevInfo;
82 
83 
84  /* driver state */
85  uint16_t hwStatus;
86  bool bRepeatStart;
87  uint16_t i2cDeviceAddress;
88  uint16_t i2cEncodedDeviceAddress; /* encoded as 7-bit device address + r/w LSB */
89  bool bSubmitCalled;
90 
91  /* prologue data */
92  volatile uint8_t *pNextPrologueByte;
93  volatile uint16_t remainingPrologueCount;
94 
95  /* write data */
96  volatile uint8_t *pNextWriteByte;
97  volatile uint16_t remainingWriteCount;
98 
99  /* read data */
100  volatile uint8_t *pNextReadByte;
101  volatile uint16_t remainingReadCount;
102 
103  volatile uint16_t nBytesProcessed;
104 
105  ADI_I2C_RESULT result; /* collector for return status */
106  ADI_I2C_HW_ERRORS hwErrors; /* collector for error status */
107  ADI_I2C_HW_ERRORS hwMaskedErrors; /* masked errors */
108 
109  SEM_VAR_DECLR /* blocking object: "Semaphore" for rtos, "nLowPowerExitFlag" for non-rtos */
110 
111 } ADI_I2C_DEV_DATA_TYPE;
112 
115 #endif /* end of ifndef ADI_I2C_DEF_H */
116 
struct __ADI_I2C_DEV_DATA_TYPE * ADI_I2C_HANDLE
Definition: adi_i2c.h:97
ADI_I2C_HW_ERRORS
Definition: adi_i2c.h:84
ADI_I2C_RESULT
Definition: adi_i2c.h:55