]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/iicps_v2_1/src/xiicps_hw.h
406892c7c0d3f562657921d2bffd9fe527aba676
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / iicps_v2_1 / src / xiicps_hw.h
1 /******************************************************************************
2 *
3 * (c) Copyright 2010-14 Xilinx, Inc. All rights reserved.
4 *
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.
8 *
9 * DISCLAIMER
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.
25 *
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.
36 *
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
38 * AT ALL TIMES.
39 *
40 ******************************************************************************/
41 /*****************************************************************************/
42 /**
43 *
44 * @file xiicps_hw.h
45 *
46 * This header file contains the hardware definition for an IIC device.
47 * It includes register definitions and interface functions to read/write
48 * the registers.
49 *
50 * <pre>
51 * MODIFICATION HISTORY:
52 *
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. 
57 * </pre>
58 *
59 ******************************************************************************/
60 #ifndef XIICPS_HW_H             /* prevent circular inclusions */
61 #define XIICPS_HW_H             /* by using protection macros */
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /***************************** Include Files *********************************/
68
69 #include "xil_types.h"
70 #include "xil_assert.h"
71 #include "xil_io.h"
72
73 /************************** Constant Definitions *****************************/
74
75 /** @name Register Map
76  *
77  * Register offsets for the IIC.
78  * @{
79  */
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 */
91 /* @} */
92
93 /** @name Control Register
94  *
95  * This register contains various control bits that
96  * affects the operation of the IIC controller. Read/Write.
97  * @{
98  */
99
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
110                                                  Master receiver*/
111 #define XIICPS_CR_NEA_MASK      0x00000004  /**< Addressing Mode 1=7 bit,
112                                                  0=10 bit */
113 #define XIICPS_CR_MS_MASK       0x00000002  /**< Master mode bit 1=Master,
114                                                  0=Slave */
115 #define XIICPS_CR_RD_WR_MASK    0x00000001  /**< Read or Write Master
116                                                  transfer  0=Transmitter,
117                                                  1=Receiver*/
118 #define XIICPS_CR_RESET_VALUE           0   /**< Reset value of the Control
119                                                  register */
120 /* @} */
121
122 /** @name IIC Status Register
123  *
124  * This register is used to indicate status of the IIC controller. Read only
125  * @{
126  */
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 */
132 /* @} */
133
134 /** @name IIC Address Register
135  *
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
139  * @{
140  */
141 #define XIICPS_ADDR_MASK        0x000003FF  /**< IIC Address Mask */
142 /* @} */
143
144 /** @name IIC Data Register
145  *
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
148  * @{
149  */
150 #define XIICPS_DATA_MASK        0x000000FF  /**< IIC Data Mask */
151 /* @} */
152
153 /** @name IIC Interrupt Registers
154  *
155  * <b>IIC Interrupt Status Register</b>
156  *
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.
164  *
165  * <b>IIC Interrupt Enable Register</b>
166  *
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.
170  *
171  * <b>IIC Interrupt Disable Register </b>
172  *
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.
176  *
177  * <b>IIC Interrupt Mask Register</b>
178  *
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.
183  *
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
187  * @{
188  */
189
190 #define XIICPS_IXR_ARB_LOST_MASK  0x00000200     /**< Arbitration Lost Interrupt
191                                                    mask */
192 #define XIICPS_IXR_RX_UNF_MASK    0x00000080     /**< FIFO Recieve Underflow
193                                                    Interrupt mask */
194 #define XIICPS_IXR_TX_OVR_MASK    0x00000040     /**< Transmit Overflow
195                                                    Interrupt mask */
196 #define XIICPS_IXR_RX_OVR_MASK    0x00000020     /**< Receive Overflow Interrupt
197                                                    mask */
198 #define XIICPS_IXR_SLV_RDY_MASK   0x00000010     /**< Monitored Slave Ready
199                                                    Interrupt mask */
200 #define XIICPS_IXR_TO_MASK        0x00000008     /**< Transfer Time Out
201                                                    Interrupt mask */
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
205                                                    Interrupt mask */
206 #define XIICPS_IXR_DEFAULT_MASK   0x000002FF     /**< Default ISR Mask */
207 #define XIICPS_IXR_ALL_INTR_MASK  0x000002FF     /**< All ISR Mask */
208 /* @} */
209
210
211 /** @name IIC Transfer Size Register
212 *
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
215 *     one
216 *   - Master receiver mode: number of data bytes that are still expected to be
217 *     received
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
221 *
222 * This register is cleared if CLR_FIFO bit in the control register is set.
223 * Read/Write
224 * @{
225 */
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 */
229 /* @} */
230
231
232 /** @name IIC Slave Monitor Pause Register
233 *
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.
237 *
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.
241 *
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.
244 * Read/Write
245 * @{
246 */
247 #define XIICPS_SLV_PAUSE_MASK    0x0000000F  /**< Slave monitor pause mask */
248 /* @} */
249
250
251 /** @name IIC Time Out Register
252 *
253 * The value of time out register represents the time out interval in number of
254 * sclk cycles minus one.
255 *
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.
259 *
260 * The reset value of the register is 0x1f.
261 * Read/Write
262 * @{
263  */
264 #define XIICPS_TIME_OUT_MASK    0x000000FF    /**< IIC Time Out mask */
265 #define XIICPS_TO_RESET_VALUE   0x0000001F    /**< IIC Time Out reset value */
266 /* @} */
267
268 /**************************** Type Definitions *******************************/
269
270 /***************** Macros (Inline Functions) Definitions *********************/
271
272 #define XIicPs_In32 Xil_In32
273 #define XIicPs_Out32 Xil_Out32
274
275 /****************************************************************************/
276 /**
277 * Read an IIC register.
278 *
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.
282 *
283 * @return       The value read from the register.
284 *
285 * @note         C-Style signature:
286 *               u32 XIicPs_ReadReg(u32 BaseAddress. int RegOffset)
287 *
288 ******************************************************************************/
289 #define XIicPs_ReadReg(BaseAddress, RegOffset) \
290         XIicPs_In32((BaseAddress) + (RegOffset))
291
292 /***************************************************************************/
293 /**
294 * Write an IIC register.
295 *
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.
300 *
301 * @return       None.
302 *
303 * @note C-Style signature:
304 *       void XIicPs_WriteReg(u32 BaseAddress, int RegOffset, u32 RegisterValue)
305 *
306 ******************************************************************************/
307 #define XIicPs_WriteReg(BaseAddress, RegOffset, RegisterValue) \
308         XIicPs_Out32((BaseAddress) + (RegOffset), (RegisterValue))
309
310 /***************************************************************************/
311 /**
312 * Read the interrupt enable register.
313 *
314 * @param        BaseAddress contains the base address of the device.
315 *
316 * @return       Current bit mask that represents currently enabled interrupts.
317 *
318 * @note         C-Style signature:
319 *               u32 XIicPs_ReadIER(u32 BaseAddress)
320 *
321 ******************************************************************************/
322 #define XIicPs_ReadIER(BaseAddress) \
323         XIicPs_ReadReg((BaseAddress),  XIICPS_IER_OFFSET)
324
325 /***************************************************************************/
326 /**
327 * Write to the interrupt enable register.
328 *
329 * @param        BaseAddress contains the base address of the device.
330 *
331 * @param        IntrMask is the interrupts to be enabled.
332 *
333 * @return       None.
334 *
335 * @note C-Style signature:
336 *       void XIicPs_EnabledInterrupts(u32 BaseAddress, u32 IntrMask)
337 *
338 ******************************************************************************/
339 #define XIicPs_EnableInterrupts(BaseAddress, IntrMask) \
340         XIicPs_WriteReg((BaseAddress), XIICPS_IER_OFFSET, (IntrMask))
341
342 /***************************************************************************/
343 /**
344 * Disable all interrupts.
345 *
346 * @param        BaseAddress contains the base address of the device.
347 *
348 * @return       None.
349 *
350 * @note         C-Style signature:
351 *               void XIicPs_DisableAllInterrupts(u32 BaseAddress)
352 *
353 ******************************************************************************/
354 #define XIicPs_DisableAllInterrupts(BaseAddress) \
355         XIicPs_WriteReg((BaseAddress), XIICPS_IDR_OFFSET, \
356                 XIICPS_IXR_ALL_INTR_MASK)
357
358 /***************************************************************************/
359 /**
360 * Disable selected interrupts.
361 *
362 * @param        BaseAddress contains the base address of the device.
363 *
364 * @param        IntrMask is the interrupts to be disabled.
365 *
366 * @return       None.
367 *
368 * @note         C-Style signature:
369 *               void XIicPs_DisableInterrupts(u32 BaseAddress, u32 IntrMask)
370 *
371 ******************************************************************************/
372 #define XIicPs_DisableInterrupts(BaseAddress, IntrMask) \
373         XIicPs_WriteReg((BaseAddress), XIICPS_IDR_OFFSET, \
374                 (IntrMask))
375
376 /************************** Variable Definitions *****************************/
377
378 /************************** Function Prototypes ******************************/
379 /*
380  * Perform reset operation to the I2c interface
381  */
382 void XIicPs_ResetHw(u32 BaseAddr);
383 #ifdef __cplusplus
384 }
385 #endif
386
387 #endif /* end of protection macro */
388