Rev 1451 | Rev 1508 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1451 | Rev 1472 | ||
---|---|---|---|
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 | 57 | ||
58 | struct str_ToNaviCtrl |
58 | struct str_ToNaviCtrl |
59 | { |
59 | { |
60 | unsigned char Sync1, Sync2; |
60 | unsigned char Sync1, Sync2; |
61 | unsigned char Command; |
61 | unsigned char Command; |
62 | signed int IntegralNick; |
62 | signed int IntegralNick; |
63 | signed int IntegralRoll; |
63 | signed int IntegralRoll; |
64 | signed int AccNick; |
64 | signed int AccNick; |
65 | signed int AccRoll; |
65 | signed int AccRoll; |
66 | signed int GyroCompass; |
66 | signed int GyroCompass; |
67 | signed int GyroNick; |
67 | signed int GyroNick; |
68 | signed int GyroRoll; |
68 | signed int GyroRoll; |
69 | signed int GyroGier; |
69 | signed int GyroGier; |
70 | union |
70 | union |
71 | { |
71 | { |
72 | char sByte[12]; |
- | |
73 | unsigned char Byte[12]; |
72 | unsigned char Byte[12]; |
- | 73 | char sByte[12]; |
|
- | 74 | unsigned int Int[6]; |
|
74 | int Int[6]; |
75 | int sInt[6]; |
- | 76 | unsigned long Long[3]; |
|
75 | long Long[3]; |
77 | long sLong[3]; |
76 | float Float[3]; |
78 | float Float[3]; |
77 | } Param; |
79 | } Param; |
78 | unsigned char Chksum; |
80 | unsigned char Chksum; |
79 | }; |
81 | }; |
80 | 82 | ||
81 | #define SPI_NCCMD_KALMAN 103 |
83 | #define SPI_NCCMD_KALMAN 103 |
82 | #define SPI_NCCMD_VERSION 104 |
84 | #define SPI_NCCMD_VERSION 104 |
83 | #define SPI_NCCMD_GPSINFO 105 |
85 | #define SPI_NCCMD_GPSINFO 105 |
84 | 86 | ||
85 | struct str_FromNaviCtrl |
87 | struct str_FromNaviCtrl |
86 | { |
88 | { |
87 | unsigned char Command; |
89 | unsigned char Command; |
88 | signed int GPS_Nick; |
90 | signed int GPS_Nick; |
89 | signed int GPS_Roll; |
91 | signed int GPS_Roll; |
90 | signed int GPS_Gier; |
92 | signed int GPS_Gier; |
91 | signed int CompassValue; |
93 | signed int CompassValue; |
92 | signed int Status; |
94 | signed int Status; |
93 | unsigned int BeepTime; |
95 | unsigned int BeepTime; |
94 | union |
96 | union |
95 | { |
97 | { |
96 | char sByte[12]; |
- | |
97 | unsigned char Byte[12]; |
98 | unsigned char Byte[12]; |
- | 99 | char sByte[12]; |
|
- | 100 | unsigned int Int[6]; |
|
98 | int Int[6]; |
101 | int sInt[6]; |
- | 102 | unsigned long Long[3]; |
|
99 | long Long[3]; |
103 | long sLong[3]; |
100 | float Float[3]; |
104 | float Float[3]; |
101 | } Param; |
105 | } Param; |
102 | unsigned char Chksum; |
106 | unsigned char Chksum; |
103 | }; |
107 | }; |
104 | 108 | ||
105 | struct str_FromNaviCtrl_Value |
109 | struct str_FromNaviCtrl_Value |
106 | { |
110 | { |
107 | signed char Kalman_K; |
111 | signed char Kalman_K; |
108 | signed char Kalman_MaxDrift; |
112 | signed char Kalman_MaxDrift; |
109 | signed char Kalman_MaxFusion; |
113 | signed char Kalman_MaxFusion; |
110 | unsigned char SerialDataOkay; |
114 | unsigned char SerialDataOkay; |
111 | signed char GpsZ; |
115 | signed char GpsZ; |
112 | }; |
116 | }; |
113 | 117 | ||
114 | struct str_SPI_VersionInfo |
118 | struct str_SPI_VersionInfo |
115 | { |
119 | { |
116 | unsigned char Major; |
120 | unsigned char Major; |
117 | unsigned char Minor; |
121 | unsigned char Minor; |
118 | unsigned char Patch; |
122 | unsigned char Patch; |
119 | unsigned char Compatible; |
123 | unsigned char Compatible; |
120 | unsigned char Hardware; |
124 | unsigned char Hardware; |
121 | }; |
125 | }; |
122 | 126 | ||
123 | // Satfix types for GPSData.SatFix |
127 | // Satfix types for GPSData.SatFix |
124 | #define SATFIX_NONE 0x00 |
128 | #define SATFIX_NONE 0x00 |
125 | #define SATFIX_DEADRECKOING 0x01 |
129 | #define SATFIX_DEADRECKOING 0x01 |
126 | #define SATFIX_2D 0x02 |
130 | #define SATFIX_2D 0x02 |
127 | #define SATFIX_3D 0x03 |
131 | #define SATFIX_3D 0x03 |
128 | #define SATFIX_GPS_DEADRECKOING 0x04 |
132 | #define SATFIX_GPS_DEADRECKOING 0x04 |
129 | #define SATFIX_TIMEONLY 0x05 |
133 | #define SATFIX_TIMEONLY 0x05 |
130 | // Flags for interpretation of the GPSData.Flags |
134 | // Flags for interpretation of the GPSData.Flags |
131 | #define FLAG_GPSFIXOK 0x01 // (i.e. within DOP & ACC Masks) |
135 | #define FLAG_GPSFIXOK 0x01 // (i.e. within DOP & ACC Masks) |
132 | #define FLAG_DIFFSOLN 0x02 // (is DGPS used) |
136 | #define FLAG_DIFFSOLN 0x02 // (is DGPS used) |
133 | #define FLAG_WKNSET 0x04 // (is Week Number valid) |
137 | #define FLAG_WKNSET 0x04 // (is Week Number valid) |
134 | #define FLAG_TOWSET 0x08 // (is Time of Week valid) |
138 | #define FLAG_TOWSET 0x08 // (is Time of Week valid) |
135 | 139 | ||
136 | struct str_GPSInfo |
140 | struct str_GPSInfo |
137 | { |
141 | { |
138 | uint8_t Flags; // Status Flags |
142 | unsigned char Flags; // Status Flags |
139 | uint8_t NumOfSats; // number of satelites |
143 | unsigned char NumOfSats; // number of satelites |
140 | uint8_t SatFix; // type of satfix |
144 | unsigned char SatFix; // type of satfix |
- | 145 | unsigned int HomeDistance; // distance to Home in dm |
|
- | 146 | int HomeBearing; // bearing to home in deg |
|
141 | }; |
147 | }; |
142 | 148 | ||
143 | 149 | ||
144 | #ifdef USE_SPI_COMMUNICATION |
150 | #ifdef USE_SPI_COMMUNICATION |
145 | extern struct str_GPSInfo GPSInfo; |
151 | extern struct str_GPSInfo GPSInfo; |
146 | extern struct str_SPI_VersionInfo NC_Version; |
152 | extern struct str_SPI_VersionInfo NC_Version; |
147 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
153 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
148 | extern struct str_ToNaviCtrl ToNaviCtrl; |
154 | extern struct str_ToNaviCtrl ToNaviCtrl; |
149 | extern struct str_FromNaviCtrl FromNaviCtrl; |
155 | extern struct str_FromNaviCtrl FromNaviCtrl; |
150 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
156 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
151 | 157 | ||
152 | 158 | ||
153 | extern void SPI_MasterInit(void); |
159 | extern void SPI_MasterInit(void); |
154 | extern void SPI_StartTransmitPacket(void); |
160 | extern void SPI_StartTransmitPacket(void); |
155 | extern void UpdateSPI_Buffer(void); |
161 | extern void UpdateSPI_Buffer(void); |
156 | extern void SPI_TransmitByte(void); |
162 | extern void SPI_TransmitByte(void); |
157 | #else |
163 | #else |
158 | 164 | ||
159 | 165 | ||
160 | // -------------------------------- Dummy ----------------------------------------- |
166 | // -------------------------------- Dummy ----------------------------------------- |
161 | #define SPI_MasterInit() ; |
167 | #define SPI_MasterInit() ; |
162 | #define SPI_StartTransmitPacket() ; |
168 | #define SPI_StartTransmitPacket() ; |
163 | #define UpdateSPI_Buffer() ; |
169 | #define UpdateSPI_Buffer() ; |
164 | #define SPI_TransmitByte() ; |
170 | #define SPI_TransmitByte() ; |
165 | #endif |
171 | #endif |
166 | 172 | ||
167 | 173 | ||
168 | #endif |
174 | #endif |
169 | 175 |