precision-converters-firmware
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
app_config.h
Go to the documentation of this file.
1/***************************************************************************//*
2 * @file app_config.h
3 * @brief Header file for application configurations (platform-agnostic)
4******************************************************************************
5 * Copyright (c) 2023 Analog Devices, Inc.
6 * Copyright (c) 2023 BayLibre, SAS
7 * All rights reserved.
8 *
9 * This software is proprietary to Analog Devices, Inc. and its licensors.
10 * By using this software you agree to the terms of the associated
11 * Analog Devices Software License Agreement.
12******************************************************************************/
13
14#ifndef _APP_CONFIG_H_
15#define _APP_CONFIG_H_
16
17/******************************************************************************/
18/***************************** Include Files **********************************/
19/******************************************************************************/
20
21#include <stdint.h>
22#include <limits.h>
23/******************************************************************************/
24/********************** Macros and Constants Definition ***********************/
25/******************************************************************************/
26
27/* List of supported platforms */
28#define MBED_PLATFORM 1
29
30/* List of data capture modes */
31#define CONTINUOUS_DATA_CAPTURE 0
32#define BURST_DATA_CAPTURE 1
33
34/* Macros for stringification */
35#define XSTR(s) #s
36#define STR(s) XSTR(s)
37
38/******************************************************************************/
39
40/**** ACTIVE_DEVICE selection *****
41* Define the device type here from the available list of devices (one at a time)
42* e.g. #define DEV_AD2S1210 -> This will make AD2S1210 as an ACTIVE_DEVICE.
43**/
44/* #define DEV_AD2S1210 */
45
46/* Name of the active device */
47#if !defined(DEV_AD2S1210)
48#define DEV_AD2S1210
49#define ACTIVE_DEVICE ID_AD2S1210
50#define ACTIVE_DEVICE_NAME "ad2s1210"
51#define DEVICE_NAME "DEV_AD2S1210"
52#endif
53
54/* Select the active platform (default is Mbed) */
55#if !defined(ACTIVE_PLATFORM)
56#define ACTIVE_PLATFORM MBED_PLATFORM
57#endif
58
59/* Select the RESOLVER data capture mode (default is CC mode) */
60#if !defined(DATA_CAPTURE_MODE)
61#define DATA_CAPTURE_MODE CONTINUOUS_DATA_CAPTURE
62#endif
63
64/* Enable the UART/VirtualCOM port connection (default VCOM) */
65/* #define USE_PHY_COM_PORT // Uncomment to select UART */
66
67#if !defined(USE_PHY_COM_PORT)
68#define USE_VIRTUAL_COM_PORT
69#endif
70
71#if (ACTIVE_PLATFORM == MBED_PLATFORM)
72#include "app_config_mbed.h"
73
74#define HW_CARRIER_NAME TARGET_NAME
75
76/* Redefine the init params structure mapping w.r.t. platform */
77#define pwm_extra_init_params mbed_pwm_extra_init_params
78#define uart_extra_init_params mbed_uart_extra_init_params
79#define vcom_extra_init_params mbed_vcom_extra_init_params
80#define spi_extra_init_params mbed_spi_extra_init_params
81#define trigger_gpio_irq_extra_params mbed_trigger_gpio_irq_init_params
82#define trigger_gpio_extra_init_params mbed_trigger_gpio_extra_init_params
83#define trigger_gpio_ops mbed_gpio_ops
84#define irq_ops mbed_gpio_irq_ops
85#define gpio_ops mbed_gpio_ops
86#define spi_ops mbed_spi_ops
87#define uart_ops mbed_uart_ops
88#define vcom_ops mbed_virtual_com_ops
89#define pwm_ops mbed_pwm_ops
90#define trigger_gpio_irq_ops mbed_gpio_irq_ops
91#define trigger_gpio_handle 0 /* Unused macro */
92#define IRQ_INT_ID GPIO_IRQ_ID1
93#define TRIGGER_GPIO_PORT 0 /* Unused macro */
94#define TRIGGER_GPIO_PIN PWM_TRIGGER
95#define TRIGGER_INT_ID GPIO_IRQ_ID1
96#else
97#error "No/Invalid active platform selected"
98#endif
99
100/* Expected HW ID */
101#define HW_MEZZANINE_NAME "EVAL-AD2S1210SDZ"
102#define HW_NAME "ad2s1210"
103#define HW_VENDOR "Analog Devices"
104#define NUM_CTX_ATTR 4
105
106#define RESOLVER_CHANNELS 3
107#define RESOLVER_MAX_ATTR 10
108
109/* Max count is always 16 bit. LSBs are ignored in lower resolutions */
110#define RESOLVER_MAX_COUNT_UNIPOLAR (uint32_t)(USHRT_MAX)
111#define RESOLVER_MAX_COUNT_BIPOLAR (uint32_t)(SHRT_MAX)
112
113/* Not all resolutions are supported use driver defined resolutions 10, 12, 14, 16 */
114#define AD2S1210_RESOLUTION AD2S1210_RES_16BIT
115
116#define AD2S1210_FCLKIN 8192000
117
118#define MATH_PI 3.1415926f
119/* velocity scale depends on resolution */
120#define AD2S1210_POS_IIO_SCALE (2 * MATH_PI / RESOLVER_MAX_COUNT_UNIPOLAR)
121
122#if (AD2S1210_FCLKIN == 8192000)
123#define AD2S1210_TRACKING_RATE_10BIT 2500
124#define AD2S1210_TRACKING_RATE_12BIT 1000
125#define AD2S1210_TRACKING_RATE_14BIT 500
126#define AD2S1210_TRACKING_RATE_16BIT 125
127#elif (AD2S1210_FCLKIN == 10240000)
128#define AD2S1210_TRACKING_RATE_10BIT 3125
129#define AD2S1210_TRACKING_RATE_12BIT 1250
130#define AD2S1210_TRACKING_RATE_14BIT 625
131#define AD2S1210_TRACKING_RATE_16BIT 156
132#if (AD2S1210_FCLKIN != 10240000)
133#warn "unknown tracking rate"
134#endif
135#endif
136
137/****** Macros used to form a VCOM serial number ******/
138/* Used to form a VCOM serial number */
139#define FIRMWARE_NAME "ad2s1210_iio"
140
141#if !defined(PLATFORM_NAME)
142#define PLATFORM_NAME HW_CARRIER_NAME
143#endif
144
145/* Below USB configurations (VID and PID) are owned and assigned by ADI.
146 * If intended to distribute software further, use the VID and PID owned by your
147 * organization
148 */
149#define VIRTUAL_COM_PORT_VID 0x0456
150#define VIRTUAL_COM_PORT_PID 0xb66c
151#define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" DEVICE_NAME "_" STR(PLATFORM_NAME))
152
153#if defined(USE_PHY_COM_PORT)
154/* If PHY com is selected, VCOM or alternate PHY com port can act as a console stdio port */
155#if (ACTIVE_PLATFORM == MBED_PLATFORM)
156#define CONSOLE_STDIO_PORT_AVAILABLE
157#endif
158#else
159/* If VCOM is selected, PHY com port will/should act as a console stdio port */
160#define CONSOLE_STDIO_PORT_AVAILABLE
161#endif
162
163/* Default baud rate for IIO UART interface */
164#define IIO_UART_BAUD_RATE (230400)
165
166/* Enable/Disable the use of SDRAM for RESOLVER data capture buffer */
167/* #define USE_SDRAM // Uncomment to use SDRAM for data buffer */
168
169/******************************************************************************/
170/********************** Public/Extern Declarations ****************************/
171/******************************************************************************/
172
173extern struct no_os_uart_desc *uart_desc;
174extern struct no_os_irq_ctrl_desc *trigger_irq_desc;
175
176int32_t init_system(void);
177int32_t init_pwm_trigger(void);
178
179#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_desc
Definition app_config.c:97
Header file for Mbed platform configurations.