Subversion Repositories FlightCtrl

Rev

Rev 921 | Rev 989 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 921 Rev 978
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
 
52
 
53
#define SPI_CMD_USER        10
53
#define SPI_CMD_USER        10
54
#define SPI_CMD_STICK       11
54
#define SPI_CMD_STICK       11
55
#define SPI_CMD_CAL_COMPASS 12
55
#define SPI_CMD_CAL_COMPASS 12
56
#define SPI_CMD_PARAMETER1  13
56
#define SPI_CMD_PARAMETER1  13
57
struct str_ToNaviCtrl
57
struct str_ToNaviCtrl
58
{
58
{
59
 unsigned char Sync1, Sync2;
59
 unsigned char Sync1, Sync2;
60
 unsigned char Command;
60
 unsigned char Command;
61
 signed int  IntegralNick;
61
 signed int  IntegralNick;
62
 signed int  IntegralRoll;
62
 signed int  IntegralRoll;
63
 signed int  AccNick;
63
 signed int  AccNick;
64
 signed int  AccRoll;
64
 signed int  AccRoll;
65
 signed int  GyroCompass;
65
 signed int  GyroCompass;
66
 signed int  GyroNick;
66
 signed int  GyroNick;
67
 signed int  GyroRoll;
67
 signed int  GyroRoll;
68
 signed int  GyroGier;
68
 signed int  GyroGier;
69
 union  
69
 union  
70
 { char Byte[12];
70
 { char Byte[12];
71
   int  Int[6];
71
   int  Int[6];
72
   long Long[3];
72
   long Long[3];
73
   float Float[3];
73
   float Float[3];
74
 } Param;
74
 } Param;
75
 unsigned char Chksum;
75
 unsigned char Chksum;
76
};
76
};
77
 
77
 
78
#define SPI_CMD_OSD_DATA         100
78
#define SPI_CMD_OSD_DATA         100
79
#define SPI_CMD_GPS_POS          101
79
#define SPI_CMD_GPS_POS          101
80
#define SPI_CMD_GPS_TARGET   102 
80
#define SPI_CMD_GPS_TARGET   102 
81
struct str_FromNaviCtrl
81
struct str_FromNaviCtrl
82
{
82
{
83
 unsigned char Command;
83
 unsigned char Command;
84
  signed int  GPS_Nick;
84
  signed int  GPS_Nick;
85
  signed int  GPS_Roll;
85
  signed int  GPS_Roll;
86
  signed int  GPS_Gier;
86
  signed int  GPS_Gier;
87
  signed int  CompassValue;
87
  signed int  CompassValue;
88
  signed int  Status;
88
  signed int  Status;
89
  unsigned char BeepTime;
89
  unsigned char BeepTime;
90
  union  
90
  union  
91
  { char Byte[12];
91
  { char Byte[12];
92
    int  Int[6];
92
    int  Int[6];
93
    long Long[3];
93
    long Long[3];
94
    float Float[3];
94
    float Float[3];
95
  } Param;
95
  } Param;
96
  unsigned char Chksum;
96
  unsigned char Chksum;
97
};
97
};
-
 
98
 
-
 
99
struct str_FromNaviCtrl_Value
-
 
100
{
-
 
101
 signed int OsdBar;
-
 
102
 signed int Distance;
98
 
103
};
99
 
104
 
100
#ifdef USE_SPI_COMMUNICATION
105
#ifdef USE_SPI_COMMUNICATION
-
 
106
 
101
 
107
extern struct str_FromNaviCtrl_Value FromNaviCtrl_Value;
102
extern struct str_ToNaviCtrl   ToNaviCtrl;
108
extern struct str_ToNaviCtrl   ToNaviCtrl;
103
extern struct str_FromNaviCtrl FromNaviCtrl;
109
extern struct str_FromNaviCtrl FromNaviCtrl;
104
extern unsigned char SPI_CommandCounter;
110
extern unsigned char SPI_CommandCounter;
105
 
111
 
106
//#define SPI_CMD_VALUE   0x03
112
//#define SPI_CMD_VALUE   0x03
107
 
113
 
108
extern void SPI_MasterInit(void);
114
extern void SPI_MasterInit(void);
109
extern void SPI_StartTransmitPacket(void);
115
extern void SPI_StartTransmitPacket(void);
110
extern void UpdateSPI_Buffer(void);
116
extern void UpdateSPI_Buffer(void);
111
extern void SPI_TransmitByte(void);
117
extern void SPI_TransmitByte(void);
112
#else
118
#else
113
 
119
 
114
 
120
 
115
// -------------------------------- Dummy -----------------------------------------
121
// -------------------------------- Dummy -----------------------------------------
116
#define  SPI_MasterInit() ; 
122
#define  SPI_MasterInit() ; 
117
#define  SPI_StartTransmitPacket() ;
123
#define  SPI_StartTransmitPacket() ;
118
#define  UpdateSPI_Buffer() ;
124
#define  UpdateSPI_Buffer() ;
119
#define  SPI_TransmitByte() ;
125
#define  SPI_TransmitByte() ;
120
#endif
126
#endif
121
 
127
 
122
 
128
 
123
#endif
129
#endif
124
 
130