Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1754 - 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 SLAVE_SELECT_DDR_PORT   DDRC
12
#define SLAVE_SELECT_PORT       PORTC
13
 
14
#if defined(__AVR_ATmega1284P__)
15
#define DD_SS                           PORTB4
16
#define DD_SCK                          PORTB7
17
#define DD_MOSI                         PORTB5
18
#define DD_MISO                         PORTB6
19
#define SPI_SLAVE_SELECT        PORTC5
20
#else
21
#define DD_SS                           PB4
22
#define DD_SCK                          PB7
23
#define DD_MOSI                         PB5
24
#define DD_MISO                         PB6
25
#define SPI_SLAVE_SELECT        PC5
26
#endif
27
 
28
// for compatibility reasons gcc3.x <-> gcc4.x
29
#ifndef SPCR
30
#define SPCR   SPCR0
31
#endif
32
#ifndef SPE
33
#define SPE   SPE0
34
#endif
35
#ifndef MSTR
36
#define MSTR   MSTR0
37
#endif
38
#ifndef SPR1
39
#define SPR1   SPR01
40
#endif
41
#ifndef SPR0
42
#define SPR0   SPR00
43
#endif
44
#ifndef SPIE
45
#define SPIE   SPIE0
46
#endif
47
#ifndef SPDR
48
#define SPDR   SPDR0
49
#endif
50
#ifndef SPIF
51
#define SPIF   SPIF0
52
#endif
53
#ifndef SPSR
54
#define SPSR   SPSR0
55
#endif
56
// -------------------------
57
 
58
#define SPI_FCCMD_USER                  10
59
#define SPI_FCCMD_STICK                 11
60
#define SPI_FCCMD_MISC                  12
61
#define SPI_FCCMD_PARAMETER1    13
62
#define SPI_FCCMD_VERSION               14
63
#define SPI_FCCMD_SERVOS                15
64
#define SPI_FCCMD_ACCU                  16
65
 
66
struct str_ToNaviCtrl
67
{
68
        unsigned char Sync1, Sync2;
69
        unsigned char Command;
70
        signed int  IntegralNick;
71
        signed int  IntegralRoll;
72
        signed int  AccNick;
73
        signed int  AccRoll;
74
        signed int  GyroCompass;
75
        signed int  GyroNick;
76
        signed int  GyroRoll;
77
        signed int  GyroGier;
78
        union
79
        {
80
                unsigned char Byte[12];
81
                char sByte[12];
82
                unsigned int Int[6];
83
                int  sInt[6];
84
                unsigned long Long[3];
85
                long sLong[3];
86
                float Float[3];
87
        } Param;
88
        unsigned char Chksum;
89
};
90
 
91
#define SPI_NCCMD_KALMAN                103
92
#define SPI_NCCMD_VERSION               104
93
#define SPI_NCCMD_GPSINFO               105
94
 
95
struct str_FromNaviCtrl
96
{
97
        unsigned char Command;
98
        signed int  GPS_Nick;
99
        signed int  GPS_Roll;
100
        signed int  GPS_Gier;
101
        signed int  CompassValue;
102
        signed int  Status;
103
        unsigned int BeepTime;
104
        union
105
        {
106
                unsigned char Byte[12];
107
                char sByte[12];
108
                unsigned int Int[6];
109
                int  sInt[6];
110
                unsigned long Long[3];
111
                long sLong[3];
112
                float Float[3];
113
        } Param;
114
        unsigned char Chksum;
115
};
116
 
117
struct str_FromNaviCtrl_Value
118
{
119
 signed char Kalman_K;
120
 signed char Kalman_MaxDrift;
121
 signed char Kalman_MaxFusion;
122
 unsigned char SerialDataOkay;
123
 signed char GpsZ;
124
};
125
 
126
struct str_SPI_VersionInfo
127
{
128
  unsigned char Major;
129
  unsigned char Minor;
130
  unsigned char Patch;
131
  unsigned char Compatible;
132
  unsigned char Hardware;
133
};
134
 
135
// Satfix types for GPSData.SatFix
136
#define SATFIX_NONE                             0x00
137
#define SATFIX_DEADRECKOING             0x01
138
#define SATFIX_2D                               0x02
139
#define SATFIX_3D                               0x03
140
#define SATFIX_GPS_DEADRECKOING 0x04
141
#define SATFIX_TIMEONLY                 0x05
142
// Flags for interpretation of the GPSData.Flags
143
#define FLAG_GPSFIXOK                   0x01 // (i.e. within DOP & ACC Masks)
144
#define FLAG_DIFFSOLN                   0x02 // (is DGPS used)
145
#define FLAG_WKNSET                             0x04 // (is Week Number valid)
146
#define FLAG_TOWSET                             0x08 // (is Time of Week valid)
147
 
148
struct str_GPSInfo
149
{
150
        unsigned char   Flags;                  // Status Flags
151
        unsigned char   NumOfSats;              // number of satelites
152
        unsigned char   SatFix;                 // type of satfix
153
        unsigned char   Speed;                  // m/sek
154
        unsigned int    HomeDistance;   // distance to Home in dm
155
        int                             HomeBearing;    // bearing to home in deg
156
};
157
 
158
 
159
#ifdef USE_SPI_COMMUNICATION
160
extern struct str_GPSInfo GPSInfo;
161
extern struct str_SPI_VersionInfo NC_Version;
162
extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value;
163
extern struct str_ToNaviCtrl   ToNaviCtrl;
164
extern struct str_FromNaviCtrl FromNaviCtrl;
165
extern unsigned char SPI_CommandCounter,NaviDataOkay;
166
extern signed char FromNC_Rotate_C, FromNC_Rotate_S;
167
extern unsigned char NC_ErrorCode;
168
extern void SPI_MasterInit(void);
169
extern void SPI_StartTransmitPacket(void);
170
extern void UpdateSPI_Buffer(void);
171
extern void SPI_TransmitByte(void);
172
#else
173
 
174
 
175
// -------------------------------- Dummy -----------------------------------------
176
#define  SPI_MasterInit() ;
177
#define  SPI_StartTransmitPacket() ;
178
#define  UpdateSPI_Buffer() ;
179
#define  SPI_TransmitByte() ;
180
#endif
181
 
182
 
183
#endif