Subversion Repositories NaviCtrl

Rev

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

Rev 206 Rev 215
Line 56... Line 56...
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 57... Line 57...
57
 
57
 
58
#include <string.h>
58
#include <string.h>
59
#include "91x_lib.h"
59
#include "91x_lib.h"
60
#include "led.h"
60
#include "led.h"
61
#include "GPS.h"
61
#include "gps.h"
62
#include "uart1.h"
62
#include "uart1.h"
63
#include "spi_slave.h"
63
#include "spi_slave.h"
64
#include "i2c.h"
64
#include "i2c.h"
65
#include "timer1.h"
65
#include "timer1.h"
Line 73... Line 73...
73
#define SPI_RXSYNCBYTE2 0x83
73
#define SPI_RXSYNCBYTE2 0x83
74
#define SPI_TXSYNCBYTE1 0x81
74
#define SPI_TXSYNCBYTE1 0x81
75
#define SPI_TXSYNCBYTE2 0x55
75
#define SPI_TXSYNCBYTE2 0x55
Line 76... Line 76...
76
 
76
 
77
//communication packets
77
//communication packets
78
volatile FromFlightCtrl_t   FromFlightCtrl;
78
FromFlightCtrl_t   FromFlightCtrl;
79
volatile ToFlightCtrl_t     ToFlightCtrl;
79
ToFlightCtrl_t     ToFlightCtrl;
80
#define SPI0_TIMEOUT 500 // 500ms
80
#define SPI0_TIMEOUT 500 // 500ms
Line 81... Line 81...
81
volatile u32 SPI0_Timeout = 0;
81
volatile u32 SPI0_Timeout = 0;
82
 
82
 
Line 254... Line 254...
254
        SPI_TxBuffer[0] = SPI_TXSYNCBYTE1;
254
        SPI_TxBuffer[0] = SPI_TXSYNCBYTE1;
255
        SPI_TxBuffer[1] = SPI_TXSYNCBYTE2;
255
        SPI_TxBuffer[1] = SPI_TXSYNCBYTE2;
256
        // set the pointer to the checksum byte in the tx buffer
256
        // set the pointer to the checksum byte in the tx buffer
257
        Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum);
257
        Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum);
Line -... Line 258...
-
 
258
 
-
 
259
        ToFlightCtrl.GPSStick.Nick = 0;
-
 
260
        ToFlightCtrl.GPSStick.Roll = 0;
-
 
261
        ToFlightCtrl.GPSStick.Yaw = 0;
258
 
262
 
259
        VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0);
263
        VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0);
Line 260... Line 264...
260
        VIC_ITCmd(SSP0_ITLine, ENABLE);
264
        VIC_ITCmd(SSP0_ITLine, ENABLE);
Line 274... Line 278...
274
        {
278
        {
275
                // avoid sending data via SPI during the update of the  ToFlightCtrl structure
279
                // avoid sending data via SPI during the update of the  ToFlightCtrl structure
276
                VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt
280
                VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt
277
                ToFlightCtrl.CompassHeading = I2C_Heading.Heading;
281
                ToFlightCtrl.CompassHeading = I2C_Heading.Heading;
278
                DebugOut.Analog[10] = ToFlightCtrl.CompassHeading;
282
                DebugOut.Analog[10] = ToFlightCtrl.CompassHeading;
279
                ToFlightCtrl.GPS_Nick   = GPS_Stick.Nick;
-
 
280
                ToFlightCtrl.GPS_Roll   = GPS_Stick.Roll;
-
 
281
                ToFlightCtrl.GPS_Yaw    = GPS_Stick.Yaw;
-
 
282
                // cycle spi commands
283
                // cycle spi commands
283
                ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
284
                ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
284
                // restart command cycle at the end
285
                // restart command cycle at the end
285
                if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
286
                if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
Line 425... Line 426...
425
                        default:
426
                        default:
426
                                break;
427
                                break;
427
                }
428
                }
Line 428... Line 429...
428
 
429
 
-
 
430
                // every time we got new data from the FC via SPI call the navigation routine
429
                // every time we got new data from the FC via SPI call the navigation routine
431
                // and update GPSStick that are returned to FC
430
                GPS_Navigation();
432
                GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick));
Line 431... Line 433...
431
                ClearFCFlags = 1;
433
                ClearFCFlags = 1;
432
 
434
 
433
                if(counter)
435
                if(counter)