Rev 1241 | Rev 1448 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1241 | Rev 1283 | ||
---|---|---|---|
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 | - | ||
9 | #define SPI_PROTOCOL_COMP 1 |
- | |
10 | 8 | ||
11 | //----------------------------------------- |
9 | //----------------------------------------- |
12 | #define DDR_SPI DDRB |
10 | #define DDR_SPI DDRB |
13 | #define DD_SS PB4 |
11 | #define DD_SS PB4 |
14 | #define DD_SCK PB7 |
12 | #define DD_SCK PB7 |
15 | #define DD_MOSI PB5 |
13 | #define DD_MOSI PB5 |
16 | #define DD_MISO PB6 |
14 | #define DD_MISO PB6 |
17 | 15 | ||
18 | // for compatibility reasons gcc3.x <-> gcc4.x |
16 | // for compatibility reasons gcc3.x <-> gcc4.x |
19 | #ifndef SPCR |
17 | #ifndef SPCR |
20 | #define SPCR SPCR0 |
18 | #define SPCR SPCR0 |
21 | #endif |
19 | #endif |
22 | #ifndef SPE |
20 | #ifndef SPE |
23 | #define SPE SPE0 |
21 | #define SPE SPE0 |
24 | #endif |
22 | #endif |
25 | #ifndef MSTR |
23 | #ifndef MSTR |
26 | #define MSTR MSTR0 |
24 | #define MSTR MSTR0 |
27 | #endif |
25 | #endif |
28 | #ifndef SPR1 |
26 | #ifndef SPR1 |
29 | #define SPR1 SPR01 |
27 | #define SPR1 SPR01 |
30 | #endif |
28 | #endif |
31 | #ifndef SPR0 |
29 | #ifndef SPR0 |
32 | #define SPR0 SPR00 |
30 | #define SPR0 SPR00 |
33 | #endif |
31 | #endif |
34 | #ifndef SPIE |
32 | #ifndef SPIE |
35 | #define SPIE SPIE0 |
33 | #define SPIE SPIE0 |
36 | #endif |
34 | #endif |
37 | #ifndef SPDR |
35 | #ifndef SPDR |
38 | #define SPDR SPDR0 |
36 | #define SPDR SPDR0 |
39 | #endif |
37 | #endif |
40 | #ifndef SPIF |
38 | #ifndef SPIF |
41 | #define SPIF SPIF0 |
39 | #define SPIF SPIF0 |
42 | #endif |
40 | #endif |
43 | #ifndef SPSR |
41 | #ifndef SPSR |
44 | #define SPSR SPSR0 |
42 | #define SPSR SPSR0 |
45 | #endif |
43 | #endif |
46 | // ------------------------- |
44 | // ------------------------- |
47 | 45 | ||
48 | #define SLAVE_SELECT_DDR_PORT DDRC |
46 | #define SLAVE_SELECT_DDR_PORT DDRC |
49 | #define SLAVE_SELECT_PORT PORTC |
47 | #define SLAVE_SELECT_PORT PORTC |
50 | #define SPI_SLAVE_SELECT PC5 |
48 | #define SPI_SLAVE_SELECT PC5 |
51 | 49 | ||
52 | 50 | ||
53 | #define SPI_CMD_USER 10 |
51 | #define SPI_CMD_USER 10 |
54 | #define SPI_CMD_STICK 11 |
52 | #define SPI_CMD_STICK 11 |
55 | #define SPI_CMD_MISC 12 |
53 | #define SPI_CMD_MISC 12 |
56 | #define SPI_CMD_PARAMETER1 13 |
54 | #define SPI_CMD_PARAMETER1 13 |
57 | #define SPI_CMD_VERSION 14 |
55 | #define SPI_CMD_VERSION 14 |
58 | #define SPI_CMD_SERVOS 15 |
56 | #define SPI_CMD_SERVOS 15 |
59 | 57 | ||
60 | struct str_ToNaviCtrl |
58 | struct str_ToNaviCtrl |
61 | { |
59 | { |
62 | unsigned char Sync1, Sync2; |
60 | unsigned char Sync1, Sync2; |
63 | unsigned char Command; |
61 | unsigned char Command; |
64 | signed int IntegralNick; |
62 | signed int IntegralNick; |
65 | signed int IntegralRoll; |
63 | signed int IntegralRoll; |
66 | signed int AccNick; |
64 | signed int AccNick; |
67 | signed int AccRoll; |
65 | signed int AccRoll; |
68 | signed int GyroCompass; |
66 | signed int GyroCompass; |
69 | signed int GyroNick; |
67 | signed int GyroNick; |
70 | signed int GyroRoll; |
68 | signed int GyroRoll; |
71 | signed int GyroGier; |
69 | signed int GyroGier; |
72 | union |
70 | union |
73 | { |
71 | { |
74 | char sByte[12]; |
72 | char sByte[12]; |
75 | unsigned char Byte[12]; |
73 | unsigned char Byte[12]; |
76 | int Int[6]; |
74 | int Int[6]; |
77 | long Long[3]; |
75 | long Long[3]; |
78 | float Float[3]; |
76 | float Float[3]; |
79 | } Param; |
77 | } Param; |
80 | unsigned char Chksum; |
78 | unsigned char Chksum; |
81 | }; |
79 | }; |
82 | 80 | ||
83 | #define SPI_KALMAN 103 |
81 | #define SPI_KALMAN 103 |
84 | 82 | ||
85 | struct str_FromNaviCtrl |
83 | struct str_FromNaviCtrl |
86 | { |
84 | { |
87 | unsigned char Command; |
85 | unsigned char Command; |
88 | signed int GPS_Nick; |
86 | signed int GPS_Nick; |
89 | signed int GPS_Roll; |
87 | signed int GPS_Roll; |
90 | signed int GPS_Gier; |
88 | signed int GPS_Gier; |
91 | signed int CompassValue; |
89 | signed int CompassValue; |
92 | signed int Status; |
90 | signed int Status; |
93 | unsigned int BeepTime; |
91 | unsigned int BeepTime; |
94 | union |
92 | union |
95 | { |
93 | { |
96 | char sByte[12]; |
94 | char sByte[12]; |
97 | unsigned char Byte[12]; |
95 | unsigned char Byte[12]; |
98 | int Int[6]; |
96 | int Int[6]; |
99 | long Long[3]; |
97 | long Long[3]; |
100 | float Float[3]; |
98 | float Float[3]; |
101 | } Param; |
99 | } Param; |
102 | unsigned char Chksum; |
100 | unsigned char Chksum; |
103 | }; |
101 | }; |
104 | 102 | ||
105 | struct str_FromNaviCtrl_Value |
103 | struct str_FromNaviCtrl_Value |
106 | { |
104 | { |
107 | signed char Kalman_K; |
105 | signed char Kalman_K; |
108 | signed char Kalman_MaxDrift; |
106 | signed char Kalman_MaxDrift; |
109 | signed char Kalman_MaxFusion; |
107 | signed char Kalman_MaxFusion; |
110 | unsigned char SerialDataOkay; |
108 | unsigned char SerialDataOkay; |
- | 109 | signed char GpsZ; |
|
111 | }; |
110 | }; |
112 | 111 | ||
113 | struct str_SPI_VersionInfo |
112 | struct str_SPI_VersionInfo |
114 | { |
113 | { |
115 | unsigned char Major; |
114 | unsigned char Major; |
116 | unsigned char Minor; |
115 | unsigned char Minor; |
117 | unsigned char Patch; |
116 | unsigned char Patch; |
118 | unsigned char Compatible; |
117 | unsigned char Compatible; |
119 | }; |
118 | }; |
120 | 119 | ||
121 | #ifdef USE_SPI_COMMUNICATION |
120 | #ifdef USE_SPI_COMMUNICATION |
122 | 121 | ||
123 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
122 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
124 | extern struct str_ToNaviCtrl ToNaviCtrl; |
123 | extern struct str_ToNaviCtrl ToNaviCtrl; |
125 | extern struct str_FromNaviCtrl FromNaviCtrl; |
124 | extern struct str_FromNaviCtrl FromNaviCtrl; |
126 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
125 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
127 | 126 | ||
128 | //#define SPI_CMD_VALUE 0x03 |
127 | //#define SPI_CMD_VALUE 0x03 |
129 | 128 | ||
130 | extern void SPI_MasterInit(void); |
129 | extern void SPI_MasterInit(void); |
131 | extern void SPI_StartTransmitPacket(void); |
130 | extern void SPI_StartTransmitPacket(void); |
132 | extern void UpdateSPI_Buffer(void); |
131 | extern void UpdateSPI_Buffer(void); |
133 | extern void SPI_TransmitByte(void); |
132 | extern void SPI_TransmitByte(void); |
134 | #else |
133 | #else |
135 | 134 | ||
136 | 135 | ||
137 | // -------------------------------- Dummy ----------------------------------------- |
136 | // -------------------------------- Dummy ----------------------------------------- |
138 | #define SPI_MasterInit() ; |
137 | #define SPI_MasterInit() ; |
139 | #define SPI_StartTransmitPacket() ; |
138 | #define SPI_StartTransmitPacket() ; |
140 | #define UpdateSPI_Buffer() ; |
139 | #define UpdateSPI_Buffer() ; |
141 | #define SPI_TransmitByte() ; |
140 | #define SPI_TransmitByte() ; |
142 | #endif |
141 | #endif |
143 | 142 | ||
144 | 143 | ||
145 | #endif |
144 | #endif |
146 | 145 |