Subversion Repositories FlightCtrl

Rev

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

Rev Author Line No. Line
304 ingob 1
// ######################## SPI - FlightCtrl ###################
2
#ifndef _SPI_H
3
#define _SPI_H
4
 
708 ingob 5
#include <util/delay.h>
597 ingob 6
 
708 ingob 7
#define USE_SPI_COMMUNICATION 
8
 
619 ingob 9
#define SPI_PROTOCOL_COMP   1
304 ingob 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
 
596 ingob 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    
606 ingob 31
#ifndef SPR0  
32
#define SPR0   SPR00
33
#endif    
596 ingob 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
// -------------------------
304 ingob 47
 
48
#define SLAVE_SELECT_DDR_PORT   DDRC
49
#define SLAVE_SELECT_PORT       PORTC
50
#define SPI_SLAVE_SELECT        PC5
51
 
708 ingob 52
struct str_ToNaviCtrl_Value
304 ingob 53
{
606 ingob 54
 unsigned char Sync1, Sync2;
708 ingob 55
 unsigned char Command;
56
 signed int IntegralNick;
57
 signed int  IntegralRoll;
709 ingob 58
 char StickNick,StickRoll,  
59
      StickGier, StickGas;
60
 signed int  GyroCompass;
61
 char User1, User2, User3, User4, User5, User6, User7, User8;
62
 unsigned char Chksum;
304 ingob 63
};
64
 
708 ingob 65
 struct str_ToNaviCtrl_Version
66
 {
67
  unsigned char Sync1, Sync2;
68
  unsigned char Command;
69
  unsigned char  HVersion;
70
  unsigned char  NVersion;
71
  unsigned char  Comp;
72
  unsigned char  d0;
73
  signed int  d1;
74
  signed int  d2;
75
  signed int  d3;
76
  signed int  d4;
77
  signed int  d5;
78
  signed int  d6;
79
  signed int  d7;
80
  unsigned char Chksum;
81
 };
82
 
83
struct str_FromNaviCtrl_Value
304 ingob 84
{
708 ingob 85
 unsigned char Command;
86
  signed int  GPS_Nick;
87
  signed int  GPS_Roll;
88
  signed int  GPS_Gier;
89
  signed int  GPS_Height;
90
  signed int  CompassValue;
91
  signed int  Status;
720 ingob 92
  unsigned char BeepTime;
93
  unsigned char d0;
708 ingob 94
  signed int  d1;
95
  signed int  d2;
96
  unsigned char Chksum;
304 ingob 97
};
98
 
708 ingob 99
 struct str_FromNaviCtrl_Version
100
 {
101
  unsigned char Command;
102
  unsigned char  HVersion;
103
  unsigned char  NVersion;
104
  unsigned char  Comp;
105
  unsigned char  d0;
106
  signed int  d1;
107
  signed int  d2;
108
  signed int  d3;
109
  signed int  d4;
110
  signed int  d5;
111
  signed int  d6;
112
  signed int  d7;
113
  unsigned char Chksum;
114
 };
115
 
597 ingob 116
#ifdef USE_SPI_COMMUNICATION
708 ingob 117
extern struct str_ToNaviCtrl_Version   ToNaviCtrl_Version;
118
extern struct str_FromNaviCtrl_Version   FromNaviCtrl_Version;
304 ingob 119
 
708 ingob 120
extern struct str_ToNaviCtrl_Value   ToNaviCtrl_Value;
121
extern struct str_FromNaviCtrl_Value   FromNaviCtrl_Value;
304 ingob 122
 
708 ingob 123
#define SPI_CMD_VERSION 0x02
124
#define SPI_CMD_VALUE   0x03
125
 
304 ingob 126
extern void SPI_MasterInit(void);
708 ingob 127
extern void SPI_StartTransmitPacket(unsigned char command);
304 ingob 128
extern void UpdateSPI_Buffer(void);
129
extern void SPI_TransmitByte(void);
597 ingob 130
#else
304 ingob 131
 
132
 
597 ingob 133
// -------------------------------- Dummy -----------------------------------------
134
#define  SPI_MasterInit() ; 
135
#define  SPI_StartTransmitPacket() ;
136
#define  UpdateSPI_Buffer() ;
137
#define  SPI_TransmitByte() ;
138
#endif
304 ingob 139
 
597 ingob 140
 
141
#endif