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