Subversion Repositories NaviCtrl

Rev

Rev 519 | Rev 532 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 519 Rev 530
1
#ifndef _SPI_SLAVE_H
1
#ifndef _SPI_SLAVE_H
2
#define _SPI_SLAVE_H
2
#define _SPI_SLAVE_H
3
 
3
 
4
#include "fifo.h"
4
#include "fifo.h"
5
#include "gps.h"
5
#include "gps.h"
6
 
6
 
7
#define SPEAK_ERR_CALIBARTION  1
7
#define SPEAK_ERR_CALIBARTION  1
8
#define SPEAK_ERR_RECEICER       2
8
#define SPEAK_ERR_RECEICER       2
9
#define SPEAK_ERR_DATABUS        3
9
#define SPEAK_ERR_DATABUS        3
10
#define SPEAK_ERR_NAVI           4
10
#define SPEAK_ERR_NAVI           4
11
#define SPEAK_ERROR                      5
11
#define SPEAK_ERROR                      5
12
#define SPEAK_ERR_COMPASS        6
12
#define SPEAK_ERR_COMPASS        6
13
#define SPEAK_ERR_SENSOR         7
13
#define SPEAK_ERR_SENSOR         7
14
#define SPEAK_ERR_GPS            8
14
#define SPEAK_ERR_GPS            8
15
#define SPEAK_ERR_MOTOR          9
15
#define SPEAK_ERR_MOTOR          9
16
#define SPEAK_MAX_TEMPERAT  10
16
#define SPEAK_MAX_TEMPERAT  10
17
#define SPEAK_ALTI_REACHED  11
17
#define SPEAK_ALTI_REACHED  11
18
#define SPEAK_WP_REACHED    12
18
#define SPEAK_WP_REACHED    12
19
#define SPEAK_NEXT_WP       13
19
#define SPEAK_NEXT_WP       13
20
#define SPEAK_LANDING       14
20
#define SPEAK_LANDING       14
21
#define SPEAK_GPS_FIX       15
21
#define SPEAK_GPS_FIX       15
22
#define SPEAK_UNDERVOLTAGE  16
22
#define SPEAK_UNDERVOLTAGE  16
23
#define SPEAK_GPS_HOLD      17
23
#define SPEAK_GPS_HOLD      17
24
#define SPEAK_GPS_HOME      18
24
#define SPEAK_GPS_HOME      18
25
#define SPEAK_GPS_OFF       19
25
#define SPEAK_GPS_OFF       19
26
#define SPEAK_BEEP          20
26
#define SPEAK_BEEP          20
27
#define SPEAK_MIKROKOPTER   21
27
#define SPEAK_MIKROKOPTER   21
28
#define SPEAK_CAPACITY      22
28
#define SPEAK_CAPACITY      22
29
#define SPEAK_CF_OFF        23
29
#define SPEAK_CF_OFF        23
30
#define SPEAK_CALIBRATE     24
30
#define SPEAK_CALIBRATE     24
31
#define SPEAK_MAX_RANGE     25
31
#define SPEAK_MAX_RANGE     25
32
#define SPEAK_MAX_ALTITUD   26
32
#define SPEAK_MAX_ALTITUD   26
33
 
33
 
34
#define SPEAK_MK_OFF            38
34
#define SPEAK_MK_OFF            38
35
#define SPEAK_ALTITUDE_ON       39
35
#define SPEAK_ALTITUDE_ON       39
36
#define SPEAK_ALTITUDE_OFF      40
36
#define SPEAK_ALTITUDE_OFF      40
37
#define SPEAK_CF_ON             46
37
#define SPEAK_CF_ON             46
38
#define SPEAK_SINKING           47
38
#define SPEAK_SINKING           47
39
#define SPEAK_RISING            48
39
#define SPEAK_RISING            48
40
#define SPEAK_HOLDING           49
40
#define SPEAK_HOLDING           49
41
#define SPEAK_GPS_ON            50
41
#define SPEAK_GPS_ON            50
42
#define SPEAK_FOLLWING          51
42
#define SPEAK_FOLLWING          51
43
#define SPEAK_STARTING      52
43
#define SPEAK_STARTING      52
44
 
44
 
45
 
45
 
46
#define SS_PIN GPIO_ReadBit(GPIO2, GPIO_Pin_7)
46
#define SS_PIN GPIO_ReadBit(GPIO2, GPIO_Pin_7)
47
 
47
 
48
#define SPI_FCCMD_USER                  10
48
#define SPI_FCCMD_USER                  10
49
#define SPI_FCCMD_STICK                 11
49
#define SPI_FCCMD_STICK                 11
50
#define SPI_FCCMD_MISC                  12
50
#define SPI_FCCMD_MISC                  12
51
#define SPI_FCCMD_PARAMETER1    13
51
#define SPI_FCCMD_PARAMETER1    13
52
#define SPI_FCCMD_VERSION               14
52
#define SPI_FCCMD_VERSION               14
53
#define SPI_FCCMD_SERVOS                15
53
#define SPI_FCCMD_SERVOS                15
54
#define SPI_FCCMD_BL_ACCU               16
54
#define SPI_FCCMD_BL_ACCU               16
55
#define SPI_FCCMD_PARAMETER2    17
55
#define SPI_FCCMD_PARAMETER2    17
56
 
56
 
57
#define CHK_POTI(b,a) { if(a < 248) b = a; else b = FC.Poti[255 - a]; }
57
#define CHK_POTI(b,a) { if(a < 248) b = a; else b = FC.Poti[255 - a]; }
58
#define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max); }
58
#define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max); }
59
 
59
 
60
// devides only the Poti-value
60
// devides only the Poti-value
61
#define CHK_POTI_DIV(b,a,div) { if(a < 248) b = a; else b = FC.Poti[255 - a] / div; }
61
#define CHK_POTI_DIV(b,a,div) { if(a < 248) b = a; else b = FC.Poti[255 - a] / div; }
62
#define CHK_POTI_MM_DIV(b,a,min,max,div) {CHK_POTI_DIV(b,a,div); LIMIT_MIN_MAX(b, min, max); }
62
#define CHK_POTI_MM_DIV(b,a,min,max,div) {CHK_POTI_DIV(b,a,div); LIMIT_MIN_MAX(b, min, max); }
63
 
63
 
64
extern s32 Kalman_K;
64
extern s32 Kalman_K;
65
extern s32 Kalman_Kompass ;
65
extern s32 Kalman_Kompass ;
66
extern s32 Kalman_MaxDrift;
66
extern s32 Kalman_MaxDrift;
67
extern s32 Kalman_MaxFusion;
67
extern s32 Kalman_MaxFusion;
68
extern s32 ToFcGpsZ;
68
extern s32 ToFcGpsZ;
69
extern s32 ToFC_Rotate_C, ToFC_Rotate_S;
69
extern s32 ToFC_Rotate_C, ToFC_Rotate_S;
70
extern s32 HeadFreeStartAngle;
70
extern s32 HeadFreeStartAngle;
71
extern s16 FC_WP_EventChannel,LogFC_WP_EventChannel;
71
extern s16 FC_WP_EventChannel,LogFC_WP_EventChannel;
72
extern u32 ToFC_AltitudeRate;
72
extern u32 ToFC_AltitudeRate;
73
extern s32 ToFC_AltitudeSetpoint;
73
extern s32 ToFC_AltitudeSetpoint;
74
extern u8 NC_GPS_ModeCharacter;
74
extern u8 NC_GPS_ModeCharacter;
75
extern u8 FC_is_Calibrated;
75
extern u8 FC_is_Calibrated;
76
extern u8 FCCalibActive;
76
extern u8 FCCalibActive;
77
extern u8 SpeakHoTT;
77
extern u8 SpeakHoTT;
78
extern u8 NC_Wait_for_LED;
78
extern u8 NC_Wait_for_LED;
79
extern s16 GyroCompassCorrected;
79
extern s16 GyroCompassCorrected;
80
extern s16 CompassSetpointCorrected; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination
80
extern s16 CompassSetpointCorrected; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination
81
extern s16 CompassSetpoint;
81
extern s16 CompassSetpoint;
-
 
82
extern u8 AmountOfMotors;
82
           
83
           
-
 
84
extern u8 BL_MinOfMaxPWM;  // indication if all BL-controllers run on full power
-
 
85
extern u8 Logging_BL_MinOfMaxPWM;
83
extern u8 BL_MinOfMaxPWM;  // indication if all BL-controllers run on full power
86
extern u8 ErrorCheck_BL_MinOfMaxPWM;
84
extern u32 FC_I2C_ErrorConter;
87
extern u32 FC_I2C_ErrorConter;
85
extern u8 FromFC_VarioCharacter;
88
extern u8 FromFC_VarioCharacter;
86
extern u8 Logging_FCStatusFlags1,Logging_FCStatusFlags2;
89
extern u8 Logging_FCStatusFlags1,Logging_FCStatusFlags2;
87
extern s16 POI_KameraNick;
90
extern s16 POI_KameraNick;
88
extern u8 NC_To_FC_Flags, NC_To_FC_Autostart;
91
extern u8 NC_To_FC_Flags, NC_To_FC_Autostart;
-
 
92
 
89
typedef struct
93
typedef struct
90
{
94
{
91
        u8   Command;
95
        u8   Command;
92
        s16  AngleNick;  // NickAngle in 0.1 deg
96
        s16  AngleNick;  // NickAngle in 0.1 deg
93
        s16  AngleRoll;  // RollAngle in 0.1 deg
97
        s16  AngleRoll;  // RollAngle in 0.1 deg
94
        s16  AccNick;
98
        s16  AccNick;
95
        s16  AccRoll;
99
        s16  AccRoll;
96
        s16  GyroHeading; // Heading in 0.1 deg
100
        s16  GyroHeading; // Heading in 0.1 deg
97
        s16  GyroNick;
101
        s16  GyroNick;
98
        s16  GyroRoll;
102
        s16  GyroRoll;
99
        s16  GyroYaw;
103
        s16  GyroYaw;
100
        u16  FCStatus;
104
        u16  FCStatus;
101
        union
105
        union
102
        {
106
        {
103
                u8    Byte[12];
107
                u8    Byte[12];
104
                s8        sByte[12];
108
                s8        sByte[12];
105
                u16   Int[6];
109
                u16   Int[6];
106
                s16   sInt[6];
110
                s16   sInt[6];
107
                u32   Long[3];
111
                u32   Long[3];
108
                s32   sLong[3];
112
                s32   sLong[3];
109
                float Float[3];
113
                float Float[3];
110
        } Param;
114
        } Param;
111
        u8 Chksum;
115
        u8 Chksum;
112
 } __attribute__((packed)) FromFlightCtrl_t;
116
 } __attribute__((packed)) FromFlightCtrl_t;
113
 
117
 
114
//NC_To_FC_Flags
118
//NC_To_FC_Flags
115
#define NC_TO_FC_FLYING_RANGE           0x01
119
#define NC_TO_FC_FLYING_RANGE           0x01
116
#define NC_TO_FC_EMERGENCY_LANDING      0x02
120
#define NC_TO_FC_EMERGENCY_LANDING      0x02
117
#define NC_TO_FC_AUTOSTART                      0x04
121
#define NC_TO_FC_AUTOSTART                      0x04
118
#define NC_TO_FC_AUTOLANDING            0x08 // not used
122
#define NC_TO_FC_AUTOLANDING            0x08 // not used
119
 
123
 
120
#define SPI_NCCMD_OSD_DATA              100
124
#define SPI_NCCMD_OSD_DATA              100
121
#define SPI_NCCMD_GPS_POS               101
125
#define SPI_NCCMD_GPS_POS               101
122
#define SPI_NCCMD_GPS_TARGET    102
126
#define SPI_NCCMD_GPS_TARGET    102
123
#define SPI_NCCMD_KALMAN                103
127
#define SPI_NCCMD_KALMAN                103
124
#define SPI_NCCMD_VERSION               104
128
#define SPI_NCCMD_VERSION               104
125
#define SPI_NCCMD_GPSINFO               105
129
#define SPI_NCCMD_GPSINFO               105
126
#define SPI_NCCMD_HOTT_INFO             106
130
#define SPI_NCCMD_HOTT_INFO             106
127
#define SPI_MISC                                107
131
#define SPI_MISC                                107
128
 
132
 
129
#define HOTT_VARIO_PACKET_ID            0x89
133
#define HOTT_VARIO_PACKET_ID            0x89
130
#define HOTT_GPS_PACKET_ID                      0x8A
134
#define HOTT_GPS_PACKET_ID                      0x8A
131
#define HOTT_ELECTRIC_AIR_PACKET_ID     0x8E
135
#define HOTT_ELECTRIC_AIR_PACKET_ID     0x8E
132
#define HOTT_GENERAL_PACKET_ID          0x8D
136
#define HOTT_GENERAL_PACKET_ID          0x8D
133
#define JETI_GPS_PACKET_ID1                     0x01
137
#define JETI_GPS_PACKET_ID1                     0x01
134
#define JETI_GPS_PACKET_ID2                     0x02
138
#define JETI_GPS_PACKET_ID2                     0x02
135
#define HOTT_WPL_NAME                           0x03
139
#define HOTT_WPL_NAME                           0x03
136
 
140
 
137
typedef struct
141
typedef struct
138
{
142
{
139
        u8 Command;
143
        u8 Command;
140
        GPS_Stick_t GPSStick;
144
        GPS_Stick_t GPSStick;
141
        s16 MagVecX;
145
        s16 MagVecX;
142
        s16 CompassHeading;
146
        s16 CompassHeading;
143
        s16 AccErrorN;
147
        s16 AccErrorN;
144
        s16 AccErrorR;
148
        s16 AccErrorR;
145
        s16 MagVecY;
149
        s16 MagVecY;
146
        s16 MagVecZ;
150
        s16 MagVecZ;
147
        u16 BeepTime;
151
        u16 BeepTime;
148
        union
152
        union
149
        {
153
        {
150
                u8    Byte[12];
154
                u8    Byte[12];
151
                s8    sByte[12];
155
                s8    sByte[12];
152
                u16       Int[6];
156
                u16       Int[6];
153
                s16   sInt[6];
157
                s16   sInt[6];
154
                u32   Long[3];
158
                u32   Long[3];
155
                s32   sLong[3];
159
                s32   sLong[3];
156
                float Float[3];
160
                float Float[3];
157
        }Param;
161
        }Param;
158
        u8 Chksum;
162
        u8 Chksum;
159
 } __attribute__((packed)) ToFlightCtrl_t;
163
 } __attribute__((packed)) ToFlightCtrl_t;
160
 
164
 
161
typedef struct
165
typedef struct
162
{
166
{
163
 u8 Current;
167
 u8 Current;
164
 u8 Temperature;
168
 u8 Temperature;
165
 u8 MaxPWM;
169
 u8 MaxPWM;
166
 u8 State;
170
 u8 State;
-
 
171
 u8 NotReadyCnt;
167
} __attribute__((packed)) Motor_t;
172
} __attribute__((packed)) Motor_t;
168
 
173
 
169
extern Motor_t Motor[12];
174
extern Motor_t Motor[12];
170
 
175
 
171
#define MOTOR_STATE_NEW_PROTOCOL_MASK   0x01
176
#define MOTOR_STATE_NEW_PROTOCOL_MASK   0x01
172
#define MOTOR_STATE_FAST_MODE           0x02
177
#define MOTOR_STATE_FAST_MODE           0x02
173
#define MOTOR_STATE_BL30                0x04   // extended Current measurement -> 200 = 20A    201 = 21A    255 = 75A (20+55)
178
#define MOTOR_STATE_BL30                0x04   // extended Current measurement -> 200 = 20A    201 = 21A    255 = 75A (20+55)
174
extern u8 Motor_Version[12]; // das kann nicht in die struct, weil der PC die Struktur bekommt
179
extern u8 Motor_Version[12]; // das kann nicht in die struct, weil der PC die Struktur bekommt
175
 
180
 
176
 
181
 
177
 
182
 
178
typedef struct
183
typedef struct
179
{
184
{
180
   u8 Major;
185
   u8 Major;
181
   u8 Minor;
186
   u8 Minor;
182
   u8 Patch;
187
   u8 Patch;
183
   u8 Compatible;
188
   u8 Compatible;
184
   u8 Hardware;
189
   u8 Hardware;
185
} __attribute__((packed)) SPI_Version_t;
190
} __attribute__((packed)) SPI_Version_t;
186
 
191
 
187
extern FromFlightCtrl_t   FromFlightCtrl;
192
extern FromFlightCtrl_t   FromFlightCtrl;
188
extern ToFlightCtrl_t     ToFlightCtrl;
193
extern ToFlightCtrl_t     ToFlightCtrl;
189
extern volatile u32 SPI0_Timeout;
194
extern volatile u32 SPI0_Timeout;
190
extern SPI_Version_t FC_Version;
195
extern SPI_Version_t FC_Version;
191
extern s16 GPS_Aid_StickMultiplikator;
196
extern s16 GPS_Aid_StickMultiplikator;
192
extern u8 CompassCalState;
197
extern u8 CompassCalState;
193
 
198
 
194
void SPI0_Init(void);
199
void SPI0_Init(void);
195
void SPI0_GetFlightCtrlVersion(void);
200
void SPI0_GetFlightCtrlVersion(void);
196
void SPI0_UpdateBuffer(void);
201
void SPI0_UpdateBuffer(void);
197
u16 BL3_Current(u8 who); // in 0.1A
202
u16 BL3_Current(u8 who); // in 0.1A
198
 
203
 
199
#endif //_SPI_SLAVE_H
204
#endif //_SPI_SLAVE_H
200
 
205