Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2751 | - | 1 | // ######################## SPI - FlightCtrl ################### |
2 | #ifndef _SPI_H |
||
3 | #define _SPI_H |
||
4 | |||
5 | #include <util/delay.h> |
||
6 | #include "vector.h" |
||
7 | |||
8 | #define USE_SPI_COMMUNICATION |
||
9 | #define SPI_BYTEGAP 5 |
||
10 | //----------------------------------------- |
||
11 | #define DDR_SPI DDRB |
||
12 | #define SLAVE_SELECT_DDR_PORT DDRC |
||
13 | #define SLAVE_SELECT_PORT PORTC |
||
14 | |||
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 | |||
29 | // for compatibility reasons gcc3.x <-> gcc4.x |
||
30 | #ifndef SPCR |
||
31 | #define SPCR SPCR0 |
||
32 | #endif |
||
33 | #ifndef SPE |
||
34 | #define SPE SPE0 |
||
35 | #endif |
||
36 | #ifndef MSTR |
||
37 | #define MSTR MSTR0 |
||
38 | #endif |
||
39 | #ifndef SPR1 |
||
40 | #define SPR1 SPR01 |
||
41 | #endif |
||
42 | #ifndef SPR0 |
||
43 | #define SPR0 SPR00 |
||
44 | #endif |
||
45 | #ifndef SPIE |
||
46 | #define SPIE SPIE0 |
||
47 | #endif |
||
48 | #ifndef SPDR |
||
49 | #define SPDR SPDR0 |
||
50 | #endif |
||
51 | #ifndef SPIF |
||
52 | #define SPIF SPIF0 |
||
53 | #endif |
||
54 | #ifndef SPSR |
||
55 | #define SPSR SPSR0 |
||
56 | #endif |
||
57 | // ------------------------- |
||
58 | |||
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 |
||
64 | #define SPI_FCCMD_SLOW3 15 |
||
65 | #define SPI_FCCMD_BL_ACCU 16 |
||
66 | #define SPI_FCCMD_PARAMETER2 17 |
||
67 | #define SPI_FCCMD_NEUTRAL 18 |
||
68 | #define SPI_FCCMD_SLOW 19 |
||
69 | #define SPI_FCCMD_SLOW2 20 |
||
70 | |||
71 | struct str_ToNaviCtrl |
||
72 | { |
||
73 | unsigned char Sync1, Sync2; |
||
74 | unsigned char Command; |
||
75 | signed int IntegralNick; |
||
76 | signed int IntegralRoll; |
||
77 | signed int AccNick; |
||
78 | signed int AccRoll; |
||
79 | signed int GyroCompass; |
||
80 | signed int GyroNick; |
||
81 | signed int GyroRoll; |
||
82 | signed int GyroGier; |
||
83 | unsigned int FCStatus; |
||
84 | union |
||
85 | { |
||
86 | unsigned char Byte[12]; |
||
87 | char sByte[12]; |
||
88 | unsigned int Int[6]; |
||
89 | int sInt[6]; |
||
90 | unsigned long Long[3]; |
||
91 | long sLong[3]; |
||
92 | float Float[3]; |
||
93 | } Param; |
||
94 | unsigned char Chksum; |
||
95 | }; |
||
96 | |||
97 | #define SPI_NCCMD_KALMAN 103 |
||
98 | #define SPI_NCCMD_VERSION 104 |
||
99 | #define SPI_NCCMD_GPSINFO 105 |
||
100 | #define SPI_NCCMD_HOTT_DATA 106 |
||
101 | #define SPI_MISC 107 |
||
102 | |||
103 | struct str_FromNaviCtrl |
||
104 | { |
||
105 | unsigned char Command; |
||
106 | signed int GPS_Nick; |
||
107 | signed int GPS_Roll; |
||
108 | signed int MagVecX; |
||
109 | signed int CompassValue; |
||
110 | signed int AccErrorN; |
||
111 | signed int AccErrorR; |
||
112 | signed int MagVecY; |
||
113 | signed int MagVecZ; |
||
114 | unsigned int BeepTime; |
||
115 | union |
||
116 | { |
||
117 | unsigned char Byte[12]; |
||
118 | char sByte[12]; |
||
119 | unsigned int Int[6]; |
||
120 | int sInt[6]; |
||
121 | unsigned long Long[3]; |
||
122 | long sLong[3]; |
||
123 | float Float[3]; |
||
124 | } Param; |
||
125 | unsigned char Chksum; |
||
126 | }; |
||
127 | |||
128 | struct str_FromNaviCtrl_Value |
||
129 | { |
||
130 | signed char Kalman_K; |
||
131 | signed char Kalman_MaxDrift; |
||
132 | signed char Kalman_MaxFusion; |
||
133 | unsigned char SerialDataOkay; |
||
134 | signed char reserve; |
||
135 | }; |
||
136 | |||
137 | struct str_SPI_VersionInfo |
||
138 | { |
||
139 | unsigned char Major; |
||
140 | unsigned char Minor; |
||
141 | unsigned char Patch; |
||
142 | unsigned char Compatible; |
||
143 | unsigned char Hardware; |
||
144 | }; |
||
145 | |||
146 | // Satfix types for GPSData.SatFix |
||
147 | #define SATFIX_NONE 0x00 |
||
148 | #define SATFIX_DEADRECKOING 0x01 |
||
149 | #define SATFIX_2D 0x02 |
||
150 | #define SATFIX_3D 0x03 |
||
151 | #define SATFIX_GPS_DEADRECKOING 0x04 |
||
152 | #define SATFIX_TIMEONLY 0x05 |
||
153 | // Flags for interpretation of the GPSData.Flags |
||
154 | #define FLAG_GPSFIXOK 0x01 // (i.e. within DOP & ACC Masks) |
||
155 | #define FLAG_DIFFSOLN 0x02 // (is DGPS used) |
||
156 | #define FLAG_WKNSET 0x04 // (is Week Number valid) |
||
157 | #define FLAG_TOWSET 0x08 // (is Time of Week valid) |
||
158 | #define FLAG_GPS_NAVIGATION_ACTIVE 0x10 // NC to FC -> NC is ready to navigate |
||
159 | |||
160 | struct str_GPSInfo |
||
161 | { |
||
162 | unsigned char Flags; // Status Flags |
||
163 | unsigned char NumOfSats; // number of satelites |
||
164 | unsigned char SatFix; // type of satfix |
||
165 | unsigned char Speed; // m/sek |
||
166 | unsigned int HomeDistance; // distance to Home in dm |
||
167 | int HomeBearing; // bearing to home in deg |
||
168 | }; |
||
169 | |||
170 | |||
171 | #ifdef USE_SPI_COMMUNICATION |
||
172 | extern struct str_GPSInfo GPSInfo; |
||
173 | extern struct str_SPI_VersionInfo NC_Version; |
||
174 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
||
175 | extern struct str_ToNaviCtrl ToNaviCtrl; |
||
176 | extern struct str_FromNaviCtrl FromNaviCtrl; |
||
177 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
||
178 | extern signed char FromNC_Rotate_C, FromNC_Rotate_S; |
||
179 | extern unsigned char NC_ErrorCode; |
||
180 | extern void SPI_MasterInit(void); |
||
181 | extern unsigned char SPI_StartTransmitPacket(void); |
||
182 | extern void UpdateSPI_Buffer(void); |
||
183 | extern void SPI_TransmitByte(void); |
||
184 | extern signed int POI_KameraNick; |
||
185 | extern unsigned char NC_GPS_ModeCharacter, NC_To_FC_Flags, NC_To_FC_MaxAltitude; |
||
186 | extern vector16_t MagVec; |
||
187 | extern unsigned char EarthMagneticField; |
||
188 | extern unsigned char EarthMagneticInclination,EarthMagneticInclinationTheoretic; |
||
189 | extern signed char FromNC_WP_EventChannel_New; |
||
190 | extern unsigned char NCForcesNewDirection; // allows Yawing without CareFree (Yawing at Coming Home) |
||
191 | #else |
||
192 | |||
193 | |||
194 | // -------------------------------- Dummy ----------------------------------------- |
||
195 | #define SPI_MasterInit() ; |
||
196 | //#define SPI_StartTransmitPacket() ; |
||
197 | #define UpdateSPI_Buffer() ; |
||
198 | #define SPI_TransmitByte() ; |
||
199 | #endif |
||
200 | |||
201 | |||
202 | #endif |