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