Subversion Repositories FlightCtrl

Rev

Rev 827 | Rev 978 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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