Dshot RPM Telemetry Refactoring (#13012)
[betaflight.git] / src / main / target / SITL / target.h
blobe51b997e84751a3e88b517f526f068fad4086dbe
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 // SITL (software in the loop) simulator
23 #pragma once
25 #include <stdint.h>
26 #include <stddef.h>
28 #include "common/utils.h"
30 #define TARGET_BOARD_IDENTIFIER "SITL"
32 #define SIMULATOR_MULTITHREAD
34 #define SYSTEM_HSE_MHZ 0
35 #define DEFAULT_CPU_OVERCLOCK 1
36 #define DMA_RAM
37 #define DMA_RW_AXI
38 #define DMA_RAM_R
39 #define DMA_RAM_W
40 #define DMA_RAM_RW
42 #define DMA_DATA_ZERO_INIT
43 #define DMA_DATA
44 #define STATIC_DMA_DATA_AUTO
46 // use simulatior's attitude directly
47 // disable this if wants to test AHRS algorithm
48 #undef USE_IMU_CALC
50 //#define SIMULATOR_ACC_SYNC
51 //#define SIMULATOR_GYRO_SYNC
52 //#define SIMULATOR_IMU_SYNC
53 //#define SIMULATOR_GYROPID_SYNC
55 // file name to save config
56 #define EEPROM_FILENAME "eeprom.bin"
57 #define CONFIG_IN_FILE
58 #define EEPROM_SIZE 32768
60 #define U_ID_0 0
61 #define U_ID_1 1
62 #define U_ID_2 2
64 #undef TASK_GYROPID_DESIRED_PERIOD
65 #define TASK_GYROPID_DESIRED_PERIOD 100
67 #undef SCHEDULER_DELAY_LIMIT
68 #define SCHEDULER_DELAY_LIMIT 1
70 #define USE_VIRTUAL_LED
72 #define USE_ACC
73 #define USE_VIRTUAL_ACC
75 #define USE_GYRO
76 #define USE_VIRTUAL_GYRO
78 #define USE_MAG
79 #define USE_VIRTUAL_MAG
81 #define USE_BARO
82 #define USE_VIRTUAL_BARO
84 #define USABLE_TIMER_CHANNEL_COUNT 0
86 #define USE_UART1
87 #define USE_UART2
88 #define USE_UART3
89 #define USE_UART4
90 #define USE_UART5
91 #define USE_UART6
92 #define USE_UART7
93 #define USE_UART8
95 #define SERIAL_PORT_COUNT 8
97 #define DEFAULT_RX_FEATURE FEATURE_RX_MSP
98 #define DEFAULT_FEATURES (FEATURE_GPS | FEATURE_TELEMETRY)
100 #define USE_PARAMETER_GROUPS
102 #define USE_PWM_OUTPUT
104 #undef USE_STACK_CHECK // I think SITL don't need this
105 #undef USE_DASHBOARD
106 #undef USE_TELEMETRY_LTM
107 #undef USE_ADC
108 #undef USE_VCP
109 #undef USE_OSD
110 #undef USE_RX_PPM
111 #undef USE_RX_PWM
112 #undef USE_SERIALRX
113 #undef USE_SERIALRX_CRSF
114 #undef USE_SERIALRX_GHST
115 #undef USE_SERIALRX_IBUS
116 #undef USE_SERIALRX_SBUS
117 #undef USE_SERIALRX_SPEKTRUM
118 #undef USE_SERIALRX_SUMD
119 #undef USE_SERIALRX_SUMH
120 #undef USE_SERIALRX_XBUS
121 #undef USE_LED_STRIP
122 #undef USE_TELEMETRY_FRSKY_HUB
123 #undef USE_TELEMETRY_HOTT
124 #undef USE_TELEMETRY_SMARTPORT
125 #undef USE_TELEMETRY_MAVLINK
126 #undef USE_RESOURCE_MGMT
127 #undef USE_CMS
128 #undef USE_TELEMETRY_CRSF
129 #undef USE_TELEMETRY_GHST
130 #undef USE_TELEMETRY_IBUS
131 #undef USE_TELEMETRY_JETIEXBUS
132 #undef USE_TELEMETRY_SRXL
133 #undef USE_SERIALRX_JETIEXBUS
134 #undef USE_VTX_COMMON
135 #undef USE_VTX_CONTROL
136 #undef USE_VTX_SMARTAUDIO
137 #undef USE_VTX_TRAMP
138 #undef USE_VTX_MSP
139 #undef USE_CAMERA_CONTROL
140 #undef USE_SERIAL_4WAY_BLHELI_BOOTLOADER
141 #undef USE_SERIAL_4WAY_SK_BOOTLOADER
143 #undef USE_I2C
144 #undef USE_SPI
146 #define TARGET_FLASH_SIZE 2048
149 #define LED_STRIP_TIMER 1
150 #define SOFTSERIAL_1_TIMER 2
151 #define SOFTSERIAL_2_TIMER 3
153 #define DEFIO_NO_PORTS // suppress 'no pins defined' warning
155 #define FLASH_PAGE_SIZE (0x400)
157 // belows are internal stuff
159 extern uint32_t SystemCoreClock;
161 typedef enum
163 Mode_TEST = 0x0,
164 Mode_Out_PP = 0x10
165 } GPIO_Mode;
167 typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
168 typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
169 typedef enum {TEST_IRQ = 0 } IRQn_Type;
170 typedef enum {
171 EXTI_Trigger_Rising = 0x08,
172 EXTI_Trigger_Falling = 0x0C,
173 EXTI_Trigger_Rising_Falling = 0x10
174 } EXTITrigger_TypeDef;
176 typedef struct
178 uint32_t IDR;
179 uint32_t ODR;
180 uint32_t BSRR;
181 uint32_t BRR;
182 } GPIO_TypeDef;
184 #define GPIOA_BASE ((intptr_t)0x0001)
186 typedef struct
188 void* test;
189 } TIM_TypeDef;
191 typedef struct
193 void* test;
194 } TIM_OCInitTypeDef;
196 typedef struct {
197 void* test;
198 } DMA_TypeDef;
200 typedef struct {
201 void* test;
202 } DMA_Channel_TypeDef;
204 typedef struct {
205 void* test;
206 } DMA_InitTypeDef;
208 uint8_t DMA_GetFlagStatus(void *);
209 void DMA_Cmd(DMA_Channel_TypeDef*, FunctionalState );
210 void DMA_ClearFlag(uint32_t);
212 typedef struct
214 void* test;
215 } SPI_TypeDef;
217 typedef struct
219 void* test;
220 } USART_TypeDef;
222 #define USART1 ((USART_TypeDef *)0x0001)
223 #define USART2 ((USART_TypeDef *)0x0002)
224 #define USART3 ((USART_TypeDef *)0x0003)
225 #define USART4 ((USART_TypeDef *)0x0004)
226 #define USART5 ((USART_TypeDef *)0x0005)
227 #define USART6 ((USART_TypeDef *)0x0006)
228 #define USART7 ((USART_TypeDef *)0x0007)
229 #define USART8 ((USART_TypeDef *)0x0008)
231 #define UART4 ((USART_TypeDef *)0x0004)
232 #define UART5 ((USART_TypeDef *)0x0005)
233 #define UART7 ((USART_TypeDef *)0x0007)
234 #define UART8 ((USART_TypeDef *)0x0008)
236 #define SIMULATOR_MAX_RC_CHANNELS 16
237 #define SIMULATOR_MAX_PWM_CHANNELS 16
239 typedef struct
241 void* test;
242 } I2C_TypeDef;
244 typedef enum
246 FLASH_BUSY = 1,
247 FLASH_ERROR_PG,
248 FLASH_ERROR_WRP,
249 FLASH_COMPLETE,
250 FLASH_TIMEOUT
251 } FLASH_Status;
253 typedef struct {
254 double timestamp; // in seconds
255 double imu_angular_velocity_rpy[3]; // rad/s -> range: +/- 8192; +/- 2000 deg/se
256 double imu_linear_acceleration_xyz[3]; // m/s/s NED, body frame -> sim 1G = 9.80665, FC 1G = 256
257 double imu_orientation_quat[4]; //w, x, y, z
258 double velocity_xyz[3]; // m/s, earth frame
259 double position_xyz[3]; // meters, NED from origin
260 double pressure;
261 } fdm_packet;
263 typedef struct {
264 double timestamp; // in seconds
265 uint16_t channels[SIMULATOR_MAX_RC_CHANNELS]; // RC channels
266 } rc_packet;
268 typedef struct {
269 float motor_speed[4]; // normal: [0.0, 1.0], 3D: [-1.0, 1.0]
270 } servo_packet;
272 typedef struct {
273 uint16_t motorCount; // Count of motor in the PWM output.
274 float pwm_output_raw[SIMULATOR_MAX_PWM_CHANNELS]; // Raw PWM from 1100 to 1900
275 } servo_packet_raw;
277 void FLASH_Unlock(void);
278 void FLASH_Lock(void);
279 FLASH_Status FLASH_ErasePage(uintptr_t Page_Address);
280 FLASH_Status FLASH_ProgramWord(uintptr_t addr, uint32_t Data);
282 uint64_t nanos64_real(void);
283 uint64_t micros64_real(void);
284 uint64_t millis64_real(void);
285 void delayMicroseconds_real(uint32_t us);
286 uint64_t micros64(void);
287 uint64_t millis64(void);
289 int lockMainPID(void);
291 int targetParseArgs(int argc, char * argv[]);