#include <adc_tools.h>
#include <params_bsu.h>
#include <params_hwp.h>

#include "DSP281x_Examples.h"   // DSP281x Examples Include File
#include "DSP281x_SWPrioritizedIsrLevels.h"   // DSP281x Examples Include File
#include "DSP281x_Device.h"
#include "xp_cds_in.h"
#include "xp_cds_out.h"
#include "xp_cds_rs.h"
#include "xp_cds_tk.h"
#include "xp_cds_tk_balzam.h"
#include "xp_project.h"


/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////







void tkak_init_plate(int k, int tkak0_off_protect, int tk_disable_output_a, int tk_disable_output_b)
{
    unsigned int t_ticks;
    //tkak 0
    project.cds_tk[k].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup


    if (k==3)
    {
//        project.cds_tk[k].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off
        // тут у нас только тормозные
        if (tkak0_off_protect==1)
            project.cds_tk[k].write.sbus.mask_protect_tk.all =  0x0000; // only break ack+cur
        else
            project.cds_tk[k].write.sbus.mask_protect_tk.all =  0x0303; // only break ack+cur

//        project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x0003; // optical bus+break
        project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x00cf; // optical bus+break

#if (TKAK_VERSION==TKAK_EDRK)
        project.cds_tk[k].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02);
        project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK);
        project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK);
#endif

#if (TKAK_VERSION==TKAK_23550)
        project.cds_tk[k].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_NS/1000.0 / 0.02);
        project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_NS/1000.0 / DIV_TIME_TK);
        project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_NS/1000.0 / DIV_TIME_TK);
#endif
    }
    else
    {
        project.cds_tk[k].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off

        if (tk_disable_output_a==1 && tk_disable_output_b==1)
        {
            project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x0000; //mask key 1-use key,0-not use key
            project.cds_tk[k].write.sbus.mask_protect_tk.all   = 0xff00; // cur+ack 1-on protect.
        }
        else
        if (tk_disable_output_a==0 && tk_disable_output_b==1)
        {
            project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x000f; //mask key 1-use key,0-not use key
            project.cds_tk[k].write.sbus.mask_protect_tk.all   = 0x0f0f; // cur+ack 1-on protect.
        }
        else
        if (tk_disable_output_a==1 && tk_disable_output_b==0)
        {
            project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x00f0; //mask key 1-use key,0-not use key
            project.cds_tk[k].write.sbus.mask_protect_tk.all   = 0xf0f0; // cur+ack 1-on protect.
        }
        else
        if (tk_disable_output_a==0 && tk_disable_output_b==0)
        {
            project.cds_tk[k].write.sbus.mask_tk_out_40pin.all = 0x00ff; //mask key 1-use key,0-not use key
            project.cds_tk[k].write.sbus.mask_protect_tk.all   = 0xffff; // cur+ack 1-on protect.
        }

        if (tkak0_off_protect==1)
            project.cds_tk[k].write.sbus.mask_protect_tk.all   = 0x0000; // cur+ack 1-on protect.


#if (TKAK_VERSION==TKAK_EDRK)
        project.cds_tk[k].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02);
        project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK);
        project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK);
#endif


#if (TKAK_VERSION==TKAK_23550)


// TK_ACKN_TIME_NS

    t_ticks = (unsigned int)(TK_ACKN_TIME_NS / DIV_TIME_TK_ACKN);

#if (TK_ACKN_TIME_NS>(DIV_TIME_TK_ACKN*255))
#error "TK_ACKN_TIME_NS выше предела!"
#endif
    project.cds_tk[k].write.sbus.ack_time.bit.time = (unsigned int)t_ticks;


//   TK_MIN_TIME_NS

    t_ticks = (unsigned int)(TK_MIN_TIME_NS / DIV_TIME_TK_MIN);

#if (TK_MIN_TIME_NS>(DIV_TIME_TK_MIN*255))
#error "TK_MIN_TIME_NS выше предела!"
#endif

    project.cds_tk[k].write.sbus.dead_min_time.bit.mintime = (unsigned int)t_ticks;


//TK_DEAD_TIME_NS

    // минимальное значение для dead_time = 5 мкс, меньше - загрузится все равно 5 мкс
    t_ticks = (unsigned int)(TK_DEAD_TIME_NS / DIV_TIME_TK_DEAD);

#if (TK_DEAD_TIME_NS>(DIV_TIME_TK_DEAD*255))
#error "TK_DEAD_TIME_MKS выше предела!"
#endif
    project.cds_tk[k].write.sbus.dead_min_time.bit.deadtime = (unsigned int)(t_ticks);


// TK_SOFT_OFF_TIME_NS

    t_ticks = (unsigned int)(TK_SOFT_OFF_TIME_NS / DIV_TIME_TK_SOFT_OFF);

#if (TK_SOFT_OFF_TIME_NS>(DIV_TIME_TK_SOFT_OFF*65535))
#error "TK_SOFT_OFF_TIME_MKS выше предела!"
#endif
    project.cds_tk[k].write.sbus.time_after_err = (unsigned int)t_ticks;

#endif




    project.cds_tk[k].write.sbus.protect_error.bit.enable_soft_disconnect = 1;
    project.cds_tk[k].write.sbus.protect_error.bit.detect_soft_disconnect = 0;//1;

    }

    if (tkak0_off_protect==1)
    {
        project.cds_tk[k].write.sbus.protect_error.bit.enable_err_power    = 0;
        project.cds_tk[k].write.sbus.protect_error.bit.enable_err_switch   = 0;
        project.cds_tk[k].write.sbus.protect_error.bit.disable_err_hwp     = 0;
        project.cds_tk[k].write.sbus.protect_error.bit.disable_err0_in     = 0;
        project.cds_tk[k].write.sbus.protect_error.bit.disable_err_mintime = 0;
        project.cds_tk[k].write.sbus.protect_error.bit.enable_line_err     = 0;
        project.cds_tk[k].write.sbus.protect_error.bit.enable_soft_disconnect = 0;
        project.cds_tk[k].write.sbus.protect_error.bit.detect_soft_disconnect = 0;
    }
    else
    {

        project.cds_tk[k].write.sbus.protect_error.bit.enable_err_power    = 1;
        project.cds_tk[k].write.sbus.protect_error.bit.disable_err_hwp     = 1;
        project.cds_tk[k].write.sbus.protect_error.bit.disable_err0_in     = 1;
        project.cds_tk[k].write.sbus.protect_error.bit.disable_err_mintime = 1;
        project.cds_tk[k].write.sbus.protect_error.bit.enable_line_err     = 1;//1;//0;//1;

        // на старых переходных платах этого сигнала нет! нужна перемыка!
        if (project.cds_tk[k].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
            project.cds_tk[k].write.sbus.protect_error.bit.enable_err_switch = 0;
        else
            project.cds_tk[k].write.sbus.protect_error.bit.enable_err_switch = 1;
    }


}


////////////////////////////////////////////////////////////////
// грузим настройки в перифер. платы и HWP
////////////////////////////////////////////////////////////////
void project_prepare_config(void)
{
    int k = 0;
// write here setup for all plates
//
//
//
//  ...
// project.cds_tk[0].write.sbus.ack_time.bit.delay = ...;




//////////////////////////////////////////////////////////////////
///
//  Настроим что принимать в шине PBUS
/////////////////////////////////////////////////////////////////

#if (USE_IN_0)
    project.cds_in[0].type_plate = cds_in_type_in_1;
//////////////////////////////////////////////////////////////////
// настроим какие данные мы хотим получать в PBUS IN0 sensors
//
    project.cds_in[0].setup_pbus.use_reg_in_pbus.all = 0;
//DataFromIn
	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg0 = 1; // use
//Gotov
	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg1 = 1; // use
//Direction
	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg2 = 1; // use

//#if (ENABLE_ROTOR_SENSOR_1_PBUS==1)
// sensor1
//SpeedS1_cnt
	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg3 = 1; // use
//SpeedS1_cnt90
	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg4 = 1; // use
//#endif

//#if (ENABLE_ROTOR_SENSOR_2_PBUS==1)
// sensor2
//SpeedS2_cnt
	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg5 = 1; // use
//SpeedS2_cnt90
	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg6 = 1; // use
//#endif

//#if (TYPE_CDS_XILINX_IN_0==TYPE_CDS_XILINX_SP2)
//	if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP2)
//is Channel Alive
//	project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg13 = 1; // use
//#endif


    if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
    {

        #if (ENABLE_ROTOR_SENSOR_1_PBUS==1)
        //Time since zero point S1
            project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg7 = 1; // use
        // Impulses since zero point Rising S1
            project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg8 = 1; // use
        //Impulses since zero point Falling S1
            project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg9 = 1; // use
        #endif


        #if (ENABLE_ROTOR_SENSOR_2_PBUS==1)
        //Time since zero point S2
            project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg10 = 1; // use
        // Impulses since zero point Rising S2
            project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg11 = 1; // use
        //Impulses since zero point Falling S2
            project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg12 = 1; // use
        #endif

        //is Channel Alive
            project.cds_in[0].setup_pbus.use_reg_in_pbus.bit.reg13 = 1; // use

    }
    project.cds_in[0].status_serial_bus.max_read_error = MAX_READ_SBUS;


#endif


#if (USE_IN_1)
    project.cds_in[1].type_plate = cds_in_type_in_2;
// IN1
    project.cds_in[1].setup_pbus.use_reg_in_pbus.all      = 0;
	project.cds_in[1].setup_pbus.use_reg_in_pbus.bit.reg0 = 1; // use
	project.cds_in[1].setup_pbus.use_reg_in_pbus.bit.reg1 = 0; // not use
	project.cds_in[1].setup_pbus.use_reg_in_pbus.bit.reg2 = 0; // not use

    project.cds_in[1].status_serial_bus.max_read_error = MAX_READ_SBUS;

#endif

#if (USE_IN_2)
    project.cds_in[2].type_plate = cds_in_type_in_2;
// IN2
    project.cds_in[2].setup_pbus.use_reg_in_pbus.all      = 0;
	project.cds_in[2].setup_pbus.use_reg_in_pbus.bit.reg0 = 1; // use
	project.cds_in[2].setup_pbus.use_reg_in_pbus.bit.reg1 = 0; // not use
	project.cds_in[2].setup_pbus.use_reg_in_pbus.bit.reg2 = 0; // not use
    project.cds_in[2].status_serial_bus.max_read_error = MAX_READ_SBUS;

#endif

#if (USE_ROT_1)
// CDS_RS
	project.cds_rs[0].setup_pbus.use_reg_in_pbus.all = 0xffff; // use all 16
#endif

#if (USE_ADC_0)
//ADC0
	project.adc[0].setup_pbus.use_reg_in_pbus.all = 0xffff; // use all 16
	/////////////////////////////////////////////////////////////////////////////
	// SERIAL_BUS Timing setup
	/////////////////////////////////////////////////////////////////////////////
    project.adc[0].status_serial_bus.max_read_error = 2;//MAX_READ_SBUS;
    project.adc[0].status_serial_bus.max_write_error = 2;//MAX_READ_SBUS;
#endif

#if (USE_ADC_1)
//ADC1
	project.adc[1].setup_pbus.use_reg_in_pbus.all = 0xffff; // use all 16
	/////////////////////////////////////////////////////////////////////////////
	// SERIAL_BUS Timing setup
	/////////////////////////////////////////////////////////////////////////////
    project.adc[1].status_serial_bus.max_read_error = 2;//MAX_READ_SBUS;
    project.adc[1].status_serial_bus.max_write_error = 2;//MAX_READ_SBUS;

#endif

#if (USE_ADC_2)
//ADC1
    project.adc[1].setup_pbus.use_reg_in_pbus.all = 0xffff; // use all 16
    /////////////////////////////////////////////////////////////////////////////
    // SERIAL_BUS Timing setup
    /////////////////////////////////////////////////////////////////////////////

    project.adc[1].status_serial_bus.max_read_error = 2;//MAX_READ_SBUS;
    project.adc[1].status_serial_bus.max_write_error = 2;//MAX_READ_SBUS;

#endif



//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

#if (USE_TK_0)
    tkak_init_plate(0, TKAK0_OFF_PROTECT, TK_DISABLE_OUTPUT_A1, TK_DISABLE_OUTPUT_B1);
#endif
#if (USE_TK_1)
    tkak_init_plate(1, TKAK1_OFF_PROTECT, TK_DISABLE_OUTPUT_C1, TK_DISABLE_OUTPUT_A2);
#endif
#if (USE_TK_2)
    tkak_init_plate(2, TKAK2_OFF_PROTECT, TK_DISABLE_OUTPUT_B2, TK_DISABLE_OUTPUT_C2);
#endif

#if (USE_TK_3)
    tkak_init_plate(3, TKAK3_OFF_PROTECT, 0, 0);
#endif

/*
#if (USE_TK_0)
//tkak 0 
    project.cds_tk[0].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup
    project.cds_tk[0].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off

#if (TK_DISABLE_OUTPUT_A1==1 && TK_DISABLE_OUTPUT_B1==1)
	project.cds_tk[0].write.sbus.mask_tk_out_40pin.all = 0x0000; //mask key 1-use key,0-not use key
	project.cds_tk[0].write.sbus.mask_protect_tk.all   = 0xff00; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_A1==0 && TK_DISABLE_OUTPUT_B1==1)
    project.cds_tk[0].write.sbus.mask_tk_out_40pin.all = 0x000f; //mask key 1-use key,0-not use key
    project.cds_tk[0].write.sbus.mask_protect_tk.all   = 0xff0f; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_A1==1 && TK_DISABLE_OUTPUT_B1==0)
    project.cds_tk[0].write.sbus.mask_tk_out_40pin.all = 0x00f0; //mask key 1-use key,0-not use key
    project.cds_tk[0].write.sbus.mask_protect_tk.all   = 0xfff0; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_A1==0 && TK_DISABLE_OUTPUT_B1==0)
    project.cds_tk[0].write.sbus.mask_tk_out_40pin.all = 0x00ff; //mask key 1-use key,0-not use key
    project.cds_tk[0].write.sbus.mask_protect_tk.all   = 0xffff; // cur+ack 1-on protect.
#endif
#endif
#endif
#endif

#if (TKAK0_OFF_PROTECT==1)
    project.cds_tk[0].write.sbus.mask_protect_tk.all   = 0x0000; // cur+ack 1-on protect.
#endif


	project.cds_tk[0].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02);
	project.cds_tk[0].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK);
	project.cds_tk[0].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK);



#if (TKAK0_OFF_PROTECT==1)
    project.cds_tk[0].write.sbus.protect_error.bit.enable_err_power    = 0;
    project.cds_tk[0].write.sbus.protect_error.bit.enable_err_switch   = 0;
    project.cds_tk[0].write.sbus.protect_error.bit.disable_err_hwp     = 0;
    project.cds_tk[0].write.sbus.protect_error.bit.disable_err0_in     = 0;
	project.cds_tk[0].write.sbus.protect_error.bit.disable_err_mintime = 0;
	project.cds_tk[0].write.sbus.protect_error.bit.enable_line_err     = 0;
#else


    project.cds_tk[0].write.sbus.protect_error.bit.enable_err_power    = 1;
    project.cds_tk[0].write.sbus.protect_error.bit.disable_err_hwp     = 1;
    project.cds_tk[0].write.sbus.protect_error.bit.disable_err0_in     = 1;
	project.cds_tk[0].write.sbus.protect_error.bit.disable_err_mintime = 1;
	project.cds_tk[0].write.sbus.protect_error.bit.enable_line_err     = 1;

    // на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_tk[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_tk[0].write.sbus.protect_error.bit.enable_err_switch = 0;
    else
        project.cds_tk[0].write.sbus.protect_error.bit.enable_err_switch = 1;


#endif


#endif


#if (USE_TK_1)
//////////////////////////////////////////////////////////////
// tkak1
    project.cds_tk[1].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup
    project.cds_tk[1].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off


#if (TK_DISABLE_OUTPUT_C1==1 && TK_DISABLE_OUTPUT_A2==1)
    project.cds_tk[1].write.sbus.mask_tk_out_40pin.all = 0x0000; //mask key 1-use key,0-not use key
    project.cds_tk[1].write.sbus.mask_protect_tk.all   = 0xff00; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_C1==0 && TK_DISABLE_OUTPUT_A2==1)
    project.cds_tk[1].write.sbus.mask_tk_out_40pin.all = 0x000f; //mask key 1-use key,0-not use key
    project.cds_tk[1].write.sbus.mask_protect_tk.all   = 0xff0f; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_C1==1 && TK_DISABLE_OUTPUT_A2==0)
    project.cds_tk[1].write.sbus.mask_tk_out_40pin.all = 0x00f0; //mask key 1-use key,0-not use key
    project.cds_tk[1].write.sbus.mask_protect_tk.all   = 0xfff0; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_C1==0 && TK_DISABLE_OUTPUT_A2==0)
    project.cds_tk[1].write.sbus.mask_tk_out_40pin.all = 0x00ff; //mask key 1-use key,0-not use key
    project.cds_tk[1].write.sbus.mask_protect_tk.all   = 0xffff; // cur+ack 1-on protect.
#endif
#endif
#endif
#endif


#if (TKAK1_OFF_PROTECT==1)
    project.cds_tk[1].write.sbus.mask_protect_tk.all   = 0x0000; // cur+ack 1-on protect.
#endif

	project.cds_tk[1].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02);
	project.cds_tk[1].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK);
	project.cds_tk[1].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK);

#if (TKAK1_OFF_PROTECT==1)
    project.cds_tk[1].write.sbus.protect_error.bit.enable_err_power    = 0;
    project.cds_tk[1].write.sbus.protect_error.bit.enable_err_switch   = 0;
    project.cds_tk[1].write.sbus.protect_error.bit.disable_err_hwp     = 0;
    project.cds_tk[1].write.sbus.protect_error.bit.disable_err0_in     = 0;
	project.cds_tk[1].write.sbus.protect_error.bit.disable_err_mintime = 0;
	project.cds_tk[1].write.sbus.protect_error.bit.enable_line_err     = 0;
#else

    project.cds_tk[1].write.sbus.protect_error.bit.enable_err_power    = 1;
    project.cds_tk[1].write.sbus.protect_error.bit.disable_err_hwp     = 1;
    project.cds_tk[1].write.sbus.protect_error.bit.disable_err0_in     = 1;
	project.cds_tk[1].write.sbus.protect_error.bit.disable_err_mintime = 1;
	project.cds_tk[1].write.sbus.protect_error.bit.enable_line_err     = 1;

	// на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_tk[1].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_tk[1].write.sbus.protect_error.bit.enable_err_switch = 0;
    else
        project.cds_tk[1].write.sbus.protect_error.bit.enable_err_switch = 1;

#endif

#endif


#if (USE_TK_2)
//////////////////////////////////////////////////////////////
// tkak2
    project.cds_tk[2].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup
    project.cds_tk[2].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off

#if (TK_DISABLE_OUTPUT_B2==1 && TK_DISABLE_OUTPUT_C2==1)
    project.cds_tk[2].write.sbus.mask_tk_out_40pin.all = 0x0000; //mask key 1-use key,0-not use key
    project.cds_tk[2].write.sbus.mask_protect_tk.all   = 0xff00; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_B2==0 && TK_DISABLE_OUTPUT_C2==1)
    project.cds_tk[2].write.sbus.mask_tk_out_40pin.all = 0x000f; //mask key 1-use key,0-not use key
    project.cds_tk[2].write.sbus.mask_protect_tk.all   = 0xff0f; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_B2==1 && TK_DISABLE_OUTPUT_C2==0)
    project.cds_tk[2].write.sbus.mask_tk_out_40pin.all = 0x00f0; //mask key 1-use key,0-not use key
    project.cds_tk[2].write.sbus.mask_protect_tk.all   = 0xfff0; // cur+ack 1-on protect.
#else
#if (TK_DISABLE_OUTPUT_B2==0 && TK_DISABLE_OUTPUT_C2==0)
    project.cds_tk[2].write.sbus.mask_tk_out_40pin.all = 0x00ff; //mask key 1-use key,0-not use key
    project.cds_tk[2].write.sbus.mask_protect_tk.all   = 0xffff; // cur+ack 1-on protect.
#endif
#endif
#endif
#endif

#if (TKAK1_OFF_PROTECT==1)
    project.cds_tk[2].write.sbus.mask_protect_tk.all   = 0x0000; // cur+ack 1-on protect.
#endif


	project.cds_tk[2].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02);
	project.cds_tk[2].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK);
	project.cds_tk[2].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK);

#if (TKAK2_OFF_PROTECT==1)

    project.cds_tk[2].write.sbus.protect_error.bit.enable_err_power    = 0;
    project.cds_tk[2].write.sbus.protect_error.bit.enable_err_switch   = 0;
    project.cds_tk[2].write.sbus.protect_error.bit.disable_err_hwp     = 0;
    project.cds_tk[2].write.sbus.protect_error.bit.disable_err0_in     = 0;
	project.cds_tk[2].write.sbus.protect_error.bit.disable_err_mintime = 0;
	project.cds_tk[2].write.sbus.protect_error.bit.enable_line_err     = 0;

#else

    project.cds_tk[2].write.sbus.protect_error.bit.enable_err_power    = 1;
    project.cds_tk[2].write.sbus.protect_error.bit.disable_err_hwp     = 1;
    project.cds_tk[2].write.sbus.protect_error.bit.disable_err0_in     = 1;
	project.cds_tk[2].write.sbus.protect_error.bit.disable_err_mintime = 1;
	project.cds_tk[2].write.sbus.protect_error.bit.enable_line_err     = 1;

    // на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_tk[2].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_tk[2].write.sbus.protect_error.bit.enable_err_switch = 0;
    else
        project.cds_tk[2].write.sbus.protect_error.bit.enable_err_switch = 1;

#endif

#endif



#if (USE_TK_3)
//////////////////////////////////////////////////////////////

// тут у нас только тормозные
    project.cds_tk[3].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup
//    project.cds_tk[3].setup_pbus.use_reg_in_pbus.all = 0x0; // PBUS all off

#if (TKAK3_OFF_PROTECT==1)
    project.cds_tk[3].write.sbus.mask_protect_tk.all =  0x0000; // only break ack+cur
#else
	project.cds_tk[3].write.sbus.mask_protect_tk.all =  0x0303; // only break ack+cur
#endif
	project.cds_tk[3].write.sbus.mask_tk_out_40pin.all = 0x00cf; // optical bus+break

	project.cds_tk[3].write.sbus.ack_time.bit.time = (int)(TK_ACKN_TIME_MKS / 0.02);
	project.cds_tk[3].write.sbus.dead_min_time.bit.mintime = (int)(TK_MIN_TIME_MKS / DIV_TIME_TK);
	project.cds_tk[3].write.sbus.dead_min_time.bit.deadtime = (int)(TK_DEAD_TIME_MKS / DIV_TIME_TK);


#if (TKAK3_OFF_PROTECT==1)

    project.cds_tk[3].write.sbus.protect_error.bit.enable_err_power    = 0;
    project.cds_tk[3].write.sbus.protect_error.bit.enable_err_switch   = 0;
    project.cds_tk[3].write.sbus.protect_error.bit.disable_err_hwp     = 0;
    project.cds_tk[3].write.sbus.protect_error.bit.disable_err0_in     = 0;
	project.cds_tk[3].write.sbus.protect_error.bit.disable_err_mintime = 0;
	project.cds_tk[3].write.sbus.protect_error.bit.enable_line_err     = 0;

#else

    project.cds_tk[3].write.sbus.protect_error.bit.enable_err_power    = 1;
    project.cds_tk[3].write.sbus.protect_error.bit.disable_err_hwp     = 1;
    project.cds_tk[3].write.sbus.protect_error.bit.disable_err0_in     = 1;
	project.cds_tk[3].write.sbus.protect_error.bit.disable_err_mintime = 1;
	project.cds_tk[3].write.sbus.protect_error.bit.enable_line_err     = 1;

    // на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_tk[3].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_tk[3].write.sbus.protect_error.bit.enable_err_switch = 0;
    else
        project.cds_tk[3].write.sbus.protect_error.bit.enable_err_switch = 1;


#endif

#endif
*/
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

// Out plane setup


#if (USE_OUT_0)
//////////////////////////////////////////////////////////////
// out0

	project.cds_out[0].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup



#if (OUT0_OFF_PROTECT==1)

    project.cds_out[0].write.sbus.protect_error.bit.disable_err0_in   = 0;
    project.cds_out[0].write.sbus.protect_error.bit.disable_err_hwp   = 0;
    project.cds_out[0].write.sbus.protect_error.bit.enable_err_power  = 0;
    project.cds_out[0].write.sbus.protect_error.bit.enable_err_switch = 0;

#else

	project.cds_out[0].write.sbus.protect_error.bit.enable_err_power  = 1;
	project.cds_out[0].write.sbus.protect_error.bit.disable_err0_in   = 1;
	project.cds_out[0].write.sbus.protect_error.bit.disable_err_hwp   = 1;
	project.cds_out[0].write.sbus.protect_error.bit.enable_err_switch = 1;
	// на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_out[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_out[0].write.sbus.protect_error.bit.enable_err_switch  = 0;
    else
        project.cds_out[0].write.sbus.protect_error.bit.enable_err_switch  = 1;

#endif

    project.cds_out[0].write.sbus.enable_protect_out.all = 0x0000;


// блокировка управляющих сигналов на плате OUT при возникновении внешнего ERR
    project.cds_out[0].write.sbus.enable_protect_out.bit.dout0 = 1; // длЯ вкл. зарЯд
    project.cds_out[0].write.sbus.enable_protect_out.bit.dout6 = 1; // 6 - разрешение включения QTV
//    project.cds_out[0].write.sbus.enable_protect_out.bit.dout7 = 1; // QTV OFF
    project.cds_out[0].write.sbus.enable_protect_out.bit.dout8 = 1; // 8 - включение QTV
    project.cds_out[0].write.sbus.enable_protect_out.bit.dout13 = 1; //  13 - включить УМП намагничивание трансформатора

#endif

#if (USE_OUT_1)

// out1
    project.cds_out[1].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup

#if (OUT1_OFF_PROTECT==1)

    project.cds_out[1].write.sbus.protect_error.bit.disable_err0_in   = 0;
    project.cds_out[1].write.sbus.protect_error.bit.disable_err_hwp   = 0;
    project.cds_out[1].write.sbus.protect_error.bit.enable_err_power  = 0;
    project.cds_out[1].write.sbus.protect_error.bit.enable_err_switch = 0;

#else
    project.cds_out[1].write.sbus.protect_error.bit.enable_err_power  = 1;
    project.cds_out[1].write.sbus.protect_error.bit.disable_err0_in   = 1;
    project.cds_out[1].write.sbus.protect_error.bit.disable_err_hwp   = 1;
    project.cds_out[1].write.sbus.protect_error.bit.enable_err_switch = 1;


    project.cds_out[1].write.sbus.protect_error.bit.enable_err_power  = 1;
    // на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_out[1].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_out[1].write.sbus.protect_error.bit.enable_err_switch = 0;
    else
        project.cds_out[1].write.sbus.protect_error.bit.enable_err_switch  = 1;
#endif

	project.cds_out[1].write.sbus.enable_protect_out.all = 0x0000;

#endif

#if (USE_OUT_2)

//out2
    project.cds_out[2].status_serial_bus.max_read_error = MAX_READ_SBUS;// SERIAL_BUS Timing setup


    project.cds_out[2].write.sbus.protect_error.bit.enable_err_power  = 1;
    project.cds_out[2].write.sbus.protect_error.bit.disable_err0_in   = 1;
    project.cds_out[2].write.sbus.protect_error.bit.disable_err_hwp   = 1;
    project.cds_out[2].write.sbus.protect_error.bit.enable_err_switch = 1;


	project.cds_out[2].write.sbus.protect_error.bit.enable_err_power  = 1;

	// на старых переходных платах этого сигнала нет! нужна перемыка!
	if (project.cds_out[2].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
	    project.cds_out[2].write.sbus.protect_error.bit.enable_err_switch = 0;
	else
	    project.cds_out[2].write.sbus.protect_error.bit.enable_err_switch  = 1;

	project.cds_out[2].write.sbus.enable_protect_out.all = 0x0000;

#endif

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
/////////////

#if (USE_IN_0)

/////////////////////////////////////////////////////////////////////
// setup incremental sensor rotor
/////////////////////////////////////////////////////////////////////
// выбор дискретизации для счетчика оборотов на плате входов
//   1 - 20ns 0 - 2us.
	project.cds_in[0].write.sbus.enabled_channels.bit.discret = 0;


// подключен только один датчик на линии In0- метка нулЯ, In1-прЯмой, In2-прЯмой90град.
// поэтому имитируем второй датчик как первый, чтоб он прошел на вход ПМ67 как второй, но
// меняем местами In1-прямой, In2-прямой90град. в настройках для второго датчика

	project.cds_in[0].write.sbus.enabled_channels.bit.sens_1_direct_ch 			= 1; //1
	project.cds_in[0].write.sbus.enabled_channels.bit.sens_1_direct_ch_90deg 	= 1; //0
	project.cds_in[0].write.sbus.enabled_channels.bit.sens_1_inv_ch 			= 0;
	project.cds_in[0].write.sbus.enabled_channels.bit.sens_1_inv_ch_90deg 		= 0;

	project.cds_in[0].write.sbus.enabled_channels.bit.sens_2_direct_ch 			= 1;
	project.cds_in[0].write.sbus.enabled_channels.bit.sens_2_direct_ch_90deg 	= 1;
	project.cds_in[0].write.sbus.enabled_channels.bit.sens_2_inv_ch 			= 0;
	project.cds_in[0].write.sbus.enabled_channels.bit.sens_2_inv_ch_90deg 		= 0;

// первый датчик In1-прямой, In2-прямой90град.
// на неиспользуемые пишем 0xf
	project.cds_in[0].write.sbus.first_sensor.bit.direct_ch 					= 0x0; // in2
	project.cds_in[0].write.sbus.first_sensor.bit.direct_ch_90deg				= 0x1; // in1
// эти отключены
	project.cds_in[0].write.sbus.first_sensor.bit.inv_ch 						= 0x0f; // in0
	project.cds_in[0].write.sbus.first_sensor.bit.inv_ch_90deg 					= 0x0f; // in0

// как бы первый, но с перекрестом  In2-прямой, In1-прямой90град.
	project.cds_in[0].write.sbus.second_sensor.bit.direct_ch 					= 0x01; // in0
	project.cds_in[0].write.sbus.second_sensor.bit.direct_ch_90deg 				= 0x00; // in1
// эти отключены
	project.cds_in[0].write.sbus.second_sensor.bit.inv_ch 						= 0x0f; // in0
	project.cds_in[0].write.sbus.second_sensor.bit.inv_ch_90deg 				= 0x0f; // in0
// метка нулЯ 
	project.cds_in[0].write.sbus.zero_sensors.bit.for_sensor1 					= 0x02; //
	project.cds_in[0].write.sbus.zero_sensors.bit.for_sensor2 					= 0x0f; //
// включаем только одну метуку нулЯ
	project.cds_in[0].write.sbus.zero_sensors.bit.enable_sensor1				= 1;
	project.cds_in[0].write.sbus.zero_sensors.bit.enable_sensor2				= 0;

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

// In plane setup
//in0

#if (IN0_OFF_PROTECT==1)

    project.cds_in[0].write.sbus.protect_error.bit.disable_err0_in   = 0;
    project.cds_in[0].write.sbus.protect_error.bit.disable_err_hwp   = 0;
    project.cds_in[0].write.sbus.protect_error.bit.enable_err_power  = 0;
    project.cds_in[0].write.sbus.protect_error.bit.enable_err_switch = 0;

#else

    project.cds_in[0].write.sbus.protect_error.bit.disable_err0_in   = 1;
    project.cds_in[0].write.sbus.protect_error.bit.disable_err_hwp   = 1;

    // на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_in[0].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
    {
        project.cds_in[0].write.sbus.protect_error.bit.enable_err_power  = 0;
        project.cds_in[0].write.sbus.protect_error.bit.enable_err_switch = 0;
    }
    else
    {
        project.cds_in[0].write.sbus.protect_error.bit.enable_err_power  = 1;
        project.cds_in[0].write.sbus.protect_error.bit.enable_err_switch = 1;
    }

#endif


#endif


#if (USE_IN_1)

// in1

#if (IN1_OFF_PROTECT==1)

    project.cds_in[1].write.sbus.protect_error.bit.disable_err0_in   = 0;
    project.cds_in[1].write.sbus.protect_error.bit.disable_err_hwp   = 0;
    project.cds_in[1].write.sbus.protect_error.bit.enable_err_power  = 0;
    project.cds_in[1].write.sbus.protect_error.bit.enable_err_switch = 0;

#else


	project.cds_in[1].write.sbus.protect_error.bit.disable_err0_in   = 1;
	project.cds_in[1].write.sbus.protect_error.bit.disable_err_hwp   = 1;
	project.cds_in[1].write.sbus.protect_error.bit.enable_err_power  = 1;

    // на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_in[1].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_in[1].write.sbus.protect_error.bit.enable_err_switch = 0;
    else
        project.cds_in[1].write.sbus.protect_error.bit.enable_err_switch = 1;

#endif

#endif



#if (USE_IN_2)

// in2
    project.cds_in[2].write.sbus.protect_error.bit.disable_err0_in   = 1;
    project.cds_in[2].write.sbus.protect_error.bit.disable_err_hwp   = 1;
	project.cds_in[2].write.sbus.protect_error.bit.enable_err_power  = 1;

    // на старых переходных платах этого сигнала нет! нужна перемыка!
    if (project.cds_in[2].type_cds_xilinx == TYPE_CDS_XILINX_SP6)
        project.cds_in[2].write.sbus.protect_error.bit.enable_err_switch = 0;

    else
        project.cds_in[2].write.sbus.protect_error.bit.enable_err_switch = 1;


#endif

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
#if (USE_HWP_0)

    // HWP setup
//    project.hwp[0].write.HWP_Speed  = MODE_HWP_SPEED_AUTO;//MODE_HWP_SPEED_NORMAL;// MODE_HWP_SPEED_AUTO; // MODE_HWP_SPEED_SLOW;//MODE_HWP_SPEED_NORMAL;// MODE_HWP_SPEED_SLOW;

    project.hwp[0].write.test_all_channel = 1;
 
    project.hwp[0].write.use_channel.minus.all = 0xfffc;
    project.hwp[0].write.use_channel.plus.all = 0xffff;

/*
    project.hwp[0].write.use_channel.plus.bit.ch0 = 1;

    project.hwp[0].write.use_channel.minus.bit.ch5 = 1;
    project.hwp[0].write.use_channel.plus.bit.ch5 = 1;

    project.hwp[0].write.use_channel.minus.bit.ch11 = 1;
    project.hwp[0].write.use_channel.plus.bit.ch11 = 1;

*/

    project.hwp[0].write.values[0].plus = convert_real_to_mv_hwp(0,LEVEL_HWP_U_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[0].minus = convert_real_to_mv_hwp(0,LEVEL_HWP_U_ZPT);

    project.hwp[0].write.values[1].plus = convert_real_to_mv_hwp(1,LEVEL_HWP_U_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[1].minus = convert_real_to_mv_hwp(1,LEVEL_HWP_U_ZPT);

    project.hwp[0].write.values[2].plus = convert_real_to_mv_hwp(2,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[2].minus = convert_real_to_mv_hwp(2,LEVEL_HWP_I_AF);
    project.hwp[0].write.values[3].plus = convert_real_to_mv_hwp(3,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[3].minus = convert_real_to_mv_hwp(3,LEVEL_HWP_I_AF);
    project.hwp[0].write.values[4].plus = convert_real_to_mv_hwp(4,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[4].minus = convert_real_to_mv_hwp(4,LEVEL_HWP_I_AF);
    project.hwp[0].write.values[5].plus = convert_real_to_mv_hwp(5,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[5].minus = convert_real_to_mv_hwp(5,LEVEL_HWP_I_AF);
    project.hwp[0].write.values[6].plus = convert_real_to_mv_hwp(6,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[6].minus = convert_real_to_mv_hwp(6,LEVEL_HWP_I_AF);
    project.hwp[0].write.values[7].plus = convert_real_to_mv_hwp(7,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[7].minus = convert_real_to_mv_hwp(7,LEVEL_HWP_I_AF);

    project.hwp[0].write.values[8].plus = convert_real_to_mv_hwp(8,LEVEL_HWP_I_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[8].minus = convert_real_to_mv_hwp(8,LEVEL_HWP_I_ZPT);
    project.hwp[0].write.values[9].plus = convert_real_to_mv_hwp(9,LEVEL_HWP_I_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[9].minus = convert_real_to_mv_hwp(9,LEVEL_HWP_I_ZPT);

    project.hwp[0].write.use_channel.minus.bit.ch9 = 0;
    project.hwp[0].write.use_channel.plus.bit.ch9 = 0;

    project.hwp[0].write.values[10].plus = convert_real_to_mv_hwp(10,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[10].minus = convert_real_to_mv_hwp(10,LEVEL_HWP_U_ABC);
    project.hwp[0].write.values[11].plus = convert_real_to_mv_hwp(11,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[11].minus = convert_real_to_mv_hwp(11,LEVEL_HWP_U_ABC);
    project.hwp[0].write.values[12].plus = convert_real_to_mv_hwp(12,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[12].minus = convert_real_to_mv_hwp(12,LEVEL_HWP_U_ABC);
    project.hwp[0].write.values[13].plus = convert_real_to_mv_hwp(13,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[13].minus = convert_real_to_mv_hwp(13,LEVEL_HWP_U_ABC);


    project.hwp[0].write.values[14].plus = convert_real_to_mv_hwp(14,LEVEL_HWP_I_BREAK);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[14].minus = convert_real_to_mv_hwp(14,LEVEL_HWP_I_BREAK);
    project.hwp[0].write.values[15].plus = convert_real_to_mv_hwp(15,LEVEL_HWP_I_BREAK);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
    project.hwp[0].write.values[15].minus = convert_real_to_mv_hwp(15,LEVEL_HWP_I_BREAK);
#endif
//////////////////////////////////////////////////////////////
#if (USE_HWP_1)

        // HWP setup
  //      project.hwp[1].write.HWP_Speed  = MODE_HWP_SPEED_AUTO;//MODE_HWP_SPEED_NORMAL;// MODE_HWP_SPEED_SLOW;
        project.hwp[1].write.test_all_channel = 1;

        project.hwp[1].write.use_channel.minus.all = 0xfffc;
        project.hwp[1].write.use_channel.plus.all = 0xffff;


        project.hwp[1].write.values[0].plus = convert_real_to_mv_hwp(0,LEVEL_HWP_U_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[0].minus = convert_real_to_mv_hwp(0,LEVEL_HWP_U_ZPT);

        project.hwp[1].write.values[1].plus = convert_real_to_mv_hwp(1,LEVEL_HWP_U_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[1].minus = convert_real_to_mv_hwp(1,LEVEL_HWP_U_ZPT);

        project.hwp[1].write.values[2].plus = convert_real_to_mv_hwp(2,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[2].minus = convert_real_to_mv_hwp(2,LEVEL_HWP_I_AF);
        project.hwp[1].write.values[3].plus = convert_real_to_mv_hwp(3,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[3].minus = convert_real_to_mv_hwp(3,LEVEL_HWP_I_AF);
        project.hwp[1].write.values[4].plus = convert_real_to_mv_hwp(4,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[4].minus = convert_real_to_mv_hwp(4,LEVEL_HWP_I_AF);
        project.hwp[1].write.values[5].plus = convert_real_to_mv_hwp(5,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[5].minus = convert_real_to_mv_hwp(5,LEVEL_HWP_I_AF);
        project.hwp[1].write.values[6].plus = convert_real_to_mv_hwp(6,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[6].minus = convert_real_to_mv_hwp(6,LEVEL_HWP_I_AF);
        project.hwp[1].write.values[7].plus = convert_real_to_mv_hwp(7,LEVEL_HWP_I_AF);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[7].minus = convert_real_to_mv_hwp(7,LEVEL_HWP_I_AF);

        project.hwp[1].write.values[8].plus = convert_real_to_mv_hwp(8,LEVEL_HWP_I_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[8].minus = convert_real_to_mv_hwp(8,LEVEL_HWP_I_ZPT);
        project.hwp[1].write.values[9].plus = convert_real_to_mv_hwp(9,LEVEL_HWP_I_ZPT);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[9].minus = convert_real_to_mv_hwp(9,LEVEL_HWP_I_ZPT);


        project.hwp[1].write.values[10].plus = convert_real_to_mv_hwp(10,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[10].minus = convert_real_to_mv_hwp(10,LEVEL_HWP_U_ABC);
        project.hwp[1].write.values[11].plus = convert_real_to_mv_hwp(11,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[11].minus = convert_real_to_mv_hwp(11,LEVEL_HWP_U_ABC);
        project.hwp[1].write.values[12].plus = convert_real_to_mv_hwp(12,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[12].minus = convert_real_to_mv_hwp(12,LEVEL_HWP_U_ABC);
        project.hwp[1].write.values[13].plus = convert_real_to_mv_hwp(13,LEVEL_HWP_U_ABC);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[13].minus = convert_real_to_mv_hwp(13,LEVEL_HWP_U_ABC);


        project.hwp[1].write.values[14].plus = convert_real_to_mv_hwp(14,LEVEL_HWP_I_BREAK);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[14].minus = convert_real_to_mv_hwp(14,LEVEL_HWP_I_BREAK);
        project.hwp[1].write.values[15].plus = convert_real_to_mv_hwp(15,LEVEL_HWP_I_BREAK);  //Uzpt1 //2 3000V - 845; 3977V - 1120; 2800V - 789; 2600V - 732
        project.hwp[1].write.values[15].minus = convert_real_to_mv_hwp(15,LEVEL_HWP_I_BREAK);
    #endif


//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
	//Incremental sensor_init
#if (ENABLE_ROTOR_SENSOR_1_PM67==1)
	inc_sensor.use_sensor1  	= 1;
#else
	inc_sensor.use_sensor1  	= 0;
#endif
 
#if (ENABLE_ROTOR_SENSOR_2_PM67==1)
	inc_sensor.use_sensor2  	= 1;
#else
	inc_sensor.use_sensor2  	= 0;
#endif


#if (ENABLE_COMBO_SENSOR_1_TO_2==1)
    inc_sensor.use_sensor2  	= 1;
#endif
#if (ENABLE_COMBO_SENSOR_2_TO_1==1)
    inc_sensor.use_sensor1  	= 1;
#endif


    inc_sensor.pm67regs.write_comand_reg.bit.set_sampling_time = SAMPLING_TIME_MS;
// 23550
//	inc_sensor.pm67regs.write_comand_reg.bit.filter_sensitivity = 5; //0x0; //до 170 об.мин
// 22220
      inc_sensor.pm67regs.write_comand_reg.bit.filter_sensitivity = 300;//5; //0x0; //до 170 об.мин



	inc_sensor.set(&inc_sensor);

	//Rotation sensor_init
/*
	rotation_sensor.in_plane.cds_in = &project.cds_in[0];
	rotation_sensor.use_sensor1 = 1;
    rotation_sensor.use_sensor2 = 1;
    rotation_sensor.use_angle_plane = 0;




    rotation_sensor.in_plane.write.sbus.enabled_channels.bit.sens_1_direct_ch =1;
    rotation_sensor.in_plane.write.sbus.enabled_channels.bit.sens_2_direct_ch_90deg =1;

//    rotation_sensor.in_plane.write.sbus.enabled_channels.bit.sens_1_direct_ch_90deg = 1;

//    rotation_sensor.in_plane.write.sbus.enabled_channels.bit.sens_2_direct_ch = 1;
//    rotation_sensor.in_plane.write.sbus.enabled_channels.bit.sens_2_direct_ch_90deg = 1;

    rotation_sensor.in_plane.write.sbus.first_sensor_inputs.bit.direct_ch = 0;
//    rotation_sensor.in_plane.write.sbus.first_sensor_inputs.bit.direct_ch_90deg = 1;

//    rotation_sensor.in_plane.write.sbus.second_sensor_inputs.bit.direct_ch = 3;
	rotation_sensor.in_plane.write.sbus.second_sensor_inputs.bit.direct_ch_90deg = 1;






    rotation_sensor.in_plane.write.regs.comand_reg.bit.set_sampling_time = SAMPLING_TIME_MS;
	rotation_sensor.in_plane.write.regs.comand_reg.bit.filter_sensitivity = 0xF; //до 170 об.мин

*/




    //filter 1 ~ 20nsec
 /*   rotation_sensor.rotation_plane.cds_rs = &project.cds_rs[0];
    rotation_sensor.rotation_plane.write.sbus.config.all = 0;
    rotation_sensor.rotation_plane.write.sbus.config.bit.channel1_enable = 1;
    rotation_sensor.rotation_plane.write.sbus.config.bit.plane_is_master = 1;
    rotation_sensor.rotation_plane.write.sbus.config.bit.survey_time = 49;
    rotation_sensor.rotation_plane.write.sbus.config.bit.transmition_speed = TS250;
										 */
//	rotation_sensor.set(&rotation_sensor);

    if (project.controller.status != component_Ready) 
     return;

//	project.load_cfg_to_plates();

}



