1 /* $Id: xiic_i.h,v 1.1.1.1 2005/04/11 02:50:21 jack Exp $ */
2 /******************************************************************************
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
14 * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
15 * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
16 * XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
17 * FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR
18 * OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
19 * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
20 * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
21 * WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
22 * CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
23 * FITNESS FOR A PARTICULAR PURPOSE.
26 * Xilinx products are not intended for use in life support appliances,
27 * devices, or systems. Use in such applications is expressly prohibited.
30 * (c) Copyright 2002 Xilinx Inc.
31 * All rights reserved.
34 * You should have received a copy of the GNU General Public License along
35 * with this program; if not, write to the Free Software Foundation, Inc.,
36 * 675 Mass Ave, Cambridge, MA 02139, USA.
38 ******************************************************************************/
39 /*****************************************************************************/
44 * This header file contains internal identifiers, which are those shared
45 * between XIic components. The identifiers in this file are not intended for
46 * use external to the driver.
49 * MODIFICATION HISTORY:
51 * Ver Who Date Changes
52 * ----- ---- -------- -----------------------------------------------
53 * 1.01a rfp 10/19/01 release
56 ******************************************************************************/
58 #ifndef XIIC_I_H /* prevent circular inclusions */
59 #define XIIC_I_H /* by using protection macros */
61 /***************************** Include Files *********************************/
63 #include "xbasic_types.h"
66 /************************** Constant Definitions *****************************/
68 /**************************** Type Definitions *******************************/
70 /***************** Macros (Inline Functions) Definitions *********************/
72 /******************************************************************************
74 * This macro sends the first byte of the address for a 10 bit address during
75 * both read and write operations. It takes care of the details to format the
78 * address = 1111_0xxD xx = address MSBits
79 * D = Tx direction = 0 = write
81 * @param SlaveAddress contains the address of the slave to send to.
83 * @param Operation indicates XIIC_READ_OPERATION or XIIC_WRITE_OPERATION
91 * Signature: void XIic_mSend10BitAddrByte1(u16 SlaveAddress, u8 Operation);
93 ******************************************************************************/
94 #define XIic_mSend10BitAddrByte1(SlaveAddress, Operation) \
96 u8 LocalAddr = (u8)((SlaveAddress) >> 7); \
97 LocalAddr = (LocalAddr & 0xF6) | 0xF0 | (Operation); \
98 XIo_Out8(InstancePtr->BaseAddress + XIIC_DTR_REG_OFFSET, LocalAddr); \
101 /******************************************************************************
103 * This macro sends the second byte of the address for a 10 bit address during
104 * both read and write operations. It takes care of the details to format the
107 * @param SlaveAddress contains the address of the slave to send to.
115 * Signature: void XIic_mSend10BitAddrByte2(u16 SlaveAddress,
118 ******************************************************************************/
119 #define XIic_mSend10BitAddrByte2(SlaveAddress) \
120 XIo_Out8(InstancePtr->BaseAddress + XIIC_DTR_REG_OFFSET, \
123 /******************************************************************************
125 * This macro sends the address for a 7 bit address during both read and write
126 * operations. It takes care of the details to format the address correctly.
128 * @param SlaveAddress contains the address of the slave to send to.
130 * @param Operation indicates XIIC_READ_OPERATION or XIIC_WRITE_OPERATION
138 * Signature: void XIic_mSend7BitAddr(u16 SlaveAddress, u8 Operation);
140 ******************************************************************************/
141 #define XIic_mSend7BitAddr(SlaveAddress, Operation) \
143 u8 LocalAddr = (u8)(SlaveAddress << 1); \
144 LocalAddr = (LocalAddr & 0xFE) | (Operation); \
145 XIo_Out8(InstancePtr->BaseAddress + XIIC_DTR_REG_OFFSET, LocalAddr); \
148 /******************************************************************************
150 * This macro disables the specified interrupts in the IPIF interrupt enable
151 * register. It is non-destructive in that the register is read and only the
152 * interrupts specified is changed.
154 * @param BaseAddress contains the IPIF registers base address.
156 * @param InterruptMask contains the interrupts to be disabled
164 * Signature: void XIic_mDisableIntr(u32 BaseAddress,
165 * u32 InterruptMask);
167 ******************************************************************************/
168 #define XIic_mDisableIntr(BaseAddress, InterruptMask) \
169 XIIF_V123B_WRITE_IIER((BaseAddress), \
170 XIIF_V123B_READ_IIER(BaseAddress) & ~(InterruptMask))
172 /******************************************************************************
174 * This macro enables the specified interrupts in the IPIF interrupt enable
175 * register. It is non-destructive in that the register is read and only the
176 * interrupts specified is changed.
178 * @param BaseAddress contains the IPIF registers base address.
180 * @param InterruptMask contains the interrupts to be disabled
188 * Signature: void XIic_mEnableIntr(u32 BaseAddress,
189 * u32 InterruptMask);
191 ******************************************************************************/
192 #define XIic_mEnableIntr(BaseAddress, InterruptMask) \
193 XIIF_V123B_WRITE_IIER((BaseAddress), \
194 XIIF_V123B_READ_IIER(BaseAddress) | (InterruptMask))
196 /******************************************************************************
198 * This macro clears the specified interrupt in the IPIF interrupt status
199 * register. It is non-destructive in that the register is read and only the
200 * interrupt specified is cleared. Clearing an interrupt acknowledges it.
202 * @param BaseAddress contains the IPIF registers base address.
204 * @param InterruptMask contains the interrupts to be disabled
212 * Signature: void XIic_mClearIntr(u32 BaseAddress,
213 * u32 InterruptMask);
215 ******************************************************************************/
216 #define XIic_mClearIntr(BaseAddress, InterruptMask) \
217 XIIF_V123B_WRITE_IISR((BaseAddress), \
218 XIIF_V123B_READ_IISR(BaseAddress) & (InterruptMask))
220 /******************************************************************************
222 * This macro clears and enables the specified interrupt in the IPIF interrupt
223 * status and enable registers. It is non-destructive in that the registers are
224 * read and only the interrupt specified is modified.
225 * Clearing an interrupt acknowledges it.
227 * @param BaseAddress contains the IPIF registers base address.
229 * @param InterruptMask contains the interrupts to be cleared and enabled
237 * Signature: void XIic_mClearEnableIntr(u32 BaseAddress,
238 * u32 InterruptMask);
240 ******************************************************************************/
241 #define XIic_mClearEnableIntr(BaseAddress, InterruptMask) \
243 XIIF_V123B_WRITE_IISR(BaseAddress, \
244 (XIIF_V123B_READ_IISR(BaseAddress) & (InterruptMask))); \
246 XIIF_V123B_WRITE_IIER(BaseAddress, \
247 (XIIF_V123B_READ_IIER(BaseAddress) | (InterruptMask))); \
250 /******************************************************************************
252 * This macro flushes the receive FIFO such that all bytes contained within it
255 * @param InstancePtr is a pointer to the IIC instance containing the FIFO
264 * Signature: void XIic_mFlushRxFifo(XIic *InstancePtr);
266 ******************************************************************************/
267 #define XIic_mFlushRxFifo(InstancePtr) \
271 u8 BytesToRead = XIo_In8(InstancePtr->BaseAddress + \
272 XIIC_RFO_REG_OFFSET) + 1; \
273 for(LoopCnt = 0; LoopCnt < BytesToRead; LoopCnt++) \
275 Temp = XIo_In8(InstancePtr->BaseAddress + XIIC_DRR_REG_OFFSET); \
279 /******************************************************************************
281 * This macro flushes the transmit FIFO such that all bytes contained within it
284 * @param InstancePtr is a pointer to the IIC instance containing the FIFO
293 * Signature: void XIic_mFlushTxFifo(XIic *InstancePtr);
295 ******************************************************************************/
296 #define XIic_mFlushTxFifo(InstancePtr); \
298 u8 CntlReg = XIo_In8(InstancePtr->BaseAddress + \
299 XIIC_CR_REG_OFFSET); \
300 XIo_Out8(InstancePtr->BaseAddress + XIIC_CR_REG_OFFSET, \
301 CntlReg | XIIC_CR_TX_FIFO_RESET_MASK); \
302 XIo_Out8(InstancePtr->BaseAddress + XIIC_CR_REG_OFFSET, CntlReg); \
305 /******************************************************************************
307 * This macro reads the next available received byte from the receive FIFO
308 * and updates all the data structures to reflect it.
310 * @param InstancePtr is a pointer to the IIC instance to be operated on.
318 * Signature: void XIic_mReadRecvByte(XIic *InstancePtr);
320 ******************************************************************************/
321 #define XIic_mReadRecvByte(InstancePtr) \
323 *InstancePtr->RecvBufferPtr++ = \
324 XIo_In8(InstancePtr->BaseAddress + XIIC_DRR_REG_OFFSET); \
325 InstancePtr->RecvByteCount--; \
326 InstancePtr->Stats.RecvBytes++; \
329 /******************************************************************************
331 * This macro writes the next byte to be sent to the transmit FIFO
332 * and updates all the data structures to reflect it.
334 * @param InstancePtr is a pointer to the IIC instance to be operated on.
342 * Signature: void XIic_mWriteSendByte(XIic *InstancePtr);
344 ******************************************************************************/
345 #define XIic_mWriteSendByte(InstancePtr) \
347 XIo_Out8(InstancePtr->BaseAddress + XIIC_DTR_REG_OFFSET, \
348 *InstancePtr->SendBufferPtr++); \
349 InstancePtr->SendByteCount--; \
350 InstancePtr->Stats.SendBytes++; \
353 /******************************************************************************
355 * This macro sets up the control register for a master receive operation.
356 * A write is necessary if a 10 bit operation is being performed.
358 * @param InstancePtr is a pointer to the IIC instance to be operated on.
360 * @param ControlRegister contains the contents of the IIC device control
363 * @param ByteCount contains the number of bytes to be received for the
364 * master receive operation
372 * Signature: void XIic_mSetControlRegister(XIic *InstancePtr,
373 * u8 ControlRegister,
376 ******************************************************************************/
377 #define XIic_mSetControlRegister(InstancePtr, ControlRegister, ByteCount) \
379 (ControlRegister) &= ~(XIIC_CR_NO_ACK_MASK | XIIC_CR_DIR_IS_TX_MASK); \
380 if (InstancePtr->Options & XII_SEND_10_BIT_OPTION) \
382 (ControlRegister) |= XIIC_CR_DIR_IS_TX_MASK; \
386 if ((ByteCount) == 1) \
388 (ControlRegister) |= XIIC_CR_NO_ACK_MASK; \
393 /******************************************************************************
395 * This macro enters a critical region by disabling the global interrupt bit
398 * @param BaseAddress contains the IPIF registers base address.
406 * Signature: void XIic_mEnterCriticalRegion(u32 BaseAddress)
408 ******************************************************************************/
409 #define XIic_mEnterCriticalRegion(BaseAddress) \
410 XIIF_V123B_GINTR_DISABLE(BaseAddress)
412 /******************************************************************************
414 * This macro exits a critical region by enabling the global interrupt bit
417 * @param BaseAddress contains the IPIF registers base address.
425 * Signature: void XIic_mExitCriticalRegion(u32 BaseAddress)
427 ******************************************************************************/
428 #define XIic_mExitCriticalRegion(BaseAddress) \
429 XIIF_V123B_GINTR_ENABLE(BaseAddress)
431 /******************************************************************************
433 * This macro clears the statistics of an instance such that it can be common
434 * such that some parts of the driver may be optional.
436 * @param InstancePtr is a pointer to the IIC instance to be operated on.
444 * Signature: void XIIC_CLEAR_STATS(XIic *InstancePtr)
446 ******************************************************************************/
447 #define XIIC_CLEAR_STATS(InstancePtr) \
452 DestPtr = (u8 *)&InstancePtr->Stats; \
453 for (NumBytes = 0; NumBytes < sizeof(XIicStats); NumBytes++) \
459 /************************** Function Prototypes ******************************/
461 extern XIic_Config XIic_ConfigTable[];
463 /* The following variables are shared across files of the driver and
464 * are function pointers that are necessary to break dependencies allowing
465 * optional parts of the driver to be used without condition compilation
467 extern void (*XIic_AddrAsSlaveFuncPtr) (XIic * InstancePtr);
468 extern void (*XIic_NotAddrAsSlaveFuncPtr) (XIic * InstancePtr);
469 extern void (*XIic_RecvSlaveFuncPtr) (XIic * InstancePtr);
470 extern void (*XIic_SendSlaveFuncPtr) (XIic * InstancePtr);
471 extern void (*XIic_RecvMasterFuncPtr) (XIic * InstancePtr);
472 extern void (*XIic_SendMasterFuncPtr) (XIic * InstancePtr);
473 extern void (*XIic_ArbLostFuncPtr) (XIic * InstancePtr);
474 extern void (*XIic_BusNotBusyFuncPtr) (XIic * InstancePtr);
476 void XIic_TransmitFifoFill(XIic * InstancePtr, int Role);
478 #endif /* end of protection macro */