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