/* 
 * File:   extern.h
 * Author: hamilton
 *
 * Created on January 27, 2014, 5:42 PM
 */

#include <dsp.h>
#include "config.h"
#include "../CommonCode/types.h"
#include "../CommonCode/pl_interp.h"

#ifndef EXTERN_H
#define	EXTERN_H


extern volatile BottomToTopDataPacket SerialDataOut;
extern volatile TopToBottomDataPacket SerialDataIn_A;  //A and B are "Ping-Pong" Buffers, filled alternatively by the UART RX Interrupt.
extern volatile TopToBottomDataPacket SerialDataIn_B;
extern volatile TopToBottomDataPacket *SerialDataIn;  //UART Rx Interrupt keeps this pointer pointing at most recent valid data while it fills the other buffer

extern volatile TopToBottomDataPacket FakeTopSidePacket;

extern volatile unsigned int CentiSecCtr;

extern PL_Interp Focus_interp;  // Used to convert focus target from serial bus to  DAC output to match camera/lens.

#ifdef DEBUG
extern tPID *PIDptr;  //Pointer to PID structure for gain adjustments in UARTRxInterrupt.c
extern volatile fractional *kCoeffs;  //Pointer to kCoeffs arrah for gain adjustments in UARTRxInterrupt.c
extern int raw;
#endif
extern volatile unsigned char SPI1_DataOut[4];
extern volatile unsigned char SPI2_DataOut[4];

extern volatile signed int RateZeroAdjust;

extern volatile signed int FocusFollow;
extern volatile signed int ZoomFollow;

extern volatile fractional kCoeffs_Zoom[];  //These are here for tuning purposes

//The following global variables are defined in extern.c
extern volatile float f_time;

extern unsigned int BufferA[INNERFILTERSAMPLES*NUMAIO] __attribute__((space(dma),aligned(64)));
extern unsigned int BufferB[INNERFILTERSAMPLES*NUMAIO] __attribute__((space(dma),aligned(64)));

extern unsigned int SPIBufferA[2] __attribute__((space(dma)));
extern unsigned int SPIBufferB[2] __attribute__((space(dma)));


extern tPID Zoom_PID;
extern tGSAL Zoom_GSAL;

extern volatile TOP_STATUS top_status;
#define TopStatus top_status.word
#define TopStatusBitFields top_status.bitfields

extern volatile BOTTOM_STATUS bottom_status;
#define BottomStatus bottom_status.word
#define BottomStatusBitFields bottom_status.bitfields


//These variables contain the raw samples, possibly several per 1kHz update rate if INNERFILTERSAMPLES > 1
extern volatile fractional ADC_CameraTemp[INNERFILTERSAMPLES];

//These variables are filtered versions of the samples collected by the ADC, A/B are ping-pong buffers that are filled alternately
extern volatile fractional CameraTemp;

extern FIRStruct Inner_Filter;

extern volatile int MeasStatus;  


extern volatile int iTemp1;
extern volatile int iTemp2;
extern volatile int iTemp3;
extern volatile int iTemp4;

extern volatile unsigned int T1_Freq;
extern volatile unsigned int T5_Freq;


#endif	/* EXTERN_H */
