/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< ------------------------------------------------------------------ Copyright (c) 2006-2018 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ IMPORTANT: THIS FILE IS AUTO-GENERATED BY LATTICE RADIANT Software. Permission: Lattice grants permission to use this code pursuant to the terms of the Lattice Corporation Open Source License Agreement. Disclaimer: Lattice provides no warranty regarding the use or functionality of this code. It is the user's responsibility to verify the user Software design for consistency and functionality through the use of formal Software validation methods. ------------------------------------------------------------------ Lattice Semiconductor Corporation 111 SW Fifth Avenue, Suite 700 Portland, OR 97204 U.S.A Email: techsupport@latticesemi.com Web: http://www.latticesemi.com/Home/Support/SubmitSupportTicket.aspx ================================================================== */ #ifndef SPI_SLAVE_H #define SPI_SLAVE_H #include #include #define SPI_Slave_DRV_VER "v1.5.0" enum { SPI_SLAVE_IDLE=0, SPI_SLAVE_READY, SPI_SLAVE_READ, SPI_SLAVE_WRITE }; /**ERR CODE**/ typedef enum { /* basic errors */ SPI_SUCCESS = 0, /**< No error condition. */ SPI_PTR_ERROR = 1, /**< PTR is NULL. */ } SPI_SLAVE_ErrorCode; #define BITS_ALL_SET 0xFF #define BITS_ALL_CLEAR 0x00 struct spi_slave_callback_entry { void (*spi_slave_callback) (void *); // the registered spi slave callback function void *context; // the context of the callback }; struct spis_instance { uint32_t base_addr; // Base address of the SPI slave device uint32_t data_width; // Data width of the SPI uint32_t fifo_depth; // Depth of the FIFO uint32_t *tx_buffer; // Pointer to the transmit buffer uint32_t tx_cnt; // Transmit counter uint32_t tx_size; // Size of the transmit buffer uint32_t *rx_buffer; // Pointer to the receive buffer uint32_t rx_cnt; // Receive counter uint32_t rx_size; // Size of the receive buffer uint8_t daisy_chain; // Whether to use daisy chain mode uint8_t spi_cpol; // SPI clock polarity uint8_t spi_cpha; // SPI clock phase uint8_t ss_polarity; // Polarity of the slave select signal uint8_t status; // Status of the SPI slave device struct spi_slave_callback_entry callback; // Callback function structure }; /* ***************************************************************************** * performs spi slave block initialization * * Note: This function initializes the spi slave block * * * Arguments: * struct spis_instance* this_spis: spi slave instance * uint32_t base_addr : base address of the spi master * uint32_t fifo_depth : spi slave fifo depth * uint32_t *slave_tx_buf : buf of data to be sent * uint32_t *slave_rx_buf : buf of data to be received * void *spi_callback : callback function * void * context : context of callback * Return Value: * int: * * ***************************************************************************** */ uint8_t spi_slave_init(struct spis_instance *this_spis, uint32_t base_addr, uint32_t fifo_depth, uint32_t *slave_tx_buf,uint32_t *slave_rx_buf,void (*spi_callback) (void *), void *context); /* ***************************************************************************** * performs spi slave block configuration * * * Arguments: * struct spis_instance* this_spis: spi slave instance * uint32_t base_addr : base address of the spi master * uint32_t fifo_width : spi slave fifo width * uint8_t data_width, : data width * uint8_t clk_polarity, : clock polarity * uint8_t clk_phase, : clock phase * uint8_t daisy_chain : enable daisy chain * uint8_t ss_polarity : plarity of ss signal * Return Value: * int: * * ***************************************************************************** */ uint8_t spi_slave_config(struct spis_instance *this_spis, uint32_t data_width, uint8_t clock_polarity, uint8_t clock_phase, uint8_t daisy_chain, uint8_t ss_polarity); /* ***************************************************************************** * performs spi slave interrupt function * * Note: This function perform the interrupt service routine * */ void spi_slave_isr(void *ctx); /* ***************************************************************************** * performs spi slave status get * * * Arguments: * struct spis_instance* this_spis: spi slave instance * uint8_t status : status value * * * Return Value: * int: * * ***************************************************************************** */ uint8_t spi_slave_get_status(struct spis_instance *this_spis,uint8_t *status); /* ***************************************************************************** * performs spi slave transfer operation * * Note: This function perform the callback function to parse data * */ void spi_slave_callback(void *context); /* ***************************************************************************** * performs spi slave data get * * * Arguments: * struct spis_instance* this_spis: spi slave instance * uint32_t data : data to be received * uint32_t length : data length * Return Value: * int: * * ***************************************************************************** */ uint8_t spi_slave_data_read(struct spis_instance *this_spis,uint32_t *data,uint8_t length); /* ***************************************************************************** * performs spi slave data sent * * * Arguments: * struct spis_instance* this_spis: spi slave instance * uint32_t data : data to be sent * uint32_t length : data length * Return Value: * int: * * ***************************************************************************** */ uint8_t spi_slave_data_write(struct spis_instance *this_spis,uint32_t *data,uint8_t length); #endif