spi: Spi_v4_5

| spi Xilinx SDK Drivers API Documentation

- Overview
- Data Structures
- APIs
- File List
- Examples

Data Structures | Macros | Typedefs | Functions | Variables
Spi_v4_5

## Data Structures
struct | XSpi_Stats
| XSpi statistics. More...
struct | XSpi_Config
| This typedef contains configuration information for the device. More...
struct | XSpi
| The XSpi driver instance data. More...

## Macros
#define | XSpi_IntrGlobalEnable(InstancePtr)
| This macro writes to the global interrupt enable register to enable interrupts from the device. More...
#define | XSpi_IntrGlobalDisable(InstancePtr) XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_DGIER_OFFSET, 0)
| This macro disables all interrupts for the device by writing to the Global interrupt enable register. More...
#define | XSpi_IsIntrGlobalEnabled(InstancePtr)
| This function determines if interrupts are enabled at the global level by reading the global interrupt register. More...
#define | XSpi_IntrGetStatus(InstancePtr) XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_IISR_OFFSET)
| This function gets the contents of the Interrupt Status Register. More...
#define | XSpi_IntrClear(InstancePtr, ClearMask)
| This function clears the specified interrupts in the Interrupt status Register. More...
#define | XSpi_IntrEnable(InstancePtr, EnableMask)
| This function sets the contents of the Interrupt Enable Register. More...
#define | XSpi_IntrDisable(InstancePtr, DisableMask)
| Disable the specified Interrupts in the Interrupt Enable Register. More...
#define | XSpi_IntrGetEnabled(InstancePtr) XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_IIER_OFFSET)
| This function gets the contents of the Interrupt Enable Register. More...
#define | XSpi_SetControlReg(InstancePtr, Mask) XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET, (Mask))
| Set the contents of the control register. More...
#define | XSpi_GetControlReg(InstancePtr) XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET)
| Get the contents of the control register. More...
#define | XSpi_GetStatusReg(InstancePtr) XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_SR_OFFSET)
| Get the contents of the status register. More...
#define | XSpi_SetXipControlReg(InstancePtr, Mask) XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET, (Mask))
| Set the contents of the XIP control register. More...
#define | XSpi_GetXipControlReg(InstancePtr) XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET)
| Get the contents of the XIP control register. More...
#define | XSpi_GetXipStatusReg(InstancePtr) XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_SR_OFFSET)
| Get the contents of the status register. More...
#define | XSpi_SetSlaveSelectReg(InstancePtr, Mask) XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_SSR_OFFSET, (Mask))
| Set the contents of the slave select register. More...
#define | XSpi_GetSlaveSelectReg(InstancePtr) XSpi_ReadReg((InstancePtr)->BaseAddr, XSP_SSR_OFFSET)
| Get the contents of the slave select register. More...
#define | XSpi_Enable(InstancePtr)
| Enable the device and uninhibit master transactions. More...
#define | XSpi_Disable(InstancePtr)
| Disable the device. More...
#define | XSpi_ReadReg(BaseAddress, RegOffset) XSpi_In32((BaseAddress) + (RegOffset))
| Read from the specified Spi device register. More...
#define | XSpi_WriteReg(BaseAddress, RegOffset, RegisterValue) XSpi_Out32((BaseAddress) + (RegOffset), (RegisterValue))
| Write to the specified Spi device register. More...
#define | XSP_SRR_RESET_MASK 0x0000000A
| SPI Software Reset Register (SRR) mask. More...

## Typedefs
typedef void(* | XSpi_StatusHandler )(void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
| The handler data type allows the user to define a callback function to handle the asynchronous processing of the SPI driver. More...

## Functions
void | XSpi_Abort (XSpi *InstancePtr)
| Aborts a transfer in progress by setting the stop bit in the control register, then resetting the FIFOs if present. More...
int | XSpi_CfgInitialize (XSpi *InstancePtr, XSpi_Config *Config, UINTPTR EffectiveAddr)
| Initializes a specific XSpi instance such that the driver is ready to use. More...
int | XSpi_Start (XSpi *InstancePtr)
| This function enables interrupts for the SPI device. More...
int | XSpi_Stop (XSpi *InstancePtr)
| This function stops the SPI device by disabling interrupts and disabling the device itself. More...
void | XSpi_Reset (XSpi *InstancePtr)
| Resets the SPI device by writing to the Software Reset register. More...
int | XSpi_Transfer (XSpi *InstancePtr, u8 *SendBufPtr, u8 *RecvBufPtr, unsigned int ByteCount)
| Transfers the specified data on the SPI bus. More...
int | XSpi_SetSlaveSelect (XSpi *InstancePtr, u32 SlaveMask)
| Selects or deselect the slave with which the master communicates. More...
u32 | XSpi_GetSlaveSelect (XSpi *InstancePtr)
| Gets the current slave select bit mask for the SPI device. More...
void | XSpi_SetStatusHandler (XSpi *InstancePtr, void *CallBackRef, XSpi_StatusHandler FuncPtr)
| Sets the status callback function, the status handler, which the driver calls when it encounters conditions that should be reported to the higher layer software. More...
void | XSpi_InterruptHandler (void *InstancePtr)
| The interrupt handler for SPI interrupts. More...
int | XSpi_Initialize (XSpi *InstancePtr, u16 DeviceId)
| Initializes a specific XSpi instance such that the driver is ready to use. More...
XSpi_Config * | XSpi_LookupConfig (u16 DeviceId)
| Looks up the device configuration based on the unique device ID. More...
int | XSpi_SelfTest (XSpi *InstancePtr)
| Runs a self-test on the driver/device. More...
void | XSpi_GetStats (XSpi *InstancePtr, XSpi_Stats *StatsPtr)
| Gets a copy of the statistics for an SPI device. More...
void | XSpi_ClearStats (XSpi *InstancePtr)
| Clears the statistics for the SPI device. More...
int | XSpi_SetOptions (XSpi *InstancePtr, u32 Options)
| This function sets the options for the SPI device driver. More...
u32 | XSpi_GetOptions (XSpi *InstancePtr)
| This function gets the options for the SPI device. More...

## Variables
XSpi_Config | XSpi_ConfigTable [XPAR_XSPI_NUM_INSTANCES]
| This table contains configuration information for each SPI device in the system. More...
XSpi_Config | XSpi_ConfigTable []
| This table contains configuration information for each SPI device in the system. More...
XSpi_Config | XSpi_ConfigTable []
| This table contains configuration information for each SPI device in the system. More...

## Configuration options
The following options may be specified or retrieved for the device and enable/disable additional features of the SPI. Each of the options are bit fields, so more than one may be specified.
#define | XSP_MASTER_OPTION 0x1
#define | XSP_CLK_ACTIVE_LOW_OPTION 0x2
#define | XSP_CLK_PHASE_1_OPTION 0x4
#define | XSP_LOOPBACK_OPTION 0x8
#define | XSP_MANUAL_SSELECT_OPTION 0x10

## Register Map
XSPI register offsets Register offsets for the XSpi device.
#define | XSP_DGIER_OFFSET 0x1C
| Global Intr Enable Reg. More...
#define | XSP_IISR_OFFSET 0x20
| Interrupt status Reg. More...
#define | XSP_IIER_OFFSET 0x28
| Interrupt Enable Reg. More...
#define | XSP_SRR_OFFSET 0x40
| Software Reset register. More...
#define | XSP_CR_OFFSET 0x60
| Control register. More...
#define | XSP_SR_OFFSET 0x64
| Status Register. More...
#define | XSP_DTR_OFFSET 0x68
| Data transmit. More...
#define | XSP_DRR_OFFSET 0x6C
| Data receive. More...
#define | XSP_SSR_OFFSET 0x70
| 32-bit slave select More...
#define | XSP_TFO_OFFSET 0x74
| Tx FIFO occupancy. More...
#define | XSP_RFO_OFFSET 0x78
| Rx FIFO occupancy. More...

## Global Interrupt Enable Register (GIER) mask(s)
#define | XSP_GINTR_ENABLE_MASK 0x80000000
| Global interrupt enable. More...

## SPI Device Interrupt Status/Enable Registers
Interrupt Status Register (IPISR) This register holds the interrupt status flags for the Spi device. Interrupt Enable Register (IPIER) This register is used to enable interrupt sources for the Spi device. Writing a '1' to a bit in this register enables the corresponding Interrupt. Writing a '0' to a bit in this register disables the corresponding Interrupt. ISR/IER registers have the same bit definitions and are only defined once.
#define | XSP_INTR_MODE_FAULT_MASK 0x00000001
| Mode fault error. More...
#define | XSP_INTR_SLAVE_MODE_FAULT_MASK 0x00000002
| Selected as slave while disabled. More...
#define | XSP_INTR_TX_EMPTY_MASK 0x00000004
| DTR/TxFIFO is empty. More...
#define | XSP_INTR_TX_UNDERRUN_MASK 0x00000008
| DTR/TxFIFO underrun. More...
#define | XSP_INTR_RX_FULL_MASK 0x00000010
| DRR/RxFIFO is full. More...
#define | XSP_INTR_RX_OVERRUN_MASK 0x00000020
| DRR/RxFIFO overrun. More...
#define | XSP_INTR_TX_HALF_EMPTY_MASK 0x00000040
| TxFIFO is half empty. More...
#define | XSP_INTR_SLAVE_MODE_MASK 0x00000080
| Slave select mode. More...
#define | XSP_INTR_RX_NOT_EMPTY_MASK 0x00000100
| RxFIFO not empty. More...
#define | XSP_INTR_CPOL_CPHA_ERR_MASK 0x00000200
| The following bits are available only in axi_qspi Interrupt Status and Interrupt Enable registers. More...
#define | XSP_INTR_SLAVE_MODE_ERR_MASK 0x00000400
| Slave mode error. More...
#define | XSP_INTR_MSB_ERR_MASK 0x00000800
| MSB Error. More...
#define | XSP_INTR_LOOP_BACK_ERR_MASK 0x00001000
| Loop back error. More...
#define | XSP_INTR_CMD_ERR_MASK 0x00002000
| 'Invalid cmd' error More...
#define | XSP_INTR_ALL
| Mask for all the interrupts in the IP Interrupt Registers. More...
#define | XSP_INTR_DFT_MASK
| The interrupts we want at startup. More...

## SPI Control Register (CR) masks
#define | XSP_CR_LOOPBACK_MASK 0x00000001
| Local loopback mode. More...
#define | XSP_CR_ENABLE_MASK 0x00000002
| System enable. More...
#define | XSP_CR_MASTER_MODE_MASK 0x00000004
| Enable master mode. More...
#define | XSP_CR_CLK_POLARITY_MASK 0x00000008
| Clock polarity high or low. More...
#define | XSP_CR_CLK_PHASE_MASK 0x00000010
| Clock phase 0 or 1. More...
#define | XSP_CR_TXFIFO_RESET_MASK 0x00000020
| Reset transmit FIFO. More...
#define | XSP_CR_RXFIFO_RESET_MASK 0x00000040
| Reset receive FIFO. More...
#define | XSP_CR_MANUAL_SS_MASK 0x00000080
| Manual slave select assert. More...
#define | XSP_CR_TRANS_INHIBIT_MASK 0x00000100
| Master transaction inhibit. More...
#define | XSP_CR_LSB_MSB_FIRST_MASK 0x00000200
| LSB/MSB first data format select. More...

## SPI Control Register (CR) masks for XIP Mode
#define | XSP_CR_XIP_CLK_PHASE_MASK 0x00000001
| Clock phase 0 or 1. More...
#define | XSP_CR_XIP_CLK_POLARITY_MASK 0x00000002
| Clock polarity high or low. More...

## Status Register (SR) masks
#define | XSP_SR_RX_EMPTY_MASK 0x00000001
| Receive Reg/FIFO is empty. More...
#define | XSP_SR_RX_FULL_MASK 0x00000002
| Receive Reg/FIFO is full. More...
#define | XSP_SR_TX_EMPTY_MASK 0x00000004
| Transmit Reg/FIFO is empty. More...
#define | XSP_SR_TX_FULL_MASK 0x00000008
| Transmit Reg/FIFO is full. More...
#define | XSP_SR_MODE_FAULT_MASK 0x00000010
| Mode fault error. More...
#define | XSP_SR_SLAVE_MODE_MASK 0x00000020
| Slave mode select. More...
#define | XSP_SR_CPOL_CPHA_ERR_MASK 0x00000040
| CPOL/CPHA error. More...
#define | XSP_SR_SLAVE_MODE_ERR_MASK 0x00000080
| Slave mode error. More...
#define | XSP_SR_MSB_ERR_MASK 0x00000100
| MSB Error. More...
#define | XSP_SR_LOOP_BACK_ERR_MASK 0x00000200
| Loop back error. More...
#define | XSP_SR_CMD_ERR_MASK 0x00000400
| 'Invalid cmd' error More...

## Status Register (SR) masks for XIP Mode
#define | XSP_SR_XIP_RX_EMPTY_MASK 0x00000001
| Receive Reg/FIFO is empty. More...
#define | XSP_SR_XIP_RX_FULL_MASK 0x00000002
| Receive Reg/FIFO is full. More...
#define | XSP_SR_XIP_MASTER_MODF_MASK 0x00000004
| Receive Reg/FIFO is full. More...
#define | XSP_SR_XIP_CPHPL_ERROR_MASK 0x00000008
| Clock Phase,Clock Polarity Error. More...
#define | XSP_SR_XIP_AXI_ERROR_MASK 0x00000010
| AXI Transaction Error. More...

## SPI Transmit FIFO Occupancy (TFO) mask
#define | XSP_TFO_MASK 0x0000001F

## SPI Receive FIFO Occupancy (RFO) mask
#define | XSP_RFO_MASK 0x0000001F

## Data Width Definitions
#define | XSP_DATAWIDTH_BYTE 8
| Tx/Rx Reg is Byte Wide. More...
#define | XSP_DATAWIDTH_HALF_WORD 16
| Tx/Rx Reg is Half Word (16 bit) Wide. More...
#define | XSP_DATAWIDTH_WORD 32
| Tx/Rx Reg is Word (32 bit) Wide. More...

## SPI Modes
The following constants define the modes in which qxi_qspi operates.
#define | XSP_STANDARD_MODE 0
#define | XSP_DUAL_MODE 1
#define | XSP_QUAD_MODE 2

## Macro Definition Documentation

#define XSP_CR_CLK_PHASE_MASK 0x00000010

Clock phase 0 or 1.

#define XSP_CR_CLK_POLARITY_MASK 0x00000008

Clock polarity high or low.

#define XSP_CR_ENABLE_MASK 0x00000002

System enable.

Referenced by XSpi_CfgInitialize(), XSpi_LowLevelExample(), XSpi_Start(), and XSpi_Stop().

#define XSP_CR_LOOPBACK_MASK 0x00000001

Local loopback mode.

Referenced by XSpi_LowLevelExample(), and XSpi_Transfer().

#define XSP_CR_LSB_MSB_FIRST_MASK 0x00000200

LSB/MSB first data format select.

The default data format is MSB first. The LSB first data format is not available in all versions of the Xilinx Spi Device whereas the MSB first data format is supported by all the versions of the Xilinx Spi Devices. Please check the HW specification to see if this feature is supported or not.

#define XSP_CR_MANUAL_SS_MASK 0x00000080

Manual slave select assert.

#define XSP_CR_MASTER_MODE_MASK 0x00000004

Enable master mode.

Referenced by XSpi_CfgInitialize(), XSpi_LowLevelExample(), and XSpi_Transfer().

#define XSP_CR_OFFSET 0x60

Control register.

Referenced by XSpi_LowLevelExample().

#define XSP_CR_RXFIFO_RESET_MASK 0x00000040

Reset receive FIFO.

Referenced by XSpi_Abort(), XSpi_CfgInitialize(), and XSpi_Start().

#define XSP_CR_TRANS_INHIBIT_MASK 0x00000100

Master transaction inhibit.

Referenced by XSpi_Abort(), XSpi_CfgInitialize(), XSpi_LowLevelExample(), and XSpi_Transfer().

#define XSP_CR_TXFIFO_RESET_MASK 0x00000020

Reset transmit FIFO.

Referenced by XSpi_Abort(), XSpi_CfgInitialize(), and XSpi_Start().

#define XSP_CR_XIP_CLK_PHASE_MASK 0x00000001

Clock phase 0 or 1.

#define XSP_CR_XIP_CLK_POLARITY_MASK 0x00000002

Clock polarity high or low.

#define XSP_DATAWIDTH_BYTE 8

Tx/Rx Reg is Byte Wide.

Referenced by XSpi_CfgInitialize(), XSpi_InterruptHandler(), and XSpi_Transfer().

#define XSP_DATAWIDTH_HALF_WORD 16

Tx/Rx Reg is Half Word (16 bit) Wide.

Referenced by XSpi_InterruptHandler(), and XSpi_Transfer().

#define XSP_DATAWIDTH_WORD 32

Tx/Rx Reg is Word (32 bit) Wide.

Referenced by XSpi_InterruptHandler(), and XSpi_Transfer().

#define XSP_DGIER_OFFSET 0x1C

Global Intr Enable Reg.

#define XSP_DRR_OFFSET 0x6C

Data receive.

Referenced by XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LowLevelExample(), and XSpi_Transfer().

#define XSP_DTR_OFFSET 0x68

Data transmit.

Referenced by XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LowLevelExample(), and XSpi_Transfer().

#define XSP_GINTR_ENABLE_MASK 0x80000000

Global interrupt enable.

#define XSP_IIER_OFFSET 0x28

Interrupt Enable Reg.

#define XSP_IISR_OFFSET 0x20

Interrupt status Reg.

#define XSP_INTR_ALL

Value:
(XSP_INTR_MODE_FAULT_MASK | \
XSP_INTR_SLAVE_MODE_FAULT_MASK | \
XSP_INTR_TX_EMPTY_MASK | \
XSP_INTR_TX_UNDERRUN_MASK | \
XSP_INTR_RX_FULL_MASK | \
XSP_INTR_TX_HALF_EMPTY_MASK | \
XSP_INTR_RX_OVERRUN_MASK | \
XSP_INTR_SLAVE_MODE_MASK | \
XSP_INTR_RX_NOT_EMPTY_MASK | \
XSP_INTR_CMD_ERR_MASK | \
XSP_INTR_LOOP_BACK_ERR_MASK | \
XSP_INTR_MSB_ERR_MASK | \
XSP_INTR_SLAVE_MODE_ERR_MASK | \
XSP_INTR_CPOL_CPHA_ERR_MASK)
XSP_INTR_RX_NOT_EMPTY_MASK
#define XSP_INTR_RX_NOT_EMPTY_MASK
RxFIFO not empty.
Definition: xspi_l.h:178
XSP_INTR_RX_FULL_MASK
#define XSP_INTR_RX_FULL_MASK
DRR/RxFIFO is full.
Definition: xspi_l.h:174
XSP_INTR_MODE_FAULT_MASK
#define XSP_INTR_MODE_FAULT_MASK
Mode fault error.
Definition: xspi_l.h:168
XSP_INTR_TX_EMPTY_MASK
#define XSP_INTR_TX_EMPTY_MASK
DTR/TxFIFO is empty.
Definition: xspi_l.h:172
XSP_INTR_TX_UNDERRUN_MASK
#define XSP_INTR_TX_UNDERRUN_MASK
DTR/TxFIFO underrun.
Definition: xspi_l.h:173
XSP_INTR_SLAVE_MODE_MASK
#define XSP_INTR_SLAVE_MODE_MASK
Slave select mode.
Definition: xspi_l.h:177
XSP_INTR_SLAVE_MODE_FAULT_MASK
#define XSP_INTR_SLAVE_MODE_FAULT_MASK
Selected as slave while disabled.
Definition: xspi_l.h:169
XSP_INTR_RX_OVERRUN_MASK
#define XSP_INTR_RX_OVERRUN_MASK
DRR/RxFIFO overrun.
Definition: xspi_l.h:175
XSP_INTR_MSB_ERR_MASK
#define XSP_INTR_MSB_ERR_MASK
MSB Error.
Definition: xspi_l.h:186
XSP_INTR_CPOL_CPHA_ERR_MASK
#define XSP_INTR_CPOL_CPHA_ERR_MASK
The following bits are available only in axi_qspi Interrupt Status and Interrupt Enable registers...
Definition: xspi_l.h:184
XSP_INTR_SLAVE_MODE_ERR_MASK
#define XSP_INTR_SLAVE_MODE_ERR_MASK
Slave mode error.
Definition: xspi_l.h:185
XSP_INTR_LOOP_BACK_ERR_MASK
#define XSP_INTR_LOOP_BACK_ERR_MASK
Loop back error.
Definition: xspi_l.h:187
XSP_INTR_CMD_ERR_MASK
#define XSP_INTR_CMD_ERR_MASK
&#39;Invalid cmd&#39; error
Definition: xspi_l.h:188
XSP_INTR_TX_HALF_EMPTY_MASK
#define XSP_INTR_TX_HALF_EMPTY_MASK
TxFIFO is half empty.
Definition: xspi_l.h:176

Mask for all the interrupts in the IP Interrupt Registers.

#define XSP_INTR_CMD_ERR_MASK 0x00002000

'Invalid cmd' error

Referenced by XSpi_InterruptHandler().

#define XSP_INTR_CPOL_CPHA_ERR_MASK 0x00000200

The following bits are available only in axi_qspi Interrupt Status and Interrupt Enable registers.

CPOL/CPHA error

#define XSP_INTR_DFT_MASK

Value:
(XSP_INTR_MODE_FAULT_MASK | \
XSP_INTR_TX_UNDERRUN_MASK | \
XSP_INTR_RX_OVERRUN_MASK | \
XSP_INTR_SLAVE_MODE_FAULT_MASK | \
XSP_INTR_CMD_ERR_MASK)
XSP_INTR_MODE_FAULT_MASK
#define XSP_INTR_MODE_FAULT_MASK
Mode fault error.
Definition: xspi_l.h:168
XSP_INTR_TX_UNDERRUN_MASK
#define XSP_INTR_TX_UNDERRUN_MASK
DTR/TxFIFO underrun.
Definition: xspi_l.h:173
XSP_INTR_SLAVE_MODE_FAULT_MASK
#define XSP_INTR_SLAVE_MODE_FAULT_MASK
Selected as slave while disabled.
Definition: xspi_l.h:169
XSP_INTR_RX_OVERRUN_MASK
#define XSP_INTR_RX_OVERRUN_MASK
DRR/RxFIFO overrun.
Definition: xspi_l.h:175
XSP_INTR_CMD_ERR_MASK
#define XSP_INTR_CMD_ERR_MASK
&#39;Invalid cmd&#39; error
Definition: xspi_l.h:188

The interrupts we want at startup.

We add the TX_EMPTY interrupt in later when we're getting ready to transfer data. The others we don't care about for now.

Referenced by XSpi_Start().

#define XSP_INTR_LOOP_BACK_ERR_MASK 0x00001000

Loop back error.

#define XSP_INTR_MODE_FAULT_MASK 0x00000001

Mode fault error.

Referenced by XSpi_InterruptHandler().

#define XSP_INTR_MSB_ERR_MASK 0x00000800

MSB Error.

#define XSP_INTR_RX_FULL_MASK 0x00000010

DRR/RxFIFO is full.

#define XSP_INTR_RX_NOT_EMPTY_MASK 0x00000100

RxFIFO not empty.

Referenced by XSpi_InterruptHandler().

#define XSP_INTR_RX_OVERRUN_MASK 0x00000020

DRR/RxFIFO overrun.

Referenced by XSpi_InterruptHandler().

#define XSP_INTR_SLAVE_MODE_ERR_MASK 0x00000400

Slave mode error.

#define XSP_INTR_SLAVE_MODE_FAULT_MASK 0x00000002

Selected as slave while disabled.

Referenced by XSpi_InterruptHandler().

#define XSP_INTR_SLAVE_MODE_MASK 0x00000080

Slave select mode.

Referenced by XSpi_InterruptHandler().

#define XSP_INTR_TX_EMPTY_MASK 0x00000004

DTR/TxFIFO is empty.

Referenced by XSpi_InterruptHandler(), and XSpi_Transfer().

#define XSP_INTR_TX_HALF_EMPTY_MASK 0x00000040

TxFIFO is half empty.

Referenced by XSpi_InterruptHandler().

#define XSP_INTR_TX_UNDERRUN_MASK 0x00000008

DTR/TxFIFO underrun.

Referenced by XSpi_InterruptHandler().

#define XSP_MASTER_OPTION 0x1

    The Master option configures the SPI device as a master. By default, the
    device is a slave.

    The Active Low Clock option configures the device's clock polarity. Setting
    this option means the clock is active low and the SCK signal idles high. By
    default, the clock is active high and SCK idles low.

    The Clock Phase option configures the SPI device for one of two transfer
    formats.  A clock phase of 0, the default, means data if valid on the first
    SCK edge (rising or falling) after the slave select (SS) signal has been
    asserted. A clock phase of 1 means data is valid on the second SCK edge
    (rising or falling) after SS has been asserted.

    The Loopback option configures the SPI device for loopback mode.  Data is
    looped back from the transmitter to the receiver.

    The Manual Slave Select option, which is default, causes the device not
    to automatically drive the slave select.  The driver selects the device
    at the start of a transfer and deselects it at the end of a transfer.
    If this option is off, then the device automatically toggles the slave
    select signal between bytes in a transfer.

Referenced by main(), SpiIntrExample(), SpiPolledExample(), and XSpi_SetOptions().

#define XSP_RFO_OFFSET 0x78

Rx FIFO occupancy.

Referenced by XSpi_SelfTest().

#define XSP_SR_CMD_ERR_MASK 0x00000400

'Invalid cmd' error

#define XSP_SR_CPOL_CPHA_ERR_MASK 0x00000040

CPOL/CPHA error.

#define XSP_SR_LOOP_BACK_ERR_MASK 0x00000200

Loop back error.

#define XSP_SR_MODE_FAULT_MASK 0x00000010

Mode fault error.

#define XSP_SR_MSB_ERR_MASK 0x00000100

MSB Error.

#define XSP_SR_OFFSET 0x64

Status Register.

Referenced by XSpi_LowLevelExample().

#define XSP_SR_RX_EMPTY_MASK 0x00000001

Receive Reg/FIFO is empty.

Referenced by XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LowLevelExample(), and XSpi_Transfer().

#define XSP_SR_RX_FULL_MASK 0x00000002

Receive Reg/FIFO is full.

#define XSP_SR_SLAVE_MODE_ERR_MASK 0x00000080

Slave mode error.

#define XSP_SR_SLAVE_MODE_MASK 0x00000020

Slave mode select.

#define XSP_SR_TX_EMPTY_MASK 0x00000004

Transmit Reg/FIFO is empty.

Referenced by XSpi_LowLevelExample().

#define XSP_SR_TX_FULL_MASK 0x00000008

Transmit Reg/FIFO is full.

Referenced by XSpi_InterruptHandler(), XSpi_LowLevelExample(), and XSpi_Transfer().

#define XSP_SR_XIP_AXI_ERROR_MASK 0x00000010

AXI Transaction Error.

#define XSP_SR_XIP_CPHPL_ERROR_MASK 0x00000008

Clock Phase,Clock Polarity Error.

#define XSP_SR_XIP_MASTER_MODF_MASK 0x00000004

Receive Reg/FIFO is full.

#define XSP_SR_XIP_RX_EMPTY_MASK 0x00000001

Receive Reg/FIFO is empty.

#define XSP_SR_XIP_RX_FULL_MASK 0x00000002

Receive Reg/FIFO is full.

#define XSP_SRR_OFFSET 0x40

Software Reset register.

Referenced by XSpi_Reset().

#define XSP_SRR_RESET_MASK 0x0000000A

SPI Software Reset Register (SRR) mask.

Referenced by XSpi_Reset().

#define XSP_SSR_OFFSET 0x70

32-bit slave select

#define XSP_TFO_OFFSET 0x74

Tx FIFO occupancy.

Referenced by XSpi_SelfTest().

#define XSpi_Disable | ( |  | InstancePtr | ) |

Value:
XSpi_SetControlReg((InstancePtr), \
XSpi_GetControlReg((InstancePtr)) & ~XSP_CR_ENABLE_MASK)
XSP_CR_ENABLE_MASK
#define XSP_CR_ENABLE_MASK
System enable.
Definition: xspi_l.h:231
XSpi_SetControlReg
#define XSpi_SetControlReg(InstancePtr, Mask)
Set the contents of the control register.
Definition: xspi.h:633
XSpi_GetControlReg
#define XSpi_GetControlReg(InstancePtr)
Get the contents of the control register.
Definition: xspi.h:651

Disable the device.

Preserves the current contents of the control register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note
  C-Style signature: void XSpi_Disable(XSpi *InstancePtr);

#define XSpi_Enable | ( |  | InstancePtr | ) |

Value:
{ \
u16 Control; \
Control = XSpi_GetControlReg((InstancePtr)); \
Control |= XSP_CR_ENABLE_MASK; \
Control &= ~XSP_CR_TRANS_INHIBIT_MASK; \
XSpi_SetControlReg((InstancePtr), Control); \
}
XSP_CR_ENABLE_MASK
#define XSP_CR_ENABLE_MASK
System enable.
Definition: xspi_l.h:231
XSpi_SetControlReg
#define XSpi_SetControlReg(InstancePtr, Mask)
Set the contents of the control register.
Definition: xspi.h:633
XSP_CR_TRANS_INHIBIT_MASK
#define XSP_CR_TRANS_INHIBIT_MASK
Master transaction inhibit.
Definition: xspi_l.h:242
XSpi_GetControlReg
#define XSpi_GetControlReg(InstancePtr)
Get the contents of the control register.
Definition: xspi.h:651

Enable the device and uninhibit master transactions.

Preserves the current contents of the control register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note
  C-Style signature: void XSpi_Enable(XSpi *InstancePtr);

#define XSpi_GetControlReg | ( |  | InstancePtr | ) | XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET)

Get the contents of the control register.

Use the XSP_CR_* constants defined above to interpret the bit-mask returned.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  A 32-bit value representing the contents of the control register.

Note
  C-Style signature: u32 XSpi_GetControlReg(XSpi *InstancePtr);

Referenced by XSpi_Abort(), XSpi_CfgInitialize(), XSpi_GetOptions(), XSpi_SelfTest(), XSpi_SetOptions(), XSpi_Start(), XSpi_Stop(), and XSpi_Transfer().

#define XSpi_GetSlaveSelectReg | ( |  | InstancePtr | ) | XSpi_ReadReg((InstancePtr)->BaseAddr, XSP_SSR_OFFSET)

Get the contents of the slave select register.

Each bit in the mask corresponds to a slave select line. Only one slave should be selected at any one time.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  The 32-bit value in the slave select register.

Note
  C-Style signature: u32 XSpi_GetSlaveSelectReg(XSpi *InstancePtr);

Referenced by XSpi_SelfTest().

#define XSpi_GetStatusReg | ( |  | InstancePtr | ) | XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_SR_OFFSET)

Get the contents of the status register.

Use the XSP_SR_* constants defined above to interpret the bit-mask returned.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  An 32-bit value representing the contents of the status register.

Note
  C-Style signature: u8 XSpi_GetStatusReg(XSpi *InstancePtr);

Referenced by XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_SelfTest(), and XSpi_Transfer().

#define XSpi_GetXipControlReg | ( |  | InstancePtr | ) | XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET)

Get the contents of the XIP control register.

Use the XSP_CR_XIP_* constants defined above to interpret the bit-mask returned.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  A 32-bit value representing the contents of the control register.

Note
  C-Style signature: u32 XSpi_GetXipControlReg(XSpi *InstancePtr);

#define XSpi_GetXipStatusReg | ( |  | InstancePtr | ) | XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_SR_OFFSET)

Get the contents of the status register.

Use the XSP_SR_XIP_* constants defined above to interpret the bit-mask returned.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  An 32-bit value representing the contents of the status register.

Note
  C-Style signature: u8 XSpi_GetXipStatusReg(XSpi *InstancePtr);

#define XSpi_IntrClear | ( |  | InstancePtr,
|  |  | ClearMask
| ) |  |

Value:
XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_IISR_OFFSET, \
XSpi_IntrGetStatus(InstancePtr) | (ClearMask))
XSpi_IntrGetStatus
#define XSpi_IntrGetStatus(InstancePtr)
This function gets the contents of the Interrupt Status Register.
Definition: xspi.h:524
XSpi_WriteReg
#define XSpi_WriteReg(BaseAddress, RegOffset, RegisterValue)
Write to the specified Spi device register.
Definition: xspi_l.h:114
XSP_IISR_OFFSET
#define XSP_IISR_OFFSET
Interrupt status Reg.
Definition: xspi_l.h:130

This function clears the specified interrupts in the Interrupt status Register.

The interrupt is cleared by writing to this register with the bits to be cleared set to a one and all others bits to zero. Setting a bit which is zero within this register causes an interrupt to be generated.

This function writes only the specified value to the register such that some status bits may be set and others cleared. It is the caller's responsibility to get the value of the register prior to setting the value to prevent an destructive behavior.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  ClearMask | is the Bitmask for interrupts to be cleared. Bit positions of "1" clears the interrupt. Bit positions of 0 will keep the previous setting. This mask is formed by OR'ing XSP_INTR_* bits defined in xspi_l.h.

Returns
  None.

Note
  C-Style signature: void XSpi_IntrClear(XSpi *InstancePtr, u32 ClearMask);

Referenced by XSpi_InterruptHandler(), and XSpi_Transfer().

#define XSpi_IntrDisable | ( |  | InstancePtr,
|  |  | DisableMask
| ) |  |

Value:
XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_IIER_OFFSET, \
XSpi_ReadReg(((InstancePtr)->BaseAddr), \
XSP_IIER_OFFSET) & (~ ((DisableMask) & XSP_INTR_ALL )))
XSP_INTR_ALL
#define XSP_INTR_ALL
Mask for all the interrupts in the IP Interrupt Registers.
Definition: xspi_l.h:193
XSP_IIER_OFFSET
#define XSP_IIER_OFFSET
Interrupt Enable Reg.
Definition: xspi_l.h:131
XSpi_WriteReg
#define XSpi_WriteReg(BaseAddress, RegOffset, RegisterValue)
Write to the specified Spi device register.
Definition: xspi_l.h:114
XSpi_ReadReg
#define XSpi_ReadReg(BaseAddress, RegOffset)
Read from the specified Spi device register.
Definition: xspi_l.h:95

Disable the specified Interrupts in the Interrupt Enable Register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  DisableMask | is the bitmask of the interrupts to be disabled. Bit positions of 1 will be disabled. Bit positions of 0 will keep the previous setting. This mask is formed by OR'ing XSP_INTR_* bits defined in xspi_l.h.

Returns
  None.

Note
  C-Style signature: void XSpi_IntrDisable(XSpi *InstancePtr, u32 DisableMask);

Referenced by XSpi_InterruptHandler().

#define XSpi_IntrEnable | ( |  | InstancePtr,
|  |  | EnableMask
| ) |  |

Value:
XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_IIER_OFFSET, \
(XSpi_ReadReg(((InstancePtr)->BaseAddr), \
XSP_IIER_OFFSET)) | (((EnableMask) & XSP_INTR_ALL )))
XSP_INTR_ALL
#define XSP_INTR_ALL
Mask for all the interrupts in the IP Interrupt Registers.
Definition: xspi_l.h:193
XSP_IIER_OFFSET
#define XSP_IIER_OFFSET
Interrupt Enable Reg.
Definition: xspi_l.h:131
XSpi_WriteReg
#define XSpi_WriteReg(BaseAddress, RegOffset, RegisterValue)
Write to the specified Spi device register.
Definition: xspi_l.h:114
XSpi_ReadReg
#define XSpi_ReadReg(BaseAddress, RegOffset)
Read from the specified Spi device register.
Definition: xspi_l.h:95

This function sets the contents of the Interrupt Enable Register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  EnableMask | is the bitmask of the interrupts to be enabled. Bit positions of 1 will be enabled. Bit positions of 0 will keep the previous setting. This mask is formed by OR'ing XSP_INTR_* bits defined in xspi_l.h.

Returns
  None.

Note
  C-Style signature: void XSpi_IntrEnable(XSpi *InstancePtr, u32 EnableMask);

Referenced by XSpi_Start(), and XSpi_Transfer().

#define XSpi_IntrGetEnabled | ( |  | InstancePtr | ) | XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_IIER_OFFSET)

This function gets the contents of the Interrupt Enable Register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  The contents read from the Interrupt Enable Register.

Note
  C-Style signature: u32 XSpi_IntrGetEnabled(XSpi *InstancePtr)

#define XSpi_IntrGetStatus | ( |  | InstancePtr | ) | XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_IISR_OFFSET)

This function gets the contents of the Interrupt Status Register.

This register indicates the status of interrupt sources for the device. The status is independent of whether interrupts are enabled such that the status register may also be polled when interrupts are not enabled.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  A status which contains the value read from the Interrupt Status Register.

Note
  C-Style signature: u32 XSpi_IntrGetStatus(XSpi *InstancePtr);

Referenced by XSpi_InterruptHandler(), and XSpi_Transfer().

#define XSpi_IntrGlobalDisable | ( |  | InstancePtr | ) | XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_DGIER_OFFSET, 0)

This macro disables all interrupts for the device by writing to the Global interrupt enable register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note
  C-Style signature: void XSpi_IntrGlobalDisable(XSpi *InstancePtr);

Referenced by SpiPolledExample(), XSpi_Stop(), and XSpi_Transfer().

#define XSpi_IntrGlobalEnable | ( |  | InstancePtr | ) |

Value:
XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_DGIER_OFFSET, \
XSP_GINTR_ENABLE_MASK)
XSP_DGIER_OFFSET
#define XSP_DGIER_OFFSET
Global Intr Enable Reg.
Definition: xspi_l.h:129
XSP_GINTR_ENABLE_MASK
#define XSP_GINTR_ENABLE_MASK
Global interrupt enable.
Definition: xspi_l.h:148
XSpi_WriteReg
#define XSpi_WriteReg(BaseAddress, RegOffset, RegisterValue)
Write to the specified Spi device register.
Definition: xspi_l.h:114

This macro writes to the global interrupt enable register to enable interrupts from the device.

Interrupts enabled using XSpi_IntrEnable() will not occur until the global interrupt enable bit is set by using this function.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note
  C-Style signature: void XSpi_IntrGlobalEnable(XSpi *InstancePtr);

Referenced by XSpi_Start(), and XSpi_Transfer().

#define XSpi_IsIntrGlobalEnabled | ( |  | InstancePtr | ) |

Value:
(XSpi_ReadReg(((InstancePtr)->BaseAddr), XSP_DGIER_OFFSET) == \
XSP_GINTR_ENABLE_MASK)
XSP_DGIER_OFFSET
#define XSP_DGIER_OFFSET
Global Intr Enable Reg.
Definition: xspi_l.h:129
XSP_GINTR_ENABLE_MASK
#define XSP_GINTR_ENABLE_MASK
Global interrupt enable.
Definition: xspi_l.h:148
XSpi_ReadReg
#define XSpi_ReadReg(BaseAddress, RegOffset)
Read from the specified Spi device register.
Definition: xspi_l.h:95

This function determines if interrupts are enabled at the global level by reading the global interrupt register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  - TRUE if global interrupts are enabled.
  - FALSE if global interrupts are disabled.

Note
  C-Style signature: int XSpi_IsIntrGlobalEnabled(XSpi *InstancePtr);

Referenced by XSpi_Transfer().

#define XSpi_ReadReg | ( |  | BaseAddress,
|  |  | RegOffset
| ) |  | XSpi_In32((BaseAddress) + (RegOffset))

Read from the specified Spi device register.

Parameters

  BaseAddress | contains the base address of the device.
  RegOffset | contains the offset from the 1st register of the device to select the specific register.

Returns
  The value read from the register.

Note
  C-Style signature: u32 XSpi_ReadReg(u32 BaseAddress, u32 RegOffset);

Referenced by XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LowLevelExample(), XSpi_SelfTest(), and XSpi_Transfer().

#define XSpi_SetControlReg | ( |  | InstancePtr,
|  |  | Mask
| ) |  | XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET, (Mask))

Set the contents of the control register.

Use the XSP_CR_* constants defined above to create the bit-mask to be written to the register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  Mask | is the 32-bit value to write to the control register.

Returns
  None.

Note
  C-Style signature: void XSpi_SetControlReg(XSpi *InstancePtr, u32 Mask);

Referenced by XSpi_Abort(), XSpi_CfgInitialize(), XSpi_SetOptions(), XSpi_Start(), XSpi_Stop(), and XSpi_Transfer().

#define XSpi_SetSlaveSelectReg | ( |  | InstancePtr,
|  |  | Mask
| ) |  | XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_SSR_OFFSET, (Mask))

Set the contents of the slave select register.

Each bit in the mask corresponds to a slave select line. Only one slave should be selected at any one time.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  Mask | is the 32-bit value to write to the slave select register.

Returns
  None.

Note
  C-Style signature: void XSpi_SetSlaveSelectReg(XSpi *InstancePtr, u32 Mask);

Referenced by XSpi_Abort(), XSpi_InterruptHandler(), and XSpi_Transfer().

#define XSpi_SetXipControlReg | ( |  | InstancePtr,
|  |  | Mask
| ) |  | XSpi_WriteReg(((InstancePtr)->BaseAddr), XSP_CR_OFFSET, (Mask))

Set the contents of the XIP control register.

Use the XSP_CR_XIP_* constants defined above to create the bit-mask to be written to the register.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  Mask | is the 32-bit value to write to the control register.

Returns
  None.

Note
  C-Style signature: void XSpi_SetXipControlReg(XSpi *InstancePtr, u32 Mask);

#define XSpi_WriteReg | ( |  | BaseAddress,
|  |  | RegOffset,
|  |  | RegisterValue
| ) |  | XSpi_Out32((BaseAddress) + (RegOffset), (RegisterValue))

Write to the specified Spi device register.

Parameters

  BaseAddress | contains the base address of the device.
  RegOffset | contains the offset from the 1st register of the device to select the specific register.
  RegisterValue | is the value to be written to the register.

Returns
  None.

Note
  C-Style signature: void XSpi_WriteReg(u32 BaseAddress, u32 RegOffset, u32 RegisterValue);

Referenced by XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LowLevelExample(), XSpi_Reset(), and XSpi_Transfer().

## Typedef Documentation

typedef void(* XSpi_StatusHandler)(void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)

The handler data type allows the user to define a callback function to handle the asynchronous processing of the SPI driver.

The application using this driver is expected to define a handler of this type to support interrupt driven mode. The handler executes in an interrupt context such that minimal processing should be performed.

Parameters

  CallBackRef | A callback reference passed in by the upper layer when setting the callback functions, and passed back to the upper layer when the callback is invoked. Its type is unimportant to the driver component, so it is a void pointer.
  StatusEvent | Indicates one or more status events that occurred. See the XSpi_SetStatusHandler() for details on the status events that can be passed in the callback.
  ByteCount | Indicates how many bytes of data were successfully transferred. This may be less than the number of bytes requested if the status event indicates an error.

## Function Documentation

void XSpi_Abort | ( | XSpi * | InstancePtr | ) |

Aborts a transfer in progress by setting the stop bit in the control register, then resetting the FIFOs if present.

The byte counts are cleared and the busy flag is set to false.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note

This function does a read/modify/write of the control register. The user of this function needs to take care of critical sections.

References XSpi::HasFifos, XSpi::IsBusy, XSpi::RemainingBytes, XSpi::RequestedBytes, XSpi::SlaveSelectMask, XSP_CR_RXFIFO_RESET_MASK, XSP_CR_TRANS_INHIBIT_MASK, XSP_CR_TXFIFO_RESET_MASK, XSpi_GetControlReg, XSpi_SetControlReg, and XSpi_SetSlaveSelectReg.

Referenced by XSpi_InterruptHandler(), and XSpi_Reset().

int XSpi_CfgInitialize | ( | XSpi * | InstancePtr,
|  | XSpi_Config * | Config,
|  | UINTPTR | EffectiveAddr
| ) |  |

Initializes a specific XSpi instance such that the driver is ready to use.

The state of the device after initialization is:

- Device is disabled
- Slave mode
- Active high clock polarity
- Clock phase 0

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  Config | is a reference to a structure containing information about a specific SPI device. This function initializes an InstancePtr object for a specific device specified by the contents of Config. This function can initialize multiple instance objects with the use of multiple calls giving different Config information on each call.
  EffectiveAddr | is the device base address in the virtual memory address space. The caller is responsible for keeping the address mapping from EffectiveAddr to the device physical base address unchanged once this function is invoked. Unexpected errors may occur if the address mapping changes after this function is called. If address translation is not used, use Config->BaseAddress for this parameters, passing the physical address instead.

Returns
  - XST_SUCCESS if successful.
  - XST_DEVICE_IS_STARTED if the device is started. It must be stopped to re-initialize.

Note
  None.

References XSpi_Config::AxiFullBaseAddress, XSpi::BaseAddr, XSpi_Stats::BytesTransferred, XSpi_Config::DataWidth, XSpi::DataWidth, XSpi::FlashBaseAddr, XSpi_Config::HasFifos, XSpi::HasFifos, XSpi::IsBusy, XSpi::IsReady, XSpi::IsStarted, XSpi_Stats::ModeFaults, XSpi_Stats::NumInterrupts, XSpi_Config::NumSlaveBits, XSpi::NumSlaveBits, XSpi::RecvBufferPtr, XSpi_Stats::RecvOverruns, XSpi::RemainingBytes, XSpi::RequestedBytes, XSpi::SendBufferPtr, XSpi_Stats::SlaveModeFaults, XSpi_Config::SlaveOnly, XSpi::SlaveOnly, XSpi::SlaveSelectMask, XSpi::SlaveSelectReg, XSpi_Config::SpiMode, XSpi::SpiMode, XSpi::Stats, XSpi::StatusHandler, XSpi_Config::Use_Startup, XSpi_Config::XipMode, XSpi::XipMode, XSpi_Stats::XmitUnderruns, XSP_CR_ENABLE_MASK, XSP_CR_MASTER_MODE_MASK, XSP_CR_RXFIFO_RESET_MASK, XSP_CR_TRANS_INHIBIT_MASK, XSP_CR_TXFIFO_RESET_MASK, XSP_DATAWIDTH_BYTE, XSP_DRR_OFFSET, XSP_DTR_OFFSET, XSP_SR_RX_EMPTY_MASK, XSpi_GetControlReg, XSpi_GetStatusReg, XSpi_ReadReg, XSpi_Reset(), XSpi_SetControlReg, and XSpi_WriteReg.

Referenced by main(), SpiIntrExample(), SpiPolledExample(), SpiSelfTestExample(), SpiXipExample(), and XSpi_Initialize().

void XSpi_ClearStats | ( | XSpi * | InstancePtr | ) |

Clears the statistics for the SPI device.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note
  Statistics are not updated in polled mode of operation.

References XSpi_Stats::BytesTransferred, XSpi::IsReady, XSpi_Stats::ModeFaults, XSpi_Stats::NumInterrupts, XSpi_Stats::RecvOverruns, XSpi_Stats::SlaveModeFaults, XSpi::Stats, and XSpi_Stats::XmitUnderruns.

u32 XSpi_GetOptions | ( | XSpi * | InstancePtr | ) |

This function gets the options for the SPI device.

The options control how the device behaves relative to the SPI bus.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns

Options contains the specified options to be set. This is a bit mask where a 1 means to turn the option on, and a 0 means to turn the option off. One or more bit values may be contained in the mask. See the bit definitions named XSP_*_OPTIONS in the file xspi.h.

Note
  None.

References XSpi::IsReady, and XSpi_GetControlReg.

u32 XSpi_GetSlaveSelect | ( | XSpi * | InstancePtr | ) |

Gets the current slave select bit mask for the SPI device.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  The value returned is a 32-bit mask with a 1 in the bit position of the slave currently selected. The value may be zero if no slaves are selected.

Note
  This API is used to get the current slave select bit mask that was set using the XSpi_SetSlaveSelect API. This API deos not read the register from the core and returns the slave select register stored in the instance pointer.

References XSpi::IsReady, and XSpi::SlaveSelectReg.

void XSpi_GetStats | ( | XSpi * | InstancePtr,
|  | XSpi_Stats * | StatsPtr
| ) |  |

Gets a copy of the statistics for an SPI device.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  StatsPtr | is a pointer to a XSpi_Stats structure which will get a copy of current statistics.

Returns
  None.

Note
  Statistics are not updated in polled mode of operation.

References XSpi_Stats::BytesTransferred, XSpi::IsReady, XSpi_Stats::ModeFaults, XSpi_Stats::NumInterrupts, XSpi_Stats::RecvOverruns, XSpi_Stats::SlaveModeFaults, XSpi::Stats, and XSpi_Stats::XmitUnderruns.

int XSpi_Initialize | ( | XSpi * | InstancePtr,
|  | u16 | DeviceId
| ) |  |

Initializes a specific XSpi instance such that the driver is ready to use.

The state of the device after initialization is:

- Device is disabled
- Slave mode
- Active high clock polarity
- Clock phase 0

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  DeviceId | is the unique id of the device controlled by this XSpi instance. Passing in a device id associates the generic XSpi instance to a specific device, as chosen by the caller or application developer.

Returns

          - XST_SUCCESS if successful.
          - XST_DEVICE_IS_STARTED if the device is started. It must be
            stopped to re-initialize.
          - XST_DEVICE_NOT_FOUND if the device was not found in the
            configuration such that initialization could not be
            accomplished.

Note
  None.

References XSpi_Config::BaseAddress, XSpi_CfgInitialize(), and XSpi_LookupConfig().

void XSpi_InterruptHandler | ( | void * | InstancePtr | ) |

The interrupt handler for SPI interrupts.

This function must be connected by the user to an interrupt source. This function does not save and restore the processor context such that the user must provide this processing.

The interrupts that are handled are:

- Mode Fault Error. This interrupt is generated if this device is selected as a slave when it is configured as a master. The driver aborts any data transfer that is in progress by resetting FIFOs (if present) and resetting its buffer pointers. The upper layer software is informed of the error.
- Data Transmit Register (FIFO) Empty. This interrupt is generated when the transmit register or FIFO is empty. The driver uses this interrupt during a transmission to continually send/receive data until there is no more data to send/receive.
- Data Transmit Register (FIFO) Underrun. This interrupt is generated when the SPI device, when configured as a slave, attempts to read an empty DTR/FIFO. An empty DTR/FIFO usually means that software is not giving the device data in a timely manner. No action is taken by the driver other than to inform the upper layer software of the error.
- Data Receive Register (FIFO) Overrun. This interrupt is generated when the SPI device attempts to write a received byte to an already full DRR/FIFO. A full DRR/FIFO usually means software is not emptying the data in a timely manner. No action is taken by the driver other than to inform the upper layer software of the error.
- Slave Mode Fault Error. This interrupt is generated if a slave device is selected as a slave while it is disabled. No action is taken by the driver other than to inform the upper layer software of the error.
- Command Error. This interrupt occurs when the first byte in the Tx FIFO, after the CS is asserted, doesn't match any command in the Lookup table. This interrupt is valid only for axi_qspi.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note

The slave select register is being set to deselect the slave when a transfer is complete. This is being done regardless of whether it is a slave or a master since the hardware does not drive the slave select as a slave.

References XSpi::BaseAddr, XSpi_Stats::BytesTransferred, XSpi::DataWidth, XSpi::IsBusy, XSpi_Stats::ModeFaults, XSpi_Stats::NumInterrupts, XSpi::RecvBufferPtr, XSpi_Stats::RecvOverruns, XSpi::RemainingBytes, XSpi::RequestedBytes, XSpi::SendBufferPtr, XSpi_Stats::SlaveModeFaults, XSpi::SlaveSelectMask, XSpi::Stats, XSpi::StatusHandler, XSpi::StatusRef, XSpi_Stats::XmitUnderruns, XSP_DATAWIDTH_BYTE, XSP_DATAWIDTH_HALF_WORD, XSP_DATAWIDTH_WORD, XSP_DRR_OFFSET, XSP_DTR_OFFSET, XSP_INTR_CMD_ERR_MASK, XSP_INTR_MODE_FAULT_MASK, XSP_INTR_RX_NOT_EMPTY_MASK, XSP_INTR_RX_OVERRUN_MASK, XSP_INTR_SLAVE_MODE_FAULT_MASK, XSP_INTR_SLAVE_MODE_MASK, XSP_INTR_TX_EMPTY_MASK, XSP_INTR_TX_HALF_EMPTY_MASK, XSP_INTR_TX_UNDERRUN_MASK, XSP_SR_RX_EMPTY_MASK, XSP_SR_TX_FULL_MASK, XSpi_Abort(), XSpi_GetStatusReg, XSpi_IntrClear, XSpi_IntrDisable, XSpi_IntrGetStatus, XSpi_ReadReg, XSpi_SetSlaveSelectReg, and XSpi_WriteReg.

XSpi_Config * XSpi_LookupConfig | ( | u16 | DeviceId | ) |

Looks up the device configuration based on the unique device ID.

A table contains the configuration info for each device in the system.

Parameters

  DeviceId | contains the ID of the device to look up the configuration for.

Returns

A pointer to the configuration found or NULL if the specified device ID was not found. See xspi.h for the definition of XSpi_Config.

Note
  None.

Referenced by main(), SpiIntrExample(), SpiPolledExample(), SpiSelfTestExample(), SpiXipExample(), and XSpi_Initialize().

void XSpi_Reset | ( | XSpi * | InstancePtr | ) |

Resets the SPI device by writing to the Software Reset register.

Reset must only be called after the driver has been initialized. The configuration of the device after reset is the same as its configuration after initialization. Refer to the XSpi_Initialize function for more details. This is a hard reset of the device. Any data transfer that is in progress is aborted.

The upper layer software is responsible for re-configuring (if necessary) and restarting the SPI device after the reset.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  None.

Note
  None.

References XSpi::BaseAddr, XSpi::IsReady, XSpi::IsStarted, XSpi::SlaveSelectMask, XSpi::SlaveSelectReg, XSP_SRR_OFFSET, XSP_SRR_RESET_MASK, XSpi_Abort(), and XSpi_WriteReg.

Referenced by XSpi_CfgInitialize(), and XSpi_SelfTest().

int XSpi_SelfTest | ( | XSpi * | InstancePtr | ) |

Runs a self-test on the driver/device.

The self-test is destructive in that a reset of the device is performed in order to check the reset values of the registers and to get the device into a known state. A simple loopback test is also performed to verify that transmit and receive are working properly. The device is changed to master mode for the loopback test, since only a master can initiate a data transfer.

Upon successful return from the self-test, the device is reset.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  - XST_SUCCESS if successful.

- XST_REGISTER_ERROR indicates a register did not read or write correctly.
  - XST_LOOPBACK_ERROR if a loopback error occurred.

Note
  None.

References XSpi::BaseAddr, XSpi::HasFifos, XSpi::IsReady, XSpi::SlaveSelectMask, XSpi::SpiMode, XSpi::XipMode, XSP_RFO_OFFSET, XSP_TFO_OFFSET, XSpi_GetControlReg, XSpi_GetSlaveSelectReg, XSpi_GetStatusReg, XSpi_ReadReg, and XSpi_Reset().

Referenced by SpiIntrExample(), SpiPolledExample(), and SpiSelfTestExample().

int XSpi_SetOptions | ( | XSpi * | InstancePtr,
|  | u32 | Options
| ) |  |

This function sets the options for the SPI device driver.

The options control how the device behaves relative to the SPI bus. The device must be idle rather than busy transferring data before setting these device options.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  Options | contains the specified options to be set. This is a bit mask where a 1 means to turn the option on, and a 0 means to turn the option off. One or more bit values may be contained in the mask. See the bit definitions named XSP_*_OPTIONS in the file xspi.h.

Returns
  -XST_SUCCESS if options are successfully set.
  - XST_DEVICE_BUSY if the device is currently transferring data. The transfer must complete or be aborted before setting options.
  - XST_SPI_SLAVE_ONLY if the caller attempted to configure a slave-only device as a master.

Note

This function makes use of internal resources that are shared between the XSpi_Stop() and XSpi_SetOptions() functions. So if one task might be setting device options while another is trying to stop the device, the user is required to provide protection of this shared data (typically using a semaphore).

References XSpi::IsBusy, XSpi::IsReady, XSpi::SlaveOnly, XSP_MASTER_OPTION, XSpi_GetControlReg, and XSpi_SetControlReg.

Referenced by main(), SpiIntrExample(), and SpiPolledExample().

int XSpi_SetSlaveSelect | ( | XSpi * | InstancePtr,
|  | u32 | SlaveMask
| ) |  |

Selects or deselect the slave with which the master communicates.

Each slave that can be selected is represented in the slave select register by a bit. The argument passed to this function is the bit mask with a 1 in the bit position of the slave being selected. Only one slave can be selected.

The user is not allowed to deselect the slave while a transfer is in progress. If no transfer is in progress, the user can select a new slave, which implicitly deselects the current slave. In order to explicitly deselect the current slave, a zero can be passed in as the argument to the function.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  SlaveMask | is a 32-bit mask with a 1 in the bit position of the slave being selected. Only one slave can be selected. The SlaveMask can be zero if the slave is being deselected.

Returns
  - XST_SUCCESS if the slave is selected or deselected successfully.

- XST_DEVICE_BUSY if a transfer is in progress, slave cannot be changed
- XST_SPI_TOO_MANY_SLAVES if more than one slave is being selected.

Note

This function only sets the slave which will be selected when a transfer occurs. The slave is not selected when the SPI is idle. The slave select has no affect when the device is configured as a slave.

References XSpi::IsBusy, XSpi::IsReady, XSpi::NumSlaveBits, and XSpi::SlaveSelectReg.

Referenced by main().

void XSpi_SetStatusHandler | ( | XSpi * | InstancePtr,
|  | void * | CallBackRef,
|  | XSpi_StatusHandler | FuncPtr
| ) |  |

Sets the status callback function, the status handler, which the driver calls when it encounters conditions that should be reported to the higher layer software.

The handler executes in an interrupt context, so it must minimize the amount of processing performed such as transferring data to a thread context. One of the following status events is passed to the status handler.

    XST_SPI_MODE_FAULT  A mode fault error occurred, meaning another
                            master tried to select this device as a slave
                            when this device was configured to be a master.
                            Any transfer in progress is aborted.

    XST_SPI_TRANSFER_DONE       The requested data transfer is done

    XST_SPI_TRANSMIT_UNDERRUN   As a slave device, the master clocked
                            data but there were none available in the
                            transmit register/FIFO. This typically means the
                            slave application did not issue a transfer
                            request fast enough, or the processor/driver
                            could not fill the transmit register/FIFO fast
                            enough.

    XST_SPI_RECEIVE_OVERRUN     The SPI device lost data. Data was received
                            but the receive data register/FIFO was full.
                            This indicates that the device is receiving data
                            faster than the processor/driver can consume it.

    XST_SPI_SLAVE_MODE_FAULT    A slave SPI device was selected as a slave while
                            it was disabled.  This indicates the master is
                            already transferring data (which is being
                            dropped until the slave application issues a
                            transfer).

    Parameters

        InstancePtris a pointer to the XSpi instance to be worked on.

        CallBackRefis the upper layer callback reference passed back
            when the callback function is invoked.

        FuncPtris the pointer to the callback function.

    ReturnsNone.
    Note
    The handler is called within interrupt context, so it should do its work
    quickly and queue potentially time-consuming work to a task-level thread.

References XSpi::IsReady, XSpi::StatusHandler, and XSpi::StatusRef.

Referenced by main(), and SpiIntrExample().

int XSpi_Start | ( | XSpi * | InstancePtr | ) |

This function enables interrupts for the SPI device.

If the Spi driver is used in interrupt mode, it is up to the user to connect the SPI interrupt handler to the interrupt controller before this function is called. If the Spi driver is used in polled mode the user has to disable the Global Interrupts after this function is called. If the device is configured with FIFOs, the FIFOs are reset at this time.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  - XST_SUCCESS if the device is successfully started
  - XST_DEVICE_IS_STARTED if the device was already started.

Note
  None.

References XSpi::IsReady, XSpi::IsStarted, XSP_CR_ENABLE_MASK, XSP_CR_RXFIFO_RESET_MASK, XSP_CR_TXFIFO_RESET_MASK, XSP_INTR_DFT_MASK, XSpi_GetControlReg, XSpi_IntrEnable, XSpi_IntrGlobalEnable, and XSpi_SetControlReg.

Referenced by main(), SpiIntrExample(), and SpiPolledExample().

int XSpi_Stop | ( | XSpi * | InstancePtr | ) |

This function stops the SPI device by disabling interrupts and disabling the device itself.

Interrupts are disabled only within the device itself. If desired, the caller is responsible for disabling interrupts in the interrupt controller and disconnecting the interrupt handler from the interrupt controller.

In interrupt mode, if the device is in progress of transferring data on the SPI bus, this function returns a status indicating the device is busy. The user will be notified via the status handler when the transfer is complete, and at that time can again try to stop the device. As a master, we do not allow the device to be stopped while a transfer is in progress because the slave may be left in a bad state. As a slave, we do not allow the device to be stopped while a transfer is in progress because the master is not done with its transfer yet.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.

Returns
  - XST_SUCCESS if the device is successfully started.

- XST_DEVICE_BUSY if a transfer is in progress and cannot be stopped.

Note

This function makes use of internal resources that are shared between the XSpi_Stop() and XSpi_SetOptions() functions. So if one task might be setting device options while another is trying to stop the device, the user is is required to provide protection of this shared data (typically using a semaphore).

References XSpi::IsBusy, XSpi::IsReady, XSpi::IsStarted, XSP_CR_ENABLE_MASK, XSpi_GetControlReg, XSpi_IntrGlobalDisable, and XSpi_SetControlReg.

int XSpi_Transfer | ( | XSpi * | InstancePtr,
|  | u8 * | SendBufPtr,
|  | u8 * | RecvBufPtr,
|  | unsigned int | ByteCount
| ) |  |

Transfers the specified data on the SPI bus.

If the SPI device is configured to be a master, this function initiates bus communication and sends/receives the data to/from the selected SPI slave. If the SPI device is configured to be a slave, this function prepares the data to be sent/received when selected by a master. For every byte sent, a byte is received.

This function/driver operates in interrupt mode and polled mode.

- In interrupt mode this function is non-blocking and the transfer is initiated by this function and completed by the interrupt service routine.
- In polled mode this function is blocking and the control exits this function only after all the requested data is transferred.

The caller has the option of providing two different buffers for send and receive, or one buffer for both send and receive, or no buffer for receive. The receive buffer must be at least as big as the send buffer to prevent unwanted memory writes. This implies that the byte count passed in as an argument must be the smaller of the two buffers if they differ in size. Here are some sample usages:

          XSpi_Transfer(InstancePtr, SendBuf, RecvBuf, ByteCount)
          The caller wishes to send and receive, and provides two different
          buffers for send and receive.

          XSpi_Transfer(InstancePtr, SendBuf, NULL, ByteCount)
          The caller wishes only to send and does not care about the received
          data. The driver ignores the received data in this case.

          XSpi_Transfer(InstancePtr, SendBuf, SendBuf, ByteCount)
          The caller wishes to send and receive, but provides the same buffer
          for doing both. The driver sends the data and overwrites the send
          buffer with received data as it transfers the data.

          XSpi_Transfer(InstancePtr, RecvBuf, RecvBuf, ByteCount)
          The caller wishes to only receive and does not care about sending
          data.  In this case, the caller must still provide a send buffer, but
          it can be the same as the receive buffer if the caller does not care
          what it sends. The device must send N bytes of data if it wishes to
          receive N bytes of data.

In interrupt mode, though this function takes a buffer as an argument, the driver can only transfer a limited number of bytes at time. It transfers only one byte at a time if there are no FIFOs, or it can transfer the number of bytes up to the size of the FIFO if FIFOs exist.

- In interrupt mode a call to this function only starts the transfer, the subsequent transfer of the data is performed by the interrupt service routine until the entire buffer has been transferred.The status callback function is called when the entire buffer has been sent/received.
- In polled mode this function is blocking and the control exits this function only after all the requested data is transferred.

As a master, the SetSlaveSelect function must be called prior to this function.

Parameters

  InstancePtr | is a pointer to the XSpi instance to be worked on.
  SendBufPtr | is a pointer to a buffer of data which is to be sent. This buffer must not be NULL.
  RecvBufPtr | is a pointer to a buffer which will be filled with received data. This argument can be NULL if the caller does not wish to receive data.
  ByteCount | contains the number of bytes to send/receive. The number of bytes received always equals the number of bytes sent.

Returns
  -XST_SUCCESS if the buffers are successfully handed off to the driver for transfer. Otherwise, returns:
  - XST_DEVICE_IS_STOPPED if the device must be started before transferring data.
  - XST_DEVICE_BUSY indicates that a data transfer is already in progress. This is determined by the driver.
  - XST_SPI_NO_SLAVE indicates the device is configured as a master and a slave has not yet been selected.

This function is not thread-safe. The higher layer software must ensure that no two threads are transferring data on the SPI bus at the same time.

References XSpi::BaseAddr, XSpi_Stats::BytesTransferred, XSpi::DataWidth, XSpi::IsBusy, XSpi::IsReady, XSpi::IsStarted, XSpi::RecvBufferPtr, XSpi::RemainingBytes, XSpi::RequestedBytes, XSpi::SendBufferPtr, XSpi::SlaveSelectMask, XSpi::SlaveSelectReg, XSpi::Stats, XSP_CR_LOOPBACK_MASK, XSP_CR_MASTER_MODE_MASK, XSP_CR_TRANS_INHIBIT_MASK, XSP_DATAWIDTH_BYTE, XSP_DATAWIDTH_HALF_WORD, XSP_DATAWIDTH_WORD, XSP_DRR_OFFSET, XSP_DTR_OFFSET, XSP_INTR_TX_EMPTY_MASK, XSP_SR_RX_EMPTY_MASK, XSP_SR_TX_FULL_MASK, XSpi_GetControlReg, XSpi_GetStatusReg, XSpi_IntrClear, XSpi_IntrEnable, XSpi_IntrGetStatus, XSpi_IntrGlobalDisable, XSpi_IntrGlobalEnable, XSpi_IsIntrGlobalEnabled, XSpi_ReadReg, XSpi_SetControlReg, XSpi_SetSlaveSelectReg, and XSpi_WriteReg.

Referenced by EepromRead(), EepromWrite(), SpiAtmelFlashPageErase(), SpiAtmelFlashRead(), SpiAtmelFlashWrite(), SpiFlashBulkErase(), SpiFlashEnableHPM(), SpiFlashGetStatus(), SpiFlashQuadEnable(), SpiFlashRead(), SpiFlashSectorErase(), SpiFlashWrite(), SpiFlashWriteEnable(), SpiIntelFlashBulkErase(), SpiIntelFlashGetStatus(), SpiIntelFlashRead(), SpiIntelFlashSectorErase(), SpiIntelFlashWrite(), SpiIntelFlashWriteEnable(), SpiIntelFlashWriteStatus(), SpiIntrExample(), SpiPolledExample(), SpiStmFlashBulkErase(), SpiStmFlashGetStatus(), SpiStmFlashRead(), SpiStmFlashSectorErase(), SpiStmFlashWrite(), and SpiStmFlashWriteEnable().

## Variable Documentation

XSpi_Config XSpi_ConfigTable[]

This table contains configuration information for each SPI device in the system.

XSpi_Config XSpi_ConfigTable[XPAR_XSPI_NUM_INSTANCES]

Initial value:
= {
{
XPAR_SPI_0_DEVICE_ID,
XPAR_SPI_0_BASEADDR,
XPAR_SPI_0_FIFO_EXIST,
XPAR_SPI_0_SLAVE_ONLY,
XPAR_SPI_0_NUM_SS_BITS,
XPAR_SPI_0_NUM_TRANSFER_BITS
XPAR_SPI_0_SPI_MODE
XPAR_SPI_0_USE_STARTUP
}
,
{
XPAR_SPI_1_DEVICE_ID,
XPAR_SPI_1_BASEADDR,
XPAR_SPI_1_FIFO_EXIST,
XPAR_SPI_1_SLAVE_ONLY,
XPAR_SPI_1_NUM_SS_BITS,
XPAR_SPI_1_NUM_TRANSFER_BITS
XPAR_SPI_1_SPI_MODE
XPAR_SPI_0_USE_STARTUP
}
}

This table contains configuration information for each SPI device in the system.

XSpi_Config XSpi_ConfigTable[]

This table contains configuration information for each SPI device in the system.