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
Data Structures | Macros | Typedefs | Functions
SpiFunctions.h File Reference

Header file for all SPI related functions. More...

#include "main.h"

Go to the source code of this file.

Data Structures

struct  BitBangSpiConf
 

Macros

#define BITBANG_HALFCLOCK_OFFSET   5
 
#define STALL_COUNT_OFFSET   10
 
#define GPIO_HIGH   (1 << 31)|(1 << 5)|(1 << 4)|(1 << 0)
 
#define GPIO_LOW   (1 << 31)|(1 << 5)|(1 << 4)
 

Typedefs

typedef struct BitBangSpiConf BitBangSpiConf
 

Functions

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...
 
CyU3PReturnStatus_t AdiSpiResetFifo (CyBool_t isTx, CyBool_t isRx)
 This function resets the SPI FIFO and disables the SPI block after completion. More...
 
CyU3PSpiConfig_t AdiGetSpiConfig ()
 This function parses the SPI control registers into an easier to work with config struct. More...
 
void AdiSetSpiWordLength (uint8_t wordLength)
 Sets the SPI controller word length (4 - 32 bits) More...
 
void AdiPrintSpiConfig (CyU3PSpiConfig_t config)
 Prints a given SPI config over the UART debug port. More...
 
CyU3PReturnStatus_t AdiRestartSpi ()
 This function restarts the SPI controller. 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 AdiTransferBytes (uint32_t writeData)
 This function performs a protocol agnostic SPI bi-directional SPI transfer of (1, 2, 4) bytes. More...
 
CyU3PReturnStatus_t AdiWriteRegByte (uint16_t addr, uint8_t data)
 This function writes a single byte of data over the SPI bus. More...
 
CyU3PReturnStatus_t AdiReadRegBytes (uint16_t addr)
 This function reads a single 16 bit SPI word from a slave device. More...
 
CyU3PReturnStatus_t AdiBitBangSpiHandler ()
 This function handles bit bang SPI requests from the control endpoint. More...
 

Detailed Description

Header file for all SPI related functions.

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)

Macro Definition Documentation

◆ BITBANG_HALFCLOCK_OFFSET

#define BITBANG_HALFCLOCK_OFFSET   5

Offset to make the short side of the bitbang SPI match long side. Approx. 62ns per tick

◆ GPIO_HIGH

#define GPIO_HIGH   (1 << 31)|(1 << 5)|(1 << 4)|(1 << 0)

Register setting to drive GPIO high (enable (31), drive high (5), drive low (4), out enabled (0))

◆ GPIO_LOW

#define GPIO_LOW   (1 << 31)|(1 << 5)|(1 << 4)

Register setting to drive GPIO low (enable (31), drive high (5), drive low (4))

◆ STALL_COUNT_OFFSET

#define STALL_COUNT_OFFSET   10

Offset for bit bang stall time calc

Typedef Documentation

◆ BitBangSpiConf

Structure to store configuration parameters for a bitbang SPI.

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.

◆ 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.

◆ 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.