1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /*****************************************************************************/
37 * This header file contains the identifiers and basic driver functions (or
38 * macros) that can be used to access the device. Other driver functions
39 * are defined in xspips.h.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ------ -------- -----------------------------------------------
46 * 1.00 drg/jz 01/25/10 First release
47 * 1.02a sg 05/31/12 Updated XSPIPS_FIFO_DEPTH to 128 from 32 to match HW
49 * 1.04a sg 01/30/13 Created XSPIPS_CR_MODF_GEN_EN_MASK macro and added it
50 * to XSPIPS_CR_RESET_STATE. Created
51 * XSPIPS_IXR_WR_TO_CLR_MASK for interrupts which need
52 * write-to-clear. Added shift and mask macros for d_nss
53 * parameter. Added Rx Watermark mask.
54 * 1.06a hk 08/22/13 Added prototypes of reset API and related constant
56 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
60 ******************************************************************************/
62 #ifndef XSPIPS_HW_H /* prevent circular inclusions */
63 #define XSPIPS_HW_H /* by using protection macros */
69 /***************************** Include Files *********************************/
71 #include "xil_types.h"
72 #include "xil_assert.h"
75 /************************** Constant Definitions *****************************/
77 /** @name Register Map
79 * Register offsets from the base address of an SPI device.
82 #define XSPIPS_CR_OFFSET 0x00U /**< Configuration */
83 #define XSPIPS_SR_OFFSET 0x04U /**< Interrupt Status */
84 #define XSPIPS_IER_OFFSET 0x08U /**< Interrupt Enable */
85 #define XSPIPS_IDR_OFFSET 0x0CU /**< Interrupt Disable */
86 #define XSPIPS_IMR_OFFSET 0x10U /**< Interrupt Enabled Mask */
87 #define XSPIPS_ER_OFFSET 0x14U /**< Enable/Disable Register */
88 #define XSPIPS_DR_OFFSET 0x18U /**< Delay Register */
89 #define XSPIPS_TXD_OFFSET 0x1CU /**< Data Transmit Register */
90 #define XSPIPS_RXD_OFFSET 0x20U /**< Data Receive Register */
91 #define XSPIPS_SICR_OFFSET 0x24U /**< Slave Idle Count */
92 #define XSPIPS_TXWR_OFFSET 0x28U /**< Transmit FIFO Watermark */
93 #define XSPIPS_RXWR_OFFSET 0x2CU /**< Receive FIFO Watermark */
96 /** @name Configuration Register
98 * This register contains various control bits that
99 * affects the operation of an SPI device. Read/Write.
102 #define XSPIPS_CR_MODF_GEN_EN_MASK 0x00020000U /**< Modefail Generation
104 #define XSPIPS_CR_MANSTRT_MASK 0x00010000U /**< Manual Transmission Start */
105 #define XSPIPS_CR_MANSTRTEN_MASK 0x00008000U /**< Manual Transmission Start
107 #define XSPIPS_CR_SSFORCE_MASK 0x00004000U /**< Force Slave Select */
108 #define XSPIPS_CR_SSCTRL_MASK 0x00003C00U /**< Slave Select Decode */
109 #define XSPIPS_CR_SSCTRL_SHIFT 10U /**< Slave Select Decode shift */
110 #define XSPIPS_CR_SSCTRL_MAXIMUM 0xFU /**< Slave Select maximum value */
111 #define XSPIPS_CR_SSDECEN_MASK 0x00000200U /**< Slave Select Decode Enable */
113 #define XSPIPS_CR_PRESC_MASK 0x00000038U /**< Prescaler Setting */
114 #define XSPIPS_CR_PRESC_SHIFT 3U /**< Prescaler shift */
115 #define XSPIPS_CR_PRESC_MAXIMUM 0x07U /**< Prescaler maximum value */
117 #define XSPIPS_CR_CPHA_MASK 0x00000004U /**< Phase Configuration */
118 #define XSPIPS_CR_CPOL_MASK 0x00000002U /**< Polarity Configuration */
120 #define XSPIPS_CR_MSTREN_MASK 0x00000001U /**< Master Mode Enable */
121 #define XSPIPS_CR_RESET_STATE 0x00020000U /**< Mode Fail Generation Enable */
125 /** @name SPI Interrupt Registers
127 * <b>SPI Status Register</b>
129 * This register holds the interrupt status flags for an SPI device. Some
130 * of the flags are level triggered, which means that they are set as long
131 * as the interrupt condition exists. Other flags are edge triggered,
132 * which means they are set once the interrupt condition occurs and remain
133 * set until they are cleared by software. The interrupts are cleared by
134 * writing a '1' to the interrupt bit position in the Status Register.
137 * <b>SPI Interrupt Enable Register</b>
139 * This register is used to enable chosen interrupts for an SPI device.
140 * Writing a '1' to a bit in this register sets the corresponding bit in the
141 * SPI Interrupt Mask register. Write only.
143 * <b>SPI Interrupt Disable Register </b>
145 * This register is used to disable chosen interrupts for an SPI device.
146 * Writing a '1' to a bit in this register clears the corresponding bit in the
147 * SPI Interrupt Mask register. Write only.
149 * <b>SPI Interrupt Mask Register</b>
151 * This register shows the enabled/disabled interrupts of an SPI device.
154 * All four registers have the same bit definitions. They are only defined once
155 * for each of the Interrupt Enable Register, Interrupt Disable Register,
156 * Interrupt Mask Register, and Channel Interrupt Status Register
160 #define XSPIPS_IXR_TXUF_MASK 0x00000040U /**< Tx FIFO Underflow */
161 #define XSPIPS_IXR_RXFULL_MASK 0x00000020U /**< Rx FIFO Full */
162 #define XSPIPS_IXR_RXNEMPTY_MASK 0x00000010U /**< Rx FIFO Not Empty */
163 #define XSPIPS_IXR_TXFULL_MASK 0x00000008U /**< Tx FIFO Full */
164 #define XSPIPS_IXR_TXOW_MASK 0x00000004U /**< Tx FIFO Overwater */
165 #define XSPIPS_IXR_MODF_MASK 0x00000002U /**< Mode Fault */
166 #define XSPIPS_IXR_RXOVR_MASK 0x00000001U /**< Rx FIFO Overrun */
167 #define XSPIPS_IXR_DFLT_MASK 0x00000027U /**< Default interrupts
169 #define XSPIPS_IXR_WR_TO_CLR_MASK 0x00000043U /**< Interrupts which
170 need write to clear */
171 #define XSPIPS_ISR_RESET_STATE 0x04U /**< Default to tx/rx
173 #define XSPIPS_IXR_DISABLE_ALL_MASK 0x00000043U /**< Disable all
178 /** @name Enable Register
180 * This register is used to enable or disable an SPI device.
184 #define XSPIPS_ER_ENABLE_MASK 0x00000001U /**< SPI Enable Bit Mask */
188 /** @name Delay Register
190 * This register is used to program timing delays in
191 * slave mode. Read/Write
194 #define XSPIPS_DR_NSS_MASK 0xFF000000U /**< Delay for slave select
195 * de-assertion between
196 * word transfers mask */
197 #define XSPIPS_DR_NSS_SHIFT 24U /**< Delay for slave select
198 * de-assertion between
199 * word transfers shift */
200 #define XSPIPS_DR_BTWN_MASK 0x00FF0000U /**< Delay Between Transfers mask */
201 #define XSPIPS_DR_BTWN_SHIFT 16U /**< Delay Between Transfers shift */
202 #define XSPIPS_DR_AFTER_MASK 0x0000FF00U /**< Delay After Transfers mask */
203 #define XSPIPS_DR_AFTER_SHIFT 8U /**< Delay After Transfers shift */
204 #define XSPIPS_DR_INIT_MASK 0x000000FFU /**< Delay Initially mask */
208 /** @name Slave Idle Count Registers
210 * This register defines the number of pclk cycles the slave waits for a the
211 * SPI clock to become stable in quiescent state before it can detect the start
212 * of the next transfer in CPHA = 1 mode.
217 #define XSPIPS_SICR_MASK 0x000000FFU /**< Slave Idle Count Mask */
222 /** @name Transmit FIFO Watermark Register
224 * This register defines the watermark setting for the Transmit FIFO. The
225 * transmit FIFO is 128 bytes deep, so the register is 7 bits. Valid values
230 #define XSPIPS_TXWR_MASK 0x0000007FU /**< Transmit Watermark Mask */
231 #define XSPIPS_TXWR_RESET_VALUE 0x00000001U /**< Transmit Watermark
232 * register reset value */
235 /** @name Receive FIFO Watermark Register
237 * This register defines the watermark setting for the Receive FIFO. The
238 * receive FIFO is 128 bytes deep, so the register is 7 bits. Valid values
243 #define XSPIPS_RXWR_MASK 0x0000007FU /**< Receive Watermark Mask */
244 #define XSPIPS_RXWR_RESET_VALUE 0x00000001U /**< Receive Watermark
245 * register reset value */
250 * This macro provides the depth of transmit FIFO and receive FIFO.
254 #define XSPIPS_FIFO_DEPTH 128U /**< FIFO depth of Tx and Rx */
257 /**************************** Type Definitions *******************************/
259 /***************** Macros (Inline Functions) Definitions *********************/
261 #define XSpiPs_In32 Xil_In32
262 #define XSpiPs_Out32 Xil_Out32
264 /****************************************************************************/
268 * @param BaseAddress contains the base address of the device.
269 * @param RegOffset contains the offset from the 1st register of the
270 * device to the target register.
272 * @return The value read from the register.
274 * @note C-Style signature:
275 * u32 XSpiPs_ReadReg(u32 BaseAddress. int RegOffset)
277 ******************************************************************************/
278 #define XSpiPs_ReadReg(BaseAddress, RegOffset) \
279 XSpiPs_In32((BaseAddress) + (RegOffset))
281 /***************************************************************************/
283 * Write to a register.
285 * @param BaseAddress contains the base address of the device.
286 * @param RegOffset contains the offset from the 1st register of the
287 * device to target register.
288 * @param RegisterValue is the value to be written to the register.
292 * @note C-Style signature:
293 * void XSpiPs_WriteReg(u32 BaseAddress, int RegOffset,
296 ******************************************************************************/
297 #define XSpiPs_WriteReg(BaseAddress, RegOffset, RegisterValue) \
298 XSpiPs_Out32((BaseAddress) + (RegOffset), (RegisterValue))
300 /************************** Function Prototypes ******************************/
302 void XSpiPs_ResetHw(u32 BaseAddress);
304 /************************** Variable Definitions *****************************/
310 #endif /* end of protection macro */