Software Drivers

xqspips.c File Reference


Detailed Description

Contains implements the interface functions of the XQspiPs driver. See xqspips.h for a detailed description of the device and driver.

 MODIFICATION HISTORY:

 Ver   Who Date     Changes
 ----- --- -------- -----------------------------------------------
 1.00  sdm 11/25/10 First release
 2.00a kka 07/25/12 Removed XQspiPs_GetWriteData API.
		     The XQspiPs_SetSlaveSelect has been modified to remove
		     the argument of the slave select as the QSPI controller
		     only supports one slave.
 		     XQspiPs_GetSlaveSelect API has been removed
 		     Added logic to XQspiPs_GetReadData to handle data
		     shift for normal data reads and instruction/status
		     reads differently based on the ShiftReadData flag.
 		     Removed the selection for the following options:
		     Master mode (XQSPIPS_MASTER_OPTION) and
		     Flash interface mode (XQSPIPS_FLASH_MODE_OPTION) option
		     as the QSPI driver supports the Master mode
		     and Flash Interface mode and doesnot support
		     Slave mode or the legacy mode.
		     Modified the XQspiPs_PolledTransfer and XQspiPs_Transfer
		     APIs so that the last argument (IsInst) specifying whether
		     it is instruction or data has been removed. The first byte
		     in the SendBufPtr argument of these APIs specify the
		     instruction to be sent to the Flash Device.
		     The XQspiPs_PolledTransfer function has been updated
		     to fill the data to fifo depth.
		     This version of the driver fixes CRs 670197/663787.
 2.01a sg  02/03/13 Added flash opcodes for DUAL_IO_READ,QUAD_IO_READ.
		     Created macros XQspiPs_IsManualStart and
		     XQspiPs_IsManualChipSelect.
		     Changed QSPI transfer logic for polled and interrupt
		     modes to be based on filled tx fifo count and receive
		     based on it. RXNEMPTY interrupt is not used.
		     Added assertions to XQspiPs_LqspiRead function.

 2.02a hk  05/14/13 Added enable and disable to the XQspiPs_LqspiRead()
			 function
            Added instructions for bank selection, die erase and
            flag status register to the flash instruction table
            Handling for instructions not in flash instruction
			 table added. Checking for Tx FIFO empty when switching from
			 TXD1/2/3 to TXD0 added. If WRSR instruction is sent with
            byte count 3 (spansion), instruction size and TXD register
			 changed accordingly. CR# 712502 and 703869.
            Added (ifdef linear base address) in the Linear read function.
            Changed  XPAR_XQSPIPS_0_LINEAR_BASEADDR to
            XPAR_PS7_QSPI_LINEAR_0_S_AXI_BASEADDR in
            XQspiPs_LqspiRead function. Fix for CR#718141

 2.03a hk  09/05/13 Modified polled and interrupt transfers to make use of
                    thresholds. This is to improve performance.
                    Added RX and TX threshold reset to one in XQspiPs_Abort.
                    Added RX threshold reset(1) after transfer in polled and
                    interrupt transfers. Made changes to make sure threshold
                    change is done only when no transfer is in progress.

 

#include "xqspips.h"

Classes

struct  XQspiPsInstFormat

Functions

int XQspiPs_CfgInitialize (XQspiPs *InstancePtr, XQspiPs_Config *ConfigPtr, u32 EffectiveAddr)
void XQspiPs_Reset (XQspiPs *InstancePtr)
void XQspiPs_Abort (XQspiPs *InstancePtr)
int XQspiPs_Transfer (XQspiPs *InstancePtr, u8 *SendBufPtr, u8 *RecvBufPtr, unsigned ByteCount)
int XQspiPs_PolledTransfer (XQspiPs *InstancePtr, u8 *SendBufPtr, u8 *RecvBufPtr, unsigned ByteCount)
int XQspiPs_LqspiRead (XQspiPs *InstancePtr, u8 *RecvBufPtr, u32 Address, unsigned ByteCount)
int XQspiPs_SetSlaveSelect (XQspiPs *InstancePtr)
void XQspiPs_SetStatusHandler (XQspiPs *InstancePtr, void *CallBackRef, XQspiPs_StatusHandler FuncPtr)
void XQspiPs_InterruptHandler (void *InstancePtr)


Function Documentation

void XQspiPs_Abort XQspiPs InstancePtr  ) 
 

Aborts a transfer in progress by disabling the device and flush the RxFIFO. The byte counts are cleared, the busy flag is cleared.

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
Returns:
None.
Note:
This function does a read/modify/write of the config register. The user of this function needs to take care of critical sections.

int XQspiPs_CfgInitialize XQspiPs InstancePtr,
XQspiPs_Config ConfigPtr,
u32  EffectiveAddr
 

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

The state of the device after initialization is:

  • Master mode
  • Active high clock polarity
  • Clock phase 0
  • Baud rate divisor 2
  • Transfer width 32
  • Master reference clock = pclk
  • No chip select active
  • Manual CS and Manual Start disabled

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
ConfigPtr is a reference to a structure containing information about a specific QSPI device. This function initializes an InstancePtr object for a specific device specified by the contents of Config.
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 ConfigPtr->Config.BaseAddress for this device.
Returns:
  • XST_SUCCESS if successful.
  • XST_DEVICE_IS_STARTED if the device is already started. It must be stopped to re-initialize.
Note:
None.

void XQspiPs_InterruptHandler void *  InstancePtr  ) 
 

The interrupt handler for QSPI interrupts. This function must be connected by the user to an interrupt controller.

The interrupts that are handled are:

  • 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 the transfer is done.

  • Data Transmit Register (FIFO) Underflow. This interrupt is generated when the QSPI 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) Overflow. This interrupt is generated when the QSPI 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.

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
Returns:
None.
Note:
The slave select register is being set to deselect the slave when a transfer is complete.

int XQspiPs_LqspiRead XQspiPs InstancePtr,
u8 *  RecvBufPtr,
u32  Address,
unsigned  ByteCount
 

Read the flash in Linear QSPI mode.

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
RecvBufPtr is a pointer to a buffer for received data.
Address is the starting address within the flash from from where data needs to be read.
ByteCount contains the number of bytes to receive.
Returns:
  • XST_SUCCESS if read is performed
  • XST_FAILURE if Linear mode is not set
Note:
None.

int XQspiPs_PolledTransfer XQspiPs InstancePtr,
u8 *  SendBufPtr,
u8 *  RecvBufPtr,
unsigned  ByteCount
 

Transfers specified data on the QSPI bus in polled mode.

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:

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

   XQspiPs_PolledTransfer(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.

   XQspiPs_PolledTransfer(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.

   XQspiPs_PolledTransfer(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.

 

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
SendBufPtr is a pointer to a data buffer that needs to be transmitted. This buffer must not be NULL.
RecvBufPtr is a pointer to a buffer for received data. This argument can be NULL if do not care about receiving.
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 device for transfer.
  • XST_DEVICE_BUSY indicates that a data transfer is already in progress. This is determined by the driver.
Note:
This function is not thread-safe. The higher layer software must ensure that no two threads are transferring data on the QSPI bus at the same time.

void XQspiPs_Reset XQspiPs InstancePtr  ) 
 

Resets the QSPI device. Reset must only be called after the driver has been initialized. Any data transfer that is in progress is aborted.

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

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
Returns:
None.
Note:
None.

int XQspiPs_SetSlaveSelect XQspiPs InstancePtr  ) 
 

Selects the slave with which the master communicates.

The user is not allowed to select the slave while a transfer is in progress.

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
Returns:
  • XST_SUCCESS if the slave is selected or deselected successfully.
  • XST_DEVICE_BUSY if a transfer is in progress, slave cannot be changed.
Note:
This function only sets the slave which will be selected when a transfer occurs. The slave is not selected when the QSPI is idle.

void XQspiPs_SetStatusHandler XQspiPs InstancePtr,
void *  CallBackRef,
XQspiPs_StatusHandler  FuncPtr
 

Sets the status callback function, the status handler, which the driver calls when it encounters conditions that should be reported to upper layer software. The handler executes in an interrupt context, so it must minimize the amount of processing performed. One of the following status events is passed to the status handler.

 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 QSPI device lost data. Data was received
				but the receive data register/FIFO was full.

 
Parameters:
InstancePtr is a pointer to the XQspiPs instance.
CallBackRef is the upper layer callback reference passed back when the callback function is invoked.
FuncPtr is the pointer to the callback function.
Returns:
None.
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.

int XQspiPs_Transfer XQspiPs InstancePtr,
u8 *  SendBufPtr,
u8 *  RecvBufPtr,
unsigned  ByteCount
 

Transfers specified data on the QSPI bus. Initiates bus communication and sends/receives data to/from the selected QSPI slave. For every byte sent, a byte is received.

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:

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

   XQspiPs_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.

   XQspiPs_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.

   XQspiPs_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.
 
Although this function takes entire buffers as arguments, the driver can only transfer a limited number of bytes at a time, limited by the size of the FIFO. A call to this function only starts the transfer, then subsequent transfers 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.

This function is non-blocking. The SetSlaveSelect function must be called prior to this function.

Parameters:
InstancePtr is a pointer to the XQspiPs instance.
SendBufPtr is a pointer to a data buffer that needs to be transmitted. This buffer must not be NULL.
RecvBufPtr is a pointer to a buffer for received data. This argument can be NULL if do not care about receiving.
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 device for transfer.
  • XST_DEVICE_BUSY indicates that a data transfer is already in progress. This is determined by the driver.
Note:
This function is not thread-safe. The higher layer software must ensure that no two threads are transferring data on the QSPI bus at the same time.
Copyright @ 1995-2014 Xilinx, Inc. All rights reserved.