Subversion Repositories NaviCtrl

Rev

Rev 781 | Rev 795 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 ingob 1
#ifndef _MAIN_H
2
#define _MAIN_H
1 ingob 3
 
314 killagreg 4
 
318 holgerb 5
//#define FOLLOW_ME
314 killagreg 6
 
7
#ifdef FOLLOW_ME
8
extern u8 TransmitAlsoToFC;
9
#endif
10
 
250 ingob 11
//-----------------------
434 holgerb 12
//#define DEBUG 0
250 ingob 13
//-----------------------
14
 
458 holgerb 15
#define VERSION_MAJOR   2
764 holgerb 16
#define VERSION_MINOR   15
788 holgerb 17
#define VERSION_PATCH   8
283 holgerb 18
// 0 = A
19
// 1 = B
20
// 2 = C
21
// 3 = D
22
// 4 = E
23
// 5 = F
24
// 6 = G
25
// 7 = H
26
// 8 = I
287 holgerb 27
// 9 = J
290 holgerb 28
// 10 = k
291 holgerb 29
// 11 = L
294 holgerb 30
// 12 = M
298 holgerb 31
// 13 = N
338 holgerb 32
// 14 = O
33
// 15 = P
34
// 16 = Q
35
// 17 = R
339 holgerb 36
// 18 = S
1 ingob 37
 
766 holgerb 38
#define CAN_SLAVE_COMPATIBLE     2
317 holgerb 39
#ifndef FOLLOW_ME
780 holgerb 40
#define FC_SPI_COMPATIBLE               84      //   <------------------
317 holgerb 41
#else
316 killagreg 42
#define FC_SPI_COMPATIBLE               0xFF
43
#endif
44
 
229 holgerb 45
#define MK3MAG_I2C_COMPATIBLE   3
607 holgerb 46
#define MAX_MOTORS 16     // since 2.10 (3.2014)
241 killagreg 47
 
320 holgerb 48
// FC.StatusFlags
255 killagreg 49
#define FC_STATUS_MOTOR_RUN                             0x01
50
#define FC_STATUS_FLY                                   0x02
51
#define FC_STATUS_CALIBRATE                             0x04
52
#define FC_STATUS_START                                 0x08
53
#define FC_STATUS_EMERGENCY_LANDING             0x10
54
#define FC_STATUS_LOWBAT                                0x20
279 holgerb 55
#define FC_STATUS_VARIO_TRIM_UP                 0x40
56
#define FC_STATUS_VARIO_TRIM_DOWN               0x80
78 holgerb 57
 
320 holgerb 58
// FC.StatusFlags2
294 holgerb 59
#define FC_STATUS2_CAREFREE                 0x01
60
#define FC_STATUS2_ALTITUDE_CONTROL         0x02
322 holgerb 61
#define FC_STATUS2_RC_FAILSAVE_ACTIVE       0x04
360 holgerb 62
#define FC_STATUS2_OUT1_ACTIVE                  0x08
63
#define FC_STATUS2_OUT2_ACTIVE                  0x10
447 holgerb 64
#define FC_STATUS2_WAIT_FOR_TAKEOFF             0x20   // Motor Running, but still on the ground
699 holgerb 65
#define FC_STATUS2_AUTO_STARTING                0x40
66
#define FC_STATUS2_AUTO_LANDING                 0x80
294 holgerb 67
 
573 holgerb 68
// FC.StatusFlags3 
616 holgerb 69
#define FC_STATUS3_REDUNDANCE_AKTIVE        0x01
573 holgerb 70
#define FC_STATUS3_BOAT                         0x02
616 holgerb 71
#define FC_STATUS3_REDUNDANCE_ERROR                     0x04
72
#define FC_STATUS3_REDUNDANCE_TEST                      0x08
699 holgerb 73
#define FC_STATUS3_NOT_CALIBRATED                       0x10
74
#define FC_STATUS3_MOTORS_STOPPED_BY_RC         0x20
573 holgerb 75
 
788 holgerb 76
 
77
// xxx.OSDStatusFlags   (multiple data sets)    -> this is the definition in the OSD data structure 
78
#define OSD_FLAG_CAREFREE                       0x01
79
#define OSD_FLAG_ALTITUDE_CONTROL               0x02
80
#define OSD_FLAG_CALIBRATE                              0x04
81
#define OSD_FLAG_OUT1_ACTIVE                            0x08
82
#define OSD_FLAG_OUT2_ACTIVE                            0x10
83
#define OSD_FLAG_LOWBAT                                 0x20
84
#define OSD_FLAG_VARIO_TRIM_UP                  0x40
85
#define OSD_FLAG_VARIO_TRIM_DOWN                0x80
86
 
87
// NaviData_Flags.OSDStatusFlags2 (Index:11)    -> this is the definition in the OSD data structure 
88
#define OSD2_FLAG_MOTOR_RUN                             0x01
89
#define OSD2_FLAG_FLY                                   0x02
90
#define OSD2_FLAG_RC_FAILSAVE_ACTIVE        0x04
91
#define OSD2_FLAG_START                                 0x08
92
#define OSD2_FLAG_EMERGENCY_LANDING             0x10
93
#define OSD2_FLAG_WAIT_FOR_TAKEOFF              0x20   // Motor Running, but still on the ground
94
#define OSD2_FLAG_AUTO_STARTING                 0x40
95
#define OSD2_FLAG_AUTO_LANDING                  0x80
96
 
97
 
98
// the OSD-Flags are built from the FC status flags. They are combined into new bytes to increse the efficiency in the data protocol
595 holgerb 99
#define OSD_FLAG_MASK1 (0x04 + 0x20 + 0x40 + 0x80)
100
#define OSD_FLAG_MASK2 (0x01 + 0x02 + 0x08 + 0x10)
101
 
788 holgerb 102
// NC calculates
103
//OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
104
//OSDStatusFlags2 = (FC.StatusFlags & ~OSD_FLAG_MASK1) | (FC.StatusFlags2 & ~OSD_FLAG_MASK2);
105
 
106
//calculate Back:
107
//FC.StatusFlags = (OSDStatusFlags & OSD_FLAG_MASK1) | (OSDStatusFlags2 & ~OSD_FLAG_MASK1);
108
//FC.StatusFlags2 = (OSDStatusFlags & OSD_FLAG_MASK2) | (OSDStatusFlags2 & ~OSD_FLAG_MASK2);
109
 
110
 
595 holgerb 111
// .NCFlags
112
#define NC_FLAG_FREE                    0x01
113
#define NC_FLAG_PH                              0x02
114
#define NC_FLAG_CH                              0x04
115
#define NC_FLAG_RANGE_LIMIT             0x08
116
#define NC_FLAG_NOSERIALLINK    0x10
117
#define NC_FLAG_TARGET_REACHED  0x20
118
#define NC_FLAG_MANUAL_CONTROL  0x40
119
#define NC_FLAG_GPS_OK                  0x80
120
 
764 holgerb 121
//IO1_Function
122
#define IO1FUNC_PARACHUTE                       9
123
#define IO1FUNC_ERROR_PARACHUTE         255
595 holgerb 124
 
125
// NC calculates
126
//OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
127
//OSDStatusFlags2 = (FC.StatusFlags & ~OSD_FLAG_MASK1) | (FC.StatusFlags2 & ~OSD_FLAG_MASK2);
128
 
129
//calculate Back:
130
//FC.StatusFlags = (OSDStatusFlags & OSD_FLAG_MASK1) | (OSDStatusFlags2 & ~OSD_FLAG_MASK1);
131
//FC.StatusFlags2 = (OSDStatusFlags & OSD_FLAG_MASK2) | (OSDStatusFlags2 & ~OSD_FLAG_MASK2);
132
 
707 holgerb 133
// FC.Error[0]
255 killagreg 134
#define FC_ERROR0_GYRO_NICK     0x01
135
#define FC_ERROR0_GYRO_ROLL     0x02
136
#define FC_ERROR0_GYRO_YAW              0x04
137
#define FC_ERROR0_ACC_NICK              0x08
138
#define FC_ERROR0_ACC_ROLL              0x10
139
#define FC_ERROR0_ACC_TOP               0x20
140
#define FC_ERROR0_PRESSURE              0x40
141
#define FC_ERROR0_CAREFREE              0x80
142
 
707 holgerb 143
// FC.Error[1]
255 killagreg 144
#define FC_ERROR1_I2C                   0x01
145
#define FC_ERROR1_BL_MISSING    0x02
146
#define FC_ERROR1_SPI_RX                0x04
147
#define FC_ERROR1_PPM                   0x08
148
#define FC_ERROR1_MIXER                 0x10
707 holgerb 149
#define FC_ERROR1_RC_VOLTAGE    0x20
150
#define FC_ERROR1_ACC_NOT_CAL   0x40
255 killagreg 151
#define FC_ERROR1_RES3                  0x80
152
 
146 killagreg 153
// NC Errors
154
#define NCERR_FLAG_FC_COMPATIBLE                        0x00000001
155
#define NCERR_FLAG_MK3MAG_COMPATIBLE            0x00000002
156
#define NCERR_FLAG_FC_COMMUNICATION                     0x00000004
157
#define NCERR_FLAG_MK3MAG_COMMUNICATION         0x00000008
158
#define NCERR_FLAG_MKGPS_COMMUNICATION          0x00000010
159
#define NCERR_FLAG_BAD_COMPASS_HEADING          0x00000020
160
#define NCERR_FLAG_RC_SIGNAL_LOST                       0x00000040
264 killagreg 161
#define NCERR_FLAG_EEPROM_NOT_FOUND                     0x00000080
49 ingob 162
 
625 holgerb 163
//NC_To_FC_Flags
781 holgerb 164
#define NC_TO_FC_FLYING_RANGE                           0x01
165
#define NC_TO_FC_EMERGENCY_LANDING                      0x02
166
#define NC_TO_FC_AUTOSTART                                      0x04
167
#define NC_TO_FC_FAILSAFE_LANDING                       0x08 // activates Servos
168
#define NC_TO_FC_SIMULATION_ACTIVE                      0x10 // don't start motors if simulation ist active
169
#define NC_TO_FC_SWITCHOFF_IF_LANDED            0x20 // switch off if MK is on the ground and doesn't further sink
625 holgerb 170
 
350 holgerb 171
//Parameter.GlobalConfig3
172
#define CFG3_NO_SDCARD_NO_START                 0x01
764 holgerb 173
#define CFG3_RISE_FIRST_WAYPOINT                0x02
350 holgerb 174
#define CFG3_VARIO_FAILSAFE                     0x04
398 holgerb 175
#define CFG3_MOTOR_SWITCH_MODE                  0x08
176
#define CFG3_NO_GPSFIX_NO_START                 0x10
764 holgerb 177
#define CFG3_USE_NC_FOR_OUT1                    0x20
178
#define CFG3_SPEAK_ALL                          0x40
179
#define CFG3_SERVO_NICK_COMP_OFF                0x80
350 holgerb 180
 
320 holgerb 181
// Parameter.GlobalConfig
331 holgerb 182
#define FC_CFG_HOEHENREGELUNG           0x01
183
#define FC_CFG_HOEHEN_SCHALTER          0x02
184
#define FC_CFG_HEADING_HOLD             0x04
185
#define FC_CFG_KOMPASS_AKTIV            0x08
186
#define FC_CFG_KOMPASS_FIX              0x10
187
#define FC_CFG_GPS_AKTIV                0x20
188
#define FC_CFG_ACHSENKOPPLUNG_AKTIV     0x40
189
#define FC_CFG_DREHRATEN_BEGRENZER      0x80
190 killagreg 190
 
489 killagreg 191
//Parameter.ExtraConfig
331 holgerb 192
#define CFG2_HEIGHT_LIMIT                       0x01
193
#define CFG2_VARIO_BEEP                         0x02
194
#define CFG_SENSITIVE_RC                        0x04
195
#define CFG_3_3V_REFERENCE                      0x08
196
#define CFG_NO_RCOFF_BEEPING                    0x10
197
#define CFG_GPS_AID                             0x20
198
#define CFG_TEACHABLE_CAREFREE                  0x40
199
#define CFG_IGNORE_MAG_ERR_AT_STARTUP   0x80
320 holgerb 200
 
588 holgerb 201
// Parameter.HomeYawMode
202
#define NO_CHANGE               0
203
#define FRONT_TO_HOME   1
204
#define REAR_TO_HOME    2
205
#define LIKE_AT_START   3
206
 
587 holgerb 207
// Parameter.ReceiverType defines for the receiver selection
208
#define RECEIVER_PPM                            0
209
#define RECEIVER_SPEKTRUM                       1
210
#define RECEIVER_SPEKTRUM_HI_RES        2
211
#define RECEIVER_SPEKTRUM_LOW_RES       3
212
#define RECEIVER_JETI                           4
213
#define RECEIVER_ACT_DSL                        5
214
#define RECEIVER_HOTT                           6
215
#define RECEIVER_SBUS                           7
216
#define RECEIVER_USER                           8
217
 
218
#define RECEIVER_UNKNOWN                        0xFF
219
 
190 killagreg 220
#define LIMIT_MIN(value, min) {if(value <= min) value = min;}
221
#define LIMIT_MAX(value, max) {if(value >= max) value = max;}
222
#define LIMIT_MIN_MAX(value, min, max) {if(value <= min) value = min; else if(value >= max) value = max;}
223
 
327 holgerb 224
 
225
#define Poti1  FC.Poti[0]
226
#define Poti2  FC.Poti[1]
227
#define Poti3  FC.Poti[2]
228
#define Poti4  FC.Poti[3]
229
#define Poti5  FC.Poti[4]
230
#define Poti6  FC.Poti[5]
231
#define Poti7  FC.Poti[6]
232
#define Poti8  FC.Poti[7]
233
 
780 holgerb 234
extern s16 LuftdruckTemperaturKompensation, LuftdruckTemperaturOffset;
41 ingob 235
extern u16 BeepTime;
92 killagreg 236
extern u8  NCFlags;
255 killagreg 237
extern u8 ClearFCStatusFlags;
41 ingob 238
void Interrupt_Init(void);
153 killagreg 239
extern s16 GeoMagDec;
504 holgerb 240
extern u8 NewWPL_Name;
1 ingob 241
 
699 holgerb 242
#define NOTHING                 0
243
#define MASTER                  1
244
#define SLAVE                   2
245
extern u8 IamMaster;
246
 
505 holgerb 247
#define VERSION_SERIAL_MAJOR    11 // do not change!
248
 
41 ingob 249
typedef struct
250
{
251
        u8 ActiveSetting;
252
        u8 User1;
253
        u8 User2;
254
        u8 User3;
255
        u8 User4;
256
        u8 User5;
257
        u8 User6;
258
        u8 User7;
259
        u8 User8;
260
        u8 NaviGpsModeControl;
261
        u8 NaviGpsGain;
262
        u8 NaviGpsP;
263
        u8 NaviGpsI;
264
        u8 NaviGpsD;
56 holgerb 265
        u8 NaviGpsPLimit;
266
        u8 NaviGpsILimit;
267
        u8 NaviGpsDLimit;
41 ingob 268
        u8 NaviGpsACC;
269
        u8 NaviGpsMinSat;
270
        u8 NaviStickThreshold;
532 holgerb 271
        u8 NaviMaxFlyingRange; // in 10m
41 ingob 272
        u8 NaviWindCorrection;
327 holgerb 273
        u8 NaviAccCompensation;
41 ingob 274
        u8 NaviSpeedCompensation;
275
        u8 LowVoltageWarning;
276
        u8 NaviAngleLimitation;
56 holgerb 277
        u8 NaviPH_LoginTime;
544 holgerb 278
        u8 OrientationAngle; // where is front - in 15°
279
        u8 CamOrientation;       // direction of the camera in 15°
320 holgerb 280
        u8 GlobalConfig;
281
        u8 ExtraConfig;
321 holgerb 282
        u8 ComingHomeAltitude;
350 holgerb 283
        u8 GlobalConfig3;
516 holgerb 284
        u8 AutoPhotoDistance; // Distance between Photo releases (Position)
489 killagreg 285
        u8 FromFC_LandingSpeed;
286
        u8 FromFC_LowVoltageHomeActive;
516 holgerb 287
        u8 AutoPhotoAltitudes; // Distance between Photo releases (Altitudes)
519 holgerb 288
        u8 SingleWpSpeed;
532 holgerb 289
        u8 DescendRange; // in 10m
290
        u8 MaximumAltitude; // in m
573 holgerb 291
        u8 Driftkomp;
587 holgerb 292
        u8 ReceiverType;
588 holgerb 293
        u8 HomeYawMode;
624 holgerb 294
        u8 Speak100m;
295
        u8 AutoWpEventValue;
646 holgerb 296
        u8 FailSafeTime;
41 ingob 297
} __attribute__((packed)) Param_t;
1 ingob 298
 
41 ingob 299
typedef struct
300
{
301
        s8 StickNick;
302
        s8 StickRoll;
303
        s8 StickYaw;
304
        s8 StickGas;
190 killagreg 305
        u8 Poti[8];
41 ingob 306
        u8 RC_Quality;
125 killagreg 307
        u8 RC_RSSI;
595 holgerb 308
        u16 BAT_Voltage;
206 killagreg 309
        u16 BAT_Current;
310
        u16 BAT_UsedCapacity;
255 killagreg 311
        u8 StatusFlags;
312
        u8 Error[5];
294 holgerb 313
        u8 StatusFlags2;
436 holgerb 314
        u8 FromFC_SpeakHoTT;
489 killagreg 315
        s16 FromFC_CompassOffset;
316
        u8 FromFC_DisableDeclination;
573 holgerb 317
        u8 StatusFlags3;
739 holgerb 318
        s16 Altimeter_5cm;  // devide by 20 to get meters & multiply with 5 to get cm
573 holgerb 319
        u8 RealStatusFlags; // this is a copy of the status flags -> but not effected by the simulation
320
        u16 AdNeutralNick;
321
        u16 AdNeutralRoll;
322
        u16 AdNeutralYaw;
587 holgerb 323
        u16 BoatNeutralNick;
324
        u16 BoatNeutralRoll;
325
        u16 BoatNeutralYaw;
607 holgerb 326
        u8 AutoPhotoDistance;
489 killagreg 327
} __attribute__((packed)) FC_t; // from FC
1 ingob 328
 
699 holgerb 329
typedef struct
330
{
331
        u8 ErrorCode;
332
        u8 StatusFlags;
333
        u8 StatusFlags2;
334
        u8 StatusFlags3;
335
        u8 NC_To_FC_Flags;
336
        u8 MagnetField;                                         // in %
337
        s16 GyroCompassCorrected;
338
} __attribute__((packed)) Partner_t;    // from FC
339
 
340
extern Partner_t Partner;
41 ingob 341
extern Param_t Parameter;
78 holgerb 342
extern volatile FC_t FC;
41 ingob 343
extern s8 ErrorMSG[25];
699 holgerb 344
extern s8 PartnerErrorMSG[25];
345
extern u8 ErrorCode,PartnerErrorCode;
41 ingob 346
extern u8 StopNavigation;
328 holgerb 347
extern u8 ErrorGpsFixLost;
513 killagreg 348
extern u8 FromFC_LoadWP_List, ToFC_MaxWpListIndex, FromFC_Load_SinglePoint, FromFC_Save_SinglePoint;
378 holgerb 349
extern volatile u32 SPIWatchDog; // stop Navigation if this goes to zero
362 holgerb 350
extern volatile u32 SD_WatchDog; // stop Logging if this goes to zero
378 holgerb 351
extern volatile u32 PollingTimeout;
663 holgerb 352
extern u32 CountGpsProcessedIn5Sec,CountNewGpsDataIn5Sec, FreqGpsNavProcessed, FreqNewGpsData;
353
extern u32 TimeSinceMotorStart;
699 holgerb 354
extern u8 NC_To_FC_Flags, NC_To_FC_Autostart;
514 holgerb 355
extern u16 SD_SettingWaitLED;
356
extern u16 SD_PosAccuracy;
357
extern u16 SD_ComingHomeSpeed;
358
extern u16 SD_DPH_Speed;
532 holgerb 359
extern u32 MaxWP_Radius_in_m;
519 holgerb 360
extern u8 SpeakWaypointRached;  // Speak once as soon as the Points are active
549 holgerb 361
extern u8 SpeakNextWaypoint;    // Speak once when reached
362
extern u8 NewWaypointsReceived; // when 1: activates the Waypoint list as soon as CH is started
699 holgerb 363
extern s16 GyroCompassCorrected;
364
extern s16 CompassSetpointCorrected; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination
365
extern s16 CompassSetpoint;
366
extern u8 AmountOfMotors;
764 holgerb 367
extern s16 SimulatedDirection;          // simulated compass direction
368
extern u16 ToFC_Parachute_Off;          // forced Switch off via IO1
369
extern u8 IO1_Function;
780 holgerb 370
extern u8 BaroCalState;
764 holgerb 371
#define OEM_NAME_LENGHT 16
372
extern u8 OEM_String[OEM_NAME_LENGHT+1];
514 holgerb 373
 
529 holgerb 374
#define CHECK_ONLY     0
375
#define GET_LICENSE    1
376
#define COPY_SD_TO_EE  2
377
extern u8 CheckLicense(u8);
378
 
681 holgerb 379
// Portpin inputs
707 holgerb 380
#define PIN6_0 (GPIO6->DR[0x3FC] & 0x01)
381
#define PIN6_1 (GPIO6->DR[0x3FC] & 0x02)
382
#define PIN6_2 (GPIO6->DR[0x3FC] & 0x04)
681 holgerb 383
#define PIN6_3 (GPIO6->DR[0x3FC] & 0x08)
384
#define PIN6_4 (GPIO6->DR[0x3FC] & 0x10)
385
#define PIN6_5 (GPIO6->DR[0x3FC] & 0x20)
386
 
707 holgerb 387
#define TRIGGER_PP_INTERN PIN6_0
388
#define TRIGGER_PP_EXTERN PIN6_3
389
#define BLITZ_CONNECTED   PIN6_4
764 holgerb 390
#define IO1_INPUT                 PIN6_5
681 holgerb 391
 
41 ingob 392
#endif // _MAIN_H