![]() |
Demo program for SPI Slave IP Core.
The Usage() function shows how to execute the test program, options available and default values set for different configuration variables. The Variables section specifies variables used in the test program, what they specify, the values it holds and can take. The main() function specifies sequence of api calls executed and tested.
Functions | |
void | SPISlaveUsage () |
int | main (int argc, char *argv[]) |
Variables | |
uint | enable =1 |
enable mode bit for the SPI Slave IP Core Channel. Toggling the enable signal will cause the registers to revert to default power-on states. It takes values 0 or 1 and defaults to 1 | |
uint | activate =0 |
output enable for the SPI Slave IP Core Channel. Enable this after configuring the registers associated with api calls starting with C. It takes values 0 or 1 and defaults to 0 | |
fpgawb_ipcore_t | ip_core |
fpgawb_ipcore_t struct which stores useful information about the IP Core after executing get IP Info api call. Check fpgawb_lib.h or api call documentation for more information | |
int | channel =-1 |
Channel number for the SPI Slave IP Core Channel. It takes values 0 to (number of IP Core channels-1) and defaults to -1 (test program executed for all channels) | |
uint | config_mode =0 |
Configuration mode for the test program. Indicates to run the program in static mode or dynamic mode. It takes values 0-Configuration/1-Dynamic. It defaults to 0. | |
fpgawb_ipcore_spi_slave_config_t | config |
fpgawb_ipcore_spi_slave_config_t struct passed as argument for setting the initialization parameters for the SPI Slave IP Core channel. Check fpgawb_lib.h or api call documentation for more information | |
fpgawb_ipcore_spi_slave_communication_params_t | comm_params |
fpgawb_ipcore_spi_slave_communication_params_t struct passed as argument for setting the communication parameters for the SPI Slave IP Core channel. Check fpgawb_lib.h or api call documentation for more information | |
uint | watermark = 1968 |
watermark signifies the threshold value that will trigger the watermark flag if the FIFO reaches that many used words. It takes integer value upto 1968 and defaults to 1968. This test program is designed to read data from the FIFO when data is available in the FIFO and does not wait for the watermark flag to be triggered. | |
int main | ( | int | argc, |
char * | argv[] | ||
) |
Step 1: OPEN DEVICE
ccurPMFC_Open(&handle,board_no,oflags)
Before using any API calls, the user needs to open the device and get a handle. This handle is then used as the first argument in most of the following APIs.
Step 2: GET DRIVER INFO
ccurPMFC_Get_Driver_Info(handle, &binfo)
This call returns useful driver information and saves in the ccurpmfc_driver_info_t structure for later use.
Step 3: GET LIBRARY INFO
ccurPMFC_Get_Library_Info(handle, &linfo)
This call returns useful library information and saves in the ccurpmfc_library_info_t structure for later use.
Step 4: GET IP INFO
fpgawb_SPI_Slave_Get_Ip_Info(handle, &ip_core)
This call returns useful IP Core information and saves in the fpgawb_ipcore_t structure for later use.
Step 5: ACTIVATE SPI SLAVE CHANNEL
fpgawb_SPI_Slave_Activate_Ch(handle,chan,enable,activate)
This call activates the SPI Slave IP Core Channel by setting board_enable to 1. Note to set activate to 0 because we will be using the Config api calls which requires activate be 0. The default for activate is 0 in this test program. It is set to 1 at the end. Please be careful to give in the value as 0 when running the test program.
Step 6: CONFIGURE/SETUP CHANNEL
fpgawb_SPI_Slave_Configure_Ch(handle,chan,&config)
This call configures/setup the initialization parameters for the SPI Slave IP core channel.
Step 7: ACTIVATE SPI SLAVE CHANNEL
fpgawb_SPI_Slave_Activate_Ch(handle,chan,1,1)
This call activates the SPI Slave IP core channel for Running after the configuration phase. Note that you put the activate to 0 before configuration so make it 1 now.
Step 8: SEIZE MSGDMA
ccurPMFC_MsgDma_Seize(handle)
Seizes the MsgDma for data transfer.
Step 9: MSGDMA INITIALIZE
fpgawb_IpCore_MsgDma_Initialize_Plus(handle,&IpCodeSelect)
This call initializes Modular Scatter-Gather DMA for the selected IP Cores specified using the _fpgawb_ipcode_select_t struct. The api call calculates and allocates physical memory for the DMA transfer and configures the DMA Descriptors.
Step 10: CONFIGURE COMMUNICATION PARAMETERS FOR CHANNEL
fpgawb_SPI_Set_Ch_Communication_Parameters(handle,chan,&spi_slave_comm_params[chan])
This call programs the
Step 11: WRITES SIGNATURE/BUFFER RESPONSE FOR THE CHANNEL
fpgawb_SPI_Slave_Set_Ch_Output(handle,chan,&spi_slave_output[chan])
This call writes the signature/buffer response for the SPI Slave IP core channel.
Step 12: CONFIGURES MSGDMA DESCRIPTOR LENGTH
fpgawb_SPI_Slave_MsgDma_Config(handle,&IpCodeSelect,&config_length)
This configures the MsgDma descriptor length for the SPI Slave IP core channel. Please refer to api call documentaion for more information on configuring the parameters.
Step 13: WRITE DATA TO THE DATA REGISTERS
fpgawb_SPI_Slave_Write_Ch_Data(handle,channel,spi_slave_data_tx)
This call writes the data received from the Master to the physical memory/buffer. Data is written to the data registers of the corresponding SPI Slave IP Core channel when MsgDma is fired.
Step 14: MSGDMA FIRE
fpgawb_IpCore_MsgDma_Fire(handle)
This call commences the MsgDma transfer which transfers the data received from the SPI Master from the physical memory/buffer to the data registers of the SPI Slave IP Core channel on the FPGA.
Step 15: READS STATUS INFORMATION FOR THE CHANNEL
fpgawb_SPI_Slave_Get_Ch_Info(handle,chan,&spi_slave_info[chan])
This call reads the status for the SPI Slave IP core channel. It contains the FIFO status information.
Step 16: CONFIGURES MSGDMA DESCRIPTOR LENGTH
fpgawb_SPI_Slave_MsgDma_Config(handle,&IpCodeSelect,&config_length)
This configures the MsgDma descriptor length for the SPI Slave IP core channel. Please refer to api call documentaion for more information on configuring the parameters.
Step 17: MSGDMA FIRE
fpgawb_IpCore_MsgDma_Fire(handle)
This call commences the MsgDma transfer from the fpga to physical memory, which contains the data received/recorded by the SPI Slave IP core channel.
Step 18: READS RECEIVED DATA
fpgawb_SPI_Slave_Read_Ch_Data(handle,channel,spi_slave_data_rx)
This call reads the data recorded in the FIFO by the SPI Slave IP core channel.
void SPISlaveUsage | ( | ) |
Usage:
./fpgawb_ipcore_spi_slave [-A Activate] [-b BoardNumber] [-c channelNumber] [-C config_mode] [-e Enable] [-f InputFile] [-n SOMINeg] [-w Watermark]
Options | Default value |
---|---|
-A Activate (0/1) | 0 |
-b Board Number | 0 |
-c channel Number (0-(Numchans-1) | -1 (all channels) |
-C Config Mode (0-static config/1-dynamic params) | 0 |
-e Enable (0/1) | 1 |
-f Input file | null |
-n SOMI Negate | 0 |
-w Watermark (<=1968) | 1968 |
Examples:
SETUP: ./fpgawb_ipcore_spi_slave -C0 -w1968
RUNTIME: ./fpgawb_ipcore_spi_slave -C1 -fangles/spi_slave_data.txt
spi_slave_data.txt file format:
First line contains the 128 port flags. Each channel has 128 data registers each of which can have a 16 bit input bus ported to it. Setting a value of 1 indicates the port flag is enabled for that data register.
Line 2 through 129 contains the 128 16 bit values in hex for the data registers. This data is transferred via MsgDma to the 64 spi data registers when register_control mode is set to 1.