Rev 708 | Rev 720 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 708 | Rev 709 | ||
---|---|---|---|
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 | struct str_ToNaviCtrl_Value |
52 | struct str_ToNaviCtrl_Value |
53 | { |
53 | { |
54 | unsigned char Sync1, Sync2; |
54 | unsigned char Sync1, Sync2; |
55 | unsigned char Command; |
55 | unsigned char Command; |
56 | signed int IntegralNick; |
56 | signed int IntegralNick; |
57 | signed int IntegralRoll; |
57 | signed int IntegralRoll; |
58 | char StickNick,StickRoll, |
58 | char StickNick,StickRoll, |
59 | StickGier, StickGas, |
59 | StickGier, StickGas; |
60 | Poti1,Poti2, |
- | |
61 | Poti3,Poti4; |
- | |
62 | signed int GyroCompass; |
60 | signed int GyroCompass; |
63 | signed int d0; |
- | |
64 | signed int d1; |
61 | char User1, User2, User3, User4, User5, User6, User7, User8; |
65 | unsigned char Chksum; |
62 | unsigned char Chksum; |
66 | }; |
63 | }; |
67 | 64 | ||
68 | struct str_ToNaviCtrl_Version |
65 | struct str_ToNaviCtrl_Version |
69 | { |
66 | { |
70 | unsigned char Sync1, Sync2; |
67 | unsigned char Sync1, Sync2; |
71 | unsigned char Command; |
68 | unsigned char Command; |
72 | unsigned char HVersion; |
69 | unsigned char HVersion; |
73 | unsigned char NVersion; |
70 | unsigned char NVersion; |
74 | unsigned char Comp; |
71 | unsigned char Comp; |
75 | unsigned char d0; |
72 | unsigned char d0; |
76 | signed int d1; |
73 | signed int d1; |
77 | signed int d2; |
74 | signed int d2; |
78 | signed int d3; |
75 | signed int d3; |
79 | signed int d4; |
76 | signed int d4; |
80 | signed int d5; |
77 | signed int d5; |
81 | signed int d6; |
78 | signed int d6; |
82 | signed int d7; |
79 | signed int d7; |
83 | unsigned char Chksum; |
80 | unsigned char Chksum; |
84 | }; |
81 | }; |
85 | 82 | ||
86 | struct str_FromNaviCtrl_Value |
83 | struct str_FromNaviCtrl_Value |
87 | { |
84 | { |
88 | unsigned char Command; |
85 | unsigned char Command; |
89 | signed int GPS_Nick; |
86 | signed int GPS_Nick; |
90 | signed int GPS_Roll; |
87 | signed int GPS_Roll; |
91 | signed int GPS_Gier; |
88 | signed int GPS_Gier; |
92 | signed int GPS_Height; |
89 | signed int GPS_Height; |
93 | signed int CompassValue; |
90 | signed int CompassValue; |
94 | signed int Status; |
91 | signed int Status; |
95 | signed int d0; |
92 | signed int d0; |
96 | signed int d1; |
93 | signed int d1; |
97 | signed int d2; |
94 | signed int d2; |
98 | unsigned char Chksum; |
95 | unsigned char Chksum; |
99 | }; |
96 | }; |
100 | 97 | ||
101 | struct str_FromNaviCtrl_Version |
98 | struct str_FromNaviCtrl_Version |
102 | { |
99 | { |
103 | unsigned char Command; |
100 | unsigned char Command; |
104 | unsigned char HVersion; |
101 | unsigned char HVersion; |
105 | unsigned char NVersion; |
102 | unsigned char NVersion; |
106 | unsigned char Comp; |
103 | unsigned char Comp; |
107 | unsigned char d0; |
104 | unsigned char d0; |
108 | signed int d1; |
105 | signed int d1; |
109 | signed int d2; |
106 | signed int d2; |
110 | signed int d3; |
107 | signed int d3; |
111 | signed int d4; |
108 | signed int d4; |
112 | signed int d5; |
109 | signed int d5; |
113 | signed int d6; |
110 | signed int d6; |
114 | signed int d7; |
111 | signed int d7; |
115 | unsigned char Chksum; |
112 | unsigned char Chksum; |
116 | }; |
113 | }; |
117 | 114 | ||
118 | #ifdef USE_SPI_COMMUNICATION |
115 | #ifdef USE_SPI_COMMUNICATION |
119 | extern struct str_ToNaviCtrl_Version ToNaviCtrl_Version; |
116 | extern struct str_ToNaviCtrl_Version ToNaviCtrl_Version; |
120 | extern struct str_FromNaviCtrl_Version FromNaviCtrl_Version; |
117 | extern struct str_FromNaviCtrl_Version FromNaviCtrl_Version; |
121 | 118 | ||
122 | extern struct str_ToNaviCtrl_Value ToNaviCtrl_Value; |
119 | extern struct str_ToNaviCtrl_Value ToNaviCtrl_Value; |
123 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
120 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
124 | 121 | ||
125 | #define SPI_CMD_VERSION 0x02 |
122 | #define SPI_CMD_VERSION 0x02 |
126 | #define SPI_CMD_VALUE 0x03 |
123 | #define SPI_CMD_VALUE 0x03 |
127 | 124 | ||
128 | extern void SPI_MasterInit(void); |
125 | extern void SPI_MasterInit(void); |
129 | extern void SPI_StartTransmitPacket(unsigned char command); |
126 | extern void SPI_StartTransmitPacket(unsigned char command); |
130 | extern void UpdateSPI_Buffer(void); |
127 | extern void UpdateSPI_Buffer(void); |
131 | extern void SPI_TransmitByte(void); |
128 | extern void SPI_TransmitByte(void); |
132 | #else |
129 | #else |
133 | 130 | ||
134 | 131 | ||
135 | // -------------------------------- Dummy ----------------------------------------- |
132 | // -------------------------------- Dummy ----------------------------------------- |
136 | #define SPI_MasterInit() ; |
133 | #define SPI_MasterInit() ; |
137 | #define SPI_StartTransmitPacket() ; |
134 | #define SPI_StartTransmitPacket() ; |
138 | #define UpdateSPI_Buffer() ; |
135 | #define UpdateSPI_Buffer() ; |
139 | #define SPI_TransmitByte() ; |
136 | #define SPI_TransmitByte() ; |
140 | #endif |
137 | #endif |
141 | 138 | ||
142 | 139 | ||
143 | #endif |
140 | #endif |
144 | 141 |