Subversion Repositories FlightCtrl

Rev

Rev 606 | Rev 691 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 606 Rev 617
Line 6... Line 6...
6
struct str_FromNaviCtrl    FromNaviCtrl;
6
struct str_FromNaviCtrl    FromNaviCtrl;
7
unsigned char              SPI_BufferIndex;
7
unsigned char              SPI_BufferIndex;
8
volatile unsigned char     SPI_Buffer[sizeof(FromNaviCtrl)];
8
volatile unsigned char     SPI_Buffer[sizeof(FromNaviCtrl)];
9
unsigned char *Ptr_buffer = (unsigned char *) &ToNaviCtrl;
9
unsigned char *Ptr_buffer = (unsigned char *) &ToNaviCtrl;
Line 10... Line 10...
10
 
10
 
11
unsigned char SPITransferCompleted;
11
unsigned char SPITransferCompleted, SPI_ChkSum;
12
#ifdef USE_SPI_COMMUNICATION
12
#ifdef USE_SPI_COMMUNICATION
13
//------------------------------------------------------
13
//------------------------------------------------------
14
void SPI_MasterInit(void)
14
void SPI_MasterInit(void)
15
{
15
{
Line 21... Line 21...
21
  SPITransferCompleted = 1;
21
  SPITransferCompleted = 1;
Line 22... Line 22...
22
 
22
 
23
  ToNaviCtrl.Sync1 = 0x81;
23
  ToNaviCtrl.Sync1 = 0x81;
Line -... Line 24...
-
 
24
  ToNaviCtrl.Sync2 = 0x55;
-
 
25
 
-
 
26
  ToNaviCtrl.Comp = 12;
-
 
27
  ToNaviCtrl.IntegralNick = 12345;
-
 
28
  ToNaviCtrl.IntegralRoll = 56789;
-
 
29
  ToNaviCtrl.StickNick = 100;
Line 24... Line 30...
24
  ToNaviCtrl.Sync2 = 0x55;
30
  ToNaviCtrl.StickRoll = 150;//(char) StickRoll;
Line 25... Line 31...
25
 
31
  ToNaviCtrl.StickGier = 200;//(char) StickGier;
26
 
32
 
27
}
33
}
28
 
34
 
29
//------------------------------------------------------
35
//------------------------------------------------------
Line 30... Line 36...
30
void SPI_StartTransmitPacket(void)
36
void SPI_StartTransmitPacket(void)
-
 
37
{
31
{
38
   //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return;    // transfer of prev. packet not completed
32
   //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return;    // transfer of prev. packet not completed
39
   if (!SPITransferCompleted) return;
33
   if (!SPITransferCompleted) return;
40
   
34
   
41
   SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
35
   SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
42
   
Line 43... Line 50...
43
       DebugOut.Analog[22] = FromNaviCtrl.GPS_Roll;
50
       DebugOut.Analog[22] = FromNaviCtrl.GPS_Roll;
44
       DebugOut.Analog[23] = FromNaviCtrl.CompassValue;
51
       DebugOut.Analog[23] = FromNaviCtrl.CompassValue;
45
*/  
52
*/  
46
   //----
53
   //----
47
   SPDR = ToNaviCtrl.Sync1;                  // Start transmission 
54
   SPDR = ToNaviCtrl.Sync1;                  // Start transmission 
-
 
55
   ToNaviCtrl.ChkSum = ToNaviCtrl.Sync1;
48
}
56
}
Line 49... Line 57...
49
 
57
 
50
//------------------------------------------------------
58
//------------------------------------------------------
51
//SIGNAL(SIG_SPI)
59
//SIGNAL(SIG_SPI)
Line 55... Line 63...
55
  SLAVE_SELECT_PORT |=  (1 << SPI_SLAVE_SELECT);   // DeselectSlave
63
  SLAVE_SELECT_PORT |=  (1 << SPI_SLAVE_SELECT);   // DeselectSlave
Line 56... Line 64...
56
   
64
   
57
          if (SPI_BufferIndex < sizeof(FromNaviCtrl))
65
          if (SPI_BufferIndex < sizeof(FromNaviCtrl))
58
      {
66
      {
-
 
67
            SPI_Buffer[SPI_BufferIndex]= SPDR;             // get data 
59
            SPI_Buffer[SPI_BufferIndex]= SPDR;             // get data 
68
               
Line 60... Line 69...
60
//              if (SPI_BufferIndex < 32 ) DebugOut.Analog[26+SPI_BufferIndex] = SPI_Buffer[SPI_BufferIndex];
69
//              if (SPI_BufferIndex < 32 ) DebugOut.Analog[26+SPI_BufferIndex] = SPI_Buffer[SPI_BufferIndex];
61
       
70
       
Line 62... Line 71...
62
        //if(SPDR!= 0x00) DebugOut.Analog[19]++; ;             
71
        //if(SPDR!= 0x00) DebugOut.Analog[19]++; ;             
63
          }
72
          }
64
 
73
 
-
 
74
   if (SPI_BufferIndex < sizeof(ToNaviCtrl))  
65
   if (SPI_BufferIndex < sizeof(ToNaviCtrl))  
75
     {
66
     {
76
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
-
 
77
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
-
 
78
           SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
67
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
79
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
-
 
80
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
68
           SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
81
           
69
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
82
           SPDR = Ptr_buffer[SPI_BufferIndex];
70
           SPDR = Ptr_buffer[SPI_BufferIndex];
83
           ToNaviCtrl.ChkSum += Ptr_buffer[SPI_BufferIndex];
71
         }
84
         }
Line 81... Line 94...
81
}
94
}
Line 82... Line 95...
82
 
95
 
83
//------------------------------------------------------
96
//------------------------------------------------------
84
void UpdateSPI_Buffer(void)
97
void UpdateSPI_Buffer(void)
85
{
98
{
86
  static unsigned char i =0;
99
  /*static unsigned char i =0;
87
  cli();
100
  cli();
88
  ToNaviCtrl.Comp = SPI_PROTOCOL_COMP;
101
  ToNaviCtrl.Comp = SPI_PROTOCOL_COMP;
89
  ToNaviCtrl.IntegralNick = (int) (IntegralNick >> 4);
102
  ToNaviCtrl.IntegralNick = (int) (IntegralNick >> 4);
90
  ToNaviCtrl.IntegralRoll = (int) (IntegralRoll >> 4);
103
  ToNaviCtrl.IntegralRoll = (int) (IntegralRoll >> 4);
91
  ToNaviCtrl.StickNick = 4;
104
  ToNaviCtrl.StickNick = 4;
92
  ToNaviCtrl.StickRoll = 5;//(char) StickRoll;
105
  ToNaviCtrl.StickRoll = 5;//(char) StickRoll;
93
  ToNaviCtrl.StickGier = 6;//(char) StickGier;
106
  ToNaviCtrl.StickGier = 6;//(char) StickGier;
-
 
107
  sei();
94
  sei();
108
  */
Line 95... Line 109...
95
}
109
}