#include <dsp.h>
#include "config.h"
#include "../CommonCode/pl_interp.h"
#include "../CommonCode/types.h"




#ifdef DEBUG
tPID *PIDptr; //Pointer to PID structure for gain adjustments in UARTRxInterrupt.c
volatile fractional *kCoeffs;  //Pointer to kCoeffs arrah for gain adjustments in UARTRxInterrupt.c
int raw = 0;
#endif

volatile unsigned int CentiSecCtr = 0;

volatile TopToBottomDataPacket SerialDataOut;
volatile BottomToTopDataPacket SerialDataIn_A;  //A and B are "Ping-Pong" Buffers, filled alternatively by the UART RX Interrupt.
volatile BottomToTopDataPacket SerialDataIn_B;
volatile BottomToTopDataPacket *SerialDataIn;  //UART Rx Interrupt keeps this pointer pointing at most recent valid data while it fills the other buffer

volatile BottomToTopDataPacket FakeBottomSidePacket;


volatile unsigned char SPI1_DataOut[4] = {0x00, 0x00, 0x00, 0x00};
volatile unsigned char SPI2_DataOut[4] = {0x00, 0x00, 0x00, 0x00};

volatile signed int Zoom_Rocker;
volatile signed int Focus_Slider;

volatile PL_Interp Zoom_interp;
volatile PL_Interp Focus_interp;

volatile int DimmerCtr = DEFAULT_DIMMER_CTR;  

volatile fractional kCoeffs_ChanA[] = {0, 0, 0};  //These are here for tuning purposes
volatile fractional kCoeffs_ChanB[] = {0, 0, 0};  //They can go back to main.c after

tPID ChanA_PID;
tPID ChanB_PID;

tGSAL ChanA_GSAL;
tGSAL ChanB_GSAL;


volatile TOP_STATUS top_status;
volatile BOTTOM_STATUS bottom_status;

unsigned int BufferA[INNERFILTERSAMPLES*NUMAIO] __attribute__((space(dma),aligned(64)));
unsigned int BufferB[INNERFILTERSAMPLES*NUMAIO] __attribute__((space(dma),aligned(64)));

unsigned int SPIBufferA[2] __attribute__((space(dma)));
unsigned int SPIBufferB[2] __attribute__((space(dma)));


//These variables contain the raw samples, possibly several per PWM update rate if INNERFILTERSAMPLES > 1
volatile fractional ADC_JoyStk_X[INNERFILTERSAMPLES];
volatile fractional ADC_JoyStk_Y[INNERFILTERSAMPLES];

//These variables are filtered versions of the samples collected by the ADC,
volatile fractional JoyStk_X;  //Point to valid memory at power up even it it hasn't been filled yet.
volatile fractional JoyStk_Y;  //Point to valid memory at power up even it it hasn't been filled yet.

volatile int MeasStatus = 0x0008;  //Set as compete so it starts the first time.

volatile int iTemp1 = 0;
volatile int iTemp2 = 0;
volatile int iTemp3 = 0;
volatile int iTemp4 = 0;

#ifdef DEBUG
volatile double f_time;
#endif

/* get command echo mode */
/* in deployment mode echo_mode = 0 && navproc_output = 1 */
int echoMode = 0;

/* ouput flags for individual topics */
int camOutput = 1;
int envOutput = 1;
int ptbOutput = 1;

/* state variable for navproc LEDs */
unsigned char npLedState = 0x00;

int tsDebugOutput = 0;
