precision-converters-firmware
app_config.h
Go to the documentation of this file.
1 /*************************************************************************/
14 #ifndef APP_CONFIG_H
15 #define APP_CONFIG_H
16 
17 /******************************************************************************/
18 /***************************** Include Files **********************************/
19 /******************************************************************************/
20 #include <stdint.h>
21 #include "no_os_gpio.h"
22 #include "no_os_uart.h"
23 #include "no_os_irq.h"
24 #include "no_os_pwm.h"
25 
26 /******************************************************************************/
27 /********************** Macros and Constants Definition ***********************/
28 /******************************************************************************/
29 /* List of supported platforms */
30 #define MBED_PLATFORM 1
31 #define STM32_PLATFORM 2
32 
33 /* List of data capture modes supported by application*/
34 #define CONTINUOUS_DATA_CAPTURE 0
35 #define WINDOWED_DATA_CAPTURE 1
36 
37 /* List of supported data capture modes by device */
38 #define SAMPLE_MODE 0
39 #define BURST_AVERAGING_MODE 1
40 #define AVERAGING_MODE 2
41 
42 /* List of supported data format by device */
43 #define STRAIGHT_BINARY 0
44 #define TWOS_COMPLEMENT 1
45 
46 /* List of data capture methods supported by hardware platform */
47 #define SPI_DMA 0
48 #define SPI_INTERRUPT 1
49 
50 /* Macros for stringification */
51 #define XSTR(s) #s
52 #define STR(s) XSTR(s)
53 
54 /******************************************************************************/
55 
56 /* Select the active platform (default is Mbed) */
57 #if !defined(ACTIVE_PLATFORM)
58 #define ACTIVE_PLATFORM STM32_PLATFORM
59 #endif
60 
61 /* Enable the UART/VirtualCOM port connection (default VCOM) */
62 //#define USE_PHY_COM_PORT // Uncomment to select UART
63 
64 #if !defined(USE_PHY_COM_PORT)
65 #define USE_VIRTUAL_COM_PORT
66 #endif
67 
68 /* Select the application data capture mode (default is CC mode) */
69 #if !defined(APP_CAPTURE_MODE)
70 #define APP_CAPTURE_MODE WINDOWED_DATA_CAPTURE
71 #endif
72 
73 /* Select the ADC data capture mode (default is sample mode) */
74 #if !defined(ADC_CAPTURE_MODE)
75 #define ADC_CAPTURE_MODE SAMPLE_MODE
76 #endif
77 
78 /* Select the ADC output data format (default is twos complement mode) */
79 #if !defined(ADC_DATA_FORMAT)
80 #define ADC_DATA_FORMAT TWOS_COMPLEMENT
81 #endif
82 
83 /* Note: The STM32 platform supports SPI interrupt and SPI DMA Mode
84  * for data capturing. The MBED platform supports only SPI interrupt mode
85  * */
86 #if !defined(INTERFACE_MODE)
87 #if (ACTIVE_PLATFORM == STM32_PLATFORM)
88 #define INTERFACE_MODE SPI_DMA
89 #else // Mbed
90 #define INTERFACE_MODE SPI_INTERRUPT
91 #endif
92 #endif
93 
94 // **** Note for User on selection of Active Device ****//
95 /* Define the device type here from the list of below device type defines
96  * (one at a time. Defining more than one device can result into compile error).
97  * e.g. #define DEV_AD4050 -> This will make AD4050 as an active device.
98  * The active device is default set to AD4052 if device type is not defined.
99  * */
100 // #define DEV_AD4050
101 
102 #if defined(DEV_AD4052)
103 #define ACTIVE_DEVICE_NAME "ad4052"
104 #define DEVICE_NAME "DEV_AD4052"
105 #define ACTIVE_DEVICE_ID ID_AD4052
106 #define HW_MEZZANINE_NAME "EVAL-AD4052-ARDZ"
107 #define ADC_SAMPLE_MODE_RESOLUTION 16
108 #define ADC_AVERAGING_MODE_RESOLUTION 20
109 #define ADC_BURST_AVG_MODE_RESOLUTION 20
110 #elif defined(DEV_AD4050)
111 #define ACTIVE_DEVICE_NAME "ad4050"
112 #define DEVICE_NAME "DEV_AD4050"
113 #define ACTIVE_DEVICE_ID ID_AD4050
114 #define HW_MEZZANINE_NAME "EVAL-AD4050-ARDZ"
115 #define ADC_SAMPLE_MODE_RESOLUTION 12
116 #define ADC_AVERAGING_MODE_RESOLUTION 14
117 #define ADC_BURST_AVG_MODE_RESOLUTION 14
118 #else
119 #define ACTIVE_DEVICE_NAME "ad4052"
120 #define DEVICE_NAME "DEV_AD4052"
121 #define ACTIVE_DEVICE_ID ID_AD4052
122 #define HW_MEZZANINE_NAME "EVAL-AD4052-ARDZ"
123 #define ADC_SAMPLE_MODE_RESOLUTION 16
124 #define ADC_AVERAGING_MODE_RESOLUTION 20
125 #define ADC_BURST_AVG_MODE_RESOLUTION 20
126 #endif
127 
128 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
129 #include "app_config_mbed.h"
130 #define HW_CARRIER_NAME TARGET_NAME
131 #elif (ACTIVE_PLATFORM == STM32_PLATFORM)
132 #include "app_config_stm32.h"
133 #define HW_CARRIER_NAME TARGET_NAME
134 #if (INTERFACE_MODE != SPI_DMA)
135 #define trigger_gpio_handle 0 // Unused macro
136 #else
137 #define trigger_gpio_handle STM32_DMA_CONT_HANDLE
138 #endif
139 #if (INTERFACE_MODE == SPI_DMA)
140 #define TRIGGER_INT_ID STM32_DMA_CONT_TRIGGER
141 #else
142 #define TRIGGER_INT_ID GP1_PIN_NUM
143 #endif
144 #else
145 #error "No/Invalid active platform selected"
146 #endif
147 
148 #define DEFAULT_BURST_SAMPLE_RATE 2000000
149 
150 /* ADC reference voltage (Range: 2.5 to 3.3v) */
151 #define ADC_REF_VOLTAGE 2.5
152 
153 #if (ADC_CAPTURE_MODE == SAMPLE_MODE)
154 #if (ADC_DATA_FORMAT == STRAIGHT_BINARY)
155 #define ADC_MAX_COUNT (uint32_t)(1 << (ADC_SAMPLE_MODE_RESOLUTION))
156 #else
157 #define ADC_MAX_COUNT (uint32_t)(1 << (ADC_SAMPLE_MODE_RESOLUTION - 1))
158 #endif
159 #else
160 #if (ADC_DATA_FORMAT == STRAIGHT_BINARY)
161 #define ADC_MAX_COUNT (uint32_t)(1 << (ADC_BURST_AVG_MODE_RESOLUTION))
162 #else
163 #define ADC_MAX_COUNT (uint32_t)(1 << (ADC_BURST_AVG_MODE_RESOLUTION - 1))
164 #endif
165 #endif
166 
167 /* Time taken for the application to process the interrupt and
168  * push data into iio buffer. */
169 #define MIN_DATA_CAPTURE_TIME_NS 8000
170 
171 /* Time taken by the MCU to Jump into the ISR after the occurrence of
172  * data ready event */
173 #if (APP_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE)
174 #define MIN_INTERRUPT_OVER_HEAD 4500
175 #else
176 #define MIN_INTERRUPT_OVER_HEAD 3000
177 #endif
178 
179 /* Baud rate for IIO application UART interface */
180 #define IIO_UART_BAUD_RATE (230400)
181 
182 /****** Macros used to form a VCOM serial number ******/
183 /* Used to form a VCOM serial number */
184 #define FIRMWARE_NAME "ad405x_iio"
185 
186 #if !defined(PLATFORM_NAME)
187 #define PLATFORM_NAME HW_CARRIER_NAME
188 #endif
189 
190 /* Below USB configurations (VID and PID) are owned and assigned by ADI.
191  * If intended to distribute software further, use the VID and PID owned by your
192  * organization */
193 #define VIRTUAL_COM_PORT_VID 0x0456
194 #define VIRTUAL_COM_PORT_PID 0xb66c
195 /* Serial number string is formed as: application name + device (target) name + platform (host) name */
196 #define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" DEVICE_NAME "_" STR(PLATFORM_NAME))
197 
198 /* Check if any serial port available for use as console stdio port */
199 #if defined(USE_PHY_COM_PORT)
200 /* If PHY com is selected, VCOM or alternate PHY com port can act as a console stdio port */
201 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
202 #define CONSOLE_STDIO_PORT_AVAILABLE
203 #endif
204 #else
205 /* If VCOM is selected, PHY com port will/should act as a console stdio port */
206 #define CONSOLE_STDIO_PORT_AVAILABLE
207 #endif
208 
209 /* Enable/Disable the use of SDRAM for ADC data capture buffer */
210 //#define USE_SDRAM // Uncomment to use SDRAM as data buffer
211 
212 /******************************************************************************/
213 /********************** Variables and User Defined Data Types *****************/
214 /******************************************************************************/
215 
216 /******************************************************************************/
217 /************************ Public Declarations *********************************/
218 /******************************************************************************/
219 extern struct no_os_pwm_desc *pwm_desc;
220 extern struct no_os_uart_desc *uart_iio_com_desc;
221 extern struct no_os_uart_desc *uart_console_stdio_desc;
222 extern struct no_os_gpio_desc *trigger_gpio_desc;
223 extern struct no_os_irq_ctrl_desc *trigger_irq_desc;
224 extern struct no_os_eeprom_desc *eeprom_desc;
225 extern struct no_os_gpio_init_param cs_pwm_gpio_params;
226 extern struct no_os_gpio_init_param pwm_gpio_params;
227 
228 #if (INTERFACE_MODE == SPI_DMA)
229 extern struct no_os_dma_xfer_desc dma_tx_desc;
230 extern struct no_os_dma_ch dma_chan;
231 extern struct no_os_pwm_init_param cs_init_params;
232 extern struct no_os_pwm_init_param pwm_init_params;
233 extern struct no_os_dma_init_param ad405x_dma_init_param;
234 extern struct no_os_gpio_init_param cs_pwm_gpio_params;
235 extern struct no_os_gpio_init_param pwm_gpio_params;
236 extern volatile uint32_t* buff_start_addr;
237 extern volatile struct iio_device_data* iio_dev_data_g;
238 extern uint32_t nb_of_samples_g;
239 extern int32_t data_read;
240 extern struct no_os_pwm_desc* tx_trigger_desc;
241 #endif
242 
243 int32_t init_pwm(void);
244 int32_t ad405x_gpio_reset(void);
245 int32_t init_system(void);
246 
247 #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_iio_com_desc
Definition: app_config.c:127
struct no_os_dma_ch dma_chan
volatile struct iio_device_data * iio_dev_data_g
Definition: ad405x_iio.c:331
uint32_t nb_of_samples_g
Definition: ad405x_iio.c:334
struct no_os_pwm_init_param pwm_init_params
Definition: app_config.c:108
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_dma_xfer_desc dma_tx_desc
int32_t ad405x_gpio_reset(void)
struct no_os_pwm_desc * pwm_desc
Definition: app_config.c:106
struct no_os_gpio_desc * trigger_gpio_desc
Definition: app_config.c:192
struct no_os_gpio_init_param cs_pwm_gpio_params
Definition: app_config.h:234
struct no_os_pwm_init_param cs_init_params
Definition: app_config.c:133
volatile uint32_t * buff_start_addr
Definition: ad405x_iio.c:174
int32_t data_read
Definition: ad405x_iio.c:337
struct no_os_gpio_init_param pwm_gpio_params
Definition: app_config.h:235
int32_t init_pwm(void)
Initialize the PWM interface.
Definition: app_config.c:283
struct no_os_dma_init_param ad405x_dma_init_param
Definition: app_config.c:205
struct no_os_uart_desc * uart_console_stdio_desc
Definition: app_config.c:100
Header file for STM32 platform configurations.