/* 
 * File:   extern.h
 * Author: hamilton
 *
 * Created on January 27, 2014, 5:42 PM
 */

#include <dsp.h>
#include "config.h"
#include "can.h"
#include "types.h"
#include "imu.h"
#include "nortek.h"

#ifndef EXTERN_H
#define	EXTERN_H


//These calibration constants are defined in "CalibrationConstants.c"
extern const int WingPos_cnt[2];
extern const  float WingPos_eng[2];

extern const int Pressure_cnt[2];
extern const  float Pressure_eng[2];

extern volatile float MaxRudderPosition;

extern volatile int BangBang_Deadband;

//The following global variables are defined in extern.c
extern volatile float time;

extern volatile unsigned int mode;


extern volatile signed long steps;
extern volatile signed long step_target;
extern volatile int direction;

extern volatile signed int CurrentHeading;
extern volatile signed int DefaultHeading;
extern volatile signed int HeadingTarget;
extern volatile unsigned int HeadingTargetTimeout;

extern volatile int f_RudderPosition;

extern volatile signed int SpecifiedRudderCmd;


extern tPID Heading_PID;
extern volatile fractional kCoeffs_Heading[];

extern FIRStruct ADC_Filter;

extern volatile int outSamples[FILTERSAMPLES];

extern volatile int temp_inSamples[FILTERSAMPLES];
extern volatile int temp_outSamples[FILTERSAMPLES];

extern int raw;

extern volatile unsigned char HeadingFilterTimeConstant;
extern volatile unsigned int HeadingFilterDivisorCounter;

extern volatile unsigned char HeadingControlUpdatePeriod;
extern volatile unsigned int HeadingControlUpdatePeriodCounter;


extern volatile int WingPos_ADC[FILTERSAMPLES];
extern volatile int Pressure_ADC[FILTERSAMPLES];

extern volatile int WingPos_Buf;
extern volatile int Pressure_Buf;

extern volatile int MeasuredHeading_Buf;

extern unsigned int BufferA[FILTERSAMPLES*NUMAIO] __attribute__((space(dma),aligned(64)));
extern unsigned int BufferB[FILTERSAMPLES*NUMAIO] __attribute__((space(dma),aligned(64)));


extern unsigned int ECAN1MSGBUF[ECAN1_MSG_BUF_LENGTH][8] __attribute__((space(dma),aligned(ECAN1_MSG_BUF_LENGTH*16)));
//extern unsigned int BufferCAN1TX[CAN1TXBUFFSIZE] __attribute__((space(dma)));


extern CANmsg message[ECAN1_NUM_TX_BUFFERS-1];  //One message structure for each transmit buffer


extern volatile STATUS Status;


extern IMU_Packet IMU_DataA,IMU_DataB;
extern volatile int IMU_Buff;

extern volatile Nortek_Packet Nortek_DataA;
extern volatile Nortek_Packet Nortek_DataB;
extern volatile int Nortek_Buff;

#ifdef DEBUG
extern volatile char test_str[255];

extern unsigned int uiTemp1;

extern int iTemp1;
extern int iTemp2;
extern int iTemp3;
extern int iTemp4;

extern float  fTemp1;
extern float  fTemp2;

extern long lTemp1;
#endif

extern unsigned int Speeds_PR2[3];
extern unsigned int PosCtrIncr[3];
extern unsigned int speed;

#endif	/* EXTERN_H */

