 |
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
|
Go to the documentation of this file.
29 #include "cyu3types.h"
30 #include "cyu3usbconst.h"
31 #include "cyu3externcstart.h"
32 #include "cyu3system.h"
35 #include "cyu3error.h"
40 #include "cyu3utils.h"
45 #include "sys/unistd.h"
59 #include "gpio_regs.h"
251 #define ADI_I2C_SET_BIT_RATE (0x10)
254 #define ADI_I2C_READ_BYTES (0x11)
257 #define ADI_I2C_WRITE_BYTES (0x12)
260 #define ADI_I2C_READ_STREAM (0x13)
263 #define ADI_I2C_RETRY_COUNT (0x14)
266 #define ADI_FIRMWARE_ID_CHECK (0xB0)
269 #define ADI_HARD_RESET (0xB1)
272 #define ADI_SET_SPI_CONFIG (0xB2)
275 #define ADI_READ_SPI_CONFIG (0xB3)
278 #define ADI_GET_STATUS (0xB4)
281 #define ADI_SERIAL_NUMBER_CHECK (0xB5)
284 #define ADI_WARM_RESET (0xB6)
287 #define ADI_SET_DUT_SUPPLY (0xB7)
290 #define ADI_GET_BUILD_DATE (0xB8)
293 #define ADI_SET_BOOT_TIME (0xB9)
296 #define ADI_GET_BOARD_TYPE (0xBA)
299 #define ADI_STREAM_GENERIC_DATA (0xC0)
302 #define ADI_STREAM_BURST_DATA (0xC1)
305 #define ADI_READ_PIN (0xC3)
308 #define ADI_READ_TIMER_VALUE (0xC4)
311 #define ADI_PULSE_DRIVE (0xC5)
314 #define ADI_PULSE_WAIT (0xC6)
317 #define ADI_SET_PIN (0xC7)
320 #define ADI_MEASURE_DR (0xC8)
323 #define ADI_PIN_DELAY_MEASURE (0xCF)
326 #define ADI_STREAM_REALTIME (0xD0)
329 #define ADI_NULL_COMMAND (0xD1)
332 #define ADI_SET_PIN_RESISTOR (0xD2)
335 #define ADI_READ_BYTES (0xF0)
338 #define ADI_WRITE_BYTE (0xF1)
341 #define ADI_CLEAR_FLASH_LOG (0xF2)
344 #define ADI_READ_FLASH (0xF3)
347 #define ADI_TRANSFER_BYTES (0xCA)
350 #define ADI_TRANSFER_STREAM (0xCC)
353 #define ADI_PWM_CMD (0xC9)
356 #define ADI_BUSY_MEASURE (0xCB)
359 #define ADI_BITBANG_SPI (0xCD)
362 #define ADI_RESET_SPI (0xCE)
369 #define S_TO_TICKS_MULT (10078400)
372 #define MS_TO_TICKS_MULT (10078)
375 #define ADI_GENERIC_STALL_OFFSET (25)
378 #define ADI_MICROSECONDS_SLEEP_OFFSET (14)
381 #define ADI_TIMER_PIN_INDEX (0x0)
388 #define ADI_STREAMING_ENDPOINT (0x81)
391 #define ADI_FROM_PC_ENDPOINT (0x1)
394 #define ADI_TO_PC_ENDPOINT (0x82)
397 #define CY_FX_BULK_BURST (8)
404 #define GCTL_WPD_CFG (*(uvint32_t *)(0xE0051028))
407 #define GCTL_WPD_CFG_UPPR (*(uvint32_t *)(0xE0051028 + 0x4))
410 #define GCTL_WPU_CFG (*(uvint32_t *)(0xE0051020))
413 #define GCTL_WPU_CFG_UPPR (*(uvint32_t *)(0xE0051020 + 0x4))
416 #define EFUSE_DIE_ID (uvint32_t *)0xE0055010
421 extern const uint8_t CyFxUSB20DeviceDscr[];
422 extern const uint8_t CyFxUSB30DeviceDscr[];
423 extern const uint8_t CyFxUSBDeviceQualDscr[];
424 extern const uint8_t CyFxUSBFSConfigDscr[];
425 extern const uint8_t CyFxUSBHSConfigDscr[];
426 extern const uint8_t CyFxUSBBOSDscr[];
427 extern const uint8_t CyFxUSBSSConfigDscr[];
428 extern const uint8_t CyFxUSBStringLangIDDscr[];
429 extern const uint8_t CyFxUSBManufactureDscr[];
430 extern const uint8_t CyFxUSBProductDscr[];
431 extern uint8_t CyFxUSBSerialNumDesc[];
447 #define UNUSED(x) (void)(x)
449 #include <cyu3externcend.h>
#define ADI_STREAM_START_CMD
Definition: StreamFunctions.h:61
#define ADI_TRANSFER_STREAM_STOP
Definition: AppThread.h:81
CyU3PReturnStatus_t AdiReadRegBytes(uint16_t addr)
This function reads a single 16 bit SPI word from a slave device.
Definition: SpiFunctions.c:710
@ iSensorFX3Board_D
Definition: main.h:79
#define ADI_TRANSFER_STREAM
Definition: main.h:350
#define ADI_HARD_RESET
Definition: main.h:269
#define FX3_GPIO4_INTERRUPT_FLAG
Definition: PinFunctions.h:131
@ iSensorFX3Board_B
Definition: main.h:73
#define ADI_I2C_SET_BIT_RATE
Definition: main.h:251
#define ADI_STREAM_DONE_CMD
Definition: StreamFunctions.h:58
void AdiAppThreadEntry(uint32_t input)
This is the entry point for the primary iSensors firmware application thread.
Definition: AppThread.c:272
#define ADI_GENERIC_STREAM_STOP
Definition: AppThread.h:57
const uint8_t FirmwareID((aligned(32)))
PinState
Definition: PinFunctions.h:41
void AdiGPIOEventHandler(uint8_t gpioId)
This function handles GPIO interrupts and sets the appropriate flag in GpioHandler.
Definition: main.c:755
#define ADI_I2C_STREAM_START
Definition: AppThread.h:90
@ iSensorFX3Board_H
Definition: main.h:91
#define ADI_SET_DUT_SUPPLY
Definition: main.h:287
struct BoardState BoardState
Struct to store the current board state (SPI config, USB speed, etc)
CyBool_t DrPolarity
Definition: main.h:174
CyBool_t DrActive
Definition: main.h:171
#define ADI_DIO3_INTERRUPT_FLAG
Definition: PinFunctions.h:116
CyU3PDmaBuffer_t SpiDmaBuffer
Definition: main.c:95
void AdiFlashReadHandler(uint32_t Address, uint16_t NumBytes)
Handles flash read requests from control endpoint.
Definition: Flash.c:198
CyU3PReturnStatus_t AdiPinRead(uint16_t pin)
This function handles Pin read control end point requests.
Definition: PinFunctions.c:1147
#define ADI_READ_BYTES
Definition: main.h:335
@ Main_c
Definition: ErrorLog.h:42
uint16_t ADI_PIN_DIO1
Definition: main.h:122
#define ADI_PIN_DELAY_MEASURE
Definition: main.h:323
#define STREAMTHREAD_STACK
Definition: StreamThread.h:29
void AdiUSBEventHandler(CyU3PUsbEventType_t evtype, uint16_t evdata)
This is a callback function to handle generic USB events.
Definition: main.c:698
#define FX3_GPIO2_INTERRUPT_FLAG
Definition: PinFunctions.h:125
#define ADI_RT_STREAM_STOP
Definition: AppThread.h:45
uint8_t * RegList
Definition: main.h:236
@ LegacyIMU
Definition: main.h:111
CyU3PEvent GpioHandler
Definition: main.c:63
CyU3PReturnStatus_t AdiBitBangSpiHandler()
This function handles bit bang SPI requests from the control endpoint.
Definition: SpiFunctions.c:221
uint16_t ADI_PIN_DIO3
Definition: main.h:128
uint32_t I2CBitRate
Definition: main.h:195
@ iSensorFX3Board_C
Definition: main.h:76
#define ADI_STREAM_GENERIC_DATA
Definition: main.h:299
#define ADI_READ_FLASH
Definition: main.h:344
#define FX3_GPIO3_INTERRUPT_FLAG
Definition: PinFunctions.h:128
#define ADI_BURST_STREAM_DONE
Definition: AppThread.h:72
CyBool_t WatchDogEnabled
Definition: main.h:177
uint32_t TimerPinConfig
Definition: main.h:162
CyU3PThread StreamThread
Definition: main.c:54
uint16_t FX3_PIN_GPIO1
Definition: main.h:134
FX3BoardType AdiGetFX3BoardType()
This function determines the type of the connected FX3 board.
Definition: main.c:1322
uint16_t TransferWordLength
Definition: main.h:218
#define GCTL_WPU_CFG_UPPR
Definition: main.h:413
uint16_t FX3_PIN_GPIO3
Definition: main.h:140
#define ADI_I2C_RETRY_COUNT
Definition: main.h:263
#define FX3_GPIO1_INTERRUPT_FLAG
Definition: PinFunctions.h:122
#define ADI_TRANSFER_STREAM_DONE
Definition: AppThread.h:84
#define ADI_TRANSFER_STREAM_START
Definition: AppThread.h:78
void AdiGetBuildDate(uint8_t *outBuf)
Gets the firmware build date, followed by the build time.
Definition: HelperFunctions.c:158
#define ADI_GET_STATUS
Definition: main.h:278
CyU3PReturnStatus_t AdiPulseDrive()
This function drives a GPIO pin for a specified number of milliseconds, then returns it to the starti...
Definition: PinFunctions.c:781
#define ADI_ID_PIN_1
Definition: PinFunctions.h:85
Header file for all data streaming functions (generic, burst, ADcm real time, transfer).
void AdiBulkEndpointHandler(CyU3PUsbEpEvtType evType, CyU3PUSBSpeed_t usbSpeed, uint8_t epNum)
This function handles events generated by the bulk endpoint.
Definition: main.c:681
char serial_number((aligned(32)))
CyU3PReturnStatus_t AdiPulseWait(uint16_t transferLength)
This function waits for a pin to reach a selected logic level. The PulseWait parameters are passed in...
Definition: PinFunctions.c:899
#define ADI_TO_PC_ENDPOINT
Definition: main.h:394
PartType DutType
Definition: main.h:153
CyU3PDmaBuffer_t ManualDMABuffer
Definition: main.c:92
#define ADI_SERIAL_NUMBER_CHECK
Definition: main.h:281
void AdiAppStart()
This function sets up the necessary resources to start the ADI application.
Definition: main.c:891
void AdiAppStop()
This function is called to shut down the application.
Definition: main.c:827
#define ADI_SET_PIN_RESISTOR
Definition: main.h:332
CyBool_t AppActive
Definition: main.h:159
#define ADI_DIO2_INTERRUPT_FLAG
Definition: PinFunctions.h:113
Header file for a set of general purpose iSensor FX3 helper functions.
@ Low
Definition: PinFunctions.h:43
uint16_t FX3_PIN_GPIO4
Definition: main.h:143
#define ADI_I2C_STREAM_DONE
Definition: AppThread.h:96
#define ADI_MEASURE_DR
Definition: main.h:320
#define ADI_BITBANG_SPI
Definition: main.h:359
FX3BoardType BoardType
Definition: main.h:189
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.
Definition: SpiFunctions.c:931
@ High
Definition: PinFunctions.h:46
Header file for USB-I2C interfacing module.
DutVoltage
Definition: HelperFunctions.h:26
Struct to store the current data stream state information.
Definition: main.h:204
#define ADI_I2C_READ_STREAM
Definition: main.h:260
CyBool_t AdiControlEndpointHandler(uint32_t setupdat0, uint32_t setupdat1)
This function handles events generated by the control endpoint. All vendor requests are handled in th...
Definition: main.c:215
CyU3PReturnStatus_t AdiSetPinResistor(uint16_t pin, PinResistorSetting setting)
Configure GPIO input stage pull up / pull down resistor.
Definition: PinFunctions.c:151
CyU3PReturnStatus_t AdiGetSpiSettings()
This function handles vendor commands to get the current SPI configuration from the FX3.
Definition: SpiFunctions.c:886
CyU3PReturnStatus_t AdiI2CWriteHandler(uint16_t RequestLength)
Handler for I2C write command from control endpoint.
Definition: I2cFunctions.c:91
CyBool_t AdiLPMRequestHandler(CyU3PUsbLinkPowerMode link_mode)
This is a callback function to handle Link Power Management (LPM) requests.
Definition: main.c:736
Header file for FX3 flash interfacing module.
CyU3PReturnStatus_t AdiReadTimerValue()
Reads the current value from the complex GPIO timer and then sends the value over the control endpoin...
Definition: PinFunctions.c:1223
uint32_t NumCaptures
Definition: main.h:227
uint32_t NumBuffers
Definition: main.h:230
#define ADI_NULL_COMMAND
Definition: main.h:329
#define ADI_FLASH_WRITE_ENABLE_PIN
Definition: PinFunctions.h:88
#define ADI_TIMER_PIN
Definition: PinFunctions.h:103
CyU3PDmaChannel ChannelFromPC
Definition: main.c:73
void CyFxApplicationDefine(void)
This function is called by the RTOS kernel after booting and creates all the user threads.
Definition: main.c:1397
uint8_t BulkBuffer((aligned(32)))
#define ADI_5V_EN
Definition: PinFunctions.h:79
Pin map for translating FX3 GPIO pins to iSensor eval board functional pins.
Definition: main.h:117
Global Control Always-On registers for the EZ-USB FX3 Device.
uint16_t ADI_PIN_DIO2
Definition: main.h:125
#define ADI_STREAMING_ENDPOINT
Definition: main.h:388
#define ADI_DIO4_INTERRUPT_FLAG
Definition: PinFunctions.h:119
#define ADI_STREAM_REALTIME
Definition: main.h:326
PinState AdiGetPinState(uint16_t pin)
Determine state of an input pin (high, low, high Z)
Definition: PinFunctions.c:77
#define ADI_PWM_CMD
Definition: main.h:353
CyU3PReturnStatus_t AdiMeasurePinFreq()
Measure the data ready frequency for a user specified pin.
Definition: PinFunctions.c:1255
void AdiGetBoardPinInfo(uint8_t *outBuf)
Gets the programmed board type and pin mapping info.
Definition: PinFunctions.c:37
Header file for the FX3 flash error logging module.
#define ADI_TRANSFER_BYTES
Definition: main.h:347
void AdiStreamThreadEntry(uint32_t input)
The entry point function for the StreamThread. Handles all streaming data captures.
Definition: StreamThread.c:47
uint32_t BytesPerFrame
Definition: main.h:206
uint32_t StallTime
Definition: main.h:165
uint16_t BytesPerBuffer
Definition: main.h:233
#define ADI_BURST_STREAM_STOP
Definition: AppThread.h:69
@ iSensorFX3Board_G
Definition: main.h:88
Struct to store the current board state (SPI config, USB speed, etc)
Definition: main.h:148
void AdiAppErrorHandler(CyU3PReturnStatus_t status)
This function handles critical errors generated by the ADI application.
Definition: main.c:801
uint32_t BootTime
Definition: main.h:186
@ ADcmXL2021
Definition: main.h:102
#define ADI_WARM_RESET
Definition: main.h:284
#define ADI_3_3V_EN
Definition: PinFunctions.h:76
uint8_t USBBuffer((aligned(32)))
void AdiAppStart()
This function sets up the necessary resources to start the ADI application.
Definition: main.c:891
void AdiAppStop()
This function is called to shut down the application.
Definition: main.c:827
CyU3PReturnStatus_t AdiMeasureBusyPulse(uint16_t transferLength)
Sets a user configurable trigger condition and then measures the following GPIO pulse.
Definition: PinFunctions.c:434
#define ADI_STREAM_STOP_CMD
Definition: StreamFunctions.h:64
#define ADI_WRITE_BYTE
Definition: main.h:338
#define ADI_I2C_READ_BYTES
Definition: main.h:254
#define ADI_GET_BOARD_TYPE
Definition: main.h:296
#define ADI_FROM_PC_ENDPOINT
Definition: main.h:391
CyU3PReturnStatus_t AdiSetDutSupply(DutVoltage SupplyMode)
This function configures the DUT supply voltage.
Definition: HelperFunctions.c:94
PartTye
Definition: main.h:97
uint32_t WatchDogTicks
Definition: main.h:183
#define UNUSED(x)
Definition: main.h:447
FX3PinMap PinMap
Definition: main.h:192
@ ADcmXL1021
Definition: main.h:99
#define ADI_USER_LED_PIN
Definition: PinFunctions.h:100
#define ADI_RT_STREAM_START
Definition: AppThread.h:42
uint16_t ADI_PIN_RESET
Definition: main.h:119
#define ADI_I2C_WRITE_BYTES
Definition: main.h:257
CyU3PI2cPreamble_t I2CStreamPreamble
Definition: main.h:242
FX3BoardType
Definition: main.h:65
#define ADI_PULSE_WAIT
Definition: main.h:314
void AdiGPIOEventHandler(uint8_t gpioId)
This function handles GPIO interrupts and sets the appropriate flag in GpioHandler.
Definition: main.c:755
#define ADI_GENERIC_STREAM_DONE
Definition: AppThread.h:60
@ iSensorFX3Board_E
Definition: main.h:82
CyU3PSpiConfig_t SpiConfig
Definition: main.h:150
#define ADI_BUSY_MEASURE
Definition: main.h:356
#define ADI_READ_SPI_CONFIG
Definition: main.h:275
uint32_t WatchDogPeriodMs
Definition: main.h:180
uint16_t ADI_PIN_DIO4
Definition: main.h:131
#define ADI_READ_PIN
Definition: main.h:305
@ ADcmXL3021
Definition: main.h:105
int main(void)
This is the main entry point function for the iSensor FX3 application firmware.
Definition: main.c:133
uint16_t DrPin
Definition: main.h:168
void AdiBulkEndpointHandler(CyU3PUsbEpEvtType evType, CyU3PUSBSpeed_t usbSpeed, uint8_t epNum)
This function handles events generated by the bulk endpoint.
Definition: main.c:681
CyU3PDmaChannel MemoryToSPI
Definition: main.c:79
uint16_t UsbBufferSize
Definition: main.h:156
#define STREAMTHREAD_PRIORITY
Definition: StreamThread.h:32
#define APPTHREAD_STACK
Definition: AppThread.h:29
CyU3PThread AppThread
Definition: main.c:57
CyU3PReturnStatus_t AdiConfigurePWM(CyBool_t EnablePWM)
This function configures the FX3 PWM outputs (enable or disable).
Definition: PinFunctions.c:669
#define ADI_PULSE_DRIVE
Definition: main.h:311
@ IMU
Definition: main.h:108
void AdiUSBEventHandler(CyU3PUsbEventType_t evtype, uint16_t evdata)
This is a callback function to handle generic USB events.
Definition: main.c:698
BoardState FX3State
Definition: main.c:112
#define ADI_STREAM_BURST_DATA
Definition: main.h:302
Header file for all the pin I/O and timing related functions.
CyU3PDmaChannel ChannelToPC
Definition: main.c:76
Main header file for the Analog Devices iSensor FX3 Demonstration Platform firmware.
#define ADI_I2C_STREAM_STOP
Definition: AppThread.h:93
#define ADI_RT_STREAM_DONE
Definition: AppThread.h:48
@ iSensorFX3Board_A
Definition: main.h:70
void AdiAppErrorHandler(CyU3PReturnStatus_t status)
This function handles critical errors generated by the ADI application.
Definition: main.c:801
uint32_t TransferByteLength
Definition: main.h:221
StreamState StreamThreadState
Definition: main.c:122
#define ADI_RESET_SPI
Definition: main.h:362
#define ADI_FIRMWARE_ID_CHECK
Definition: main.h:266
void WriteErrorLogCount(uint32_t count)
Sets the error log count value in flash.
Definition: ErrorLog.c:87
@ CypressFX3Board
Definition: main.h:67
#define ADI_GET_BUILD_DATE
Definition: main.h:290
#define ADI_GENERIC_STREAM_START
Definition: AppThread.h:54
CyBool_t PinExitEnable
Definition: main.h:209
CyU3PReturnStatus_t AdiTransferBytes(uint32_t writeData)
This function performs a protocol agnostic SPI bi-directional SPI transfer of (1, 2,...
Definition: SpiFunctions.c:671
CyBool_t AdiLPMRequestHandler(CyU3PUsbLinkPowerMode link_mode)
This is a callback function to handle Link Power Management (LPM) requests.
Definition: main.c:736
void AdiSendStatus(uint32_t status, uint16_t count, CyBool_t isControlEndpoint)
Sends status back to PC over control endpoint or manual bulk in endpoint.
Definition: HelperFunctions.c:191
struct FX3PinMap FX3PinMap
Pin map for translating FX3 GPIO pins to iSensor eval board functional pins.
#define ADI_SET_PIN
Definition: main.h:317
#define ADI_TIMER_PIN_INDEX
Definition: main.h:381
FX3BoardType AdiGetFX3BoardType()
This function determines the type of the connected FX3 board.
Definition: main.c:1322
#define ADI_SET_SPI_CONFIG
Definition: main.h:272
#define APPTHREAD_PRIORITY
Definition: AppThread.h:32
CyU3PReturnStatus_t AdiI2CReadHandler(uint16_t RequestLength)
Handler for I2C read command from control endpoint.
Definition: I2cFunctions.c:38
#define ADI_BURST_STREAM_START
Definition: AppThread.h:66
CyU3PReturnStatus_t AdiMeasurePinDelay(uint16_t transferLength)
Measures the delay from a trigger pin edge (sync) to a busy pin edge.
Definition: PinFunctions.c:271
CyU3PReturnStatus_t AdiWriteRegByte(uint16_t addr, uint8_t data)
This function writes a single byte of data over the SPI bus.
Definition: SpiFunctions.c:763
#define ADI_SET_BOOT_TIME
Definition: main.h:293
#define ADI_READ_TIMER_VALUE
Definition: main.h:308
void AdiFlashDeInit()
De-init the flash memory interfacing module.
Definition: Flash.c:128
#define ADI_DIO1_INTERRUPT_FLAG
Definition: PinFunctions.h:110
CyU3PReturnStatus_t AdiSetPin(uint16_t pinNumber, CyBool_t polarity)
This function configures the specified pin as an output and drives it with the desired value.
Definition: PinFunctions.c:1043
#define ADI_CLEAR_FLASH_LOG
Definition: main.h:341
Header file for the streaming thread.
volatile CyBool_t KillStreamEarly
Definition: main.c:119
@ HighZ
Definition: PinFunctions.h:49
Header file for all the primary application thread functions.
CyBool_t PinStartEnable
Definition: main.h:212
uint16_t I2CRetryCount
Definition: main.h:198
CyU3PEvent EventHandler
Definition: main.c:60
uint16_t FX3_PIN_GPIO2
Definition: main.h:137
CyU3PReturnStatus_t AdiI2CInit(uint32_t BitRate, CyBool_t isDMA)
Init I2C peripheral.
Definition: I2cFunctions.c:130
Header file for all SPI related functions.
uint32_t NumRealTimeCaptures
Definition: main.h:215
CyU3PReturnStatus_t AdiRestartSpi()
This function restarts the SPI controller.
Definition: SpiFunctions.c:188
@ iSensorFX3Board_F
Definition: main.h:85
void AdiLogError(FileIdentifier File, uint32_t Line, uint32_t ErrorCode)
Logs a firmware error to flash memory for later examination.
Definition: ErrorLog.c:51
CyBool_t AdiControlEndpointHandler(uint32_t setupdat0, uint32_t setupdat1)
This function handles events generated by the control endpoint. All vendor requests are handled in th...
Definition: main.c:215
uint16_t BytesPerUsbPacket
Definition: main.h:239
struct StreamState StreamState
Struct to store the current data stream state information.
CyU3PDmaChannel StreamingChannel
Definition: main.c:70
uint16_t RoundedByteTransferLength
Definition: main.h:224
#define ADI_ID_PIN_0
Definition: PinFunctions.h:82