Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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