![]() |
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
|
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... | |
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.
#define ADI_BITBANG_SPI (0xCD) |
Bitbang a SPI message on the selected pins
#define ADI_BUSY_MEASURE (0xCB) |
Command to trigger an event on the DUT and measure a subsequent pulse
#define ADI_CLEAR_FLASH_LOG (0xF2) |
Clear error log stored in flash memory
#define ADI_FIRMWARE_ID_CHECK (0xB0) |
Return FX3 firmware ID (defined below)
#define ADI_FROM_PC_ENDPOINT (0x1) |
BULK-OUT endpoint (general data from PC to FX3)
#define ADI_GENERIC_STALL_OFFSET (25) |
Offset to take away from the timer period for generic stream stall time. In 10MHz timer ticks
#define ADI_GET_BOARD_TYPE (0xBA) |
Get the type of the programmed board
#define ADI_GET_BUILD_DATE (0xB8) |
Get firmware build date / time
#define ADI_GET_STATUS (0xB4) |
Return the current status of the FX3 firmware
#define ADI_HARD_RESET (0xB1) |
Hard-reset the FX3 firmware (return to bootloader mode)
#define ADI_I2C_READ_BYTES (0x11) |
I2C read command
#define ADI_I2C_READ_STREAM (0x13) |
I2C continuous stream read command
#define ADI_I2C_RETRY_COUNT (0x14) |
I2C set rety count after slave sends NAK
#define ADI_I2C_SET_BIT_RATE (0x10) |
I2C set bit rate command
#define ADI_I2C_WRITE_BYTES (0x12) |
I2C write command
#define ADI_MEASURE_DR (0xC8) |
Return the pulse frequency (data ready) on a user-specified pin
#define ADI_MICROSECONDS_SLEEP_OFFSET (14) |
Minimum possible sleep time
#define ADI_NULL_COMMAND (0xD1) |
Do nothing (default case)
#define ADI_PIN_DELAY_MEASURE (0xCF) |
Measure the propagation time from a sync edge tto data ready edge
#define ADI_PULSE_DRIVE (0xC5) |
Drive a user-specified GPIO for a user-specified time
#define ADI_PULSE_WAIT (0xC6) |
Wait for a user-specified pin to reach a user-specified level (with timeout)
#define ADI_PWM_CMD (0xC9) |
Command to enable or disable a PWM signal
#define ADI_READ_BYTES (0xF0) |
Read a word at a specified address and return the data over the control endpoint
#define ADI_READ_FLASH (0xF3) |
Read flash memory
#define ADI_READ_PIN (0xC3) |
Read the value of a user-specified GPIO
#define ADI_READ_SPI_CONFIG (0xB3) |
Return FX3 SPI configuration
#define ADI_READ_TIMER_VALUE (0xC4) |
Read the current FX3 timer register value
#define ADI_RESET_SPI (0xCE) |
Reset the hardware SPI controller
#define ADI_SERIAL_NUMBER_CHECK (0xB5) |
Return the FX3 unique serial number
#define ADI_SET_BOOT_TIME (0xB9) |
Set the boot time code
#define ADI_SET_DUT_SUPPLY (0xB7) |
Set the DUT supply voltage (only works on ADI FX3 boards)
#define ADI_SET_PIN (0xC7) |
Drive a user-specified GPIO
#define ADI_SET_PIN_RESISTOR (0xD2) |
Set GPIO resistor pull up or pull down
#define ADI_SET_SPI_CONFIG (0xB2) |
Set FX3 SPI configuration
#define ADI_STREAM_BURST_DATA (0xC1) |
Start/stop a burst data stream
#define ADI_STREAM_GENERIC_DATA (0xC0) |
Start/stop a generic data stream
#define ADI_STREAM_REALTIME (0xD0) |
Start/stop a real-time stream
#define ADI_STREAMING_ENDPOINT (0x81) |
BULK-IN endpoint (data goes from FX3 into PC)
#define ADI_TIMER_PIN_INDEX (0x0) |
Complex GPIO index for the timer input (ADI_TIMER_PIN % 8)
#define ADI_TO_PC_ENDPOINT (0x82) |
BULK-IN endpoint (general data from FX3 to PC)
#define ADI_TRANSFER_BYTES (0xCA) |
Used to transfer bytes without any intervention/protocol management
#define ADI_TRANSFER_STREAM (0xCC) |
Starts a transfer stream for the ISpi32Interface
#define ADI_WARM_RESET (0xB6) |
Soft-reset the FX3 firmware (don't return to bootloader mode)
#define ADI_WRITE_BYTE (0xF1) |
Write one byte of data to a user-specified address
#define CY_FX_BULK_BURST (8) |
Burst size for SS operation only
#define EFUSE_DIE_ID (uvint32_t *)0xE0055010 |
FX3 serial number register
#define GCTL_WPD_CFG (*(uvint32_t *)(0xE0051028)) |
FX3 GPIO weak pull down control register (lower 32 bits)
#define GCTL_WPD_CFG_UPPR (*(uvint32_t *)(0xE0051028 + 0x4)) |
FX3 GPIO weak pull down control register (upper 32 bits)
#define GCTL_WPU_CFG (*(uvint32_t *)(0xE0051020)) |
FX3 GPIO weak pull up control register (lower 32 bits)
#define GCTL_WPU_CFG_UPPR (*(uvint32_t *)(0xE0051020 + 0x4)) |
FX3 GPIO weak pull up control register (upper 32 bits)
#define MS_TO_TICKS_MULT (10078) |
Conversion factor from clock ticks to milliseconds on GPIO timer
#define S_TO_TICKS_MULT (10078400) |
Conversion factor from clock ticks to seconds on GPIO timer (avoids some error)
#define UNUSED | ( | x | ) | (void)(x) |
Function macro to squash unused variable warnings
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
enum FX3BoardType |
Enum for the available FX3 board types. Boards are identified by the value on ID pin 0 and ID pin 1
enum PartTye |
void AdiAppErrorHandler | ( | CyU3PReturnStatus_t | status | ) |
This function handles critical errors generated by the ADI application.
status | The error code which corresponds with the fatal error encountered during startup. |
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.
void AdiAppStart | ( | ) |
This function sets up the necessary resources to start the ADI application.
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
void AdiAppStop | ( | ) |
This function is called to shut down the application.
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).
void AdiBulkEndpointHandler | ( | CyU3PUsbEpEvtType | evType, |
CyU3PUSBSpeed_t | usbSpeed, | ||
uint8_t | epNum | ||
) |
This function handles events generated by the bulk endpoint.
evType | The type of the event being handled |
usbSpeed | The current connection speed |
epNum | The end point number |
This function is currently unused. All event management to the host PC is performed through the control endpoint.
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.
setupdat0 | The first set of setup data. Contains of the request and value fields. |
setupdat1 | The second set of setup data. Contains the index and length fields. |
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.
FX3BoardType AdiGetFX3BoardType | ( | ) |
This function determines the type of the connected 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.
void AdiGPIOEventHandler | ( | uint8_t | gpioId | ) |
This function handles GPIO interrupts and sets the appropriate flag in GpioHandler.
gpioId | The pin number of the pin which generated the interrupt |
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.
CyBool_t AdiLPMRequestHandler | ( | CyU3PUsbLinkPowerMode | link_mode | ) |
This is a callback function to handle Link Power Management (LPM) requests.
link_mode | The USB link power state that is being set |
void AdiUSBEventHandler | ( | CyU3PUsbEventType_t | evtype, |
uint16_t | evdata | ||
) |
This is a callback function to handle generic USB events.
evtype | The type of the event being handled |
evdata | The data from the USB event |
This function handles USB events by calling start/stop functions to manage the ADI application.