Rev 1994 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1995 | - | 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 | |||
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_SERVOS 15 |
||
65 | #define SPI_FCCMD_ACCU 16 |
||
66 | |||
67 | struct str_ToNaviCtrl |
||
68 | { |
||
69 | unsigned char Sync1, Sync2; |
||
70 | unsigned char Command; |
||
71 | signed int IntegralNick; |
||
72 | signed int IntegralRoll; |
||
73 | signed int AccNick; |
||
74 | signed int AccRoll; |
||
75 | signed int GyroCompass; |
||
76 | signed int GyroNick; |
||
77 | signed int GyroRoll; |
||
78 | signed int GyroGier; |
||
79 | unsigned int FCStatus; |
||
80 | union |
||
81 | { |
||
82 | unsigned char Byte[12]; |
||
83 | char sByte[12]; |
||
84 | unsigned int Int[6]; |
||
85 | int sInt[6]; |
||
86 | unsigned long Long[3]; |
||
87 | long sLong[3]; |
||
88 | float Float[3]; |
||
89 | } Param; |
||
90 | unsigned char Chksum; |
||
91 | }; |
||
92 | |||
93 | #define SPI_NCCMD_KALMAN 103 |
||
94 | #define SPI_NCCMD_VERSION 104 |
||
95 | #define SPI_NCCMD_GPSINFO 105 |
||
96 | #define SPI_NCCMD_HOTT_DATA 106 |
||
97 | #define SPI_MISC 107 |
||
98 | |||
99 | struct str_FromNaviCtrl |
||
100 | { |
||
101 | unsigned char Command; |
||
102 | signed int GPS_Nick; |
||
103 | signed int GPS_Roll; |
||
104 | signed int GPS_Gier; |
||
105 | signed int CompassValue; |
||
106 | // signed int MagVecX; |
||
107 | // signed int MagVecY; |
||
108 | signed int AccErrorN; |
||
109 | signed int AccErrorR; |
||
110 | signed int MagVecZ; |
||
111 | signed int Status; |
||
112 | unsigned int BeepTime; |
||
113 | union |
||
114 | { |
||
115 | unsigned char Byte[12]; |
||
116 | char sByte[12]; |
||
117 | unsigned int Int[6]; |
||
118 | int sInt[6]; |
||
119 | unsigned long Long[3]; |
||
120 | long sLong[3]; |
||
121 | float Float[3]; |
||
122 | } Param; |
||
123 | unsigned char Chksum; |
||
124 | }; |
||
125 | |||
126 | struct str_FromNaviCtrl_Value |
||
127 | { |
||
128 | signed char Kalman_K; |
||
129 | signed char Kalman_MaxDrift; |
||
130 | signed char Kalman_MaxFusion; |
||
131 | unsigned char SerialDataOkay; |
||
132 | signed char GpsZ; |
||
133 | }; |
||
134 | |||
135 | struct str_SPI_VersionInfo |
||
136 | { |
||
137 | unsigned char Major; |
||
138 | unsigned char Minor; |
||
139 | unsigned char Patch; |
||
140 | unsigned char Compatible; |
||
141 | unsigned char Hardware; |
||
142 | }; |
||
143 | |||
144 | // Satfix types for GPSData.SatFix |
||
145 | #define SATFIX_NONE 0x00 |
||
146 | #define SATFIX_DEADRECKOING 0x01 |
||
147 | #define SATFIX_2D 0x02 |
||
148 | #define SATFIX_3D 0x03 |
||
149 | #define SATFIX_GPS_DEADRECKOING 0x04 |
||
150 | #define SATFIX_TIMEONLY 0x05 |
||
151 | // Flags for interpretation of the GPSData.Flags |
||
152 | #define FLAG_GPSFIXOK 0x01 // (i.e. within DOP & ACC Masks) |
||
153 | #define FLAG_DIFFSOLN 0x02 // (is DGPS used) |
||
154 | #define FLAG_WKNSET 0x04 // (is Week Number valid) |
||
155 | #define FLAG_TOWSET 0x08 // (is Time of Week valid) |
||
156 | #define FLAG_GPS_NAVIGATION_ACTIVE 0x10 // NC to FC -> NC is ready to navigate |
||
157 | |||
158 | struct str_GPSInfo |
||
159 | { |
||
160 | unsigned char Flags; // Status Flags |
||
161 | unsigned char NumOfSats; // number of satelites |
||
162 | unsigned char SatFix; // type of satfix |
||
163 | unsigned char Speed; // m/sek |
||
164 | unsigned int HomeDistance; // distance to Home in dm |
||
165 | int HomeBearing; // bearing to home in deg |
||
166 | }; |
||
167 | |||
168 | |||
169 | #ifdef USE_SPI_COMMUNICATION |
||
170 | extern struct str_GPSInfo GPSInfo; |
||
171 | extern struct str_SPI_VersionInfo NC_Version; |
||
172 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
||
173 | extern struct str_ToNaviCtrl ToNaviCtrl; |
||
174 | extern struct str_FromNaviCtrl FromNaviCtrl; |
||
175 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
||
176 | extern signed char FromNC_Rotate_C, FromNC_Rotate_S; |
||
177 | extern unsigned char NC_ErrorCode; |
||
178 | extern void SPI_MasterInit(void); |
||
179 | extern void SPI_StartTransmitPacket(void); |
||
180 | extern void UpdateSPI_Buffer(void); |
||
181 | extern void SPI_TransmitByte(void); |
||
182 | extern signed int POI_KameraNick; |
||
183 | extern unsigned char NC_GPS_ModeCharacter; |
||
184 | extern vector16_t MagVec; |
||
185 | extern unsigned char EarthMagneticField; |
||
186 | extern unsigned char EarthMagneticInclination,EarthMagneticInclinationTheoretic; |
||
187 | #else |
||
188 | |||
189 | |||
190 | // -------------------------------- Dummy ----------------------------------------- |
||
191 | #define SPI_MasterInit() ; |
||
192 | #define SPI_StartTransmitPacket() ; |
||
193 | #define UpdateSPI_Buffer() ; |
||
194 | #define SPI_TransmitByte() ; |
||
195 | #endif |
||
196 | |||
197 | |||
198 | #endif |