precision-converters-firmware
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
app_config.h
Go to the documentation of this file.
1/*************************************************************************/
13#ifndef _APP_CONFIG_H_
14#define _APP_CONFIG_H_
15
16/******************************************************************************/
17/***************************** Include Files **********************************/
18/******************************************************************************/
19
20#include <stdint.h>
21#include "ad4170.h"
22
23/******************************************************************************/
24/********************** Macros and Constants Definition ***********************/
25/******************************************************************************/
26
27/* Macros for stringification */
28#define XSTR(s) #s
29#define STR(s) XSTR(s)
30
31/* List of supported platforms */
32#define MBED_PLATFORM 1
33#define STM32_PLATFORM 2
34
35/* List of demo mode configurations */
36#define USER_DEFAULT_CONFIG 0
37#define RTD_2WIRE_CONFIG 1
38#define RTD_3WIRE_CONFIG 2
39#define RTD_4WIRE_CONFIG 3
40#define THERMISTOR_CONFIG 4
41#define THERMOCOUPLE_CONFIG 5
42#define ACCELEROMETER_CONFIG 6
43#define LOADCELL_CONFIG 7
44
45/* List of data capture modes for AD4170 device */
46#define CONTINUOUS_DATA_CAPTURE 0
47#define BURST_DATA_CAPTURE 1
48
49/* List of supported interface modes for data capturing */
50#define TDM_MODE 0
51#define SPI_INTERRUPT_MODE 1
52#define SPI_DMA_MODE 2
53
54/* List of supported IIO clients
55 * Note: Local client is supported only for Mbed platform
56 * for now
57 * */
58#define IIO_CLIENT_REMOTE 0 // Remote (PC) IIO client
59#define IIO_CLIENT_LOCAL 1 // Local (display) IIO client
60
61// **** Note for User: ACTIVE_DEVICE selection ****//
62/* Define the device type from the list of below device type defines (one at a time)
63 * e.g. #define DEV_AD4170 -> This will make AD4170 as an ACTIVE_DEVICE.
64 * The ACTIVE_DEVICE is default set to AD4170 if device type is not defined.
65 * */
66//#define DEV_AD4170
67
68#if defined(DEV_AD4170)
69#define ACTIVE_DEVICE_NAME "ad4170"
70#define DEVICE_NAME "DEV_AD4170"
71#define ACTIVE_DEVICE_ID ID_AD4170
72#define HW_MEZZANINE_NAME "EVAL-AD4170-4ARDZ"
73#elif defined (DEV_AD4190)
74#define ACTIVE_DEVICE_NAME "ad4190"
75#define DEVICE_NAME "DEV_AD4190"
76#define ACTIVE_DEVICE_ID ID_AD4190
77#define HW_MEZZANINE_NAME "EVAL-AD4190-4ARDZ"
78#else
79#warning No/Unsupported ADxxxxy symbol defined. AD4170 defined
80#define DEV_AD4170
81#define ACTIVE_DEVICE_NAME "ad4170"
82#define DEVICE_NAME "DEV_AD4170"
83#define ACTIVE_DEVICE_ID ID_AD4170
84#define HW_MEZZANINE_NAME "EVAL-AD4170-4ARDZ"
85#endif
86
87/* Note: The below macro and the type of digital filter chosen together
88 * decides the output data rate to be configured for the device.
89 * Filter configuration can be modified by changing the macro "AD4170_FILTER_CONFIG"
90 * in the respective user configuration header file.
91 * Please refer to the datasheet for more details on the other filter configurations.
92 * It has to be noted that this is not the maximum ODR permissible by the device, but
93 * a value specific to the NUCLEO-H563ZI/SDP-K1 platform tested with a 10MHz SPI clock. The maximum
94 * ODR might vary across platforms and data continuity is not guaranteed above this ODR
95 * on the IIO Client*/
96
97/* Value corresponding to 24KSPS ODR (per channel) with Sinc5 average filter */
98#define FS_SINC5_AVG_24_KSPS 20
99
100/* Value corresponding to 512ksps ODR (per channel) with Sinc5 filter */
101#define FS_SINC5_512_KSPS 1
102
103/* Value corresponding to 62.5 ODR (per channel) with Sinc3 filter */
104#define FS_SINC3_62P5_KSPS 4
105
106/* Select the active platform (default is Mbed) */
107#if !defined(ACTIVE_PLATFORM)
108#define ACTIVE_PLATFORM MBED_PLATFORM
109#endif
110
111/* Select active IIO client */
112#if !defined(ACTIVE_IIO_CLIENT)
113#define ACTIVE_IIO_CLIENT IIO_CLIENT_REMOTE
114#endif
115
116/* Note: The STM32 platform supports SPI interrupt and TDM DMA data capturing
117 * using the Nucleo-H563ZI and SPI DMA Mode using the SDP-K1
118 * while the MBED platform supports only SPI interrupt Mode */
119#if !defined(INTERFACE_MODE)
120#if (ACTIVE_PLATFORM == STM32_PLATFORM)
121/* Note: SDP-K1 supports only SPI DMA Mode in stm32 platform*/
122#if defined (TARGET_SDP_K1)
123#define INTERFACE_MODE SPI_DMA_MODE
124#else // Nucleo H563
125#define INTERFACE_MODE TDM_MODE
126#endif
127#else // Mbed
128#define INTERFACE_MODE SPI_INTERRUPT_MODE
129#endif
130#endif
131
132/* Select the demo mode configuration (default is user config) */
133#if !defined(ACTIVE_DEMO_MODE_CONFIG)
134#define ACTIVE_DEMO_MODE_CONFIG USER_DEFAULT_CONFIG
135#endif
136
137/* Select the ADC data capture mode (default is CC mode) */
138#if !defined(DATA_CAPTURE_MODE)
139#define DATA_CAPTURE_MODE CONTINUOUS_DATA_CAPTURE
140#endif
141
142/* Enable the UART/VirtualCOM port connection (default VCOM) */
143//#define USE_PHY_COM_PORT // Uncomment to select UART
144
145#if !defined(USE_PHY_COM_PORT)
146#define USE_VIRTUAL_COM_PORT
147#endif
148
149#if (ACTIVE_PLATFORM == MBED_PLATFORM)
150#include "app_config_mbed.h"
151#define HW_CARRIER_NAME TARGET_NAME
152/* Redefine the init params structure mapping w.r.t. platform */
153#define ticker_int_extra_init_params mbed_ticker_int_extra_init_params
154#define vcom_extra_init_params mbed_vcom_extra_init_params
155#define vcom_ops mbed_virtual_com_ops
156#define uart_extra_init_params mbed_uart_extra_init_params
157#define uart_ops mbed_uart_ops
158#define spi_extra_init_params mbed_spi_extra_init_params
159#define i2c_extra_init_params mbed_i2c_extra_init_params
160#define trigger_gpio_irq_extra_params mbed_trigger_gpio_irq_init_params
161#define gpio_dig_aux1_extra_init_params mbed_dig_aux1_gpio_extra_init_params
162#define gpio_dig_aux2_extra_init_params mbed_dig_aux2_gpio_extra_init_params
163#define gpio_sync_inb_extra_init_params mbed_sync_inb_gpio_extra_init_params
164#define trigger_gpio_extra_init_params mbed_trigger_gpio_extra_init_params
165#define trigger_gpio_ops mbed_gpio_ops
166#define irq_ops mbed_gpio_irq_ops
167#define ticker_irq_ops mbed_irq_ops
168#define gpio_ops mbed_gpio_ops
169#define spi_ops mbed_spi_ops
170#define i2c_ops mbed_i2c_ops
171#define trigger_gpio_irq_ops mbed_gpio_irq_ops
172#define trigger_gpio_handle 0 // Unused macro
173#define TRIGGER_GPIO_PORT 0 // Unused macro
174#define TRIGGER_GPIO_PIN DIG_AUX_1
175#define TRIGGER_INT_ID GPIO_IRQ_ID1
176#define TICKER_ID TICKER_INT_ID
177#define SPI_DEVICE_ID 0 // unused
178#define I2C_DEVICE_ID 0 // Unused
179#define TRIGGER_GPIO_IRQ_CTRL_ID 0 // Unused
180#elif (ACTIVE_PLATFORM == STM32_PLATFORM)
181#include "app_config_stm32.h"
182
183#define spi_extra_init_params stm32_spi_extra_init_params
184#define uart_extra_init_params stm32_uart_extra_init_params
185#define trigger_gpio_extra_init_params stm32_trigger_gpio_extra_init_params
186#define trigger_gpio_irq_extra_params stm32_trigger_gpio_irq_init_params
187#define gpio_dig_aux1_extra_init_params stm32_dig_aux1_gpio_extra_init_params
188#define gpio_dig_aux2_extra_init_params stm32_dig_aux2_gpio_extra_init_params
189#define gpio_sync_inb_extra_init_params stm32_sync_inb_gpio_extra_init_params
190#define csb_gpio_extra_init_params stm32_csb_gpio_extra_init_params
191#define ticker_int_extra_init_params stm32_ticket_int_init_params
192#define tdm_extra_init_params stm32_tdm_extra_init_params
193#define i2c_extra_init_params stm32_i2c_extra_init_params
194#if (INTERFACE_MODE == SPI_DMA_MODE)
195#define tx_trigger_extra_init_params stm32_tx_trigger_extra_init_params
196#endif
197#if defined (TARGET_SDP_K1)
198#define vcom_extra_init_params stm32_vcom_extra_init_params
199#endif
200
201#define spi_ops stm32_spi_ops
202#define uart_ops stm32_uart_ops
203#define gpio_ops stm32_gpio_ops
204#define i2c_ops stm32_i2c_ops
205#define irq_ops stm32_gpio_irq_ops
206#define tdm_ops stm32_tdm_platform_ops
207#define trigger_gpio_irq_ops stm32_gpio_irq_ops
208#if (INTERFACE_MODE == SPI_DMA_MODE)
209#define dma_ops stm32_dma_ops
210#define pwm_ops stm32_pwm_ops
211#endif
212#if defined (TARGET_SDP_K1)
213#define vcom_ops stm32_usb_uart_ops
214#endif
215
216#define TRIGGER_GPIO_PORT DIG_AUX_1_PORT
217#define TRIGGER_GPIO_PIN DIG_AUX_1
218#define TRIGGER_GPIO_IRQ_CTRL_ID TRIGGER_GPIO_PIN
219#define CSB_GPIO_PORT STM32_SPI_CS_PORT
220
221#define SPI_DEVICE_ID STM32_SPI_ID
222#define I2C_DEVICE_ID STM32_I2C_ID
223#define TRIGGER_INT_ID 0 // unused
224#define trigger_gpio_handle 0 // unused
225#define DMA_IRQ_ID GPDMA1_Channel7_IRQn
226#else
227#error "No/Invalid active platform selected"
228#endif
229
230/* List the differential/single-ended channels based on active device.
231 * Note : There can be max 16 channels in the device sequencer but since
232 * input pairs can be only 3/6/4/8/16, only those many channels are exposed
233 * out, based on the user selected channel configuration.
234 **/
235#if defined(DEV_AD4170)
236#define DIFFERENTIAL_CHNS 4
237#define SINGLE_ENDED_CHNS 8
238#elif defined (DEV_AD4190)
239#define DIFFERENTIAL_CHNS 4
240#define SINGLE_ENDED_CHNS 8
241#endif
242
243/* Include user config files and params according to active/selected demo mode config */
244#if (ACTIVE_DEMO_MODE_CONFIG == USER_DEFAULT_CONFIG)
245#include "ad4170_user_config.h"
246#define ad4170_init_params ad4170_user_config_params
247#elif ((ACTIVE_DEMO_MODE_CONFIG == RTD_2WIRE_CONFIG) || \
248(ACTIVE_DEMO_MODE_CONFIG == RTD_3WIRE_CONFIG) || (ACTIVE_DEMO_MODE_CONFIG == RTD_4WIRE_CONFIG))
249#include "ad4170_rtd_config.h"
250#define ad4170_init_params ad4170_rtd_config_params
251#elif (ACTIVE_DEMO_MODE_CONFIG == THERMISTOR_CONFIG)
253#define ad4170_init_params ad4170_thermistor_config_params
254#elif (ACTIVE_DEMO_MODE_CONFIG == THERMOCOUPLE_CONFIG)
256#define ad4170_init_params ad4170_thermocouple_config_params
257#elif (ACTIVE_DEMO_MODE_CONFIG == ACCELEROMETER_CONFIG)
259#define ad4170_init_params ad4170_accelerometer_config_params
260#elif (ACTIVE_DEMO_MODE_CONFIG == LOADCELL_CONFIG)
262#define ad4170_init_params ad4170_loadcell_config_params
263#else
264#include "ad4170_user_config.h"
265#define ad4170_init_params ad4170_user_config_params
266#warning "No/Invalid active demo config selected, user config used as default"
267#endif
268
269/* ADC resolution for active device */
270#define ADC_RESOLUTION 24
271
272/* Bytes per sample */
273#define BYTES_PER_SAMPLE sizeof(uint32_t) // For ADC resolution of 24-bits
274
275/* ADC max count (full scale value) for unipolar inputs */
276#define ADC_MAX_COUNT_UNIPOLAR (uint32_t)((1 << ADC_RESOLUTION) - 1)
277
278/* ADC max count (full scale value) for bipolar inputs */
279#define ADC_MAX_COUNT_BIPOLAR (uint32_t)(1 << (ADC_RESOLUTION-1))
280
281/* Default ADC reference voltages for each reference source */
282#define AD4170_REFIN_REFIN1_VOLTAGE 2.5
283#define AD4170_REFIN_REFIN2_VOLTAGE 2.5
284#define AD4170_REFIN_AVDD_VOLTAGE 5.0
285#define AD4170_REFIN_REFOUT_VOLTAGE 2.5
286
287/****** Macros used to form a VCOM serial number ******/
288#define FIRMWARE_NAME "ad4170_iio"
289
290#if !defined(PLATFORM_NAME)
291#define PLATFORM_NAME HW_CARRIER_NAME
292#endif
293
294/* Below USB configurations (VID and PID) are owned and assigned by ADI.
295 * If intended to distribute software further, use the VID and PID owned by your
296 * organization */
297#define VIRTUAL_COM_PORT_VID 0x0456
298#define VIRTUAL_COM_PORT_PID 0xb66c
299/* Serial number string is formed as: application name + device (target) name + platform (host) name */
300#define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" DEVICE_NAME "_" STR(PLATFORM_NAME))
301
302/* Baud rate for IIO application UART interface */
303#define IIO_UART_BAUD_RATE (230400)
304
305/* Enable/Disable the use of SDRAM for ADC data capture buffer */
306//#define USE_SDRAM // Uncomment to use SDRAM for data buffer
307
308/* Calculations for sampling frequency (used to define timeout in IIO client):
309 * Note: Below calculations are based on default user configurations set in the
310 * ad4170_xyz_config.h files. These configurations are used for data capturing.
311 * Clock: Internal 16Mhz oscillotor
312 * Filter Type: Selected in user config files
313 * Filter FS: Selected in user config files
314 * Filter ODR Average (as defined in datasheet): Selected in user config files
315 **/
316/* AD4170 default internal clock frequency (Fclock = 16Mhz)*/
317#define AD4170_INTERNAL_CLOCK (16000000U)
318
319/* Default sampling frequency for AD4170 (in SPS) */
320#define AD4170_DEFLT_SAMPLING_FREQUENCY (AD4170_INTERNAL_CLOCK / FS_TO_ODR_CONV_SCALER)
321
322/* Scale value for Filters - SINC5, SINC5_AVG and SINC3 */
323#define FILTER_SCALE 32
324
325/******************************************************************************/
326/************************ Public Declarations *********************************/
327/******************************************************************************/
328
329extern struct no_os_gpio_init_param gpio_init_ldac_n;
330extern struct no_os_gpio_init_param gpio_init_rdy;
331extern struct no_os_gpio_init_param gpio_init_sync_inb;
332extern struct no_os_gpio_desc *led_gpio_desc;
333extern struct no_os_uart_desc *uart_desc;
334extern struct no_os_gpio_desc *trigger_gpio_desc;
335extern struct no_os_gpio_desc *csb_gpio_desc;
336extern struct no_os_spi_init_param spi_init_params;
337extern struct no_os_irq_ctrl_desc *trigger_irq_desc;
338extern struct no_os_tdm_desc *ad4170_tdm_desc;
339extern struct no_os_eeprom_desc *eeprom_desc;
340extern struct no_os_pwm_desc *tx_trigger_desc;
341int32_t init_system(void);
342void ticker_callback(void *ctx);
343
344#endif //_APP_CONFIG_H_
struct no_os_irq_ctrl_desc * trigger_irq_desc
Definition app_config.c:103
int32_t init_system(void)
Initialize the system peripherals.
Definition app_config.c:185
struct no_os_uart_desc * uart_desc
Definition app_config.c:97
struct no_os_eeprom_desc * eeprom_desc
Definition app_config.c:176
struct no_os_pwm_desc * tx_trigger_desc
Definition app_config.c:149
struct no_os_spi_init_param spi_init_params
Definition ad3530r_user_config.c:48
struct no_os_gpio_desc * trigger_gpio_desc
Definition app_config.c:170
struct no_os_gpio_desc * csb_gpio_desc
Definition app_config.c:179
Header for AD4170 Accelerometer configurations module.
struct no_os_gpio_init_param gpio_init_rdy
Definition app_config.c:69
struct no_os_gpio_desc * led_gpio_desc
Definition app_config.c:214
void ticker_callback(void *ctx)
This is an ISR (Interrupt Service Routine) for Ticker object.
Definition ad4170_iio.c:2859
struct no_os_tdm_desc * ad4170_tdm_desc
Definition app_config.c:132
struct no_os_gpio_init_param gpio_init_ldac_n
Definition app_config.c:61
struct no_os_gpio_init_param gpio_init_sync_inb
Definition app_config.c:77
Header for AD4170 Loadcell configurations module.
Header for AD4170 RTD configurations module.
Header for AD4170 thermistor configurations module.
Header for AD4170 default user configurations file.
Header file for Mbed platform configurations.