OpenCores
URL https://opencores.org/ocsvn/xenie/xenie/trunk

Subversion Repositories xenie

[/] [xenie/] [trunk/] [examples/] [Eth_example/] [mb_fw/] [drivers/] [iic_v3_4/] [src/] [xiic_i.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 DFC
/******************************************************************************
2
*
3
* Copyright (C) 2002 - 2015 Xilinx, Inc.  All rights reserved.
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining a copy
6
* of this software and associated documentation files (the "Software"), to deal
7
* in the Software without restriction, including without limitation the rights
8
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
* copies of the Software, and to permit persons to whom the Software is
10
* furnished to do so, subject to the following conditions:
11
*
12
* The above copyright notice and this permission notice shall be included in
13
* all copies or substantial portions of the Software.
14
*
15
* Use of the Software is limited solely to applications:
16
* (a) running on a Xilinx device, or
17
* (b) that interact with a Xilinx device through a bus or interconnect.
18
*
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
* SOFTWARE.
26
*
27
* Except as contained in this notice, the name of the Xilinx shall not be used
28
* in advertising or otherwise to promote the sale, use or other dealings in
29
* this Software without prior written authorization from Xilinx.
30
*
31
******************************************************************************/
32
/*****************************************************************************/
33
/**
34
*
35
* @file xiic_i.h
36
* @addtogroup iic_v3_1
37
* @{
38
*
39
* This header file contains internal identifiers, which are those shared
40
* between XIic components.  The identifiers in this file are not intended for
41
* use external to the driver.
42
*
43
* <pre>
44
* MODIFICATION HISTORY:
45
*
46
* Ver   Who  Date     Changes
47
* ----- ---- -------- -----------------------------------------------
48
* 1.01a rfp  10/19/01 release
49
* 1.01c ecm  12/05/02 new rev
50
* 1.13a wgr  03/22/07 Converted to new coding style.
51
* 2.00a sdm  10/22/09 Converted all register accesses to 32 bit access.
52
*                     Removed the macro XIIC_CLEAR_STATS, user has to
53
*                     use the the XIic_ClearStats API in its place.
54
*                     Removed the macro XIic_mEnterCriticalRegion,
55
*                     XIic_IntrGlobalDisable should be used in its place.
56
*                     Removed the macro XIic_mExitCriticalRegion,
57
*                     XIic_IntrGlobalEnable should be used in its place.
58
*                     Removed the _m prefix from all the macros
59
*                     XIic_mSend10BitAddrByte1 is now XIic_Send10BitAddrByte1
60
*                     XIic_mSend10BitAddrByte2 is now XIic_Send10BitAddrByte2
61
*                     XIic_mSend7BitAddr is now XIic_Send7BitAddr
62
*                     XIic_mDisableIntr is now XIic_DisableIntr
63
*                     XIic_mEnableIntr is now XIic_EnableIntr
64
*                     XIic_mClearIntr is now XIic_ClearIntr
65
*                     XIic_mClearEnableIntr is now XIic_ClearEnableIntr
66
*                     XIic_mFlushRxFifo is now XIic_FlushRxFifo
67
*                     XIic_mFlushTxFifo is now XIic_FlushTxFifo
68
*                     XIic_mReadRecvByte is now XIic_ReadRecvByte
69
*                     XIic_mWriteSendByte is now XIic_WriteSendByte
70
*                     XIic_mSetControlRegister is now XIic_SetControlRegister
71
* 2.07a adk   18/04/13 Updated the code to avoid unused variable warnings when
72
*                         compiling with the -Wextra -Wall flags.
73
*                         Changes done in files xiic.c and xiic_i.h. CR:705001
74
*
75
* </pre>
76
*
77
******************************************************************************/
78
 
79
#ifndef XIIC_I_H                /* prevent circular inclusions */
80
#define XIIC_I_H                /* by using protection macros */
81
 
82
#ifdef __cplusplus
83
extern "C" {
84
#endif
85
 
86
/***************************** Include Files *********************************/
87
 
88
#include "xil_types.h"
89
#include "xil_assert.h"
90
#include "xstatus.h"
91
#include "xiic.h"
92
 
93
/************************** Constant Definitions *****************************/
94
 
95
/**************************** Type Definitions *******************************/
96
 
97
/***************** Macros (Inline Functions) Definitions *********************/
98
 
99
/******************************************************************************
100
*
101
* This macro sends the first byte of the address for a 10 bit address during
102
* both read and write operations. It takes care of the details to format the
103
* address correctly.
104
*
105
* address = 1111_0xxD   xx = address MSBits
106
*                        D = Tx direction = 0 = write
107
*
108
* @param        SlaveAddress contains the address of the slave to send to.
109
* @param        Operation indicates XIIC_READ_OPERATION or XIIC_WRITE_OPERATION
110
*
111
* @return       None.
112
*
113
* @note         Signature:
114
*               void XIic_Send10BitAddrByte1(u16 SlaveAddress, u8 Operation);
115
*
116
******************************************************************************/
117
#define XIic_Send10BitAddrByte1(SlaveAddress, Operation)                \
118
{                                                                       \
119
        u8 LocalAddr = (u8)((SlaveAddress) >> 7);                       \
120
        LocalAddr = (LocalAddr & 0xF6) | 0xF0 | (Operation);            \
121
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_DTR_REG_OFFSET,    \
122
                        (u32) LocalAddr);                               \
123
}
124
 
125
/******************************************************************************
126
*
127
* This macro sends the second byte of the address for a 10 bit address during
128
* both read and write operations. It takes care of the details to format the
129
* address correctly.
130
*
131
* @param        SlaveAddress contains the address of the slave to send to.
132
*
133
* @return       None.
134
*
135
* @note         Signature: void XIic_Send10BitAddrByte2(u16 SlaveAddress,
136
*                               u8 Operation);
137
*
138
******************************************************************************/
139
#define XIic_Send10BitAddrByte2(SlaveAddress)                           \
140
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_DTR_REG_OFFSET,    \
141
                        (u32)(SlaveAddress));                           \
142
 
143
/******************************************************************************
144
*
145
* This macro sends the address for a 7 bit address during both read and write
146
* operations. It takes care of the details to format the address correctly.
147
*
148
* @param        SlaveAddress contains the address of the slave to send to.
149
* @param        Operation indicates XIIC_READ_OPERATION or XIIC_WRITE_OPERATION
150
*
151
* @return       None.
152
*
153
* @note         Signature:
154
*               void XIic_Send7BitAddr(u16 SlaveAddress, u8 Operation);
155
*
156
******************************************************************************/
157
#define XIic_Send7BitAddr(SlaveAddress, Operation)                      \
158
{                                                                       \
159
        u8 LocalAddr = (u8)(SlaveAddress << 1);                 \
160
        LocalAddr = (LocalAddr & 0xFE) | (Operation);                   \
161
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_DTR_REG_OFFSET,    \
162
                        (u32) LocalAddr);                               \
163
}
164
 
165
/******************************************************************************
166
*
167
* This macro disables the specified interrupts in the Interrupt enable
168
* register.  It is non-destructive in that the register is read and only the
169
* interrupts specified is changed.
170
*
171
* @param        BaseAddress is the base address of the IIC device.
172
* @param        InterruptMask contains the interrupts to be disabled
173
*
174
* @return       None.
175
*
176
* @note         Signature:
177
*               void XIic_DisableIntr(u32 BaseAddress, u32 InterruptMask);
178
*
179
******************************************************************************/
180
#define XIic_DisableIntr(BaseAddress, InterruptMask)                    \
181
        XIic_WriteIier((BaseAddress),                                   \
182
                XIic_ReadIier(BaseAddress) & ~(InterruptMask))
183
 
184
/******************************************************************************
185
*
186
* This macro enables the specified interrupts in the Interrupt enable
187
* register.  It is non-destructive in that the register is read and only the
188
* interrupts specified is changed.
189
*
190
* @param        BaseAddress is the base address of the IIC device.
191
* @param        InterruptMask contains the interrupts to be disabled
192
*
193
* @return       None.
194
*
195
* @note         Signature:
196
*               void XIic_EnableIntr(u32 BaseAddress, u32 InterruptMask);
197
*
198
******************************************************************************/
199
#define XIic_EnableIntr(BaseAddress, InterruptMask)                     \
200
        XIic_WriteIier((BaseAddress),                                   \
201
                XIic_ReadIier(BaseAddress) | (InterruptMask))
202
 
203
/******************************************************************************
204
*
205
* This macro clears the specified interrupt in the Interrupt status
206
* register.  It is non-destructive in that the register is read and only the
207
* interrupt specified is cleared.  Clearing an interrupt acknowledges it.
208
*
209
* @param        BaseAddress is the base address of the IIC device.
210
* @param        InterruptMask contains the interrupts to be disabled
211
*
212
* @return       None.
213
*
214
* @note         Signature:
215
*               void XIic_ClearIntr(u32 BaseAddress, u32 InterruptMask);
216
*
217
******************************************************************************/
218
#define XIic_ClearIntr(BaseAddress, InterruptMask)                      \
219
        XIic_WriteIisr((BaseAddress),                                   \
220
                XIic_ReadIisr(BaseAddress) & (InterruptMask))
221
 
222
/******************************************************************************
223
*
224
* This macro clears and enables the specified interrupt in the Interrupt
225
* status and enable registers.  It is non-destructive in that the registers are
226
* read and only the interrupt specified is modified.
227
* Clearing an interrupt acknowledges it.
228
*
229
* @param        BaseAddress is the base address of the IIC device.
230
* @param        InterruptMask contains the interrupts to be cleared and enabled
231
*
232
* @return       None.
233
*
234
* @note         Signature:
235
*               void XIic_ClearEnableIntr(u32 BaseAddress, u32 InterruptMask);
236
*
237
******************************************************************************/
238
#define XIic_ClearEnableIntr(BaseAddress, InterruptMask)                \
239
{                                                                       \
240
        XIic_WriteIisr(BaseAddress,                                     \
241
                (XIic_ReadIisr(BaseAddress) & (InterruptMask)));        \
242
                                                                        \
243
        XIic_WriteIier(BaseAddress,                                     \
244
                (XIic_ReadIier(BaseAddress) | (InterruptMask)));        \
245
}
246
 
247
/******************************************************************************
248
*
249
* This macro flushes the receive FIFO such that all bytes contained within it
250
* are discarded.
251
*
252
* @param        InstancePtr is a pointer to the IIC instance containing the FIFO
253
*               to be flushed.
254
*
255
* @return       None.
256
*
257
* @note         Signature:
258
*               void XIic_FlushRxFifo(XIic *InstancePtr);
259
*
260
******************************************************************************/
261
#define XIic_FlushRxFifo(InstancePtr)                                   \
262
{                                                                       \
263
        int LoopCnt;                                                    \
264
        u8 BytesToRead = XIic_ReadReg(InstancePtr->BaseAddress, \
265
                                XIIC_RFO_REG_OFFSET) + 1;               \
266
        for(LoopCnt = 0; LoopCnt < BytesToRead; LoopCnt++)               \
267
        {                                                               \
268
                 XIic_ReadReg(InstancePtr->BaseAddress, \
269
                                          XIIC_DRR_REG_OFFSET);         \
270
        }                                                               \
271
}
272
 
273
/******************************************************************************
274
*
275
* This macro flushes the transmit FIFO such that all bytes contained within it
276
* are discarded.
277
*
278
* @param        InstancePtr is a pointer to the IIC instance containing the FIFO
279
*               to be flushed.
280
*
281
* @return       None.
282
*
283
* @note         Signature:
284
*               void XIic_FlushTxFifo(XIic *InstancePtr);
285
*
286
******************************************************************************/
287
#define XIic_FlushTxFifo(InstancePtr);                                  \
288
{                                                                       \
289
        u32 CntlReg = XIic_ReadReg(InstancePtr->BaseAddress,            \
290
                                        XIIC_CR_REG_OFFSET);            \
291
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_CR_REG_OFFSET,     \
292
                        CntlReg | XIIC_CR_TX_FIFO_RESET_MASK);          \
293
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_CR_REG_OFFSET,     \
294
                        CntlReg);                                       \
295
}
296
 
297
/******************************************************************************
298
*
299
* This macro reads the next available received byte from the receive FIFO
300
* and updates all the data structures to reflect it.
301
*
302
* @param        InstancePtr is a pointer to the IIC instance to be operated on.
303
*
304
* @return       None.
305
*
306
* @note         Signature:
307
*               void XIic_ReadRecvByte(XIic *InstancePtr);
308
*
309
******************************************************************************/
310
#define XIic_ReadRecvByte(InstancePtr)                                  \
311
{                                                                       \
312
        *InstancePtr->RecvBufferPtr++ =                                 \
313
        XIic_ReadReg(InstancePtr->BaseAddress, XIIC_DRR_REG_OFFSET);    \
314
        InstancePtr->RecvByteCount--;                                   \
315
        InstancePtr->Stats.RecvBytes++;                                 \
316
}
317
 
318
/******************************************************************************
319
*
320
* This macro writes the next byte to be sent to the transmit FIFO
321
* and updates all the data structures to reflect it.
322
*
323
* @param        InstancePtr is a pointer to the IIC instance to be operated on.
324
*
325
* @return       None.
326
*
327
* @note         Signature:
328
*               void XIic_WriteSendByte(XIic *InstancePtr);
329
*
330
******************************************************************************/
331
#define XIic_WriteSendByte(InstancePtr)                         \
332
{                                                                       \
333
        XIic_WriteReg(InstancePtr->BaseAddress, XIIC_DTR_REG_OFFSET,    \
334
                *InstancePtr->SendBufferPtr++);                         \
335
        InstancePtr->SendByteCount--;                                   \
336
        InstancePtr->Stats.SendBytes++;                                 \
337
}
338
 
339
/******************************************************************************
340
*
341
* This macro sets up the control register for a master receive operation.
342
* A write is necessary if a 10 bit operation is being performed.
343
*
344
* @param        InstancePtr is a pointer to the IIC instance to be operated on.
345
* @param        ControlRegister contains the contents of the IIC device control
346
*               register
347
* @param        ByteCount contains the number of bytes to be received for the
348
*               master receive operation
349
*
350
* @return       None.
351
*
352
* @note         Signature:
353
*               void XIic_SetControlRegister(XIic *InstancePtr,
354
*                                               u8 ControlRegister,
355
*                                               int ByteCount);
356
*
357
******************************************************************************/
358
#define XIic_SetControlRegister(InstancePtr, ControlRegister, ByteCount)     \
359
{                                                                             \
360
        (ControlRegister) &= ~(XIIC_CR_NO_ACK_MASK | XIIC_CR_DIR_IS_TX_MASK); \
361
        if (InstancePtr->Options & XII_SEND_10_BIT_OPTION) {            \
362
                (ControlRegister) |= XIIC_CR_DIR_IS_TX_MASK;            \
363
        } else {                                                        \
364
                if ((ByteCount) == 1)                                   \
365
                {                                                       \
366
                        (ControlRegister) |= XIIC_CR_NO_ACK_MASK;       \
367
                }                                                       \
368
        }                                                               \
369
}
370
 
371
/************************** Function Prototypes ******************************/
372
 
373
extern XIic_Config XIic_ConfigTable[];
374
 
375
/* The following variables are shared across files of the driver and
376
 * are function pointers that are necessary to break dependencies allowing
377
 * optional parts of the driver to be used without condition compilation
378
 */
379
extern void (*XIic_AddrAsSlaveFuncPtr) (XIic *InstancePtr);
380
extern void (*XIic_NotAddrAsSlaveFuncPtr) (XIic *InstancePtr);
381
extern void (*XIic_RecvSlaveFuncPtr) (XIic *InstancePtr);
382
extern void (*XIic_SendSlaveFuncPtr) (XIic *InstancePtr);
383
extern void (*XIic_RecvMasterFuncPtr) (XIic *InstancePtr);
384
extern void (*XIic_SendMasterFuncPtr) (XIic *InstancePtr);
385
extern void (*XIic_ArbLostFuncPtr) (XIic *InstancePtr);
386
extern void (*XIic_BusNotBusyFuncPtr) (XIic *InstancePtr);
387
 
388
void XIic_TransmitFifoFill(XIic *InstancePtr, int Role);
389
 
390
#ifdef __cplusplus
391
}
392
#endif
393
 
394
#endif /* end of protection macro */
395
/** @} */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.