precision-converters-firmware
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 #else
74 #warning No/Unsupported ADxxxxy symbol defined. AD4170 defined
75 #define DEV_AD4170
76 #define ACTIVE_DEVICE_NAME "ad4170"
77 #define DEVICE_NAME "DEV_AD4170"
78 #define ACTIVE_DEVICE_ID ID_AD4170
79 #define HW_MEZZANINE_NAME "EVAL-AD4170-4ARDZ"
80 #endif
81 
82 /* Select the active platform (default is Mbed) */
83 #if !defined(ACTIVE_PLATFORM)
84 #define ACTIVE_PLATFORM MBED_PLATFORM
85 #endif
86 
87 /* Select active IIO client */
88 #if !defined(ACTIVE_IIO_CLIENT)
89 #define ACTIVE_IIO_CLIENT IIO_CLIENT_REMOTE
90 #endif
91 
92 /* Note: The STM32 platform supports SPI interrupt and TDM DMA data capturing
93  * using the Nucleo-H563ZI and SPI DMA Mode using the SDP-K1
94  * while the MBED platform supports only SPI interrupt Mode */
95 #if !defined(INTERFACE_MODE)
96 #if (ACTIVE_PLATFORM == STM32_PLATFORM)
97 /* Note: SDP-K1 supports only SPI DMA Mode in stm32 platform*/
98 #if defined (TARGET_SDP_K1)
99 #define INTERFACE_MODE SPI_DMA_MODE
100 #else // Nucleo H563
101 #define INTERFACE_MODE TDM_MODE
102 #endif
103 #else // Mbed
104 #define INTERFACE_MODE SPI_INTERRUPT_MODE
105 #endif
106 #endif
107 
108 /* Select the demo mode configuration (default is user config) */
109 #if !defined(ACTIVE_DEMO_MODE_CONFIG)
110 #define ACTIVE_DEMO_MODE_CONFIG USER_DEFAULT_CONFIG
111 #endif
112 
113 /* Select the ADC data capture mode (default is CC mode) */
114 #if !defined(DATA_CAPTURE_MODE)
115 #define DATA_CAPTURE_MODE CONTINUOUS_DATA_CAPTURE
116 #endif
117 
118 /* Enable the UART/VirtualCOM port connection (default VCOM) */
119 //#define USE_PHY_COM_PORT // Uncomment to select UART
120 
121 #if !defined(USE_PHY_COM_PORT)
122 #define USE_VIRTUAL_COM_PORT
123 #endif
124 
125 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
126 #include "app_config_mbed.h"
127 #define HW_CARRIER_NAME TARGET_NAME
128 /* Redefine the init params structure mapping w.r.t. platform */
129 #define ticker_int_extra_init_params mbed_ticker_int_extra_init_params
130 #if defined(USE_VIRTUAL_COM_PORT)
131 #define uart_extra_init_params mbed_vcom_extra_init_params
132 #define uart_ops mbed_virtual_com_ops
133 #else
134 #define uart_extra_init_params mbed_uart_extra_init_params
135 #define uart_ops mbed_uart_ops
136 #endif
137 #define spi_extra_init_params mbed_spi_extra_init_params
138 #define i2c_extra_init_params mbed_i2c_extra_init_params
139 #define trigger_gpio_irq_extra_params mbed_trigger_gpio_irq_init_params
140 #define gpio_dig_aux1_extra_init_params mbed_dig_aux1_gpio_extra_init_params
141 #define gpio_dig_aux2_extra_init_params mbed_dig_aux2_gpio_extra_init_params
142 #define gpio_sync_inb_extra_init_params mbed_sync_inb_gpio_extra_init_params
143 #define trigger_gpio_extra_init_params mbed_trigger_gpio_extra_init_params
144 #define trigger_gpio_ops mbed_gpio_ops
145 #define irq_ops mbed_gpio_irq_ops
146 #define ticker_irq_ops mbed_irq_ops
147 #define gpio_ops mbed_gpio_ops
148 #define spi_ops mbed_spi_ops
149 #define i2c_ops mbed_i2c_ops
150 #define trigger_gpio_irq_ops mbed_gpio_irq_ops
151 #define trigger_gpio_handle 0 // Unused macro
152 #define TRIGGER_GPIO_PORT 0 // Unused macro
153 #define TRIGGER_GPIO_PIN DIG_AUX_1
154 #define TRIGGER_INT_ID GPIO_IRQ_ID1
155 #define TICKER_ID TICKER_INT_ID
156 #define SPI_DEVICE_ID 0 // unused
157 #define I2C_DEVICE_ID 0 // Unused
158 #define TRIGGER_GPIO_IRQ_CTRL_ID 0 // Unused
159 #elif (ACTIVE_PLATFORM == STM32_PLATFORM)
160 #include "app_config_stm32.h"
161 
162 #define spi_extra_init_params stm32_spi_extra_init_params
163 #define uart_extra_init_params stm32_uart_extra_init_params
164 #define trigger_gpio_extra_init_params stm32_trigger_gpio_extra_init_params
165 #define trigger_gpio_irq_extra_params stm32_trigger_gpio_irq_init_params
166 #define gpio_dig_aux1_extra_init_params stm32_dig_aux1_gpio_extra_init_params
167 #define gpio_dig_aux2_extra_init_params stm32_dig_aux2_gpio_extra_init_params
168 #define gpio_sync_inb_extra_init_params stm32_sync_inb_gpio_extra_init_params
169 #define csb_gpio_extra_init_params stm32_csb_gpio_extra_init_params
170 #define ticker_int_extra_init_params stm32_ticket_int_init_params
171 #define tdm_extra_init_params stm32_tdm_extra_init_params
172 #define i2c_extra_init_params stm32_i2c_extra_init_params
173 #if (INTERFACE_MODE == SPI_DMA_MODE)
174 #define tx_trigger_extra_init_params stm32_tx_trigger_extra_init_params
175 #endif
176 #if defined (TARGET_SDP_K1)
177 #define vcom_extra_init_params stm32_vcom_extra_init_params
178 #endif
179 
180 #define spi_ops stm32_spi_ops
181 #define uart_ops stm32_uart_ops
182 #define gpio_ops stm32_gpio_ops
183 #define i2c_ops stm32_i2c_ops
184 #define irq_ops stm32_gpio_irq_ops
185 #define tdm_ops stm32_tdm_platform_ops
186 #define trigger_gpio_irq_ops stm32_gpio_irq_ops
187 #if (INTERFACE_MODE == SPI_DMA_MODE)
188 #define dma_ops stm32_dma_ops
189 #define pwm_ops stm32_pwm_ops
190 #endif
191 #if defined (TARGET_SDP_K1)
192 #define vcom_ops stm32_usb_uart_ops
193 #endif
194 
195 #define TRIGGER_GPIO_PORT DIG_AUX_1_PORT
196 #define TRIGGER_GPIO_PIN DIG_AUX_1
197 #define TRIGGER_GPIO_IRQ_CTRL_ID TRIGGER_GPIO_PIN
198 #define CSB_GPIO_PORT STM32_SPI_CS_PORT
199 
200 #define SPI_DEVICE_ID STM32_SPI_ID
201 #define I2C_DEVICE_ID STM32_I2C_ID
202 #define TRIGGER_INT_ID 0 // unused
203 #define trigger_gpio_handle 0 // unused
204 #define DMA_IRQ_ID GPDMA1_Channel7_IRQn
205 #else
206 #error "No/Invalid active platform selected"
207 #endif
208 
209 /* List the differential/single-ended channels based on active device.
210  * Note : There can be max 16 channels in the device sequencer but since
211  * input pairs can be only 3/6/4/8/16, only those many channels are exposed
212  * out, based on the user selected channel configuration.
213  **/
214 #if defined(DEV_AD4170)
215 #define DIFFERENTIAL_CHNS 4
216 #define SINGLE_ENDED_CHNS 8
217 #endif
218 
219 /* Include user config files and params according to active/selected demo mode config */
220 #if (ACTIVE_DEMO_MODE_CONFIG == USER_DEFAULT_CONFIG)
221 #include "ad4170_user_config.h"
222 #define ad4170_init_params ad4170_user_config_params
223 #elif ((ACTIVE_DEMO_MODE_CONFIG == RTD_2WIRE_CONFIG) || \
224 (ACTIVE_DEMO_MODE_CONFIG == RTD_3WIRE_CONFIG) || (ACTIVE_DEMO_MODE_CONFIG == RTD_4WIRE_CONFIG))
225 #include "ad4170_rtd_config.h"
226 #define ad4170_init_params ad4170_rtd_config_params
227 #elif (ACTIVE_DEMO_MODE_CONFIG == THERMISTOR_CONFIG)
229 #define ad4170_init_params ad4170_thermistor_config_params
230 #elif (ACTIVE_DEMO_MODE_CONFIG == THERMOCOUPLE_CONFIG)
232 #define ad4170_init_params ad4170_thermocouple_config_params
233 #elif (ACTIVE_DEMO_MODE_CONFIG == ACCELEROMETER_CONFIG)
235 #define ad4170_init_params ad4170_accelerometer_config_params
236 #elif (ACTIVE_DEMO_MODE_CONFIG == LOADCELL_CONFIG)
237 #include "ad4170_loadcell_config.h"
238 #define ad4170_init_params ad4170_loadcell_config_params
239 #else
240 #include "ad4170_user_config.h"
241 #define ad4170_init_params ad4170_user_config_params
242 #warning "No/Invalid active demo config selected, user config used as default"
243 #endif
244 
245 /* ADC resolution for active device */
246 #define ADC_RESOLUTION 24
247 
248 /* Bytes per sample */
249 #define BYTES_PER_SAMPLE sizeof(uint32_t) // For ADC resolution of 24-bits
250 
251 /* ADC max count (full scale value) for unipolar inputs */
252 #define ADC_MAX_COUNT_UNIPOLAR (uint32_t)((1 << ADC_RESOLUTION) - 1)
253 
254 /* ADC max count (full scale value) for bipolar inputs */
255 #define ADC_MAX_COUNT_BIPOLAR (uint32_t)(1 << (ADC_RESOLUTION-1))
256 
257 /* Default ADC reference voltages for each reference source */
258 #define AD4170_REFIN_REFIN1_VOLTAGE 2.5
259 #define AD4170_REFIN_REFIN2_VOLTAGE 2.5
260 #define AD4170_REFIN_AVDD_VOLTAGE 5.0
261 #define AD4170_REFIN_REFOUT_VOLTAGE 2.5
262 
263 /****** Macros used to form a VCOM serial number ******/
264 #define FIRMWARE_NAME "ad4170_iio"
265 
266 #if !defined(PLATFORM_NAME)
267 #define PLATFORM_NAME HW_CARRIER_NAME
268 #endif
269 
270 /* Below USB configurations (VID and PID) are owned and assigned by ADI.
271  * If intended to distribute software further, use the VID and PID owned by your
272  * organization */
273 #define VIRTUAL_COM_PORT_VID 0x0456
274 #define VIRTUAL_COM_PORT_PID 0xb66c
275 /* Serial number string is formed as: application name + device (target) name + platform (host) name */
276 #define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" DEVICE_NAME "_" STR(PLATFORM_NAME))
277 
278 /* Baud rate for IIO application UART interface */
279 #define IIO_UART_BAUD_RATE (230400)
280 
281 /* Enable/Disable the use of SDRAM for ADC data capture buffer */
282 //#define USE_SDRAM // Uncomment to use SDRAM for data buffer
283 
284 /* Calculations for sampling frequency (used to define timeout in IIO client):
285  * Note: Below calculations are based on default user configurations set in the
286  * ad4170_xyz_config.h files. These configurations are used for data capturing.
287  * Clock: Internal 16Mhz oscillotor
288  * Filter Type: Selected in user config files
289  * Filter FS: Selected in user config files
290  * Filter ODR Average (as defined in datasheet): Selected in user config files
291  **/
292 /* AD4170 default internal clock frequency (Fclock = 16Mhz)*/
293 #define AD4170_INTERNAL_CLOCK (16000000U)
294 
295 /* Default sampling frequency for AD4170 (in SPS) */
296 #define AD4170_DEFLT_SAMPLING_FREQUENCY (AD4170_INTERNAL_CLOCK / FS_TO_ODR_CONV_SCALER)
297 
298 /******************************************************************************/
299 /************************ Public Declarations *********************************/
300 /******************************************************************************/
301 
302 extern struct no_os_gpio_init_param gpio_init_ldac_n;
303 extern struct no_os_gpio_init_param gpio_init_rdy;
304 extern struct no_os_gpio_init_param gpio_init_sync_inb;
305 extern struct no_os_gpio_desc *led_gpio_desc;
306 extern struct no_os_uart_desc *uart_desc;
307 extern struct no_os_gpio_desc *trigger_gpio_desc;
308 extern struct no_os_gpio_desc *csb_gpio_desc;
309 extern struct no_os_spi_init_param spi_init_params;
310 extern struct no_os_irq_ctrl_desc *trigger_irq_desc;
311 extern struct no_os_tdm_desc *ad4170_tdm_desc;
312 extern struct no_os_eeprom_desc *eeprom_desc;
313 extern struct no_os_pwm_desc *tx_trigger_desc;
314 int32_t init_system(void);
315 void ticker_callback(void *ctx);
316 
317 #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:194
struct no_os_pwm_desc * tx_trigger_desc
Definition: app_config.c:202
struct no_os_gpio_desc * trigger_gpio_desc
Definition: app_config.c:192
struct no_os_spi_init_param spi_init_params
Definition: app_config.c:56
Header for AD4170 Accelerometer configurations module.
struct no_os_gpio_init_param gpio_init_rdy
Definition: app_config.c:68
struct no_os_gpio_desc * led_gpio_desc
Definition: app_config.c:213
void ticker_callback(void *ctx)
This is an ISR (Interrupt Service Routine) for Ticker object.
Definition: ad4170_iio.c:2832
struct no_os_tdm_desc * ad4170_tdm_desc
struct no_os_gpio_desc * csb_gpio_desc
Definition: app_config.c:231
struct no_os_gpio_init_param gpio_init_ldac_n
Definition: app_config.c:60
struct no_os_gpio_init_param gpio_init_sync_inb
Definition: app_config.c:76
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.