spips
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Groups Pages
Xspips_flash_intr_example

Macros

#define WRITE_STATUS_CMD   0x01
 Write status register command. More...
 
#define WRITE_CMD   0x02
 Page program command. More...
 
#define READ_CMD   0x03
 Read data command. More...
 
#define WRITE_DISABLE_CMD   0x04
 Write disable command. More...
 
#define READ_STATUS_CMD   0x05
 Read status register command. More...
 
#define WRITE_ENABLE_CMD   0x06
 Write enable command. More...
 
#define FAST_READ_CMD   0x0B
 Fast read command. More...
 
#define CHIP_ERASE_CMD   0x60
 Chip erase command. More...
 
#define BULK_ERASE_CMD   0xC7
 Bulk erase command. More...
 
#define BLOCK_ERASE_64K_CMD   0xD8
 64 KB block erase command. More...
 
#define READ_ID   0x90
 Read ID command. More...
 
#define SST_READ_ID   0x9F
 SST flash read ID command. More...
 
#define GLOBAL_BLK_PROT_UNLK   0x98
 Global Block-Protection Unlock register command. More...
 
#define SST_FLASH_ID   0xBF
 All SST flash parts have ID 0xBF. More...
 
#define COMMAND_OFFSET   0
 Flash instruction. More...
 
#define ADDRESS_1_OFFSET   1
 MSB byte of address to read or write. More...
 
#define ADDRESS_2_OFFSET   2
 Middle byte of address to read or write. More...
 
#define ADDRESS_3_OFFSET   3
 LSB byte of address to read or write. More...
 
#define DATA_OFFSET   4
 Start of Data for Read/Write. More...
 
#define DUMMY_SIZE   1
 Number of dummy bytes for fast read. More...
 
#define RD_ID_SIZE   4
 Read ID command + 3 bytes ID response. More...
 
#define OVERHEAD_SIZE   4
 Command and address bytes. More...
 
#define UNIQUE_VALUE   0x55
 Unique test data value. More...
 
#define MAX_DATA   1024*1024
 Max data size. More...
 
#define FLASH_SPI_SELECT_1   0x01
 Flash on chip select 1. More...
 
#define FLASH_SPI_SELECT_0   0x00
 Flash on chip select 0. More...
 

Functions

void SpiPsHandler (void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
 Handles the status events of the SPI driver. More...
 
int SpiPsFlashIntrExample (XSpiPs *SpiInstancePtr, UINTPTR BaseAddress)
 Illustrates how to use the XSpiPs device driver in interrupt mode. More...
 
int main (void)
 Calls the SPI Flash interrupt example. More...
 

Variables

volatile int TransferInProgress
 Indicates that an SPI transfer is in progress. More...
 
int Error
 Tracks any errors that occur during interrupt processing. More...
 
u8 ReadBuffer [MAX_DATA+DATA_OFFSET+DUMMY_SIZE]
 Buffer for the data read from the flash. More...
 
u8 WriteBuffer [MAX_DATA+DATA_OFFSET]
 Data to write to the flash. More...
 

Macro Definition Documentation

#define ADDRESS_1_OFFSET   1

MSB byte of address to read or write.

#define ADDRESS_2_OFFSET   2

Middle byte of address to read or write.

#define ADDRESS_3_OFFSET   3

LSB byte of address to read or write.

#define BLOCK_ERASE_64K_CMD   0xD8

64 KB block erase command.

#define BULK_ERASE_CMD   0xC7

Bulk erase command.

#define CHIP_ERASE_CMD   0x60

Chip erase command.

#define COMMAND_OFFSET   0

Flash instruction.

#define DATA_OFFSET   4

Start of Data for Read/Write.

Referenced by SpiPsFlashIntrExample().

#define DUMMY_SIZE   1

Number of dummy bytes for fast read.

#define FAST_READ_CMD   0x0B

Fast read command.

#define FLASH_SPI_SELECT_0   0x00

Flash on chip select 0.

Referenced by SpiPsFlashIntrExample().

#define FLASH_SPI_SELECT_1   0x01

Flash on chip select 1.

Referenced by SpiPsFlashIntrExample().

#define GLOBAL_BLK_PROT_UNLK   0x98

Global Block-Protection Unlock register command.

#define MAX_DATA   1024*1024

Max data size.

Referenced by SpiPsFlashIntrExample().

#define OVERHEAD_SIZE   4

Command and address bytes.

#define RD_ID_SIZE   4

Read ID command + 3 bytes ID response.

#define READ_CMD   0x03

Read data command.

Referenced by SpiPsFlashIntrExample().

#define READ_ID   0x90

Read ID command.

#define READ_STATUS_CMD   0x05

Read status register command.

#define SST_FLASH_ID   0xBF

All SST flash parts have ID 0xBF.

#define SST_READ_ID   0x9F

SST flash read ID command.

#define UNIQUE_VALUE   0x55

Unique test data value.

Referenced by SpiPsFlashIntrExample().

#define WRITE_CMD   0x02

Page program command.

Referenced by SpiPsFlashIntrExample().

#define WRITE_DISABLE_CMD   0x04

Write disable command.

#define WRITE_ENABLE_CMD   0x06

Write enable command.

#define WRITE_STATUS_CMD   0x01

Write status register command.

Function Documentation

int main ( void  )

Calls the SPI Flash interrupt example.

Returns
  • XST_SUCCESS if successful
  • XST_FAILURE if not successful

References SpiPsFlashIntrExample().

int SpiPsFlashIntrExample ( XSpiPs *  SpiInstancePtr,
UINTPTR  BaseAddress 
)

Illustrates how to use the XSpiPs device driver in interrupt mode.

The function writes and reads data from a serial flash.

Parameters
[in]SpiInstancePtrPointer to the SPI driver instance to use.
[in]BaseAddressThe base address of the device.
Returns
  • XST_SUCCESS if successful
  • XST_FAILURE if not successful
Note
- In XSCT/classic flow, the device configuration is looked up based on DeviceId.
  • The function calls other functions which contain loops that may be infinite if interrupts are not working such that it may not return. If the device slave select is not correct and the device is not responding on bus it reads a status of 0xFF for the status register as the bus is pulled up.

References XSpiPs_Config::BaseAddress, DATA_OFFSET, FLASH_SPI_SELECT_0, FLASH_SPI_SELECT_1, XSpiPs_Config::IntrId, XSpiPs_Config::IntrParent, MAX_DATA, READ_CMD, ReadBuffer, SpiPsHandler(), UNIQUE_VALUE, WRITE_CMD, WriteBuffer, XSpiPs_CfgInitialize(), XSPIPS_CLK_PRESCALE_8, XSPIPS_FORCE_SSELECT_OPTION, XSpiPs_InterruptHandler(), XSpiPs_LookupConfig(), XSPIPS_MANUAL_START_OPTION, XSPIPS_MASTER_OPTION, XSpiPs_SelfTest(), XSpiPs_SetClkPrescaler(), XSpiPs_SetOptions(), XSpiPs_SetSlaveSelect(), and XSpiPs_SetStatusHandler().

Referenced by main().

void SpiPsHandler ( void *  CallBackRef,
u32  StatusEvent,
unsigned int  ByteCount 
)

Handles the status events of the SPI driver.

It is called from an interrupt context such that the amount of processing performed should be minimized. It is called when a transfer of SPI data completes or an error occurs.

This handler provides an example of how to handle SPI interrupts but is application specific.

Parameters
[in]CallBackRefA reference passed to the handler.
[in]StatusEventThe status of the SPI .
[in]ByteCountThe number of bytes transferred.

References Error, and TransferInProgress.

Referenced by SpiPsFlashIntrExample().

Variable Documentation

int Error

Tracks any errors that occur during interrupt processing.

Buffer for the data read from the flash.

volatile int TransferInProgress

Indicates that an SPI transfer is in progress.

The variable is shared between non-interrupt processing and interrupt processing such that it must be global.

u8 WriteBuffer[MAX_DATA+DATA_OFFSET]

Data to write to the flash.