| spi Vitis Drivers API Documentation

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

Functions
xspi_eeprom_example.c File Reference

## Overview

This file contains a design example using the SPI driver (XSpi) and hardware device with a serial EEPROM device.

The hardware which this example runs on must have a serial EEPROM (Microchip 25XX320 or 25XX160) for it to run. This example has been tested with the SPI EEPROM on the ML410 platform for PPC processor.

Note

None.

     MODIFICATION HISTORY:

     Ver   Who  Date     Changes

     1.00b jhl  02/27/01 First release
     1.00c jhl  08/15/03 Fixed bugs (local instances and large buffers are now
                                     moved to globals)
     1.11a sv   9/10/07  Minor changes to comply to Doxygen and coding guidelines
     3.00a ktn  10/28/09 Converted all register accesses to 32 bit access.
                          Updated to use the HAL APIs/macros. Replaced call to
                          XSpi_Initialize API with XSpi_LookupConfig and
                          XSpi_CfgInitialize.
     4.2   ms   01/23/17 Added xil_printf statement in main function to
                         ensure that "Successfully ran" and "Failed" strings
                         are available in all examples. This is a fix for
                         CR-965028.
           ms   04/05/17 Modified Comment lines to follow doxygen rules.
     4.11  sb   07/11/23 Added support for system device-tree flow.

## Functions
void | SpiHandler (void *CallBackRef, u32 StatusEvent, unsigned int ByteCount)
| This function is the handler which performs processing for the SPI driver. More...
void | EepromRead (XSpi *SpiPtr, u16 Address, int ByteCount, EepromBuffer Buffer)
| This function reads from the Microchip serial EEPROM connected to the SPI interface. More...
void | EepromWrite (XSpi *SpiPtr, u16 Address, u8 ByteCount, EepromBuffer Buffer)
| This function writes to the Microchip serial EEPROM connected to the SPI interface. More...
int | main (void)
| The purpose of this function is to illustrate how to use the XSpi device driver. More...

## Function Documentation

void EepromRead | ( | XSpi * | SpiPtr,
|  | u16 | Address,
|  | int | ByteCount,
|  | EepromBuffer | Buffer
| ) |  |

This function reads from the Microchip serial EEPROM connected to the SPI interface.

Parameters

  SpiPtr | is a pointer to the SPI driver component to use.
  Address | contains the address to read data from in the EEPROM.
  ByteCount | contains the number of bytes to read.
  Buffer | is a buffer to read the data into.

Returns
  None.

Note
  None.

References XSpi_Transfer().

Referenced by main().

void EepromWrite | ( | XSpi * | SpiPtr,
|  | u16 | Address,
|  | u8 | ByteCount,
|  | EepromBuffer | Buffer
| ) |  |

This function writes to the Microchip serial EEPROM connected to the SPI interface.

This function is not designed to be a driver to handle all the conditions of the EEPROM device. The EEPROM contains a 32 byte write buffer which can be filled and then a write is automatically performed by the device. All the data put into the buffer must be in the same page of the device with page boundaries being on 32 byte boundaries.

Parameters

  SpiPtr | is a pointer to the SPI driver component to use.
  Address | contains the address to write data to in the EEPROM.
  ByteCount | contains the number of bytes to write.
  Buffer | is a buffer of data to write from.

Returns
  None.

Note
  None.

References XSpi_Transfer().

Referenced by main().

int main | ( | void |  | ) |

The purpose of this function is to illustrate how to use the XSpi device driver.

This test writes and reads data from a Microchip serial EEPROM. This part must be present in the hardware to use this example.

Returns
  XST_SUCCESS if successful else XST_FAILURE.

Note

This function calls 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 will read a status of 0xFF for the status register as the bus is pulled up.

References XSpi_Config::BaseAddress, EepromRead(), EepromWrite(), SpiHandler(), XSP_MASTER_OPTION, XSpi_CfgInitialize(), XSpi_InterruptHandler(), XSpi_LookupConfig(), XSpi_SetOptions(), XSpi_SetSlaveSelect(), XSpi_SetStatusHandler(), and XSpi_Start().

void SpiHandler | ( | void * | CallBackRef,
|  | u32 | StatusEvent,
|  | unsigned int | ByteCount
| ) |  |

This function is the handler which performs processing for 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

  CallBackRef | is a reference passed to the handler.
  StatusEvent | is the status of the SPI .
  ByteCount | is the number of bytes transferred.

Returns
  None

Note
  None.