Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
827 | ingob | 1 | // ######################## SPI - FlightCtrl ################### |
2 | #ifndef _SPI_H |
||
3 | #define _SPI_H |
||
4 | |||
5 | #include <util/delay.h> |
||
1852 | killagreg | 6 | #include "vector.h" |
827 | ingob | 7 | |
1051 | killagreg | 8 | #define USE_SPI_COMMUNICATION |
2407 | holgerb | 9 | #define SPI_BYTEGAP 5 |
827 | ingob | 10 | //----------------------------------------- |
11 | #define DDR_SPI DDRB |
||
1561 | killagreg | 12 | #define SLAVE_SELECT_DDR_PORT DDRC |
13 | #define SLAVE_SELECT_PORT PORTC |
||
827 | ingob | 14 | |
1561 | killagreg | 15 | #if defined(__AVR_ATmega1284P__) |
16 | #define DD_SS PORTB4 |
||
17 | #define DD_SCK PORTB7 |
||
18 | #define DD_MOSI PORTB5 |
||
19 | #define DD_MISO PORTB6 |
||
20 | #define SPI_SLAVE_SELECT PORTC5 |
||
21 | #else |
||
22 | #define DD_SS PB4 |
||
23 | #define DD_SCK PB7 |
||
24 | #define DD_MOSI PB5 |
||
25 | #define DD_MISO PB6 |
||
26 | #define SPI_SLAVE_SELECT PC5 |
||
27 | #endif |
||
28 | |||
1051 | killagreg | 29 | // for compatibility reasons gcc3.x <-> gcc4.x |
30 | #ifndef SPCR |
||
827 | ingob | 31 | #define SPCR SPCR0 |
1051 | killagreg | 32 | #endif |
33 | #ifndef SPE |
||
827 | ingob | 34 | #define SPE SPE0 |
1051 | killagreg | 35 | #endif |
36 | #ifndef MSTR |
||
827 | ingob | 37 | #define MSTR MSTR0 |
1051 | killagreg | 38 | #endif |
39 | #ifndef SPR1 |
||
827 | ingob | 40 | #define SPR1 SPR01 |
1051 | killagreg | 41 | #endif |
42 | #ifndef SPR0 |
||
827 | ingob | 43 | #define SPR0 SPR00 |
1051 | killagreg | 44 | #endif |
45 | #ifndef SPIE |
||
827 | ingob | 46 | #define SPIE SPIE0 |
1051 | killagreg | 47 | #endif |
48 | #ifndef SPDR |
||
827 | ingob | 49 | #define SPDR SPDR0 |
1051 | killagreg | 50 | #endif |
51 | #ifndef SPIF |
||
827 | ingob | 52 | #define SPIF SPIF0 |
1051 | killagreg | 53 | #endif |
54 | #ifndef SPSR |
||
827 | ingob | 55 | #define SPSR SPSR0 |
1051 | killagreg | 56 | #endif |
827 | ingob | 57 | // ------------------------- |
58 | |||
1448 | killagreg | 59 | #define SPI_FCCMD_USER 10 |
60 | #define SPI_FCCMD_STICK 11 |
||
61 | #define SPI_FCCMD_MISC 12 |
||
62 | #define SPI_FCCMD_PARAMETER1 13 |
||
63 | #define SPI_FCCMD_VERSION 14 |
||
2499 | holgerb | 64 | #define SPI_FCCMD_SLOW3 15 |
2341 | holgerb | 65 | #define SPI_FCCMD_BL_ACCU 16 |
2183 | holgerb | 66 | #define SPI_FCCMD_PARAMETER2 17 |
2478 | holgerb | 67 | #define SPI_FCCMD_NEUTRAL 18 |
68 | #define SPI_FCCMD_SLOW 19 |
||
2499 | holgerb | 69 | #define SPI_FCCMD_SLOW2 20 |
2596 | holgerb | 70 | #define SPI_FCCMD_STICK2 21 |
991 | ingob | 71 | |
2596 | holgerb | 72 | |
73 | #define SPI_FCSYNCBYTE1 0xAA |
||
74 | #define SPI_FCSYNCBYTE2 0x85 |
||
75 | #define SPI_FCSYNCBYTE_HB1 0xA2 // for the huge Block |
||
76 | #define SPI_FCSYNCBYTE_HB2 0x48 // for the huge Block |
||
77 | #define SPI_NCSYNCBYTE1 0x82 |
||
78 | #define SPI_NCSYNCBYTE2 0x55 |
||
79 | #define SPI_NCSYNCBYTE_HB1 0xB2 // for the huge Block |
||
80 | #define SPI_NCSYNCBYTE_HB2 0xA5 // for the huge Block |
||
81 | |||
82 | /* |
||
827 | ingob | 83 | struct str_ToNaviCtrl |
84 | { |
||
1231 | killagreg | 85 | unsigned char Sync1, Sync2; |
86 | unsigned char Command; |
||
87 | signed int IntegralNick; |
||
88 | signed int IntegralRoll; |
||
89 | signed int AccNick; |
||
90 | signed int AccRoll; |
||
91 | signed int GyroCompass; |
||
92 | signed int GyroNick; |
||
93 | signed int GyroRoll; |
||
94 | signed int GyroGier; |
||
1852 | killagreg | 95 | unsigned int FCStatus; |
1231 | killagreg | 96 | union |
97 | { |
||
1472 | killagreg | 98 | unsigned char Byte[12]; |
1231 | killagreg | 99 | char sByte[12]; |
1472 | killagreg | 100 | unsigned int Int[6]; |
101 | int sInt[6]; |
||
102 | unsigned long Long[3]; |
||
103 | long sLong[3]; |
||
1231 | killagreg | 104 | float Float[3]; |
105 | } Param; |
||
106 | unsigned char Chksum; |
||
1051 | killagreg | 107 | }; |
2596 | holgerb | 108 | */ |
827 | ingob | 109 | |
2596 | holgerb | 110 | struct str_HugeBlockToNavi |
111 | { |
||
112 | unsigned char Sync1,Sync2; |
||
113 | unsigned char WhoAmI; |
||
2631 | holgerb | 114 | unsigned char Data[200]; |
2596 | holgerb | 115 | unsigned char Chksum; |
116 | }; |
||
117 | extern struct str_HugeBlockToNavi HugeBlockToNavi; |
||
118 | |||
119 | struct str_HugeBlockFromNavi |
||
120 | { |
||
121 | unsigned char WhoAmI; |
||
2631 | holgerb | 122 | unsigned char Data[200]; |
2596 | holgerb | 123 | unsigned char Chksum; |
124 | }; |
||
125 | extern struct str_HugeBlockFromNavi HugeBlockFromNavi; |
||
126 | |||
127 | extern void TransmitHugeBlock(void); |
||
2604 | holgerb | 128 | extern void SendSettingToNC(void); |
2596 | holgerb | 129 | |
130 | struct str_ToNaviCtrl |
||
131 | { |
||
132 | unsigned char Sync1, Sync2; |
||
133 | unsigned char Command; |
||
134 | signed int IntegralNick; |
||
135 | signed int IntegralRoll; |
||
136 | signed int GyroCompass; |
||
137 | signed int GyroGier; |
||
138 | unsigned int FCStatus; |
||
139 | union |
||
140 | { |
||
141 | unsigned char Byte[20]; |
||
142 | char sByte[20]; |
||
143 | unsigned int Int[10]; |
||
144 | int sInt[10]; |
||
145 | unsigned long Long[5]; |
||
146 | long sLong[5]; |
||
147 | float Float[5]; |
||
148 | } Param; |
||
149 | unsigned char Chksum; |
||
150 | }; |
||
151 | |||
152 | |||
1448 | killagreg | 153 | #define SPI_NCCMD_KALMAN 103 |
154 | #define SPI_NCCMD_VERSION 104 |
||
1451 | killagreg | 155 | #define SPI_NCCMD_GPSINFO 105 |
1940 | holgerb | 156 | #define SPI_NCCMD_HOTT_DATA 106 |
1972 | holgerb | 157 | #define SPI_MISC 107 |
2596 | holgerb | 158 | #define SPI_SERIAL_CH 108 // kommt nur, wenn NC den Datensatz empfangen hat |
1241 | killagreg | 159 | |
827 | ingob | 160 | struct str_FromNaviCtrl |
161 | { |
||
1231 | killagreg | 162 | unsigned char Command; |
2596 | holgerb | 163 | signed int GPS_Nick; |
164 | signed int GPS_Roll; |
||
165 | signed int CompassValue; |
||
1936 | holgerb | 166 | signed int AccErrorN; |
167 | signed int AccErrorR; |
||
1231 | killagreg | 168 | union |
169 | { |
||
2596 | holgerb | 170 | unsigned char Byte[20]; |
171 | char sByte[20]; |
||
172 | unsigned int Int[10]; |
||
173 | int sInt[10]; |
||
174 | unsigned long Long[5]; |
||
175 | long sLong[5]; |
||
176 | float Float[5]; |
||
1231 | killagreg | 177 | } Param; |
178 | unsigned char Chksum; |
||
1051 | killagreg | 179 | }; |
827 | ingob | 180 | |
978 | hbuss | 181 | struct str_FromNaviCtrl_Value |
182 | { |
||
992 | hbuss | 183 | signed char Kalman_K; |
184 | signed char Kalman_MaxDrift; |
||
185 | signed char Kalman_MaxFusion; |
||
1215 | hbuss | 186 | unsigned char SerialDataOkay; |
2501 | holgerb | 187 | signed char reserve; |
978 | hbuss | 188 | }; |
827 | ingob | 189 | |
1051 | killagreg | 190 | struct str_SPI_VersionInfo |
191 | { |
||
192 | unsigned char Major; |
||
193 | unsigned char Minor; |
||
194 | unsigned char Patch; |
||
195 | unsigned char Compatible; |
||
1448 | killagreg | 196 | unsigned char Hardware; |
1051 | killagreg | 197 | }; |
198 | |||
1451 | killagreg | 199 | // Satfix types for GPSData.SatFix |
200 | #define SATFIX_NONE 0x00 |
||
201 | #define SATFIX_DEADRECKOING 0x01 |
||
202 | #define SATFIX_2D 0x02 |
||
203 | #define SATFIX_3D 0x03 |
||
204 | #define SATFIX_GPS_DEADRECKOING 0x04 |
||
205 | #define SATFIX_TIMEONLY 0x05 |
||
206 | // Flags for interpretation of the GPSData.Flags |
||
1916 | holgerb | 207 | #define FLAG_GPSFIXOK 0x01 // (i.e. within DOP & ACC Masks) |
208 | #define FLAG_DIFFSOLN 0x02 // (is DGPS used) |
||
209 | #define FLAG_WKNSET 0x04 // (is Week Number valid) |
||
210 | #define FLAG_TOWSET 0x08 // (is Time of Week valid) |
||
211 | #define FLAG_GPS_NAVIGATION_ACTIVE 0x10 // NC to FC -> NC is ready to navigate |
||
1451 | killagreg | 212 | |
213 | struct str_GPSInfo |
||
214 | { |
||
1472 | killagreg | 215 | unsigned char Flags; // Status Flags |
216 | unsigned char NumOfSats; // number of satelites |
||
217 | unsigned char SatFix; // type of satfix |
||
1690 | holgerb | 218 | unsigned char Speed; // m/sek |
1472 | killagreg | 219 | unsigned int HomeDistance; // distance to Home in dm |
220 | int HomeBearing; // bearing to home in deg |
||
1451 | killagreg | 221 | }; |
222 | |||
223 | |||
827 | ingob | 224 | #ifdef USE_SPI_COMMUNICATION |
1451 | killagreg | 225 | extern struct str_GPSInfo GPSInfo; |
1448 | killagreg | 226 | extern struct str_SPI_VersionInfo NC_Version; |
978 | hbuss | 227 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
827 | ingob | 228 | extern struct str_ToNaviCtrl ToNaviCtrl; |
229 | extern struct str_FromNaviCtrl FromNaviCtrl; |
||
1215 | hbuss | 230 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
1664 | holgerb | 231 | extern signed char FromNC_Rotate_C, FromNC_Rotate_S; |
2619 | holgerb | 232 | extern unsigned char NC_ErrorCode,Partner_ErrorCode; |
827 | ingob | 233 | extern void SPI_MasterInit(void); |
2386 | holgerb | 234 | extern unsigned char SPI_StartTransmitPacket(void); |
827 | ingob | 235 | extern void UpdateSPI_Buffer(void); |
236 | extern void SPI_TransmitByte(void); |
||
1840 | holgerb | 237 | extern signed int POI_KameraNick; |
2034 | holgerb | 238 | extern unsigned char NC_GPS_ModeCharacter, NC_To_FC_Flags, NC_To_FC_MaxAltitude; |
1852 | killagreg | 239 | extern vector16_t MagVec; |
1972 | holgerb | 240 | extern unsigned char EarthMagneticField; |
241 | extern unsigned char EarthMagneticInclination,EarthMagneticInclinationTheoretic; |
||
2485 | holgerb | 242 | extern signed char FromNC_WP_EventChannel_New; |
2501 | holgerb | 243 | extern unsigned char NCForcesNewDirection; // allows Yawing without CareFree (Yawing at Coming Home) |
2604 | holgerb | 244 | extern unsigned char NC_RequestsConfig; |
2624 | holgerb | 245 | extern unsigned char CamCtrlCharacter; |
827 | ingob | 246 | #else |
247 | |||
248 | |||
249 | // -------------------------------- Dummy ----------------------------------------- |
||
1051 | killagreg | 250 | #define SPI_MasterInit() ; |
2386 | holgerb | 251 | //#define SPI_StartTransmitPacket() ; |
827 | ingob | 252 | #define UpdateSPI_Buffer() ; |
253 | #define SPI_TransmitByte() ; |
||
254 | #endif |
||
255 | |||
256 | |||
257 | #endif |