/* 
 * 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 TopToBottomDataPacket SerialDataOut;
extern volatile BottomToTopDataPacket SerialDataIn_A;  //A and B are "Ping-Pong" Buffers, filled alternatively by the UART RX Interrupt.
extern volatile BottomToTopDataPacket SerialDataIn_B;
extern volatile BottomToTopDataPacket *SerialDataIn;  //UART Rx Interrupt keeps this pointer pointing at most recent valid data while it fills the other buffer

extern volatile BottomToTopDataPacket FakeBottomSidePacket;

extern volatile unsigned int CentiSecCtr;

#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 Zoom_Rocker;
extern volatile signed int Focus_Slider;

extern PL_Interp Zoom_interp;
extern PL_Interp Focus_interp;

extern volatile int DimmerCtr;

extern volatile fractional kCoeffs_ChanA[];  //These are here for tuning purposes
extern volatile fractional kCoeffs_ChanB[];  //They can go back to main.c after

//The following global variables are defined in extern.c
extern volatile double 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 ChanA_PID;
extern tPID ChanB_PID;


extern tGSAL ChanA_GSAL;
extern tGSAL ChanB_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_JoyStk_X[INNERFILTERSAMPLES];
extern volatile fractional ADC_JoyStk_Y[INNERFILTERSAMPLES];

//These variables are filtered versions of the samples collected by the ADC, 
extern volatile fractional JoyStk_X;  //Point to valid memory at power up even it it hasn't been filled yet.
extern volatile fractional JoyStk_Y;  //Point to valid memory at power up even it it hasn't been filled yet.

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 int echoMode;

/* ouput flags for individual topics */
extern int camOutput;
extern int envOutput;
extern int ptbOutput;

/* state variable for navproc LEDs */
extern unsigned char npLedState;

extern int tsDebugOutput;

#endif	/* EXTERN_H */
