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