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
main.c File Reference

Entry point and setup functions for the Analog Devices iSensor FX3 Demonstration Platform firmware. More...

#include "main.h"

Functions

uint8_t USBBuffer ((aligned(32)))
 
uint8_t BulkBuffer ((aligned(32)))
 
const uint8_t FirmwareID ((aligned(32)))
 
char serial_number ((aligned(32)))
 
int main (void)
 This is the main entry point function for the iSensor FX3 application firmware. 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...
 
void AdiAppErrorHandler (CyU3PReturnStatus_t status)
 This function handles critical errors generated by the ADI application. More...
 
void AdiAppStop ()
 This function is called to shut down the application. More...
 
void AdiAppStart ()
 This function sets up the necessary resources to start the ADI application. More...
 
FX3BoardType AdiGetFX3BoardType ()
 This function determines the type of the connected FX3 board. More...
 
void CyFxApplicationDefine (void)
 This function is called by the RTOS kernel after booting and creates all the user threads. More...
 

Variables

CyU3PThread StreamThread = {0}
 
CyU3PThread AppThread = {0}
 
CyU3PEvent EventHandler = {0}
 
CyU3PEvent GpioHandler = {0}
 
CyU3PDmaChannel StreamingChannel = {0}
 
CyU3PDmaChannel ChannelFromPC = {0}
 
CyU3PDmaChannel ChannelToPC = {0}
 
CyU3PDmaChannel MemoryToSPI = {0}
 
CyU3PDmaBuffer_t ManualDMABuffer = {0}
 
CyU3PDmaBuffer_t SpiDmaBuffer = {0}
 
BoardState FX3State = {.SpiConfig = {0}, .PinMap = {0}}
 
volatile CyBool_t KillStreamEarly = CyFalse
 
StreamState StreamThreadState = {0}
 

Detailed Description

Entry point and setup functions 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)

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.

◆ BulkBuffer()

uint8_t BulkBuffer ( (aligned(32))  )

12KB Generic bulk buffer. Used for when data is manually sent to or received from the PC via bulk endpoints.

◆ CyFxApplicationDefine()

void CyFxApplicationDefine ( void  )

This function is called by the RTOS kernel after booting and creates all the user threads.

After the ThreadX kernel is started by a call to CyU3PKernelEntry() in main, this function is called. It creates the AppThread (for general execution / handling vendor requests) and the StreamThread for handling high throughput data streaming from a DUT.

◆ FirmwareID()

const uint8_t FirmwareID ( (aligned(32))  )

Constant firmware ID string. Manually updated when releasing new version of the FX3 firmware. Must match FX3 API version number.

◆ main()

int main ( void  )

This is the main entry point function for the iSensor FX3 application firmware.

Returns
A status code indicating the success of the function. Should never return.

This firmware image is loaded into RAM over USB by the second-stange iSensor FX3 Bootloader when the Connect() function is called in the FX3 API. Once the full image has been loaded into SRAM, and the CRC verified, the iSensor FX3 bootloader jumps to this main function. Main initializes the device, memory, and IO matrix, and then boots the RTOS kernel.

◆ serial_number()

char serial_number ( (aligned(32))  )

FX3 unique serial number. Set at runtime during the initialization process.

◆ USBBuffer()

uint8_t USBBuffer ( (aligned(32))  )

4KB USB Data buffer. Used to receive data from the control endpoint

Variable Documentation

◆ AppThread

CyU3PThread AppThread = {0}

RTOS thread handle for the main application

◆ ChannelFromPC

CyU3PDmaChannel ChannelFromPC = {0}

DMA channel for BULK-OUT endpoint 0x1 (PC to FX3)

◆ ChannelToPC

CyU3PDmaChannel ChannelToPC = {0}

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

◆ EventHandler

CyU3PEvent EventHandler = {0}

ADI event structure

◆ FX3State

BoardState FX3State = {.SpiConfig = {0}, .PinMap = {0}}

Struct. which stores all run time configurable FX3 settings

◆ GpioHandler

CyU3PEvent GpioHandler = {0}

ADI GPIO event structure (RTOS handles GPIO ISR)

◆ KillStreamEarly

volatile CyBool_t KillStreamEarly = CyFalse

Signal data stream thread to kill data capture early (True = kill thread signaled, False = allow execution)

◆ ManualDMABuffer

CyU3PDmaBuffer_t ManualDMABuffer = {0}

DMA buffer structure for output buffer

◆ MemoryToSPI

CyU3PDmaChannel MemoryToSPI = {0}

DMA channel for reading a memory location into a DMA consumer

◆ SpiDmaBuffer

CyU3PDmaBuffer_t SpiDmaBuffer = {0}

DMA buffer structure for SPI transmit

◆ StreamingChannel

CyU3PDmaChannel StreamingChannel = {0}

DMA channel for real time streaming (SPI to USB BULK-IN 0x81)

◆ StreamThread

CyU3PThread StreamThread = {0}

RTOS thread handle for continuous data streaming functionality

◆ StreamThreadState

StreamState StreamThreadState = {0}

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