Subversion Repositories FlightCtrl

Rev

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

Rev 520 Rev 522
Line 1... Line 1...
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
2
// + Copyright (c) 04.2007 Holger Buss
3
// + only for non-profit use
3
// + only for non-profit use
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// + see the File "License.txt" for further Informations
5
// + see the File "License.txt" for further Informations
6
// +
-
 
7
// + GPS read out:
-
 
8
// + modified Version of the Pitschu Brushless Ufo - (c) Peter Schulten, Mülheim, Germany
-
 
9
// + only for non-profit use 
-
 
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 11... Line 7...
11
 
7
 
12
#include "main.h"
8
#include "main.h"
Line 13... Line 9...
13
#include "uart.h"
9
#include "uart.h"
14
 
10
 
-
 
11
unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0;
15
unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0;
12
unsigned volatile char SioTmp = 0;
16
unsigned volatile char SioTmp = 0;
13
unsigned volatile char SioTmp1 = 0;
17
unsigned volatile char SendeBuffer[MAX_SENDE_BUFF];
14
unsigned volatile char SendeBuffer[MAX_SENDE_BUFF];
18
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
15
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
19
unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF];
16
unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF];
Line 36... Line 33...
36
int Debug_Timer;
33
int Debug_Timer;
Line 37... Line 34...
37
 
34
 
38
const unsigned char ANALOG_TEXT[32][16] =
35
const unsigned char ANALOG_TEXT[32][16] =
39
{
36
{
40
   //1234567890123456 
37
   //1234567890123456 
41
    "IntegralNick____", //00
38
    "IntegralNick    ", //0
42
    "IntegralRoll____", //01
39
    "IntegralRoll    ",
43
    "AccNick_________", //02
40
    "AccNick         ",
44
    "AccRoll_________", //03
41
    "AccRoll         ",
45
    "P_GPS_Faktor____", //04
42
    "GyroGier        ",
46
    "D_GPS_Faktor____", //05
43
    "HoehenWert      ", //5
47
    "Soll_Pos_North__", //06
44
    "AccZ            ",
48
    "Soll_Pos_East___", //07
45
    "Gas             ",
49
    "KompassValue____", //08
46
    "KompassValue    ",
50
    "UBat____________", //09
47
    "Spannung        ",
51
    "SenderOkay______", //10
48
    "Empfang         ", //10
52
    "GPSFix__________", //11
49
    "Analog11        ",
53
    "Gesamtstrom_____", //12
50
    "Motor_Vorne     ",
54
    "Geschwindigkeit_", //13
51
    "Motor_Hinten    ",
55
    "Pos.north_______", //14
52
    "Motor_Links     ",
56
    "Pos.east________", //15
53
    "Motor_Rechts    ", //15
57
    "Poti3___________", //16
54
    "Acc_Z           ",
58
    "Höhe_GPS________", //17
55
    "MittelAccNick   ",
59
    "Home_North______", //18
56
    "MittelAccRoll   ",
60
    "Home_East_______", //19
57
    "IntegralErrNick ",
61
    "Posabw_North____", //20
58
    "IntegralErrRoll ", //20
62
    "Posabw_East_____", //21
59
    "MittelIntNick   ",
63
    "P_Einfluss_North", //22
60
    "MittelIntRoll       ",
64
    "P_Einfluss_East_", //23
61
    "NeutralNick     ",
65
    "D_Einfluss_North", //24
62
    "RollOffset      ",
66
    "D_Einfluss_East_", //25
63
    "IntRoll*Faktor  ", //25
67
    "NORTH_MITTEL____", //26
64
    "Analog26        ",
68
    "EAST_MITTEL_____", //27
65
    "DirektAusglRoll ",
69
    "GPS_Nick________", //28
66
    "MesswertRoll    ",
70
    "GPS_Roll________", //29
67
    "AusgleichRoll   ",
71
    "StickNick_______", //30
68
    "I-LageRoll      ", //30
72
    "StickRoll_______"  //31
69
    "StickRoll       "
Line -... Line 70...
-
 
70
};
-
 
71
 
73
};
72
 
Line 74... Line 73...
74
 
73
 
75
 
74
 
76
char newData_navPosUtm = 0;  // Flag, wenn neue PosUtm-Daten vorliegen (211007Kr)
75
char newData_navPosUtm = 0;  // Flag, wenn neue PosUtm-Daten vorliegen (211007Kr)
Line 187... Line 186...
187
   UDR = tmp_tx;
186
   UDR = tmp_tx;
188
  }
187
  }
189
  else ptr = 0;
188
  else ptr = 0;
190
}
189
}
Line -... Line 190...
-
 
190
 
-
 
191
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
192
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
-
 
193
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
194
SIGNAL(INT_VEC_RX)
-
 
195
{
-
 
196
 static unsigned int crc;
-
 
197
 static unsigned char crc1,crc2,buf_ptr;
-
 
198
 static unsigned char UartState = 0;
-
 
199
 unsigned char CrcOkay = 0;
-
 
200
 
-
 
201
 SioTmp = UDR;
-
 
202
 if(buf_ptr >= MAX_EMPFANGS_BUFF)    UartState = 0;
-
 
203
 if(SioTmp == '\r' && UartState == 2)
-
 
204
  {
-
 
205
   UartState = 0;
-
 
206
   crc -= RxdBuffer[buf_ptr-2];
-
 
207
   crc -= RxdBuffer[buf_ptr-1];
-
 
208
   crc %= 4096;
-
 
209
   crc1 = '=' + crc / 64;
-
 
210
   crc2 = '=' + crc % 64;
-
 
211
   CrcOkay = 0;
-
 
212
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
-
 
213
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
-
 
214
    {
-
 
215
     NeuerDatensatzEmpfangen = 1;
-
 
216
         AnzahlEmpfangsBytes = buf_ptr;
-
 
217
     RxdBuffer[buf_ptr] = '\r';
-
 
218
         if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando
-
 
219
        }                                
-
 
220
  }
-
 
221
  else
-
 
222
  switch(UartState)
-
 
223
  {
-
 
224
   case 0:
-
 
225
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
-
 
226
                  buf_ptr = 0;
-
 
227
                  RxdBuffer[buf_ptr++] = SioTmp;
-
 
228
                  crc = SioTmp;
-
 
229
          break;
-
 
230
   case 1: // Adresse auswerten
-
 
231
                  UartState++;
-
 
232
                  RxdBuffer[buf_ptr++] = SioTmp;
-
 
233
                  crc += SioTmp;
-
 
234
                  break;
-
 
235
   case 2: //  Eingangsdaten sammeln
-
 
236
                  RxdBuffer[buf_ptr] = SioTmp;
-
 
237
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
-
 
238
                  else UartState = 0;
-
 
239
                  crc += SioTmp;
-
 
240
                  break;
191
 
241
   default:
-
 
242
          UartState = 0;
-
 
243
          break;
-
 
244
  }
-
 
245
}
-
 
246
 
-
 
247
 
-
 
248
 
-
 
249
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
250
//++ Sende-Part der Datenübertragung an zweiten UART
-
 
251
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
192
void GPSscanData (void)
252
SIGNAL(SIG_USART1_TRANS)
-
 
253
{
-
 
254
        //zum 2te Uart (GPS) wird im Moment nichts gesendet
-
 
255
 
-
 
256
 
-
 
257
}
Line 193... Line 258...
193
{
258
 
-
 
259
 
-
 
260
 
Line 194... Line 261...
194
 
261
 
195
 
262
void GPSscanData (void)
196
       
263
{
197
 
264
 
Line 232... Line 299...
232
                navVelNed.packetStatus = 0;
299
                navVelNed.packetStatus = 0;
233
        }
300
        }
Line 234... Line 301...
234
 
301
 
Line -... Line 302...
-
 
302
}
235
}
303
 
236
 
304
 
237
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
305
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
238
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
306
//++ Empfangs-Part der Datenübertragung von zweitem UART
239
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
307
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
240
SIGNAL(INT_VEC_RX)
-
 
241
{
-
 
242
 static unsigned int crc;
-
 
243
 static unsigned char crc1,crc2,buf_ptr;
-
 
Line 244... Line -...
244
 static unsigned char UartState = 0;
-
 
245
 unsigned char CrcOkay = 0;
-
 
246
 
308
SIGNAL(SIG_USART1_RECV)
247
 SioTmp = UDR;
309
{
Line -... Line 310...
-
 
310
 
-
 
311
    uint8_t c;
248
 
312
        uint8_t re;
249
    uint8_t c;
313
 
Line 250... Line 314...
250
        uint8_t re;
314
        SioTmp1 = UDR1;  
251
 
315
 
252
        re = (UCSR0A & (_B1(FE0) | _B1(DOR0)));         // any error occured ?
316
        re = (UCSR1A & (_B1(FE1) | _B1(DOR1)));         // any error occured ?
253
        c = SioTmp;  
317
        c = SioTmp1;  
254
       
318
       
255
#ifdef GPS_DEBUG
319
#ifdef GPS_DEBUG
256
        *bp++ = c;
320
        *bp++ = c;
257
        if (bp >= (buf+200)) bp = buf;
321
        if (bp >= (buf+200)) bp = buf;
258
        if (v24state == 0)
322
        if (v24state == 0)
259
        {
323
        {
260
                v24state = 1;
324
                v24state = 1;
261
                UDR0 = *ep++;
325
                UDR1 = *ep++;
Line 262... Line 326...
262
                if (ep >= buf+200)
326
                if (ep >= buf+200)
263
                        ep = buf;
327
                        ep = buf;
Line 369... Line 433...
369
                gpsState = GPS_EMPTY;
433
                gpsState = GPS_EMPTY;
370
        }
434
        }
371
        GPSscanData ();
435
        GPSscanData ();
Line 372... Line -...
372
 
-
 
373
 
-
 
374
 
-
 
375
 
-
 
376
 
-
 
377
 
-
 
378
 
-
 
379
 if(buf_ptr >= MAX_EMPFANGS_BUFF)    UartState = 0;
-
 
380
 if(SioTmp == '\r' && UartState == 2)
-
 
381
  {
-
 
382
   UartState = 0;
-
 
383
   crc -= RxdBuffer[buf_ptr-2];
-
 
384
   crc -= RxdBuffer[buf_ptr-1];
-
 
385
   crc %= 4096;
-
 
386
   crc1 = '=' + crc / 64;
-
 
387
   crc2 = '=' + crc % 64;
-
 
388
   CrcOkay = 0;
-
 
389
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
-
 
390
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
-
 
391
    {
-
 
392
     NeuerDatensatzEmpfangen = 1;
-
 
393
         AnzahlEmpfangsBytes = buf_ptr;
-
 
394
     RxdBuffer[buf_ptr] = '\r';
-
 
395
         if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando
-
 
396
        }                                
-
 
397
  }
-
 
398
  else
-
 
399
  switch(UartState)
-
 
400
  {
-
 
401
   case 0:
-
 
402
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
-
 
403
                  buf_ptr = 0;
-
 
404
                  RxdBuffer[buf_ptr++] = SioTmp;
-
 
405
                  crc = SioTmp;
-
 
406
          break;
-
 
407
   case 1: // Adresse auswerten
-
 
408
                  UartState++;
-
 
409
                  RxdBuffer[buf_ptr++] = SioTmp;
-
 
410
                  crc += SioTmp;
-
 
411
                  break;
-
 
412
   case 2: //  Eingangsdaten sammeln
-
 
413
                  RxdBuffer[buf_ptr] = SioTmp;
-
 
414
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
-
 
415
                  else UartState = 0;
-
 
416
                  crc += SioTmp;
-
 
417
                  break;
-
 
418
   default:
-
 
419
          UartState = 0;
-
 
420
          break;
436
 
Line 421... Line 437...
421
  }
437
 
422
}
438
}
Line 437... Line 453...
437
  UebertragungAbgeschlossen = 0;
453
  UebertragungAbgeschlossen = 0;
438
  UDR = SendeBuffer[0];
454
  UDR = SendeBuffer[0];
439
}
455
}
Line -... Line 456...
-
 
456
 
440
 
457
 
441
 
458
 
442
// --------------------------------------------------------------------------
459
// --------------------------------------------------------------------------
443
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
460
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
444
{
461
{
Line 613... Line 630...
613
        //UBRR = 33;
630
        //UBRR = 33;
614
        //öffnet einen Kanal für printf (STDOUT)
631
        //öffnet einen Kanal für printf (STDOUT)
615
        //fdevopen (uart_putchar, 0);
632
        //fdevopen (uart_putchar, 0);
616
        //sbi(PORTD,4);
633
        //sbi(PORTD,4);
617
  Debug_Timer = SetDelay(200);  
634
  Debug_Timer = SetDelay(200);  
618
 
-
 
619
  gpsState = GPS_EMPTY;
-
 
620
}
635
}
Line -... Line 636...
-
 
636
 
-
 
637
 
-
 
638
//############################################################################
-
 
639
//INstallation der 2ten Seriellen Schnittstelle
-
 
640
void UART1_Init (void)
-
 
641
//############################################################################
-
 
642
{
-
 
643
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
-
 
644
 
-
 
645
        UCSR1B=(1 << TXEN1) | (1 << RXEN1);
-
 
646
    // UART Double Speed (U2X)
-
 
647
        UCSR1A   |= (1<<U2X1);          
-
 
648
        // RX-Interrupt Freigabe
-
 
649
        UCSR1B |= (1<<RXCIE1);          
-
 
650
        // TX-Interrupt Freigabe
-
 
651
        UCSR1B |= (1<<TXCIE1);          
-
 
652
 
-
 
653
        //Teiler wird gesetzt 
-
 
654
        UBRR1L=(SYSCLK / (BAUD_RATE1 * 8L) - 1);
-
 
655
        //UBRR1L = 33;
-
 
656
        //öffnet einen Kanal für printf (STDOUT)
-
 
657
        //fdevopen (uart_putchar, 0);
-
 
658
        //sbi(PORTD,4);
-
 
659
  Debug_Timer = SetDelay(200);  
-
 
660
}
-
 
661
 
-
 
662
 
621
 
663
 
622
//---------------------------------------------------------------------------------------------
664
//---------------------------------------------------------------------------------------------
623
void DatenUebertragung(void)  
665
void DatenUebertragung(void)  
624
{
666
{