Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1388 | Arthur | 1 | // ######################## SPI - FlightCtrl ################### |
2 | #ifndef _SPI_H |
||
3 | #define _SPI_H |
||
4 | |||
5 | #include <util/delay.h> |
||
6 | |||
7 | #define USE_SPI_COMMUNICATION |
||
8 | |||
9 | //----------------------------------------- |
||
10 | #define DDR_SPI DDRB |
||
11 | #define DD_SS PB4 |
||
12 | #define DD_SCK PB7 |
||
13 | #define DD_MOSI PB5 |
||
14 | #define DD_MISO PB6 |
||
15 | |||
16 | // for compatibility reasons gcc3.x <-> gcc4.x |
||
17 | #ifndef SPCR |
||
18 | #define SPCR SPCR0 |
||
19 | #endif |
||
20 | #ifndef SPE |
||
21 | #define SPE SPE0 |
||
22 | #endif |
||
23 | #ifndef MSTR |
||
24 | #define MSTR MSTR0 |
||
25 | #endif |
||
26 | #ifndef SPR1 |
||
27 | #define SPR1 SPR01 |
||
28 | #endif |
||
29 | #ifndef SPR0 |
||
30 | #define SPR0 SPR00 |
||
31 | #endif |
||
32 | #ifndef SPIE |
||
33 | #define SPIE SPIE0 |
||
34 | #endif |
||
35 | #ifndef SPDR |
||
36 | #define SPDR SPDR0 |
||
37 | #endif |
||
38 | #ifndef SPIF |
||
39 | #define SPIF SPIF0 |
||
40 | #endif |
||
41 | #ifndef SPSR |
||
42 | #define SPSR SPSR0 |
||
43 | #endif |
||
44 | // ------------------------- |
||
45 | |||
46 | #define SLAVE_SELECT_DDR_PORT DDRC |
||
47 | #define SLAVE_SELECT_PORT PORTC |
||
48 | #define SPI_SLAVE_SELECT PC5 |
||
49 | |||
50 | |||
51 | #define SPI_CMD_USER 10 |
||
52 | #define SPI_CMD_STICK 11 |
||
53 | #define SPI_CMD_MISC 12 |
||
54 | #define SPI_CMD_PARAMETER1 13 |
||
55 | #define SPI_CMD_VERSION 14 |
||
56 | #define SPI_CMD_SERVOS 15 |
||
57 | |||
58 | struct str_ToNaviCtrl |
||
59 | { |
||
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; |
||
79 | }; |
||
80 | |||
81 | #define SPI_KALMAN 103 |
||
82 | |||
83 | struct str_FromNaviCtrl |
||
84 | { |
||
85 | unsigned char Command; |
||
86 | signed int GPS_Nick; |
||
87 | signed int GPS_Roll; |
||
88 | signed int GPS_Gier; |
||
89 | signed int CompassValue; |
||
90 | signed int Status; |
||
91 | unsigned int BeepTime; |
||
92 | union |
||
93 | { |
||
94 | char sByte[12]; |
||
95 | unsigned char Byte[12]; |
||
96 | int Int[6]; |
||
97 | long Long[3]; |
||
98 | float Float[3]; |
||
99 | } Param; |
||
100 | unsigned char Chksum; |
||
101 | }; |
||
102 | |||
103 | struct str_FromNaviCtrl_Value |
||
104 | { |
||
105 | signed char Kalman_K; |
||
106 | signed char Kalman_MaxDrift; |
||
107 | signed char Kalman_MaxFusion; |
||
108 | unsigned char SerialDataOkay; |
||
109 | signed char GpsZ; |
||
110 | }; |
||
111 | |||
112 | struct str_SPI_VersionInfo |
||
113 | { |
||
114 | unsigned char Major; |
||
115 | unsigned char Minor; |
||
116 | unsigned char Patch; |
||
117 | unsigned char Compatible; |
||
118 | }; |
||
119 | |||
120 | #ifdef USE_SPI_COMMUNICATION |
||
121 | |||
122 | extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
||
123 | extern struct str_ToNaviCtrl ToNaviCtrl; |
||
124 | extern struct str_FromNaviCtrl FromNaviCtrl; |
||
125 | extern unsigned char SPI_CommandCounter,NaviDataOkay; |
||
126 | |||
127 | //#define SPI_CMD_VALUE 0x03 |
||
128 | |||
129 | extern void SPI_MasterInit(void); |
||
130 | extern void SPI_StartTransmitPacket(void); |
||
131 | extern void UpdateSPI_Buffer(void); |
||
132 | extern void SPI_TransmitByte(void); |
||
133 | #else |
||
134 | |||
135 | |||
136 | // -------------------------------- Dummy ----------------------------------------- |
||
137 | #define SPI_MasterInit() ; |
||
138 | #define SPI_StartTransmitPacket() ; |
||
139 | #define UpdateSPI_Buffer() ; |
||
140 | #define SPI_TransmitByte() ; |
||
141 | #endif |
||
142 | |||
143 | |||
144 | #endif |