/*                                                     
	???? ???	  (?) 2006 ?.
	
	Processor:			TMS320C32

	Filename:			vector_troll.h

	??????? ?????????? ?????????y

	Edit date:		04-12-02

	Function:		

	Revisions:
*/


#ifndef _VECTOR_SEV
#define _VECTOR_SEV


#ifdef __cplusplus
  extern "C" {
#endif                  
        
        
#include "IQmathLib.h"

        
typedef struct
{
    float W;         /* Угловау скороть ротора	*/
    float Angle;     /* Угол положениу ротора	*/
    float Phi;		/* Поправка к углу ротора	*/ 
    float k;         /* Коэфф. модуляции	*/ 
    float k1;         /* Коэфф. модулуции	*/ 
    float k2;         /* Коэфф. модулуции	*/ 
    float f;         /* Частота статора	*/

	_iq iqk;
	_iq iqk1;
	_iq iqk2;
	_iq iqf;


	    
} WINDING;




typedef struct
{             
    unsigned int Prepare;
	unsigned int terminal_prepare;
	unsigned int prepareSVU;
	unsigned int Test_Lamps;
    unsigned int fault;

    unsigned int prevGo;
    unsigned int Go;
	unsigned int Stop;
	unsigned int Mode;
    unsigned int Revers; 
    unsigned int Is_Blocked;
     
	unsigned int Ready1;
	unsigned int Ready2;
	unsigned int Discharge;
	unsigned int is_charging;

	unsigned int ErrorChannel1;
	unsigned int ErrorChannel2;
	unsigned int FaultChannel1;
	unsigned int FaultChannel2;

	unsigned int secondPChState;
    
	unsigned int Set_power; 
    
    unsigned int Impuls; 
    
    unsigned int Obmotka1;
    unsigned int Obmotka2;
//    unsigned int Down50;

    unsigned int Power_over_Nominal;
	unsigned int I_over_nominal;			//????????? ?????? ?????? ? ??????????? ???????????? ????
	unsigned int I_over_1_6_nominal;			//????????? ?????? ?????? ? ??????????? ???????????? ????
	unsigned int I_over_1_8_nominal;			//????????? ?????? ?????? ? ??????????? ???????????? ????
	unsigned int Moment_over_1_6_noninal;	//????????? ?????? ?????? ? ??????????? ???????????? ??????? ? 1.6 ???
	unsigned int Moment_over_1_8_nominal;	//????????? ?????? ?????? ? ??????????? ???????????? ??????? ? 1.8 ???
	unsigned int DownToNominal;
	unsigned int DownToNominalCurrent;
	unsigned int DownToNominalMoment;
	unsigned int DownTemperature;
	unsigned int DownToNominalVoltage;
	unsigned int DownToNominalFreq;
	unsigned int nominal_I_exceeded_counter;	//??????? ??? ????????? ??????????? ???
	unsigned int nominal_M_exceeded_counter;	//??????? ??? ????????? ??????????? ??????
//	unsigned int I_zpt_over_nominal;

    unsigned int Up50;
    unsigned int Ciclelog;
    unsigned int pidD_set;
    unsigned int Bpsi;
    unsigned int Piregul1;
    unsigned int Piregul2;
    unsigned int Startstoplog;
    unsigned int Setspeed;

	unsigned int BWC_turn_ON;
	unsigned int BWC_Auto_mode;
    
    unsigned int Setsdvigfaza;
    unsigned int Off_piregul;
    
    unsigned int Restart;
    unsigned int stop_Log; 
    
    unsigned int Work_net;
	unsigned int Mask_impuls;
	unsigned int Impuls_width;


    unsigned int Work;

    unsigned int Auto;
    
    unsigned int Uzad;
    unsigned int Umin;

    unsigned int RScount;
	unsigned int vector_run;
	unsigned int test_all_run;

	unsigned int decr_mzz_temp;
//	unsigned int flag_decr_mzz_temp;

	unsigned int flag_Break_Resistor_Error;
	unsigned int flag_local_control; //1 - local
	unsigned int flag_leading;				//Текущий ПЧ мастер
	unsigned int flag_second_leading;		//Второй ПЧ мастер
	unsigned int read_task_from_optical_bus;
	unsigned int sync_rotor_from_optical_bus;
	unsigned int sync_Iq_from_optical_bus;
	unsigned int flag_distance;
	unsigned int flag_second_PCH;
	unsigned int leftShaft;
	unsigned int inverter_number;
	unsigned int ice_movement_limit;
	unsigned int flag_batery_charged;
	unsigned int flag_Pump_Is_On;		//Gidropodpor
	unsigned int flag_turn_On_Pump;
	unsigned int flag_UMP_blocked;
	unsigned int power_units_doors_closed;
	unsigned int power_units_doors_locked;
	
	unsigned int flag_decr_mzz_power;

	unsigned int rotor_stopped;

	float decr_mzz_power;
	_iq iq_decr_mzz_power;

	_iq iq_decr_mzz_voltage;

    float     fzad;
    float     kzad;
    float     kzad_plus;
	float     fzad_provorot;
    float	 Sdvigfaza;
    
    float     mzz_zad;
    float     fr_zad;
    float 	 Power;
    float	 p_zad;
    
    
//    _iq  iq_bpsi_zad;
	_iq iq_mzz_zad;
	_iq iq_fzad_provorot;
	_iq iq_fzad;
	_iq iq_p_zad;
	_iq iq_p_rampa;
	_iq iq_p_zad_electric;
	_iq iq_p_limit_zad;
	int p_limit_zad; //Ограничение мощности с верхнего уровня
    
	unsigned int flag_Enable_Prepare;

	union {
		unsigned int all;
		struct {
			unsigned int BV1: 1;
			unsigned int BV2: 1;
			unsigned int BI1: 1;
			unsigned int BI2: 1;
			unsigned int UMU: 1;
			unsigned int UKSI: 1;
			unsigned int reserved: 10;
		} UKSS;
	} status_ready;
	
	unsigned int On_Power_QTV;
	unsigned int Power_QTV_is_On;

	unsigned int RS_MPU_ERROR;
	unsigned int MPU_Ready;

	unsigned int flag_tormog;

	int special_test_from_mpu;

	int MessageToCan1;
	int MessageToCan2;
	int flag_change_pwm_freq;
	int flag_random_freq;
	long tmp;

	unsigned int rele1;

	_iq cosinusTerminal;
	_iq cosinusTerminalSquared;
//	_iq cosinusFiOut;

	int setCosTerminal;
	int setTettaKt;

	//Sync vals
	int pwm_freq_plus_minus_zero;
	int disable_sync;
	int sync_ready;
	int flag_sync_vipr1_vipr2;
	int level_find_sync_zero;
	int delta_error_sync;
	int delta_capnum;
	int count_error_sync;
	int capnum0;
	int PWMcounterVal;
    
	int build_version;

} FLAG;


extern FLAG f;
extern WINDING a;
             
#ifdef __cplusplus
	}
#endif

#endif /* _VECTOR_SEV */


