ADI iSensor FX3 Firmware  v2.9.4-pub
Firmware for the Analog Devices EVAL-ADIS-FX3 IMU Evaluation Platform. This firmware can be compiled using the Cypress EZ USB Suite IDE
Functions | Variables
SpiFunctions.c File Reference

This file contains all generic SPI read/write function implementations. More...

#include "SpiFunctions.h"

Functions

static void AdiBitBangSpiTransferCPHA0 (uint8_t *MOSI, uint8_t *MISO, uint32_t BitCount, BitBangSpiConf config)
 Performs a single bit banged SPI transfer. Pins must already be configured as needed. More...
 
static void AdiBitBangSpiTransferCPHA1 (uint8_t *MOSI, uint8_t *MISO, uint32_t BitCount, BitBangSpiConf config)
 Performs a single bit banged SPI transfer. Pins must already be configured as needed. More...
 
static CyU3PReturnStatus_t AdiBitBangSpiSetup (BitBangSpiConf config)
 Configures all pins and timers needed to bitbang a SPI connection. More...
 
static void AdiWaitForSpiNotBusy ()
 Waits for the SPI controller busy bit to be not set. More...
 
void AdiSpiPrepareForTransfer ()
 Set up the SPI for a register based transfer. More...
 
void AdiSpiTransferWord (uint8_t *txBuf, uint8_t *rxBuf)
 Bi-directional SPI transfer function, in register mode. Optimized for speed. More...
 
CyU3PReturnStatus_t AdiRestartSpi ()
 This function restarts the SPI controller. More...
 
CyU3PReturnStatus_t AdiBitBangSpiHandler ()
 This function handles bit bang SPI requests from the control endpoint. More...
 
CyU3PSpiConfig_t AdiGetSpiConfig ()
 This function parses the SPI control registers into an easier to work with config struct. More...
 
void AdiPrintSpiConfig (CyU3PSpiConfig_t config)
 Prints a given SPI config over the UART debug port. More...
 
CyU3PReturnStatus_t AdiTransferBytes (uint32_t writeData)
 This function performs a protocol agnostic SPI bi-directional SPI transfer of (1, 2, 4) bytes. More...
 
CyU3PReturnStatus_t AdiReadRegBytes (uint16_t addr)
 This function reads a single 16 bit SPI word from a slave device. More...
 
CyU3PReturnStatus_t AdiWriteRegByte (uint16_t addr, uint8_t data)
 This function writes a single byte of data over the SPI bus. More...
 
void AdiSetSpiWordLength (uint8_t wordLength)
 Sets the SPI controller word length (4 - 32 bits) More...
 
CyU3PReturnStatus_t AdiSpiResetFifo (CyBool_t isTx, CyBool_t isRx)
 This function resets the SPI FIFO and disables the SPI block after completion. More...
 
CyU3PReturnStatus_t AdiGetSpiSettings ()
 This function handles vendor commands to get the current SPI configuration from the FX3. More...
 
CyBool_t AdiSpiUpdate (uint16_t index, uint16_t value, uint16_t length)
 This function handles a vendor command request to update the SPI/DR Pin configuration. More...
 

Variables

BoardState FX3State
 
StreamState StreamThreadState
 
CyU3PDmaBuffer_t ManualDMABuffer
 
CyU3PDmaChannel ChannelToPC
 
uint8_t USBBuffer [4096]
 
uint8_t BulkBuffer [12288]
 
static uvint32_t * SCLKPin
 
static uvint32_t * CSPin
 
static uvint32_t * MISOPin
 
static uvint32_t * MOSIPin
 
static uint32_t SCLKActiveMask
 
static uint32_t SCLKInactiveMask
 
static uint32_t SCLKLowTime
 
static uint32_t SPIWordLen
 

Detailed Description

This file contains all generic SPI read/write function implementations.

Copyright (c) 2018-2020 Analog Devices, Inc. All Rights Reserved. This software is proprietary to Analog Devices, Inc. and its licensors.

THIS SOFTWARE UTILIZES LIBRARIES DEVELOPED AND MAINTAINED BY CYPRESS INC. THE LICENSE INCLUDED IN THIS REPOSITORY DOES NOT EXTEND TO CYPRESS PROPERTY.

Use of this file is governed by the license agreement included in this repository.

Date
8/1/2019
Author
A. Nolan (alex..nosp@m.nola.nosp@m.n@ana.nosp@m.log..nosp@m.com)
J. Chong (juan..nosp@m.chon.nosp@m.g@ana.nosp@m.log..nosp@m.com)

Function Documentation

◆ AdiBitBangSpiHandler()

CyU3PReturnStatus_t AdiBitBangSpiHandler ( )

This function handles bit bang SPI requests from the control endpoint.

Returns
A status code indicating the success of the SPI bitbang operation.

This function requires all data to have been retrieved from the control endpoint before being called. It parses all the parameters about the current bit bang SPI operation to perform from the transaction. The pins/timing/config is sent from the FX3 API to the firmware with each bitbang SPI transaction.

◆ AdiBitBangSpiSetup()

static CyU3PReturnStatus_t AdiBitBangSpiSetup ( BitBangSpiConf  config)
static

Configures all pins and timers needed to bitbang a SPI connection.

Parameters
configA structure containing all the relevant bit banged SPI configuration parameters.
Returns
A status code indicating the success of the bitbang SPI setup process.

◆ AdiBitBangSpiTransferCPHA0()

static void AdiBitBangSpiTransferCPHA0 ( uint8_t *  MOSI,
uint8_t *  MISO,
uint32_t  BitCount,
BitBangSpiConf  config 
)
static

Performs a single bit banged SPI transfer. Pins must already be configured as needed.

Parameters
MOSIA pointer to the master out data buffer. This data will be transmitted MSB first, over the MOSI line in config.
MISOA pointer to the data receive (rx) buffer. The data received from a slave will be placed here.
BitCountThe number of bits to transfer.
configThe configuration settings to use for the transfer.

This function allows a user to use any pins on the FX3 as a low speed SPI master. The API provided is similar to the Cypress API for the hardware SPI. This function is fixed to operate in CPHA mode 0 (sample data on idle-active edge, update data on active-idle edge).

◆ AdiBitBangSpiTransferCPHA1()

static void AdiBitBangSpiTransferCPHA1 ( uint8_t *  MOSI,
uint8_t *  MISO,
uint32_t  BitCount,
BitBangSpiConf  config 
)
static

Performs a single bit banged SPI transfer. Pins must already be configured as needed.

Parameters
MOSIA pointer to the master out data buffer. This data will be transmitted MSB first, over the MOSI line in config.
MISOA pointer to the data receive (rx) buffer. The data received from a slave will be placed here.
BitCountThe number of bits to transfer.
configThe configuration settings to use for the transfer.

This function allows a user to use any pins on the FX3 as a low speed SPI master. The API provided is similar to the Cypress API for the hardware SPI. This function is fixed to operate in CPHA mode 1 (update data on idle-active edge, sample on active-idle edge).

◆ AdiGetSpiConfig()

CyU3PSpiConfig_t AdiGetSpiConfig ( )

This function parses the SPI control registers into an easier to work with config struct.

Returns
The current SPI config, as set in the SPI controller hardware.

This function can be used to ensure synchronization between the SPI controller and the SPI settings in firmware, without having to perform a SPI controller reset operation. Resetting the SPI controller can cause undesired effects on the SPI lines.

◆ AdiGetSpiSettings()

CyU3PReturnStatus_t AdiGetSpiSettings ( )

This function handles vendor commands to get the current SPI configuration from the FX3.

Returns
A status code indicating the success of the function.

This function allows the FX3 API to verify that the FX3 board has the same SPI settings as the current FX3 connection instance. The current configuration is sent to the PC via EP0.

◆ AdiPrintSpiConfig()

void AdiPrintSpiConfig ( CyU3PSpiConfig_t  config)

Prints a given SPI config over the UART debug port.

Parameters
configThe SPI config structure to print out.
Returns
void

◆ AdiReadRegBytes()

CyU3PReturnStatus_t AdiReadRegBytes ( uint16_t  addr)

This function reads a single 16 bit SPI word from a slave device.

Parameters
addrThe address to send to the DUT in the first SPI transaction.
Returns
A status code indicating the success of the function.

This function reads a single word over SPI. Note that reads are not "full duplex" and will require a discrete read to set the address to be read from (two 16 bit transactions per read).

◆ AdiRestartSpi()

CyU3PReturnStatus_t AdiRestartSpi ( )

This function restarts the SPI controller.

Returns
A status code indicating the success of the setConfig call after re-initialization.

This function can be used to restore hardware SPI functionality after overriding the SPI pins to act as a bit-banged SPI port. This function can be called before or after the SPI controller has been initialized without causing problems. This function may cause erroneous toggles on the SPI lines during the initialization process - be careful to ensure that the connected DUT is not particularly sensitive to extra toggles.

◆ AdiSetSpiWordLength()

void AdiSetSpiWordLength ( uint8_t  wordLength)

Sets the SPI controller word length (4 - 32 bits)

Parameters
wordLengthThe number of bits to transfer in a single SPI transaction

This function writes directly to the SPI control register. It does not cause the toggle on the chip select line seen using the cypress API for setting the SPI word length.

◆ AdiSpiPrepareForTransfer()

void AdiSpiPrepareForTransfer ( )

Set up the SPI for a register based transfer.

Returns
void

The process is as follows:

(1) Disable SPI (2) Disable interrupts (3) Ensure Rx and Tx clear is disabled (4) Clear FIFOs (5) Set the file scope SPI word length variable

◆ AdiSpiResetFifo()

CyU3PReturnStatus_t AdiSpiResetFifo ( CyBool_t  isTx,
CyBool_t  isRx 
)

This function resets the SPI FIFO and disables the SPI block after completion.

Parameters
isTxBoolean to indicate if you're clearing the TX FIFO
isRxBoolean to indicate if you're clearing the RX FIFO
Returns
The success of the SPI reset FIFO operation.

It is a copy of the private CyU3PSpiResetFifo() function which bypasses some input sanitization which the Cypress libraries perform. This is required due to our high-speed, register-initiated transfers.

◆ AdiSpiTransferWord()

void AdiSpiTransferWord ( uint8_t *  txBuf,
uint8_t *  rxBuf 
)

Bi-directional SPI transfer function, in register mode. Optimized for speed.

Returns
void

This function is used to allow for a reduced SPI stall time. Is fairly "unsafe" in that all hardware has to be configured for correct operation, and free, before this function can be called.

◆ AdiSpiUpdate()

CyBool_t AdiSpiUpdate ( uint16_t  index,
uint16_t  value,
uint16_t  length 
)

This function handles a vendor command request to update the SPI/DR Pin configuration.

Parameters
indexThe wIndex from the control endpoint transaction which indicates which parameter to update
valueThe wValue from the control endpoint transaction which holds the SPI value to set for the selected parameter.
lengthThe length of the Data In phase of the control endpoint transaction
Returns
A boolean indicating if the SPI configuration was a success

This function provides an API for maintaining synchronicity in SPI and data ready triggering settings between the FX3 API and the firmware. Any time a setting is changed on the FX3 API, this function will be invoked to reflect that change.

◆ AdiTransferBytes()

CyU3PReturnStatus_t AdiTransferBytes ( uint32_t  writeData)

This function performs a protocol agnostic SPI bi-directional SPI transfer of (1, 2, 4) bytes.

Parameters
writeDataThe data to transmit on the MOSI line.
Returns
A status code indicating the success of the function.

This function performs a bi-directional SPI transfer, on up to 4 bytes of data. The transfer length is determined by the current SPI config word length setting. The data received on the MISO line is placed in USBBuffer[4 - 7] following the transfer.

◆ AdiWaitForSpiNotBusy()

static void AdiWaitForSpiNotBusy ( )
static

Waits for the SPI controller busy bit to be not set.

Returns
void

◆ AdiWriteRegByte()

CyU3PReturnStatus_t AdiWriteRegByte ( uint16_t  addr,
uint8_t  data 
)

This function writes a single byte of data over the SPI bus.

Parameters
addrThe DUT address to write data to (7 bits).
dataThe byte of data to write to the address
Returns
A status code indicating the success of the function.

This function uses the standard iSensor SPI protocol to issue a write command. For the standard iSensor SPI parts, a write is performed in a single 16 bit command, where the first bit clocked out is the write bit (high) followed by the address and data.

Variable Documentation

◆ ChannelToPC

CyU3PDmaChannel ChannelToPC
extern

DMA channel for BULK-IN endpoint 0x82 (FX3 to PC)

◆ CSPin

uvint32_t* CSPin
static

Pointer to bit bang SPI CS pin

◆ FX3State

BoardState FX3State
extern

Struct. which stores all run time configurable FX3 settings

◆ ManualDMABuffer

CyU3PDmaBuffer_t ManualDMABuffer
extern

DMA buffer structure for output buffer

◆ MISOPin

uvint32_t* MISOPin
static

Pointer to bit bang SPI MISO pin

◆ MOSIPin

uvint32_t* MOSIPin
static

Pointer to bit bang SPI MOSI pin

◆ SCLKActiveMask

uint32_t SCLKActiveMask
static

SCLK active setting. Based on CPOL

◆ SCLKInactiveMask

uint32_t SCLKInactiveMask
static

SCLK idle setting. Based on CPOL

◆ SCLKLowTime

uint32_t SCLKLowTime
static

SCLK low period offset

◆ SCLKPin

uvint32_t* SCLKPin
static

Pointer to bit bang SPI SCLK pin

◆ SPIWordLen

uint32_t SPIWordLen
static

Word length for a register based SPI tranfer

◆ StreamThreadState

StreamState StreamThreadState
extern

Struct of data used to synchronize the data streaming / app threads