/* 
 * File:   extern.h
 * Author: hamilton
 *
 */

#ifndef EXTERN_H
#define	EXTERN_H

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


extern ReceivedCmdParams CmdParams[NUMBER_OF_CMDS_TO_INTERPRET];

extern volatile unsigned int WindingCurrent;

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

extern const int TetherVoltage_cnt[2];
extern const  float TetherVoltage_eng[2];

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

//The following global variables are defined in extern.c
extern volatile unsigned int time_ctr;

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 int BattVoltage_ADC[FILTERSAMPLES];
extern volatile int TetherVoltage_ADC[FILTERSAMPLES];
extern volatile int Pressure_ADC[FILTERSAMPLES];

extern volatile int BattVoltage_Buf;
extern volatile int TetherVoltage_Buf;
extern volatile int Pressure_Buf;

extern volatile long TrefoilPosition;


extern volatile int MeasuredHeading_Buf;
extern volatile unsigned long PowerLossTimout_ctr;

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 unsigned int power_loss_timeout;
extern volatile unsigned int comms_loss_timeout;

extern volatile Maxon_Frame Maxon_FrameA;
extern volatile int Maxon_CommError;
extern volatile unsigned long CAN_PacketSend_ctr;  //Counts tenths of a second in CAN ISR for RS-232 timeout purposes.  Rolls over in ~14 years.

extern volatile unsigned int StatusWord;
extern volatile signed long MotorCurrentActualValue;
extern volatile signed long TreFoilPositionActualValue;

extern volatile int MAXON_CmdFromCAN;

extern volatile char DoorPositionUnknown;
extern volatile char HomeDirection;

extern volatile int CurrentPositionSet;

extern volatile unsigned int i_ctr;

extern volatile char StateMachine;

#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


#endif	/* EXTERN_H */

