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 
22 /******************************************************************************/
23 /********************** Macros and Constants Definition ***********************/
24 /******************************************************************************/
25 
26 /* List of supported platforms */
27 #define MBED_PLATFORM 1
28 
29 /* List of supported DAC data stream modes */
30 #define CYCLIC_STREAM 0
31 #define ARBITRARY_STREAM 1
32 
33 /* Macros for stringification */
34 #define XSTR(s) #s
35 #define STR(s) XSTR(s)
36 
37 /******************************************************************************/
38 
39 /* Select the active platform (default is Mbed) */
40 #if !defined(ACTIVE_PLATFORM)
41 #define ACTIVE_PLATFORM MBED_PLATFORM
42 #endif
43 
44 /* Select the DAC data stream mode (default is Cyclic stream mode) */
45 #if !defined(DATA_STREAM_MODE)
46 #define DATA_STREAM_MODE CYCLIC_STREAM
47 #endif
48 
49 /* Enable the UART/VirtualCOM port connection (default VCOM) */
50 //#define USE_PHY_COM_PORT // Uncomment to select UART
51 
52 #if !defined(USE_PHY_COM_PORT)
53 #define USE_VIRTUAL_COM_PORT
54 #endif
55 
56 // **** Note for User: ACTIVE_DEVICE selection **** //
57 /* Define the device type here from the list of below device type defines
58  * (one at a time. Defining more than one device can result into compile error).
59  * e.g. #define DEV_AD5780 -> This will make AD5780 as an ACTIVE_DEVICE.
60  * The ACTIVE_DEVICE is default set to AD5780 if device type is not defined.
61  * */
62 
63 //#define DEV_AD5780
64 
65 #if defined(DEV_AD5780)
66 #define ACTIVE_DEVICE_NAME "ad5780"
67 #define DEVICE_NAME "DEV_AD5780"
68 #define ACTIVE_DEVICE ID_AD5780
69 #define HW_MEZZANINE_NAME "EVAL-AD5780ARDZ"
70 #define DAC_RESOLUTION 18
71 #elif defined(DEV_AD5781)
72 #define ACTIVE_DEVICE_NAME "ad5781"
73 #define DEVICE_NAME "DEV_AD5781"
74 #define ACTIVE_DEVICE ID_AD5781
75 #define HW_MEZZANINE_NAME "EVAL-AD5781ARDZ"
76 #define DAC_RESOLUTION 18
77 #elif defined(DEV_AD5790)
78 #define ACTIVE_DEVICE_NAME "ad5790"
79 #define DEVICE_NAME "DEV_AD5790"
80 #define ACTIVE_DEVICE ID_AD5790
81 #define HW_MEZZANINE_NAME "EVAL-AD5790ARDZ"
82 #define DAC_RESOLUTION 20
83 #elif defined(DEV_AD5791)
84 #define ACTIVE_DEVICE_NAME "ad5791"
85 #define DEVICE_NAME "DEV_AD5791"
86 #define ACTIVE_DEVICE ID_AD5791
87 #define HW_MEZZANINE_NAME "EVAL-AD5791ARDZ"
88 #define DAC_RESOLUTION 20
89 #elif defined(DEV_AD5760)
90 #define ACTIVE_DEVICE_NAME "ad5760"
91 #define DEVICE_NAME "DEV_AD5760"
92 #define ACTIVE_DEVICE ID_AD5760
93 #define HW_MEZZANINE_NAME "EVAL-AD5760ARDZ"
94 #define DAC_RESOLUTION 16
95 #else
96 #warning No/Unsupported ADxxxx symbol defined. AD5780 defined
97 #define DEV_AD5780
98 #define ACTIVE_DEVICE_NAME "ad5780"
99 #define DEVICE_NAME "DEV_AD5780"
100 #define ACTIVE_DEVICE ID_AD5780
101 #define HW_MEZZANINE_NAME "EVAL-AD5780ARDZ"
102 #define DAC_RESOLUTION 18
103 #endif
104 
105 /* Define DAC voltage reference here. When internal reference is used,
106  * devices AD5781, AD5791 support only one voltage span (-10 to 10V) by
107  * default and the devices AD5760, AD5780, AD5790 support two voltage
108  * spans based on the jumper setting (-10 to 10V, 0 to 10V).
109  * The default voltage reference is internal reference (-10 to 10V). */
110 
111 //#define INT_REF_0V_TO_10V
112 
113 #if defined(INT_REF_M10V_TO_10V) //internal reference bipolar
114 #define DAC_CH_SPAN 20
115 #define DAC_VREFN -10.0
116 #define DAC_VREFN_GAIN_OF_TWO -30.0
117 #elif defined(INT_REF_0V_TO_10V) //internal reference unipolar
118 #define DAC_CH_SPAN 10
119 #define DAC_VREFN 0.0
120 #define DAC_VREFN_GAIN_OF_TWO -10.0
121 #elif defined(EXT_REF) //external reference
122 #define DAC_VREFN -10.0
123 #define DAC_VREFP 10.0
124 #define DAC_CH_SPAN (DAC_VREFP-DAC_VREFN)
125 #else
126 #warning No/Unsupported Reference selection defined. Internal reference -10V to 10V defined
127 #define INT_REF_M10V_TO_10V
128 #define DAC_CH_SPAN 20
129 #define DAC_VREFN -10.0
130 #define DAC_VREFN_GAIN_OF_TWO -30.0
131 #endif
132 
133 /* Number of DAC Channels */
134 #define AD579X_NUM_CHANNELS 1
135 
136 /* DAC maximum count */
137 #define DAC_MAX_COUNT (uint32_t)((1 << DAC_RESOLUTION) - 1)
138 
139 /* DAC maximum count in offset binary code */
140 #define DAC_MAX_COUNT_BIN_OFFSET (uint32_t)((1 << DAC_RESOLUTION) - 1)
141 
142 /* DAC maximum count in 2s complement code */
143 #define DAC_MAX_COUNT_2S_COMPL (uint32_t)(1 << (DAC_RESOLUTION-1))
144 
145 /* Number of voltage spans possible for linearity compensation error handling */
146 #define NUM_OF_V_SPANS 5
147 
148 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
149 #include "app_config_mbed.h"
150 
151 #define HW_CARRIER_NAME TARGET_NAME
152 
153 /* Redefine the init params structure mapping w.r.t. platform */
154 #define pwm_extra_init_params mbed_pwm_extra_init_params
155 #define uart_extra_init_params mbed_uart_extra_init_params
156 #define vcom_extra_init_params mbed_vcom_extra_init_params
157 #define spi_extra_init_params mbed_spi_extra_init_params
158 #define i2c_extra_init_params mbed_i2c_extra_init_params
159 #define trigger_gpio_irq_extra_params mbed_trigger_gpio_irq_init_params
160 #define gpio_ops mbed_gpio_ops
161 #define spi_ops mbed_spi_ops
162 #define i2c_ops mbed_i2c_ops
163 #define uart_ops mbed_uart_ops
164 #define vcom_ops mbed_virtual_com_ops
165 #define pwm_ops mbed_pwm_ops
166 #define trigger_gpio_irq_ops mbed_gpio_irq_ops
167 #else
168 #error "No/Invalid active platform selected"
169 #endif
170 
171 /****** Macros used to form a VCOM serial number ******/
172 
173 /* Baud rate for IIO application UART interface */
174 #define IIO_UART_BAUD_RATE (230400)
175 
176 /* Used to form a VCOM serial number */
177 #define FIRMWARE_NAME "ad579x_iio"
178 
179 #if !defined(PLATFORM_NAME)
180 #define PLATFORM_NAME HW_CARRIER_NAME
181 #endif
182 
183 /* Below USB configurations (VID and PID) are owned and assigned by ADI.
184  * If intended to distribute software further, use the VID and PID owned by your
185  * organization */
186 #define VIRTUAL_COM_PORT_VID 0x0456
187 #define VIRTUAL_COM_PORT_PID 0xb66c
188 /* Serial number string is formed as: application name + device (target) name + platform (host) name */
189 #define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" DEVICE_NAME "_" STR(PLATFORM_NAME))
190 
191 /* Check if any serial port available for use as console stdio port */
192 #if defined(USE_PHY_COM_PORT)
193 /* If PHY com is selected, VCOM or alternate PHY com port can act as a console stdio port */
194 #if (ACTIVE_PLATFORM == MBED_PLATFORM)
195 #define CONSOLE_STDIO_PORT_AVAILABLE
196 #endif
197 #else
198 /* If VCOM is selected, PHY com port will/should act as a console stdio port */
199 #define CONSOLE_STDIO_PORT_AVAILABLE
200 #endif
201 
202 /* Enable/Disable the use of SDRAM for DAC data streaming buffer */
203 //#define USE_SDRAM // Uncomment to use SDRAM for data buffer
204 
205 /* PWM period and duty cycle */
206 #define CONV_PERIOD_NSEC(x) (((float)(1.0 / x) * 1000000) * 1000)
207 #define CONV_DUTY_CYCLE_NSEC(x) (CONV_PERIOD_NSEC(x) / 2)
208 
209 /******************************************************************************/
210 /************************ Public Declarations *********************************/
211 /******************************************************************************/
212 
213 extern struct no_os_pwm_desc *pwm_desc;
214 extern struct no_os_uart_desc *uart_iio_com_desc;
215 extern struct no_os_uart_desc *uart_console_stdio_desc;
216 extern struct no_os_irq_ctrl_desc *trigger_irq_desc;
217 extern struct no_os_eeprom_desc *eeprom_desc;
218 
219 int32_t init_pwm_trigger(void);
220 int32_t init_system(void);
221 
222 #endif /* APP_CONFIG_H_ */
int32_t init_pwm_trigger(void)
Initialize the PWM trigger contoller.
Definition: app_config.c:161
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_pwm_desc * pwm_desc
Definition: app_config.c:106
struct no_os_uart_desc * uart_console_stdio_desc
Definition: app_config.c:100
Header file for Mbed platform configurations.