spips: xspips_eeprom_intr_example.c File Reference

| spips Xilinx SDK Drivers API Documentation

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

Functions
xspips_eeprom_intr_example.c File Reference

## Overview

This file contains a design example using the SPI driver (XSpiPs) in interrupt mode 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.

Note

None.

     MODIFICATION HISTORY:

     Ver   Who  Date     Changes

     1.00  sdm  02/27/10 First release
     1.00  sdm  10/25/11 Updated the chip select to be used to second chip select
           ms   04/05/17 Modified Comment lines in functions to
                         recognize it as documentation block for doxygen
                         generation and also modified filename tag to include
                         the file in doxygen examples.

## 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 (XSpiPs *SpiPtr, u16 Address, int ByteCount, EepromBuffer Buffer)
| This function reads from the serial EEPROM connected to the SPI interface. More...
void | EepromWrite (XSpiPs *SpiPtr, u16 Address, u8 ByteCount, EepromBuffer Buffer)
| This function writes to the serial EEPROM connected to the SPI interface. More...
int | SpiPsEepromIntrExample (XScuGic *IntcInstancePtr, XSpiPs *SpiInstancePtr, u16 SpiDeviceId, u16 SpiIntrId)
| The purpose of this function is to illustrate how to use the XSpiPs device driver in interrupt mode . More...
int | main (void)
| Main function to call the Spi Eeprom example. More...

## Function Documentation

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

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

Parameters

  SpiPtr | is a pointer to the SPI driver instance 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.

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 XSpiPs_Transfer().

Referenced by SpiPsEepromIntrExample(), and SpiPsEepromPolledExample().

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

This function writes to the 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 instance 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 XSpiPs_Transfer().

Referenced by SpiPsEepromIntrExample(), and SpiPsEepromPolledExample().

int main | ( | void |  | ) |

Main function to call the Spi Eeprom example.

Parameters

  None |

Returns
  XST_SUCCESS if successful, otherwise XST_FAILURE.

Note
  None

References SpiPsEepromIntrExample().

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.

Referenced by SpiPsEepromIntrExample().

int SpiPsEepromIntrExample | ( | XScuGic * | IntcInstancePtr,
|  | XSpiPs * | SpiInstancePtr,
|  | u16 | SpiDeviceId,
|  | u16 | SpiIntrId
| ) |  |

The purpose of this function is to illustrate how to use the XSpiPs device driver in interrupt mode .

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

Parameters

  IntcInstancePtr | is a pointer to the GIC driver to use.
  SpiInstancePtr | is a pointer to the SPI driver to use.
  SpiDeviceId | is the DeviceId of the Spi device.
  SpiIntrId | is the Spi Interrupt Id.

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 XSpiPs_Config::BaseAddress, EepromRead(), EepromWrite(), SpiHandler(), XSpiPs_CfgInitialize(), XSPIPS_CLK_PRESCALE_64, XSPIPS_FORCE_SSELECT_OPTION, XSpiPs_LookupConfig(), XSPIPS_MASTER_OPTION, XSpiPs_SelfTest(), XSpiPs_SetClkPrescaler(), XSpiPs_SetOptions(), XSpiPs_SetSlaveSelect(), and XSpiPs_SetStatusHandler().

Referenced by main().