IIO firmware for the AD4110

Dependencies:   tempsensors sdp_k1_sdram

Committer:
Janani Sunil
Date:
Mon Aug 01 11:09:48 2022 +0530
Revision:
1:a78dbaa4b05d
Parent:
0:6ca37a8f8ba9
Initial implementation of AD4110 IIO Firmware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Janani Sunil 0:6ca37a8f8ba9 1 /*************************************************************************//**
Janani Sunil 0:6ca37a8f8ba9 2 * @file app_config.h
Janani Sunil 0:6ca37a8f8ba9 3 * @brief Configuration file for AD4110_1 IIO firmware application
Janani Sunil 0:6ca37a8f8ba9 4 ******************************************************************************
Janani Sunil 0:6ca37a8f8ba9 5 * Copyright (c) 2022 Analog Devices, Inc.
Janani Sunil 0:6ca37a8f8ba9 6 *
Janani Sunil 0:6ca37a8f8ba9 7 * All rights reserved.
Janani Sunil 0:6ca37a8f8ba9 8 *
Janani Sunil 0:6ca37a8f8ba9 9 * This software is proprietary to Analog Devices, Inc. and its licensors.
Janani Sunil 0:6ca37a8f8ba9 10 * By using this software you agree to the terms of the associated
Janani Sunil 0:6ca37a8f8ba9 11 * Analog Devices Software License Agreement.
Janani Sunil 0:6ca37a8f8ba9 12 *****************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 13
Janani Sunil 0:6ca37a8f8ba9 14 #ifndef APP_CONFIG_H
Janani Sunil 0:6ca37a8f8ba9 15 #define APP_CONFIG_H
Janani Sunil 0:6ca37a8f8ba9 16
Janani Sunil 0:6ca37a8f8ba9 17 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 18 /***************************** Include Files **********************************/
Janani Sunil 0:6ca37a8f8ba9 19 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 20
Janani Sunil 0:6ca37a8f8ba9 21 #include <stdint.h>
Janani Sunil 0:6ca37a8f8ba9 22 #include "no_os_gpio.h"
Janani Sunil 0:6ca37a8f8ba9 23
Janani Sunil 0:6ca37a8f8ba9 24 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 25 /********************** Macros and Constants Definition ***********************/
Janani Sunil 0:6ca37a8f8ba9 26 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 27
Janani Sunil 0:6ca37a8f8ba9 28 /* List of supported platforms*/
Janani Sunil 0:6ca37a8f8ba9 29 #define MBED_PLATFORM 1
Janani Sunil 0:6ca37a8f8ba9 30
Janani Sunil 0:6ca37a8f8ba9 31 /* List of demo mode configurations */
Janani Sunil 0:6ca37a8f8ba9 32 #define VOLTAGE_MODE_CONFIG 1
Janani Sunil 0:6ca37a8f8ba9 33 #define CURRENT_MODE_CONFIG 2
Janani Sunil 0:6ca37a8f8ba9 34 #define FIELD_POWER_SUPPLY_CONFIG 3
Janani Sunil 0:6ca37a8f8ba9 35 #define THERMOCOUPLE_CONFIG 4
Janani Sunil 0:6ca37a8f8ba9 36 #define RTD_CONFIG 5
Janani Sunil 0:6ca37a8f8ba9 37
Janani Sunil 0:6ca37a8f8ba9 38 #define ACTIVE_DEVICE "ad4110"
Janani Sunil 0:6ca37a8f8ba9 39
Janani Sunil 0:6ca37a8f8ba9 40 /* Select the active platform */
Janani Sunil 0:6ca37a8f8ba9 41 #if !defined(ACTIVE_PLATFORM)
Janani Sunil 0:6ca37a8f8ba9 42 #define ACTIVE_PLATFORM MBED_PLATFORM
Janani Sunil 0:6ca37a8f8ba9 43 #endif
Janani Sunil 0:6ca37a8f8ba9 44
Janani Sunil 0:6ca37a8f8ba9 45 /* Select the demo mode configuration default is RTD mode */
Janani Sunil 0:6ca37a8f8ba9 46 #if !defined(ACTIVE_DEMO_MODE_CONFIG)
Janani Sunil 0:6ca37a8f8ba9 47 #define ACTIVE_DEMO_MODE_CONFIG RTD_CONFIG
Janani Sunil 0:6ca37a8f8ba9 48 #endif
Janani Sunil 0:6ca37a8f8ba9 49
Janani Sunil 0:6ca37a8f8ba9 50 /* List of data capture modes for AD717x device */
Janani Sunil 0:6ca37a8f8ba9 51 #define CONTINUOUS_DATA_CAPTURE 0
Janani Sunil 0:6ca37a8f8ba9 52 #define BURST_DATA_CAPTURE 1
Janani Sunil 0:6ca37a8f8ba9 53
Janani Sunil 0:6ca37a8f8ba9 54 /* Macros for stringification */
Janani Sunil 0:6ca37a8f8ba9 55 #define XSTR(s) #s
Janani Sunil 0:6ca37a8f8ba9 56 #define STR(s) XSTR(s)
Janani Sunil 0:6ca37a8f8ba9 57
Janani Sunil 0:6ca37a8f8ba9 58 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
Janani Sunil 0:6ca37a8f8ba9 59 #include "app_config_mbed.h"
Janani Sunil 0:6ca37a8f8ba9 60
Janani Sunil 0:6ca37a8f8ba9 61 /* Redefine the init params structure mapping w.r.t. platform */
Janani Sunil 0:6ca37a8f8ba9 62 #define uart_extra_init_params mbed_uart_extra_init_params
Janani Sunil 0:6ca37a8f8ba9 63 #define spi_extra_init_params mbed_spi_extra_init_params
Janani Sunil 0:6ca37a8f8ba9 64 #define ext_int_extra_init_params mbed_ext_int_extra_init_params
Janani Sunil 0:6ca37a8f8ba9 65 #define IRQ_INT_ID EXTERNAL_INT_ID1
Janani Sunil 0:6ca37a8f8ba9 66 #define csb_platform_ops mbed_gpio_ops
Janani Sunil 0:6ca37a8f8ba9 67 #define irq_platform_ops mbed_irq_ops
Janani Sunil 0:6ca37a8f8ba9 68 #define spi_platform_ops mbed_spi_ops
Janani Sunil 0:6ca37a8f8ba9 69 #define HW_CARRIER_NAME STR(TARGET_NAME)
Janani Sunil 0:6ca37a8f8ba9 70 #else
Janani Sunil 0:6ca37a8f8ba9 71 #error "No/Invalid active platform selected"
Janani Sunil 0:6ca37a8f8ba9 72 #endif
Janani Sunil 0:6ca37a8f8ba9 73
Janani Sunil 0:6ca37a8f8ba9 74 #define HW_MEZZANINE_NAME "EVAL-AD4110-1SDZ"
Janani Sunil 0:6ca37a8f8ba9 75 #define HW_NAME ACTIVE_DEVICE
Janani Sunil 0:6ca37a8f8ba9 76
Janani Sunil 0:6ca37a8f8ba9 77 /* Baud rate for IIO application UART interface */
Janani Sunil 0:6ca37a8f8ba9 78 #define IIO_UART_BAUD_RATE 230400
Janani Sunil 0:6ca37a8f8ba9 79
Janani Sunil 0:6ca37a8f8ba9 80 /* Enable the UART/VirtualCOM port connection (default VCOM) */
Janani Sunil 0:6ca37a8f8ba9 81 //#define USE_PHY_COM_PORT // Uncomment to select UART
Janani Sunil 0:6ca37a8f8ba9 82
Janani Sunil 0:6ca37a8f8ba9 83 #if !defined(USE_PHY_COM_PORT)
Janani Sunil 0:6ca37a8f8ba9 84
Janani Sunil 0:6ca37a8f8ba9 85 /* VCOM Serial number definition */
Janani Sunil 0:6ca37a8f8ba9 86 #define FIRMWARE_NAME "ad4110-1_iio-application"
Janani Sunil 0:6ca37a8f8ba9 87
Janani Sunil 0:6ca37a8f8ba9 88 #if !defined(PLATFORM_NAME)
Janani Sunil 0:6ca37a8f8ba9 89 #define PLATFORM_NAME "SDP_K1"
Janani Sunil 0:6ca37a8f8ba9 90 #endif
Janani Sunil 0:6ca37a8f8ba9 91
Janani Sunil 0:6ca37a8f8ba9 92 #if !defined(EVB_INTERFACE)
Janani Sunil 0:6ca37a8f8ba9 93 #define EVB_INTERFACE "ARDUINO"
Janani Sunil 0:6ca37a8f8ba9 94 #endif
Janani Sunil 0:6ca37a8f8ba9 95
Janani Sunil 0:6ca37a8f8ba9 96 /* Below USB configurations (VID and PID) are owned and assigned by ADI.
Janani Sunil 0:6ca37a8f8ba9 97 * If intended to distribute software further, use the VID and PID owned by your
Janani Sunil 0:6ca37a8f8ba9 98 * organization */
Janani Sunil 0:6ca37a8f8ba9 99 #define VIRTUAL_COM_PORT_VID 0x0456
Janani Sunil 0:6ca37a8f8ba9 100 #define VIRTUAL_COM_PORT_PID 0xb66c
Janani Sunil 0:6ca37a8f8ba9 101
Janani Sunil 0:6ca37a8f8ba9 102 #define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" PLATFORM_NAME "_" EVB_INTERFACE)
Janani Sunil 0:6ca37a8f8ba9 103 #endif // !defined(USE_PHY_COM_PORT)
Janani Sunil 0:6ca37a8f8ba9 104
Janani Sunil 0:6ca37a8f8ba9 105 /* Select the ADC data capture mode (default is CC mode) */
Janani Sunil 0:6ca37a8f8ba9 106 #if !defined(DATA_CAPTURE_MODE)
Janani Sunil 0:6ca37a8f8ba9 107 #define DATA_CAPTURE_MODE BURST_DATA_CAPTURE
Janani Sunil 0:6ca37a8f8ba9 108 #endif
Janani Sunil 0:6ca37a8f8ba9 109
Janani Sunil 0:6ca37a8f8ba9 110 /* The below macro defines the register set to be accessed during the debug
Janani Sunil 0:6ca37a8f8ba9 111 * register read/write via IIO Client. Assign the below macro to AD4110_AFE
Janani Sunil 0:6ca37a8f8ba9 112 * for AFE register read/write */
Janani Sunil 0:6ca37a8f8ba9 113 #define REGISTER_READ_SEL A4110_ADC
Janani Sunil 0:6ca37a8f8ba9 114
Janani Sunil 0:6ca37a8f8ba9 115 /* Enable/Disable the use of SDRAM for ADC data capture buffer */
Janani Sunil 0:6ca37a8f8ba9 116 //#define USE_SDRAM_CAPTURE_BUFFER // Uncomment to use SDRAM as data buffer
Janani Sunil 0:6ca37a8f8ba9 117
Janani Sunil 0:6ca37a8f8ba9 118 /* AD4110 Sampling Rate of the device in SPS, excluding the fractional part.
Janani Sunil 0:6ca37a8f8ba9 119 * The following are the possible values of sampling frequencies (in SPS):
Janani Sunil 0:6ca37a8f8ba9 120 *
Janani Sunil 0:6ca37a8f8ba9 121 * 125000 , 62500, 31250, 25000, 15625, 10390, 4994, 2498,
Janani Sunil 0:6ca37a8f8ba9 122 * 1000, 500, 395, 200, 100, 59, 49, 20, 16, 10, 5. */
Janani Sunil 0:6ca37a8f8ba9 123
Janani Sunil 0:6ca37a8f8ba9 124 /* Sampling rate- The default sampling rate is 125000 SPS, which is the maximum
Janani Sunil 0:6ca37a8f8ba9 125 * output data rate. */
Janani Sunil 0:6ca37a8f8ba9 126 #define AD4110_SAMPLING_RATE 125000
Janani Sunil 0:6ca37a8f8ba9 127
Janani Sunil 0:6ca37a8f8ba9 128 /* Assign the ODR bitfield value depending on chosen sampling frequency */
Janani Sunil 0:6ca37a8f8ba9 129 #if (AD4110_SAMPLING_RATE == 125000)
Janani Sunil 0:6ca37a8f8ba9 130 #define AD4110_ODR_SEL 0
Janani Sunil 0:6ca37a8f8ba9 131 #elif (AD4110_SAMPLING_RATE == 62500)
Janani Sunil 0:6ca37a8f8ba9 132 #define Ad4110_ODR_SEL 2
Janani Sunil 0:6ca37a8f8ba9 133 #elif (AD4110_SAMPLING_RATE == 31250)
Janani Sunil 0:6ca37a8f8ba9 134 #define AD4110_ODR_SEL 4
Janani Sunil 0:6ca37a8f8ba9 135 #elif (AD4110_SAMPLING_RATE == 25000)
Janani Sunil 0:6ca37a8f8ba9 136 #define AD4110_ODR_SEL 5
Janani Sunil 0:6ca37a8f8ba9 137 #elif (AD4110_SAMPLING_RATE == 15625)
Janani Sunil 0:6ca37a8f8ba9 138 #define AD4110_ODR_SEL 6
Janani Sunil 0:6ca37a8f8ba9 139 #elif (AD4110_SAMPLING_RATE == 10390)
Janani Sunil 0:6ca37a8f8ba9 140 #define AD4110_ODR_SEL 7
Janani Sunil 0:6ca37a8f8ba9 141 #elif (AD4110_SAMPLING_RATE == 4994)
Janani Sunil 0:6ca37a8f8ba9 142 #define AD4110_ODR_SEL 8
Janani Sunil 0:6ca37a8f8ba9 143 #elif (AD4110_SAMPLING_RATE == 2498)
Janani Sunil 0:6ca37a8f8ba9 144 #define AD4110_ODR_SEL 9
Janani Sunil 0:6ca37a8f8ba9 145 #elif (AD4110_SAMPLING_RATE == 1000)
Janani Sunil 0:6ca37a8f8ba9 146 #define AD4110_ODR_SEL 10
Janani Sunil 0:6ca37a8f8ba9 147 #elif (AD4110_SAMPLING_RATE == 500)
Janani Sunil 0:6ca37a8f8ba9 148 #define AD4110_ODR_SEL 11
Janani Sunil 0:6ca37a8f8ba9 149 #elif (AD4110_SAMPLING_RATE == 395)
Janani Sunil 0:6ca37a8f8ba9 150 #define AD4110_ODR_SEL 12
Janani Sunil 0:6ca37a8f8ba9 151 #elif (AD4110_SAMPLING_RATE == 200)
Janani Sunil 0:6ca37a8f8ba9 152 #define AD4110_ODR_SEL 13
Janani Sunil 0:6ca37a8f8ba9 153 #elif (AD4110_SAMPLING_RATE == 100)
Janani Sunil 0:6ca37a8f8ba9 154 #define AD4110_ODR_SEL 14
Janani Sunil 0:6ca37a8f8ba9 155 #elif (AD4110_SAMPLING_RATE == 59)
Janani Sunil 0:6ca37a8f8ba9 156 #define AD4110_ODR_SEL 15
Janani Sunil 0:6ca37a8f8ba9 157 #elif (AD4110_SAMPLING_RATE == 49)
Janani Sunil 0:6ca37a8f8ba9 158 #define AD4110_ODR_SEL 16
Janani Sunil 0:6ca37a8f8ba9 159 #elif (AD4110_SAMPLING_RATE == 20)
Janani Sunil 0:6ca37a8f8ba9 160 #define AD4110_ODR_SEL 17
Janani Sunil 0:6ca37a8f8ba9 161 #elif (AD4110_SAMPLING_RATE == 16)
Janani Sunil 0:6ca37a8f8ba9 162 #define AD4110_ODR_SEL 18
Janani Sunil 0:6ca37a8f8ba9 163 #elif (AD4110_SAMPLING_RATE == 10)
Janani Sunil 0:6ca37a8f8ba9 164 #define AD4110_ODR_SEL 19
Janani Sunil 0:6ca37a8f8ba9 165 #elif (AD4110_SAMPLING_RATE == 5)
Janani Sunil 0:6ca37a8f8ba9 166 #define AD4110_ODR_SEL 20
Janani Sunil 0:6ca37a8f8ba9 167 #else
Janani Sunil 0:6ca37a8f8ba9 168 #warning "Invalid sampling frequency selection, using 125000 as default"
Janani Sunil 0:6ca37a8f8ba9 169 #define AD4110_SAMPLING_RATE 125000
Janani Sunil 0:6ca37a8f8ba9 170 #define AD4110_ODR_SEL 0
Janani Sunil 0:6ca37a8f8ba9 171 #endif
Janani Sunil 0:6ca37a8f8ba9 172
Janani Sunil 0:6ca37a8f8ba9 173 /* Include user config files and params according to active/selected demo mode config */
Janani Sunil 0:6ca37a8f8ba9 174 #if (ACTIVE_DEMO_MODE_CONFIG == VOLTAGE_MODE_CONFIG)
Janani Sunil 0:6ca37a8f8ba9 175 #include "ad4110_user_config.h"
Janani Sunil 0:6ca37a8f8ba9 176 #define ad4110_init_params ad4110_user_config_params
Janani Sunil 0:6ca37a8f8ba9 177 #elif (ACTIVE_DEMO_MODE_CONFIG == CURRENT_MODE_CONFIG)
Janani Sunil 0:6ca37a8f8ba9 178 #include "ad4110_current_mode_config.h"
Janani Sunil 0:6ca37a8f8ba9 179 #define ad4110_init_params ad4110_current_mode_init_params
Janani Sunil 0:6ca37a8f8ba9 180 #elif (ACTIVE_DEMO_MODE_CONFIG == FIELD_POWER_SUPPLY_CONFIG)
Janani Sunil 0:6ca37a8f8ba9 181 #include "ad4110_field_power_supply_config.h"
Janani Sunil 0:6ca37a8f8ba9 182 #define ad4110_init_params ad4110_field_power_supply_mode_init_params
Janani Sunil 0:6ca37a8f8ba9 183 #elif (ACTIVE_DEMO_MODE_CONFIG == THERMOCOUPLE_CONFIG)
Janani Sunil 0:6ca37a8f8ba9 184 #include "ad4110_thermocouple_mode_config.h"
Janani Sunil 0:6ca37a8f8ba9 185 #define ad4110_init_params ad4110_thermocouple_mode_init_params
Janani Sunil 0:6ca37a8f8ba9 186 #elif (ACTIVE_DEMO_MODE_CONFIG == RTD_CONFIG)
Janani Sunil 0:6ca37a8f8ba9 187 #include "ad4110_rtd_mode_config.h"
Janani Sunil 0:6ca37a8f8ba9 188 #define ad4110_init_params ad4110_rtd_mode_init_params
Janani Sunil 0:6ca37a8f8ba9 189 #endif
Janani Sunil 0:6ca37a8f8ba9 190
Janani Sunil 0:6ca37a8f8ba9 191 /* ADC Resolution */
Janani Sunil 0:6ca37a8f8ba9 192 #define AD4110_RESOLUTION 24
Janani Sunil 0:6ca37a8f8ba9 193
Janani Sunil 0:6ca37a8f8ba9 194 /* ADC internal reference voltage */
Janani Sunil 0:6ca37a8f8ba9 195 #define AD4110_REF_VOLTAGE 2.5
Janani Sunil 0:6ca37a8f8ba9 196
Janani Sunil 0:6ca37a8f8ba9 197 /* ADC number of channels */
Janani Sunil 0:6ca37a8f8ba9 198 #define AD4110_NUM_CHANNELS 4
Janani Sunil 0:6ca37a8f8ba9 199
Janani Sunil 0:6ca37a8f8ba9 200 /* ADC max count (full scale value) for unipolar inputs */
Janani Sunil 0:6ca37a8f8ba9 201 #define ADC_MAX_COUNT_UNIPOLAR (uint32_t)((1 << AD4110_RESOLUTION) - 1)
Janani Sunil 0:6ca37a8f8ba9 202
Janani Sunil 0:6ca37a8f8ba9 203 /* ADC max count (full scale value) for bipolar inputs */
Janani Sunil 0:6ca37a8f8ba9 204 #define ADC_MAX_COUNT_BIPOLAR (uint32_t)(1 << (AD4110_RESOLUTION-1))
Janani Sunil 0:6ca37a8f8ba9 205
Janani Sunil 0:6ca37a8f8ba9 206 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 207 /********************** Variables and User Defined Data Types *****************/
Janani Sunil 0:6ca37a8f8ba9 208 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 209
Janani Sunil 0:6ca37a8f8ba9 210 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 211 /************************ Public Declarations *********************************/
Janani Sunil 0:6ca37a8f8ba9 212 /******************************************************************************/
Janani Sunil 0:6ca37a8f8ba9 213
Janani Sunil 0:6ca37a8f8ba9 214 extern struct no_os_uart_desc *uart_desc;
Janani Sunil 0:6ca37a8f8ba9 215 extern no_os_gpio_desc *csb_gpio;
Janani Sunil 0:6ca37a8f8ba9 216 extern struct no_os_irq_ctrl_desc *external_int_desc;
Janani Sunil 0:6ca37a8f8ba9 217 int32_t init_system(void);
Janani Sunil 0:6ca37a8f8ba9 218
Janani Sunil 0:6ca37a8f8ba9 219 #endif // APP_CONFIG_H
Janani Sunil 0:6ca37a8f8ba9 220