Rev 1448 | Rev 1472 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
827 | ingob | 1 | // ######################## SPI - FlightCtrl ################### |
2 | #ifndef _SPI_H |
||
3 | #define _SPI_H |
||
4 | |||
5 | #include <util/delay.h> |
||
6 | |||
1051 | killagreg | 7 | #define USE_SPI_COMMUNICATION |
827 | ingob | 8 | |
9 | //----------------------------------------- |
||
10 | #define DDR_SPI DDRB |
||
11 | #define DD_SS PB4 |
||
12 | #define DD_SCK PB7 |
||
13 | #define DD_MOSI PB5 |
||
1051 | killagreg | 14 | #define DD_MISO PB6 |
827 | ingob | 15 | |
1051 | killagreg | 16 | // for compatibility reasons gcc3.x <-> gcc4.x |
17 | #ifndef SPCR |
||
827 | ingob | 18 | #define SPCR SPCR0 |
1051 | killagreg | 19 | #endif |
20 | #ifndef SPE |
||
827 | ingob | 21 | #define SPE SPE0 |
1051 | killagreg | 22 | #endif |
23 | #ifndef MSTR |
||
827 | ingob | 24 | #define MSTR MSTR0 |
1051 | killagreg | 25 | #endif |
26 | #ifndef SPR1 |
||
827 | ingob | 27 | #define SPR1 SPR01 |
1051 | killagreg | 28 | #endif |
29 | #ifndef SPR0 |
||
827 | ingob | 30 | #define SPR0 SPR00 |
1051 | killagreg | 31 | #endif |
32 | #ifndef SPIE |
||
827 | ingob | 33 | #define SPIE SPIE0 |
1051 | killagreg | 34 | #endif |
35 | #ifndef SPDR |
||
827 | ingob | 36 | #define SPDR SPDR0 |
1051 | killagreg | 37 | #endif |
38 | #ifndef SPIF |
||
827 | ingob | 39 | #define SPIF SPIF0 |
1051 | killagreg | 40 | #endif |
41 | #ifndef SPSR |
||
827 | ingob | 42 | #define SPSR SPSR0 |
1051 | killagreg | 43 | #endif |
827 | ingob | 44 | // ------------------------- |
45 | |||
46 | #define SLAVE_SELECT_DDR_PORT DDRC |
||
47 | #define SLAVE_SELECT_PORT PORTC |
||
48 | #define SPI_SLAVE_SELECT PC5 |
||
49 | |||
50 | |||
1448 | killagreg | 51 | #define SPI_FCCMD_USER 10 |
52 | #define SPI_FCCMD_STICK 11 |
||
53 | #define SPI_FCCMD_MISC 12 |
||
54 | #define SPI_FCCMD_PARAMETER1 13 |
||
55 | #define SPI_FCCMD_VERSION 14 |
||
56 | #define SPI_FCCMD_SERVOS 15 |
||
991 | ingob | 57 | |
827 | ingob | 58 | struct str_ToNaviCtrl |
59 | { |
||
1231 | killagreg | 60 | unsigned char Sync1, Sync2; |
61 | unsigned char Command; |
||
62 | signed int IntegralNick; |
||
63 | signed int IntegralRoll; |
||
64 | signed int AccNick; |
||
65 | signed int AccRoll; |
||
66 | signed int GyroCompass; |
||
67 | signed int GyroNick; |
||
68 | signed int GyroRoll; |
||
69 | signed int GyroGier; |
||
70 | union |
||
71 | { |
||
72 | char sByte[12]; |
||
73 | unsigned char Byte[12]; |
||
74 | int Int[6]; |
||
75 | long Long[3]; |
||
76 | float Float[3]; |
||
77 | } Param; |
||
78 | unsigned char Chksum; |
||
1051 | killagreg | 79 | }; |
827 | ingob | 80 | |
1448 | killagreg | 81 | #define SPI_NCCMD_KALMAN 103 |
82 | #define SPI_NCCMD_VERSION 104 |
||
1451 | killagreg | 83 | #define SPI_NCCMD_GPSINFO 105 |
1241 | killagreg | 84 | |
827 | ingob | 85 | struct str_FromNaviCtrl |
86 | { |
||
1231 | killagreg | 87 | unsigned char Command; |
88 | signed int GPS_Nick; |
||
89 | signed int GPS_Roll; |
||
90 | signed int GPS_Gier; |
||
91 | signed int CompassValue; |
||
92 | signed int Status; |
||
93 | unsigned int BeepTime; |
||
94 | union |
||
95 | { |
||
96 | char sByte[12]; |
||
97 | unsigned char Byte[12]; |
||
98 | int Int[6]; |
||
99 | long Long[3]; |
||
100 | float Float[3]; |
||
101 | } Param; |
||
102 | unsigned char Chksum; |
||
1051 | killagreg | 103 | }; |
827 | ingob | 104 | |
978 | hbuss | 105 | struct str_FromNaviCtrl_Value |
106 | { |
||
992 | hbuss | 107 | signed char Kalman_K; |
108 | signed char Kalman_MaxDrift; |
||
109 | signed char Kalman_MaxFusion; |
||
1215 | hbuss | 110 | unsigned char SerialDataOkay; |
1283 | hbuss | 111 | signed char GpsZ; |
978 | hbuss | 112 | }; |
827 | ingob | 113 | |
1051 | killagreg | 114 | struct str_SPI_VersionInfo |
115 | { |
||
116 | unsigned char Major; |
||
117 | unsigned char Minor; |
||
118 | unsigned char Patch; |
||
119 | unsigned char Compatible; |
||
1448 | killagreg | 120 | unsigned char Hardware; |
1051 | killagreg | 121 | }; |
122 | |||
1451 | killagreg | 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 |
||
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 | |||
827 | ingob | 144 | #ifdef USE_SPI_COMMUNICATION |
1451 | killagreg | 145 | extern struct str_GPSInfo GPSInfo; |
1448 | killagreg | 146 | extern struct str_SPI_VersionInfo NC_Version; |
978 | hbuss | 147 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
827 | ingob | 148 | extern struct str_ToNaviCtrl ToNaviCtrl; |
149 | extern struct str_FromNaviCtrl FromNaviCtrl; |
||
1215 | hbuss | 150 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
827 | ingob | 151 | |
152 | |||
153 | extern void SPI_MasterInit(void); |
||
154 | extern void SPI_StartTransmitPacket(void); |
||
155 | extern void UpdateSPI_Buffer(void); |
||
156 | extern void SPI_TransmitByte(void); |
||
157 | #else |
||
158 | |||
159 | |||
160 | // -------------------------------- Dummy ----------------------------------------- |
||
1051 | killagreg | 161 | #define SPI_MasterInit() ; |
827 | ingob | 162 | #define SPI_StartTransmitPacket() ; |
163 | #define UpdateSPI_Buffer() ; |
||
164 | #define SPI_TransmitByte() ; |
||
165 | #endif |
||
166 | |||
167 | |||
168 | #endif |