1 /******************************************************************************
2 *
3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4 * Analog Devices, Inc.),
5 * Copyright (C) 2023-2024 Analog Devices, Inc.
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 #include <stdio.h>
22 #include <stddef.h>
23 #include <stdint.h>
24 #include "mxc_errors.h"
25 #include "mxc_delay.h"
26 #include "mxc_assert.h"
27 #include "mxc_lock.h"
28 #include "mxc_sys.h"
29 #include "i2c_revb.h"
30 #include "i2c_reva.h"
31
32 /* **** Definitions **** */
33
34 /* **** Variable Declaration **** */
35
36 // Saves the state of the non-blocking requests
37 typedef struct {
38 mxc_i2c_revb_req_t *req;
39 int master; // 1 for Master, 0 for slave
40 int channelTx; // DMA channel for TX transaction
41 int channelRx; // DMA channel for RX transaction
42 int writeDone; // Write done flag
43 int readDone; // Flag done flag
44 } mxc_i2c_revb_req_state_t;
45
46 /* ************************************************************************* */
47 /* Control/Configuration functions */
48 /* ************************************************************************* */
49
MXC_I2C_RevB_Init(mxc_i2c_revb_regs_t * i2c,int masterMode,unsigned int slaveAddr)50 int MXC_I2C_RevB_Init(mxc_i2c_revb_regs_t *i2c, int masterMode, unsigned int slaveAddr)
51 {
52 return MXC_I2C_RevA_Init((mxc_i2c_reva_regs_t *)i2c, masterMode, slaveAddr);
53 }
54
MXC_I2C_RevB_SetSlaveAddr(mxc_i2c_revb_regs_t * i2c,unsigned int slaveAddr,int idx)55 int MXC_I2C_RevB_SetSlaveAddr(mxc_i2c_revb_regs_t *i2c, unsigned int slaveAddr, int idx)
56 {
57 if (i2c == NULL || slaveAddr > MXC_F_I2C_REVB_SLV_ADDR_SLA || idx != 0) {
58 return E_BAD_PARAM;
59 }
60
61 i2c->slv_addr = 0;
62
63 if (slaveAddr > MXC_I2C_REVB_MAX_ADDR_WIDTH) {
64 i2c->slv_addr |= MXC_S_I2C_REVB_SLV_ADDR_EA_10BIT_ADDR;
65 }
66
67 i2c->slv_addr |= slaveAddr & MXC_F_I2C_REVB_SLV_ADDR_SLA;
68
69 return E_NO_ERROR;
70 }
71
MXC_I2C_RevB_Shutdown(mxc_i2c_revb_regs_t * i2c)72 int MXC_I2C_RevB_Shutdown(mxc_i2c_revb_regs_t *i2c)
73 {
74 return MXC_I2C_RevA_Shutdown((mxc_i2c_reva_regs_t *)i2c);
75 }
76
MXC_I2C_RevB_SetFrequency(mxc_i2c_revb_regs_t * i2c,unsigned int hz)77 int MXC_I2C_RevB_SetFrequency(mxc_i2c_revb_regs_t *i2c, unsigned int hz)
78 {
79 return MXC_I2C_RevA_SetFrequency((mxc_i2c_reva_regs_t *)i2c, hz);
80 }
81
MXC_I2C_RevB_GetFrequency(mxc_i2c_revb_regs_t * i2c)82 unsigned int MXC_I2C_RevB_GetFrequency(mxc_i2c_revb_regs_t *i2c)
83 {
84 return MXC_I2C_RevA_GetFrequency((mxc_i2c_reva_regs_t *)i2c);
85 }
86
MXC_I2C_RevB_ReadyForSleep(mxc_i2c_revb_regs_t * i2c)87 int MXC_I2C_RevB_ReadyForSleep(mxc_i2c_revb_regs_t *i2c)
88 {
89 return MXC_I2C_RevA_ReadyForSleep((mxc_i2c_reva_regs_t *)i2c);
90 }
91
MXC_I2C_RevB_SetClockStretching(mxc_i2c_revb_regs_t * i2c,int enable)92 int MXC_I2C_RevB_SetClockStretching(mxc_i2c_revb_regs_t *i2c, int enable)
93 {
94 return MXC_I2C_RevA_SetClockStretching((mxc_i2c_reva_regs_t *)i2c, enable);
95 }
96
MXC_I2C_RevB_GetClockStretching(mxc_i2c_revb_regs_t * i2c)97 int MXC_I2C_RevB_GetClockStretching(mxc_i2c_revb_regs_t *i2c)
98 {
99 return MXC_I2C_RevA_GetClockStretching((mxc_i2c_reva_regs_t *)i2c);
100 }
101
102 /* ************************************************************************* */
103 /* Low-level functions */
104 /* ************************************************************************* */
105
MXC_I2C_RevB_Start(mxc_i2c_revb_regs_t * i2c)106 int MXC_I2C_RevB_Start(mxc_i2c_revb_regs_t *i2c)
107 {
108 return MXC_I2C_RevA_Start((mxc_i2c_reva_regs_t *)i2c);
109 }
110
MXC_I2C_RevB_Stop(mxc_i2c_revb_regs_t * i2c)111 int MXC_I2C_RevB_Stop(mxc_i2c_revb_regs_t *i2c)
112 {
113 return MXC_I2C_RevA_Stop((mxc_i2c_reva_regs_t *)i2c);
114 }
115
MXC_I2C_RevB_WriteByte(mxc_i2c_revb_regs_t * i2c,unsigned char byte)116 int MXC_I2C_RevB_WriteByte(mxc_i2c_revb_regs_t *i2c, unsigned char byte)
117 {
118 return MXC_I2C_RevA_WriteByte((mxc_i2c_reva_regs_t *)i2c, byte);
119 }
120
MXC_I2C_RevB_ReadByte(mxc_i2c_revb_regs_t * i2c,unsigned char * byte,int ack)121 int MXC_I2C_RevB_ReadByte(mxc_i2c_revb_regs_t *i2c, unsigned char *byte, int ack)
122 {
123 return MXC_I2C_RevA_ReadByte((mxc_i2c_reva_regs_t *)i2c, byte, ack);
124 }
125
MXC_I2C_RevB_ReadByteInteractive(mxc_i2c_revb_regs_t * i2c,unsigned char * byte,mxc_i2c_revb_getAck_t getAck)126 int MXC_I2C_RevB_ReadByteInteractive(mxc_i2c_revb_regs_t *i2c, unsigned char *byte,
127 mxc_i2c_revb_getAck_t getAck)
128 {
129 return MXC_I2C_RevA_ReadByteInteractive((mxc_i2c_reva_regs_t *)i2c, byte,
130 (mxc_i2c_reva_getAck_t)getAck);
131 }
132
MXC_I2C_RevB_Write(mxc_i2c_revb_regs_t * i2c,unsigned char * bytes,unsigned int * len)133 int MXC_I2C_RevB_Write(mxc_i2c_revb_regs_t *i2c, unsigned char *bytes, unsigned int *len)
134 {
135 return MXC_I2C_RevA_Write((mxc_i2c_reva_regs_t *)i2c, bytes, len);
136 }
137
MXC_I2C_RevB_Read(mxc_i2c_revb_regs_t * i2c,unsigned char * bytes,unsigned int * len,int ack)138 int MXC_I2C_RevB_Read(mxc_i2c_revb_regs_t *i2c, unsigned char *bytes, unsigned int *len, int ack)
139 {
140 return MXC_I2C_RevA_Read((mxc_i2c_reva_regs_t *)i2c, bytes, len, ack);
141 }
142
MXC_I2C_RevB_ReadRXFIFO(mxc_i2c_revb_regs_t * i2c,volatile unsigned char * bytes,unsigned int len)143 int MXC_I2C_RevB_ReadRXFIFO(mxc_i2c_revb_regs_t *i2c, volatile unsigned char *bytes,
144 unsigned int len)
145 {
146 return MXC_I2C_RevA_ReadRXFIFO((mxc_i2c_reva_regs_t *)i2c, bytes, len);
147 }
148
MXC_I2C_RevB_ReadRXFIFODMA(mxc_i2c_revb_regs_t * i2c,unsigned char * bytes,unsigned int len,mxc_dma_regs_t * dma)149 int MXC_I2C_RevB_ReadRXFIFODMA(mxc_i2c_revb_regs_t *i2c, unsigned char *bytes, unsigned int len,
150 mxc_dma_regs_t *dma)
151 {
152 return MXC_I2C_RevA_ReadRXFIFODMA((mxc_i2c_reva_regs_t *)i2c, bytes, len, dma);
153 }
154
MXC_I2C_RevB_GetRXFIFOAvailable(mxc_i2c_revb_regs_t * i2c)155 int MXC_I2C_RevB_GetRXFIFOAvailable(mxc_i2c_revb_regs_t *i2c)
156 {
157 return MXC_I2C_RevA_GetRXFIFOAvailable((mxc_i2c_reva_regs_t *)i2c);
158 }
159
MXC_I2C_RevB_WriteTXFIFO(mxc_i2c_revb_regs_t * i2c,volatile unsigned char * bytes,unsigned int len)160 int MXC_I2C_RevB_WriteTXFIFO(mxc_i2c_revb_regs_t *i2c, volatile unsigned char *bytes,
161 unsigned int len)
162 {
163 return MXC_I2C_RevA_WriteTXFIFO((mxc_i2c_reva_regs_t *)i2c, bytes, len);
164 }
165
MXC_I2C_RevB_WriteTXFIFODMA(mxc_i2c_revb_regs_t * i2c,unsigned char * bytes,unsigned int len,mxc_dma_regs_t * dma)166 int MXC_I2C_RevB_WriteTXFIFODMA(mxc_i2c_revb_regs_t *i2c, unsigned char *bytes, unsigned int len,
167 mxc_dma_regs_t *dma)
168 {
169 return MXC_I2C_RevA_WriteTXFIFODMA((mxc_i2c_reva_regs_t *)i2c, bytes, len, dma);
170 }
171
MXC_I2C_RevB_GetTXFIFOAvailable(mxc_i2c_revb_regs_t * i2c)172 int MXC_I2C_RevB_GetTXFIFOAvailable(mxc_i2c_revb_regs_t *i2c)
173 {
174 return MXC_I2C_RevA_GetTXFIFOAvailable((mxc_i2c_reva_regs_t *)i2c);
175 }
176
MXC_I2C_RevB_ClearRXFIFO(mxc_i2c_revb_regs_t * i2c)177 void MXC_I2C_RevB_ClearRXFIFO(mxc_i2c_revb_regs_t *i2c)
178 {
179 MXC_I2C_RevA_ClearRXFIFO((mxc_i2c_reva_regs_t *)i2c);
180 }
181
MXC_I2C_RevB_ClearTXFIFO(mxc_i2c_revb_regs_t * i2c)182 void MXC_I2C_RevB_ClearTXFIFO(mxc_i2c_revb_regs_t *i2c)
183 {
184 MXC_I2C_RevA_ClearTXFIFO((mxc_i2c_reva_regs_t *)i2c);
185 }
186
MXC_I2C_RevB_GetFlags(mxc_i2c_revb_regs_t * i2c,unsigned int * flags0,unsigned int * flags1)187 int MXC_I2C_RevB_GetFlags(mxc_i2c_revb_regs_t *i2c, unsigned int *flags0, unsigned int *flags1)
188 {
189 return MXC_I2C_RevA_GetFlags((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
190 }
191
MXC_I2C_RevB_ClearFlags(mxc_i2c_revb_regs_t * i2c,unsigned int flags0,unsigned int flags1)192 void MXC_I2C_RevB_ClearFlags(mxc_i2c_revb_regs_t *i2c, unsigned int flags0, unsigned int flags1)
193 {
194 MXC_I2C_RevA_ClearFlags((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
195 }
196
MXC_I2C_RevB_EnableInt(mxc_i2c_revb_regs_t * i2c,unsigned int flags0,unsigned int flags1)197 void MXC_I2C_RevB_EnableInt(mxc_i2c_revb_regs_t *i2c, unsigned int flags0, unsigned int flags1)
198 {
199 MXC_I2C_RevA_EnableInt((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
200 }
201
MXC_I2C_RevB_DisableInt(mxc_i2c_revb_regs_t * i2c,unsigned int flags0,unsigned int flags1)202 void MXC_I2C_RevB_DisableInt(mxc_i2c_revb_regs_t *i2c, unsigned int flags0, unsigned int flags1)
203 {
204 MXC_I2C_RevA_DisableInt((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
205 }
206
MXC_I2C_RevB_EnablePreload(mxc_i2c_revb_regs_t * i2c)207 void MXC_I2C_RevB_EnablePreload(mxc_i2c_revb_regs_t *i2c)
208 {
209 MXC_I2C_RevA_EnablePreload((mxc_i2c_reva_regs_t *)i2c);
210 }
211
MXC_I2C_RevB_DisablePreload(mxc_i2c_revb_regs_t * i2c)212 void MXC_I2C_RevB_DisablePreload(mxc_i2c_revb_regs_t *i2c)
213 {
214 MXC_I2C_RevA_DisablePreload((mxc_i2c_reva_regs_t *)i2c);
215 }
216
MXC_I2C_RevB_EnableGeneralCall(mxc_i2c_revb_regs_t * i2c)217 void MXC_I2C_RevB_EnableGeneralCall(mxc_i2c_revb_regs_t *i2c)
218 {
219 i2c->ctrl0 |= MXC_F_I2C_REVB_CTRL0_GCEN;
220 }
221
MXC_I2C_RevB_DisableGeneralCall(mxc_i2c_revb_regs_t * i2c)222 void MXC_I2C_RevB_DisableGeneralCall(mxc_i2c_revb_regs_t *i2c)
223 {
224 i2c->ctrl0 &= ~MXC_F_I2C_REVB_CTRL0_GCEN;
225 }
226
MXC_I2C_RevB_SetTimeout(mxc_i2c_revb_regs_t * i2c,unsigned int timeout)227 void MXC_I2C_RevB_SetTimeout(mxc_i2c_revb_regs_t *i2c, unsigned int timeout)
228 {
229 MXC_I2C_RevA_SetTimeout((mxc_i2c_reva_regs_t *)i2c, timeout);
230 }
231
MXC_I2C_RevB_GetTimeout(mxc_i2c_revb_regs_t * i2c)232 unsigned int MXC_I2C_RevB_GetTimeout(mxc_i2c_revb_regs_t *i2c)
233 {
234 return MXC_I2C_RevA_GetTimeout((mxc_i2c_reva_regs_t *)i2c);
235 }
236
MXC_I2C_RevB_Recover(mxc_i2c_revb_regs_t * i2c,unsigned int retries)237 int MXC_I2C_RevB_Recover(mxc_i2c_revb_regs_t *i2c, unsigned int retries)
238 {
239 return MXC_I2C_RevA_Recover((mxc_i2c_reva_regs_t *)i2c, retries);
240 }
241
242 /* ************************************************************************* */
243 /* Transaction level functions */
244 /* ************************************************************************* */
245
MXC_I2C_RevB_MasterTransaction(mxc_i2c_revb_req_t * req)246 int MXC_I2C_RevB_MasterTransaction(mxc_i2c_revb_req_t *req)
247 {
248 return MXC_I2C_RevA_MasterTransaction((mxc_i2c_reva_req_t *)req);
249 }
250
MXC_I2C_RevB_MasterTransactionAsync(mxc_i2c_revb_req_t * req)251 int MXC_I2C_RevB_MasterTransactionAsync(mxc_i2c_revb_req_t *req)
252 {
253 return MXC_I2C_RevA_MasterTransactionAsync((mxc_i2c_reva_req_t *)req);
254 }
255
MXC_I2C_RevB_MasterTransactionDMA(mxc_i2c_revb_req_t * req,mxc_dma_regs_t * dma)256 int MXC_I2C_RevB_MasterTransactionDMA(mxc_i2c_revb_req_t *req, mxc_dma_regs_t *dma)
257 {
258 return MXC_I2C_RevA_MasterTransactionDMA((mxc_i2c_reva_req_t *)req, dma);
259 }
260
MXC_I2C_RevB_SlaveTransaction(mxc_i2c_revb_regs_t * i2c,mxc_i2c_revb_slave_handler_t callback,uint32_t interruptCheck)261 int MXC_I2C_RevB_SlaveTransaction(mxc_i2c_revb_regs_t *i2c, mxc_i2c_revb_slave_handler_t callback,
262 uint32_t interruptCheck)
263 {
264 return MXC_I2C_RevA_SlaveTransaction((mxc_i2c_reva_regs_t *)i2c,
265 (mxc_i2c_reva_slave_handler_t)callback, interruptCheck);
266 }
267
MXC_I2C_RevB_SlaveTransactionAsync(mxc_i2c_revb_regs_t * i2c,mxc_i2c_revb_slave_handler_t callback,uint32_t interruptCheck)268 int MXC_I2C_RevB_SlaveTransactionAsync(mxc_i2c_revb_regs_t *i2c,
269 mxc_i2c_revb_slave_handler_t callback,
270 uint32_t interruptCheck)
271 {
272 return MXC_I2C_RevA_SlaveTransactionAsync(
273 (mxc_i2c_reva_regs_t *)i2c, (mxc_i2c_reva_slave_handler_t)callback, interruptCheck);
274 }
275
MXC_I2C_RevB_SetRXThreshold(mxc_i2c_revb_regs_t * i2c,unsigned int numBytes)276 int MXC_I2C_RevB_SetRXThreshold(mxc_i2c_revb_regs_t *i2c, unsigned int numBytes)
277 {
278 return MXC_I2C_RevA_SetRXThreshold((mxc_i2c_reva_regs_t *)i2c, numBytes);
279 }
280
MXC_I2C_RevB_GetRXThreshold(mxc_i2c_revb_regs_t * i2c)281 unsigned int MXC_I2C_RevB_GetRXThreshold(mxc_i2c_revb_regs_t *i2c)
282 {
283 return MXC_I2C_RevA_GetRXThreshold((mxc_i2c_reva_regs_t *)i2c);
284 }
285
MXC_I2C_RevB_SetTXThreshold(mxc_i2c_revb_regs_t * i2c,unsigned int numBytes)286 int MXC_I2C_RevB_SetTXThreshold(mxc_i2c_revb_regs_t *i2c, unsigned int numBytes)
287 {
288 return MXC_I2C_RevA_SetTXThreshold((mxc_i2c_reva_regs_t *)i2c, numBytes);
289 }
290
MXC_I2C_RevB_GetTXThreshold(mxc_i2c_revb_regs_t * i2c)291 unsigned int MXC_I2C_RevB_GetTXThreshold(mxc_i2c_revb_regs_t *i2c)
292 {
293 return MXC_I2C_RevA_GetTXThreshold((mxc_i2c_reva_regs_t *)i2c);
294 }
295
MXC_I2C_RevB_AsyncCallback(mxc_i2c_revb_regs_t * i2c,int retVal)296 void MXC_I2C_RevB_AsyncCallback(mxc_i2c_revb_regs_t *i2c, int retVal)
297 {
298 MXC_I2C_RevA_AsyncCallback((mxc_i2c_reva_regs_t *)i2c, retVal);
299 }
300
MXC_I2C_RevB_AsyncStop(mxc_i2c_revb_regs_t * i2c)301 void MXC_I2C_RevB_AsyncStop(mxc_i2c_revb_regs_t *i2c)
302 {
303 MXC_I2C_RevA_AsyncStop((mxc_i2c_reva_regs_t *)i2c);
304 }
305
MXC_I2C_RevB_AbortAsync(mxc_i2c_revb_regs_t * i2c)306 void MXC_I2C_RevB_AbortAsync(mxc_i2c_revb_regs_t *i2c)
307 {
308 MXC_I2C_RevA_AbortAsync((mxc_i2c_reva_regs_t *)i2c);
309 }
310
MXC_I2C_RevB_MasterAsyncHandler(int i2cNum)311 void MXC_I2C_RevB_MasterAsyncHandler(int i2cNum)
312 {
313 MXC_I2C_RevA_MasterAsyncHandler(i2cNum);
314 }
315
MXC_I2C_RevB_SlaveAsyncHandler(mxc_i2c_revb_regs_t * i2c,mxc_i2c_revb_slave_handler_t callback,unsigned int interruptEnables,int * retVal)316 unsigned int MXC_I2C_RevB_SlaveAsyncHandler(mxc_i2c_revb_regs_t *i2c,
317 mxc_i2c_revb_slave_handler_t callback,
318 unsigned int interruptEnables, int *retVal)
319 {
320 *retVal = E_NO_ERROR;
321
322 // Callback called on
323 // Slave Address Match (distinguish read/write)
324 // RX Threshold
325 // TX Threshold
326 // Done
327 // TX Underflow
328 // RX Overflow
329 //
330 // Event Codes
331 // I2C_EVT_MASTER_WR
332 // I2C_EVT_MASTER_RD
333 // I2C_EVT_RX_THRESH
334 // I2C_EVT_TX_THRESH
335 // I2C_EVT_TRANS_COMP
336 // I2C_EVT_UNDERFLOW
337 // I2C_EVT_OVERFLOW
338 if (!(interruptEnables & (MXC_F_I2C_REVB_INT_FL0_AMI))) {
339 // The STOPERR/STARTERR interrupt that's enabled here could fire before we are addressed
340 // (fires anytime a stop/start is detected out of sequence).
341 if (i2c->int_fl0 & MXC_I2C_REVB_ERROR) {
342 *retVal = E_COMM_ERR;
343 callback(i2c, MXC_I2C_REVB_EVT_TRANS_COMP, retVal);
344 MXC_I2C_ClearFlags((mxc_i2c_regs_t *)i2c, MXC_I2C_REVB_INTFL0_MASK,
345 MXC_I2C_REVB_INTFL1_MASK); // Clear all I2C Interrupts
346 MXC_I2C_ClearTXFIFO((mxc_i2c_regs_t *)i2c);
347 MXC_I2C_ClearRXFIFO((mxc_i2c_regs_t *)i2c);
348 interruptEnables = 0;
349 AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL;
350 }
351
352 if (interruptEnables & (MXC_F_I2C_REVB_INT_FL0_RXTHI | MXC_F_I2C_REVB_INT_FL1_RXOFI)) {
353 if (i2c->int_fl0 & MXC_F_I2C_REVB_INT_FL0_RXTHI) {
354 callback(i2c, MXC_I2C_REVB_EVT_RX_THRESH, NULL);
355 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_RXTHI;
356 }
357
358 if (i2c->int_fl1 & MXC_F_I2C_REVB_INT_FL1_RXOFI) {
359 callback(i2c, MXC_I2C_REVB_EVT_OVERFLOW, NULL);
360 i2c->int_fl1 = MXC_F_I2C_REVB_INT_FL1_RXOFI;
361 }
362 }
363
364 if (interruptEnables & (MXC_F_I2C_REVB_INT_FL0_TXTHI | MXC_F_I2C_REVB_INT_FL1_TXUFI |
365 MXC_F_I2C_REVB_INT_FL0_TXLOI)) {
366 if (i2c->int_fl0 & MXC_F_I2C_REVB_INT_FL0_TXTHI) {
367 callback(i2c, MXC_I2C_REVB_EVT_TX_THRESH, NULL);
368 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_TXTHI;
369 }
370
371 if (i2c->int_fl1 & MXC_F_I2C_REVB_INT_FL1_TXUFI) {
372 callback(i2c, MXC_I2C_REVB_EVT_UNDERFLOW, NULL);
373 i2c->int_fl1 = MXC_F_I2C_REVB_INT_FL1_TXUFI;
374 }
375
376 if (i2c->int_fl0 & MXC_F_I2C_REVB_INT_FL0_TXLOI) {
377 *retVal = E_NO_ERROR;
378 callback(i2c, MXC_I2C_REVB_EVT_TRANS_COMP, retVal);
379 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_TXLOI;
380 interruptEnables = 0;
381 AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL;
382 }
383 }
384
385 if (i2c->int_fl0 & MXC_F_I2C_REVB_INT_FL0_STOPI) {
386 *retVal = E_NO_ERROR;
387 callback(i2c, MXC_I2C_REVB_EVT_TRANS_COMP, retVal);
388 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_STOPI;
389 interruptEnables = 0;
390 AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL;
391 }
392 }
393
394 if (i2c->int_fl0 & MXC_F_I2C_REVB_INT_FL0_AMI) {
395 if (i2c->ctrl0 & MXC_F_I2C_REVB_CTRL0_READ) {
396 callback(i2c, MXC_I2C_REVB_EVT_MASTER_RD, NULL);
397 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_AMI;
398 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_AMI;
399 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_TXLOI;
400 interruptEnables = MXC_F_I2C_REVB_INT_FL0_TXTHI | MXC_F_I2C_REVB_INT_FL1_TXUFI |
401 MXC_F_I2C_REVB_INT_FL0_TXLOI | MXC_I2C_REVB_ERROR;
402 } else {
403 callback(i2c, MXC_I2C_REVB_EVT_MASTER_WR, NULL);
404 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_AMI;
405 i2c->int_fl0 = MXC_F_I2C_REVB_INT_FL0_AMI;
406 interruptEnables = MXC_F_I2C_REVB_INT_FL0_RXTHI | MXC_F_I2C_REVB_INT_FL1_RXOFI |
407 MXC_I2C_REVB_ERROR;
408 }
409 } else if (i2c->int_fl0 & MXC_I2C_REVB_ERROR) {
410 *retVal = E_COMM_ERR;
411 callback(i2c, MXC_I2C_REVB_EVT_TRANS_COMP, retVal);
412 MXC_I2C_RevB_ClearFlags(i2c, MXC_I2C_REVB_INTFL0_MASK,
413 MXC_I2C_REVB_INTFL1_MASK); // clear all i2c interrupts
414 MXC_I2C_RevB_ClearTXFIFO(i2c);
415 MXC_I2C_RevB_ClearRXFIFO(i2c);
416 interruptEnables = 0;
417 AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL;
418 }
419
420 return interruptEnables;
421 }
422
MXC_I2C_RevB_AsyncHandler(mxc_i2c_revb_regs_t * i2c,uint32_t interruptCheck)423 void MXC_I2C_RevB_AsyncHandler(mxc_i2c_revb_regs_t *i2c, uint32_t interruptCheck)
424 {
425 int i2cNum = MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c);
426 int slaveRetVal;
427
428 if (i2cNum < 0) {
429 return;
430 }
431
432 if (i2c->ctrl0 & MXC_F_I2C_REVB_CTRL0_MST) {
433 MXC_I2C_RevB_MasterAsyncHandler(i2cNum);
434 } else {
435 mxc_i2c_revb_slave_handler_t callback = (mxc_i2c_revb_slave_handler_t)AsyncRequests[i2cNum];
436 i2c->int_en0 = MXC_I2C_RevB_SlaveAsyncHandler(i2c, callback, i2c->int_en0, &slaveRetVal);
437 }
438 }
439
MXC_I2C_RevB_DMACallback(int ch,int error)440 void MXC_I2C_RevB_DMACallback(int ch, int error)
441 {
442 MXC_I2C_RevA_DMACallback(ch, error);
443 }
444