#include <dsp.h>
#include "config.h"
#include "../CommonCode/types.h"
#include "../CommonCode/pl_interp.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 BottomToTopDataPacket SerialDataOut;
volatile TopToBottomDataPacket SerialDataIn_A;  //A and B are "Ping-Pong" Buffers, filled alternatively by the UART RX Interrupt.
volatile TopToBottomDataPacket SerialDataIn_B;
volatile TopToBottomDataPacket *SerialDataIn;  //UART Rx Interrupt keeps this pointer pointing at most recent valid data while it fills the other buffer

volatile TopToBottomDataPacket FakeTopSidePacket;

volatile unsigned int CentiSecCtr = 0;

volatile unsigned char SPI1_DataOut[4] = {0x00, 0x00, 0x00, 0x00};
volatile unsigned char SPI2_DataOut[4] = {0x00, 0x00, 0x00, 0x00};

volatile signed int RateZeroAdjust;

volatile PL_Interp Focus_interp;  // Used to convert focus target from serial bus to  DAC output to match camera/lens.


volatile signed int FocusFollow;
volatile signed int ZoomFollow;

volatile fractional kCoeffs_Zoom[] = {0, 0, 0};  //These are here for tuning purposes

tPID Zoom_PID;
tGSAL Zoom_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_CameraTemp[INNERFILTERSAMPLES];

volatile fractional CameraTemp;  //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;

volatile unsigned int T1_Freq;
volatile unsigned int T5_Freq;

#ifdef DEBUG
volatile float f_time;
#endif

