]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/iicps_v3_1/src/xiicps_hw.h
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / iicps_v3_1 / src / xiicps_hw.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 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 xiicps_hw.h
36 * @addtogroup iicps_v3_0
37 * @{
38 *
39 * This header file contains the hardware definition for an IIC device.
40 * It includes register definitions and interface functions to read/write
41 * the registers.
42 *
43 * <pre>
44 * MODIFICATION HISTORY:
45 *
46 * Ver   Who     Date     Changes
47 * ----- ------  -------- -----------------------------------------------
48 * 1.00a drg/jz  01/30/10 First release
49 * 1.04a kpc             11/07/13 Added function prototype.
50 * 3.0   sk              11/03/14 Modified the TimeOut Register value to 0xFF
51 *                               01/31/15 Modified the code according to MISRAC 2012 Compliant.
52 * </pre>
53 *
54 ******************************************************************************/
55 #ifndef XIICPS_HW_H             /* prevent circular inclusions */
56 #define XIICPS_HW_H             /* by using protection macros */
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 /***************************** Include Files *********************************/
63
64 #include "xil_types.h"
65 #include "xil_assert.h"
66 #include "xil_io.h"
67
68 /************************** Constant Definitions *****************************/
69
70 /** @name Register Map
71  *
72  * Register offsets for the IIC.
73  * @{
74  */
75 #define XIICPS_CR_OFFSET                        0x00U  /**< 32-bit Control */
76 #define XIICPS_SR_OFFSET                        0x04U  /**< Status */
77 #define XIICPS_ADDR_OFFSET                      0x08U  /**< IIC Address */
78 #define XIICPS_DATA_OFFSET                      0x0CU  /**< IIC FIFO Data */
79 #define XIICPS_ISR_OFFSET                       0x10U  /**< Interrupt Status */
80 #define XIICPS_TRANS_SIZE_OFFSET        0x14U  /**< Transfer Size */
81 #define XIICPS_SLV_PAUSE_OFFSET         0x18U  /**< Slave monitor pause */
82 #define XIICPS_TIME_OUT_OFFSET          0x1CU  /**< Time Out */
83 #define XIICPS_IMR_OFFSET                       0x20U  /**< Interrupt Enabled Mask */
84 #define XIICPS_IER_OFFSET                       0x24U  /**< Interrupt Enable */
85 #define XIICPS_IDR_OFFSET                       0x28U  /**< Interrupt Disable */
86 /* @} */
87
88 /** @name Control Register
89  *
90  * This register contains various control bits that
91  * affects the operation of the IIC controller. Read/Write.
92  * @{
93  */
94
95 #define XIICPS_CR_DIV_A_MASK    0x0000C000U /**< Clock Divisor A */
96 #define XIICPS_CR_DIV_A_SHIFT                   14U /**< Clock Divisor A shift */
97 #define XIICPS_DIV_A_MAX                                 4U /**< Maximum value of Divisor A */
98 #define XIICPS_CR_DIV_B_MASK    0x00003F00U /**< Clock Divisor B */
99 #define XIICPS_CR_DIV_B_SHIFT                    8U /**< Clock Divisor B shift */
100 #define XIICPS_CR_CLR_FIFO_MASK 0x00000040U /**< Clear FIFO, auto clears*/
101 #define XIICPS_CR_SLVMON_MASK   0x00000020U /**< Slave monitor mode */
102 #define XIICPS_CR_HOLD_MASK             0x00000010U /**<  Hold bus 1=Hold scl,
103                                                                                                 0=terminate transfer */
104 #define XIICPS_CR_ACKEN_MASK    0x00000008U /**< Enable TX of ACK when
105                                                                                                 Master receiver*/
106 #define XIICPS_CR_NEA_MASK              0x00000004U /**< Addressing Mode 1=7 bit,
107                                                                                                 0=10 bit */
108 #define XIICPS_CR_MS_MASK               0x00000002U /**< Master mode bit 1=Master,
109                                                                                                 0=Slave */
110 #define XIICPS_CR_RD_WR_MASK    0x00000001U /**< Read or Write Master
111                                                                                                 transfer  0=Transmitter,
112                                                                                                 1=Receiver*/
113 #define XIICPS_CR_RESET_VALUE                    0U /**< Reset value of the Control
114                                                                                                 register */
115 /* @} */
116
117 /** @name IIC Status Register
118  *
119  * This register is used to indicate status of the IIC controller. Read only
120  * @{
121  */
122 #define XIICPS_SR_BA_MASK               0x00000100U  /**< Bus Active Mask */
123 #define XIICPS_SR_RXOVF_MASK    0x00000080U  /**< Receiver Overflow Mask */
124 #define XIICPS_SR_TXDV_MASK             0x00000040U  /**< Transmit Data Valid Mask */
125 #define XIICPS_SR_RXDV_MASK             0x00000020U  /**< Receiver Data Valid Mask */
126 #define XIICPS_SR_RXRW_MASK             0x00000008U  /**< Receive read/write Mask */
127 /* @} */
128
129 /** @name IIC Address Register
130  *
131  * Normal addressing mode uses add[6:0]. Extended addressing mode uses add[9:0].
132  * A write access to this register always initiates a transfer if the IIC is in
133  * master mode. Read/Write
134  * @{
135  */
136 #define XIICPS_ADDR_MASK        0x000003FF  /**< IIC Address Mask */
137 /* @} */
138
139 /** @name IIC Data Register
140  *
141  * When written to, the data register sets data to transmit. When read from, the
142  * data register reads the last received byte of data. Read/Write
143  * @{
144  */
145 #define XIICPS_DATA_MASK        0x000000FF  /**< IIC Data Mask */
146 /* @} */
147
148 /** @name IIC Interrupt Registers
149  *
150  * <b>IIC Interrupt Status Register</b>
151  *
152  * This register holds the interrupt status flags for the IIC controller. Some
153  * of the flags are level triggered
154  * - i.e. are set as long as the interrupt condition exists.  Other flags are
155  *   edge triggered, which means they are set one the interrupt condition occurs
156  *   then remain set until they are cleared by software.
157  *   The interrupts are cleared by writing a one to the interrupt bit position
158  *   in the Interrupt Status Register. Read/Write.
159  *
160  * <b>IIC Interrupt Enable Register</b>
161  *
162  * This register is used to enable interrupt sources for the IIC controller.
163  * Writing a '1' to a bit in this register clears the corresponding bit in the
164  * IIC Interrupt Mask register.  Write only.
165  *
166  * <b>IIC Interrupt Disable Register </b>
167  *
168  * This register is used to disable interrupt sources for the IIC controller.
169  * Writing a '1' to a bit in this register sets the corresponding bit in the
170  * IIC Interrupt Mask register. Write only.
171  *
172  * <b>IIC Interrupt Mask Register</b>
173  *
174  * This register shows the enabled/disabled status of each IIC controller
175  * interrupt source. A bit set to 1 will ignore the corresponding interrupt in
176  * the status register. A bit set to 0 means the interrupt is enabled.
177  * All mask bits are set and all interrupts are disabled after reset. Read only.
178  *
179  * All four registers have the same bit definitions. They are only defined once
180  * for each of the Interrupt Enable Register, Interrupt Disable Register,
181  * Interrupt Mask Register, and Interrupt Status Register
182  * @{
183  */
184
185 #define XIICPS_IXR_ARB_LOST_MASK  0x00000200U    /**< Arbitration Lost Interrupt
186                                                                                                         mask */
187 #define XIICPS_IXR_RX_UNF_MASK    0x00000080U    /**< FIFO Recieve Underflow
188                                                                                                         Interrupt mask */
189 #define XIICPS_IXR_TX_OVR_MASK    0x00000040U    /**< Transmit Overflow
190                                                                                                         Interrupt mask */
191 #define XIICPS_IXR_RX_OVR_MASK    0x00000020U    /**< Receive Overflow Interrupt
192                                                                                                         mask */
193 #define XIICPS_IXR_SLV_RDY_MASK   0x00000010U    /**< Monitored Slave Ready
194                                                                                                         Interrupt mask */
195 #define XIICPS_IXR_TO_MASK        0x00000008U    /**< Transfer Time Out
196                                                                                                         Interrupt mask */
197 #define XIICPS_IXR_NACK_MASK      0x00000004U    /**< NACK Interrupt mask */
198 #define XIICPS_IXR_DATA_MASK      0x00000002U    /**< Data Interrupt mask */
199 #define XIICPS_IXR_COMP_MASK      0x00000001U    /**< Transfer Complete
200                                                                                                         Interrupt mask */
201 #define XIICPS_IXR_DEFAULT_MASK   0x000002FFU    /**< Default ISR Mask */
202 #define XIICPS_IXR_ALL_INTR_MASK  0x000002FFU    /**< All ISR Mask */
203 /* @} */
204
205
206 /** @name IIC Transfer Size Register
207 *
208 * The register's meaning varies according to the operating mode as follows:
209 *   - Master transmitter mode: number of data bytes still not transmitted minus
210 *     one
211 *   - Master receiver mode: number of data bytes that are still expected to be
212 *     received
213 *   - Slave transmitter mode: number of bytes remaining in the FIFO after the
214 *     master terminates the transfer
215 *   - Slave receiver mode: number of valid data bytes in the FIFO
216 *
217 * This register is cleared if CLR_FIFO bit in the control register is set.
218 * Read/Write
219 * @{
220 */
221 #define XIICPS_TRANS_SIZE_MASK  0x0000003F /**< IIC Transfer Size Mask */
222 #define XIICPS_FIFO_DEPTH          16     /**< Number of bytes in the FIFO */
223 #define XIICPS_DATA_INTR_DEPTH     14    /**< Number of bytes at DATA intr */
224 /* @} */
225
226
227 /** @name IIC Slave Monitor Pause Register
228 *
229 * This register is associated with the slave monitor mode of the I2C interface.
230 * It is meaningful only when the module is in master mode and bit SLVMON in the
231 * control register is set.
232 *
233 * This register defines the pause interval between consecutive attempts to
234 * address the slave once a write to an I2C address register is done by the
235 * host. It represents the number of sclk cycles minus one between two attempts.
236 *
237 * The reset value of the register is 0, which results in the master repeatedly
238 * trying to access the slave immediately after unsuccessful attempt.
239 * Read/Write
240 * @{
241 */
242 #define XIICPS_SLV_PAUSE_MASK    0x0000000F  /**< Slave monitor pause mask */
243 /* @} */
244
245
246 /** @name IIC Time Out Register
247 *
248 * The value of time out register represents the time out interval in number of
249 * sclk cycles minus one.
250 *
251 * When the accessed slave holds the sclk line low for longer than the time out
252 * period, thus prohibiting the I2C interface in master mode to complete the
253 * current transfer, an interrupt is generated and TO interrupt flag is set.
254 *
255 * The reset value of the register is 0x1f.
256 * Read/Write
257 * @{
258  */
259 #define XIICPS_TIME_OUT_MASK    0x000000FFU    /**< IIC Time Out mask */
260 #define XIICPS_TO_RESET_VALUE   0x000000FFU    /**< IIC Time Out reset value */
261 /* @} */
262
263 /**************************** Type Definitions *******************************/
264
265 /***************** Macros (Inline Functions) Definitions *********************/
266
267 #define XIicPs_In32 Xil_In32
268 #define XIicPs_Out32 Xil_Out32
269
270 /****************************************************************************/
271 /**
272 * Read an IIC register.
273 *
274 * @param        BaseAddress contains the base address of the device.
275 * @param        RegOffset contains the offset from the 1st register of the
276 *               device to select the specific register.
277 *
278 * @return       The value read from the register.
279 *
280 * @note         C-Style signature:
281 *               u32 XIicPs_ReadReg(u32 BaseAddress. int RegOffset)
282 *
283 ******************************************************************************/
284 #define XIicPs_ReadReg(BaseAddress, RegOffset) \
285         XIicPs_In32((BaseAddress) + (u32)(RegOffset))
286
287 /***************************************************************************/
288 /**
289 * Write an IIC register.
290 *
291 * @param        BaseAddress contains the base address of the device.
292 * @param        RegOffset contains the offset from the 1st register of the
293 *               device to select the specific register.
294 * @param        RegisterValue is the value to be written to the register.
295 *
296 * @return       None.
297 *
298 * @note C-Style signature:
299 *       void XIicPs_WriteReg(u32 BaseAddress, int RegOffset, u32 RegisterValue)
300 *
301 ******************************************************************************/
302 #define XIicPs_WriteReg(BaseAddress, RegOffset, RegisterValue) \
303         XIicPs_Out32((BaseAddress) + (u32)(RegOffset), (u32)(RegisterValue))
304
305 /***************************************************************************/
306 /**
307 * Read the interrupt enable register.
308 *
309 * @param        BaseAddress contains the base address of the device.
310 *
311 * @return       Current bit mask that represents currently enabled interrupts.
312 *
313 * @note         C-Style signature:
314 *               u32 XIicPs_ReadIER(u32 BaseAddress)
315 *
316 ******************************************************************************/
317 #define XIicPs_ReadIER(BaseAddress) \
318         XIicPs_ReadReg((BaseAddress),  XIICPS_IER_OFFSET)
319
320 /***************************************************************************/
321 /**
322 * Write to the interrupt enable register.
323 *
324 * @param        BaseAddress contains the base address of the device.
325 *
326 * @param        IntrMask is the interrupts to be enabled.
327 *
328 * @return       None.
329 *
330 * @note C-Style signature:
331 *       void XIicPs_EnabledInterrupts(u32 BaseAddress, u32 IntrMask)
332 *
333 ******************************************************************************/
334 #define XIicPs_EnableInterrupts(BaseAddress, IntrMask) \
335         XIicPs_WriteReg((BaseAddress), XIICPS_IER_OFFSET, (IntrMask))
336
337 /***************************************************************************/
338 /**
339 * Disable all interrupts.
340 *
341 * @param        BaseAddress contains the base address of the device.
342 *
343 * @return       None.
344 *
345 * @note         C-Style signature:
346 *               void XIicPs_DisableAllInterrupts(u32 BaseAddress)
347 *
348 ******************************************************************************/
349 #define XIicPs_DisableAllInterrupts(BaseAddress) \
350         XIicPs_WriteReg((BaseAddress), XIICPS_IDR_OFFSET, \
351                 XIICPS_IXR_ALL_INTR_MASK)
352
353 /***************************************************************************/
354 /**
355 * Disable selected interrupts.
356 *
357 * @param        BaseAddress contains the base address of the device.
358 *
359 * @param        IntrMask is the interrupts to be disabled.
360 *
361 * @return       None.
362 *
363 * @note         C-Style signature:
364 *               void XIicPs_DisableInterrupts(u32 BaseAddress, u32 IntrMask)
365 *
366 ******************************************************************************/
367 #define XIicPs_DisableInterrupts(BaseAddress, IntrMask) \
368         XIicPs_WriteReg((BaseAddress), XIICPS_IDR_OFFSET, \
369                 (IntrMask))
370
371 /************************** Variable Definitions *****************************/
372
373 /************************** Function Prototypes ******************************/
374 /*
375  * Perform reset operation to the I2c interface
376  */
377 void XIicPs_ResetHw(u32 BaseAddress);
378 #ifdef __cplusplus
379 }
380 #endif
381
382 #endif /* end of protection macro */
383 /** @} */