Rev 1715 | Details | Compare with Previous | 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> |
||
6 | |||
1051 | killagreg | 7 | #define USE_SPI_COMMUNICATION |
827 | ingob | 8 | |
9 | //----------------------------------------- |
||
10 | #define DDR_SPI DDRB |
||
1561 | killagreg | 11 | #define SLAVE_SELECT_DDR_PORT DDRC |
12 | #define SLAVE_SELECT_PORT PORTC |
||
827 | ingob | 13 | |
1561 | killagreg | 14 | #if defined(__AVR_ATmega1284P__) |
15 | #define DD_SS PORTB4 |
||
16 | #define DD_SCK PORTB7 |
||
17 | #define DD_MOSI PORTB5 |
||
18 | #define DD_MISO PORTB6 |
||
19 | #define SPI_SLAVE_SELECT PORTC5 |
||
20 | #else |
||
21 | #define DD_SS PB4 |
||
22 | #define DD_SCK PB7 |
||
23 | #define DD_MOSI PB5 |
||
24 | #define DD_MISO PB6 |
||
25 | #define SPI_SLAVE_SELECT PC5 |
||
26 | #endif |
||
27 | |||
1051 | killagreg | 28 | // for compatibility reasons gcc3.x <-> gcc4.x |
29 | #ifndef SPCR |
||
827 | ingob | 30 | #define SPCR SPCR0 |
1051 | killagreg | 31 | #endif |
32 | #ifndef SPE |
||
827 | ingob | 33 | #define SPE SPE0 |
1051 | killagreg | 34 | #endif |
35 | #ifndef MSTR |
||
827 | ingob | 36 | #define MSTR MSTR0 |
1051 | killagreg | 37 | #endif |
38 | #ifndef SPR1 |
||
827 | ingob | 39 | #define SPR1 SPR01 |
1051 | killagreg | 40 | #endif |
41 | #ifndef SPR0 |
||
827 | ingob | 42 | #define SPR0 SPR00 |
1051 | killagreg | 43 | #endif |
44 | #ifndef SPIE |
||
827 | ingob | 45 | #define SPIE SPIE0 |
1051 | killagreg | 46 | #endif |
47 | #ifndef SPDR |
||
827 | ingob | 48 | #define SPDR SPDR0 |
1051 | killagreg | 49 | #endif |
50 | #ifndef SPIF |
||
827 | ingob | 51 | #define SPIF SPIF0 |
1051 | killagreg | 52 | #endif |
53 | #ifndef SPSR |
||
827 | ingob | 54 | #define SPSR SPSR0 |
1051 | killagreg | 55 | #endif |
827 | ingob | 56 | // ------------------------- |
57 | |||
1448 | killagreg | 58 | #define SPI_FCCMD_USER 10 |
59 | #define SPI_FCCMD_STICK 11 |
||
60 | #define SPI_FCCMD_MISC 12 |
||
61 | #define SPI_FCCMD_PARAMETER1 13 |
||
62 | #define SPI_FCCMD_VERSION 14 |
||
63 | #define SPI_FCCMD_SERVOS 15 |
||
1508 | killagreg | 64 | #define SPI_FCCMD_ACCU 16 |
991 | ingob | 65 | |
827 | ingob | 66 | struct str_ToNaviCtrl |
67 | { |
||
1231 | killagreg | 68 | unsigned char Sync1, Sync2; |
69 | unsigned char Command; |
||
70 | signed int IntegralNick; |
||
71 | signed int IntegralRoll; |
||
72 | signed int AccNick; |
||
73 | signed int AccRoll; |
||
74 | signed int GyroCompass; |
||
75 | signed int GyroNick; |
||
76 | signed int GyroRoll; |
||
77 | signed int GyroGier; |
||
78 | union |
||
79 | { |
||
1472 | killagreg | 80 | unsigned char Byte[12]; |
1231 | killagreg | 81 | char sByte[12]; |
1472 | killagreg | 82 | unsigned int Int[6]; |
83 | int sInt[6]; |
||
84 | unsigned long Long[3]; |
||
85 | long sLong[3]; |
||
1231 | killagreg | 86 | float Float[3]; |
87 | } Param; |
||
88 | unsigned char Chksum; |
||
1051 | killagreg | 89 | }; |
827 | ingob | 90 | |
1448 | killagreg | 91 | #define SPI_NCCMD_KALMAN 103 |
92 | #define SPI_NCCMD_VERSION 104 |
||
1451 | killagreg | 93 | #define SPI_NCCMD_GPSINFO 105 |
1241 | killagreg | 94 | |
827 | ingob | 95 | struct str_FromNaviCtrl |
96 | { |
||
1231 | killagreg | 97 | unsigned char Command; |
98 | signed int GPS_Nick; |
||
99 | signed int GPS_Roll; |
||
100 | signed int GPS_Gier; |
||
101 | signed int CompassValue; |
||
102 | signed int Status; |
||
103 | unsigned int BeepTime; |
||
104 | union |
||
105 | { |
||
1472 | killagreg | 106 | unsigned char Byte[12]; |
1231 | killagreg | 107 | char sByte[12]; |
1472 | killagreg | 108 | unsigned int Int[6]; |
109 | int sInt[6]; |
||
110 | unsigned long Long[3]; |
||
111 | long sLong[3]; |
||
1231 | killagreg | 112 | float Float[3]; |
113 | } Param; |
||
114 | unsigned char Chksum; |
||
1051 | killagreg | 115 | }; |
827 | ingob | 116 | |
978 | hbuss | 117 | struct str_FromNaviCtrl_Value |
118 | { |
||
992 | hbuss | 119 | signed char Kalman_K; |
120 | signed char Kalman_MaxDrift; |
||
121 | signed char Kalman_MaxFusion; |
||
1215 | hbuss | 122 | unsigned char SerialDataOkay; |
1283 | hbuss | 123 | signed char GpsZ; |
978 | hbuss | 124 | }; |
827 | ingob | 125 | |
1051 | killagreg | 126 | struct str_SPI_VersionInfo |
127 | { |
||
128 | unsigned char Major; |
||
129 | unsigned char Minor; |
||
130 | unsigned char Patch; |
||
131 | unsigned char Compatible; |
||
1448 | killagreg | 132 | unsigned char Hardware; |
1051 | killagreg | 133 | }; |
134 | |||
1451 | killagreg | 135 | // Satfix types for GPSData.SatFix |
136 | #define SATFIX_NONE 0x00 |
||
137 | #define SATFIX_DEADRECKOING 0x01 |
||
138 | #define SATFIX_2D 0x02 |
||
139 | #define SATFIX_3D 0x03 |
||
140 | #define SATFIX_GPS_DEADRECKOING 0x04 |
||
141 | #define SATFIX_TIMEONLY 0x05 |
||
142 | // Flags for interpretation of the GPSData.Flags |
||
143 | #define FLAG_GPSFIXOK 0x01 // (i.e. within DOP & ACC Masks) |
||
144 | #define FLAG_DIFFSOLN 0x02 // (is DGPS used) |
||
145 | #define FLAG_WKNSET 0x04 // (is Week Number valid) |
||
146 | #define FLAG_TOWSET 0x08 // (is Time of Week valid) |
||
147 | |||
148 | struct str_GPSInfo |
||
149 | { |
||
1472 | killagreg | 150 | unsigned char Flags; // Status Flags |
151 | unsigned char NumOfSats; // number of satelites |
||
152 | unsigned char SatFix; // type of satfix |
||
1690 | holgerb | 153 | unsigned char Speed; // m/sek |
1472 | killagreg | 154 | unsigned int HomeDistance; // distance to Home in dm |
155 | int HomeBearing; // bearing to home in deg |
||
1451 | killagreg | 156 | }; |
157 | |||
158 | |||
827 | ingob | 159 | #ifdef USE_SPI_COMMUNICATION |
1451 | killagreg | 160 | extern struct str_GPSInfo GPSInfo; |
1448 | killagreg | 161 | extern struct str_SPI_VersionInfo NC_Version; |
978 | hbuss | 162 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
827 | ingob | 163 | extern struct str_ToNaviCtrl ToNaviCtrl; |
164 | extern struct str_FromNaviCtrl FromNaviCtrl; |
||
1215 | hbuss | 165 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
1664 | holgerb | 166 | extern signed char FromNC_Rotate_C, FromNC_Rotate_S; |
1703 | holgerb | 167 | extern unsigned char NC_ErrorCode; |
827 | ingob | 168 | extern void SPI_MasterInit(void); |
169 | extern void SPI_StartTransmitPacket(void); |
||
170 | extern void UpdateSPI_Buffer(void); |
||
171 | extern void SPI_TransmitByte(void); |
||
172 | #else |
||
173 | |||
174 | |||
175 | // -------------------------------- Dummy ----------------------------------------- |
||
1051 | killagreg | 176 | #define SPI_MasterInit() ; |
827 | ingob | 177 | #define SPI_StartTransmitPacket() ; |
178 | #define UpdateSPI_Buffer() ; |
||
179 | #define SPI_TransmitByte() ; |
||
180 | #endif |
||
181 | |||
182 | |||
183 | #endif |