#include "xspi.h"
#include "xspi_i.h"
Functions | |
void | XSpi_Abort (XSpi *InstancePtr) |
int | XSpi_CfgInitialize (XSpi *InstancePtr, XSpi_Config *Config, u32 EffectiveAddr) |
int | XSpi_Start (XSpi *InstancePtr) |
int | XSpi_Stop (XSpi *InstancePtr) |
void | XSpi_Reset (XSpi *InstancePtr) |
int | XSpi_Transfer (XSpi *InstancePtr, u8 *SendBufPtr, u8 *RecvBufPtr, unsigned int ByteCount) |
int | XSpi_SetSlaveSelect (XSpi *InstancePtr, u32 SlaveMask) |
u32 | XSpi_GetSlaveSelect (XSpi *InstancePtr) |
void | XSpi_SetStatusHandler (XSpi *InstancePtr, void *CallBackRef, XSpi_StatusHandler FuncPtr) |
void | XSpi_InterruptHandler (void *InstancePtr) |
Contains required functions of the XSpi driver component. See xspi.h for a detailed description of the device and driver.
MODIFICATION HISTORY:
Ver Who Date Changes ----- ---- -------- ----------------------------------------------- 1.00a rpm 10/11/01 First release 1.00b jhl 03/14/02 Repartitioned driver for smaller files. 1.00b rpm 04/25/02 Collapsed IPIF and reg base addresses into one 1.00b rmm 05/14/03 Fixed diab compiler warnings relating to asserts 1.01a jvb 12/13/05 Changed Initialize() into CfgInitialize(), and made CfgInitialize() take a pointer to a config structure instead of a device id. Moved Initialize() into xspi_sinit.c, and had Initialize() call CfgInitialize() after it retrieved the config structure using the device id. Removed include of xparameters.h along with any dependencies on xparameters.h and the _g.c config table. 1.11a wgr 03/22/07 Converted to new coding style. 1.11a rpm 01/22/08 Updated comment on Transfer regarding needing interrupts. 1.12a sdm 03/27/08 Updated the code to support 16/32 bit transfer width and polled mode of operation. Even for the polled mode of operation the Interrupt Logic in the core should be included. The driver can be put in polled mode of operation by disabling the Global Interrupt after the Spi Initialization is completed. 2.00a sdm 07/30/08 Updated the code to support 16/32 bit transfer width and polled mode of operation. Even for the polled mode of operation the Interrupt Logic in the core should be included. The driver can be put in polled mode of operation by disabling the Global Interrupt after the Spi Initialization is completed. 2.01b sdm 04/08/09 Fixed an issue in the XSpi_Transfer function where the Global Interrupt is being enabled in polled mode when a slave is not selected. 3.00a ktn 10/28/09 Updated all the register accesses as 32 bit access. Updated to use the HAL APIs/macros. Removed the macro XSpi_mReset, XSpi_Reset API should be used in its place. The macros have been renamed to remove _m from the name. Removed an unnecessary read to the core register in the XSpi_GetSlaveSelect API. 3.01a sdm 04/23/10 Updated the driver to handle new slave mode interrupts and the DTR Half Empty interrupt. 3.04a bss 03/21/12 Updated XSpi_CfgInitialize to support XIP Mode 3.05a adk 18/04/13 Updated the code to avoid unused variable warnings when compiling with the -Wextra -Wall flags In the file xspi.c. CR:705005. 3.06a adk 07/08/13 Added a dummy read in the CfgInitialize(), if startup block is used in the h/w design (CR 721229). 3.07a adk 11/10/13 In the xspi_transfer function moved the assert slave chip select after the configuration of the Data Transmit register inorder to work with CPOL and CPHA High Options. As per spec (Dual/Quad SPI Transaction instrunction 7,8,9) CR:732962 4.1 bss 08/07/14 Modified XSpi_Transfer to check for Interrupt Status register Tx Empty bit instead of Status register CR#810294.
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.
InstancePtr | is a pointer to the XSpi instance to be worked on. |
This function does a read/modify/write of the control register. The user of this function needs to take care of critical sections.
int XSpi_CfgInitialize | ( | XSpi * | InstancePtr, | |
XSpi_Config * | Config, | |||
u32 | EffectiveAddr | |||
) |
Initializes a specific XSpi instance such that the driver is ready to use.
The state of the device after initialization is:
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. |
u32 XSpi_GetSlaveSelect | ( | XSpi * | InstancePtr | ) |
Gets the current slave select bit mask for the SPI device.
InstancePtr | is a pointer to the XSpi instance to be worked on. |
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:
InstancePtr | is a pointer to the XSpi instance to be worked on. |
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.
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.
InstancePtr | is a pointer to the XSpi instance to be worked on. |
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.
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. |
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.
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.
InstancePtr | is a pointer to the XSpi instance to be worked on. | |
CallBackRef | is the upper layer callback reference passed back when the callback function is invoked. | |
FuncPtr | is the pointer to the callback function. |
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.
InstancePtr | is a pointer to the XSpi instance to be worked on. |
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.
InstancePtr | is a pointer to the XSpi instance to be worked on. |
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).
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.
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.
As a master, the SetSlaveSelect function must be called prior to this function.
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. |
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.
Copyright © 1995-2014 Xilinx, Inc. All rights reserved.