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 <stdio.h>
21 #include <stdint.h>
22 #include "no_os_uart.h"
23 #include "no_os_gpio.h"
24 
25 /******************************************************************************/
26 /********************** Macros and Constants Definition ***********************/
27 /******************************************************************************/
28 
29 /* List of supported platforms */
30 #define STM32_PLATFORM 1
31 #define MBED_PLATFORM 2
32 
33 /* List of supported data capture modes */
34 #define BURST_DATA_CAPTURE 0
35 #define CONTINUOUS_DATA_CAPTURE 1
36 
37 /* List of supported interface modes for data capturing */
38 #define TDM_MODE 0
39 #define SPI_MODE 1
40 
41 /* List of ADC types for data capturing */
42 #define SD_ADC 0
43 #define SAR_ADC 1
44 
45 #if !defined (ACTIVE_PLATFORM)
46 #define ACTIVE_PLATFORM MBED_PLATFORM
47 #endif
48 
49 /* Select between the SAR and SD ADC for data capture */
50 #if !defined(ADC_TYPE)
51 #define ADC_TYPE SD_ADC
52 #endif
53 
54 /* Select the ADC data capture mode (default is CC mode for SD ADC) */
55 #if !defined(DATA_CAPTURE_MODE)
56 /* NOTE: SAR_ADC data capture works only in burst mode */
57 #if (ADC_TYPE == SAR_ADC)
58 #define DATA_CAPTURE_MODE BURST_DATA_CAPTURE
59 #else
60 #define DATA_CAPTURE_MODE CONTINUOUS_DATA_CAPTURE
61 #endif // ADC_TYPE
62 #endif // DATA_CAPTURE_MODE
63 
64 // **** Note for User: ACTIVE_DEVICE selection ****//
65 /* Define the device type from the list of below device type defines (one at a time)
66  * e.g. #define DEV_AD7770 -> This will make AD7770 as an ACTIVE_DEVICE.
67  * The ACTIVE_DEVICE is default set to AD7770 if device type is not defined.
68  * */
69 //#define DEV_AD7770
70 
71 /* Comment this macro to enable Unipolar mode of operation. Default is Bipolar.
72  * NOTE: There needs to be jumper configurations set respective to Bipolar/ Unipolar
73  * operation. Please refer to the user guide for the same. */
74 #define BIPOLAR
75 
76 /* Macros for stringification */
77 #define XSTR(s) #s
78 #define STR(s) XSTR(s)
79 
80 /* Enable the UART/VirtualCOM port connection (default VCOM) */
81 //#define USE_PHY_COM_PORT // Uncomment to select UART
82 
83 #if !defined(USE_PHY_COM_PORT)
84 #define USE_VIRTUAL_COM_PORT
85 #endif
86 
87 #if defined(DEV_AD7770)
88 #define ACTIVE_DEVICE "ad7770"
89 #define DEVICE_NAME "DEV_AD7770"
90 #define HW_MEZZANINE_NAME "EVAL-AD7770ARDZ"
91 #elif defined(DEV_AD7771)
92 #define ACTIVE_DEVICE "ad7771"
93 #define DEVICE_NAME "DEV_AD7771"
94 #define HW_MEZZANINE_NAME "EVAL-AD7771ARDZ"
95 #elif defined(DEV_AD7779)
96 #define ACTIVE_DEVICE "ad7779"
97 #define DEVICE_NAME "DEV_AD7779"
98 #define HW_MEZZANINE_NAME "EVAL-AD7779ARDZ"
99 #else
100 #warning No/Unsupported ADxxxxy symbol defined. AD7770 defined
101 #define DEV_AD7770
102 #define ACTIVE_DEVICE "ad7770"
103 #define DEVICE_NAME "DEV_AD7770"
104 #define HW_MEZZANINE_NAME "EVAL-AD7770ARDZ"
105 #endif
106 
107 /* Note: The STM32 platform supports SPI and TDM Mode of data capturing.
108  * and the MBED platform supports only SPI Mode. */
109 #if !defined(INTERFACE_MODE)
110 #if (ACTIVE_PLATFORM == STM32_PLATFORM)
111 #define INTERFACE_MODE TDM_MODE
112 #else // Mbed
113 #define INTERFACE_MODE SPI_MODE
114 #endif
115 #endif
116 
117 #if (ADC_TYPE == SD_ADC)
118 /* SD ADC is 32 bit */
119 #define BYTES_PER_SAMPLE sizeof(uint32_t)
120 #else
121 /* SAR ADC is 12 bit */
122 #define BYTES_PER_SAMPLE sizeof(uint16_t)
123 #endif
124 
125 #if (ACTIVE_PLATFORM == STM32_PLATFORM)
126 #include "app_config_stm32.h"
127 
128 #define uart_extra_init_params stm32_uart_extra_init_params
129 #define spi_extra_init_params stm32_spi_extra_init_params
130 #define gpio_reset_extra_init_params stm32_gpio_reset_extra_init_params
131 #define gpio_mode0_extra_init_params stm32_gpio_mode0_extra_init_params
132 #define gpio_mode1_extra_init_params stm32_gpio_mode1_extra_init_params
133 #define gpio_mode2_extra_init_params stm32_gpio_mode2_extra_init_params
134 #define gpio_mode3_extra_init_params stm32_gpio_mode3_extra_init_params
135 #define gpio_dclk0_extra_init_params stm32_gpio_dclk0_extra_init_params
136 #define gpio_dclk1_extra_init_params stm32_gpio_dclk1_extra_init_params
137 #define gpio_dclk2_extra_init_params stm32_gpio_dclk2_extra_init_params
138 #define gpio_sync_in_extra_init_params stm32_gpio_sync_in_extra_init_params
139 #define gpio_convst_sar_extra_init_params stm32_gpio_convst_sar_extra_init_params
140 #define gpio_drdy_extra_init_params stm32_gpio_drdy_extra_init_params
141 #define gpio_error_extra_init_params stm32_gpio_error_extra_init_params
142 #define trigger_gpio_irq_extra_params stm32_trigger_gpio_irq_init_params
143 #define tdm_extra_init_params stm32_tdm_extra_init_params
144 #define pwm_extra_init_params stm32_pwm_extra_init_params
145 #define i2c_extra_init_params stm32_i2c_extra_init_params
146 
147 #define spi_platform_ops stm32_spi_ops
148 #define gpio_platform_ops stm32_gpio_ops
149 #define trigger_gpio_irq_ops stm32_gpio_irq_ops
150 #define uart_ops stm32_uart_ops
151 #define tdm_platform_ops stm32_tdm_platform_ops
152 #define i2c_ops stm32_i2c_ops
153 #define pwm_ops stm32_pwm_ops
154 
155 #define trigger_gpio_handle 0 // Unused macro
156 
157 #define HW_CARRIER_NAME NUCLEO-H563ZI
158 #elif (ACTIVE_PLATFORM == MBED_PLATFORM)
159 #include "app_config_mbed.h"
160 
161 /* Re-define platform specific parameters */
162 #define uart_extra_init_params mbed_uart_extra_init_params
163 #define vcom_extra_init_params mbed_vcom_extra_init_params
164 #define spi_extra_init_params mbed_spi_extra_init_params
165 #define i2c_extra_init_params mbed_i2c_extra_init_params
166 #define gpio_reset_extra_init_params mbed_gpio_reset_extra_init_params
167 #define gpio_mode0_extra_init_params mbed_gpio_mode0_extra_init_params
168 #define gpio_mode1_extra_init_params mbed_gpio_mode1_extra_init_params
169 #define gpio_mode2_extra_init_params mbed_gpio_mode2_extra_init_params
170 #define gpio_mode3_extra_init_params mbed_gpio_mode3_extra_init_params
171 #define gpio_dclk0_extra_init_params mbed_gpio_dclk0_extra_init_params
172 #define gpio_dclk1_extra_init_params mbed_gpio_dclk1_extra_init_params
173 #define gpio_dclk2_extra_init_params mbed_gpio_dclk2_extra_init_params
174 #define gpio_sync_in_extra_init_params mbed_gpio_sync_in_extra_init_params
175 #define gpio_convst_sar_extra_init_params mbed_gpio_convst_sar_extra_init_params
176 #define gpio_drdy_extra_init_params mbed_gpio_drdy_extra_init_params
177 #define gpio_error_extra_init_params mbed_gpio_error_extra_init_params
178 #define trigger_gpio_irq_extra_params mbed_trigger_gpio_irq_init_params
179 #define pwm_extra_init_params mbed_pwm_init_params
180 #define spi_platform_ops mbed_spi_ops
181 #define i2c_ops mbed_i2c_ops
182 #define gpio_platform_ops mbed_gpio_ops
183 #define trigger_gpio_irq_ops mbed_gpio_irq_ops
184 #define uart_ops mbed_uart_ops
185 #define vcom_ops mbed_virtual_com_ops
186 #define pwm_ops mbed_pwm_ops
187 #define trigger_gpio_handle 0 // Unused macro
188 
189 #define HW_CARRIER_NAME TARGET_NAME
190 #endif
191 
192 /* Enable/Disable the use of SDRAM for ADC data capture buffer */
193 // #define USE_SDRAM // Uncomment to use SDRAM as data buffer
194 
195 /* Check if any serial port available for use as console stdio port */
196 #if defined(USE_PHY_COM_PORT)
197 /* If PHY com is selected, VCOM or alternate PHY com port can act as a console stdio port */
198 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
199 #define CONSOLE_STDIO_PORT_AVAILABLE
200 #endif
201 #else
202 /* If VCOM is selected, PHY com port will/should act as a console stdio port */
203 #define CONSOLE_STDIO_PORT_AVAILABLE
204 #endif
205 
206 /* VCOM Serial number definition */
207 #define FIRMWARE_NAME "ad777x_iio"
208 
209 #if !defined(PLATFORM_NAME)
210 #define PLATFORM_NAME HW_CARRIER_NAME
211 #endif
212 
213 /* Below USB configurations (VID and PID) are owned and assigned by ADI.
214  * If intended to distribute software further, use the VID and PID owned by your
215  * organization */
216 #define VIRTUAL_COM_PORT_VID 0x0456
217 #define VIRTUAL_COM_PORT_PID 0xb66c
218 
219 #define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" DEVICE_NAME "_" STR(PLATFORM_NAME))
220 
221 /* Baudrate for UART Transactions */
222 #define IIO_UART_BAUD_RATE 230400
223 
224 /* Number of channels in the AD777x Family */
225 #if (ADC_TYPE == SAR_ADC)
226 /* Choose the SAR input for data capturing. Default is AUXAIN+/AUXAIN.
227  * Please refer to the GLOBAL_MUX_CTRL bit in GLOBAL_MUX_CONFIG register
228  * the datasheet for other SAR MUX configurations */
229 #define SAR_MUX_CONF 0
230 #define AD777x_NUM_CHANNELS 1
231 #else // SD_ADC
232 #define AD777x_NUM_CHANNELS 8
233 #endif
234 
235 /* ADC resolution for active device */
236 #if (ADC_TYPE == SAR_ADC)
237 #define ADC_RESOLUTION 12
238 #else
239 #define ADC_RESOLUTION 24
240 #endif
241 
242 /* ADC max count (full scale value) for unipolar inputs */
243 #define ADC_MAX_COUNT_UNIPOLAR (uint32_t)((1 << ADC_RESOLUTION) - 1)
244 
245 /* ADC max count (full scale value) for bipolar inputs */
246 #define ADC_MAX_COUNT_BIPOLAR (uint32_t)(1 << (ADC_RESOLUTION-1))
247 
248 /* Uncomment this macro to enable external master clock MCLK */
249 //#define ENABLE_EXT_MCLK
250 
251 /* Select the external master clock frequency
252  * Note: The maximum programmable PWM frequency for mbed platform
253  * is only 500kHz */
254 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
255 #define AD777X_EXT_MCLK_FREQ 500000
256 #else
257 #define AD777X_EXT_MCLK_FREQ 8192000
258 #endif
259 
260 /* AD777x Master Clock Frequency */
261 #if !defined (ENABLE_EXT_MCLK)
262 #define AD777x_MCLK_FREQ 8192000 // Fixed
263 #else
264 #define AD777x_MCLK_FREQ AD777X_EXT_MCLK_FREQ
265 #endif
266 
267 #define AD777x_MCLK_PERIOD (((float)(1.0 / AD777x_MCLK_FREQ) * 1000000) * 1000)
268 
269 /******************************************************************************/
270 /************************ Public Declarations *********************************/
271 /******************************************************************************/
272 
273 int32_t init_system(void);
274 void data_capture_callback(void *ctx);
275 extern struct no_os_uart_desc *uart_iio_com_desc;
276 extern struct no_os_uart_desc *uart_console_stdio_desc;
277 extern struct no_os_gpio_desc *gpio_drdy_desc;
278 extern struct no_os_gpio_desc *gpio_error_desc;
279 extern struct no_os_irq_ctrl_desc *trigger_irq_desc;
280 extern struct no_os_tdm_desc *ad777x_tdm_desc;
281 extern struct no_os_eeprom_desc *eeprom_desc;
282 
283 #endif // APP_CONFIG_H
284 
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_iio_com_desc
Definition: app_config.c:127
struct no_os_eeprom_desc * eeprom_desc
Definition: app_config.c:194
struct no_os_uart_desc * uart_console_stdio_desc
Definition: app_config.c:100
void data_capture_callback(void *ctx)
Interrupt Service Routine to monitor data ready event.
Definition: ad405x_iio.c:1286
struct no_os_gpio_desc * gpio_drdy_desc
Definition: app_config.c:165
struct no_os_tdm_desc * ad777x_tdm_desc
struct no_os_gpio_desc * gpio_error_desc
Definition: app_config.c:168
Header file for Mbed platform configurations.