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 | Enumerations | Functions | Variables
main.h File Reference

Main header file for the Analog Devices iSensor FX3 Demonstration Platform firmware. More...

#include "cyu3types.h"
#include "cyu3usbconst.h"
#include "cyu3externcstart.h"
#include "cyu3system.h"
#include "cyu3os.h"
#include "cyu3dma.h"
#include "cyu3error.h"
#include "cyu3usb.h"
#include "cyu3i2c.h"
#include "cyu3spi.h"
#include "cyu3uart.h"
#include "cyu3utils.h"
#include "cyu3gpio.h"
#include "cyu3vic.h"
#include "cyu3pib.h"
#include "stdlib.h"
#include "sys/unistd.h"
#include "AppThread.h"
#include "PinFunctions.h"
#include "SpiFunctions.h"
#include "StreamFunctions.h"
#include "StreamThread.h"
#include "Flash.h"
#include "ErrorLog.h"
#include "I2cFunctions.h"
#include "HelperFunctions.h"
#include "gpio_regs.h"
#include "spi_regs.h"
#include "gctlaon_regs.h"
#include <cyu3externcend.h>

Go to the source code of this file.

Data Structures

struct  FX3PinMap
 Pin map for translating FX3 GPIO pins to iSensor eval board functional pins. More...
 
struct  BoardState
 Struct to store the current board state (SPI config, USB speed, etc) More...
 
struct  StreamState
 Struct to store the current data stream state information. More...
 

Macros

#define ADI_I2C_SET_BIT_RATE   (0x10)
 
#define ADI_I2C_READ_BYTES   (0x11)
 
#define ADI_I2C_WRITE_BYTES   (0x12)
 
#define ADI_I2C_READ_STREAM   (0x13)
 
#define ADI_I2C_RETRY_COUNT   (0x14)
 
#define ADI_FIRMWARE_ID_CHECK   (0xB0)
 
#define ADI_HARD_RESET   (0xB1)
 
#define ADI_SET_SPI_CONFIG   (0xB2)
 
#define ADI_READ_SPI_CONFIG   (0xB3)
 
#define ADI_GET_STATUS   (0xB4)
 
#define ADI_SERIAL_NUMBER_CHECK   (0xB5)
 
#define ADI_WARM_RESET   (0xB6)
 
#define ADI_SET_DUT_SUPPLY   (0xB7)
 
#define ADI_GET_BUILD_DATE   (0xB8)
 
#define ADI_SET_BOOT_TIME   (0xB9)
 
#define ADI_GET_BOARD_TYPE   (0xBA)
 
#define ADI_STREAM_GENERIC_DATA   (0xC0)
 
#define ADI_STREAM_BURST_DATA   (0xC1)
 
#define ADI_READ_PIN   (0xC3)
 
#define ADI_READ_TIMER_VALUE   (0xC4)
 
#define ADI_PULSE_DRIVE   (0xC5)
 
#define ADI_PULSE_WAIT   (0xC6)
 
#define ADI_SET_PIN   (0xC7)
 
#define ADI_MEASURE_DR   (0xC8)
 
#define ADI_PIN_DELAY_MEASURE   (0xCF)
 
#define ADI_STREAM_REALTIME   (0xD0)
 
#define ADI_NULL_COMMAND   (0xD1)
 
#define ADI_SET_PIN_RESISTOR   (0xD2)
 
#define ADI_READ_BYTES   (0xF0)
 
#define ADI_WRITE_BYTE   (0xF1)
 
#define ADI_CLEAR_FLASH_LOG   (0xF2)
 
#define ADI_READ_FLASH   (0xF3)
 
#define ADI_TRANSFER_BYTES   (0xCA)
 
#define ADI_TRANSFER_STREAM   (0xCC)
 
#define ADI_PWM_CMD   (0xC9)
 
#define ADI_BUSY_MEASURE   (0xCB)
 
#define ADI_BITBANG_SPI   (0xCD)
 
#define ADI_RESET_SPI   (0xCE)
 
#define S_TO_TICKS_MULT   (10078400)
 
#define MS_TO_TICKS_MULT   (10078)
 
#define ADI_GENERIC_STALL_OFFSET   (25)
 
#define ADI_MICROSECONDS_SLEEP_OFFSET   (14)
 
#define ADI_TIMER_PIN_INDEX   (0x0)
 
#define ADI_STREAMING_ENDPOINT   (0x81)
 
#define ADI_FROM_PC_ENDPOINT   (0x1)
 
#define ADI_TO_PC_ENDPOINT   (0x82)
 
#define CY_FX_BULK_BURST   (8)
 
#define GCTL_WPD_CFG   (*(uvint32_t *)(0xE0051028))
 
#define GCTL_WPD_CFG_UPPR   (*(uvint32_t *)(0xE0051028 + 0x4))
 
#define GCTL_WPU_CFG   (*(uvint32_t *)(0xE0051020))
 
#define GCTL_WPU_CFG_UPPR   (*(uvint32_t *)(0xE0051020 + 0x4))
 
#define EFUSE_DIE_ID   (uvint32_t *)0xE0055010
 
#define UNUSED(x)   (void)(x)
 

Typedefs

typedef enum FX3BoardType FX3BoardType
 
typedef enum PartTye PartType
 
typedef struct FX3PinMap FX3PinMap
 Pin map for translating FX3 GPIO pins to iSensor eval board functional pins.
 
typedef struct BoardState BoardState
 Struct to store the current board state (SPI config, USB speed, etc)
 
typedef struct StreamState StreamState
 Struct to store the current data stream state information.
 

Enumerations

enum  FX3BoardType {
  CypressFX3Board = 0, iSensorFX3Board_A = 1, iSensorFX3Board_B = 2, iSensorFX3Board_C = 3,
  iSensorFX3Board_D = 4, iSensorFX3Board_E = 5, iSensorFX3Board_F = 6, iSensorFX3Board_G = 7,
  iSensorFX3Board_H = 8
}
 
enum  PartTye {
  ADcmXL1021 = 0, ADcmXL2021, ADcmXL3021, IMU,
  LegacyIMU
}
 

Functions

void AdiAppStart ()
 This function sets up the necessary resources to start the ADI application. More...
 
void AdiAppStop ()
 This function is called to shut down the application. More...
 
void AdiAppErrorHandler (CyU3PReturnStatus_t status)
 This function handles critical errors generated by the ADI application. More...
 
FX3BoardType AdiGetFX3BoardType ()
 This function determines the type of the connected FX3 board. More...
 
CyBool_t AdiControlEndpointHandler (uint32_t setupdat0, uint32_t setupdat1)
 This function handles events generated by the control endpoint. All vendor requests are handled in this function. More...
 
void AdiBulkEndpointHandler (CyU3PUsbEpEvtType evType, CyU3PUSBSpeed_t usbSpeed, uint8_t epNum)
 This function handles events generated by the bulk endpoint. More...
 
void AdiUSBEventHandler (CyU3PUsbEventType_t evtype, uint16_t evdata)
 This is a callback function to handle generic USB events. More...
 
CyBool_t AdiLPMRequestHandler (CyU3PUsbLinkPowerMode link_mode)
 This is a callback function to handle Link Power Management (LPM) requests. More...
 
void AdiGPIOEventHandler (uint8_t gpioId)
 This function handles GPIO interrupts and sets the appropriate flag in GpioHandler. More...
 

Variables

const uint8_t CyFxUSB20DeviceDscr []
 
const uint8_t CyFxUSB30DeviceDscr []
 
const uint8_t CyFxUSBDeviceQualDscr []
 
const uint8_t CyFxUSBFSConfigDscr []
 
const uint8_t CyFxUSBHSConfigDscr []
 
const uint8_t CyFxUSBBOSDscr []
 
const uint8_t CyFxUSBSSConfigDscr []
 
const uint8_t CyFxUSBStringLangIDDscr []
 
const uint8_t CyFxUSBManufactureDscr []
 
const uint8_t CyFxUSBProductDscr []
 
uint8_t CyFxUSBSerialNumDesc []
 

Detailed Description

Main header file for the Analog Devices iSensor FX3 Demonstration Platform firmware.

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

◆ ADI_BITBANG_SPI

#define ADI_BITBANG_SPI   (0xCD)

Bitbang a SPI message on the selected pins

◆ ADI_BUSY_MEASURE

#define ADI_BUSY_MEASURE   (0xCB)

Command to trigger an event on the DUT and measure a subsequent pulse

◆ ADI_CLEAR_FLASH_LOG

#define ADI_CLEAR_FLASH_LOG   (0xF2)

Clear error log stored in flash memory

◆ ADI_FIRMWARE_ID_CHECK

#define ADI_FIRMWARE_ID_CHECK   (0xB0)

Return FX3 firmware ID (defined below)

◆ ADI_FROM_PC_ENDPOINT

#define ADI_FROM_PC_ENDPOINT   (0x1)

BULK-OUT endpoint (general data from PC to FX3)

◆ ADI_GENERIC_STALL_OFFSET

#define ADI_GENERIC_STALL_OFFSET   (25)

Offset to take away from the timer period for generic stream stall time. In 10MHz timer ticks

◆ ADI_GET_BOARD_TYPE

#define ADI_GET_BOARD_TYPE   (0xBA)

Get the type of the programmed board

◆ ADI_GET_BUILD_DATE

#define ADI_GET_BUILD_DATE   (0xB8)

Get firmware build date / time

◆ ADI_GET_STATUS

#define ADI_GET_STATUS   (0xB4)

Return the current status of the FX3 firmware

◆ ADI_HARD_RESET

#define ADI_HARD_RESET   (0xB1)

Hard-reset the FX3 firmware (return to bootloader mode)

◆ ADI_I2C_READ_BYTES

#define ADI_I2C_READ_BYTES   (0x11)

I2C read command

◆ ADI_I2C_READ_STREAM

#define ADI_I2C_READ_STREAM   (0x13)

I2C continuous stream read command

◆ ADI_I2C_RETRY_COUNT

#define ADI_I2C_RETRY_COUNT   (0x14)

I2C set rety count after slave sends NAK

◆ ADI_I2C_SET_BIT_RATE

#define ADI_I2C_SET_BIT_RATE   (0x10)

I2C set bit rate command

◆ ADI_I2C_WRITE_BYTES

#define ADI_I2C_WRITE_BYTES   (0x12)

I2C write command

◆ ADI_MEASURE_DR

#define ADI_MEASURE_DR   (0xC8)

Return the pulse frequency (data ready) on a user-specified pin

◆ ADI_MICROSECONDS_SLEEP_OFFSET

#define ADI_MICROSECONDS_SLEEP_OFFSET   (14)

Minimum possible sleep time

◆ ADI_NULL_COMMAND

#define ADI_NULL_COMMAND   (0xD1)

Do nothing (default case)

◆ ADI_PIN_DELAY_MEASURE

#define ADI_PIN_DELAY_MEASURE   (0xCF)

Measure the propagation time from a sync edge tto data ready edge

◆ ADI_PULSE_DRIVE

#define ADI_PULSE_DRIVE   (0xC5)

Drive a user-specified GPIO for a user-specified time

◆ ADI_PULSE_WAIT

#define ADI_PULSE_WAIT   (0xC6)

Wait for a user-specified pin to reach a user-specified level (with timeout)

◆ ADI_PWM_CMD

#define ADI_PWM_CMD   (0xC9)

Command to enable or disable a PWM signal

◆ ADI_READ_BYTES

#define ADI_READ_BYTES   (0xF0)

Read a word at a specified address and return the data over the control endpoint

◆ ADI_READ_FLASH

#define ADI_READ_FLASH   (0xF3)

Read flash memory

◆ ADI_READ_PIN

#define ADI_READ_PIN   (0xC3)

Read the value of a user-specified GPIO

◆ ADI_READ_SPI_CONFIG

#define ADI_READ_SPI_CONFIG   (0xB3)

Return FX3 SPI configuration

◆ ADI_READ_TIMER_VALUE

#define ADI_READ_TIMER_VALUE   (0xC4)

Read the current FX3 timer register value

◆ ADI_RESET_SPI

#define ADI_RESET_SPI   (0xCE)

Reset the hardware SPI controller

◆ ADI_SERIAL_NUMBER_CHECK

#define ADI_SERIAL_NUMBER_CHECK   (0xB5)

Return the FX3 unique serial number

◆ ADI_SET_BOOT_TIME

#define ADI_SET_BOOT_TIME   (0xB9)

Set the boot time code

◆ ADI_SET_DUT_SUPPLY

#define ADI_SET_DUT_SUPPLY   (0xB7)

Set the DUT supply voltage (only works on ADI FX3 boards)

◆ ADI_SET_PIN

#define ADI_SET_PIN   (0xC7)

Drive a user-specified GPIO

◆ ADI_SET_PIN_RESISTOR

#define ADI_SET_PIN_RESISTOR   (0xD2)

Set GPIO resistor pull up or pull down

◆ ADI_SET_SPI_CONFIG

#define ADI_SET_SPI_CONFIG   (0xB2)

Set FX3 SPI configuration

◆ ADI_STREAM_BURST_DATA

#define ADI_STREAM_BURST_DATA   (0xC1)

Start/stop a burst data stream

◆ ADI_STREAM_GENERIC_DATA

#define ADI_STREAM_GENERIC_DATA   (0xC0)

Start/stop a generic data stream

◆ ADI_STREAM_REALTIME

#define ADI_STREAM_REALTIME   (0xD0)

Start/stop a real-time stream

◆ ADI_STREAMING_ENDPOINT

#define ADI_STREAMING_ENDPOINT   (0x81)

BULK-IN endpoint (data goes from FX3 into PC)

◆ ADI_TIMER_PIN_INDEX

#define ADI_TIMER_PIN_INDEX   (0x0)

Complex GPIO index for the timer input (ADI_TIMER_PIN % 8)

◆ ADI_TO_PC_ENDPOINT

#define ADI_TO_PC_ENDPOINT   (0x82)

BULK-IN endpoint (general data from FX3 to PC)

◆ ADI_TRANSFER_BYTES

#define ADI_TRANSFER_BYTES   (0xCA)

Used to transfer bytes without any intervention/protocol management

◆ ADI_TRANSFER_STREAM

#define ADI_TRANSFER_STREAM   (0xCC)

Starts a transfer stream for the ISpi32Interface

◆ ADI_WARM_RESET

#define ADI_WARM_RESET   (0xB6)

Soft-reset the FX3 firmware (don't return to bootloader mode)

◆ ADI_WRITE_BYTE

#define ADI_WRITE_BYTE   (0xF1)

Write one byte of data to a user-specified address

◆ CY_FX_BULK_BURST

#define CY_FX_BULK_BURST   (8)

Burst size for SS operation only

◆ EFUSE_DIE_ID

#define EFUSE_DIE_ID   (uvint32_t *)0xE0055010

FX3 serial number register

◆ GCTL_WPD_CFG

#define GCTL_WPD_CFG   (*(uvint32_t *)(0xE0051028))

FX3 GPIO weak pull down control register (lower 32 bits)

◆ GCTL_WPD_CFG_UPPR

#define GCTL_WPD_CFG_UPPR   (*(uvint32_t *)(0xE0051028 + 0x4))

FX3 GPIO weak pull down control register (upper 32 bits)

◆ GCTL_WPU_CFG

#define GCTL_WPU_CFG   (*(uvint32_t *)(0xE0051020))

FX3 GPIO weak pull up control register (lower 32 bits)

◆ GCTL_WPU_CFG_UPPR

#define GCTL_WPU_CFG_UPPR   (*(uvint32_t *)(0xE0051020 + 0x4))

FX3 GPIO weak pull up control register (upper 32 bits)

◆ MS_TO_TICKS_MULT

#define MS_TO_TICKS_MULT   (10078)

Conversion factor from clock ticks to milliseconds on GPIO timer

◆ S_TO_TICKS_MULT

#define S_TO_TICKS_MULT   (10078400)

Conversion factor from clock ticks to seconds on GPIO timer (avoids some error)

◆ UNUSED

#define UNUSED (   x)    (void)(x)

Function macro to squash unused variable warnings

Typedef Documentation

◆ FX3BoardType

typedef enum FX3BoardType FX3BoardType

Enum for the available FX3 board types. Boards are identified by the value on ID pin 0 and ID pin 1

◆ PartType

typedef enum PartTye PartType

Enum for the available part (DUT) types

Enumeration Type Documentation

◆ FX3BoardType

Enum for the available FX3 board types. Boards are identified by the value on ID pin 0 and ID pin 1

Enumerator
CypressFX3Board 

Cypress SuperSpeed Explorer kit board. Can be used with breakout board for iSensors connectors. Hardware ID = 2'bZ1

iSensorFX3Board_A 

Rev. A iSensor FX3 based eval board manufactured by Analog Devices. Hardware ID = 2'bZZ

iSensorFX3Board_B 

Rev. B iSensor FX3 board. This revision was not manufactured. Hardware ID = 2'bZ0

iSensorFX3Board_C 

Rev. C iSensor FX3 based eval board manufactured by Analog Devices. Hardware ID = 2'b1Z

iSensorFX3Board_D 

Rev. D iSensor FX3 based eval board manufactured by Analog Devices. Hardware ID = 2'b0Z

iSensorFX3Board_E 

Rev. E iSensor FX3 based eval board manufactured by Analog Devices. Hardware ID = 2'b00

iSensorFX3Board_F 

Rev. F iSensor FX3 based eval board manufactured by Analog Devices. Hardware ID = 2'b01

iSensorFX3Board_G 

Rev. G iSensor FX3 based eval board manufactured by Analog Devices. Hardware ID = 2'b10

iSensorFX3Board_H 

Rev. H iSensor FX3 based eval board manufactured by Analog Devices. Hardware ID = 2'b11

◆ PartTye

enum PartTye

Enum for the available part (DUT) types

Enumerator
ADcmXL1021 

0 for ADcmXL1021 (single axis)

ADcmXL2021 

1 for ADcmXL2021 (two axis)

ADcmXL3021 

2 for ADcmXL3021 (three axis)

IMU 

3 Other DUTs (IMU)

LegacyIMU 

4 Legacy IMU family (ADIS16448, etc)

Function Documentation

◆ AdiAppErrorHandler()

void AdiAppErrorHandler ( CyU3PReturnStatus_t  status)

This function handles critical errors generated by the ADI application.

Parameters
statusThe error code which corresponds with the fatal error encountered during startup.
Returns
void

This function prints the error message to the debug console, waits five seconds, and performs a hard reset. Performing the hard reset will clear the SRAM and reboot the FX3 into the second stage iSensors FX3 bootloader. Could probably do something more intelligent, but at least this approach will not lock up the FX3 after a failed boot.

◆ AdiAppStart()

void AdiAppStart ( )

This function sets up the necessary resources to start the ADI application.

Returns
void

The application startup process configures all GPIO and timers used by the firmware, as well as the USB endpoints, DMA controller, and SPI hardware. After all configuration is performed, the AppActive flag is set to true.

GPIO Clock configuration: SYS_CLK = 403.2MHz GPIO Fast Clock = SYS_CLK / 2 -> 201.6MHz GPIO Slow Clock (Used for 10MHz timer) = Fast Clock / 20 -> 10.08MHz Simple GPIO Sample Clock = Fast Clock / 2 -> 100.8MHz

◆ AdiAppStop()

void AdiAppStop ( )

This function is called to shut down the application.

Returns
void

This function cleans up the resources used by the ADI application and prepares them for the next run. Since this function is intended to be called as part of the shut down process, no error handling is performed. Any transient errors should be resolved the next time the system boots (after this function call is finished).

◆ AdiBulkEndpointHandler()

void AdiBulkEndpointHandler ( CyU3PUsbEpEvtType  evType,
CyU3PUSBSpeed_t  usbSpeed,
uint8_t  epNum 
)

This function handles events generated by the bulk endpoint.

Parameters
evTypeThe type of the event being handled
usbSpeedThe current connection speed
epNumThe end point number
Returns
A status code indicating the success of the function.

This function is currently unused. All event management to the host PC is performed through the control endpoint.

◆ AdiControlEndpointHandler()

CyBool_t AdiControlEndpointHandler ( uint32_t  setupdat0,
uint32_t  setupdat1 
)

This function handles events generated by the control endpoint. All vendor requests are handled in this function.

Parameters
setupdat0The first set of setup data. Contains of the request and value fields.
setupdat1The second set of setup data. Contains the index and length fields.
Returns
A boolean indicating if the control endpoint event was handled properly.

This function handles all USB events generated by the control endpoint. For the iSensor FX3 firmware, these events are a set of custom vendor commands. These vendor commands must be issued by the host PC. To ensure consistent behavior, all vendor commands should be issued using a function call in the FX3API. The FX3 API manages the control endpoint parameters to ensure valid behavior in all cases.

Fast enumeration is used. Only requests addressed to the interface, class, vendor and unknown control requests are received by this function.

◆ AdiGetFX3BoardType()

FX3BoardType AdiGetFX3BoardType ( )

This function determines the type of the connected FX3 board.

Returns
The connected board type. This can be a Cypress Explorer kit or iSensor FX3 board

This function works by measuring two ID pins which are assigned on the iSensor FX3 demonstration platform. These ID pins can be high, low, or tri-stated, allowing for 9 possible hardware ID configurations. The weak pull up / weak pull down functionality of the FX3 GPIO allows reliable differentiation between all three states.

◆ AdiGPIOEventHandler()

void AdiGPIOEventHandler ( uint8_t  gpioId)

This function handles GPIO interrupts and sets the appropriate flag in GpioHandler.

Parameters
gpioIdThe pin number of the pin which generated the interrupt
Returns
void

This function is called by the RTOS whenever the GPIO interrupt vector is enabled and a GPIO interrupt is received. Instead of performing any work in this function, to improve system responsiveness, this function sets an RTOS event flag, to be handled by the application thread.

◆ AdiLPMRequestHandler()

CyBool_t AdiLPMRequestHandler ( CyU3PUsbLinkPowerMode  link_mode)

This is a callback function to handle Link Power Management (LPM) requests.

Parameters
link_modeThe USB link power state that is being set
Returns
Returns true so that the USB driver always stays in high power state.

◆ AdiUSBEventHandler()

void AdiUSBEventHandler ( CyU3PUsbEventType_t  evtype,
uint16_t  evdata 
)

This is a callback function to handle generic USB events.

Parameters
evtypeThe type of the event being handled
evdataThe data from the USB event

This function handles USB events by calling start/stop functions to manage the ADI application.