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