Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1234 | ligi | 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 | #define SPI_PROTOCOL_COMP 1 |
||
10 | |||
11 | //----------------------------------------- |
||
12 | #define DDR_SPI DDRB |
||
13 | #define DD_SS PB4 |
||
14 | #define DD_SCK PB7 |
||
15 | #define DD_MOSI PB5 |
||
16 | #define DD_MISO PB6 |
||
17 | |||
18 | // for compatibility reasons gcc3.x <-> gcc4.x |
||
19 | #ifndef SPCR |
||
20 | #define SPCR SPCR0 |
||
21 | #endif |
||
22 | #ifndef SPE |
||
23 | #define SPE SPE0 |
||
24 | #endif |
||
25 | #ifndef MSTR |
||
26 | #define MSTR MSTR0 |
||
27 | #endif |
||
28 | #ifndef SPR1 |
||
29 | #define SPR1 SPR01 |
||
30 | #endif |
||
31 | #ifndef SPR0 |
||
32 | #define SPR0 SPR00 |
||
33 | #endif |
||
34 | #ifndef SPIE |
||
35 | #define SPIE SPIE0 |
||
36 | #endif |
||
37 | #ifndef SPDR |
||
38 | #define SPDR SPDR0 |
||
39 | #endif |
||
40 | #ifndef SPIF |
||
41 | #define SPIF SPIF0 |
||
42 | #endif |
||
43 | #ifndef SPSR |
||
44 | #define SPSR SPSR0 |
||
45 | #endif |
||
46 | // ------------------------- |
||
47 | |||
48 | #define SLAVE_SELECT_DDR_PORT DDRC |
||
49 | #define SLAVE_SELECT_PORT PORTC |
||
50 | #define SPI_SLAVE_SELECT PC5 |
||
51 | |||
52 | |||
53 | #define SPI_CMD_USER 10 |
||
54 | #define SPI_CMD_STICK 11 |
||
55 | #define SPI_CMD_MISC 12 |
||
56 | #define SPI_CMD_PARAMETER1 13 |
||
57 | #define SPI_CMD_VERSION 14 |
||
58 | |||
59 | struct str_ToNaviCtrl |
||
60 | { |
||
61 | unsigned char Sync1, Sync2; |
||
62 | unsigned char Command; |
||
63 | signed int IntegralNick; |
||
64 | signed int IntegralRoll; |
||
65 | signed int AccNick; |
||
66 | signed int AccRoll; |
||
67 | signed int GyroCompass; |
||
68 | signed int GyroNick; |
||
69 | signed int GyroRoll; |
||
70 | signed int GyroGier; |
||
71 | union |
||
72 | { |
||
73 | char sByte[12]; |
||
74 | unsigned char Byte[12]; |
||
75 | int Int[6]; |
||
76 | long Long[3]; |
||
77 | float Float[3]; |
||
78 | } Param; |
||
79 | unsigned char Chksum; |
||
80 | }; |
||
81 | |||
82 | #define SPI_KALMAN 103 |
||
83 | #define SPI_EXTCTRL 104 |
||
84 | struct str_FromNaviCtrl |
||
85 | { |
||
86 | unsigned char Command; |
||
87 | signed int GPS_Nick; |
||
88 | signed int GPS_Roll; |
||
89 | signed int GPS_Gier; |
||
90 | signed int CompassValue; |
||
91 | signed int Status; |
||
92 | unsigned int BeepTime; |
||
93 | union |
||
94 | { |
||
95 | char sByte[12]; |
||
96 | unsigned char Byte[12]; |
||
97 | int Int[6]; |
||
98 | long Long[3]; |
||
99 | float Float[3]; |
||
100 | } Param; |
||
101 | unsigned char Chksum; |
||
102 | }; |
||
103 | |||
104 | struct str_FromNaviCtrl_Value |
||
105 | { |
||
106 | signed char Kalman_K; |
||
107 | signed char Kalman_MaxDrift; |
||
108 | signed char Kalman_MaxFusion; |
||
109 | unsigned char SerialDataOkay; |
||
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 |