1 /******************************************************************************
3 * (c) Copyright 2010-14 Xilinx, Inc. All rights reserved.
5 * This file contains confidential and proprietary information of Xilinx, Inc.
6 * and is protected under U.S. and international copyright and other
7 * intellectual property laws.
10 * This disclaimer is not a license and does not grant any rights to the
11 * materials distributed herewith. Except as otherwise provided in a valid
12 * license issued to you by Xilinx, and to the maximum extent permitted by
13 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
14 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
15 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
16 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
17 * and (2) Xilinx shall not be liable (whether in contract or tort, including
18 * negligence, or under any other theory of liability) for any loss or damage
19 * of any kind or nature related to, arising under or in connection with these
20 * materials, including for any direct, or any indirect, special, incidental,
21 * or consequential loss or damage (including loss of data, profits, goodwill,
22 * or any type of loss or damage suffered as a result of any action brought by
23 * a third party) even if such damage or loss was reasonably foreseeable or
24 * Xilinx had been advised of the possibility of the same.
26 * CRITICAL APPLICATIONS
27 * Xilinx products are not designed or intended to be fail-safe, or for use in
28 * any application requiring fail-safe performance, such as life-support or
29 * safety devices or systems, Class III medical devices, nuclear facilities,
30 * applications related to the deployment of airbags, or any other applications
31 * that could lead to death, personal injury, or severe property or
32 * environmental damage (individually and collectively, "Critical
33 * Applications"). Customer assumes the sole risk and liability of any use of
34 * Xilinx products in Critical Applications, subject only to applicable laws
35 * and regulations governing limitations on product liability.
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
40 ******************************************************************************/
41 /*****************************************************************************/
46 * This header file contains the hardware definition for an IIC device.
47 * It includes register definitions and interface functions to read/write
51 * MODIFICATION HISTORY:
53 * Ver Who Date Changes
54 * ----- ------ -------- -----------------------------------------------
55 * 1.00a drg/jz 01/30/10 First release
56 * 1.04a kpc 11/07/13 Added function prototype.
59 ******************************************************************************/
60 #ifndef XIICPS_HW_H /* prevent circular inclusions */
61 #define XIICPS_HW_H /* by using protection macros */
67 /***************************** Include Files *********************************/
69 #include "xil_types.h"
70 #include "xil_assert.h"
73 /************************** Constant Definitions *****************************/
75 /** @name Register Map
77 * Register offsets for the IIC.
80 #define XIICPS_CR_OFFSET 0x00 /**< 32-bit Control */
81 #define XIICPS_SR_OFFSET 0x04 /**< Status */
82 #define XIICPS_ADDR_OFFSET 0x08 /**< IIC Address */
83 #define XIICPS_DATA_OFFSET 0x0C /**< IIC FIFO Data */
84 #define XIICPS_ISR_OFFSET 0x10 /**< Interrupt Status */
85 #define XIICPS_TRANS_SIZE_OFFSET 0x14 /**< Transfer Size */
86 #define XIICPS_SLV_PAUSE_OFFSET 0x18 /**< Slave monitor pause */
87 #define XIICPS_TIME_OUT_OFFSET 0x1C /**< Time Out */
88 #define XIICPS_IMR_OFFSET 0x20 /**< Interrupt Enabled Mask */
89 #define XIICPS_IER_OFFSET 0x24 /**< Interrupt Enable */
90 #define XIICPS_IDR_OFFSET 0x28 /**< Interrupt Disable */
93 /** @name Control Register
95 * This register contains various control bits that
96 * affects the operation of the IIC controller. Read/Write.
100 #define XIICPS_CR_DIV_A_MASK 0x0000C000 /**< Clock Divisor A */
101 #define XIICPS_CR_DIV_A_SHIFT 14 /**< Clock Divisor A shift */
102 #define XIICPS_DIV_A_MAX 4 /**< Maximum value of Divisor A */
103 #define XIICPS_CR_DIV_B_MASK 0x00003F00 /**< Clock Divisor B */
104 #define XIICPS_CR_DIV_B_SHIFT 8 /**< Clock Divisor B shift */
105 #define XIICPS_CR_CLR_FIFO_MASK 0x00000040 /**< Clear FIFO, auto clears*/
106 #define XIICPS_CR_SLVMON_MASK 0x00000020 /**< Slave monitor mode */
107 #define XIICPS_CR_HOLD_MASK 0x00000010 /**< Hold bus 1=Hold scl,
108 0=terminate transfer */
109 #define XIICPS_CR_ACKEN_MASK 0x00000008 /**< Enable TX of ACK when
111 #define XIICPS_CR_NEA_MASK 0x00000004 /**< Addressing Mode 1=7 bit,
113 #define XIICPS_CR_MS_MASK 0x00000002 /**< Master mode bit 1=Master,
115 #define XIICPS_CR_RD_WR_MASK 0x00000001 /**< Read or Write Master
116 transfer 0=Transmitter,
118 #define XIICPS_CR_RESET_VALUE 0 /**< Reset value of the Control
122 /** @name IIC Status Register
124 * This register is used to indicate status of the IIC controller. Read only
127 #define XIICPS_SR_BA_MASK 0x00000100 /**< Bus Active Mask */
128 #define XIICPS_SR_RXOVF_MASK 0x00000080 /**< Receiver Overflow Mask */
129 #define XIICPS_SR_TXDV_MASK 0x00000040 /**< Transmit Data Valid Mask */
130 #define XIICPS_SR_RXDV_MASK 0x00000020 /**< Receiver Data Valid Mask */
131 #define XIICPS_SR_RXRW_MASK 0x00000008 /**< Receive read/write Mask */
134 /** @name IIC Address Register
136 * Normal addressing mode uses add[6:0]. Extended addressing mode uses add[9:0].
137 * A write access to this register always initiates a transfer if the IIC is in
138 * master mode. Read/Write
141 #define XIICPS_ADDR_MASK 0x000003FF /**< IIC Address Mask */
144 /** @name IIC Data Register
146 * When written to, the data register sets data to transmit. When read from, the
147 * data register reads the last received byte of data. Read/Write
150 #define XIICPS_DATA_MASK 0x000000FF /**< IIC Data Mask */
153 /** @name IIC Interrupt Registers
155 * <b>IIC Interrupt Status Register</b>
157 * This register holds the interrupt status flags for the IIC controller. Some
158 * of the flags are level triggered
159 * - i.e. are set as long as the interrupt condition exists. Other flags are
160 * edge triggered, which means they are set one the interrupt condition occurs
161 * then remain set until they are cleared by software.
162 * The interrupts are cleared by writing a one to the interrupt bit position
163 * in the Interrupt Status Register. Read/Write.
165 * <b>IIC Interrupt Enable Register</b>
167 * This register is used to enable interrupt sources for the IIC controller.
168 * Writing a '1' to a bit in this register clears the corresponding bit in the
169 * IIC Interrupt Mask register. Write only.
171 * <b>IIC Interrupt Disable Register </b>
173 * This register is used to disable interrupt sources for the IIC controller.
174 * Writing a '1' to a bit in this register sets the corresponding bit in the
175 * IIC Interrupt Mask register. Write only.
177 * <b>IIC Interrupt Mask Register</b>
179 * This register shows the enabled/disabled status of each IIC controller
180 * interrupt source. A bit set to 1 will ignore the corresponding interrupt in
181 * the status register. A bit set to 0 means the interrupt is enabled.
182 * All mask bits are set and all interrupts are disabled after reset. Read only.
184 * All four registers have the same bit definitions. They are only defined once
185 * for each of the Interrupt Enable Register, Interrupt Disable Register,
186 * Interrupt Mask Register, and Interrupt Status Register
190 #define XIICPS_IXR_ARB_LOST_MASK 0x00000200 /**< Arbitration Lost Interrupt
192 #define XIICPS_IXR_RX_UNF_MASK 0x00000080 /**< FIFO Recieve Underflow
194 #define XIICPS_IXR_TX_OVR_MASK 0x00000040 /**< Transmit Overflow
196 #define XIICPS_IXR_RX_OVR_MASK 0x00000020 /**< Receive Overflow Interrupt
198 #define XIICPS_IXR_SLV_RDY_MASK 0x00000010 /**< Monitored Slave Ready
200 #define XIICPS_IXR_TO_MASK 0x00000008 /**< Transfer Time Out
202 #define XIICPS_IXR_NACK_MASK 0x00000004 /**< NACK Interrupt mask */
203 #define XIICPS_IXR_DATA_MASK 0x00000002 /**< Data Interrupt mask */
204 #define XIICPS_IXR_COMP_MASK 0x00000001 /**< Transfer Complete
206 #define XIICPS_IXR_DEFAULT_MASK 0x000002FF /**< Default ISR Mask */
207 #define XIICPS_IXR_ALL_INTR_MASK 0x000002FF /**< All ISR Mask */
211 /** @name IIC Transfer Size Register
213 * The register's meaning varies according to the operating mode as follows:
214 * - Master transmitter mode: number of data bytes still not transmitted minus
216 * - Master receiver mode: number of data bytes that are still expected to be
218 * - Slave transmitter mode: number of bytes remaining in the FIFO after the
219 * master terminates the transfer
220 * - Slave receiver mode: number of valid data bytes in the FIFO
222 * This register is cleared if CLR_FIFO bit in the control register is set.
226 #define XIICPS_TRANS_SIZE_MASK 0x0000003F /**< IIC Transfer Size Mask */
227 #define XIICPS_FIFO_DEPTH 16 /**< Number of bytes in the FIFO */
228 #define XIICPS_DATA_INTR_DEPTH 14 /**< Number of bytes at DATA intr */
232 /** @name IIC Slave Monitor Pause Register
234 * This register is associated with the slave monitor mode of the I2C interface.
235 * It is meaningful only when the module is in master mode and bit SLVMON in the
236 * control register is set.
238 * This register defines the pause interval between consecutive attempts to
239 * address the slave once a write to an I2C address register is done by the
240 * host. It represents the number of sclk cycles minus one between two attempts.
242 * The reset value of the register is 0, which results in the master repeatedly
243 * trying to access the slave immediately after unsuccessful attempt.
247 #define XIICPS_SLV_PAUSE_MASK 0x0000000F /**< Slave monitor pause mask */
251 /** @name IIC Time Out Register
253 * The value of time out register represents the time out interval in number of
254 * sclk cycles minus one.
256 * When the accessed slave holds the sclk line low for longer than the time out
257 * period, thus prohibiting the I2C interface in master mode to complete the
258 * current transfer, an interrupt is generated and TO interrupt flag is set.
260 * The reset value of the register is 0x1f.
264 #define XIICPS_TIME_OUT_MASK 0x000000FF /**< IIC Time Out mask */
265 #define XIICPS_TO_RESET_VALUE 0x0000001F /**< IIC Time Out reset value */
268 /**************************** Type Definitions *******************************/
270 /***************** Macros (Inline Functions) Definitions *********************/
272 #define XIicPs_In32 Xil_In32
273 #define XIicPs_Out32 Xil_Out32
275 /****************************************************************************/
277 * Read an IIC register.
279 * @param BaseAddress contains the base address of the device.
280 * @param RegOffset contains the offset from the 1st register of the
281 * device to select the specific register.
283 * @return The value read from the register.
285 * @note C-Style signature:
286 * u32 XIicPs_ReadReg(u32 BaseAddress. int RegOffset)
288 ******************************************************************************/
289 #define XIicPs_ReadReg(BaseAddress, RegOffset) \
290 XIicPs_In32((BaseAddress) + (RegOffset))
292 /***************************************************************************/
294 * Write an IIC register.
296 * @param BaseAddress contains the base address of the device.
297 * @param RegOffset contains the offset from the 1st register of the
298 * device to select the specific register.
299 * @param RegisterValue is the value to be written to the register.
303 * @note C-Style signature:
304 * void XIicPs_WriteReg(u32 BaseAddress, int RegOffset, u32 RegisterValue)
306 ******************************************************************************/
307 #define XIicPs_WriteReg(BaseAddress, RegOffset, RegisterValue) \
308 XIicPs_Out32((BaseAddress) + (RegOffset), (RegisterValue))
310 /***************************************************************************/
312 * Read the interrupt enable register.
314 * @param BaseAddress contains the base address of the device.
316 * @return Current bit mask that represents currently enabled interrupts.
318 * @note C-Style signature:
319 * u32 XIicPs_ReadIER(u32 BaseAddress)
321 ******************************************************************************/
322 #define XIicPs_ReadIER(BaseAddress) \
323 XIicPs_ReadReg((BaseAddress), XIICPS_IER_OFFSET)
325 /***************************************************************************/
327 * Write to the interrupt enable register.
329 * @param BaseAddress contains the base address of the device.
331 * @param IntrMask is the interrupts to be enabled.
335 * @note C-Style signature:
336 * void XIicPs_EnabledInterrupts(u32 BaseAddress, u32 IntrMask)
338 ******************************************************************************/
339 #define XIicPs_EnableInterrupts(BaseAddress, IntrMask) \
340 XIicPs_WriteReg((BaseAddress), XIICPS_IER_OFFSET, (IntrMask))
342 /***************************************************************************/
344 * Disable all interrupts.
346 * @param BaseAddress contains the base address of the device.
350 * @note C-Style signature:
351 * void XIicPs_DisableAllInterrupts(u32 BaseAddress)
353 ******************************************************************************/
354 #define XIicPs_DisableAllInterrupts(BaseAddress) \
355 XIicPs_WriteReg((BaseAddress), XIICPS_IDR_OFFSET, \
356 XIICPS_IXR_ALL_INTR_MASK)
358 /***************************************************************************/
360 * Disable selected interrupts.
362 * @param BaseAddress contains the base address of the device.
364 * @param IntrMask is the interrupts to be disabled.
368 * @note C-Style signature:
369 * void XIicPs_DisableInterrupts(u32 BaseAddress, u32 IntrMask)
371 ******************************************************************************/
372 #define XIicPs_DisableInterrupts(BaseAddress, IntrMask) \
373 XIicPs_WriteReg((BaseAddress), XIICPS_IDR_OFFSET, \
376 /************************** Variable Definitions *****************************/
378 /************************** Function Prototypes ******************************/
380 * Perform reset operation to the I2c interface
382 void XIicPs_ResetHw(u32 BaseAddr);
387 #endif /* end of protection macro */