Rev 819 | Rev 825 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 819 | Rev 823 | ||
---|---|---|---|
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 | ||
- | 52 | ||
- | 53 | #define SPI_CMD_USER 10 |
|
- | 54 | #define SPI_CMD_STICK 11 |
|
51 | 55 | #define SPI_CMD_CAL_COMPASS 12 |
|
52 | struct str_ToNaviCtrl_Value |
56 | struct str_ToNaviCtrl |
53 | { |
57 | { |
54 | unsigned char Sync1, Sync2; |
58 | unsigned char Sync1, Sync2; |
55 | unsigned char Command; |
59 | unsigned char Command; |
56 | signed int IntegralNick; |
60 | signed int IntegralNick; |
57 | signed int IntegralRoll; |
61 | signed int IntegralRoll; |
58 | signed int AccNick; |
62 | signed int AccNick; |
59 | signed int AccRoll; |
63 | signed int AccRoll; |
60 | char StickNick,StickRoll, StickGier, StickGas; |
- | |
61 | signed int GyroCompass; |
64 | signed int GyroCompass; |
- | 65 | signed int GyroNick; |
|
62 | unsigned char User1, User2, User3, User4, User5, User6, User7;//, User8; |
66 | signed int GyroRoll; |
63 | unsigned char CalState; |
67 | signed int GyroGier; |
- | 68 | union |
|
- | 69 | { char Byte[12]; |
|
- | 70 | int Int[6]; |
|
- | 71 | long Long[3]; |
|
- | 72 | float Float[3]; |
|
- | 73 | } Param; |
|
64 | unsigned char Chksum; |
74 | unsigned char Chksum; |
65 | }; |
75 | }; |
66 | 76 | ||
67 | struct str_ToNaviCtrl_Version |
- | |
68 | { |
77 | #define SPI_CMD_OSD_DATA 100 |
69 | unsigned char Sync1, Sync2; |
- | |
70 | unsigned char Command; |
- | |
71 | unsigned char HVersion; |
- | |
72 | unsigned char NVersion; |
- | |
73 | unsigned char Comp; |
78 | #define SPI_CMD_GPS_POS 101 |
74 | unsigned char ActualSettingNo; |
- | |
75 | unsigned char MinimumSatNo; |
- | |
76 | unsigned char d1; |
- | |
77 | signed int d2; |
- | |
78 | signed int d3; |
- | |
79 | signed int d4; |
- | |
80 | signed int d5; |
- | |
81 | signed int d6; |
- | |
82 | signed int d7; |
- | |
83 | unsigned char Chksum; |
- | |
84 | }; |
- | |
85 | 79 | #define SPI_CMD_GPS_TARGET 102 |
|
86 | struct str_FromNaviCtrl_Value |
80 | struct str_FromNaviCtrl |
87 | { |
81 | { |
88 | unsigned char Command; |
82 | unsigned char Command; |
89 | signed int GPS_Nick; |
83 | signed int GPS_Nick; |
90 | signed int GPS_Roll; |
84 | signed int GPS_Roll; |
91 | signed int GPS_Gier; |
85 | signed int GPS_Gier; |
92 | signed int GPS_Height; |
- | |
93 | signed int CompassValue; |
86 | signed int CompassValue; |
94 | signed int Status; |
87 | signed int Status; |
95 | unsigned char BeepTime; |
88 | unsigned char BeepTime; |
- | 89 | union |
|
96 | unsigned char OsdBar; |
90 | { char Byte[12]; |
97 | signed int Distance; |
91 | int Int[6]; |
98 | signed int d2; |
92 | long Long[3]; |
99 | signed int d3; |
93 | float Float[3]; |
100 | signed int d4; |
94 | } Param; |
101 | unsigned char Chksum; |
95 | unsigned char Chksum; |
102 | }; |
96 | }; |
103 | - | ||
104 | struct str_FromNaviCtrl_Version |
- | |
105 | { |
- | |
106 | unsigned char Command; |
- | |
107 | unsigned char HVersion; |
- | |
108 | unsigned char NVersion; |
- | |
109 | unsigned char Comp; |
- | |
110 | unsigned char d0; |
- | |
111 | signed int d1; |
- | |
112 | signed int d2; |
- | |
113 | signed int d3; |
- | |
114 | signed int d4; |
- | |
115 | signed int d5; |
- | |
116 | signed int d6; |
- | |
117 | signed int d7; |
- | |
118 | unsigned char Chksum; |
- | |
119 | }; |
97 | |
120 | - | ||
121 | #ifdef USE_SPI_COMMUNICATION |
- | |
122 | extern struct str_ToNaviCtrl_Version ToNaviCtrl_Version; |
98 | |
123 | extern struct str_FromNaviCtrl_Version FromNaviCtrl_Version; |
99 | #ifdef USE_SPI_COMMUNICATION |
124 | - | ||
125 | extern struct str_ToNaviCtrl_Value ToNaviCtrl_Value; |
100 | |
126 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
101 | extern struct str_ToNaviCtrl ToNaviCtrl; |
127 | 102 | extern struct str_FromNaviCtrl FromNaviCtrl; |
|
128 | #define SPI_CMD_VERSION 0x02 |
103 | |
129 | #define SPI_CMD_VALUE 0x03 |
104 | //#define SPI_CMD_VALUE 0x03 |
130 | 105 | ||
131 | extern void SPI_MasterInit(void); |
106 | extern void SPI_MasterInit(void); |
132 | extern void SPI_StartTransmitPacket(unsigned char command); |
107 | extern void SPI_StartTransmitPacket(void); |
133 | extern void UpdateSPI_Buffer(void); |
108 | extern void UpdateSPI_Buffer(void); |
134 | extern void SPI_TransmitByte(void); |
109 | extern void SPI_TransmitByte(void); |
135 | #else |
110 | #else |
136 | 111 | ||
137 | 112 | ||
138 | // -------------------------------- Dummy ----------------------------------------- |
113 | // -------------------------------- Dummy ----------------------------------------- |
139 | #define SPI_MasterInit() ; |
114 | #define SPI_MasterInit() ; |
140 | #define SPI_StartTransmitPacket() ; |
115 | #define SPI_StartTransmitPacket() ; |
141 | #define UpdateSPI_Buffer() ; |
116 | #define UpdateSPI_Buffer() ; |
142 | #define SPI_TransmitByte() ; |
117 | #define SPI_TransmitByte() ; |
143 | #endif |
118 | #endif |
144 | 119 | ||
145 | 120 | ||
146 | #endif |
121 | #endif |
147 | 122 |