1415 lines
37 KiB
C
1415 lines
37 KiB
C
#include "xp_hwp.h"
|
|
|
|
#include "DSP281x_Examples.h" // DSP281x Examples Include File
|
|
#include "DSP281x_Device.h"
|
|
#include "MemoryFunctions.h"
|
|
#include "Spartan2E_Adr.h"
|
|
#include "TuneUpPlane.h"
|
|
#include "xerror.h"
|
|
#include "xp_controller.h"
|
|
|
|
|
|
T_controller_read r_controller;
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////// //////////////////////
|
|
unsigned int calcVoltsToDACUop(unsigned int miliVolts)
|
|
{
|
|
static unsigned int voltsOut = 0;
|
|
static float rez = 0;
|
|
static float volts = 0.0;
|
|
static float percent = 0.0;
|
|
|
|
volts = miliVolts / 3.0; // 3 áåðåòñß èç êîýô. óñèëåíèß ïåðâîãî ÎÓ ïî êàíàëó Uop
|
|
percent = (float)(volts / UrefDAC);
|
|
rez = 4095.0 * percent;
|
|
voltsOut = (int)rez; // = 4095.0 * miliVolts / (UrefDAC*3.0);
|
|
|
|
return voltsOut;
|
|
}
|
|
/////////////////////////////////////////////////////////////
|
|
unsigned int voltsForChanals(int miliVolts, unsigned int miliVoltsUop)
|
|
{
|
|
static float volts = 0.0;
|
|
static float percent = 0.0;
|
|
static float rez = 0;
|
|
static unsigned int voltsOut = 0;
|
|
|
|
volts = miliVoltsUop - miliVolts; // âû÷èòàåì, ò.ê. ïåðâûé ÎÓ ââîäèò èíâåðñèþ âõîäíîãî ñèãíàëà : ACP_XX = (-1) * ACPXX
|
|
percent = (float)(volts / UrefDAC);
|
|
rez = 4095.0 * percent;
|
|
voltsOut = (int)rez; // = 4095.0 * miliVolts / UrefDAC;
|
|
|
|
return voltsOut;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
unsigned int calcVoltsToDACUtest(unsigned int miliVolts)
|
|
{
|
|
static unsigned int voltsOut = 0;
|
|
static float rez = 0;
|
|
static float volts = 0.0;
|
|
static float percent = 0.0;
|
|
|
|
volts = miliVolts; // âûõîä íà ÎÓ = 3*Uop - (Utest + ACPx)
|
|
percent = (float)(volts / UrefDAC);
|
|
rez = 4095.0 * percent;
|
|
voltsOut = (int)rez; // = 4095.0 * miliVolts / (UrefDAC*3.0);
|
|
|
|
return voltsOut;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
int convert_values(T_hwp *v)
|
|
{
|
|
int i;
|
|
v->low_setup.DACValues[0] = calcVoltsToDACUtest(v->write.U_test);
|
|
v->low_setup.DACValues[1] = calcVoltsToDACUop(v->write.U_opora);
|
|
|
|
|
|
|
|
for (i=0;i<16;i++)
|
|
{
|
|
if (i == 0 || i == 1)
|
|
{
|
|
if (i==0)
|
|
v->low_setup.DACValues[2] = voltsForChanals(v->write.values[i].plus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/ );
|
|
if (i==1)
|
|
v->low_setup.DACValues[3] = voltsForChanals(v->write.values[i].plus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/);
|
|
}
|
|
else
|
|
{
|
|
v->low_setup.DACValues[i*2] = voltsForChanals(v->write.values[i].plus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/);
|
|
v->low_setup.DACValues[i*2+1] = voltsForChanals(-v->write.values[i].minus, HWP_U_OPORA_DEFINE/*v->write.U_opora*/);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
int convert_masks(T_hwp *v)
|
|
{
|
|
|
|
v->low_setup.mask_13to0.all = 0;
|
|
v->low_setup.mask_29to14.all = 0;
|
|
|
|
// íàêëàäûâàåì ìàñêè íà îòêëþ÷åííûå êàíàëû
|
|
v->write.mask.plus.all |= (v->write.use_channel.plus.all);
|
|
v->write.mask.minus.all |= (v->write.use_channel.minus.all);
|
|
|
|
//set masks on UREF0_29
|
|
v->low_setup.mask_13to0.bit.DACCh0 = v->write.mask.plus.bit.ch0;
|
|
v->low_setup.mask_13to0.bit.DACCh1 = v->write.mask.plus.bit.ch1;
|
|
|
|
v->low_setup.mask_13to0.bit.DACCh2 = v->write.mask.plus.bit.ch2;
|
|
v->low_setup.mask_13to0.bit.DACCh3 = v->write.mask.minus.bit.ch2;
|
|
|
|
v->low_setup.mask_13to0.bit.DACCh4 = v->write.mask.plus.bit.ch3;
|
|
v->low_setup.mask_13to0.bit.DACCh5 = v->write.mask.minus.bit.ch3;
|
|
|
|
v->low_setup.mask_13to0.bit.DACCh6 = v->write.mask.plus.bit.ch4;
|
|
v->low_setup.mask_13to0.bit.DACCh7 = v->write.mask.minus.bit.ch4;
|
|
|
|
v->low_setup.mask_13to0.bit.DACCh8 = v->write.mask.plus.bit.ch5;
|
|
v->low_setup.mask_13to0.bit.DACCh9 = v->write.mask.minus.bit.ch5;
|
|
|
|
v->low_setup.mask_13to0.bit.DACCh10 = v->write.mask.plus.bit.ch6;
|
|
v->low_setup.mask_13to0.bit.DACCh11 = v->write.mask.minus.bit.ch6;
|
|
|
|
v->low_setup.mask_13to0.bit.DACCh12 = v->write.mask.plus.bit.ch7;
|
|
v->low_setup.mask_13to0.bit.DACCh13 = v->write.mask.minus.bit.ch7;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh14 = v->write.mask.plus.bit.ch8;
|
|
v->low_setup.mask_29to14.bit.DACCh15 = v->write.mask.minus.bit.ch8;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh16 = v->write.mask.plus.bit.ch9;
|
|
v->low_setup.mask_29to14.bit.DACCh17 = v->write.mask.minus.bit.ch9;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh18 = v->write.mask.plus.bit.ch10;
|
|
v->low_setup.mask_29to14.bit.DACCh19 = v->write.mask.minus.bit.ch10;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh20 = v->write.mask.plus.bit.ch11;
|
|
v->low_setup.mask_29to14.bit.DACCh21 = v->write.mask.minus.bit.ch11;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh22 = v->write.mask.plus.bit.ch12;
|
|
v->low_setup.mask_29to14.bit.DACCh23 = v->write.mask.minus.bit.ch12;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh24 = v->write.mask.plus.bit.ch13;
|
|
v->low_setup.mask_29to14.bit.DACCh25 = v->write.mask.minus.bit.ch13;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh26 = v->write.mask.plus.bit.ch14;
|
|
v->low_setup.mask_29to14.bit.DACCh27 = v->write.mask.minus.bit.ch14;
|
|
|
|
v->low_setup.mask_29to14.bit.DACCh28 = v->write.mask.plus.bit.ch15;
|
|
v->low_setup.mask_29to14.bit.DACCh29 = v->write.mask.minus.bit.ch15;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
|
|
void hwp_init(T_hwp *v)
|
|
{
|
|
|
|
if (v->useit == 0)
|
|
return ;
|
|
|
|
convert_values(v);
|
|
convert_masks(v);
|
|
|
|
#if (USE_HWP_0)
|
|
if (v->plane_address == C_hwp0_address)
|
|
v->low_setup.dac_config.bit.HWPAddress = 0;
|
|
#endif
|
|
|
|
#if (USE_HWP_1)
|
|
if (v->plane_address == C_hwp1_address)
|
|
v->low_setup.dac_config.bit.HWPAddress = 1;
|
|
#endif
|
|
|
|
#if (USE_HWP_2)
|
|
// if (v->plane_address == C_hwp2_address)
|
|
// v->low_setup.dac_config.bit.HWPAddress = /0/1/2;
|
|
#endif
|
|
|
|
|
|
#if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_NORMAL)
|
|
v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_NORMAL;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp
|
|
#endif
|
|
|
|
#if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_SLOW)
|
|
v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_SLOW;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp
|
|
#endif
|
|
|
|
#if (HWP_SPEED_VERSION_DEFINE==MODE_HWP_SPEED_AUTO)
|
|
v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_AUTO;//HWP_SPEED_VERSION_DEFINE; // new version hwp with low speed serial hwp
|
|
#endif
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
int run_internal_test(T_hwp *v)
|
|
{
|
|
int i,k,err, may_be_err_ch;
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
|
|
|
|
for (i=0;i<16;i++)
|
|
{
|
|
v->write.values[i].plus = HWP_DEF_LEVEL_ERROR;
|
|
v->write.values[i].minus = HWP_DEF_LEVEL_ERROR;
|
|
}
|
|
// prepare for test plus
|
|
|
|
v->write.U_test = HWP_U_TEST_DEFINE;
|
|
v->write.U_opora = HWP_U_OPORA_DEFINE;
|
|
//
|
|
v->write.mask.minus.all = HWP_ENABLE_ALL_MASK;
|
|
v->write.mask.plus.all = HWP_ENABLE_ALL_MASK;
|
|
|
|
convert_values(v);
|
|
convert_masks(v);
|
|
|
|
err = 0;
|
|
err += hwp_write_all_dacs(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
// DELAY_US(200);
|
|
|
|
if (err)
|
|
{
|
|
v->status = component_Error;
|
|
return 1;
|
|
}
|
|
|
|
err += hwp_reset_error(v);
|
|
hwp_read_error(v);
|
|
|
|
// ÷èòàåì ñîñòîßíèß êîìïàðàòîðîâ, íå äîëæíî áûòü ñðàáàòûâàíèé!
|
|
err += hwp_read_comparators(v);
|
|
|
|
if (v->read.errors.er0_HWP || err)
|
|
{
|
|
v->status = component_Error;
|
|
// íåò ñáðîñà ëèíèè er0_hwp
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
|
|
// start plus
|
|
for (i=0;i<16;i++)
|
|
{
|
|
// DELAY_US(200000); // +
|
|
v->write.mask.plus.all = HWP_ENABLE_ALL_MASK;
|
|
convert_masks(v);
|
|
// DELAY_US(20000);//+
|
|
err = hwp_write_all_mask(v);
|
|
|
|
err = 0;
|
|
v->read.test_passed.plus.all &= ~(1 << i);
|
|
|
|
if (!(v->write.use_channel.plus.all & (1 << i)))
|
|
{
|
|
// êàíàë èñêëþ÷åí èç îïðîñà
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*10; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê èñêëþ÷åíèÿ
|
|
may_be_err_ch = 1;
|
|
if (v->write.test_all_channel==0)
|
|
continue;
|
|
}
|
|
else
|
|
may_be_err_ch = 0;
|
|
|
|
|
|
v->write.U_test = HWP_U_TEST_LEVEL_FOR_PREPARE_PLUS_TEST;
|
|
v->write.U_opora = HWP_U_OPORA_LEVEL_FOR_PREPARE_PLUS_TEST;
|
|
|
|
for (k=0;k<16;k++)
|
|
{
|
|
if (k==i)
|
|
v->write.values[k].plus = HWP_U_LEVEL_COMP_FOR_TEST_DEFINE; // âûñòàâèëè óðîâåíü äëÿ òåñòà
|
|
else
|
|
v->write.values[k].plus = HWP_DEF_LEVEL_ERROR;
|
|
}
|
|
|
|
convert_values(v);
|
|
|
|
err += hwp_write_all_dacs(v);
|
|
// DELAY_US(20000);//+
|
|
err += hwp_write_all_dacs(v);
|
|
// DELAY_US(20000); // +
|
|
err += hwp_reset_error(v);
|
|
// DELAY_US(20000);
|
|
DELAY_US(2000);
|
|
|
|
hwp_read_error(v);
|
|
// DELAY_US(20000);//+
|
|
|
|
/*
|
|
if (v->read.errors.er0_HWP)
|
|
{
|
|
DELAY_US(20000);
|
|
DELAY_US(20000);
|
|
DELAY_US(20000);
|
|
DELAY_US(20000);
|
|
|
|
i_led2_on_off(1);
|
|
// err += hwp_write_all_dacs(v);
|
|
// DELAY_US(2000); // +
|
|
err += hwp_reset_error(v);
|
|
DELAY_US(20000);
|
|
DELAY_US(20000);
|
|
|
|
i_led2_on_off(0);
|
|
|
|
hwp_read_error(v);
|
|
DELAY_US(20000);//+
|
|
|
|
if (v->read.errors.er0_HWP)
|
|
{
|
|
i_led2_on_off(1);
|
|
// err += hwp_write_all_dacs(v);
|
|
// DELAY_US(2000); // +
|
|
err += hwp_reset_error(v);
|
|
DELAY_US(20000);
|
|
DELAY_US(20000);
|
|
DELAY_US(20000);
|
|
DELAY_US(20000);
|
|
|
|
i_led2_on_off(0);
|
|
|
|
hwp_read_error(v);
|
|
DELAY_US(20000);//+
|
|
DELAY_US(20000);
|
|
|
|
if (v->read.errors.er0_HWP==0)
|
|
{
|
|
DELAY_US(20000);
|
|
err += hwp_reset_error(v);
|
|
err += hwp_reset_error(v);
|
|
err += hwp_reset_error(v);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
DELAY_US(20000);
|
|
err += hwp_reset_error(v);
|
|
err += hwp_reset_error(v);
|
|
err += hwp_reset_error(v);
|
|
}
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
err += hwp_read_comparators(v);
|
|
// DELAY_US(20000);//+
|
|
|
|
|
|
if (v->read.errors.er0_HWP || err)
|
|
{
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*2; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
v->status = component_Error;
|
|
// íåò ñáðîñà ëèíèè er0_hwp èëè îøèáêà çàïèñè óñòàâîê â DAC
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
|
|
// òåïåðü ïèøåì ìàñêè íà îøèáêè êðîìå ïðîâåðßåìîãî êàíàëà è îïßòü
|
|
// ÷èòàåì ñîñòîßíèå êîìïàðàòîðà, íå äîëæíî áûòü ñðàáàòûâàíèß!
|
|
|
|
v->write.mask.plus.all = (1 << i); // clear mask
|
|
convert_masks(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
// ÷èòàåì ñîñòîßíèß êîìïàðàòîðîâ, íå äîëæíî áûòü ñðàáàòûâàíèé!
|
|
err += hwp_read_comparators(v);
|
|
if (v->read.comp_s.plus.all || err)
|
|
{
|
|
// åñòü ñðàáîòàâøèé êîìïàðàòîð - ýòî îøèáêà!
|
|
// ñ÷èòûâàåòñß ñîñòîßíèå ñðàáîòàâøåãî êîìïàðàòîðà, íî íåò ñèãíàëà íà ëèíèè er0_hwp,
|
|
//à íå äîëæíî áûòü èëè îøèáêà ÷òåíèß ñîñòîßíèß êîìïàðàòîðîâ
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*3; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
// ñíèìàåì âñå ìàñêè ñ îøèáîê è ÷èòàåì ñîñòîßíèå êîìïàðàòîðîâ,
|
|
// ñðàáîòàâøèõ íå äîëæíî áûòü!
|
|
v->write.mask.plus.all = HWP_DISABLE_ALL_MASK; // clear all mask
|
|
// v->write.mask.plus.all = (1 << i); // clear mask
|
|
if (may_be_err_ch==0)
|
|
v->write.mask.plus.all = v->write.use_channel.plus.all;
|
|
|
|
convert_masks(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
// ÷èòàåì ñîñòîßíèß êîìïàðàòîðîâ, íå äîëæíî áûòü ñðàáàòûâàíèé!
|
|
err += hwp_read_comparators(v);
|
|
if (v->read.comp_s.plus.all || err)
|
|
{
|
|
// åñòü ñðàáîòàâøèé êîìïàðàòîð - ýòî îøèáêà!
|
|
// ñ÷èòûâàåòñß ñîñòîßíèå ñðàáîòàâøåãî êîìïàðàòîðà, íî íåò ñèãíàëà íà ëèíèè er0_hwp,
|
|
//à íå äîëæíî áûòü èëè îøèáêà ÷òåíèß ñîñòîßíèß êîìïàðàòîðîâ
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*4; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
// ïðîâåðßåì ïðîõîæäåíèå ëèíèè ERR0_HWP
|
|
v->write.mask.plus.all = (1 << i); // will wait it status
|
|
|
|
err += hwp_read_comparators(v);
|
|
|
|
hwp_read_error(v);
|
|
if ((v->read.errors.er0_HWP && v->read.comp_s.plus.all==0)|| err)
|
|
{
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*5; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
v->status = component_Error;
|
|
|
|
// åñòü ñèãíàë íà ëèíèè er0_hwp, à íå äîëæíî áûòü èëè îøèáêà çàïèñè ìàñîê â DAC
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
err += hwp_read_comparators(v);
|
|
|
|
if ( (v->read.comp_s.plus.all && v->read.errors.er0_HWP==0) || err)
|
|
{
|
|
// v->status = component_Error;
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*6; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
|
|
// ñ÷èòûâàåòñß ñîñòîßíèå ñðàáîòàâøåãî êîìïàðàòîðà, íî íåò ñèãíàëà íà ëèíèè er0_hwp,
|
|
//à íå äîëæíî áûòü èëè îøèáêà ÷òåíèß ñîñòîßíèß êîìïàðàòîðîâ
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
// Çàìåðßåì âðåìß ñðàáàòûâàíèß êîìïàðàòîðà
|
|
hwp_clear_delay();
|
|
v->write.U_test = HWP_U_TEST_LEVEL_FOR_DO_PLUS_TEST;
|
|
convert_values(v);
|
|
err += hwp_write_u_test_dacs(v);
|
|
|
|
|
|
if (err)
|
|
{
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
|
|
v->status = component_Error;
|
|
// îøèáêà çàïèñè óñòâêè â DAC U_test
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
DELAY_US(2000);
|
|
|
|
hwp_read_error(v);
|
|
err = hwp_read_delay(v);
|
|
err += hwp_read_comparators(v);
|
|
|
|
if (!v->read.errors.er0_HWP)
|
|
{
|
|
// v->status = component_Error;
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE*7; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
|
|
// íåò ñèãíàë íà ëèíèè er0_hwp, à äîëæåí áûòü
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
|
|
if (v->read.comp_s.plus.all != v->write.mask.plus.all)
|
|
err++;
|
|
|
|
if (v->low_setup.delay.bit.ready == 0 || err)
|
|
{
|
|
v->real_delays.plus[i] = HWP_MAX_ERROR_DELAY_DEFINE; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
}
|
|
else
|
|
{
|
|
v->real_delays.plus[i] = v->low_setup.delay.bit.counter/6;
|
|
if (v->real_delays.plus[i]>=MINIMAL_TEST_TIME_ERROR_HWP && v->real_delays.plus[i]<=MAXIMAL_TEST_TIME_ERROR_HWP)
|
|
v->read.test_passed.plus.all |= (1 << i);
|
|
}
|
|
|
|
v->write.values[i].plus = HWP_DEF_LEVEL_ERROR;
|
|
}
|
|
|
|
|
|
// prepare for test minus
|
|
// ïîäíèìàåì ñèãíàëû íà âåðõíèé óðîâåíü = 3500 mV
|
|
v->write.U_opora = 3500;//HWP_U_OPORA_DEFINE;
|
|
// è çàòåì òåñò íà 1500 mV
|
|
v->write.U_test = 1500;//HWP_U_TEST_DEFINE;
|
|
// â èòîãå ïîëó÷àåì ñèãíàëû îáðàòíî íà óðîâíå 2000 mV.
|
|
// ïîäàâàß äàëüøå òåñò =0V ïîëó÷èì èçìåíåíèå ñèãíàëà äëß ïðîâåðêè ñðàáàòûâàíèß êîìïàðàòîðîâ.
|
|
|
|
v->write.mask.minus.all = HWP_ENABLE_ALL_MASK;
|
|
v->write.mask.plus.all = HWP_ENABLE_ALL_MASK;
|
|
|
|
convert_values(v);
|
|
convert_masks(v);
|
|
|
|
err = 0;
|
|
err += hwp_write_all_dacs(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
if (err)
|
|
{
|
|
v->status = component_Error;
|
|
// îøèáêà çàïèñè óñòàâîê â DAC èëè ìàñîê
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
err += hwp_reset_error(v);
|
|
DELAY_US(2000);
|
|
hwp_read_error(v);
|
|
|
|
if (v->read.errors.er0_HWP || err)
|
|
{
|
|
v->status = component_Error;
|
|
// åñòü ñèãíàë íà ëèíèè er0_hwp, à íå äîëæíî áûòü
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
// minus
|
|
|
|
for (i=2;i<16;i++)
|
|
{
|
|
v->write.mask.minus.all = HWP_ENABLE_ALL_MASK;
|
|
convert_masks(v);
|
|
err = hwp_write_all_mask(v);
|
|
|
|
|
|
err = 0;
|
|
v->read.test_passed.minus.all &= ~(1 << i);
|
|
|
|
if (!(v->write.use_channel.minus.all & (1 << i)))
|
|
{
|
|
// êàíàë èñêëþ÷åí èç îïðîñà
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*10; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê èñêëþ÷åíèÿ
|
|
may_be_err_ch = 1;
|
|
if (v->write.test_all_channel==0)
|
|
continue;
|
|
}
|
|
else
|
|
may_be_err_ch = 0;
|
|
|
|
|
|
v->write.U_test = HWP_U_TEST_LEVEL_FOR_PREPARE_MINUS_TEST;//HWP_U_TEST_DEFINE;
|
|
v->write.U_opora = HWP_U_OPORA_LEVEL_FOR_PREPARE_MINUS_TEST;//HWP_U_OPORA_DEFINE;
|
|
|
|
for (k=2;k<16;k++)
|
|
{
|
|
if (k==i)
|
|
v->write.values[k].minus = HWP_U_LEVEL_COMP_FOR_TEST_DEFINE; // âûñòàâèëè óðîâåíü äëÿ òåñòà
|
|
else
|
|
v->write.values[k].minus = HWP_DEF_LEVEL_ERROR;
|
|
}
|
|
|
|
convert_values(v);
|
|
err += hwp_write_all_dacs(v);
|
|
|
|
err += hwp_reset_error(v);
|
|
DELAY_US(2000);
|
|
|
|
hwp_read_error(v);
|
|
err += hwp_read_comparators(v);
|
|
if (v->read.errors.er0_HWP || err)
|
|
{
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*2; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
|
|
v->status = component_Error;
|
|
// åñòü ñèãíàë íà ëèíèè er0_hwp, à íå äîëæíî áûòü
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
err += hwp_read_comparators(v);
|
|
|
|
if (v->read.comp_s.minus.all || err)
|
|
{
|
|
// v->status = component_Error;
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*3; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
|
|
// ñ÷èòûâàåòñß ñîñòîßíèå ñðàáîòàâøåãî êîìïàðàòîðà, íî íåò ñèãíàëà íà ëèíèè er0_hwp,
|
|
//à íå äîëæíî áûòü èëè îøèáêà ÷òåíèß ñîñòîßíèß êîìïàðàòîðîâ
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
// ñíèìàåì âñå ìàñêè ñ îøèáîê è ÷èòàåì ñîñòîßíèå êîìïàðàòîðîâ,
|
|
// ñðàáîòàâøèõ íå äîëæíî áûòü!
|
|
v->write.mask.minus.all = HWP_DISABLE_ALL_MASK; // clear all mask
|
|
// v->write.mask.minus.all = (1 << i); // clear mask
|
|
if (may_be_err_ch==0)
|
|
v->write.mask.minus.all = v->write.use_channel.minus.all;
|
|
|
|
|
|
convert_masks(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
// ÷èòàåì ñîñòîßíèß êîìïàðàòîðîâ, íå äîëæíî áûòü ñðàáàòûâàíèé!
|
|
err += hwp_read_comparators(v);
|
|
if (v->read.comp_s.minus.all || err)
|
|
{
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*4; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
// åñòü ñðàáîòàâøèé êîìïàðàòîð - ýòî îøèáêà!
|
|
// ñ÷èòûâàåòñß ñîñòîßíèå ñðàáîòàâøåãî êîìïàðàòîðà, íî íåò ñèãíàëà íà ëèíèè er0_hwp,
|
|
//à íå äîëæíî áûòü èëè îøèáêà ÷òåíèß ñîñòîßíèß êîìïàðàòîðîâ
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
// òåïåðü ïèøåì ìàñêè íà îøèáêè êðîìå ïðîâåðßåìîãî êàíàëà è îïßòü
|
|
// ÷èòàåì ñîñòîßíèå êîìïàðàòîðà, íå äîëæíî áûòü ñðàáàòûâàíèß!
|
|
|
|
v->write.mask.minus.all = (1 << i); // clear mask
|
|
convert_masks(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
// ÷èòàåì ñîñòîßíèß êîìïàðàòîðîâ, íå äîëæíî áûòü ñðàáàòûâàíèé!
|
|
err += hwp_read_comparators(v);
|
|
if (v->read.comp_s.minus.all || err)
|
|
{
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*5; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
// åñòü ñðàáîòàâøèé êîìïàðàòîð - ýòî îøèáêà!
|
|
// ñ÷èòûâàåòñß ñîñòîßíèå ñðàáîòàâøåãî êîìïàðàòîðà, íî íåò ñèãíàëà íà ëèíèè er0_hwp,
|
|
//à íå äîëæíî áûòü èëè îøèáêà ÷òåíèß ñîñòîßíèß êîìïàðàòîðîâ
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
|
|
// ïðîâåðßåì ïðîõîæäåíèå ëèíèè ERR0_HWP
|
|
|
|
v->write.mask.minus.all = (1 << i); // will wait it status
|
|
|
|
hwp_read_error(v);
|
|
if ((v->read.errors.er0_HWP && v->read.comp_s.minus.all==0) || err)
|
|
{
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*6; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
v->status = component_Error;
|
|
// åñòü ñèãíàë íà ëèíèè er0_hwp, à íå äîëæíî áûòü
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
hwp_clear_delay();
|
|
v->write.U_test = HWP_U_TEST_LEVEL_FOR_DO_MINUS_TEST;
|
|
convert_values(v);
|
|
err += hwp_write_u_test_dacs(v);
|
|
|
|
if (err)
|
|
{
|
|
v->status = component_Error;
|
|
// îøèáêà çàïèñè óñòâêè â DAC U_test
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
DELAY_US(2000);
|
|
|
|
hwp_read_error(v);
|
|
err = hwp_read_delay(v);
|
|
err += hwp_read_comparators(v);
|
|
|
|
if (!v->read.errors.er0_HWP)
|
|
{
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE*7; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
if (may_be_err_ch)
|
|
continue; // åñëè êàíàë è òàê èñêëþ÷åí, òî ýòî ïðàâèëüíàÿ îøèáêà âîçìîæíî
|
|
// v->status = component_Error;
|
|
// íåò ñèãíàë íà ëèíèè er0_hwp, à äîëæåí áûòü
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
continue;
|
|
// return 1;
|
|
}
|
|
|
|
hwp_read_delay(v);
|
|
|
|
err += hwp_read_comparators(v);
|
|
|
|
if (v->read.comp_s.minus.all != v->write.mask.minus.all)
|
|
err++;
|
|
|
|
if (v->low_setup.delay.bit.ready == 0 || err)
|
|
{
|
|
v->real_delays.minus[i] = HWP_MAX_ERROR_DELAY_DEFINE; // ãðóçèì î÷åíü áîëüøîå ÷èñëî - êàê ïðèçíàê îøèáêè
|
|
}
|
|
else
|
|
{
|
|
v->real_delays.minus[i] = v->low_setup.delay.bit.counter/6;
|
|
if (v->real_delays.minus[i]>=MINIMAL_TEST_TIME_ERROR_HWP && v->real_delays.minus[i]<=MAXIMAL_TEST_TIME_ERROR_HWP)
|
|
v->read.test_passed.minus.all |= (1 << i);
|
|
}
|
|
v->write.values[i].minus = HWP_DEF_LEVEL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
// m = (v->read.test_passed.minus.all & v->write.use_channel.minus.all);
|
|
// p = (v->read.test_passed.plus.all & v->write.use_channel.plus.all);
|
|
|
|
// if ((v->write.use_channel.minus.all != v->read.test_passed.minus.all ) || (v->write.use_channel.plus.all != v->read.test_passed.plus.all ) )
|
|
if ((v->write.use_channel.minus.all != (v->read.test_passed.minus.all & v->write.use_channel.minus.all) )
|
|
|| (v->write.use_channel.plus.all != (v->read.test_passed.plus.all & v->write.use_channel.plus.all ) ) )
|
|
{
|
|
v->status = component_Error;
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
|
|
// finish
|
|
|
|
v->write.U_test = HWP_U_TEST_DEFINE;
|
|
v->write.U_opora = HWP_U_OPORA_DEFINE;
|
|
|
|
v->write.mask.minus.all = HWP_ENABLE_ALL_MASK;
|
|
v->write.mask.plus.all = HWP_ENABLE_ALL_MASK;
|
|
|
|
convert_values(v);
|
|
convert_masks(v);
|
|
|
|
err = 0;
|
|
err += hwp_write_all_dacs(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
if (err)
|
|
{
|
|
v->status = component_Error;
|
|
// îøèáêà çàïèñè óñòàâîê â DAC èëè ìàñîê
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
err += hwp_reset_error(v);
|
|
|
|
hwp_read_error(v);
|
|
|
|
if (v->read.errors.er0_HWP || err)
|
|
{
|
|
v->status = component_Error;
|
|
// åñòü ñèãíàë íà ëèíèè er0_hwp, à íå äîëæíî áûòü
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
|
|
int hwp_internal_test(T_hwp *v)
|
|
{
|
|
int i,err;
|
|
T_hwp_channels old_mask;
|
|
unsigned int old_U_test, old_U_opora;
|
|
T_hwp_cannel_values old_channel_values[16];
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
if (v->status != component_Ready)
|
|
return 1;
|
|
|
|
// ïðîâåðèì ÷òî óñòàâêè âñå ïðàâèëüíûå
|
|
for (i=0;i<16;i++)
|
|
{
|
|
if (v->write.values[i].plus>=HWP_U_OPORA_DEFINE)
|
|
{
|
|
XERROR_DEBUG_MODE_HWP_ERROR_SET_LEVEL_PROTECT; // îøèáêà ðàñ÷åòà óñòàâîê çàùèò, ïåðåïîëíåíèå áîëüøå HWP_U_OPORA_DEFINE
|
|
v->status = component_Error;
|
|
return 1;
|
|
}
|
|
|
|
if (v->write.values[i].minus>=HWP_U_OPORA_DEFINE)
|
|
{
|
|
XERROR_DEBUG_MODE_HWP_ERROR_SET_LEVEL_PROTECT; // îøèáêà ðàñ÷åòà óñòàâîê çàùèò, ïåðåïîëíåíèå áîëüøå HWP_U_OPORA_DEFINE
|
|
v->status = component_Error;
|
|
return 1;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
old_mask = v->write.mask;
|
|
old_U_test = v->write.U_test;
|
|
old_U_opora = v->write.U_opora;
|
|
for (i=0;i<16;i++)
|
|
old_channel_values[i] = v->write.values[i];
|
|
|
|
err = run_internal_test(v);
|
|
|
|
v->write.mask = old_mask;
|
|
v->write.U_test = old_U_test;
|
|
v->write.U_opora = old_U_opora;
|
|
for (i=0;i<16;i++)
|
|
v->write.values[i] = old_channel_values[i];
|
|
|
|
convert_values(v);
|
|
convert_masks(v);
|
|
|
|
err += hwp_write_all_dacs(v);
|
|
err += hwp_write_all_mask(v);
|
|
|
|
if (err)
|
|
{
|
|
// XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
v->status = component_Error;
|
|
return 1;
|
|
}
|
|
|
|
err += hwp_reset_error(v);
|
|
hwp_read_error(v);
|
|
|
|
if (v->read.errors.er0_HWP || err)
|
|
{
|
|
v->status = component_Error;
|
|
// íåò ñáðîñà ëèíèè er0_hwp
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
int hwp_read_delay(T_hwp *v)
|
|
{
|
|
unsigned int cnt_wait_tr;
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
|
|
v->low_setup.delay.bit.ready = 0;
|
|
cnt_wait_tr = MAX_WAIT_TEST_ERROR_HWP;
|
|
|
|
// wait finish transmit data
|
|
while((v->low_setup.delay.bit.ready==0) && (cnt_wait_tr!=0))
|
|
{
|
|
v->low_setup.delay.all = i_ReadMemory(ADR_HWP_TEST_TIMER);
|
|
cnt_wait_tr--;
|
|
}
|
|
|
|
if (cnt_wait_tr==0)
|
|
return 1; // error
|
|
else
|
|
return 0; // all ok
|
|
|
|
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
void hwp_clear_delay(void)
|
|
{
|
|
WriteMemory(ADR_HWP_TEST_TIMER, 0x0);
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
void hwp_autospeed_detect(T_hwp *v)
|
|
{
|
|
int err1 = 0, err2 = 0;
|
|
|
|
|
|
// auto set speed?
|
|
if (v->write.HWP_Speed == MODE_HWP_SPEED_AUTO)
|
|
{
|
|
if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_NOTDETECTED)
|
|
{
|
|
v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_SLOW;
|
|
// v->write.HWP_Speed = MODE_HWP_SPEED_SLOW;
|
|
|
|
err1 = hwp_read_comparators(v);
|
|
|
|
v->low_setup.dac_config.bit.HWP_Speed = MODE_HWP_SPEED_NORMAL;
|
|
// v->write.HWP_Speed = MODE_HWP_SPEED_NORMAL;
|
|
|
|
err2 = hwp_read_comparators(v);
|
|
|
|
|
|
if (err1==0 /*&& err2==1*/) // ïî÷åìó-òî âòîîàÿ ïëàòà hwp Îòâå÷àåò è íà áûñòðîé ñêîðîñòè!? î÷åíü ñòðàííî!!!
|
|
{
|
|
v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_DETECTED;
|
|
v->write.HWP_Speed = MODE_HWP_SPEED_SLOW;
|
|
hwp_read_comparators(v);
|
|
return;
|
|
}
|
|
else
|
|
if (err1==1 && err2==0)
|
|
{
|
|
v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_DETECTED;
|
|
v->write.HWP_Speed = MODE_HWP_SPEED_NORMAL;
|
|
hwp_read_comparators(v);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_FIALED;
|
|
v->write.HWP_Speed = MODE_HWP_SPEED_SLOW;
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return;
|
|
|
|
}
|
|
|
|
} // HWP_AUTOSPEED_NOTDETECTED
|
|
} // MODE_HWP_SPEED_AUTO
|
|
else
|
|
if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_NOTDETECTED)
|
|
v->write.flag_detect_HWP_Speed = HWP_AUTOSPEED_OFF;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
int hwp_read_all(T_hwp *v)
|
|
{
|
|
int err = 0, err_ready = 0;
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
if (v->status == component_Error || v->status == component_NotFinded)
|
|
return 2;
|
|
|
|
// hwp_autospeed_detect(v);
|
|
|
|
if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_FIALED)
|
|
{
|
|
if (v->status==component_NotReady)
|
|
v->status = component_NotFinded;
|
|
else
|
|
v->status = component_Error;
|
|
|
|
return 2;
|
|
}
|
|
|
|
v->low_setup.dac_config.bit.HWP_Speed = v->write.HWP_Speed;
|
|
err = hwp_read_comparators(v);
|
|
err_ready = check_cds_ready_hwpbus( err, ITS_READ_BUS, &v->status_hwp_bus);
|
|
|
|
set_status_cds(err_ready, &v->status);
|
|
|
|
return err_ready;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
int hwp_read_comparators(T_hwp *v)
|
|
{
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
// send cmd to read comparators
|
|
v->low_setup.dac_config.bit.DACOrMask = 1;
|
|
v->low_setup.dac_config.bit.R_W_Direction = 1;
|
|
|
|
v->low_setup.transmitErr = wait_hwp_transfer(v);
|
|
|
|
v->low_setup.dac_config.bit.DACOrMask = 0;
|
|
v->low_setup.dac_config.bit.R_W_Direction = 0;
|
|
|
|
if (v->low_setup.transmitErr)
|
|
{
|
|
// îøèáêà ïåðåäà÷è ïî ñåðèàëüíîé øèíå HWP
|
|
// if (v->write.HWP_Speed != MODE_HWP_SPEED_AUTO)
|
|
// XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
v->low_setup.comp_29to14.all = i_ReadMemory(ADR_HWP_DATA_RECEVED_0);
|
|
v->low_setup.comp_13to0.all = i_ReadMemory(ADR_HWP_DATA_RECEVED_1);
|
|
|
|
|
|
v->read.comp_s.plus.bit.ch0 = v->low_setup.comp_13to0.bit.DACCh0;
|
|
v->read.comp_s.plus.bit.ch1 = v->low_setup.comp_13to0.bit.DACCh1;
|
|
|
|
v->read.comp_s.plus.bit.ch2 = v->low_setup.comp_13to0.bit.DACCh2;
|
|
v->read.comp_s.minus.bit.ch2 = v->low_setup.comp_13to0.bit.DACCh3;
|
|
|
|
v->read.comp_s.plus.bit.ch3 = v->low_setup.comp_13to0.bit.DACCh4;
|
|
v->read.comp_s.minus.bit.ch3 = v->low_setup.comp_13to0.bit.DACCh5;
|
|
|
|
v->read.comp_s.plus.bit.ch4 = v->low_setup.comp_13to0.bit.DACCh6;
|
|
v->read.comp_s.minus.bit.ch4 = v->low_setup.comp_13to0.bit.DACCh7;
|
|
|
|
v->read.comp_s.plus.bit.ch5 = v->low_setup.comp_13to0.bit.DACCh8;
|
|
v->read.comp_s.minus.bit.ch5 = v->low_setup.comp_13to0.bit.DACCh9;
|
|
|
|
v->read.comp_s.plus.bit.ch6 = v->low_setup.comp_13to0.bit.DACCh10;
|
|
v->read.comp_s.minus.bit.ch6 = v->low_setup.comp_13to0.bit.DACCh11;
|
|
|
|
v->read.comp_s.plus.bit.ch7 = v->low_setup.comp_13to0.bit.DACCh12;
|
|
v->read.comp_s.minus.bit.ch7 = v->low_setup.comp_13to0.bit.DACCh13;
|
|
|
|
//
|
|
v->read.comp_s.plus.bit.ch8 = v->low_setup.comp_29to14.bit.DACCh14;
|
|
v->read.comp_s.minus.bit.ch8 = v->low_setup.comp_29to14.bit.DACCh15;
|
|
|
|
v->read.comp_s.plus.bit.ch9 = v->low_setup.comp_29to14.bit.DACCh16;
|
|
v->read.comp_s.minus.bit.ch9 = v->low_setup.comp_29to14.bit.DACCh17;
|
|
|
|
v->read.comp_s.plus.bit.ch10 = v->low_setup.comp_29to14.bit.DACCh18;
|
|
v->read.comp_s.minus.bit.ch10 = v->low_setup.comp_29to14.bit.DACCh19;
|
|
|
|
v->read.comp_s.plus.bit.ch11 = v->low_setup.comp_29to14.bit.DACCh20;
|
|
v->read.comp_s.minus.bit.ch11 = v->low_setup.comp_29to14.bit.DACCh21;
|
|
|
|
v->read.comp_s.plus.bit.ch12 = v->low_setup.comp_29to14.bit.DACCh22;
|
|
v->read.comp_s.minus.bit.ch12 = v->low_setup.comp_29to14.bit.DACCh23;
|
|
|
|
v->read.comp_s.plus.bit.ch13 = v->low_setup.comp_29to14.bit.DACCh24;
|
|
v->read.comp_s.minus.bit.ch13 = v->low_setup.comp_29to14.bit.DACCh25;
|
|
|
|
v->read.comp_s.plus.bit.ch14 = v->low_setup.comp_29to14.bit.DACCh26;
|
|
v->read.comp_s.minus.bit.ch14 = v->low_setup.comp_29to14.bit.DACCh27;
|
|
|
|
v->read.comp_s.plus.bit.ch15 = v->low_setup.comp_29to14.bit.DACCh28;
|
|
v->read.comp_s.minus.bit.ch15 = v->low_setup.comp_29to14.bit.DACCh29;
|
|
|
|
return 0;
|
|
|
|
}
|
|
///////////////////////////////////////////////
|
|
|
|
|
|
int hwp_write_all_mask(T_hwp *v)
|
|
{
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
WriteMemory(ADR_HWP_DATA_RECEVED_0, v->low_setup.mask_29to14.all);
|
|
WriteMemory(ADR_HWP_DATA_RECEVED_1, v->low_setup.mask_13to0.all);
|
|
|
|
// send cmd to write masks
|
|
v->low_setup.dac_ch.bit.DACChannelNumb = 0;
|
|
v->low_setup.dac_config.bit.DACOrMask = 1;
|
|
v->low_setup.dac_config.bit.ErrReset = 0;
|
|
v->low_setup.dac_config.bit.R_W_Direction = 0;
|
|
v->low_setup.dac_config.bit.DACNumber = 0;
|
|
|
|
v->low_setup.transmitErr = wait_hwp_transfer(v);
|
|
|
|
v->low_setup.dac_config.bit.DACOrMask = 0;
|
|
|
|
if (v->low_setup.transmitErr)
|
|
{
|
|
// îøèáêà ïåðåäà÷è ïî ñåðèàëüíîé øèíå HWP
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
int hwp_write_u_test_dacs(T_hwp *v)
|
|
{
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
v->low_setup.dac_ch.bit.DACChannelNumb = 0;
|
|
v->low_setup.dac_config.bit.DACOrMask = 0;
|
|
v->low_setup.dac_config.bit.ErrReset = 0;
|
|
v->low_setup.dac_config.bit.R_W_Direction = 0;
|
|
v->low_setup.dac_config.bit.DACNumber = 0;
|
|
|
|
//HWP LOAD___________________
|
|
|
|
v->low_setup.dac_ch.bit.DACValue = v->low_setup.DACValues[0];
|
|
v->low_setup.dac_ch.bit.DACChannelNumb = 0;
|
|
WriteMemory(ADR_HWP_SERVICE_1, v->low_setup.dac_ch.all);
|
|
|
|
v->low_setup.transmitErr = wait_hwp_transfer(v);
|
|
|
|
if(v->low_setup.transmitErr)
|
|
{
|
|
v->read.errors.transmit_data = 1;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
///////////////////////////////////////////////
|
|
// return - 0 - all ok
|
|
// 1 - timeout send
|
|
// 2 - error transfer
|
|
///////////////////////////////////////////////
|
|
int wait_hwp_transfer(T_hwp *v)
|
|
{
|
|
unsigned int cnt_wait_tr;
|
|
volatile unsigned int r_hwp;
|
|
int err;
|
|
|
|
err = 1;
|
|
cnt_wait_tr = MAX_WAIT_TRANSMIT_TO_HWP;
|
|
|
|
v->low_setup.dac_config.bit.transfer_finished = 0;
|
|
WriteMemory(ADR_HWP_SERVICE_0, v->low_setup.dac_config.all);
|
|
|
|
DELAY_US(500);
|
|
|
|
// wait finish transmit data
|
|
while(err && (cnt_wait_tr!=0))
|
|
{
|
|
r_hwp = ReadMemory (ADR_HWP_SERVICE_0);
|
|
if (r_hwp & 0x1)
|
|
err = 0;
|
|
cnt_wait_tr--;
|
|
DELAY_US(10);
|
|
}
|
|
|
|
if (err)
|
|
return err;
|
|
|
|
// error transmit?
|
|
r_hwp = ReadMemory (ADR_HWP_SERVICE_0);
|
|
|
|
if (r_hwp & 0x2)
|
|
return 2;
|
|
else
|
|
return 0;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
int hwp_write_all_dacs(T_hwp *v)
|
|
{
|
|
int i = 0, j = 0;
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
v->low_setup.dac_ch.bit.DACChannelNumb = 0;
|
|
v->low_setup.dac_config.bit.DACOrMask = 0;
|
|
v->low_setup.dac_config.bit.ErrReset = 0;
|
|
v->low_setup.dac_config.bit.R_W_Direction = 0;
|
|
v->low_setup.dac_config.bit.DACNumber = 0;
|
|
|
|
//HWP LOAD___________________
|
|
|
|
while(i < 32)
|
|
{
|
|
DELAY_US(200);
|
|
DELAY_US(200);
|
|
|
|
v->low_setup.dac_ch.bit.DACValue = v->low_setup.DACValues[i];
|
|
if ((i%8 == 0) && i!=0)
|
|
{
|
|
j = 0;
|
|
v->low_setup.dac_config.bit.DACNumber++;
|
|
}
|
|
v->low_setup.dac_ch.bit.DACChannelNumb = j;
|
|
WriteMemory(ADR_HWP_SERVICE_1, v->low_setup.dac_ch.all);
|
|
DELAY_US(200);
|
|
DELAY_US(200);
|
|
|
|
v->low_setup.transmitErr = wait_hwp_transfer(v);
|
|
|
|
if(v->low_setup.transmitErr)
|
|
{
|
|
v->read.errors.transmit_data = 0;
|
|
|
|
if (i<16)
|
|
v->low_setup.error_transfer_to_dac_0_1.all |= (1 << i);
|
|
|
|
if (i>=16)
|
|
v->low_setup.error_transfer_to_dac_2_3.all |= (1 << (i-16));
|
|
|
|
i++;
|
|
j++;
|
|
}
|
|
else
|
|
{
|
|
i++;
|
|
j++;
|
|
}
|
|
|
|
}
|
|
|
|
if ( (v->low_setup.error_transfer_to_dac_0_1.all == 0xffff)
|
|
&& (v->low_setup.error_transfer_to_dac_2_3.all == 0xffff))
|
|
{
|
|
v->read.errors.transmit_data = 1;
|
|
// îøèáêà çàãðóçêè âñåõ DACîâ
|
|
// ñêîðåå âñåãî ïëàòû ïðîñòî íåò!
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
return 2;
|
|
}
|
|
|
|
|
|
if (v->low_setup.error_transfer_to_dac_0_1.all || v->low_setup.error_transfer_to_dac_2_3.all)
|
|
{
|
|
v->read.errors.transmit_data = 1;
|
|
// îøèáêà çàãðóçêè îäíîãî èç DACîâ
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
}
|
|
|
|
if (v->read.errors.transmit_data)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
|
|
|
|
int hwp_write_all(T_hwp *v)
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
if (v->status == component_Error || v->status == component_NotFinded)
|
|
return 1;
|
|
|
|
hwp_autospeed_detect(v);
|
|
|
|
if (v->write.flag_detect_HWP_Speed == HWP_AUTOSPEED_FIALED)
|
|
{
|
|
if (v->status==component_NotReady)
|
|
v->status = component_NotFinded;
|
|
else
|
|
v->status = component_Error;
|
|
return 1;
|
|
}
|
|
|
|
if (v->write.HWP_Speed>1) // òóò èëè 0 èëè 1, åñëè 16 òî ýòî îøèáêà ïîñëåäîâàòåëüíîñòè èíèòà
|
|
{
|
|
// îøèáêà ïîñëåäîâàòåëüíîñòè èíèòà, ñêîðåå âñåãî ïëàòà óæå áûëà ïðèîòåñòèðîâàíà ñ àâòîñêðîñòüþ, à ìû åå îïÿòü ñáðîñèëè â àâòîñêîðîñòü.
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
}
|
|
v->low_setup.dac_config.bit.HWP_Speed = v->write.HWP_Speed;
|
|
|
|
convert_values(v);
|
|
convert_masks(v);
|
|
|
|
err = hwp_write_all_dacs(v);
|
|
|
|
if (err == 0)
|
|
err = hwp_write_all_mask(v);
|
|
|
|
|
|
if (err)
|
|
{
|
|
if (v->status==component_NotReady)
|
|
v->status = component_NotFinded;
|
|
else
|
|
v->status = component_Error;
|
|
}
|
|
else
|
|
v->status = component_Ready;
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
void hwp_read_error(T_hwp *v)
|
|
{
|
|
if (v->useit == 0)
|
|
return ;
|
|
|
|
r_controller.errors.all = i_ReadMemory (ADR_ERRORS_TOTAL_INFO);
|
|
v->read.errors.er0_HWP = r_controller.errors.bit.errHWP;
|
|
|
|
|
|
}
|
|
///////////////////////////////////////////////
|
|
|
|
int hwp_reset_error(T_hwp *v)
|
|
{
|
|
int err;
|
|
|
|
if (v->useit == 0)
|
|
return 0;
|
|
|
|
if (v->status == component_NotReady || v->status == component_NotFinded)
|
|
return 1;
|
|
|
|
|
|
if (v->status == component_Error)
|
|
v->status = component_Started;
|
|
clear_cur_stat_hwpbus(&v->status_hwp_bus);
|
|
|
|
|
|
|
|
err = 0;
|
|
v->low_setup.dac_config.bit.ErrReset = 1;
|
|
|
|
v->low_setup.transmitErr = wait_hwp_transfer(v);
|
|
|
|
if (v->low_setup.transmitErr)
|
|
{
|
|
// îøèáêà ïåðåäà÷è ïî ñåðèàëüíîé øèíå HWP
|
|
XERROR_DEBUG_MODE_HWP_NOT_READY;
|
|
err = 1;
|
|
}
|
|
|
|
|
|
DELAY_US(200);
|
|
|
|
v->low_setup.dac_config.bit.ErrReset = 0;
|
|
|
|
return err;
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
|
|
void hwp_store_disable_error(T_hwp *v)
|
|
{
|
|
if (v->useit == 0)
|
|
return ;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
void hwp_restore_enable_error(T_hwp *v)
|
|
{
|
|
if (v->useit == 0)
|
|
return ;
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////
|
|
///////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|