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