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