Rev 532 | Rev 573 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 532 | Rev 559 | ||
---|---|---|---|
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 | extern u8 AmountOfMotors; |
- | 83 | extern s16 SimulatedDirection; // simulated compass direction |
|
83 | 84 | ||
84 | extern u8 BL_MinOfMaxPWM; // indication if all BL-controllers run on full power |
85 | extern u8 BL_MinOfMaxPWM; // indication if all BL-controllers run on full power |
85 | extern u8 Logging_BL_MinOfMaxPWM; |
86 | extern u8 Logging_BL_MinOfMaxPWM; |
86 | extern u8 ErrorCheck_BL_MinOfMaxPWM; |
87 | extern u8 ErrorCheck_BL_MinOfMaxPWM; |
87 | extern u32 FC_I2C_ErrorConter; |
88 | extern u32 FC_I2C_ErrorConter; |
88 | extern u8 FromFC_VarioCharacter; |
89 | extern u8 FromFC_VarioCharacter; |
89 | extern u8 Logging_FCStatusFlags1,Logging_FCStatusFlags2; |
90 | extern u8 Logging_FCStatusFlags1,Logging_FCStatusFlags2; |
90 | extern s16 POI_KameraNick; |
91 | extern s16 POI_KameraNick; |
91 | extern u8 NC_To_FC_Flags, NC_To_FC_Autostart; |
92 | extern u8 NC_To_FC_Flags, NC_To_FC_Autostart; |
92 | extern u16 FlugMinutenGesamt; |
93 | extern u16 FlugMinutenGesamt; |
93 | 94 | ||
94 | typedef struct |
95 | typedef struct |
95 | { |
96 | { |
96 | u8 Command; |
97 | u8 Command; |
97 | s16 AngleNick; // NickAngle in 0.1 deg |
98 | s16 AngleNick; // NickAngle in 0.1 deg |
98 | s16 AngleRoll; // RollAngle in 0.1 deg |
99 | s16 AngleRoll; // RollAngle in 0.1 deg |
99 | s16 AccNick; |
100 | s16 AccNick; |
100 | s16 AccRoll; |
101 | s16 AccRoll; |
101 | s16 GyroHeading; // Heading in 0.1 deg |
102 | s16 GyroHeading; // Heading in 0.1 deg |
102 | s16 GyroNick; |
103 | s16 GyroNick; |
103 | s16 GyroRoll; |
104 | s16 GyroRoll; |
104 | s16 GyroYaw; |
105 | s16 GyroYaw; |
105 | u16 FCStatus; |
106 | u16 FCStatus; |
106 | union |
107 | union |
107 | { |
108 | { |
108 | u8 Byte[12]; |
109 | u8 Byte[12]; |
109 | s8 sByte[12]; |
110 | s8 sByte[12]; |
110 | u16 Int[6]; |
111 | u16 Int[6]; |
111 | s16 sInt[6]; |
112 | s16 sInt[6]; |
112 | u32 Long[3]; |
113 | u32 Long[3]; |
113 | s32 sLong[3]; |
114 | s32 sLong[3]; |
114 | float Float[3]; |
115 | float Float[3]; |
115 | } Param; |
116 | } Param; |
116 | u8 Chksum; |
117 | u8 Chksum; |
117 | } __attribute__((packed)) FromFlightCtrl_t; |
118 | } __attribute__((packed)) FromFlightCtrl_t; |
118 | 119 | ||
119 | //NC_To_FC_Flags |
120 | //NC_To_FC_Flags |
120 | #define NC_TO_FC_FLYING_RANGE 0x01 |
121 | #define NC_TO_FC_FLYING_RANGE 0x01 |
121 | #define NC_TO_FC_EMERGENCY_LANDING 0x02 |
122 | #define NC_TO_FC_EMERGENCY_LANDING 0x02 |
122 | #define NC_TO_FC_AUTOSTART 0x04 |
123 | #define NC_TO_FC_AUTOSTART 0x04 |
123 | #define NC_TO_FC_AUTOLANDING 0x08 // not used |
124 | #define NC_TO_FC_AUTOLANDING 0x08 // not used |
- | 125 | #define NC_TO_FC_SIMULATION_ACTIVE 0x10 // don't start motors if simulation ist active |
|
124 | 126 | ||
125 | #define SPI_NCCMD_OSD_DATA 100 |
127 | #define SPI_NCCMD_OSD_DATA 100 |
126 | #define SPI_NCCMD_GPS_POS 101 |
128 | #define SPI_NCCMD_GPS_POS 101 |
127 | #define SPI_NCCMD_GPS_TARGET 102 |
129 | #define SPI_NCCMD_GPS_TARGET 102 |
128 | #define SPI_NCCMD_KALMAN 103 |
130 | #define SPI_NCCMD_KALMAN 103 |
129 | #define SPI_NCCMD_VERSION 104 |
131 | #define SPI_NCCMD_VERSION 104 |
130 | #define SPI_NCCMD_GPSINFO 105 |
132 | #define SPI_NCCMD_GPSINFO 105 |
131 | #define SPI_NCCMD_HOTT_INFO 106 |
133 | #define SPI_NCCMD_HOTT_INFO 106 |
132 | #define SPI_MISC 107 |
134 | #define SPI_MISC 107 |
133 | 135 | ||
134 | #define HOTT_VARIO_PACKET_ID 0x89 |
136 | #define HOTT_VARIO_PACKET_ID 0x89 |
135 | #define HOTT_GPS_PACKET_ID 0x8A |
137 | #define HOTT_GPS_PACKET_ID 0x8A |
136 | #define HOTT_ELECTRIC_AIR_PACKET_ID 0x8E |
138 | #define HOTT_ELECTRIC_AIR_PACKET_ID 0x8E |
137 | #define HOTT_GENERAL_PACKET_ID 0x8D |
139 | #define HOTT_GENERAL_PACKET_ID 0x8D |
138 | #define JETI_GPS_PACKET_ID1 0x01 |
140 | #define JETI_GPS_PACKET_ID1 0x01 |
139 | #define JETI_GPS_PACKET_ID2 0x02 |
141 | #define JETI_GPS_PACKET_ID2 0x02 |
140 | #define HOTT_WPL_NAME 0x03 |
142 | #define HOTT_WPL_NAME 0x03 |
141 | 143 | ||
142 | typedef struct |
144 | typedef struct |
143 | { |
145 | { |
144 | u8 Command; |
146 | u8 Command; |
145 | GPS_Stick_t GPSStick; |
147 | GPS_Stick_t GPSStick; |
146 | s16 MagVecX; |
148 | s16 MagVecX; |
147 | s16 CompassHeading; |
149 | s16 CompassHeading; |
148 | s16 AccErrorN; |
150 | s16 AccErrorN; |
149 | s16 AccErrorR; |
151 | s16 AccErrorR; |
150 | s16 MagVecY; |
152 | s16 MagVecY; |
151 | s16 MagVecZ; |
153 | s16 MagVecZ; |
152 | u16 BeepTime; |
154 | u16 BeepTime; |
153 | union |
155 | union |
154 | { |
156 | { |
155 | u8 Byte[12]; |
157 | u8 Byte[12]; |
156 | s8 sByte[12]; |
158 | s8 sByte[12]; |
157 | u16 Int[6]; |
159 | u16 Int[6]; |
158 | s16 sInt[6]; |
160 | s16 sInt[6]; |
159 | u32 Long[3]; |
161 | u32 Long[3]; |
160 | s32 sLong[3]; |
162 | s32 sLong[3]; |
161 | float Float[3]; |
163 | float Float[3]; |
162 | }Param; |
164 | }Param; |
163 | u8 Chksum; |
165 | u8 Chksum; |
164 | } __attribute__((packed)) ToFlightCtrl_t; |
166 | } __attribute__((packed)) ToFlightCtrl_t; |
165 | 167 | ||
166 | typedef struct |
168 | typedef struct |
167 | { |
169 | { |
168 | u8 Current; |
170 | u8 Current; |
169 | u8 Temperature; |
171 | u8 Temperature; |
170 | u8 MaxPWM; |
172 | u8 MaxPWM; |
171 | u8 State; |
173 | u8 State; |
172 | u8 NotReadyCnt; |
174 | u8 NotReadyCnt; |
173 | } __attribute__((packed)) Motor_t; |
175 | } __attribute__((packed)) Motor_t; |
174 | 176 | ||
175 | extern Motor_t Motor[12]; |
177 | extern Motor_t Motor[12]; |
176 | 178 | ||
177 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
179 | #define MOTOR_STATE_NEW_PROTOCOL_MASK 0x01 |
178 | #define MOTOR_STATE_FAST_MODE 0x02 |
180 | #define MOTOR_STATE_FAST_MODE 0x02 |
179 | #define MOTOR_STATE_BL30 0x04 // extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
181 | #define MOTOR_STATE_BL30 0x04 // extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
180 | extern u8 Motor_Version[12]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
182 | extern u8 Motor_Version[12]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
181 | 183 | ||
182 | 184 | ||
183 | 185 | ||
184 | typedef struct |
186 | typedef struct |
185 | { |
187 | { |
186 | u8 Major; |
188 | u8 Major; |
187 | u8 Minor; |
189 | u8 Minor; |
188 | u8 Patch; |
190 | u8 Patch; |
189 | u8 Compatible; |
191 | u8 Compatible; |
190 | u8 Hardware; |
192 | u8 Hardware; |
191 | } __attribute__((packed)) SPI_Version_t; |
193 | } __attribute__((packed)) SPI_Version_t; |
192 | 194 | ||
193 | extern FromFlightCtrl_t FromFlightCtrl; |
195 | extern FromFlightCtrl_t FromFlightCtrl; |
194 | extern ToFlightCtrl_t ToFlightCtrl; |
196 | extern ToFlightCtrl_t ToFlightCtrl; |
195 | extern volatile u32 SPI0_Timeout; |
197 | extern volatile u32 SPI0_Timeout; |
196 | extern SPI_Version_t FC_Version; |
198 | extern SPI_Version_t FC_Version; |
197 | extern s16 GPS_Aid_StickMultiplikator; |
199 | extern s16 GPS_Aid_StickMultiplikator; |
198 | extern u8 CompassCalState; |
200 | extern u8 CompassCalState; |
199 | 201 | ||
200 | void SPI0_Init(void); |
202 | void SPI0_Init(void); |
201 | void SPI0_GetFlightCtrlVersion(void); |
203 | void SPI0_GetFlightCtrlVersion(void); |
202 | void SPI0_UpdateBuffer(void); |
204 | void SPI0_UpdateBuffer(void); |
203 | u16 BL3_Current(u8 who); // in 0.1A |
205 | u16 BL3_Current(u8 who); // in 0.1A |
204 | 206 | ||
205 | #endif //_SPI_SLAVE_H |
207 | #endif //_SPI_SLAVE_H |
206 | 208 |