diff --git a/pbv3/AMACv2.cpp b/pbv3/AMACv2.cpp index 2e06722237e5e1e694aaf0c23974705c396f5a5a..ef5526ef758645950320c04964a7ac1b6bc226f7 100644 --- a/pbv3/AMACv2.cpp +++ b/pbv3/AMACv2.cpp @@ -10,9 +10,8 @@ using Clock = std::chrono::steady_clock; typedef std::chrono::time_point<Clock> timep; #include "EndeavourComException.h" -#include "NotSupportedException.h" - #include "Logger.h" +#include "NotSupportedException.h" #define RANGE_MAX_NTC 7 #define RANGE_MIN_NTC 0 @@ -21,496 +20,456 @@ typedef std::chrono::time_point<Clock> timep; #define RANGE_MIN_HVRET 0 AMACv2::AMACv2(unsigned short amacid, std::shared_ptr<EndeavourRaw> raw) - : AMACv2RegMap(), m_amacid(amacid) + : AMACv2RegMap(), + m_amacid(amacid) { - // TODO WARNING: EndeavourCom contains AMACID!!!! - m_endeavour_com = std::make_shared<EndeavourCom>(amacid, raw); - constructor_circuit_versions_n_data(); + // TODO WARNING: EndeavourCom contains AMACID!!!! + m_endeavour_com = std::make_shared<EndeavourCom>(amacid, raw); + constructor_circuit_versions_n_data(); } AMACv2::AMACv2(unsigned short amacid, std::unique_ptr<EndeavourRaw> raw_unique) - : AMACv2RegMap(), m_amacid(amacid) + : AMACv2RegMap(), + m_amacid(amacid) { - m_endeavour_com = std::make_shared<EndeavourCom>(amacid, std::move(raw_unique)); - constructor_circuit_versions_n_data(); + m_endeavour_com = + std::make_shared<EndeavourCom>(amacid, std::move(raw_unique)); + constructor_circuit_versions_n_data(); } AMACv2::AMACv2(unsigned short amacid, std::shared_ptr<EndeavourCom> com) - : AMACv2RegMap(), m_amacid(amacid) + : AMACv2RegMap(), + m_amacid(amacid) { - m_endeavour_com = com; - constructor_circuit_versions_n_data(); + m_endeavour_com = com; + constructor_circuit_versions_n_data(); } -AMACv2::~AMACv2(){} +AMACv2::~AMACv2() {} -void AMACv2::constructor_circuit_versions_n_data(void) -{ - if (m_circuit.size() == 0) - { // fill the default circuit data - m_circuit["ntcpb_B"] = 3900; // "For PB NTCs B is 3900 for 10k parts and 4500 for 1k parts" - m_circuit["ntcpb_R25"] = 10e3; // "some have 1k and some have 10k parts" - //m_circuit["ntcpb_B"] = 4500; - //m_circuit["ntcpb_R25"] = 1e3; - - m_circuit["ntchybrid_R25"] = 10e3; // "yes, hybrid NTCs are all 10k parts" - m_circuit["ntchybrid_B"] = 3435; // "For hybrid NTCs B is 3435" - m_circuit["trace_resistance_ntcpb"] = 0.; // -280.-250.; // - //double Rntc = Rgain*m_NTCpbCal/(NTCvolt-m_NTCpbCal); //-280-250; - m_circuit["trace_resistance_ntcx"] = 0.; - m_circuit["trace_resistance_ntcy"] = 0.; +void AMACv2::constructor_circuit_versions_n_data(void) { + if (m_circuit.size() == 0) { // fill the default circuit data + m_circuit["ntcpb_B"] = 3900; // "For PB NTCs B is 3900 for 10k parts + // and 4500 for 1k parts" + m_circuit["ntcpb_R25"] = + 10e3; // "some have 1k and some have 10k parts" + // m_circuit["ntcpb_B"] = 4500; + // m_circuit["ntcpb_R25"] = 1e3; + + m_circuit["ntchybrid_R25"] = + 10e3; // "yes, hybrid NTCs are all 10k parts" + m_circuit["ntchybrid_B"] = 3435; // "For hybrid NTCs B is 3435" + m_circuit["trace_resistance_ntcpb"] = 0.; // -280.-250.; // + // double Rntc = Rgain*m_NTCpbCal/(NTCvolt-m_NTCpbCal); //-280-250; + m_circuit["trace_resistance_ntcx"] = 0.; + m_circuit["trace_resistance_ntcy"] = 0.; } - //// AMAC-version specific data: AM channels, etc - //// these are for v2 - //m_ch_map[AM::CUR10V ] = 12; - //m_ch_map[AM::CUR10VTPL ] = 12; - //m_ch_map[AM::CUR10VTPH ] = 12; - //m_ch_map[AM::CUR1V ] = 13; - //m_ch_map[AM::CUR1VTPL ] = 13; - //m_ch_map[AM::CUR1VTPH ] = 13; - //detectAndSetVersion(); // nope, first set the ID + //// AMAC-version specific data: AM channels, etc + //// these are for v2 + // m_ch_map[AM::CUR10V ] = 12; + // m_ch_map[AM::CUR10VTPL ] = 12; + // m_ch_map[AM::CUR10VTPH ] = 12; + // m_ch_map[AM::CUR1V ] = 13; + // m_ch_map[AM::CUR1VTPL ] = 13; + // m_ch_map[AM::CUR1VTPH ] = 13; + // detectAndSetVersion(); // nope, first set the ID } const std::map<AMACv2::AM, std::string> AMACv2::Map_AMStr = { - {AM::VDCDC ,"VDCDC" }, - {AM::VDDLR ,"VDDLR" }, - {AM::VDDLRLo ,"VDDLRLo" }, - {AM::VDDLRHi ,"VDDLRHi" }, - {AM::DCDCIN ,"DCDCIN" }, - {AM::VDDREG ,"VDDREG" }, - {AM::VDDBG ,"VDDBG" }, - {AM::AM900BG ,"AM900BG" }, - {AM::AM600BG ,"AM600BG" }, - {AM::CAL ,"CAL" }, - {AM::AMREF ,"AMREF" }, - {AM::CALX ,"CALX" }, - {AM::CALY ,"CALY" }, - {AM::SHUNTX ,"SHUNTX" }, - {AM::SHUNTY ,"SHUNTY" }, - {AM::DCDCADJ ,"DCDCADJ" }, - {AM::CTAT ,"CTAT" }, - {AM::NTCX ,"NTCX" }, - {AM::NTCY ,"NTCY" }, - {AM::NTCPB ,"NTCPB" }, - {AM::HREFX ,"HREFX" }, - {AM::HREFY ,"HREFY" }, - {AM::CUR10V ,"CUR10V" }, - {AM::CUR10VTPL,"CUR10VTPL"}, - {AM::CUR10VTPH,"CUR10VTPH"}, - {AM::CUR1V ,"CUR1V" }, - {AM::CUR1VTPL ,"CUR1VTPL" }, - {AM::CUR1VTPH ,"CUR1VTPH" }, - {AM::HVRET ,"HVRET" }, - {AM::PTAT ,"PTAT" }, + {AM::VDCDC, "VDCDC"}, {AM::VDDLR, "VDDLR"}, + {AM::VDDLRLo, "VDDLRLo"}, {AM::VDDLRHi, "VDDLRHi"}, + {AM::DCDCIN, "DCDCIN"}, {AM::VDDREG, "VDDREG"}, + {AM::VDDBG, "VDDBG"}, {AM::AM900BG, "AM900BG"}, + {AM::AM600BG, "AM600BG"}, {AM::CAL, "CAL"}, + {AM::AMREF, "AMREF"}, {AM::CALX, "CALX"}, + {AM::CALY, "CALY"}, {AM::SHUNTX, "SHUNTX"}, + {AM::SHUNTY, "SHUNTY"}, {AM::DCDCADJ, "DCDCADJ"}, + {AM::CTAT, "CTAT"}, {AM::NTCX, "NTCX"}, + {AM::NTCY, "NTCY"}, {AM::NTCPB, "NTCPB"}, + {AM::HREFX, "HREFX"}, {AM::HREFY, "HREFY"}, + {AM::CUR10V, "CUR10V"}, {AM::CUR10VTPL, "CUR10VTPL"}, + {AM::CUR10VTPH, "CUR10VTPH"}, {AM::CUR1V, "CUR1V"}, + {AM::CUR1VTPL, "CUR1VTPL"}, {AM::CUR1VTPH, "CUR1VTPH"}, + {AM::HVRET, "HVRET"}, {AM::PTAT, "PTAT"}, }; -AMACv2::Version AMACv2::getVersion() -{ - return amac_version; -} +AMACv2::Version AMACv2::getVersion() { return amac_version; } -uint32_t AMACv2::read_version() -{ - uint32_t reg_status = m_endeavour_com->read_reg(m_amacid, AMACv2RegMap::RegisterStatus.getAddress()); - uint32_t version_id = ( (reg_status & 0b11000000) >> 6); - return version_id; +uint32_t AMACv2::read_version() { + uint32_t reg_status = m_endeavour_com->read_reg( + m_amacid, AMACv2RegMap::RegisterStatus.getAddress()); + uint32_t version_id = ((reg_status & 0b11000000) >> 6); + return version_id; } -AMACv2::Version AMACv2::convertVersion(uint32_t version_id) -{ - switch(version_id) { - case 0: - return Version::v2; - - case 1: - return Version::star; +AMACv2::Version AMACv2::convertVersion(uint32_t version_id) { + switch (version_id) { + case 0: + return Version::v2; - default: - amac_version = Version::unknown; - throw NotSupportedException("AMACv2::convertVersion unknown AMAC version: " + std::to_string(version_id)); - } + case 1: + return Version::star; - return Version::unknown; -} - -int AMACv2::detectVersion() -{ - // Get the AMAC version - uint32_t version_id = read_version(); - //setVersion(version_id); - - Version av = convertVersion(version_id); - bool it_is_star_v = (av == Version::star); - bool it_is_v2 = (av == Version::v2); - logger(logDEBUG) << "AMACv2::detectVersion done, it is star=" << it_is_star_v << " | it is v2=" << it_is_v2; + default: + amac_version = Version::unknown; + throw NotSupportedException( + "AMACv2::convertVersion unknown AMAC version: " + + std::to_string(version_id)); + } - return version_id; -} + return Version::unknown; +} + +int AMACv2::detectVersion() { + // Get the AMAC version + uint32_t version_id = read_version(); + // setVersion(version_id); + + Version av = convertVersion(version_id); + bool it_is_star_v = (av == Version::star); + bool it_is_v2 = (av == Version::v2); + logger(logDEBUG) << "AMACv2::detectVersion done, it is star=" + << it_is_star_v << " | it is v2=" << it_is_v2; + + return version_id; +} + +void AMACv2::detectAndSetVersion() { setVersion(detectVersion()); } + +void AMACv2::setVersion(int version_reg_value) { + amac_version = convertVersion(version_reg_value); + setVersion(amac_version); +} + +void AMACv2::setVersion(Version ver) { + //// Get the AMAC version + // uint32_t reg_status = m_endeavour_com->read_reg(m_amacid, + // AMACv2RegMap::RegisterStatus.getAddress()); uint32_t version_id = ( + // (reg_status & 0b11000000) >> 6); + + // switch(version_id) { + switch (ver) { + case Version::v2: + amac_version = Version::v2; + logger(logDEBUG) << "AMAC version: v2"; + m_ch_map[AM::VDCDC] = 0; + m_ch_map[AM::VDDLR] = 1; + m_ch_map[AM::DCDCIN] = 2; + m_ch_map[AM::VDDREG] = 3; + m_ch_map[AM::VDDBG] = 3; + m_ch_map[AM::AM900BG] = 3; + m_ch_map[AM::AM600BG] = 4; + m_ch_map[AM::CAL] = 4; + m_ch_map[AM::AMREF] = 4; + m_ch_map[AM::CALX] = 5; + m_ch_map[AM::CALY] = 5; + m_ch_map[AM::SHUNTX] = 5; + m_ch_map[AM::SHUNTY] = 5; + m_ch_map[AM::DCDCADJ] = 5; + m_ch_map[AM::CTAT] = 6; + m_ch_map[AM::NTCX] = 7; + m_ch_map[AM::NTCY] = 8; + m_ch_map[AM::NTCPB] = 9; + m_ch_map[AM::HREFX] = 10; + m_ch_map[AM::HREFY] = 11; + m_ch_map[AM::CUR10V] = 12; + m_ch_map[AM::CUR10VTPL] = 12; + m_ch_map[AM::CUR10VTPH] = 12; + m_ch_map[AM::CUR1V] = 13; + m_ch_map[AM::CUR1VTPL] = 13; + m_ch_map[AM::CUR1VTPH] = 13; + m_ch_map[AM::HVRET] = 14; + m_ch_map[AM::PTAT] = 15; + m_channelmap = AMAC_INFO::channelmap_v2; + m_muxmap = AMAC_INFO::muxmap_v2; + break; + + case Version::star: + amac_version = Version::star; + logger(logDEBUG) << "AMAC version: star"; + m_ch_map[AM::VDCDC] = 0; + m_ch_map[AM::VDDLR] = 12; + m_ch_map[AM::VDDLRLo] = 12; + m_ch_map[AM::VDDLRHi] = 12; + m_ch_map[AM::DCDCIN] = 1; + m_ch_map[AM::VDDREG] = 13; + m_ch_map[AM::VDDBG] = 15; + m_ch_map[AM::AM900BG] = 12; + m_ch_map[AM::AM600BG] = 12; + m_ch_map[AM::CAL] = 11; + m_ch_map[AM::AMREF] = 13; + m_ch_map[AM::CALX] = 15; + m_ch_map[AM::CALY] = 15; + m_ch_map[AM::SHUNTX] = 15; + m_ch_map[AM::SHUNTY] = 15; + m_ch_map[AM::DCDCADJ] = 13; + m_ch_map[AM::CTAT] = 5; + m_ch_map[AM::NTCX] = 2; + m_ch_map[AM::NTCY] = 3; + m_ch_map[AM::NTCPB] = 4; + m_ch_map[AM::HREFX] = 9; + m_ch_map[AM::HREFY] = 10; + m_ch_map[AM::CUR10V] = 13; + m_ch_map[AM::CUR10VTPL] = 14; + m_ch_map[AM::CUR10VTPH] = 14; + m_ch_map[AM::CUR1V] = 6; + m_ch_map[AM::CUR1VTPL] = 14; + m_ch_map[AM::CUR1VTPH] = 14; + m_ch_map[AM::HVRET] = 7; + m_ch_map[AM::PTAT] = 8; + m_channelmap = AMAC_INFO::channelmap_star; + m_muxmap = AMAC_INFO::muxmap_star; + break; + + default: + amac_version = Version::unknown; + throw NotSupportedException( + "AMACv2::setVersion unknown AMAC version"); + } -void AMACv2::detectAndSetVersion() -{ - setVersion(detectVersion()); -} + // Initiallize AMACv2RegMap + init_regmap(amac_version); -void AMACv2::setVersion(int version_reg_value) -{ - amac_version = convertVersion(version_reg_value); - setVersion(amac_version); + bool it_is_star_v = (amac_version == Version::star); + bool it_is_v2 = (amac_version == Version::v2); + logger(logDEBUG) << "AMACv2::setVersion done (it is star=" << it_is_star_v + << " | it is v2=" << it_is_v2; } -void AMACv2::setVersion(Version ver) -{ - //// Get the AMAC version - //uint32_t reg_status = m_endeavour_com->read_reg(m_amacid, AMACv2RegMap::RegisterStatus.getAddress()); - //uint32_t version_id = ( (reg_status & 0b11000000) >> 6); - - //switch(version_id) { - switch(ver) { - case Version::v2: - amac_version = Version::v2; - logger(logDEBUG) << "AMAC version: v2"; - m_ch_map[AM::VDCDC] = 0; - m_ch_map[AM::VDDLR] = 1; - m_ch_map[AM::DCDCIN] = 2; - m_ch_map[AM::VDDREG] = 3; - m_ch_map[AM::VDDBG] = 3; - m_ch_map[AM::AM900BG] = 3; - m_ch_map[AM::AM600BG] = 4; - m_ch_map[AM::CAL] = 4; - m_ch_map[AM::AMREF] = 4; - m_ch_map[AM::CALX] = 5; - m_ch_map[AM::CALY] = 5; - m_ch_map[AM::SHUNTX] = 5; - m_ch_map[AM::SHUNTY] = 5; - m_ch_map[AM::DCDCADJ] = 5; - m_ch_map[AM::CTAT] = 6; - m_ch_map[AM::NTCX] = 7; - m_ch_map[AM::NTCY] = 8; - m_ch_map[AM::NTCPB] = 9; - m_ch_map[AM::HREFX] = 10; - m_ch_map[AM::HREFY] = 11; - m_ch_map[AM::CUR10V] = 12; - m_ch_map[AM::CUR10VTPL] = 12; - m_ch_map[AM::CUR10VTPH] = 12; - m_ch_map[AM::CUR1V] = 13; - m_ch_map[AM::CUR1VTPL] = 13; - m_ch_map[AM::CUR1VTPH] = 13; - m_ch_map[AM::HVRET] = 14; - m_ch_map[AM::PTAT] = 15; - m_channelmap = AMAC_INFO::channelmap_v2; - m_muxmap = AMAC_INFO::muxmap_v2; - break; - - case Version::star: - amac_version = Version::star; - logger(logDEBUG) << "AMAC version: star"; - m_ch_map[AM::VDCDC] = 0; - m_ch_map[AM::VDDLR] = 12; - m_ch_map[AM::VDDLRLo] = 12; - m_ch_map[AM::VDDLRHi] = 12; - m_ch_map[AM::DCDCIN] = 1; - m_ch_map[AM::VDDREG] = 13; - m_ch_map[AM::VDDBG] = 15; - m_ch_map[AM::AM900BG] = 12; - m_ch_map[AM::AM600BG] = 12; - m_ch_map[AM::CAL] = 11; - m_ch_map[AM::AMREF] = 13; - m_ch_map[AM::CALX] = 15; - m_ch_map[AM::CALY] = 15; - m_ch_map[AM::SHUNTX] = 15; - m_ch_map[AM::SHUNTY] = 15; - m_ch_map[AM::DCDCADJ] = 13; - m_ch_map[AM::CTAT] = 5; - m_ch_map[AM::NTCX] = 2; - m_ch_map[AM::NTCY] = 3; - m_ch_map[AM::NTCPB] = 4; - m_ch_map[AM::HREFX] = 9; - m_ch_map[AM::HREFY] = 10; - m_ch_map[AM::CUR10V] = 13; - m_ch_map[AM::CUR10VTPL] = 14; - m_ch_map[AM::CUR10VTPH] = 14; - m_ch_map[AM::CUR1V] = 6; - m_ch_map[AM::CUR1VTPL] = 14; - m_ch_map[AM::CUR1VTPH] = 14; - m_ch_map[AM::HVRET] = 7; - m_ch_map[AM::PTAT] = 8; - m_channelmap = AMAC_INFO::channelmap_star; - m_muxmap = AMAC_INFO::muxmap_star; - break; - - default: - amac_version = Version::unknown; - throw NotSupportedException("AMACv2::setVersion unknown AMAC version"); - - } - - // Initiallize AMACv2RegMap - init_regmap(amac_version); - - bool it_is_star_v = (amac_version == Version::star); - bool it_is_v2 = (amac_version == Version::v2); - logger(logDEBUG) << "AMACv2::setVersion done (it is star=" << it_is_star_v << " | it is v2=" << it_is_v2; -} - -void AMACv2::init() -{ - // Set AMAC ID - if(!isCommIDSet()) - { - m_endeavour_com->setid(m_amacid, EndeavourCom::REFMODE::IDPads, m_padid); - usleep(10); +void AMACv2::init() { + // Set AMAC ID + if (!isCommIDSet()) { + m_endeavour_com->setid(m_amacid, EndeavourCom::REFMODE::IDPads, + m_padid); + usleep(10); } - // Detect the AMAC version and set the corresponding regmap - detectAndSetVersion(); + // Detect the AMAC version and set the corresponding regmap + detectAndSetVersion(); - // Load current register values - loadRegisters(); + // Load current register values + loadRegisters(); } -void AMACv2::setid(EndeavourCom::REFMODE mode, unsigned int refid) -{ - // Call AMAC SETID - m_endeavour_com->setid(m_amacid, mode, refid); - if (mode == EndeavourCom::REFMODE::IDPads) m_padid = refid; - else m_efuseid = refid; +void AMACv2::setid(EndeavourCom::REFMODE mode, unsigned int refid) { + // Call AMAC SETID + m_endeavour_com->setid(m_amacid, mode, refid); + if (mode == EndeavourCom::REFMODE::IDPads) + m_padid = refid; + else + m_efuseid = refid; } - -void AMACv2::initRegisters() -{ - // Initialize registers with default values - for(AMACv2Field AMACv2RegMap::* field : m_fields) - { - if((this->*field).canBeWrittenField()) - (this->*field).writeDefaultVal(); +void AMACv2::initRegisters() { + // Initialize registers with default values + for (AMACv2Field AMACv2RegMap::*field : m_fields) { + if ((this->*field).canBeWrittenField()) + (this->*field).writeDefaultVal(); } - // Write AMAC registers into the chip - for(const AMACv2Register *reg : getRegisters()) - { - if(reg->isRW()!=RW) - continue; + // Write AMAC registers into the chip + for (const AMACv2Register* reg : getRegisters()) { + if (reg->isRW() != RW) continue; - m_endeavour_com->write_reg(m_amacid, reg->getAddress(), getReg(reg->getAddress())); + m_endeavour_com->write_reg(m_amacid, reg->getAddress(), + getReg(reg->getAddress())); } } -void AMACv2::loadRegisters() -{ - logger(logDEBUG) << "AMACv2::loadRegisters"; - // Load register map with current values - for(const AMACv2Register *reg : getRegisters()) - { - if(reg->isRW()!=RW && reg->isRW()!=RO) - continue; +void AMACv2::loadRegisters() { + logger(logDEBUG) << "AMACv2::loadRegisters"; + // Load register map with current values + for (const AMACv2Register* reg : getRegisters()) { + if (reg->isRW() != RW && reg->isRW() != RO) continue; - uint32_t value = m_endeavour_com->read_reg(m_amacid, reg->getAddress()); - setReg(reg->getAddress(), value); - logger(logDEBUG) << "AMACv2::loadRegisters " << reg->getName() << " " << std::to_string(reg->getAddress()) << " " << value; + uint32_t value = m_endeavour_com->read_reg(m_amacid, reg->getAddress()); + setReg(reg->getAddress(), value); + logger(logDEBUG) << "AMACv2::loadRegisters " << reg->getName() << " " + << std::to_string(reg->getAddress()) << " " << value; } } -bool AMACv2::isCommIDSet() -{ - try - { read_reg(0); } - catch(const EndeavourComException& e) - { return false; } - return true; +bool AMACv2::isCommIDSet() { + try { + read_reg(0); + } catch (const EndeavourComException& e) { + return false; + } + return true; } -void AMACv2::syncReg(AMACv2Field AMACv2RegMap::* ref) -{ - AMACv2Register *reg=(this->*ref).getRegister(); - m_endeavour_com->write_reg(m_amacid, reg->getAddress(), reg->getValue()); +void AMACv2::syncReg(AMACv2Field AMACv2RegMap::*ref) { + AMACv2Register* reg = (this->*ref).getRegister(); + m_endeavour_com->write_reg(m_amacid, reg->getAddress(), reg->getValue()); } -bool AMACv2::circuit_set(std::string param, double value) -{ - logger(logDEBUG) << "AMACv2::circuit_set " << param << " to " << std::to_string(value); - m_circuit[param] = value; +bool AMACv2::circuit_set(std::string param, double value) { + logger(logDEBUG) << "AMACv2::circuit_set " << param << " to " + << std::to_string(value); + m_circuit[param] = value; - return true; + return true; } -double AMACv2::circuit(std::string param) -{ - - if (m_circuit.find(param) == m_circuit.end()) - { - logger(logERROR) << "AMACv2::circuit does not have parameter " << param << " returning 0."; - return 0.; +double AMACv2::circuit(std::string param) { + if (m_circuit.find(param) == m_circuit.end()) { + logger(logERROR) << "AMACv2::circuit does not have parameter " << param + << " returning 0."; + return 0.; } - else - { - double p = m_circuit[param]; - logger(logDEBUG) << "AMACv2::circuit " << param << " = " << std::to_string(p); - return p; + else { + double p = m_circuit[param]; + logger(logDEBUG) << "AMACv2::circuit " << param << " = " + << std::to_string(p); + return p; } } -void AMACv2::wrField(AMACv2Field AMACv2RegMap::* ref, uint32_t data) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - std::chrono::microseconds diagnostic_time; +void AMACv2::wrField(AMACv2Field AMACv2RegMap::*ref, uint32_t data) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + std::chrono::microseconds diagnostic_time; - if(! (this->*ref).isValid() ) return; + if (!(this->*ref).isValid()) return; - AMACv2Register *reg=(this->*ref).getRegister(); - logger(logDEBUG) << "AMACv2::wrField getField " << (this->*ref).getName() << " reg " << std::to_string(reg->getAddress()) << " value " << reg->getValue(); + AMACv2Register* reg = (this->*ref).getRegister(); + logger(logDEBUG) << "AMACv2::wrField getField " << (this->*ref).getName() + << " reg " << std::to_string(reg->getAddress()) + << " value " << reg->getValue(); - setField(ref, data); - logger(logDEBUG) << "AMACv2::wrField setField " << (this->*ref).getName() << " reg value " << reg->getValue(); + setField(ref, data); + logger(logDEBUG) << "AMACv2::wrField setField " << (this->*ref).getName() + << " reg value " << reg->getValue(); - m_endeavour_com->write_reg(m_amacid, reg->getAddress(), reg->getValue()); - //usleep(1e4); // TOCHECK no need for this now? + m_endeavour_com->write_reg(m_amacid, reg->getAddress(), reg->getValue()); + // usleep(1e4); // TOCHECK no need for this now? - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "AMACv2::wrField time " << diagnostic_time.count() << " us"; + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "AMACv2::wrField time " << diagnostic_time.count() + << " us"; } -void AMACv2::wrField(const std::string& fieldName, uint32_t data) -{ - wrField(m_fieldMap[fieldName], data); +void AMACv2::wrField(const std::string& fieldName, uint32_t data) { + wrField(m_fieldMap[fieldName], data); } -uint32_t AMACv2::rdField(AMACv2Field AMACv2RegMap::* ref) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - std::chrono::microseconds diagnostic_time; +uint32_t AMACv2::rdField(AMACv2Field AMACv2RegMap::*ref) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + std::chrono::microseconds diagnostic_time; - if(! (this->*ref).isValid() ) return 0; - unsigned int reg_num = getAddr(ref); - uint32_t ret = m_endeavour_com->read_reg(m_amacid, reg_num); - //setReg(getAddr(ref), ret); - AMACv2Register *reg=(this->*ref).getRegister(); - reg->setValue(ret); - uint32_t field_val = getField(ref); - logger(logDEBUG) << "AMACv2::rdField " << (this->*ref).getName() << " reg_num=" << reg_num << " reg_val=" << ret << " field_val=" << field_val; + if (!(this->*ref).isValid()) return 0; + unsigned int reg_num = getAddr(ref); + uint32_t ret = m_endeavour_com->read_reg(m_amacid, reg_num); + // setReg(getAddr(ref), ret); + AMACv2Register* reg = (this->*ref).getRegister(); + reg->setValue(ret); + uint32_t field_val = getField(ref); + logger(logDEBUG) << "AMACv2::rdField " << (this->*ref).getName() + << " reg_num=" << reg_num << " reg_val=" << ret + << " field_val=" << field_val; - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "AMACv2::rdField time " << diagnostic_time.count() << " us"; + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "AMACv2::rdField time " << diagnostic_time.count() + << " us"; - return field_val; + return field_val; } -uint32_t AMACv2::rdField(const std::string& fieldName) -{ - return rdField(m_fieldMap[fieldName]); +uint32_t AMACv2::rdField(const std::string& fieldName) { + return rdField(m_fieldMap[fieldName]); } -std::vector<std::string> AMACv2::dataFieldNames() -{ - std::vector<std::string> names; - for (auto & field : m_channelmap) - { names.push_back(field.first); } - return names; +std::vector<std::string> AMACv2::dataFieldNames() { + std::vector<std::string> names; + for (auto& field : m_channelmap) { + names.push_back(field.first); + } + return names; } -std::vector<std::string> AMACv2::muxNames() -{ - std::vector<std::string> names; - for (auto & field : m_muxmap) - { names.push_back(field.first); } - return names; +std::vector<std::string> AMACv2::muxNames() { + std::vector<std::string> names; + for (auto& field : m_muxmap) { + names.push_back(field.first); + } + return names; } -uint32_t AMACv2::readDataFieldName(std::string field_name) -{ - if (m_channelmap.find(field_name) == m_channelmap.end()) - { - throw NotSupportedException("AMAC::readDataFieldName unknown channel name " + field_name); +uint32_t AMACv2::readDataFieldName(std::string field_name) { + if (m_channelmap.find(field_name) == m_channelmap.end()) { + throw NotSupportedException( + "AMAC::readDataFieldName unknown channel name " + field_name); } - if (m_muxmap.find(field_name) != m_muxmap.end()) - { - // set all mutexes as needed - for (const auto& a_mux : m_muxmap[field_name]) wrField(a_mux.first, a_mux.second); - //std::this_thread::sleep_for(std::chrono::milliseconds(500)); // TODO: is this needed? + if (m_muxmap.find(field_name) != m_muxmap.end()) { + // set all mutexes as needed + for (const auto& a_mux : m_muxmap[field_name]) + wrField(a_mux.first, a_mux.second); + // std::this_thread::sleep_for(std::chrono::milliseconds(500)); // TODO: + // is this needed? } - // read - return rdField(m_channelmap[field_name]); + // read + return rdField(m_channelmap[field_name]); } -void AMACv2::writeDataFieldName(std::string field_name, uint32_t data) -{ - if (m_channelmap.find(field_name) == m_channelmap.end()) - { - throw NotSupportedException("AMAC::writeDataFieldName unknown channel name " + field_name); +void AMACv2::writeDataFieldName(std::string field_name, uint32_t data) { + if (m_channelmap.find(field_name) == m_channelmap.end()) { + throw NotSupportedException( + "AMAC::writeDataFieldName unknown channel name " + field_name); } - //// TODO: mutex is never needed to _write_ the data, right? - //if (m_muxmap.find(field_name) != m_muxmap.end()) - // { - // // set all mutexes as needed - // for (const auto& a_mux : m_muxmap[field_name]) wrField(a_mux.first, a_mux.second); - // //std::this_thread::sleep_for(std::chrono::milliseconds(500)); // TODO: is this needed? - // } + //// TODO: mutex is never needed to _write_ the data, right? + // if (m_muxmap.find(field_name) != m_muxmap.end()) + // { + // // set all mutexes as needed + // for (const auto& a_mux : m_muxmap[field_name]) wrField(a_mux.first, + // a_mux.second); + // //std::this_thread::sleep_for(std::chrono::milliseconds(500)); // TODO: + // is this needed? + // } - // write the reg - wrField(m_channelmap[field_name], data); - return; + // write the reg + wrField(m_channelmap[field_name], data); + return; } - -uint8_t AMACv2::getFieldWidth(AMACv2Field AMACv2RegMap::* ref) -{ - if(! (this->*ref).isValid() ) return 0; - return (this->*ref).getWidth(); +uint8_t AMACv2::getFieldWidth(AMACv2Field AMACv2RegMap::*ref) { + if (!(this->*ref).isValid()) return 0; + return (this->*ref).getWidth(); } -void AMACv2::write_reg(unsigned int address, unsigned int data) -{ - m_endeavour_com->write_reg(m_amacid, address, data); - setReg(address, data); - usleep(1e4); // TODO: is this sleep for 10ms needed? +void AMACv2::write_reg(unsigned int address, unsigned int data) { + m_endeavour_com->write_reg(m_amacid, address, data); + setReg(address, data); + usleep(1e4); // TODO: is this sleep for 10ms needed? } -unsigned int AMACv2::read_reg(unsigned int address) -{ - uint32_t value = m_endeavour_com->read_reg(m_amacid, address); - setReg(address, value); - return value; +unsigned int AMACv2::read_reg(unsigned int address) { + uint32_t value = m_endeavour_com->read_reg(m_amacid, address); + setReg(address, value); + return value; } -void AMACv2::setPADID(uint8_t padid) -{ - m_padid=padid; -} +void AMACv2::setPADID(uint8_t padid) { m_padid = padid; } -uint8_t AMACv2::getPADID() -{ - return m_padid; -} +uint8_t AMACv2::getPADID() { return m_padid; } -void AMACv2::setEFUSEID(uint8_t efuseid) -{ - m_efuseid=efuseid; -} +void AMACv2::setEFUSEID(uint8_t efuseid) { m_efuseid = efuseid; } -uint8_t AMACv2::getEFUSEID() -{ - return m_efuseid; -} +uint8_t AMACv2::getEFUSEID() { return m_efuseid; } -void AMACv2::setADCslope (double ADCslope) -{ - m_ADCslope=ADCslope; -} +void AMACv2::setADCslope(double ADCslope) { m_ADCslope = ADCslope; } -void AMACv2::setADCoffset(uint8_t ch, uint32_t counts) -{ - if(ch>=16) return; - m_ADCoffset[ch]=counts; +void AMACv2::setADCoffset(uint8_t ch, uint32_t counts) { + if (ch >= 16) return; + m_ADCoffset[ch] = counts; } void AMACv2::enableNTCCalibration() { @@ -529,1133 +488,1181 @@ void AMACv2::disableNTCCalibration() { wrField(&AMACv2RegMap::NTCy0Cal, bit_set); } -void AMACv2::setNTCxCal(double ntccal) -{ m_NTCxCal=ntccal; } +void AMACv2::setNTCxCal(double ntccal) { m_NTCxCal = ntccal; } -void AMACv2::setNTCyCal(double ntccal) -{ m_NTCyCal=ntccal; } +void AMACv2::setNTCyCal(double ntccal) { m_NTCyCal = ntccal; } -void AMACv2::setNTCpbCal(double ntccal) -{ m_NTCpbCal=ntccal; } +void AMACv2::setNTCpbCal(double ntccal) { m_NTCpbCal = ntccal; } -void AMACv2::setPTAT0(double ptat0) -{ m_PTAT0=ptat0; } +void AMACv2::setPTAT0(double ptat0) { m_PTAT0 = ptat0; } -void AMACv2::setCTAT0(uint8_t offset, double ctat0) -{ - if(offset>=16) return; - m_CTAT0[offset]=ctat0; +void AMACv2::setCTAT0(uint8_t offset, double ctat0) { + if (offset >= 16) return; + m_CTAT0[offset] = ctat0; } -void AMACv2::setCur1VOffset (double offset) -{ m_Cur1VOffset = offset; } +void AMACv2::setCur1VOffset(double offset) { m_Cur1VOffset = offset; } -void AMACv2::setCur10VOffset (double offset) -{ m_Cur10VOffset = offset; } +void AMACv2::setCur10VOffset(double offset) { m_Cur10VOffset = offset; } +double AMACv2::calibrateCounts(uint8_t ch, uint32_t counts) { + if (ch >= 16) return 0.; -double AMACv2::calibrateCounts(uint8_t ch, uint32_t counts) -{ - if(ch>=16) return 0.; - - // whatch out `counts - offset` -- counts is uint, the result can be negative, uint will go outside the range - long counts_subtraction = counts; - counts_subtraction -= m_ADCoffset[ch]; - double res = m_ADCslope * counts_subtraction; - - //if (ch==14) - // { - // std::cerr << "AMACv2::calibrateCounts ch=14: counts=" << counts - // << " m_ADCoffset[14]=" << m_ADCoffset[ch] - // << " counts_subtraction=" << counts_subtraction - // << " m_ADCslope=" << m_ADCslope - // << " res=" << res << std::endl; - // } - - // in ITSDAQ: https://gitlab.cern.ch/atlas-itk-strips-daq/itsdaq-sw/-/blob/master/macros/AMACv2_final.cpp#L689 -/* -float CALfactor = 1.0; -if (AMchan == 0) CALfactor = 2; -if (AMchan == 1) CALfactor = 2; -if (AMchan == 2) CALfactor = 15; -if (AMchan == 3 && MUX == 0) CALfactor = 1.5; -*/ + // whatch out `counts - offset` -- counts is uint, the result can be + // negative, uint will go outside the range + long counts_subtraction = counts; + counts_subtraction -= m_ADCoffset[ch]; + double res = m_ADCslope * counts_subtraction; + + // if (ch==14) + // { + // std::cerr << "AMACv2::calibrateCounts ch=14: counts=" << counts + // << " m_ADCoffset[14]=" << m_ADCoffset[ch] + // << " counts_subtraction=" << counts_subtraction + // << " m_ADCslope=" << m_ADCslope + // << " res=" << res << std::endl; + // } + + // in ITSDAQ: + // https://gitlab.cern.ch/atlas-itk-strips-daq/itsdaq-sw/-/blob/master/macros/AMACv2_final.cpp#L689 + /* + float CALfactor = 1.0; + if (AMchan == 0) CALfactor = 2; + if (AMchan == 1) CALfactor = 2; + if (AMchan == 2) CALfactor = 15; + if (AMchan == 3 && MUX == 0) CALfactor = 1.5; + */ - logger(logINFO) << "AMACv2::calibrateCounts ch " << (int)ch << " " << counts << " slope " << m_ADCslope << " offset " << m_ADCoffset[ch] << " -> " << res; - return res; -} + logger(logINFO) << "AMACv2::calibrateCounts ch " << (int)ch << " " << counts + << " slope " << m_ADCslope << " offset " << m_ADCoffset[ch] + << " -> " << res; + return res; +} + +struct MultiCounts AMACv2::readAM_v2(AM am, uint32_t n_reads) { + logger(logDEBUG) << "AMACv2::readAM_v2 AM " << (int)am << " n_reads " + << n_reads; + AMACv2Field AMACv2RegMap::*ch; + + switch (am) { + case AM::VDCDC: + ch = &AMACv2::Ch0Value; + break; + + case AM::VDDLR: + ch = &AMACv2::Ch1Value; + break; + + case AM::DCDCIN: + ch = &AMACv2::Ch2Value; + break; + + case AM::VDDREG: + wrField(&AMACv2::Ch3Mux, 0); + ch = &AMACv2::Ch3Value; + break; + + case AM::VDDBG: + wrField(&AMACv2::Ch3Mux, 1); + ch = &AMACv2::Ch3Value; + break; + + case AM::AM900BG: + wrField(&AMACv2::Ch3Mux, 2); + ch = &AMACv2::Ch3Value; + break; + + case AM::AM600BG: + wrField(&AMACv2::Ch4Mux, 0); + ch = &AMACv2::Ch4Value; + break; + + case AM::CAL: + wrField(&AMACv2::Ch4Mux, 1); + ch = &AMACv2::Ch4Value; + break; + + case AM::AMREF: + wrField(&AMACv2::Ch4Mux, 2); + ch = &AMACv2::Ch4Value; + break; + + case AM::CALX: + wrField(&AMACv2::Ch5Mux, 0); + ch = &AMACv2::Ch5Value; + break; + + case AM::CALY: + wrField(&AMACv2::Ch5Mux, 1); + ch = &AMACv2::Ch5Value; + break; + + case AM::SHUNTX: + wrField(&AMACv2::Ch5Mux, 2); + ch = &AMACv2::Ch5Value; + break; + + case AM::SHUNTY: + wrField(&AMACv2::Ch5Mux, 3); + ch = &AMACv2::Ch5Value; + break; + + case AM::DCDCADJ: + wrField(&AMACv2::Ch5Mux, 4); + ch = &AMACv2::Ch5Value; + break; + + case AM::CTAT: + ch = &AMACv2::Ch6Value; + break; + + case AM::NTCX: + ch = &AMACv2::Ch7Value; + break; + + case AM::NTCY: + ch = &AMACv2::Ch8Value; + break; + + case AM::NTCPB: + ch = &AMACv2::Ch9Value; + break; + + case AM::HREFX: + ch = &AMACv2::Ch10Value; + break; + + case AM::HREFY: + ch = &AMACv2::Ch11Value; + break; + + case AM::CUR10V: + wrField(&AMACv2::Ch12Mux, 0); + ch = &AMACv2::Ch12Value; + break; + + case AM::CUR10VTPL: + wrField(&AMACv2::Ch12Mux, 1); + ch = &AMACv2::Ch12Value; + break; + + case AM::CUR10VTPH: + wrField(&AMACv2::Ch12Mux, 2); + ch = &AMACv2::Ch12Value; + break; + + case AM::CUR1V: + wrField(&AMACv2::Ch13Mux, 0); + ch = &AMACv2::Ch13Value; + break; + + case AM::CUR1VTPL: + wrField(&AMACv2::Ch13Mux, 1); + ch = &AMACv2::Ch13Value; + break; + + case AM::CUR1VTPH: + wrField(&AMACv2::Ch13Mux, 2); + ch = &AMACv2::Ch13Value; + break; + + case AM::HVRET: + ch = &AMACv2::Ch14Value; + break; + + case AM::PTAT: + ch = &AMACv2::Ch15Value; + break; + + default: + return {.multi_counts = 0, .multi_counts_rms = 0}; + } -struct MultiCounts AMACv2::readAM_v2(AM am, uint32_t n_reads) -{ - logger(logDEBUG) << "AMACv2::readAM_v2 AM " << (int)am << " n_reads " << n_reads; - AMACv2Field AMACv2RegMap::* ch; - - switch(am) { - case AM::VDCDC: - ch=&AMACv2::Ch0Value; - break; - - case AM::VDDLR: - ch=&AMACv2::Ch1Value; - break; - - case AM::DCDCIN: - ch=&AMACv2::Ch2Value; - break; - - case AM::VDDREG: - wrField(&AMACv2::Ch3Mux,0); - ch=&AMACv2::Ch3Value; - break; - - case AM::VDDBG: - wrField(&AMACv2::Ch3Mux,1); - ch=&AMACv2::Ch3Value; - break; - - case AM::AM900BG: - wrField(&AMACv2::Ch3Mux,2); - ch=&AMACv2::Ch3Value; - break; - - case AM::AM600BG: - wrField(&AMACv2::Ch4Mux,0); - ch=&AMACv2::Ch4Value; - break; - - case AM::CAL: - wrField(&AMACv2::Ch4Mux,1); - ch=&AMACv2::Ch4Value; - break; - - case AM::AMREF: - wrField(&AMACv2::Ch4Mux,2); - ch=&AMACv2::Ch4Value; - break; - - case AM::CALX: - wrField(&AMACv2::Ch5Mux,0); - ch=&AMACv2::Ch5Value; - break; - - case AM::CALY: - wrField(&AMACv2::Ch5Mux,1); - ch=&AMACv2::Ch5Value; - break; - - case AM::SHUNTX: - wrField(&AMACv2::Ch5Mux,2); - ch=&AMACv2::Ch5Value; - break; - - case AM::SHUNTY: - wrField(&AMACv2::Ch5Mux,3); - ch=&AMACv2::Ch5Value; - break; - - case AM::DCDCADJ: - wrField(&AMACv2::Ch5Mux,4); - ch=&AMACv2::Ch5Value; - break; - - case AM::CTAT: - ch=&AMACv2::Ch6Value; - break; - - case AM::NTCX: - ch=&AMACv2::Ch7Value; - break; - - case AM::NTCY: - ch=&AMACv2::Ch8Value; - break; - - case AM::NTCPB: - ch=&AMACv2::Ch9Value; - break; - - case AM::HREFX: - ch=&AMACv2::Ch10Value; - break; - - case AM::HREFY: - ch=&AMACv2::Ch11Value; - break; - - case AM::CUR10V: - wrField(&AMACv2::Ch12Mux,0); - ch=&AMACv2::Ch12Value; - break; - - case AM::CUR10VTPL: - wrField(&AMACv2::Ch12Mux,1); - ch=&AMACv2::Ch12Value; - break; - - case AM::CUR10VTPH: - wrField(&AMACv2::Ch12Mux,2); - ch=&AMACv2::Ch12Value; - break; - - case AM::CUR1V: - wrField(&AMACv2::Ch13Mux,0); - ch=&AMACv2::Ch13Value; - break; - - case AM::CUR1VTPL: - wrField(&AMACv2::Ch13Mux,1); - ch=&AMACv2::Ch13Value; - break; - - case AM::CUR1VTPH: - wrField(&AMACv2::Ch13Mux,2); - ch=&AMACv2::Ch13Value; - break; - - case AM::HVRET: - ch=&AMACv2::Ch14Value; - break; - - case AM::PTAT: - ch=&AMACv2::Ch15Value; - break; - - default: - return {.multi_counts=0, .multi_counts_rms=0}; - } + /* + uint32_t average_val=0; + std::array<uint32_t, n_reads> vals; + for(uint32_t i=0;i<n_reads;i++) { + std::this_thread::sleep_for(std::chrono::milliseconds(2)); + average_val+=rdField(ch); + } + average_val = average_val/n_reads; -/* - uint32_t average_val=0; - std::array<uint32_t, n_reads> vals; - for(uint32_t i=0;i<n_reads;i++) { - std::this_thread::sleep_for(std::chrono::milliseconds(2)); - average_val+=rdField(ch); - } - average_val = average_val/n_reads; - - return val/n_reads; // it returns the integer part of division -*/ + return val/n_reads; // it returns the integer part of division + */ - return readAM_channelReg(ch, n_reads); + return readAM_channelReg(ch, n_reads); } -struct MultiCounts AMACv2::readAM_channelReg(AMACv2Field AMACv2RegMap::* ch, uint32_t n_reads) -{ - uint32_t val_average=0, val_rms=0; - std::vector<uint32_t> vals; vals.reserve(n_reads); - - for (uint32_t i=0;i<n_reads;i++) { - std::this_thread::sleep_for(std::chrono::milliseconds(2)); - vals.push_back(rdField(ch)); - val_average += vals.back(); - } - val_average = val_average/n_reads; // the integer part of division, i.e. the fraction is truncated - - for (auto& val : vals) { - val_rms += val*val; - } - val_rms = std::sqrt(val_rms); +struct MultiCounts AMACv2::readAM_channelReg(AMACv2Field AMACv2RegMap::*ch, + uint32_t n_reads) { + uint32_t val_average = 0, val_rms = 0; + std::vector<uint32_t> vals; + vals.reserve(n_reads); - logger(logDEBUG) << "AMACv2::readAM_channelReg ch " << (this->*ch).getName() << " val_average=" << val_average << " rms=" << val_rms << " n_reads=" << n_reads; - return {.multi_counts=val_average, .multi_counts_rms=val_rms}; -} - -struct MultiCounts AMACv2::readAM_star(AM am, uint32_t n_reads) -{ - logger(logDEBUG) << "AMACv2::readAM_star AM " << (int)am << " n_reads " << n_reads; - AMACv2Field AMACv2RegMap::* ch; - - switch(am) { - case AM::VDCDC: - ch=&AMACv2::Ch0Value; - break; - - case AM::VDDLR: - wrField(&AMACv2::Ch12Mux,0); - wrField(&AMACv2::Ch12AMux,1); - ch=&AMACv2::Ch12Value; - break; - - case AM::VDDLRLo: - wrField(&AMACv2::Ch12Mux,0); - wrField(&AMACv2::Ch12AMux,0); - ch=&AMACv2::Ch12Value; - break; - - case AM::VDDLRHi: - wrField(&AMACv2::Ch12Mux,0); - wrField(&AMACv2::Ch12AMux,1); - ch=&AMACv2::Ch12Value; - break; - - case AM::DCDCIN: - ch=&AMACv2::Ch1Value; - break; - - case AM::VDDREG: - wrField(&AMACv2::Ch13Mux,1); - ch=&AMACv2::Ch13Value; - break; - - case AM::VDDBG: - wrField(&AMACv2::Ch15Mux,0); - ch=&AMACv2::Ch15Value; - break; - - case AM::AM900BG: - wrField(&AMACv2::Ch12Mux,1); - ch=&AMACv2::Ch12Value; - break; - - case AM::AM600BG: - wrField(&AMACv2::Ch12Mux,2); - ch=&AMACv2::Ch12Value; - break; - - case AM::CAL: - ch=&AMACv2::Ch11Value; - break; - - case AM::AMREF: - wrField(&AMACv2::Ch13Mux,2); - ch=&AMACv2::Ch13Value; - break; - - case AM::CALX: - wrField(&AMACv2::Ch15Mux,1); - ch=&AMACv2::Ch15Value; - break; - - case AM::CALY: - wrField(&AMACv2::Ch15Mux,2); - ch=&AMACv2::Ch15Value; - break; - - case AM::SHUNTX: - wrField(&AMACv2::Ch15Mux,3); - ch=&AMACv2::Ch15Value; - break; - - case AM::SHUNTY: - wrField(&AMACv2::Ch15Mux,4); - ch=&AMACv2::Ch15Value; - break; - - case AM::DCDCADJ: - wrField(&AMACv2::Ch13Mux,4); - ch=&AMACv2::Ch13Value; - break; - - case AM::CTAT: - ch=&AMACv2::Ch5Value; - break; - - case AM::NTCX: - ch=&AMACv2::Ch2Value; - break; - - case AM::NTCY: - ch=&AMACv2::Ch3Value; - break; - - case AM::NTCPB: - ch=&AMACv2::Ch4Value; - break; - - case AM::HREFX: - ch=&AMACv2::Ch9Value; - break; - - case AM::HREFY: - ch=&AMACv2::Ch10Value; - break; - - case AM::CUR10V: - wrField(&AMACv2::Ch13Mux,0); - ch=&AMACv2::Ch13Value; - break; - - case AM::CUR10VTPL: - wrField(&AMACv2::Ch14Mux,1); - ch=&AMACv2::Ch14Value; - break; - - case AM::CUR10VTPH: - wrField(&AMACv2::Ch14Mux,2); - ch=&AMACv2::Ch14Value; - break; - - case AM::CUR1V: - ch=&AMACv2::Ch6Value; - break; - - case AM::CUR1VTPL: - wrField(&AMACv2::Ch14Mux,3); - ch=&AMACv2::Ch14Value; - break; - - case AM::CUR1VTPH: - wrField(&AMACv2::Ch14Mux,4); - ch=&AMACv2::Ch14Value; - break; - - case AM::HVRET: - ch=&AMACv2::Ch7Value; - break; - - case AM::PTAT: - ch=&AMACv2::Ch8Value; - break; - - default: - return {.multi_counts=0, .multi_counts_rms=0}; - } + for (uint32_t i = 0; i < n_reads; i++) { + std::this_thread::sleep_for(std::chrono::milliseconds(2)); + vals.push_back(rdField(ch)); + val_average += vals.back(); + } + val_average = val_average / n_reads; // the integer part of division, i.e. + // the fraction is truncated -/* - uint32_t val=0; - for(uint32_t i=0;i<n_reads;i++) { - std::this_thread::sleep_for(std::chrono::milliseconds(2)); - val+=rdField(ch); // TODO: what avout the average deviation too? - } + for (auto& val : vals) { + val_rms += val * val; + } + val_rms = std::sqrt(val_rms); + + logger(logDEBUG) << "AMACv2::readAM_channelReg ch " << (this->*ch).getName() + << " val_average=" << val_average << " rms=" << val_rms + << " n_reads=" << n_reads; + return {.multi_counts = val_average, .multi_counts_rms = val_rms}; +} + +struct MultiCounts AMACv2::readAM_star(AM am, uint32_t n_reads) { + logger(logDEBUG) << "AMACv2::readAM_star AM " << (int)am << " n_reads " + << n_reads; + AMACv2Field AMACv2RegMap::*ch; + + switch (am) { + case AM::VDCDC: + ch = &AMACv2::Ch0Value; + break; + + case AM::VDDLR: + wrField(&AMACv2::Ch12Mux, 0); + wrField(&AMACv2::Ch12AMux, 1); + ch = &AMACv2::Ch12Value; + break; + + case AM::VDDLRLo: + wrField(&AMACv2::Ch12Mux, 0); + wrField(&AMACv2::Ch12AMux, 0); + ch = &AMACv2::Ch12Value; + break; + + case AM::VDDLRHi: + wrField(&AMACv2::Ch12Mux, 0); + wrField(&AMACv2::Ch12AMux, 1); + ch = &AMACv2::Ch12Value; + break; + + case AM::DCDCIN: + ch = &AMACv2::Ch1Value; + break; + + case AM::VDDREG: + wrField(&AMACv2::Ch13Mux, 1); + ch = &AMACv2::Ch13Value; + break; + + case AM::VDDBG: + wrField(&AMACv2::Ch15Mux, 0); + ch = &AMACv2::Ch15Value; + break; + + case AM::AM900BG: + wrField(&AMACv2::Ch12Mux, 1); + ch = &AMACv2::Ch12Value; + break; + + case AM::AM600BG: + wrField(&AMACv2::Ch12Mux, 2); + ch = &AMACv2::Ch12Value; + break; + + case AM::CAL: + ch = &AMACv2::Ch11Value; + break; + + case AM::AMREF: + wrField(&AMACv2::Ch13Mux, 2); + ch = &AMACv2::Ch13Value; + break; + + case AM::CALX: + wrField(&AMACv2::Ch15Mux, 1); + ch = &AMACv2::Ch15Value; + break; + + case AM::CALY: + wrField(&AMACv2::Ch15Mux, 2); + ch = &AMACv2::Ch15Value; + break; + + case AM::SHUNTX: + wrField(&AMACv2::Ch15Mux, 3); + ch = &AMACv2::Ch15Value; + break; + + case AM::SHUNTY: + wrField(&AMACv2::Ch15Mux, 4); + ch = &AMACv2::Ch15Value; + break; + + case AM::DCDCADJ: + wrField(&AMACv2::Ch13Mux, 4); + ch = &AMACv2::Ch13Value; + break; + + case AM::CTAT: + ch = &AMACv2::Ch5Value; + break; + + case AM::NTCX: + ch = &AMACv2::Ch2Value; + break; + + case AM::NTCY: + ch = &AMACv2::Ch3Value; + break; + + case AM::NTCPB: + ch = &AMACv2::Ch4Value; + break; + + case AM::HREFX: + ch = &AMACv2::Ch9Value; + break; + + case AM::HREFY: + ch = &AMACv2::Ch10Value; + break; + + case AM::CUR10V: + wrField(&AMACv2::Ch13Mux, 0); + ch = &AMACv2::Ch13Value; + break; + + case AM::CUR10VTPL: + wrField(&AMACv2::Ch14Mux, 1); + ch = &AMACv2::Ch14Value; + break; + + case AM::CUR10VTPH: + wrField(&AMACv2::Ch14Mux, 2); + ch = &AMACv2::Ch14Value; + break; + + case AM::CUR1V: + ch = &AMACv2::Ch6Value; + break; + + case AM::CUR1VTPL: + wrField(&AMACv2::Ch14Mux, 3); + ch = &AMACv2::Ch14Value; + break; + + case AM::CUR1VTPH: + wrField(&AMACv2::Ch14Mux, 4); + ch = &AMACv2::Ch14Value; + break; + + case AM::HVRET: + ch = &AMACv2::Ch7Value; + break; + + case AM::PTAT: + ch = &AMACv2::Ch8Value; + break; + + default: + return {.multi_counts = 0, .multi_counts_rms = 0}; + } - return val/n_reads; -*/ + /* + uint32_t val=0; + for(uint32_t i=0;i<n_reads;i++) { + std::this_thread::sleep_for(std::chrono::milliseconds(2)); + val+=rdField(ch); // TODO: what avout the average deviation too? + } + + return val/n_reads; + */ + + return readAM_channelReg(ch, n_reads); +} + +struct MultiCounts AMACv2::readAM(AM am, uint32_t reads) { + logger(logDEBUG) << "AMACv2::readAM"; + + MultiCounts res; + switch (amac_version) { + case Version::v2: + res = readAM_v2(am, reads); + break; + case Version::star: + res = readAM_star(am, reads); + break; + default: + logger(logDEBUG) << "AMACv2::readAM default"; + res = {.multi_counts = 0, .multi_counts_rms = 0}; + } - return readAM_channelReg(ch, n_reads); + logger(logDEBUG) << "AMACv2::readAM multi_counts= " << res.multi_counts + << " rms=" << res.multi_counts_rms; + return res; +} + +AMACv2Field AMACv2RegMap::*AMACv2::convertAMChannelToChValue( + const AM& am_chan) { + switch (amac_version) { + case Version::v2: + // return convertAMChannelToChValue_v2(am_chan); + return AMAC_INFO::am_channels_v2[am_chan]; + case Version::star: + // return convertAMChannelToChValue_star(am_chan); + return AMAC_INFO::am_channels_star[am_chan]; + default: + throw NotSupportedException( + "AMACv2::convertAMChannelToChValue unknown amac version: " + "neither v2 nor star"); + } } -struct MultiCounts AMACv2::readAM(AM am, uint32_t reads) -{ - logger(logDEBUG) << "AMACv2::readAM"; - - MultiCounts res; - switch(amac_version) { - case Version::v2: - res = readAM_v2(am, reads); - break; - case Version::star: - res = readAM_star(am, reads); - break; - default: - logger(logDEBUG) << "AMACv2::readAM default"; - res = {.multi_counts=0, .multi_counts_rms=0}; - } - - logger(logDEBUG) << "AMACv2::readAM multi_counts= " << res.multi_counts << " rms=" << res.multi_counts_rms; - return res; -} - -AMACv2Field AMACv2RegMap::* AMACv2::convertAMChannelToChValue (const AM& am_chan) -{ - switch(amac_version) { - case Version::v2: - //return convertAMChannelToChValue_v2(am_chan); - return AMAC_INFO::am_channels_v2[am_chan]; - case Version::star: - //return convertAMChannelToChValue_star(am_chan); - return AMAC_INFO::am_channels_star[am_chan]; - default: - throw NotSupportedException("AMACv2::convertAMChannelToChValue unknown amac version: neither v2 nor star"); - } -} - -//uint8_t AMACv2::convertAMChannelToInt(AMACv2Field& chan) -uint8_t AMACv2::convertAMChValueToInt(AMACv2Field AMACv2RegMap::* chan) -{ - - if (chan == &AMACv2::Ch0Value) return 0; - else if (chan == &AMACv2::Ch1Value) return 1; - else if (chan == &AMACv2::Ch2Value) return 2; - else if (chan == &AMACv2::Ch3Value) return 3; - else if (chan == &AMACv2::Ch4Value) return 4; - else if (chan == &AMACv2::Ch5Value) return 5; - else if (chan == &AMACv2::Ch6Value) return 6; - else if (chan == &AMACv2::Ch7Value) return 7; - else if (chan == &AMACv2::Ch8Value) return 8; - else if (chan == &AMACv2::Ch9Value) return 9; - else if (chan == &AMACv2::Ch10Value) return 10; - else if (chan == &AMACv2::Ch11Value) return 11; - else if (chan == &AMACv2::Ch12Value) return 12; - else if (chan == &AMACv2::Ch13Value) return 13; - else if (chan == &AMACv2::Ch14Value) return 14; - else if (chan == &AMACv2::Ch15Value) return 15; - else +// uint8_t AMACv2::convertAMChannelToInt(AMACv2Field& chan) +uint8_t AMACv2::convertAMChValueToInt(AMACv2Field AMACv2RegMap::*chan) { + if (chan == &AMACv2::Ch0Value) + return 0; + else if (chan == &AMACv2::Ch1Value) + return 1; + else if (chan == &AMACv2::Ch2Value) + return 2; + else if (chan == &AMACv2::Ch3Value) + return 3; + else if (chan == &AMACv2::Ch4Value) + return 4; + else if (chan == &AMACv2::Ch5Value) + return 5; + else if (chan == &AMACv2::Ch6Value) + return 6; + else if (chan == &AMACv2::Ch7Value) + return 7; + else if (chan == &AMACv2::Ch8Value) + return 8; + else if (chan == &AMACv2::Ch9Value) + return 9; + else if (chan == &AMACv2::Ch10Value) + return 10; + else if (chan == &AMACv2::Ch11Value) + return 11; + else if (chan == &AMACv2::Ch12Value) + return 12; + else if (chan == &AMACv2::Ch13Value) + return 13; + else if (chan == &AMACv2::Ch14Value) + return 14; + else if (chan == &AMACv2::Ch15Value) + return 15; + else { - logger(logERROR) << "AMACv2::convertAMChannelToInt unknown channel chan=" << chan; - throw NotSupportedException("AMACv2::convertAMChannelToInt unknown channel"); + logger(logERROR) + << "AMACv2::convertAMChannelToInt unknown channel chan=" << chan; + throw NotSupportedException( + "AMACv2::convertAMChannelToInt unknown channel"); } - return 255; -} - -std::pair<float, float> AMACv2::readAMChan(AMACv2Field AMACv2RegMap::* field_to_read, - std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> fields_to_write, - unsigned n_reads, - bool reset_mutexes) -{ - // - // return {mean, sigma}; - // - // the semantics of reading AM channnels with mutexed sub-channels - // it is really a little program: write to some fields, read from the target one - - // test that the target is a channel - uint8_t ch_n = convertAMChValueToInt(field_to_read); - if (ch_n == 255) { - logger(logERROR) << "AMACv2::readAMChan given not channel field " << (this->*field_to_read).getName() << " returning {0., 0.}"; - return {-1., -1.}; - } - - // set all mutexes - for (const auto& a_mux : fields_to_write) { - if (a_mux.first != &AMACv2::Ch15Mux && - a_mux.first != &AMACv2::Ch14Mux && - a_mux.first != &AMACv2::Ch13Mux && - a_mux.first != &AMACv2::Ch12Mux && - a_mux.first != &AMACv2::Ch12AMux && - a_mux.first != &AMACv2::Ch5Mux && - a_mux.first != &AMACv2::Ch4Mux && - a_mux.first != &AMACv2::Ch3Mux) { - logger(logERROR) << "AMACv2::readAMChan given not a channel mutex " << (this->*(a_mux.first)).getName() << " skipping"; - continue; + return 255; +} + +std::pair<float, float> AMACv2::readAMChan( + AMACv2Field AMACv2RegMap::*field_to_read, + std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> + fields_to_write, + unsigned n_reads, bool reset_mutexes) { + // + // return {mean, sigma}; + // + // the semantics of reading AM channnels with mutexed sub-channels + // it is really a little program: write to some fields, read from the target + // one + + // test that the target is a channel + uint8_t ch_n = convertAMChValueToInt(field_to_read); + if (ch_n == 255) { + logger(logERROR) << "AMACv2::readAMChan given not channel field " + << (this->*field_to_read).getName() + << " returning {0., 0.}"; + return {-1., -1.}; } - wrField(a_mux.first, a_mux.second); - } + // set all mutexes + for (const auto& a_mux : fields_to_write) { + if (a_mux.first != &AMACv2::Ch15Mux && + a_mux.first != &AMACv2::Ch14Mux && + a_mux.first != &AMACv2::Ch13Mux && + a_mux.first != &AMACv2::Ch12Mux && + a_mux.first != &AMACv2::Ch12AMux && + a_mux.first != &AMACv2::Ch5Mux && a_mux.first != &AMACv2::Ch4Mux && + a_mux.first != &AMACv2::Ch3Mux) { + logger(logERROR) << "AMACv2::readAMChan given not a channel mutex " + << (this->*(a_mux.first)).getName() << " skipping"; + continue; + } + + wrField(a_mux.first, a_mux.second); + } - // read the channel N times, calibrate the counts each time, return mean and deviation - // + // read the channel N times, calibrate the counts each time, return mean and + // deviation + // - float mean = 0; - std::vector<float> readings; + float mean = 0; + std::vector<float> readings; - for (int i=0; i<n_reads; i++) { - uint32_t counts = rdField(field_to_read); - float val = calibrateCounts(ch_n, counts); - readings.push_back(val); - mean += val; - } + for (int i = 0; i < n_reads; i++) { + uint32_t counts = rdField(field_to_read); + float val = calibrateCounts(ch_n, counts); + readings.push_back(val); + mean += val; + } - // ok, let's calc the deviation - mean /= n_reads; - float sigma = 0; - for (auto val : readings) - { sigma += (val - mean) * (val - mean); } - sigma = std::sqrt(sigma / float(n_reads)); + // ok, let's calc the deviation + mean /= n_reads; + float sigma = 0; + for (auto val : readings) { + sigma += (val - mean) * (val - mean); + } + sigma = std::sqrt(sigma / float(n_reads)); - return {mean, sigma}; + return {mean, sigma}; } -//uint32_t AMACv2::readDataField(AMACv2Field AMACv2RegMap::* field_to_read, std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> fields_to_write) { +// uint32_t AMACv2::readDataField(AMACv2Field AMACv2RegMap::* field_to_read, +// std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> fields_to_write) +// { // // the semantics of reading AM channnels with mutexed sub-channels -// // it is really a little program: write to some fields, read from the target one +// // it is really a little program: write to some fields, read from the target +// one // // // set all "mutexes" -// for (const auto& a_mux : fields_to_write) wrField(a_mux.first, a_mux.second); +// for (const auto& a_mux : fields_to_write) wrField(a_mux.first, +// a_mux.second); // // // return the target // return rdField(field_to_read); //} -double AMACv2::getADC(uint8_t ch) -{ - if(ch>=16) return 0.; - uint32_t counts=0; - counts=rdField("Ch"+std::to_string(ch)+"Value"); +double AMACv2::getADC(uint8_t ch) { + if (ch >= 16) return 0.; + uint32_t counts = 0; + counts = rdField("Ch" + std::to_string(ch) + "Value"); - return calibrateCounts(ch, counts); + return calibrateCounts(ch, counts); } -double scale_counts_rms(uint32_t counts, uint32_t counts_rms, double param_to_scale) { - return (param_to_scale/counts) * counts_rms; +double scale_counts_rms(uint32_t counts, uint32_t counts_rms, + double param_to_scale) { + return (param_to_scale / counts) * counts_rms; } -struct VoltMultiCounts AMACv2::vc_getHVret(uint32_t n_reads, bool autorange) // TODO: the calibrations do not have HVret autorange now! +struct VoltMultiCounts AMACv2::vc_getHVret( + uint32_t n_reads, + bool autorange) // TODO: the calibrations do not have HVret autorange now! { - MultiCounts am_res = readAM(AM::HVRET, n_reads); - uint32_t counts = am_res.multi_counts; + MultiCounts am_res = readAM(AM::HVRET, n_reads); + uint32_t counts = am_res.multi_counts; - if (autorange) { - uint32_t range = rdField(&AMACv2RegMap::HVcurGain); - int direction = 0; + if (autorange) { + uint32_t range = rdField(&AMACv2RegMap::HVcurGain); + int direction = 0; - if((counts > 1020)&&(range < RANGE_MAX_HVRET)){ - direction = 1; - } - if((counts < 100)&&(range > RANGE_MIN_HVRET)){ - direction = -1; - } + if ((counts > 1020) && (range < RANGE_MAX_HVRET)) { + direction = 1; + } + if ((counts < 100) && (range > RANGE_MIN_HVRET)) { + direction = -1; + } - if (direction !=0 ) { // change the range - wrField(&AMACv2RegMap::HVcurGain, range+direction); - am_res = readAM(AM::HVRET, n_reads); - counts = am_res.multi_counts; + if (direction != 0) { // change the range + wrField(&AMACv2RegMap::HVcurGain, range + direction); + am_res = readAM(AM::HVRET, n_reads); + counts = am_res.multi_counts; + } } - } - // calibrate the counts for this channel - uint8_t ch = convertAMChValueToInt(convertAMChannelToChValue(AM::HVRET)); // TODO: move this inside an overloaded calibrateCounts ? - double volt = calibrateCounts(ch, counts); + // calibrate the counts for this channel + uint8_t ch = convertAMChValueToInt(convertAMChannelToChValue( + AM::HVRET)); // TODO: move this inside an overloaded calibrateCounts ? + double volt = calibrateCounts(ch, counts); - // just scale the rms - double volt_rms = scale_counts_rms(counts, am_res.multi_counts_rms, volt); + // just scale the rms + double volt_rms = scale_counts_rms(counts, am_res.multi_counts_rms, volt); - logger(logDEBUG) << "AMACv2::vc_getHVret " << m_amacid << " : " - << " ch=" << std::to_string(ch) << " n_reads=" << n_reads << " counts=" << counts - << " volt=" << volt << " rms=" << volt_rms; + logger(logDEBUG) << "AMACv2::vc_getHVret " << m_amacid << " : " + << " ch=" << std::to_string(ch) << " n_reads=" << n_reads + << " counts=" << counts << " volt=" << volt + << " rms=" << volt_rms; - return {.multi_counts=counts, .multi_counts_rms=am_res.multi_counts_rms, .volt=volt, .volt_rms=volt_rms}; + return {.multi_counts = counts, + .multi_counts_rms = am_res.multi_counts_rms, + .volt = volt, + .volt_rms = volt_rms}; } -struct ParamVoltMultiCounts AMACv2::getHVcur(uint32_t n_reads, bool autorange) -{ - struct VoltMultiCounts hv_meas = vc_getHVret(n_reads, autorange); - double hv_ret_mean = hv_meas.volt; - double hv_ret_rms = scale_counts_rms(hv_meas.multi_counts, hv_meas.multi_counts_rms, hv_ret_mean); +struct ParamVoltMultiCounts AMACv2::getHVcur(uint32_t n_reads, bool autorange) { + struct VoltMultiCounts hv_meas = vc_getHVret(n_reads, autorange); + double hv_ret_mean = hv_meas.volt; + double hv_ret_rms = scale_counts_rms(hv_meas.multi_counts, + hv_meas.multi_counts_rms, hv_ret_mean); - // https://gitlab.cern.ch/atlas-itk-strips-daq/itsdaq-sw/-/blob/master/macros/AMACStar.cpp + // https://gitlab.cern.ch/atlas-itk-strips-daq/itsdaq-sw/-/blob/master/macros/AMACStar.cpp - // get switch configuration (reg50 is AMACCnt in Star, it is 56 in v2) - //uint32_t SR=rdField(&AMACv2RegMap::NTCx0SenseRange); - uint8_t hv_gain = rdField(&AMACv2RegMap::HVcurGain); + // get switch configuration (reg50 is AMACCnt in Star, it is 56 in v2) + // uint32_t SR=rdField(&AMACv2RegMap::NTCx0SenseRange); + uint8_t hv_gain = rdField(&AMACv2RegMap::HVcurGain); - int S0 = (hv_gain >> (0+0)) & 1; - int S1 = (hv_gain >> (0+1)) & 1; - int S2 = (hv_gain >> (0+2)) & 1; - int S3 = (hv_gain >> (0+3)) & 1; + int S0 = (hv_gain >> (0 + 0)) & 1; + int S1 = (hv_gain >> (0 + 1)) & 1; + int S2 = (hv_gain >> (0 + 2)) & 1; + int S3 = (hv_gain >> (0 + 3)) & 1; - // resistors - float R = 200e3; - float R0 = 17.5e3; - float R1 = 1.8e3; - float R2 = 300; - float R3 = 120; + // resistors + float R = 200e3; + float R0 = 17.5e3; + float R1 = 1.8e3; + float R2 = 300; + float R3 = 120; - // calculate Rset - float Rset = 1/(1/R+S0/R0+S1/R1+S2/R2+S3/R3); + // calculate Rset + float Rset = 1 / (1 / R + S0 / R0 + S1 / R1 + S2 / R2 + S3 / R3); - double Imean = (hv_ret_mean) / Rset; // let's try 1k scaling (1000*Rset); - // todo: check if an offset is needed here: hv_ret_mean - 100.mV + double Imean = (hv_ret_mean) / Rset; // let's try 1k scaling (1000*Rset); + // todo: check if an offset is needed here: hv_ret_mean - 100.mV - // just scale the rms - double Irms = scale_counts_rms(hv_meas.multi_counts, hv_meas.multi_counts_rms, Imean); + // just scale the rms + double Irms = + scale_counts_rms(hv_meas.multi_counts, hv_meas.multi_counts_rms, Imean); - std::cerr << "AMACv2::getHVcur " - << " gain switches3210=" << std::to_string(S3) << std::to_string(S2) << std::to_string(S1) << std::to_string(S0) - << " counts= " << std::to_string(hv_meas.multi_counts) - << " hv_ret_mean= " << std::to_string(hv_ret_mean) - << " hv_gain=" << std::to_string(hv_gain) - << " Rset= " << std::to_string(Rset) - << " Imean (=hv_ret_mean/Rset) [mA] " << std::to_string(Imean) - << " Irms[mA] " << std::to_string(Irms) - << std::endl; + std::cerr << "AMACv2::getHVcur " + << " gain switches3210=" << std::to_string(S3) + << std::to_string(S2) << std::to_string(S1) << std::to_string(S0) + << " counts= " << std::to_string(hv_meas.multi_counts) + << " hv_ret_mean= " << std::to_string(hv_ret_mean) + << " hv_gain=" << std::to_string(hv_gain) + << " Rset= " << std::to_string(Rset) + << " Imean (=hv_ret_mean/Rset) [mA] " << std::to_string(Imean) + << " Irms[mA] " << std::to_string(Irms) << std::endl; - return {.multi_counts=hv_meas.multi_counts, .multi_counts_rms=hv_meas.multi_counts_rms, - .volt=hv_ret_mean, .volt_rms=hv_ret_rms, - .param=Imean, .param_rms=Irms}; + return {.multi_counts = hv_meas.multi_counts, + .multi_counts_rms = hv_meas.multi_counts_rms, + .volt = hv_ret_mean, + .volt_rms = hv_ret_rms, + .param = Imean, + .param_rms = Irms}; } -double AMACv2::getLinPOLCur() -{ - if( amac_version == Version::v2 ) return 0.0; - uint32_t counts_hi=readAM(AM::VDDLRHi); - uint32_t counts_lo=readAM(AM::VDDLRLo); +double AMACv2::getLinPOLCur() { + if (amac_version == Version::v2) return 0.0; + uint32_t counts_hi = readAM(AM::VDDLRHi); + uint32_t counts_lo = readAM(AM::VDDLRLo); - static const double sf_VDDLR=(14+8.7)/14; - return sf_VDDLR * fabs( calibrateCounts(m_ch_map[AM::VDDLRHi], counts_hi) - calibrateCounts(m_ch_map[AM::VDDLRLo], counts_lo) ); - // TODO: move the m_ch_map[AM::VDDLRHi] inside an overloaded calibrateCounts ? + static const double sf_VDDLR = (14 + 8.7) / 14; + return sf_VDDLR * fabs(calibrateCounts(m_ch_map[AM::VDDLRHi], counts_hi) - + calibrateCounts(m_ch_map[AM::VDDLRLo], counts_lo)); + // TODO: move the m_ch_map[AM::VDDLRHi] inside an overloaded calibrateCounts + // ? } -double AMACv2::getVDDREG() -{ - uint32_t counts=readAM(AM::VDDREG); - return calibrateCounts(m_ch_map[AM::VDDREG], counts)*3/2; +double AMACv2::getVDDREG() { + uint32_t counts = readAM(AM::VDDREG); + return calibrateCounts(m_ch_map[AM::VDDREG], counts) * 3 / 2; } -double AMACv2::getAM600() -{ - uint32_t counts=readAM(AM::AM600BG); - return calibrateCounts(m_ch_map[AM::AM600BG], counts); +double AMACv2::getAM600() { + uint32_t counts = readAM(AM::AM600BG); + return calibrateCounts(m_ch_map[AM::AM600BG], counts); } -double AMACv2::getAM900() -{ - uint32_t counts=readAM(AM::AM900BG); - return calibrateCounts(m_ch_map[AM::AM900BG], counts); +double AMACv2::getAM900() { + uint32_t counts = readAM(AM::AM900BG); + return calibrateCounts(m_ch_map[AM::AM900BG], counts); } - - -struct VoltMultiCounts AMACv2::getNTC_VC(AM am, AMACv2Field AMACv2RegMap::* sense_range, bool autorange) -{ - uint32_t counts = readAM(am); - - if (autorange) { - uint32_t range=rdField(sense_range); - int direction = 0; - - if((counts > 1020)&&(range < RANGE_MAX_NTC)){ - direction = 1; - } - if((counts < 100)&&(range > RANGE_MIN_NTC)){ - direction = -1; +struct VoltMultiCounts AMACv2::getNTC_VC(AM am, + AMACv2Field AMACv2RegMap::*sense_range, + bool autorange) { + uint32_t counts = readAM(am); + + if (autorange) { + uint32_t range = rdField(sense_range); + int direction = 0; + + if ((counts > 1020) && (range < RANGE_MAX_NTC)) { + direction = 1; + } + if ((counts < 100) && (range > RANGE_MIN_NTC)) { + direction = -1; + } + + if (direction != 0) { // change the range + wrField(sense_range, range + direction); + counts = readAM(am); + } } - if (direction !=0 ) { // change the range - wrField(sense_range, range+direction); - counts = readAM(am); - } - } - - auto volts = calibrateCounts(m_ch_map[am], counts); + auto volts = calibrateCounts(m_ch_map[am], counts); - logger(logDEBUG) << "AMACv2::getNTC_VC count " << std::to_string(counts) << " volts " << std::to_string(volts); - return {.multi_counts=counts, .volt=volts}; + logger(logDEBUG) << "AMACv2::getNTC_VC count " << std::to_string(counts) + << " volts " << std::to_string(volts); + return {.multi_counts = counts, .volt = volts}; } -struct VoltMultiCounts AMACv2::getNTCxVC(bool autorange) -{ - struct VoltMultiCounts res = getNTC_VC(AM::NTCX, &AMACv2RegMap::NTCx0SenseRange, autorange); - uint32_t counts = res.multi_counts; - auto volts = calibrateCounts(m_ch_map[AM::NTCX], counts); - logger(logDEBUG) << "AMACv2::getNTCxVC count " << std::to_string(counts) << " volts " << std::to_string(volts); - return {.multi_counts=counts, .volt=volts}; +struct VoltMultiCounts AMACv2::getNTCxVC(bool autorange) { + struct VoltMultiCounts res = + getNTC_VC(AM::NTCX, &AMACv2RegMap::NTCx0SenseRange, autorange); + uint32_t counts = res.multi_counts; + auto volts = calibrateCounts(m_ch_map[AM::NTCX], counts); + logger(logDEBUG) << "AMACv2::getNTCxVC count " << std::to_string(counts) + << " volts " << std::to_string(volts); + return {.multi_counts = counts, .volt = volts}; } -struct VoltMultiCounts AMACv2::getNTCyVC(bool autorange) -{ - struct VoltMultiCounts res = getNTC_VC(AM::NTCY, &AMACv2RegMap::NTCy0SenseRange, autorange); - uint32_t counts = res.multi_counts; - auto volts = calibrateCounts(m_ch_map[AM::NTCY], counts); - logger(logDEBUG) << "AMACv2::getNTCyVC count " << std::to_string(counts) << " volts " << std::to_string(volts); - return {.multi_counts=counts, .volt=volts}; +struct VoltMultiCounts AMACv2::getNTCyVC(bool autorange) { + struct VoltMultiCounts res = + getNTC_VC(AM::NTCY, &AMACv2RegMap::NTCy0SenseRange, autorange); + uint32_t counts = res.multi_counts; + auto volts = calibrateCounts(m_ch_map[AM::NTCY], counts); + logger(logDEBUG) << "AMACv2::getNTCyVC count " << std::to_string(counts) + << " volts " << std::to_string(volts); + return {.multi_counts = counts, .volt = volts}; } -struct VoltMultiCounts AMACv2::getNTCpbVC(bool autorange) -{ - struct VoltMultiCounts res = getNTC_VC(AM::NTCPB, &AMACv2RegMap::NTCpbSenseRange, autorange); - uint32_t counts = res.multi_counts; - auto volts = calibrateCounts(m_ch_map[AM::NTCPB], counts); - logger(logDEBUG) << "AMACv2::getNTCpbVC count " << std::to_string(counts) << " volts " << std::to_string(volts); - return {.multi_counts=counts, .volt=volts}; +struct VoltMultiCounts AMACv2::getNTCpbVC(bool autorange) { + struct VoltMultiCounts res = + getNTC_VC(AM::NTCPB, &AMACv2RegMap::NTCpbSenseRange, autorange); + uint32_t counts = res.multi_counts; + auto volts = calibrateCounts(m_ch_map[AM::NTCPB], counts); + logger(logDEBUG) << "AMACv2::getNTCpbVC count " << std::to_string(counts) + << " volts " << std::to_string(volts); + return {.multi_counts = counts, .volt = volts}; } -double AMACv2::current10V(uint32_t reads) -{ - double volt = getCur10V(reads); - double cur = (volt - m_Cur10VOffset)/10.4/33e-3; - logger(logDEBUG) << "AMACv2::current10V volt " << std::to_string(volt) << " (offset " << std::to_string(m_Cur10VOffset) << ") current " << std::to_string(cur); - return cur; +double AMACv2::current10V(uint32_t reads) { + double volt = getCur10V(reads); + double cur = (volt - m_Cur10VOffset) / 10.4 / 33e-3; + logger(logDEBUG) << "AMACv2::current10V volt " << std::to_string(volt) + << " (offset " << std::to_string(m_Cur10VOffset) + << ") current " << std::to_string(cur); + return cur; } - -double AMACv2::current1V(uint32_t reads) -{ - double volt = getCur1V(reads); - double cur = (volt - m_Cur1VOffset)/30./7.6e-3; - logger(logDEBUG) << "AMACv2::current1V volt " << std::to_string(volt) << " (offset " << std::to_string(m_Cur1VOffset) << ") current " << std::to_string(cur); - return cur; +double AMACv2::current1V(uint32_t reads) { + double volt = getCur1V(reads); + double cur = (volt - m_Cur1VOffset) / 30. / 7.6e-3; + logger(logDEBUG) << "AMACv2::current1V volt " << std::to_string(volt) + << " (offset " << std::to_string(m_Cur1VOffset) + << ") current " << std::to_string(cur); + return cur; } -struct VoltMultiCounts AMACv2::vc_getCur10V(uint32_t reads) -{ - struct MultiCounts res = readAM(AM::CUR10V, reads); - uint32_t multi_counts = res.multi_counts; - double volt = calibrateCounts(m_ch_map[AM::CUR10V], multi_counts); - logger(logDEBUG) << "AMACv2::vc_getCur10V count " << std::to_string(multi_counts) << " volt " << std::to_string(volt); - return {.multi_counts=multi_counts, .volt=volt}; +struct VoltMultiCounts AMACv2::vc_getCur10V(uint32_t reads) { + struct MultiCounts res = readAM(AM::CUR10V, reads); + uint32_t multi_counts = res.multi_counts; + double volt = calibrateCounts(m_ch_map[AM::CUR10V], multi_counts); + logger(logDEBUG) << "AMACv2::vc_getCur10V count " + << std::to_string(multi_counts) << " volt " + << std::to_string(volt); + return {.multi_counts = multi_counts, .volt = volt}; } - -double AMACv2::getCur10VTPL(uint32_t reads) -{ - MultiCounts res = readAM(AM::CUR10VTPL, reads); - uint32_t counts = res.multi_counts; - return calibrateCounts(m_ch_map[AM::CUR10VTPL], counts); +double AMACv2::getCur10VTPL(uint32_t reads) { + MultiCounts res = readAM(AM::CUR10VTPL, reads); + uint32_t counts = res.multi_counts; + return calibrateCounts(m_ch_map[AM::CUR10VTPL], counts); } -double AMACv2::getCur10VTPH(uint32_t reads) -{ - MultiCounts res = readAM(AM::CUR10VTPH, reads); - uint32_t counts = res.multi_counts; - return calibrateCounts(m_ch_map[AM::CUR10VTPH], counts); +double AMACv2::getCur10VTPH(uint32_t reads) { + MultiCounts res = readAM(AM::CUR10VTPH, reads); + uint32_t counts = res.multi_counts; + return calibrateCounts(m_ch_map[AM::CUR10VTPH], counts); } - -struct VoltMultiCounts AMACv2::vc_getCur1V(uint32_t reads) -{ - MultiCounts res = readAM(AM::CUR1V, reads); - uint32_t counts = res.multi_counts; - double volt = calibrateCounts(m_ch_map[AM::CUR1V], counts); - logger(logDEBUG) << "AMACv2::vc_getCur1V count " << std::to_string(counts) << " volt " << std::to_string(volt); - return {.multi_counts=counts, .volt=volt}; +struct VoltMultiCounts AMACv2::vc_getCur1V(uint32_t reads) { + MultiCounts res = readAM(AM::CUR1V, reads); + uint32_t counts = res.multi_counts; + double volt = calibrateCounts(m_ch_map[AM::CUR1V], counts); + logger(logDEBUG) << "AMACv2::vc_getCur1V count " << std::to_string(counts) + << " volt " << std::to_string(volt); + return {.multi_counts = counts, .volt = volt}; } -double AMACv2::getCur1VTPL(uint32_t reads) -{ - MultiCounts res = readAM(AM::CUR1VTPL, reads); - uint32_t counts = res.multi_counts; - return calibrateCounts(m_ch_map[AM::CUR1VTPL], counts); +double AMACv2::getCur1VTPL(uint32_t reads) { + MultiCounts res = readAM(AM::CUR1VTPL, reads); + uint32_t counts = res.multi_counts; + return calibrateCounts(m_ch_map[AM::CUR1VTPL], counts); } -double AMACv2::getCur1VTPH(uint32_t reads) -{ - MultiCounts res = readAM(AM::CUR1VTPH, reads); - uint32_t counts = res.multi_counts; - return calibrateCounts(m_ch_map[AM::CUR1VTPH], counts); +double AMACv2::getCur1VTPH(uint32_t reads) { + MultiCounts res = readAM(AM::CUR1VTPH, reads); + uint32_t counts = res.multi_counts; + return calibrateCounts(m_ch_map[AM::CUR1VTPH], counts); } -double AMACv2::convertCur10V(uint32_t Cur10V) -{ - return (calibrateCounts(m_ch_map[AM::CUR10V], Cur10V)-m_Cur10VOffset)/10.4/33e-3; +double AMACv2::convertCur10V(uint32_t Cur10V) { + return (calibrateCounts(m_ch_map[AM::CUR10V], Cur10V) - m_Cur10VOffset) / + 10.4 / 33e-3; } -double AMACv2::convertCur1V(uint32_t Cur1V) -{ - return (calibrateCounts(m_ch_map[AM::CUR1V], Cur1V )-m_Cur1VOffset )/30 /7.6e-3; +double AMACv2::convertCur1V(uint32_t Cur1V) { + return (calibrateCounts(m_ch_map[AM::CUR1V], Cur1V) - m_Cur1VOffset) / 30 / + 7.6e-3; } /* double AMACv2::convertCur10V(uint32_t Cur10V) { - return (calibrateCounts(m_ch_map[AM::CUR10V], Cur10V) - m_Cur10VOffset) / 10.4 / 33e-3; + return (calibrateCounts(m_ch_map[AM::CUR10V], Cur10V) - m_Cur10VOffset) +/ 10.4 / 33e-3; } double AMACv2::convertCur1V(uint32_t Cur1V) { - return (calibrateCounts(m_ch_map[AM::CUR1V], Cur1V) - m_Cur1VOffset) / 30 / 7.6e-3; + return (calibrateCounts(m_ch_map[AM::CUR1V], Cur1V) - m_Cur1VOffset) / 30 +/ 7.6e-3; } */ -double AMACv2::convertVDCDC(uint32_t VDCDC) -{ - return 2*calibrateCounts(0, VDCDC)/1e3; +double AMACv2::convertVDCDC(uint32_t VDCDC) { + return 2 * calibrateCounts(0, VDCDC) / 1e3; } +double AMACv2::temperatureNTC(double NTCvolt, double NTCcal, + uint32_t sense_range, double trace_resistance, + double B, double R25) { + // Determine the settings + bool NTCS0 = (sense_range >> 0) & 1; + bool NTCS1 = (sense_range >> 1) & 1; + bool NTCS2 = (sense_range >> 2) & 1; -double AMACv2::temperatureNTC(double NTCvolt, double NTCcal, uint32_t sense_range, double trace_resistance, double B, double R25) -{ - // Determine the settings - bool NTCS0=(sense_range>>0)&1; - bool NTCS1=(sense_range>>1)&1; - bool NTCS2=(sense_range>>2)&1; - - // Readings - //double NTCvolt=getNTCpb(); + // Readings + // double NTCvolt=getNTCpb(); - // AMACv2 gain resistors - static const double R=200e3; - static const double R0=133e3; - static const double R1=50e3; - static const double R2=22.22e3; + // AMACv2 gain resistors + static const double R = 200e3; + static const double R0 = 133e3; + static const double R1 = 50e3; + static const double R2 = 22.22e3; - double Rgain=1/(1/R+NTCS0/R0+NTCS1/R1+NTCS2/R2); + double Rgain = 1 / (1 / R + NTCS0 / R0 + NTCS1 / R1 + NTCS2 / R2); - // NTC resistance - //double Rntc = Rgain*NTCcal/(NTCvolt-NTCcal) -280. -200. -50.; // the resistors on the contacts to the NTC - double Acl = NTCvolt / NTCcal; - double Rntc = Rgain / (Acl - 1.); + // NTC resistance + // double Rntc = Rgain*NTCcal/(NTCvolt-NTCcal) -280. -200. -50.; // the + // resistors on the contacts to the NTC + double Acl = NTCvolt / NTCcal; + double Rntc = Rgain / (Acl - 1.); - //Rntc -= m_circuit_trace_resistance_ntcpb; - Rntc -= trace_resistance; + // Rntc -= m_circuit_trace_resistance_ntcpb; + Rntc -= trace_resistance; - // And finally calculate temperature - //static const double B=3900; - //static const double B = m_circuit_ntcpb_B; - //double B = circuit("ntcpb_B"); - //static const double R25=10e3; - //static const double R25 = m_circuit_ntcpb_R25; - //double R25 = circuit("ntcpb_R25"); + // And finally calculate temperature + // static const double B=3900; + // static const double B = m_circuit_ntcpb_B; + // double B = circuit("ntcpb_B"); + // static const double R25=10e3; + // static const double R25 = m_circuit_ntcpb_R25; + // double R25 = circuit("ntcpb_R25"); - static const double T0=273.15; // must be 273.15 ? - static const double T25=T0+25; - double temp=1./(log(Rntc/R25)/B+1/T25)-T0; + static const double T0 = 273.15; // must be 273.15 ? + static const double T25 = T0 + 25; + double temp = 1. / (log(Rntc / R25) / B + 1 / T25) - T0; - logger(logDEBUG) << "AMACv2::temperatureNTC " << m_amacid << " : " - << " gain=" << Rgain - << " volt=" << NTCvolt << " cal=" << NTCcal - << " Rntc=" << Rntc - << " temp=" << temp; + logger(logDEBUG) << "AMACv2::temperatureNTC " << m_amacid << " : " + << " gain=" << Rgain << " volt=" << NTCvolt + << " cal=" << NTCcal << " Rntc=" << Rntc + << " temp=" << temp; - return temp; + return temp; } +struct ParamVoltMultiCounts AMACv2::temperatureXnV(bool autorange) { + // Readings + struct VoltMultiCounts meas = getNTCxVC(autorange); + double NTCvolt = meas.volt; -struct ParamVoltMultiCounts AMACv2::temperatureXnV(bool autorange) -{ - // Readings - struct VoltMultiCounts meas = getNTCxVC(autorange); - double NTCvolt = meas.volt; - - // Determine the settings - uint32_t SR=rdField(&AMACv2RegMap::NTCx0SenseRange); + // Determine the settings + uint32_t SR = rdField(&AMACv2RegMap::NTCx0SenseRange); - double temp = temperatureNTC(NTCvolt, m_NTCxCal, SR, - circuit("trace_resistance_ntcx"), circuit("ntchybrid_B"), circuit("ntchybrid_R25")); + double temp = + temperatureNTC(NTCvolt, m_NTCxCal, SR, circuit("trace_resistance_ntcx"), + circuit("ntchybrid_B"), circuit("ntchybrid_R25")); - logger(logDEBUG) << "AMACv2::temperatureXnV counts=" << meas.multi_counts << " volt=" << NTCvolt << " temp=" << temp; - return {.multi_counts=meas.multi_counts, .volt=NTCvolt, .param=temp}; + logger(logDEBUG) << "AMACv2::temperatureXnV counts=" << meas.multi_counts + << " volt=" << NTCvolt << " temp=" << temp; + return {.multi_counts = meas.multi_counts, .volt = NTCvolt, .param = temp}; } -struct ParamVoltMultiCounts AMACv2::temperatureYnV(bool autorange) -{ - // Readings - struct VoltMultiCounts meas = getNTCyVC(autorange); - double NTCvolt = meas.volt; +struct ParamVoltMultiCounts AMACv2::temperatureYnV(bool autorange) { + // Readings + struct VoltMultiCounts meas = getNTCyVC(autorange); + double NTCvolt = meas.volt; - // Determine the settings - uint32_t SR=rdField(&AMACv2RegMap::NTCy0SenseRange); + // Determine the settings + uint32_t SR = rdField(&AMACv2RegMap::NTCy0SenseRange); - double temp = temperatureNTC(NTCvolt, m_NTCyCal, SR, - circuit("trace_resistance_ntcy"), circuit("ntchybrid_B"), circuit("ntchybrid_R25")); + double temp = + temperatureNTC(NTCvolt, m_NTCyCal, SR, circuit("trace_resistance_ntcy"), + circuit("ntchybrid_B"), circuit("ntchybrid_R25")); - logger(logDEBUG) << "AMACv2::temperatureYnV counts=" << meas.multi_counts << " volt=" << NTCvolt << " temp=" << temp; - return {.multi_counts=meas.multi_counts, .volt=NTCvolt, .param=temp}; + logger(logDEBUG) << "AMACv2::temperatureYnV counts=" << meas.multi_counts + << " volt=" << NTCvolt << " temp=" << temp; + return {.multi_counts = meas.multi_counts, .volt = NTCvolt, .param = temp}; } -struct ParamVoltMultiCounts AMACv2::temperaturePBnV(bool autorange) -{ - // Readings - struct VoltMultiCounts meas = getNTCpbVC(autorange); - double NTCvolt = meas.volt; +struct ParamVoltMultiCounts AMACv2::temperaturePBnV(bool autorange) { + // Readings + struct VoltMultiCounts meas = getNTCpbVC(autorange); + double NTCvolt = meas.volt; - // Determine the settings - uint32_t SR=rdField(&AMACv2RegMap::NTCpbSenseRange); + // Determine the settings + uint32_t SR = rdField(&AMACv2RegMap::NTCpbSenseRange); - double temp = temperatureNTC(NTCvolt, m_NTCpbCal, SR, - circuit("trace_resistance_ntcpb"), circuit("ntcpb_B"), circuit("ntcpb_R25")); + double temp = temperatureNTC(NTCvolt, m_NTCpbCal, SR, + circuit("trace_resistance_ntcpb"), + circuit("ntcpb_B"), circuit("ntcpb_R25")); - logger(logDEBUG) << "AMACv2::temperaturePBnV counts=" << meas.multi_counts << " volt=" << NTCvolt << " temp=" << temp; - return {.multi_counts=meas.multi_counts, .volt=NTCvolt, .param=temp}; + logger(logDEBUG) << "AMACv2::temperaturePBnV counts=" << meas.multi_counts + << " volt=" << NTCvolt << " temp=" << temp; + return {.multi_counts = meas.multi_counts, .volt = NTCvolt, .param = temp}; } -struct VoltMultiCounts AMACv2::getPTAT_vc() -{ - uint32_t counts=readAM(AM::PTAT); - //return {.multi_counts=counts, .volt=calibrateCounts(m_ch_map[AM::PTAT], counts)}; - double ptat_voltage_divider_factor = 2.; // the 1/2 voltage divider on the powerboard in front of the AMAC ADC PTAT pin - return {.multi_counts=counts, .volt=calibrateCounts(m_ch_map[AM::PTAT], counts) * ptat_voltage_divider_factor}; +struct VoltMultiCounts AMACv2::getPTAT_vc() { + uint32_t counts = readAM(AM::PTAT); + // return {.multi_counts=counts, .volt=calibrateCounts(m_ch_map[AM::PTAT], + // counts)}; + double ptat_voltage_divider_factor = + 2.; // the 1/2 voltage divider on the powerboard in front of the AMAC + // ADC PTAT pin + return {.multi_counts = counts, + .volt = calibrateCounts(m_ch_map[AM::PTAT], counts) * + ptat_voltage_divider_factor}; } -double AMACv2::getCTAT() -{ - uint32_t counts=readAM(AM::CTAT); - return calibrateCounts(m_ch_map[AM::CTAT], counts); +double AMACv2::getCTAT() { + uint32_t counts = readAM(AM::CTAT); + return calibrateCounts(m_ch_map[AM::CTAT], counts); } -struct ParamVoltMultiCounts AMACv2::temperaturePTAT_pvc() -{ - //return (getPTAT()-m_PTAT0)/8.5; // 8.5 -- FEAST datasheet - // (getPTAT()-m_PTAT0)/4.85; // and now it's 4.85 -- bPOL datasheet - struct VoltMultiCounts meas = getPTAT_vc(); - // the PTAT voltage range is fitted into the AM 1V range with a 1/2 voltage divider - // made with 2 100K resistors - //double ptat_voltage_divider_factor = 2.; // TODO this voltage correction must be applied to the voltage measurement, right? - double ptat_voltage_divider_factor = 1.; // TODO this voltage correction must be applied to the voltage measurement, right? - double ptat = ptat_voltage_divider_factor * (meas.volt - m_PTAT0)/4.85; - return {.multi_counts=meas.multi_counts, .volt=meas.volt, .param=ptat}; -} - -double AMACv2::temperatureCTAT() -{ - uint32_t CTAToffset=rdField(&AMACv2RegMap::CTAToffset); - return (getCTAT()-m_CTAT0[CTAToffset])/(-1.5); +struct ParamVoltMultiCounts AMACv2::temperaturePTAT_pvc() { + // return (getPTAT()-m_PTAT0)/8.5; // 8.5 -- FEAST datasheet + // (getPTAT()-m_PTAT0)/4.85; // and now it's 4.85 -- bPOL datasheet + struct VoltMultiCounts meas = getPTAT_vc(); + // the PTAT voltage range is fitted into the AM 1V range with a 1/2 voltage + // divider made with 2 100K resistors + // double ptat_voltage_divider_factor = 2.; // TODO this voltage correction + // must be applied to the voltage measurement, right? + double ptat_voltage_divider_factor = + 1.; // TODO this voltage correction must be applied to the voltage + // measurement, right? + double ptat = ptat_voltage_divider_factor * (meas.volt - m_PTAT0) / 4.85; + return { + .multi_counts = meas.multi_counts, .volt = meas.volt, .param = ptat}; } -uint32_t AMACv2::readEFuse() -{ - wrField(&AMACv2RegMap::FlagResetF, 1); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - return rdField(&AMACv2RegMap::SerNum); +double AMACv2::temperatureCTAT() { + uint32_t CTAToffset = rdField(&AMACv2RegMap::CTAToffset); + return (getCTAT() - m_CTAT0[CTAToffset]) / (-1.5); +} + +uint32_t AMACv2::readEFuse() { + wrField(&AMACv2RegMap::FlagResetF, 1); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + return rdField(&AMACv2RegMap::SerNum); } //------ Channel and Mux Maps // originally these are just shortcuts // but, considering PP2, these serve as maps between AMAC pins and board layout -std::map<std::string, AMACv2Field AMACv2RegMap::*> AMAC_INFO::channelmap_v2={ - {"DCDCen" ,&AMACv2::DCDCen}, - {"DCDCenC" ,&AMACv2::DCDCenC}, - {"VDCDC" ,&AMACv2::Ch0Value}, - {"VDDLR" ,&AMACv2::Ch1Value}, - {"DCDCIN" ,&AMACv2::Ch2Value}, - {"VDDREG" ,&AMACv2::Ch3Value}, - {"sysBG" ,&AMACv2::Ch3Value}, // TODO == VDDBG? - {"AM900BG" ,&AMACv2::Ch3Value}, - {"AM600BG" ,&AMACv2::Ch4Value}, - {"CAL" ,&AMACv2::Ch4Value}, - {"AMREF" ,&AMACv2::Ch4Value}, - {"CALX" ,&AMACv2::Ch5Value}, - {"CALY" ,&AMACv2::Ch5Value}, - {"SHUNTX" ,&AMACv2::Ch5Value}, - {"SHUNTY" ,&AMACv2::Ch5Value}, - {"HGND" ,&AMACv2::Ch5Value}, - {"DIETEMP" ,&AMACv2::Ch6Value}, - {"CTAT" ,&AMACv2::Ch6Value}, - {"PTAT" ,&AMACv2::Ch15Value}, - {"NTCX" ,&AMACv2::Ch7Value}, - {"NTCY" ,&AMACv2::Ch8Value}, - {"NTCPB" ,&AMACv2::Ch9Value}, - {"HREFX" ,&AMACv2::Ch10Value}, - {"HREFY" ,&AMACv2::Ch11Value}, - {"HVret" ,&AMACv2::Ch14Value}, - {"CUR1V" ,&AMACv2::Ch13Value}, - {"CUR1VTPL" ,&AMACv2::Ch13Value}, - {"CUR1VTPH" ,&AMACv2::Ch13Value}, - {"CUR10V" ,&AMACv2::Ch12Value}, - {"CUR10VTPL" ,&AMACv2::Ch12Value}, - {"CUR10VTPH" ,&AMACv2::Ch12Value}, - - { "CntSetHV0en" , &AMACv2::CntSetHV0en}, - { "CntSetCHV0en" , &AMACv2::CntSetCHV0en}, - { "CntSetHV1en" , &AMACv2::CntSetHV1en}, - { "CntSetCHV1en" , &AMACv2::CntSetCHV1en}, - { "CntSetHV2en" , &AMACv2::CntSetHV2en}, - { "CntSetCHV2en" , &AMACv2::CntSetCHV2en}, - { "CntSetHV3en" , &AMACv2::CntSetHV3en}, - { "CntSetCHV3en" , &AMACv2::CntSetCHV3en}, - }; - -std::map<std::string, std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> > AMAC_INFO::muxmap_v2={ - {"VDDREG" , {{&AMACv2::Ch3Mux ,0}}}, - {"sysBG" , {{&AMACv2::Ch3Mux ,1}}}, // TODO: same as VDDBG? - {"AM900BG" , {{&AMACv2::Ch3Mux ,2}}}, - {"AM600BG" , {{&AMACv2::Ch4Mux ,0}}}, - {"CAL" , {{&AMACv2::Ch4Mux ,1}}}, - {"AMREF" , {{&AMACv2::Ch4Mux ,2}}}, - {"CALX" , {{&AMACv2::Ch5Mux ,0}}}, - {"CALY" , {{&AMACv2::Ch5Mux ,1}}}, - {"SHUNTX" , {{&AMACv2::Ch5Mux ,2}}}, - {"SHUNTY" , {{&AMACv2::Ch5Mux ,3}}}, - {"HGND" , {{&AMACv2::Ch5Mux ,4}}}, - {"CUR10V" , {{&AMACv2::Ch12Mux,0}}}, - {"CUR10VTPL" , {{&AMACv2::Ch12Mux,1}}}, - {"CUR10VTPH" , {{&AMACv2::Ch12Mux,2}}}, - {"CUR1V" , {{&AMACv2::Ch13Mux,0}}}, - {"CUR1VTPL" , {{&AMACv2::Ch13Mux,1}}}, - {"CUR1VTPH" , {{&AMACv2::Ch13Mux,2}}} - }; - -std::map<std::string, AMACv2Field AMACv2RegMap::*> AMAC_INFO::channelmap_star={ - {"DCDCen" , &AMACv2::DCDCen}, // no DCDCenC - {"VDCDC" , &AMACv2::Ch0Value}, - {"VDDLR" , &AMACv2::Ch12Value}, - {"VDDLRLo" , &AMACv2::Ch12Value}, - {"VDDLRHi" , &AMACv2::Ch12Value}, // == VDDLR ? - {"DCDCIN" , &AMACv2::Ch1Value}, - {"VDDREG" , &AMACv2::Ch13Value}, - {"VDDBG" , &AMACv2::Ch15Value}, - {"AM900BG" , &AMACv2::Ch12Value}, - {"AM600BG" , &AMACv2::Ch12Value}, - {"CAL" , &AMACv2::Ch11Value}, - {"CTAT" , &AMACv2::Ch5Value}, - {"PTAT" , &AMACv2::Ch8Value}, - {"NTCX" , &AMACv2::Ch2Value}, - {"NTCY" , &AMACv2::Ch3Value}, - {"NTCPB" , &AMACv2::Ch4Value}, - {"HREFX" , &AMACv2::Ch9Value}, - {"HREFY" , &AMACv2::Ch10Value}, - {"HVret" , &AMACv2::Ch7Value}, - {"CUR1V" , &AMACv2::Ch6Value}, - {"CUR1VTPL" , &AMACv2::Ch14Value}, - {"CUR1VTPH" , &AMACv2::Ch14Value}, - - {"AMREF" , &AMACv2::Ch13Value}, - {"CALX" , &AMACv2::Ch15Value}, - {"CALY" , &AMACv2::Ch15Value}, - {"SHUNTX" , &AMACv2::Ch15Value}, - {"SHUNTY" , &AMACv2::Ch15Value}, - {"DCDCADJ" , &AMACv2::Ch13Value}, - {"CUR10V" , &AMACv2::Ch13Value}, - {"CUR10VTPL" , &AMACv2::Ch14Value}, - {"CUR10VTPH" , &AMACv2::Ch14Value}, - - {"CntSetHV0en" ,&AMACv2::CntSetHV0en}, // just control regs - //{"CntSetCHV0en" ,&AMACv2::CntSetCHV0en}, // there is no copy reg in star version - {"CntSetHV1en" ,&AMACv2::CntSetHV1en}, - {"CntSetHV2en" ,&AMACv2::CntSetHV2en}, - {"CntSetHV3en" ,&AMACv2::CntSetHV3en}, - }; - -std::map<std::string, std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> > AMAC_INFO::muxmap_star={ - {"VDDLR" , {{&AMACv2::Ch12Mux,0}, {&AMACv2::Ch12AMux,1}}}, - {"VDDLRLo" , {{&AMACv2::Ch12Mux,0}, {&AMACv2::Ch12AMux,0}}}, - {"VDDLRHi" , {{&AMACv2::Ch12Mux,0}, {&AMACv2::Ch12AMux,1}}}, // == VDDLR ? - {"VDDREG" , {{&AMACv2::Ch13Mux,1}}}, - {"VDDBG" , {{&AMACv2::Ch15Mux,0}}}, - {"AM900BG" , {{&AMACv2::Ch12Mux,1}}}, - {"AM600BG" , {{&AMACv2::Ch12Mux,2}}}, - {"AMREF" , {{&AMACv2::Ch13Mux,2}}}, - {"CALX" , {{&AMACv2::Ch15Mux,1}}}, - {"CALY" , {{&AMACv2::Ch15Mux,2}}}, - {"SHUNTX" , {{&AMACv2::Ch15Mux,3}}}, - {"SHUNTY" , {{&AMACv2::Ch15Mux,4}}}, - {"DCDCADJ" , {{&AMACv2::Ch13Mux,4}}}, - {"CUR10V" , {{&AMACv2::Ch13Mux,0}}}, - {"CUR10VTPL" , {{&AMACv2::Ch14Mux,1}}}, - {"CUR10VTPH" , {{&AMACv2::Ch14Mux,2}}}, - {"CUR1VTPL" , {{&AMACv2::Ch14Mux,3}}}, - {"CUR1VTPH" , {{&AMACv2::Ch14Mux,4}}}, - }; +std::map<std::string, AMACv2Field AMACv2RegMap::*> AMAC_INFO::channelmap_v2 = { + {"DCDCen", &AMACv2::DCDCen}, + {"DCDCenC", &AMACv2::DCDCenC}, + {"VDCDC", &AMACv2::Ch0Value}, + {"VDDLR", &AMACv2::Ch1Value}, + {"DCDCIN", &AMACv2::Ch2Value}, + {"VDDREG", &AMACv2::Ch3Value}, + {"sysBG", &AMACv2::Ch3Value}, // TODO == VDDBG? + {"AM900BG", &AMACv2::Ch3Value}, + {"AM600BG", &AMACv2::Ch4Value}, + {"CAL", &AMACv2::Ch4Value}, + {"AMREF", &AMACv2::Ch4Value}, + {"CALX", &AMACv2::Ch5Value}, + {"CALY", &AMACv2::Ch5Value}, + {"SHUNTX", &AMACv2::Ch5Value}, + {"SHUNTY", &AMACv2::Ch5Value}, + {"HGND", &AMACv2::Ch5Value}, + {"DIETEMP", &AMACv2::Ch6Value}, + {"CTAT", &AMACv2::Ch6Value}, + {"PTAT", &AMACv2::Ch15Value}, + {"NTCX", &AMACv2::Ch7Value}, + {"NTCY", &AMACv2::Ch8Value}, + {"NTCPB", &AMACv2::Ch9Value}, + {"HREFX", &AMACv2::Ch10Value}, + {"HREFY", &AMACv2::Ch11Value}, + {"HVret", &AMACv2::Ch14Value}, + {"CUR1V", &AMACv2::Ch13Value}, + {"CUR1VTPL", &AMACv2::Ch13Value}, + {"CUR1VTPH", &AMACv2::Ch13Value}, + {"CUR10V", &AMACv2::Ch12Value}, + {"CUR10VTPL", &AMACv2::Ch12Value}, + {"CUR10VTPH", &AMACv2::Ch12Value}, + + {"CntSetHV0en", &AMACv2::CntSetHV0en}, + {"CntSetCHV0en", &AMACv2::CntSetCHV0en}, + {"CntSetHV1en", &AMACv2::CntSetHV1en}, + {"CntSetCHV1en", &AMACv2::CntSetCHV1en}, + {"CntSetHV2en", &AMACv2::CntSetHV2en}, + {"CntSetCHV2en", &AMACv2::CntSetCHV2en}, + {"CntSetHV3en", &AMACv2::CntSetHV3en}, + {"CntSetCHV3en", &AMACv2::CntSetCHV3en}, +}; + +std::map<std::string, + std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>>> + AMAC_INFO::muxmap_v2 = { + {"VDDREG", {{&AMACv2::Ch3Mux, 0}}}, + {"sysBG", {{&AMACv2::Ch3Mux, 1}}}, // TODO: same as VDDBG? + {"AM900BG", {{&AMACv2::Ch3Mux, 2}}}, + {"AM600BG", {{&AMACv2::Ch4Mux, 0}}}, + {"CAL", {{&AMACv2::Ch4Mux, 1}}}, + {"AMREF", {{&AMACv2::Ch4Mux, 2}}}, + {"CALX", {{&AMACv2::Ch5Mux, 0}}}, + {"CALY", {{&AMACv2::Ch5Mux, 1}}}, + {"SHUNTX", {{&AMACv2::Ch5Mux, 2}}}, + {"SHUNTY", {{&AMACv2::Ch5Mux, 3}}}, + {"HGND", {{&AMACv2::Ch5Mux, 4}}}, + {"CUR10V", {{&AMACv2::Ch12Mux, 0}}}, + {"CUR10VTPL", {{&AMACv2::Ch12Mux, 1}}}, + {"CUR10VTPH", {{&AMACv2::Ch12Mux, 2}}}, + {"CUR1V", {{&AMACv2::Ch13Mux, 0}}}, + {"CUR1VTPL", {{&AMACv2::Ch13Mux, 1}}}, + {"CUR1VTPH", {{&AMACv2::Ch13Mux, 2}}}}; + +std::map<std::string, AMACv2Field AMACv2RegMap::*> AMAC_INFO::channelmap_star = + { + {"DCDCen", &AMACv2::DCDCen}, // no DCDCenC + {"VDCDC", &AMACv2::Ch0Value}, + {"VDDLR", &AMACv2::Ch12Value}, + {"VDDLRLo", &AMACv2::Ch12Value}, + {"VDDLRHi", &AMACv2::Ch12Value}, // == VDDLR ? + {"DCDCIN", &AMACv2::Ch1Value}, + {"VDDREG", &AMACv2::Ch13Value}, + {"VDDBG", &AMACv2::Ch15Value}, + {"AM900BG", &AMACv2::Ch12Value}, + {"AM600BG", &AMACv2::Ch12Value}, + {"CAL", &AMACv2::Ch11Value}, + {"CTAT", &AMACv2::Ch5Value}, + {"PTAT", &AMACv2::Ch8Value}, + {"NTCX", &AMACv2::Ch2Value}, + {"NTCY", &AMACv2::Ch3Value}, + {"NTCPB", &AMACv2::Ch4Value}, + {"HREFX", &AMACv2::Ch9Value}, + {"HREFY", &AMACv2::Ch10Value}, + {"HVret", &AMACv2::Ch7Value}, + {"CUR1V", &AMACv2::Ch6Value}, + {"CUR1VTPL", &AMACv2::Ch14Value}, + {"CUR1VTPH", &AMACv2::Ch14Value}, + + {"AMREF", &AMACv2::Ch13Value}, + {"CALX", &AMACv2::Ch15Value}, + {"CALY", &AMACv2::Ch15Value}, + {"SHUNTX", &AMACv2::Ch15Value}, + {"SHUNTY", &AMACv2::Ch15Value}, + {"DCDCADJ", &AMACv2::Ch13Value}, + {"CUR10V", &AMACv2::Ch13Value}, + {"CUR10VTPL", &AMACv2::Ch14Value}, + {"CUR10VTPH", &AMACv2::Ch14Value}, + + {"CntSetHV0en", &AMACv2::CntSetHV0en}, // just control regs + //{"CntSetCHV0en" ,&AMACv2::CntSetCHV0en}, // there is no copy reg in + //star version + {"CntSetHV1en", &AMACv2::CntSetHV1en}, + {"CntSetHV2en", &AMACv2::CntSetHV2en}, + {"CntSetHV3en", &AMACv2::CntSetHV3en}, +}; + +std::map<std::string, + std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>>> + AMAC_INFO::muxmap_star = { + {"VDDLR", {{&AMACv2::Ch12Mux, 0}, {&AMACv2::Ch12AMux, 1}}}, + {"VDDLRLo", {{&AMACv2::Ch12Mux, 0}, {&AMACv2::Ch12AMux, 0}}}, + {"VDDLRHi", + {{&AMACv2::Ch12Mux, 0}, {&AMACv2::Ch12AMux, 1}}}, // == VDDLR ? + {"VDDREG", {{&AMACv2::Ch13Mux, 1}}}, + {"VDDBG", {{&AMACv2::Ch15Mux, 0}}}, + {"AM900BG", {{&AMACv2::Ch12Mux, 1}}}, + {"AM600BG", {{&AMACv2::Ch12Mux, 2}}}, + {"AMREF", {{&AMACv2::Ch13Mux, 2}}}, + {"CALX", {{&AMACv2::Ch15Mux, 1}}}, + {"CALY", {{&AMACv2::Ch15Mux, 2}}}, + {"SHUNTX", {{&AMACv2::Ch15Mux, 3}}}, + {"SHUNTY", {{&AMACv2::Ch15Mux, 4}}}, + {"DCDCADJ", {{&AMACv2::Ch13Mux, 4}}}, + {"CUR10V", {{&AMACv2::Ch13Mux, 0}}}, + {"CUR10VTPL", {{&AMACv2::Ch14Mux, 1}}}, + {"CUR10VTPH", {{&AMACv2::Ch14Mux, 2}}}, + {"CUR1VTPL", {{&AMACv2::Ch14Mux, 3}}}, + {"CUR1VTPH", {{&AMACv2::Ch14Mux, 4}}}, +}; std::map<AMACv2::AM, AMACv2Field AMACv2RegMap::*> AMAC_INFO::am_channels_v2 = { - { AMACv2::AM::VDCDC, &AMACv2::Ch0Value}, - { AMACv2::AM::VDDLR, &AMACv2::Ch1Value}, - { AMACv2::AM::DCDCIN, &AMACv2::Ch2Value}, - { AMACv2::AM::VDDREG, &AMACv2::Ch3Value}, - { AMACv2::AM::VDDBG, &AMACv2::Ch3Value}, - { AMACv2::AM::AM900BG, &AMACv2::Ch3Value}, - { AMACv2::AM::AM600BG, &AMACv2::Ch4Value}, - { AMACv2::AM::CAL, &AMACv2::Ch4Value}, - { AMACv2::AM::AMREF, &AMACv2::Ch4Value}, - { AMACv2::AM::CALX, &AMACv2::Ch5Value}, - { AMACv2::AM::CALY, &AMACv2::Ch5Value}, - { AMACv2::AM::SHUNTX, &AMACv2::Ch5Value}, - { AMACv2::AM::SHUNTY, &AMACv2::Ch5Value}, - { AMACv2::AM::DCDCADJ, &AMACv2::Ch5Value}, - { AMACv2::AM::CTAT, &AMACv2::Ch6Value}, - { AMACv2::AM::NTCX, &AMACv2::Ch7Value}, - { AMACv2::AM::NTCY, &AMACv2::Ch8Value}, - { AMACv2::AM::NTCPB, &AMACv2::Ch9Value}, - { AMACv2::AM::HREFX, &AMACv2::Ch10Value}, - { AMACv2::AM::HREFY, &AMACv2::Ch11Value}, - { AMACv2::AM::CUR10V, &AMACv2::Ch12Value}, - { AMACv2::AM::CUR10VTPL, &AMACv2::Ch12Value}, - { AMACv2::AM::CUR10VTPH, &AMACv2::Ch12Value}, - { AMACv2::AM::CUR1V, &AMACv2::Ch13Value}, - { AMACv2::AM::CUR1VTPL, &AMACv2::Ch13Value}, - { AMACv2::AM::CUR1VTPH, &AMACv2::Ch13Value}, - { AMACv2::AM::HVRET, &AMACv2::Ch14Value}, - { AMACv2::AM::PTAT, &AMACv2::Ch15Value}, + {AMACv2::AM::VDCDC, &AMACv2::Ch0Value}, + {AMACv2::AM::VDDLR, &AMACv2::Ch1Value}, + {AMACv2::AM::DCDCIN, &AMACv2::Ch2Value}, + {AMACv2::AM::VDDREG, &AMACv2::Ch3Value}, + {AMACv2::AM::VDDBG, &AMACv2::Ch3Value}, + {AMACv2::AM::AM900BG, &AMACv2::Ch3Value}, + {AMACv2::AM::AM600BG, &AMACv2::Ch4Value}, + {AMACv2::AM::CAL, &AMACv2::Ch4Value}, + {AMACv2::AM::AMREF, &AMACv2::Ch4Value}, + {AMACv2::AM::CALX, &AMACv2::Ch5Value}, + {AMACv2::AM::CALY, &AMACv2::Ch5Value}, + {AMACv2::AM::SHUNTX, &AMACv2::Ch5Value}, + {AMACv2::AM::SHUNTY, &AMACv2::Ch5Value}, + {AMACv2::AM::DCDCADJ, &AMACv2::Ch5Value}, + {AMACv2::AM::CTAT, &AMACv2::Ch6Value}, + {AMACv2::AM::NTCX, &AMACv2::Ch7Value}, + {AMACv2::AM::NTCY, &AMACv2::Ch8Value}, + {AMACv2::AM::NTCPB, &AMACv2::Ch9Value}, + {AMACv2::AM::HREFX, &AMACv2::Ch10Value}, + {AMACv2::AM::HREFY, &AMACv2::Ch11Value}, + {AMACv2::AM::CUR10V, &AMACv2::Ch12Value}, + {AMACv2::AM::CUR10VTPL, &AMACv2::Ch12Value}, + {AMACv2::AM::CUR10VTPH, &AMACv2::Ch12Value}, + {AMACv2::AM::CUR1V, &AMACv2::Ch13Value}, + {AMACv2::AM::CUR1VTPL, &AMACv2::Ch13Value}, + {AMACv2::AM::CUR1VTPH, &AMACv2::Ch13Value}, + {AMACv2::AM::HVRET, &AMACv2::Ch14Value}, + {AMACv2::AM::PTAT, &AMACv2::Ch15Value}, }; -std::map<AMACv2::AM, AMACv2Field AMACv2RegMap::*> AMAC_INFO::am_channels_star = { - { AMACv2::AM::VDCDC, &AMACv2::Ch0Value}, - { AMACv2::AM::VDDLR, &AMACv2::Ch12Value}, - { AMACv2::AM::VDDLRLo, &AMACv2::Ch12Value}, - { AMACv2::AM::VDDLRHi, &AMACv2::Ch12Value}, - { AMACv2::AM::DCDCIN, &AMACv2::Ch1Value}, - { AMACv2::AM::VDDREG, &AMACv2::Ch13Value}, - { AMACv2::AM::VDDBG, &AMACv2::Ch15Value}, - { AMACv2::AM::AM900BG, &AMACv2::Ch12Value}, - { AMACv2::AM::AM600BG, &AMACv2::Ch12Value}, - { AMACv2::AM::CAL, &AMACv2::Ch11Value}, - { AMACv2::AM::AMREF, &AMACv2::Ch13Value}, - { AMACv2::AM::CALX, &AMACv2::Ch15Value}, - { AMACv2::AM::CALY, &AMACv2::Ch15Value}, - { AMACv2::AM::SHUNTX, &AMACv2::Ch15Value}, - { AMACv2::AM::SHUNTY, &AMACv2::Ch15Value}, - { AMACv2::AM::DCDCADJ, &AMACv2::Ch13Value}, - { AMACv2::AM::CTAT, &AMACv2::Ch5Value}, - { AMACv2::AM::NTCX, &AMACv2::Ch2Value}, - { AMACv2::AM::NTCY, &AMACv2::Ch3Value}, - { AMACv2::AM::NTCPB, &AMACv2::Ch4Value}, - { AMACv2::AM::HREFX, &AMACv2::Ch9Value}, - { AMACv2::AM::HREFY, &AMACv2::Ch10Value}, - { AMACv2::AM::CUR10V, &AMACv2::Ch13Value}, - { AMACv2::AM::CUR10VTPL, &AMACv2::Ch14Value}, - { AMACv2::AM::CUR10VTPH, &AMACv2::Ch14Value}, - { AMACv2::AM::CUR1V, &AMACv2::Ch6Value}, - { AMACv2::AM::CUR1VTPL, &AMACv2::Ch14Value}, - { AMACv2::AM::CUR1VTPH, &AMACv2::Ch14Value}, - { AMACv2::AM::HVRET, &AMACv2::Ch7Value}, - { AMACv2::AM::PTAT, &AMACv2::Ch8Value}, +std::map<AMACv2::AM, AMACv2Field AMACv2RegMap::*> AMAC_INFO::am_channels_star = + { + {AMACv2::AM::VDCDC, &AMACv2::Ch0Value}, + {AMACv2::AM::VDDLR, &AMACv2::Ch12Value}, + {AMACv2::AM::VDDLRLo, &AMACv2::Ch12Value}, + {AMACv2::AM::VDDLRHi, &AMACv2::Ch12Value}, + {AMACv2::AM::DCDCIN, &AMACv2::Ch1Value}, + {AMACv2::AM::VDDREG, &AMACv2::Ch13Value}, + {AMACv2::AM::VDDBG, &AMACv2::Ch15Value}, + {AMACv2::AM::AM900BG, &AMACv2::Ch12Value}, + {AMACv2::AM::AM600BG, &AMACv2::Ch12Value}, + {AMACv2::AM::CAL, &AMACv2::Ch11Value}, + {AMACv2::AM::AMREF, &AMACv2::Ch13Value}, + {AMACv2::AM::CALX, &AMACv2::Ch15Value}, + {AMACv2::AM::CALY, &AMACv2::Ch15Value}, + {AMACv2::AM::SHUNTX, &AMACv2::Ch15Value}, + {AMACv2::AM::SHUNTY, &AMACv2::Ch15Value}, + {AMACv2::AM::DCDCADJ, &AMACv2::Ch13Value}, + {AMACv2::AM::CTAT, &AMACv2::Ch5Value}, + {AMACv2::AM::NTCX, &AMACv2::Ch2Value}, + {AMACv2::AM::NTCY, &AMACv2::Ch3Value}, + {AMACv2::AM::NTCPB, &AMACv2::Ch4Value}, + {AMACv2::AM::HREFX, &AMACv2::Ch9Value}, + {AMACv2::AM::HREFY, &AMACv2::Ch10Value}, + {AMACv2::AM::CUR10V, &AMACv2::Ch13Value}, + {AMACv2::AM::CUR10VTPL, &AMACv2::Ch14Value}, + {AMACv2::AM::CUR10VTPH, &AMACv2::Ch14Value}, + {AMACv2::AM::CUR1V, &AMACv2::Ch6Value}, + {AMACv2::AM::CUR1VTPL, &AMACv2::Ch14Value}, + {AMACv2::AM::CUR1VTPH, &AMACv2::Ch14Value}, + {AMACv2::AM::HVRET, &AMACv2::Ch7Value}, + {AMACv2::AM::PTAT, &AMACv2::Ch8Value}, }; diff --git a/pbv3/AMACv2.h b/pbv3/AMACv2.h index 2bb5f0f718fa2281582bced784ffc1af4e4f4eaa..623b914fefa74308a7420370af90d6269bec046e 100644 --- a/pbv3/AMACv2.h +++ b/pbv3/AMACv2.h @@ -1,488 +1,561 @@ #ifndef AMACv2_H_ #define AMACv2_H_ +#include <cmath> +#include <map> +#include <utility> + #include "AMACv2RegMap.h" #include "EndeavourCom.h" #include "EndeavourRaw.h" -#include <map> -#include <utility> -#include <cmath> - -/// \brief return value of a raw ADC measurement, i.e. the average count from a series of readings and its rms +/// \brief return value of a raw ADC measurement, i.e. the average count from a +/// series of readings and its rms struct MultiCounts { - uint32_t multi_counts; //!< it's "multi" because it is an average of several ADC readings, the floating point is truncated to uint - uint32_t multi_counts_rms; + uint32_t + multi_counts; //!< it's "multi" because it is an average of several ADC + //!< readings, the floating point is truncated to uint + uint32_t multi_counts_rms; }; -/// \brief return value of calibrated voltage and the average count from a series of readings +/// \brief return value of calibrated voltage and the average count from a +/// series of readings struct VoltMultiCounts { - uint32_t multi_counts; - uint32_t multi_counts_rms; - double volt; double volt_rms; + uint32_t multi_counts; + uint32_t multi_counts_rms; + double volt; + double volt_rms; }; /// \brief return value for a calibrated physical parameter struct ParamVoltMultiCounts { - uint32_t multi_counts; uint32_t multi_counts_rms; - double volt; double volt_rms; - double param; double param_rms; + uint32_t multi_counts; + uint32_t multi_counts_rms; + double volt; + double volt_rms; + double param; + double param_rms; }; -//class AMACv2 : public EndeavourCom, public AMACv2RegMap -class AMACv2 : public AMACv2RegMap -{ -public: - - //! AMAC measurement channels - enum AM { - VDCDC, - VDDLR, - VDDLRLo, - VDDLRHi, - DCDCIN, - VDDREG, - VDDBG, - AM900BG, - AM600BG, - CAL, - AMREF, - CALX, - CALY, - SHUNTX, - SHUNTY, - DCDCADJ, - CTAT, - NTCX, - NTCY, - NTCPB, - HREFX, - HREFY, - CUR10V, - CUR10VTPL, - CUR10VTPH, - CUR1V, - CUR1VTPL, - CUR1VTPH, - HVRET, - PTAT, - }; - - AMACv2(unsigned short amacid, std::shared_ptr<EndeavourCom> com); // with hardware - AMACv2(unsigned short amacid, std::shared_ptr<EndeavourRaw> raw); // it just constructs Com from Raw - AMACv2(unsigned short amacid, std::unique_ptr<EndeavourRaw> raw); // the old powertools constructor for compatibility - ~AMACv2(); - - //! \brief Get the AMAC version set for the SW object - Version getVersion(); - uint32_t read_version(); - Version convertVersion(uint32_t version_id); - - //! \brief Detect the HW AMAC version and set the corresponding regmap for the SW object - void detectAndSetVersion(); - void setVersion(int version_reg_value); - void setVersion(Version ver); - int detectVersion(); - - void constructor_circuit_versions_n_data(void); - - //! \brief the map that stores the curcuit data, exposed for more flexibility during development - std::map<std::string, double> m_circuit; - - // get raw endeavour bus from endeavour com - const std::shared_ptr<EndeavourRaw>& raw() {return m_endeavour_com->raw();}; - - void _set_amacid(unsigned short amacid) {m_amacid = amacid;}; - unsigned short _get_amacid() {return m_amacid;}; - - //! \brief get circuitry parameters in different versions of the power board - /** - * "some have 1k and some have 10k parts" - * double m_circuit_ntcpb_R25 = 10e3; - - * // "For PB NTCs B is 3900 for 10k parts and 4500 for 1k parts" - * double m_circuit_ntcpb_B = 3900; - * // "For hybrid NTCs B is 3435" - * // "yes, hybrid NTCs are all 10k parts" - * double m_circuit_ntchybrid_R25 = 10e3; - * double m_circuit_ntchybrid_B = 3435; - - * double m_circuit_trace_resistance_ntcpb = 0.; - * double m_circuit_trace_resistance_ntcx = 0.; - * double m_circuit_trace_resistance_ntcy = 0.; - */ - double circuit(std::string param_name); - - //! \brief set circuitry parameters - bool circuit_set(std::string param, double value); - - //! \brief Initialize the communication with chip - /** - * Consists of two steps: - * 1. Call setID (if needed, as determined by isCommIDSet). - * 2. Load current chip register values into the local register map. - */ - void init(); - - //! \brief Load AMAC with local register map - void initRegisters(); - - /** - * Load registers from the AMAC chip and store them in the - * internal register map - */ - void loadRegisters(); - - bool isCommIDSet(); - - // forwarders to EndeavourCom - // these set SW values of registers and then issue EndeavourCom to HW - virtual void write_reg(unsigned int address, unsigned int data); - virtual unsigned int read_reg(unsigned int address); - virtual unsigned int readnext_reg(void) {return m_endeavour_com->readnext_reg(m_amacid);}; - // this one sets refid (padid) and sends a HW call through EndeavourCom, it does not reset the m_amacid - virtual void setid(EndeavourCom::REFMODE mode, unsigned int refid); - virtual void setid_via_fuses(unsigned int refid) {setid(EndeavourCom::REFMODE::EfuseId, refid);}; - virtual void setid_via_bonds(unsigned int refid) {setid(EndeavourCom::REFMODE::IDPads, refid);}; - virtual void reset(void) {m_endeavour_com->reset();}; - virtual void connect(void) {m_endeavour_com->connect();}; - virtual void disconnect(void) {m_endeavour_com->disconnect();}; - - // field-aware calls - void wrField(AMACv2Field AMACv2RegMap::* ref, uint32_t data); - void wrField(const std::string& fieldName, uint32_t data); - - uint32_t rdField(AMACv2Field AMACv2RegMap::* ref); - uint32_t rdField(const std::string& fieldName); - - //! Get the AMAC version - uint8_t getFieldWidth(AMACv2Field AMACv2RegMap::* ref); - - // - // PADID and eFuse settings - void setPADID(uint8_t padid); - uint8_t getPADID(); - void setEFUSEID(uint8_t efuseid); - uint8_t getEFUSEID(); - - // this one actually reads the efuseid from HW - uint32_t readEFuse(); - - /** \name Calibrations - * @{ - */ - - //! Set slope of AM - /** - * \param ADCslope slope of AM ramp in mV/count - */ - void setADCslope (double ADCslope); - - //! Set the AM offset for a given channel - /** - * \param ch Channel - * \param counts counts at zero voltage - */ - void setADCoffset(uint8_t ch, uint32_t counts); - - //! Enable NTC calibration - /** - */ - void enableNTCCalibration(); - - //! Disable NTC calibration - /** - */ - void disableNTCCalibration(); - - //! Set the NTCx reference - /** - * \param ntccal reference in mV - */ - void setNTCxCal(double ntccal); - - //! Set the NTCy reference - /** - * \param ntccal reference in mV - */ - void setNTCyCal(double ntccal); - - //! Set the NTCpb reference - /** - * \param ntccal reference in mV - */ - void setNTCpbCal(double ntccal); - - //! Set PTAT absolute scale - /** - * \param ptat0 PTAT reading (mV) at 0C - */ - void setPTAT0(double ptat0); - - //! Set the CTAT absolute scale - /** - * \param offset CTAT offset - * \param ctat0 CTAT reading (mV) at 0C - */ - void setCTAT0(uint8_t offset, double ctat0); - - //! Set the Cur1V measurement offset - /** - * \param offset for Cur1V measurement - */ - void setCur1VOffset(double offset); - - //! Set the Cur10V measurement offset - /** - * \param offset for Cur10V measurement - */ - void setCur10VOffset(double offset); - - /** @} */ - - /** \name Analogue Monitor Readings - * @{ - */ - - //! Map to go from AM enum to string - static const std::map<AMACv2::AM, std::string> Map_AMStr; - - //! \brief AM reading of quantity [counts] - /** - * Measures a given quantity using the AM block. If - * the `am` is in a multiplexed channel, then it is - * also selected. - * - * Makes a number of reads and returns their average. - * - * \param am Quantity to measure - * \param reads Number of reads to make, default=1 - * - * \return Measured voltaeg [counts] - */ - struct MultiCounts readAM(AM am, uint32_t reads); - uint32_t readAM(AM am) {struct MultiCounts res = readAM(am, 1); return res.multi_counts;}; - - struct MultiCounts readAM_v2(AM am, uint32_t reads); - struct MultiCounts readAM_star(AM am, uint32_t reads); - - struct MultiCounts readAM_channelReg(AMACv2Field AMACv2RegMap::* ch, uint32_t n_reads); - - //uint8_t convertAMChValueToInt (AMACv2Field& chan); - uint8_t convertAMChValueToInt (AMACv2Field AMACv2RegMap::* chan); - AMACv2Field AMACv2RegMap::* convertAMChannelToChValue (const AM& am_chan); - //AMACv2Field convertAMChannelToChValue_v2 (AM& am_chan); - //AMACv2Field convertAMChannelToChValue_star (AM& am_chan); - - //! \brief AM reading for channel `ch` [mV] - /** - * \param ch AM channel to read - * - * \return Measured voltage [mV] - */ - double getADC(uint8_t ch); - - //! \brief HVret (channel - offset) / slope - struct VoltMultiCounts vc_getHVret(uint32_t reads=1, bool autorange=false); - double getHVret(uint32_t n_reads=1, bool autorange=false) {struct VoltMultiCounts res = vc_getHVret(n_reads, autorange); return res.volt;}; - //! \brief getHVret / (1000*Rset) - struct ParamVoltMultiCounts getHVcur(uint32_t n_reads, bool autorange=false); - double getHVcur(bool autorange=false) {struct ParamVoltMultiCounts res = getHVcur(1, autorange); return res.param;}; - - double getLinPOLCur(); - - double getVDDREG(); - double getAM600(); - double getAM900(); - - //! Get temperature reading from NTCx in volts - //struct VoltMultiCounts getNTC_VC (bool autorange=false); - struct VoltMultiCounts getNTC_VC(AM am, AMACv2Field AMACv2RegMap::* sense_range, bool autorange); - - struct VoltMultiCounts getNTCxVC (bool autorange=false); - double getNTCx (bool autorange=false) {struct VoltMultiCounts meas = getNTCxVC(autorange); return meas.volt;}; - - //! Get temperature reading from NTCy in volts - struct VoltMultiCounts getNTCyVC (bool autorange=false); - double getNTCy (bool autorange=false) {struct VoltMultiCounts meas = getNTCyVC(autorange); return meas.volt;}; - - //! Get temperature reading from NTCpb in volts - struct VoltMultiCounts getNTCpbVC (bool autorange=false); - double getNTCpb (bool autorange=false) {struct VoltMultiCounts meas = getNTCpbVC(autorange); return meas.volt;}; - - //! Get CTAT reading from AMAC in volts - double getCTAT(); - - struct VoltMultiCounts vc_getCur10V(uint32_t reads=1); - double getCur10V (uint32_t reads=1) {struct VoltMultiCounts res = vc_getCur10V(reads); return res.volt;}; - double getCur10VTPL (uint32_t reads=1); - double getCur10VTPH (uint32_t reads=1); - - struct VoltMultiCounts vc_getCur1V(uint32_t reads=1); - double getCur1V (uint32_t reads=1) {struct VoltMultiCounts res = vc_getCur1V(reads); return res.volt;}; - double getCur1VTPL (uint32_t reads=1); - double getCur1VTPH (uint32_t reads=1); - - double current10V (uint32_t reads=1); - double current1V (uint32_t reads=1); - - double convertCur10V(uint32_t Cur10V); - double convertCur1V(uint32_t Cur1V); - double convertVDCDC(uint32_t VDCDC); - - - - /** @} */ - - /** \name Temperature Measurements - * @{ - */ - - //! Common calcilation oF NTC temperature in C - /** - * ITSDAQ: https://gitlab.cern.ch/atlas-itk-strips-daq/itsdaq-sw/-/blob/master/macros/AMACv2_final.cpp#L779 - */ - double temperatureNTC(double NTCvolt, double NTCcal, uint32_t sense_range, double trace_resistance, double B, double R25); - - //! Get Hybrid X temperature in C - /** - * Assuming random NTC for conversion - */ - struct ParamVoltMultiCounts temperatureXnV (bool autorange=false); - double temperatureX (bool autorange=false) {struct ParamVoltMultiCounts meas = temperatureXnV (autorange); return meas.param;}; - - //! Get Hybrid Y temperature in C - /** - * Assuming random NTC for conversion - */ - struct ParamVoltMultiCounts temperatureYnV (bool autorange=false); - double temperatureY (bool autorange=false) {struct ParamVoltMultiCounts meas = temperatureYnV (autorange); return meas.param;}; - - //! Get Powerboard temperature in C - /** - * Assuming [Panasonic ERT-J0EM103J](https://industrial.panasonic.com/cdbs/www-data/pdf/AUA0000/AUA0000C8.pdf) - * as the NTC for converting volts to C. - */ - struct ParamVoltMultiCounts temperaturePBnV (bool autorange=false); - double temperaturePB (bool autorange=false) {struct ParamVoltMultiCounts meas = temperaturePBnV (autorange); return meas.param;}; - - //! Get PTAT reading from bPOL in volts - double getPTAT() {struct VoltMultiCounts res = getPTAT_vc(); return res.volt;}; - struct VoltMultiCounts getPTAT_vc(); - - //! Get bPOL temperature in C - /** - * Assumes 8.5mV/C and PTAT0 calibraton. - * temp = (PTAT-PTAT0)/8.5 - */ - double temperaturePTAT() {struct ParamVoltMultiCounts meas = temperaturePTAT_pvc(); return meas.param;}; - struct ParamVoltMultiCounts temperaturePTAT_pvc(); - - //! Get AMAC temperature in C - /** - * Assumes 1.5mV/C and CTAT0 calibraton. - * temp = (CTAT-CTAT0)/1.5 - */ - double temperatureCTAT(); - - /** @} */ - -public: - std::map<std::string, AMACv2Field AMACv2RegMap::*> m_channelmap; - std::map<std::string, std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> > m_muxmap; - uint32_t readDataFieldName (std::string name); - void writeDataFieldName (std::string name, uint32_t data); - std::vector<std::string> dataFieldNames(void); - std::vector<std::string> muxNames(void); - - std::pair<float, float> readAMChan( - AMACv2Field AMACv2RegMap::* field_to_read, // channel - std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> fields_to_set, // mutexes - unsigned n_reads=1, - bool reset_mux=false); - -private: - std::shared_ptr<EndeavourCom> m_endeavour_com; // the driver of calls to HW - unsigned short m_amacid; - - double calibrateCounts(uint8_t ch, uint32_t counts); - - void syncReg(AMACv2Field AMACv2RegMap::* ref); - - double m_ADCslope =1.; - uint32_t m_ADCoffset[16] ={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - uint8_t m_padid =0; - uint8_t m_efuseid =0; - - double m_NTCxCal =250.; - double m_NTCyCal =250.; - double m_NTCpbCal =250.; - - double m_PTAT0 =250.; // empirically derived - uint32_t m_CTAT0[16] ={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - - double m_Cur10VOffset =200.; - double m_Cur1VOffset =200.; - - - // AMAC version-specific data: AM channels, etc - // AMACv2 as default - int amac_version_id = -1; // for version "unknown" - Version amac_version = Version::unknown; // version is "unknown" but channel values are v2 - - // AMAC channels (version star?) - //uint8_t ch_VDCDC = 0; - //uint8_t ch_VDDLR = 12; - //uint8_t ch_VDDLRLo = 12; - //uint8_t ch_VDDLRHi = 12; - //uint8_t ch_DCDCIN = 1; - //uint8_t ch_VDDREG = 13; - //uint8_t ch_VDDBG = 15; - //uint8_t ch_AM900BG = 12; - //uint8_t ch_AM600BG = 12; - //uint8_t ch_CAL = 11; - //uint8_t ch_AMREF = 13; - //uint8_t ch_CALX = 15; - //uint8_t ch_CALY = 15; - //uint8_t ch_SHUNTX = 15; - //uint8_t ch_SHUNTY = 15; - //uint8_t ch_DCDCADJ = 13; - //uint8_t ch_CTAT = 5; - //uint8_t ch_NTCX = 2; - //uint8_t ch_NTCY = 3; - //uint8_t ch_NTCPB = 4; - //uint8_t ch_HREFX = 9; - //uint8_t ch_HREFY = 10; - //uint8_t ch_CUR10V = 13; - //uint8_t ch_CUR10VTPL = 14; - //uint8_t ch_CUR10VTPH = 14; - //uint8_t ch_CUR1V = 6; - //uint8_t ch_CUR1VTPL = 14; - //uint8_t ch_CUR1VTPH = 14; - //uint8_t ch_HVRET = 7; - //uint8_t ch_PTAT = 8; - - // better like this? - std::map<AM, uint8_t> m_ch_map; - - /* these are v2? - uint8_t CH_CUR10V = 12; - uint8_t CH_CUR10VTPL = 12; - uint8_t CH_CUR10VTPH = 12; - - uint8_t CH_CUR1V = 13; - uint8_t CH_CUR1VTPL = 13; - uint8_t CH_CUR1VTPH = 13; - */ +// class AMACv2 : public EndeavourCom, public AMACv2RegMap +class AMACv2 : public AMACv2RegMap { + public: + //! AMAC measurement channels + enum AM { + VDCDC, + VDDLR, + VDDLRLo, + VDDLRHi, + DCDCIN, + VDDREG, + VDDBG, + AM900BG, + AM600BG, + CAL, + AMREF, + CALX, + CALY, + SHUNTX, + SHUNTY, + DCDCADJ, + CTAT, + NTCX, + NTCY, + NTCPB, + HREFX, + HREFY, + CUR10V, + CUR10VTPL, + CUR10VTPH, + CUR1V, + CUR1VTPL, + CUR1VTPH, + HVRET, + PTAT, + }; + + AMACv2(unsigned short amacid, + std::shared_ptr<EndeavourCom> com); // with hardware + AMACv2( + unsigned short amacid, + std::shared_ptr<EndeavourRaw> raw); // it just constructs Com from Raw + AMACv2(unsigned short amacid, + std::unique_ptr<EndeavourRaw> + raw); // the old powertools constructor for compatibility + ~AMACv2(); + + //! \brief Get the AMAC version set for the SW object + Version getVersion(); + uint32_t read_version(); + Version convertVersion(uint32_t version_id); + + //! \brief Detect the HW AMAC version and set the corresponding regmap for + //! the SW object + void detectAndSetVersion(); + void setVersion(int version_reg_value); + void setVersion(Version ver); + int detectVersion(); + + void constructor_circuit_versions_n_data(void); + + //! \brief the map that stores the curcuit data, exposed for more + //! flexibility during development + std::map<std::string, double> m_circuit; + + // get raw endeavour bus from endeavour com + const std::shared_ptr<EndeavourRaw>& raw() { + return m_endeavour_com->raw(); + }; + + void _set_amacid(unsigned short amacid) { m_amacid = amacid; }; + unsigned short _get_amacid() { return m_amacid; }; + + //! \brief get circuitry parameters in different versions of the power board + /** + * "some have 1k and some have 10k parts" + * double m_circuit_ntcpb_R25 = 10e3; + + * // "For PB NTCs B is 3900 for 10k parts and 4500 for 1k parts" + * double m_circuit_ntcpb_B = 3900; + * // "For hybrid NTCs B is 3435" + * // "yes, hybrid NTCs are all 10k parts" + * double m_circuit_ntchybrid_R25 = 10e3; + * double m_circuit_ntchybrid_B = 3435; + + * double m_circuit_trace_resistance_ntcpb = 0.; + * double m_circuit_trace_resistance_ntcx = 0.; + * double m_circuit_trace_resistance_ntcy = 0.; + */ + double circuit(std::string param_name); + + //! \brief set circuitry parameters + bool circuit_set(std::string param, double value); + + //! \brief Initialize the communication with chip + /** + * Consists of two steps: + * 1. Call setID (if needed, as determined by isCommIDSet). + * 2. Load current chip register values into the local register map. + */ + void init(); + + //! \brief Load AMAC with local register map + void initRegisters(); + + /** + * Load registers from the AMAC chip and store them in the + * internal register map + */ + void loadRegisters(); + + bool isCommIDSet(); + + // forwarders to EndeavourCom + // these set SW values of registers and then issue EndeavourCom to HW + virtual void write_reg(unsigned int address, unsigned int data); + virtual unsigned int read_reg(unsigned int address); + virtual unsigned int readnext_reg(void) { + return m_endeavour_com->readnext_reg(m_amacid); + }; + // this one sets refid (padid) and sends a HW call through EndeavourCom, it + // does not reset the m_amacid + virtual void setid(EndeavourCom::REFMODE mode, unsigned int refid); + virtual void setid_via_fuses(unsigned int refid) { + setid(EndeavourCom::REFMODE::EfuseId, refid); + }; + virtual void setid_via_bonds(unsigned int refid) { + setid(EndeavourCom::REFMODE::IDPads, refid); + }; + virtual void reset(void) { m_endeavour_com->reset(); }; + virtual void connect(void) { m_endeavour_com->connect(); }; + virtual void disconnect(void) { m_endeavour_com->disconnect(); }; + + // field-aware calls + void wrField(AMACv2Field AMACv2RegMap::*ref, uint32_t data); + void wrField(const std::string& fieldName, uint32_t data); + + uint32_t rdField(AMACv2Field AMACv2RegMap::*ref); + uint32_t rdField(const std::string& fieldName); + + //! Get the AMAC version + uint8_t getFieldWidth(AMACv2Field AMACv2RegMap::*ref); + + // + // PADID and eFuse settings + void setPADID(uint8_t padid); + uint8_t getPADID(); + void setEFUSEID(uint8_t efuseid); + uint8_t getEFUSEID(); + + // this one actually reads the efuseid from HW + uint32_t readEFuse(); + + /** \name Calibrations + * @{ + */ + + //! Set slope of AM + /** + * \param ADCslope slope of AM ramp in mV/count + */ + void setADCslope(double ADCslope); + + //! Set the AM offset for a given channel + /** + * \param ch Channel + * \param counts counts at zero voltage + */ + void setADCoffset(uint8_t ch, uint32_t counts); + + //! Enable NTC calibration + /** + */ + void enableNTCCalibration(); + + //! Disable NTC calibration + /** + */ + void disableNTCCalibration(); + + //! Set the NTCx reference + /** + * \param ntccal reference in mV + */ + void setNTCxCal(double ntccal); + + //! Set the NTCy reference + /** + * \param ntccal reference in mV + */ + void setNTCyCal(double ntccal); + + //! Set the NTCpb reference + /** + * \param ntccal reference in mV + */ + void setNTCpbCal(double ntccal); + + //! Set PTAT absolute scale + /** + * \param ptat0 PTAT reading (mV) at 0C + */ + void setPTAT0(double ptat0); + + //! Set the CTAT absolute scale + /** + * \param offset CTAT offset + * \param ctat0 CTAT reading (mV) at 0C + */ + void setCTAT0(uint8_t offset, double ctat0); + + //! Set the Cur1V measurement offset + /** + * \param offset for Cur1V measurement + */ + void setCur1VOffset(double offset); + + //! Set the Cur10V measurement offset + /** + * \param offset for Cur10V measurement + */ + void setCur10VOffset(double offset); + + /** @} */ + + /** \name Analogue Monitor Readings + * @{ + */ + + //! Map to go from AM enum to string + static const std::map<AMACv2::AM, std::string> Map_AMStr; + + //! \brief AM reading of quantity [counts] + /** + * Measures a given quantity using the AM block. If + * the `am` is in a multiplexed channel, then it is + * also selected. + * + * Makes a number of reads and returns their average. + * + * \param am Quantity to measure + * \param reads Number of reads to make, default=1 + * + * \return Measured voltaeg [counts] + */ + struct MultiCounts readAM(AM am, uint32_t reads); + uint32_t readAM(AM am) { + struct MultiCounts res = readAM(am, 1); + return res.multi_counts; + }; + + struct MultiCounts readAM_v2(AM am, uint32_t reads); + struct MultiCounts readAM_star(AM am, uint32_t reads); + + struct MultiCounts readAM_channelReg(AMACv2Field AMACv2RegMap::*ch, + uint32_t n_reads); + + // uint8_t convertAMChValueToInt (AMACv2Field& chan); + uint8_t convertAMChValueToInt(AMACv2Field AMACv2RegMap::*chan); + AMACv2Field AMACv2RegMap::*convertAMChannelToChValue(const AM& am_chan); + // AMACv2Field convertAMChannelToChValue_v2 (AM& am_chan); + // AMACv2Field convertAMChannelToChValue_star (AM& am_chan); + + //! \brief AM reading for channel `ch` [mV] + /** + * \param ch AM channel to read + * + * \return Measured voltage [mV] + */ + double getADC(uint8_t ch); + + //! \brief HVret (channel - offset) / slope + struct VoltMultiCounts vc_getHVret(uint32_t reads = 1, + bool autorange = false); + double getHVret(uint32_t n_reads = 1, bool autorange = false) { + struct VoltMultiCounts res = vc_getHVret(n_reads, autorange); + return res.volt; + }; + //! \brief getHVret / (1000*Rset) + struct ParamVoltMultiCounts getHVcur(uint32_t n_reads, + bool autorange = false); + double getHVcur(bool autorange = false) { + struct ParamVoltMultiCounts res = getHVcur(1, autorange); + return res.param; + }; + + double getLinPOLCur(); + + double getVDDREG(); + double getAM600(); + double getAM900(); + + //! Get temperature reading from NTCx in volts + // struct VoltMultiCounts getNTC_VC (bool autorange=false); + struct VoltMultiCounts getNTC_VC(AM am, + AMACv2Field AMACv2RegMap::*sense_range, + bool autorange); + + struct VoltMultiCounts getNTCxVC(bool autorange = false); + double getNTCx(bool autorange = false) { + struct VoltMultiCounts meas = getNTCxVC(autorange); + return meas.volt; + }; + + //! Get temperature reading from NTCy in volts + struct VoltMultiCounts getNTCyVC(bool autorange = false); + double getNTCy(bool autorange = false) { + struct VoltMultiCounts meas = getNTCyVC(autorange); + return meas.volt; + }; + + //! Get temperature reading from NTCpb in volts + struct VoltMultiCounts getNTCpbVC(bool autorange = false); + double getNTCpb(bool autorange = false) { + struct VoltMultiCounts meas = getNTCpbVC(autorange); + return meas.volt; + }; + + //! Get CTAT reading from AMAC in volts + double getCTAT(); + + struct VoltMultiCounts vc_getCur10V(uint32_t reads = 1); + double getCur10V(uint32_t reads = 1) { + struct VoltMultiCounts res = vc_getCur10V(reads); + return res.volt; + }; + double getCur10VTPL(uint32_t reads = 1); + double getCur10VTPH(uint32_t reads = 1); + + struct VoltMultiCounts vc_getCur1V(uint32_t reads = 1); + double getCur1V(uint32_t reads = 1) { + struct VoltMultiCounts res = vc_getCur1V(reads); + return res.volt; + }; + double getCur1VTPL(uint32_t reads = 1); + double getCur1VTPH(uint32_t reads = 1); + + double current10V(uint32_t reads = 1); + double current1V(uint32_t reads = 1); + + double convertCur10V(uint32_t Cur10V); + double convertCur1V(uint32_t Cur1V); + double convertVDCDC(uint32_t VDCDC); + + /** @} */ + + /** \name Temperature Measurements + * @{ + */ + + //! Common calcilation oF NTC temperature in C + /** + * ITSDAQ: + * https://gitlab.cern.ch/atlas-itk-strips-daq/itsdaq-sw/-/blob/master/macros/AMACv2_final.cpp#L779 + */ + double temperatureNTC(double NTCvolt, double NTCcal, uint32_t sense_range, + double trace_resistance, double B, double R25); + + //! Get Hybrid X temperature in C + /** + * Assuming random NTC for conversion + */ + struct ParamVoltMultiCounts temperatureXnV(bool autorange = false); + double temperatureX(bool autorange = false) { + struct ParamVoltMultiCounts meas = temperatureXnV(autorange); + return meas.param; + }; + + //! Get Hybrid Y temperature in C + /** + * Assuming random NTC for conversion + */ + struct ParamVoltMultiCounts temperatureYnV(bool autorange = false); + double temperatureY(bool autorange = false) { + struct ParamVoltMultiCounts meas = temperatureYnV(autorange); + return meas.param; + }; + + //! Get Powerboard temperature in C + /** + * Assuming [Panasonic + * ERT-J0EM103J](https://industrial.panasonic.com/cdbs/www-data/pdf/AUA0000/AUA0000C8.pdf) + * as the NTC for converting volts to C. + */ + struct ParamVoltMultiCounts temperaturePBnV(bool autorange = false); + double temperaturePB(bool autorange = false) { + struct ParamVoltMultiCounts meas = temperaturePBnV(autorange); + return meas.param; + }; + + //! Get PTAT reading from bPOL in volts + double getPTAT() { + struct VoltMultiCounts res = getPTAT_vc(); + return res.volt; + }; + struct VoltMultiCounts getPTAT_vc(); + + //! Get bPOL temperature in C + /** + * Assumes 8.5mV/C and PTAT0 calibraton. + * temp = (PTAT-PTAT0)/8.5 + */ + double temperaturePTAT() { + struct ParamVoltMultiCounts meas = temperaturePTAT_pvc(); + return meas.param; + }; + struct ParamVoltMultiCounts temperaturePTAT_pvc(); + + //! Get AMAC temperature in C + /** + * Assumes 1.5mV/C and CTAT0 calibraton. + * temp = (CTAT-CTAT0)/1.5 + */ + double temperatureCTAT(); + + /** @} */ + + public: + std::map<std::string, AMACv2Field AMACv2RegMap::*> m_channelmap; + std::map<std::string, + std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>>> + m_muxmap; + uint32_t readDataFieldName(std::string name); + void writeDataFieldName(std::string name, uint32_t data); + std::vector<std::string> dataFieldNames(void); + std::vector<std::string> muxNames(void); + + std::pair<float, float> readAMChan( + AMACv2Field AMACv2RegMap::*field_to_read, // channel + std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> + fields_to_set, // mutexes + unsigned n_reads = 1, bool reset_mux = false); + + private: + std::shared_ptr<EndeavourCom> m_endeavour_com; // the driver of calls to HW + unsigned short m_amacid; + + double calibrateCounts(uint8_t ch, uint32_t counts); + + void syncReg(AMACv2Field AMACv2RegMap::*ref); + + double m_ADCslope = 1.; + uint32_t m_ADCoffset[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + uint8_t m_padid = 0; + uint8_t m_efuseid = 0; + + double m_NTCxCal = 250.; + double m_NTCyCal = 250.; + double m_NTCpbCal = 250.; + + double m_PTAT0 = 250.; // empirically derived + uint32_t m_CTAT0[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + + double m_Cur10VOffset = 200.; + double m_Cur1VOffset = 200.; + + // AMAC version-specific data: AM channels, etc + // AMACv2 as default + int amac_version_id = -1; // for version "unknown" + Version amac_version = + Version::unknown; // version is "unknown" but channel values are v2 + + // AMAC channels (version star?) + // uint8_t ch_VDCDC = 0; + // uint8_t ch_VDDLR = 12; + // uint8_t ch_VDDLRLo = 12; + // uint8_t ch_VDDLRHi = 12; + // uint8_t ch_DCDCIN = 1; + // uint8_t ch_VDDREG = 13; + // uint8_t ch_VDDBG = 15; + // uint8_t ch_AM900BG = 12; + // uint8_t ch_AM600BG = 12; + // uint8_t ch_CAL = 11; + // uint8_t ch_AMREF = 13; + // uint8_t ch_CALX = 15; + // uint8_t ch_CALY = 15; + // uint8_t ch_SHUNTX = 15; + // uint8_t ch_SHUNTY = 15; + // uint8_t ch_DCDCADJ = 13; + // uint8_t ch_CTAT = 5; + // uint8_t ch_NTCX = 2; + // uint8_t ch_NTCY = 3; + // uint8_t ch_NTCPB = 4; + // uint8_t ch_HREFX = 9; + // uint8_t ch_HREFY = 10; + // uint8_t ch_CUR10V = 13; + // uint8_t ch_CUR10VTPL = 14; + // uint8_t ch_CUR10VTPH = 14; + // uint8_t ch_CUR1V = 6; + // uint8_t ch_CUR1VTPL = 14; + // uint8_t ch_CUR1VTPH = 14; + // uint8_t ch_HVRET = 7; + // uint8_t ch_PTAT = 8; + + // better like this? + std::map<AM, uint8_t> m_ch_map; + + /* these are v2? + uint8_t CH_CUR10V = 12; + uint8_t CH_CUR10VTPL = 12; + uint8_t CH_CUR10VTPH = 12; + + uint8_t CH_CUR1V = 13; + uint8_t CH_CUR1VTPL = 13; + uint8_t CH_CUR1VTPH = 13; + */ }; namespace AMAC_INFO { - extern std::map<std::string,AMACv2Field AMACv2RegMap::*> channelmap_v2; - extern std::map<std::string,AMACv2Field AMACv2RegMap::*> channelmap_star; - extern std::map<std::string, std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> > muxmap_v2; - extern std::map<std::string, std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>> > muxmap_star; - extern std::map<AMACv2::AM, AMACv2Field AMACv2RegMap::*> am_channels_star; - extern std::map<AMACv2::AM, AMACv2Field AMACv2RegMap::*> am_channels_v2; -} - -#endif // AMACv2_H_ +extern std::map<std::string, AMACv2Field AMACv2RegMap::*> channelmap_v2; +extern std::map<std::string, AMACv2Field AMACv2RegMap::*> channelmap_star; +extern std::map<std::string, + std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>>> + muxmap_v2; +extern std::map<std::string, + std::vector<std::pair<AMACv2Field AMACv2RegMap::*, uint32_t>>> + muxmap_star; +extern std::map<AMACv2::AM, AMACv2Field AMACv2RegMap::*> am_channels_star; +extern std::map<AMACv2::AM, AMACv2Field AMACv2RegMap::*> am_channels_v2; +} // namespace AMAC_INFO + +#endif // AMACv2_H_ diff --git a/pbv3/AMACv2Field.cpp b/pbv3/AMACv2Field.cpp index 94f5fc0847eaeae569ce6e6404e6533d5b2c55ee..65a56d913c8a54ab7724c8f7df4c93e044e1c045 100644 --- a/pbv3/AMACv2Field.cpp +++ b/pbv3/AMACv2Field.cpp @@ -1,83 +1,71 @@ #include "AMACv2Field.h" -AMACv2Field::AMACv2Field(const std::string& fieldName, AMACv2Register *reg, uint8_t offset, uint8_t width, uint32_t defaultVal) - : m_fieldName(fieldName), m_register(reg), m_offset(offset), m_width(width), m_defaultVal(defaultVal) -{ - m_mask = (uint32_t) (((1 << m_width) - 1) << m_offset); - if(reg->isRW() != RO) - this->write(m_defaultVal); +AMACv2Field::AMACv2Field(const std::string& fieldName, AMACv2Register* reg, + uint8_t offset, uint8_t width, uint32_t defaultVal) + : m_fieldName(fieldName), + m_register(reg), + m_offset(offset), + m_width(width), + m_defaultVal(defaultVal) { + m_mask = (uint32_t)(((1 << m_width) - 1) << m_offset); + if (reg->isRW() != RO) this->write(m_defaultVal); } -bool AMACv2Field::isValid() const -{ return !m_fieldName.empty(); } +bool AMACv2Field::isValid() const { return !m_fieldName.empty(); } - -bool AMACv2Field::canBeWrittenField() const -{ - if(! isValid() ) return false; - return (m_register->isRW() != RO); +bool AMACv2Field::canBeWrittenField() const { + if (!isValid()) return false; + return (m_register->isRW() != RO); } -bool AMACv2Field::canBeReadField() const -{ - if(! isValid() ) return false; - return (m_register->isRW() != WO); +bool AMACv2Field::canBeReadField() const { + if (!isValid()) return false; + return (m_register->isRW() != WO); } -bool AMACv2Field::isReadWrite() const -{ - if(! isValid() ) return false; - return (m_register->isRW() == RW); +bool AMACv2Field::isReadWrite() const { + if (!isValid()) return false; + return (m_register->isRW() == RW); } -std::string AMACv2Field::getName() const -{ return m_fieldName; } +std::string AMACv2Field::getName() const { return m_fieldName; } -AMACv2Register* AMACv2Field::getRegister() const -{ return m_register; } +AMACv2Register* AMACv2Field::getRegister() const { return m_register; } -uint8_t AMACv2Field::getWidth() const -{ return m_width; } +uint8_t AMACv2Field::getWidth() const { return m_width; } -void AMACv2Field::setDefaultVal(uint32_t defaultVal) -{ - m_defaultVal=defaultVal; +void AMACv2Field::setDefaultVal(uint32_t defaultVal) { + m_defaultVal = defaultVal; } -void AMACv2Field::writeDefaultVal() -{ - if(! isValid() ) return; - if(m_register->isRW() == RO) - { - std::cerr << " --> Error: Read-only register \"" << m_fieldName <<"\""<< std::endl; - return; +void AMACv2Field::writeDefaultVal() { + if (!isValid()) return; + if (m_register->isRW() == RO) { + std::cerr << " --> Error: Read-only register \"" << m_fieldName << "\"" + << std::endl; + return; } - write(m_defaultVal); + write(m_defaultVal); } - -void AMACv2Field::write(const uint32_t& cfgBits) -{ - if(! isValid() ) return; - if(m_register->isRW() == RO) - { - std::cerr << " --> Error: Read-only register \"" << m_fieldName <<"\""<< std::endl; - return; +void AMACv2Field::write(const uint32_t& cfgBits) { + if (!isValid()) return; + if (m_register->isRW() == RO) { + std::cerr << " --> Error: Read-only register \"" << m_fieldName << "\"" + << std::endl; + return; } - uint32_t value=m_register->getValue(); - value = (value&~m_mask) | ((cfgBits << m_offset) & m_mask); - m_register->setValue(value); + uint32_t value = m_register->getValue(); + value = (value & ~m_mask) | ((cfgBits << m_offset) & m_mask); + m_register->setValue(value); } -uint32_t AMACv2Field::read() const -{ - if(! isValid() ) return 0; - if(m_register->isRW() == WO) - { - std::cerr << " --> Error: Write-only register \"" << m_fieldName <<"\""<< std::endl; - return 0; +uint32_t AMACv2Field::read() const { + if (!isValid()) return 0; + if (m_register->isRW() == WO) { + std::cerr << " --> Error: Write-only register \"" << m_fieldName << "\"" + << std::endl; + return 0; } - return ((m_register->getValue() & m_mask) >> m_offset); + return ((m_register->getValue() & m_mask) >> m_offset); } - - diff --git a/pbv3/AMACv2Field.h b/pbv3/AMACv2Field.h index 6ec864c9dd88dee61ab026edec7a4435d44b902d..9e0eeda86916a187888f7d29a72e0d5b9b4a2894 100644 --- a/pbv3/AMACv2Field.h +++ b/pbv3/AMACv2Field.h @@ -11,61 +11,61 @@ * A register field is a set of bits inside a register that * control a specific setting. */ -class AMACv2Field -{ -private: - //! The whole register - AMACv2Register *m_register = nullptr; - - //! Default field value - uint32_t m_defaultVal = 0; - - //! Number of bits - uint8_t m_width = 0; - - //! Position of the LSB - uint8_t m_offset = 0; - - //! Mask for updating register values - uint32_t m_mask = 0; - - //! Name of field - std::string m_fieldName = ""; -public: - //! Empty (invalid) field definition - AMACv2Field() =default; - - //! Define a bit field inside register `reg`. - AMACv2Field(const std::string& fieldName, AMACv2Register *reg, uint8_t offset, uint8_t width, uint32_t defaultVal); - - //! Valid field definition - bool isValid() const; - - bool canBeWrittenField() const; - bool canBeReadField() const; - bool isReadWrite() const; - - //! Get field name - /** - * \return name of the field - */ - std::string getName() const; - - //! Get underlaying register - AMACv2Register* getRegister() const; - - //! Get field width - /** - * \return width of field in bytes - */ - uint8_t getWidth() const; - - void setDefaultVal(uint32_t defaultVal); - void writeDefaultVal(); - - void write(const uint32_t& cfgBits); - uint32_t read() const; -}; +class AMACv2Field { + private: + //! The whole register + AMACv2Register* m_register = nullptr; + + //! Default field value + uint32_t m_defaultVal = 0; + + //! Number of bits + uint8_t m_width = 0; + + //! Position of the LSB + uint8_t m_offset = 0; + + //! Mask for updating register values + uint32_t m_mask = 0; + + //! Name of field + std::string m_fieldName = ""; + + public: + //! Empty (invalid) field definition + AMACv2Field() = default; + + //! Define a bit field inside register `reg`. + AMACv2Field(const std::string& fieldName, AMACv2Register* reg, + uint8_t offset, uint8_t width, uint32_t defaultVal); + //! Valid field definition + bool isValid() const; + + bool canBeWrittenField() const; + bool canBeReadField() const; + bool isReadWrite() const; + + //! Get field name + /** + * \return name of the field + */ + std::string getName() const; + + //! Get underlaying register + AMACv2Register* getRegister() const; + + //! Get field width + /** + * \return width of field in bytes + */ + uint8_t getWidth() const; + + void setDefaultVal(uint32_t defaultVal); + void writeDefaultVal(); + + void write(const uint32_t& cfgBits); + uint32_t read() const; +}; -#endif // AMACV2_FIELD_H +#endif // AMACV2_FIELD_H diff --git a/pbv3/AMACv2RegMap.cpp b/pbv3/AMACv2RegMap.cpp index 4e2f8d3b77ff75e0e99dc7c2b3f8909da5f07b36..da7f72dcd8fcc387a9725f9f5f446829da718234 100644 --- a/pbv3/AMACv2RegMap.cpp +++ b/pbv3/AMACv2RegMap.cpp @@ -2,466 +2,732 @@ #include <algorithm> -AMACv2RegMap::AMACv2RegMap() -{ - RegisterStatus = {"Status", 0, RO}; - RegisterSerNum = {"SerNum", 31, RO}; - RegisterFlagResets = {"FlagResets", 32, WO}; - SerNum = {"SerNum", &RegisterSerNum, 0, 24, 0x0}; - FlagResetF = {"FlagResetF", &RegisterFlagResets, 16, 1, 0x0 }; +AMACv2RegMap::AMACv2RegMap() { + RegisterStatus = {"Status", 0, RO}; + RegisterSerNum = {"SerNum", 31, RO}; + RegisterFlagResets = {"FlagResets", 32, WO}; + SerNum = {"SerNum", &RegisterSerNum, 0, 24, 0x0}; + FlagResetF = {"FlagResetF", &RegisterFlagResets, 16, 1, 0x0}; } -void AMACv2RegMap::init_regmap(Version version) -{ - switch(version) - { - case Version::v2: - init_v2(); - break; - case Version::star: - init_star(); - break; - default: - throw std::runtime_error("AMACv2RegMap: Unknown version"); - break; - } - // - // List of all available registers - m_registers = { - &AMACv2RegMap::RegisterStatus, &AMACv2RegMap::RegisterHxFlags, &AMACv2RegMap::RegisterHyFlags, &AMACv2RegMap::RegisterHyHxFlags, &AMACv2RegMap::RegisterHV0Flags, &AMACv2RegMap::RegisterHV2Flags, &AMACv2RegMap::RegisterHV2HV0Flags, &AMACv2RegMap::RegisterDCDCFlags, &AMACv2RegMap::RegisterWRNHxFlags, &AMACv2RegMap::RegisterWRNDCDCFlags, &AMACv2RegMap::RegisterSynFlags, - &AMACv2RegMap::RegisterValue0, &AMACv2RegMap::RegisterValue1, &AMACv2RegMap::RegisterValue2, &AMACv2RegMap::RegisterValue3, &AMACv2RegMap::RegisterValue4, &AMACv2RegMap::RegisterValue5, - &AMACv2RegMap::RegisterSEUstatus0, &AMACv2RegMap::RegisterSEUstatus1, - &AMACv2RegMap::RegisterSerNum, - &AMACv2RegMap::RegisterFlagResets, &AMACv2RegMap::RegisterLogicReset, &AMACv2RegMap::RegisterHardReset, - &AMACv2RegMap::RegisterCntSet, &AMACv2RegMap::RegisterCntSetC, &AMACv2RegMap::RegisterDCDCen, &AMACv2RegMap::RegisterDCDCenC, &AMACv2RegMap::RegisterIlock, &AMACv2RegMap::RegisterIlockC, &AMACv2RegMap::RegisterRstCnt, &AMACv2RegMap::RegisterRstCntC, &AMACv2RegMap::RegisterAMen, &AMACv2RegMap::RegisterAMenC, &AMACv2RegMap::RegisterAMpwr, &AMACv2RegMap::RegisterAMpwrC, &AMACv2RegMap::RegisterBgCnt, &AMACv2RegMap::RegisterAMCnt, &AMACv2RegMap::RegisterDACs0, &AMACv2RegMap::RegisterDACbias, &AMACv2RegMap::RegisterAMACCnt, &AMACv2RegMap::RegisterNTCRange, &AMACv2RegMap::RegisterLVCurCal, - &AMACv2RegMap::RegisterHxICfg, &AMACv2RegMap::RegisterHyICfg, &AMACv2RegMap::RegisterHyHxICfg, &AMACv2RegMap::RegisterHV0ICfg, &AMACv2RegMap::RegisterHV2ICfg, &AMACv2RegMap::RegisterHV2HV0ICfg, &AMACv2RegMap::RegisterDCDCICfg, &AMACv2RegMap::RegisterWRNICfg, &AMACv2RegMap::RegisterWRNDCDCICfg, - &AMACv2RegMap::RegisterHxTLUT, &AMACv2RegMap::RegisterHxModLUT1, &AMACv2RegMap::RegisterHxModLUT2, - &AMACv2RegMap::RegisterHyTLUT, &AMACv2RegMap::RegisterHyModLUT1, &AMACv2RegMap::RegisterHyModLUT2, - &AMACv2RegMap::RegisterHV0TLUT, &AMACv2RegMap::RegisterHV0ModLUT1, &AMACv2RegMap::RegisterHV0ModLUT2, - &AMACv2RegMap::RegisterHV2TLUT, &AMACv2RegMap::RegisterHV2ModLUT1, &AMACv2RegMap::RegisterHV2ModLUT2, - &AMACv2RegMap::RegisterDCDCTLUT, &AMACv2RegMap::RegisterDCDCModLUT1, &AMACv2RegMap::RegisterDCDCModLUT2, - &AMACv2RegMap::RegisterWRNTLUT, &AMACv2RegMap::RegisterWRNModLUT1, &AMACv2RegMap::RegisterWRNModLUT2, - &AMACv2RegMap::RegisterHxFlagEn, &AMACv2RegMap::RegisterHyFlagEn, &AMACv2RegMap::RegisterHyHxFlagEn, &AMACv2RegMap::RegisterHV0FlagEn, &AMACv2RegMap::RegisterHV2FlagEn, &AMACv2RegMap::RegisterHV2HV0FlagEn, &AMACv2RegMap::RegisterDCDCFlagEn, &AMACv2RegMap::RegisterSynFlagEn, &AMACv2RegMap::RegisterWRNDCDCFlagEn, - &AMACv2RegMap::RegisterHxTh0, &AMACv2RegMap::RegisterHxTh1, &AMACv2RegMap::RegisterHxTh2, &AMACv2RegMap::RegisterHxTh3, - &AMACv2RegMap::RegisterHyTh0, &AMACv2RegMap::RegisterHyTh1, &AMACv2RegMap::RegisterHyTh2, &AMACv2RegMap::RegisterHyTh3, - &AMACv2RegMap::RegisterHV0Th0, &AMACv2RegMap::RegisterHV0Th1, &AMACv2RegMap::RegisterHV0Th2, &AMACv2RegMap::RegisterHV0Th3, - &AMACv2RegMap::RegisterHV2Th0, &AMACv2RegMap::RegisterHV2Th1, &AMACv2RegMap::RegisterHV2Th2, &AMACv2RegMap::RegisterHV2Th3, - &AMACv2RegMap::RegisterDCDCTh0, &AMACv2RegMap::RegisterDCDCTh1, &AMACv2RegMap::RegisterDCDCTh2, &AMACv2RegMap::RegisterDCDCTh3, - &AMACv2RegMap::RegisterWRNTh0, &AMACv2RegMap::RegisterWRNTh1, &AMACv2RegMap::RegisterWRNTh2, &AMACv2RegMap::RegisterWRNTh3, - &AMACv2RegMap::RegisterHxLoTh0, &AMACv2RegMap::RegisterHxLoTh1, &AMACv2RegMap::RegisterHxLoTh2, &AMACv2RegMap::RegisterHxLoTh3, &AMACv2RegMap::RegisterHxLoTh4, &AMACv2RegMap::RegisterHxLoTh5, - &AMACv2RegMap::RegisterHxHiTh0, &AMACv2RegMap::RegisterHxHiTh1, &AMACv2RegMap::RegisterHxHiTh2, &AMACv2RegMap::RegisterHxHiTh3, &AMACv2RegMap::RegisterHxHiTh4, &AMACv2RegMap::RegisterHxHiTh5, - &AMACv2RegMap::RegisterHyLoTh0, &AMACv2RegMap::RegisterHyLoTh1, &AMACv2RegMap::RegisterHyLoTh2, &AMACv2RegMap::RegisterHyLoTh3, &AMACv2RegMap::RegisterHyLoTh4, &AMACv2RegMap::RegisterHyLoTh5, - &AMACv2RegMap::RegisterHyHiTh0, &AMACv2RegMap::RegisterHyHiTh1, &AMACv2RegMap::RegisterHyHiTh2, &AMACv2RegMap::RegisterHyHiTh3, &AMACv2RegMap::RegisterHyHiTh4, &AMACv2RegMap::RegisterHyHiTh5, - &AMACv2RegMap::RegisterHV0LoTh0, &AMACv2RegMap::RegisterHV0LoTh1, &AMACv2RegMap::RegisterHV0LoTh2, &AMACv2RegMap::RegisterHV0LoTh3, &AMACv2RegMap::RegisterHV0LoTh4, &AMACv2RegMap::RegisterHV0LoTh5, - &AMACv2RegMap::RegisterHV0HiTh0, &AMACv2RegMap::RegisterHV0HiTh1, &AMACv2RegMap::RegisterHV0HiTh2, &AMACv2RegMap::RegisterHV0HiTh3, &AMACv2RegMap::RegisterHV0HiTh4, &AMACv2RegMap::RegisterHV0HiTh5, - &AMACv2RegMap::RegisterHV2LoTh0, &AMACv2RegMap::RegisterHV2LoTh1, &AMACv2RegMap::RegisterHV2LoTh2, &AMACv2RegMap::RegisterHV2LoTh3, &AMACv2RegMap::RegisterHV2LoTh4, &AMACv2RegMap::RegisterHV2LoTh5, - &AMACv2RegMap::RegisterHV2HiTh0, &AMACv2RegMap::RegisterHV2HiTh1, &AMACv2RegMap::RegisterHV2HiTh2, &AMACv2RegMap::RegisterHV2HiTh3, &AMACv2RegMap::RegisterHV2HiTh4, &AMACv2RegMap::RegisterHV2HiTh5, - &AMACv2RegMap::RegisterDCDCLoTh0, &AMACv2RegMap::RegisterDCDCLoTh1, &AMACv2RegMap::RegisterDCDCLoTh2, &AMACv2RegMap::RegisterDCDCLoTh3, &AMACv2RegMap::RegisterDCDCLoTh4, &AMACv2RegMap::RegisterDCDCLoTh5, - &AMACv2RegMap::RegisterDCDCHiTh0, &AMACv2RegMap::RegisterDCDCHiTh1, &AMACv2RegMap::RegisterDCDCHiTh2, &AMACv2RegMap::RegisterDCDCHiTh3, &AMACv2RegMap::RegisterDCDCHiTh4, &AMACv2RegMap::RegisterDCDCHiTh5, - &AMACv2RegMap::RegisterWRNLoTh0, &AMACv2RegMap::RegisterWRNLoTh1, &AMACv2RegMap::RegisterWRNLoTh2, &AMACv2RegMap::RegisterWRNLoTh3, &AMACv2RegMap::RegisterWRNLoTh4, &AMACv2RegMap::RegisterWRNLoTh5, - &AMACv2RegMap::RegisterWRNHiTh0, &AMACv2RegMap::RegisterWRNHiTh1, &AMACv2RegMap::RegisterWRNHiTh2, &AMACv2RegMap::RegisterWRNHiTh3, &AMACv2RegMap::RegisterWRNHiTh4, &AMACv2RegMap::RegisterWRNHiTh5 - }; +void AMACv2RegMap::init_regmap(Version version) { + switch (version) { + case Version::v2: + init_v2(); + break; + case Version::star: + init_star(); + break; + default: + throw std::runtime_error("AMACv2RegMap: Unknown version"); + break; + } + // + // List of all available registers + m_registers = {&AMACv2RegMap::RegisterStatus, + &AMACv2RegMap::RegisterHxFlags, + &AMACv2RegMap::RegisterHyFlags, + &AMACv2RegMap::RegisterHyHxFlags, + &AMACv2RegMap::RegisterHV0Flags, + &AMACv2RegMap::RegisterHV2Flags, + &AMACv2RegMap::RegisterHV2HV0Flags, + &AMACv2RegMap::RegisterDCDCFlags, + &AMACv2RegMap::RegisterWRNHxFlags, + &AMACv2RegMap::RegisterWRNDCDCFlags, + &AMACv2RegMap::RegisterSynFlags, + &AMACv2RegMap::RegisterValue0, + &AMACv2RegMap::RegisterValue1, + &AMACv2RegMap::RegisterValue2, + &AMACv2RegMap::RegisterValue3, + &AMACv2RegMap::RegisterValue4, + &AMACv2RegMap::RegisterValue5, + &AMACv2RegMap::RegisterSEUstatus0, + &AMACv2RegMap::RegisterSEUstatus1, + &AMACv2RegMap::RegisterSerNum, + &AMACv2RegMap::RegisterFlagResets, + &AMACv2RegMap::RegisterLogicReset, + &AMACv2RegMap::RegisterHardReset, + &AMACv2RegMap::RegisterCntSet, + &AMACv2RegMap::RegisterCntSetC, + &AMACv2RegMap::RegisterDCDCen, + &AMACv2RegMap::RegisterDCDCenC, + &AMACv2RegMap::RegisterIlock, + &AMACv2RegMap::RegisterIlockC, + &AMACv2RegMap::RegisterRstCnt, + &AMACv2RegMap::RegisterRstCntC, + &AMACv2RegMap::RegisterAMen, + &AMACv2RegMap::RegisterAMenC, + &AMACv2RegMap::RegisterAMpwr, + &AMACv2RegMap::RegisterAMpwrC, + &AMACv2RegMap::RegisterBgCnt, + &AMACv2RegMap::RegisterAMCnt, + &AMACv2RegMap::RegisterDACs0, + &AMACv2RegMap::RegisterDACbias, + &AMACv2RegMap::RegisterAMACCnt, + &AMACv2RegMap::RegisterNTCRange, + &AMACv2RegMap::RegisterLVCurCal, + &AMACv2RegMap::RegisterHxICfg, + &AMACv2RegMap::RegisterHyICfg, + &AMACv2RegMap::RegisterHyHxICfg, + &AMACv2RegMap::RegisterHV0ICfg, + &AMACv2RegMap::RegisterHV2ICfg, + &AMACv2RegMap::RegisterHV2HV0ICfg, + &AMACv2RegMap::RegisterDCDCICfg, + &AMACv2RegMap::RegisterWRNICfg, + &AMACv2RegMap::RegisterWRNDCDCICfg, + &AMACv2RegMap::RegisterHxTLUT, + &AMACv2RegMap::RegisterHxModLUT1, + &AMACv2RegMap::RegisterHxModLUT2, + &AMACv2RegMap::RegisterHyTLUT, + &AMACv2RegMap::RegisterHyModLUT1, + &AMACv2RegMap::RegisterHyModLUT2, + &AMACv2RegMap::RegisterHV0TLUT, + &AMACv2RegMap::RegisterHV0ModLUT1, + &AMACv2RegMap::RegisterHV0ModLUT2, + &AMACv2RegMap::RegisterHV2TLUT, + &AMACv2RegMap::RegisterHV2ModLUT1, + &AMACv2RegMap::RegisterHV2ModLUT2, + &AMACv2RegMap::RegisterDCDCTLUT, + &AMACv2RegMap::RegisterDCDCModLUT1, + &AMACv2RegMap::RegisterDCDCModLUT2, + &AMACv2RegMap::RegisterWRNTLUT, + &AMACv2RegMap::RegisterWRNModLUT1, + &AMACv2RegMap::RegisterWRNModLUT2, + &AMACv2RegMap::RegisterHxFlagEn, + &AMACv2RegMap::RegisterHyFlagEn, + &AMACv2RegMap::RegisterHyHxFlagEn, + &AMACv2RegMap::RegisterHV0FlagEn, + &AMACv2RegMap::RegisterHV2FlagEn, + &AMACv2RegMap::RegisterHV2HV0FlagEn, + &AMACv2RegMap::RegisterDCDCFlagEn, + &AMACv2RegMap::RegisterSynFlagEn, + &AMACv2RegMap::RegisterWRNDCDCFlagEn, + &AMACv2RegMap::RegisterHxTh0, + &AMACv2RegMap::RegisterHxTh1, + &AMACv2RegMap::RegisterHxTh2, + &AMACv2RegMap::RegisterHxTh3, + &AMACv2RegMap::RegisterHyTh0, + &AMACv2RegMap::RegisterHyTh1, + &AMACv2RegMap::RegisterHyTh2, + &AMACv2RegMap::RegisterHyTh3, + &AMACv2RegMap::RegisterHV0Th0, + &AMACv2RegMap::RegisterHV0Th1, + &AMACv2RegMap::RegisterHV0Th2, + &AMACv2RegMap::RegisterHV0Th3, + &AMACv2RegMap::RegisterHV2Th0, + &AMACv2RegMap::RegisterHV2Th1, + &AMACv2RegMap::RegisterHV2Th2, + &AMACv2RegMap::RegisterHV2Th3, + &AMACv2RegMap::RegisterDCDCTh0, + &AMACv2RegMap::RegisterDCDCTh1, + &AMACv2RegMap::RegisterDCDCTh2, + &AMACv2RegMap::RegisterDCDCTh3, + &AMACv2RegMap::RegisterWRNTh0, + &AMACv2RegMap::RegisterWRNTh1, + &AMACv2RegMap::RegisterWRNTh2, + &AMACv2RegMap::RegisterWRNTh3, + &AMACv2RegMap::RegisterHxLoTh0, + &AMACv2RegMap::RegisterHxLoTh1, + &AMACv2RegMap::RegisterHxLoTh2, + &AMACv2RegMap::RegisterHxLoTh3, + &AMACv2RegMap::RegisterHxLoTh4, + &AMACv2RegMap::RegisterHxLoTh5, + &AMACv2RegMap::RegisterHxHiTh0, + &AMACv2RegMap::RegisterHxHiTh1, + &AMACv2RegMap::RegisterHxHiTh2, + &AMACv2RegMap::RegisterHxHiTh3, + &AMACv2RegMap::RegisterHxHiTh4, + &AMACv2RegMap::RegisterHxHiTh5, + &AMACv2RegMap::RegisterHyLoTh0, + &AMACv2RegMap::RegisterHyLoTh1, + &AMACv2RegMap::RegisterHyLoTh2, + &AMACv2RegMap::RegisterHyLoTh3, + &AMACv2RegMap::RegisterHyLoTh4, + &AMACv2RegMap::RegisterHyLoTh5, + &AMACv2RegMap::RegisterHyHiTh0, + &AMACv2RegMap::RegisterHyHiTh1, + &AMACv2RegMap::RegisterHyHiTh2, + &AMACv2RegMap::RegisterHyHiTh3, + &AMACv2RegMap::RegisterHyHiTh4, + &AMACv2RegMap::RegisterHyHiTh5, + &AMACv2RegMap::RegisterHV0LoTh0, + &AMACv2RegMap::RegisterHV0LoTh1, + &AMACv2RegMap::RegisterHV0LoTh2, + &AMACv2RegMap::RegisterHV0LoTh3, + &AMACv2RegMap::RegisterHV0LoTh4, + &AMACv2RegMap::RegisterHV0LoTh5, + &AMACv2RegMap::RegisterHV0HiTh0, + &AMACv2RegMap::RegisterHV0HiTh1, + &AMACv2RegMap::RegisterHV0HiTh2, + &AMACv2RegMap::RegisterHV0HiTh3, + &AMACv2RegMap::RegisterHV0HiTh4, + &AMACv2RegMap::RegisterHV0HiTh5, + &AMACv2RegMap::RegisterHV2LoTh0, + &AMACv2RegMap::RegisterHV2LoTh1, + &AMACv2RegMap::RegisterHV2LoTh2, + &AMACv2RegMap::RegisterHV2LoTh3, + &AMACv2RegMap::RegisterHV2LoTh4, + &AMACv2RegMap::RegisterHV2LoTh5, + &AMACv2RegMap::RegisterHV2HiTh0, + &AMACv2RegMap::RegisterHV2HiTh1, + &AMACv2RegMap::RegisterHV2HiTh2, + &AMACv2RegMap::RegisterHV2HiTh3, + &AMACv2RegMap::RegisterHV2HiTh4, + &AMACv2RegMap::RegisterHV2HiTh5, + &AMACv2RegMap::RegisterDCDCLoTh0, + &AMACv2RegMap::RegisterDCDCLoTh1, + &AMACv2RegMap::RegisterDCDCLoTh2, + &AMACv2RegMap::RegisterDCDCLoTh3, + &AMACv2RegMap::RegisterDCDCLoTh4, + &AMACv2RegMap::RegisterDCDCLoTh5, + &AMACv2RegMap::RegisterDCDCHiTh0, + &AMACv2RegMap::RegisterDCDCHiTh1, + &AMACv2RegMap::RegisterDCDCHiTh2, + &AMACv2RegMap::RegisterDCDCHiTh3, + &AMACv2RegMap::RegisterDCDCHiTh4, + &AMACv2RegMap::RegisterDCDCHiTh5, + &AMACv2RegMap::RegisterWRNLoTh0, + &AMACv2RegMap::RegisterWRNLoTh1, + &AMACv2RegMap::RegisterWRNLoTh2, + &AMACv2RegMap::RegisterWRNLoTh3, + &AMACv2RegMap::RegisterWRNLoTh4, + &AMACv2RegMap::RegisterWRNLoTh5, + &AMACv2RegMap::RegisterWRNHiTh0, + &AMACv2RegMap::RegisterWRNHiTh1, + &AMACv2RegMap::RegisterWRNHiTh2, + &AMACv2RegMap::RegisterWRNHiTh3, + &AMACv2RegMap::RegisterWRNHiTh4, + &AMACv2RegMap::RegisterWRNHiTh5}; - for(AMACv2Register AMACv2RegMap::* reg : m_registers) - { - m_regAddrMap[(this->*reg).getAddress()]=reg; - m_regMap [(this->*reg).getName ()]=reg; + for (AMACv2Register AMACv2RegMap::*reg : m_registers) { + m_regAddrMap[(this->*reg).getAddress()] = reg; + m_regMap[(this->*reg).getName()] = reg; } - - // - // List of all available fields - m_fields = - { - // Status - &AMACv2RegMap::StatusAM, &AMACv2RegMap::StatusWARN, &AMACv2RegMap::StatusDCDC, &AMACv2RegMap::StatusHV3, &AMACv2RegMap::StatusHV2, &AMACv2RegMap::StatusHV1, &AMACv2RegMap::StatusHV0, &AMACv2RegMap::StatusY2LDO, &AMACv2RegMap::StatusY1LDO, &AMACv2RegMap::StatusY0LDO, &AMACv2RegMap::StatusX2LDO, &AMACv2RegMap::StatusX1LDO, &AMACv2RegMap::StatusX0LDO, &AMACv2RegMap::StatusGPI, &AMACv2RegMap::StatusPGOOD, &AMACv2RegMap::StatusILockWARN, &AMACv2RegMap::StatusILockDCDC, &AMACv2RegMap::StatusILockHV2, &AMACv2RegMap::StatusILockHV0, &AMACv2RegMap::StatusILockYLDO, &AMACv2RegMap::StatusILockxLDO, &AMACv2RegMap::AMACVersion, - // HxFlags - &AMACv2RegMap::HxFlagsHi, &AMACv2RegMap::HxFlagsLo, &AMACv2RegMap::HxChFlags, - // HyFlags - &AMACv2RegMap::HyFlagsHi, &AMACv2RegMap::HyFlagsLo, &AMACv2RegMap::HyChFlags, - // HV0Flags - &AMACv2RegMap::HV0FlagsHi, &AMACv2RegMap::HV0FlagsLo, &AMACv2RegMap::HV0ChFlags, - // HV2Flags - &AMACv2RegMap::HV2FlagsHi, &AMACv2RegMap::HV2FlagsLo, &AMACv2RegMap::HV2ChFlags, - // DCDCFlags - &AMACv2RegMap::DCDCflagsHi, &AMACv2RegMap::DCDCflagsLo, &AMACv2RegMap::DCDCChFlags, - // WRNHxFlags - &AMACv2RegMap::WRNflagsHi, &AMACv2RegMap::WRNflagsLo, &AMACv2RegMap::WRNChFlags, - // SynFlags - &AMACv2RegMap::SynFlagsHx, &AMACv2RegMap::SynFlagsHy, &AMACv2RegMap::SynFlagsHV0, &AMACv2RegMap::SynFlagsHV2, &AMACv2RegMap::SynFlagsDCDC, &AMACv2RegMap::SynFlagsWRN, - // Value0 - &AMACv2RegMap::Value0AMen, &AMACv2RegMap::Ch0Value, &AMACv2RegMap::Ch1Value, &AMACv2RegMap::Ch2Value, - // Value1 - &AMACv2RegMap::Value1AMen, &AMACv2RegMap::Ch3Value, &AMACv2RegMap::Ch4Value, &AMACv2RegMap::Ch5Value, - // Value2 - &AMACv2RegMap::Value2AMen, &AMACv2RegMap::Ch6Value, &AMACv2RegMap::Ch7Value, &AMACv2RegMap::Ch8Value, - // Value3 - &AMACv2RegMap::Value3AMen, &AMACv2RegMap::Ch9Value, &AMACv2RegMap::Ch10Value, &AMACv2RegMap::Ch11Value, - // Value4 - &AMACv2RegMap::Value4AMen, &AMACv2RegMap::Ch12Value, &AMACv2RegMap::Ch13Value, &AMACv2RegMap::Ch14Value, &AMACv2RegMap::Ch12S, &AMACv2RegMap::Ch13S, - // Value5 - &AMACv2RegMap::Value5AMen, &AMACv2RegMap::Ch15Value, &AMACv2RegMap::Ch14S, &AMACv2RegMap::Ch15S, - // SEUstatus - &AMACv2RegMap::SEUStatusLo, &AMACv2RegMap::SEUStatusHi, - // SerNum - &AMACv2RegMap::PadID, &AMACv2RegMap::SerNum, - // FlagResets - &AMACv2RegMap::FlagResetOe, &AMACv2RegMap::FlagResetF, &AMACv2RegMap::FlagResetS, &AMACv2RegMap::FlagResetWRN, &AMACv2RegMap::FlagResetDCDC, &AMACv2RegMap::FlagResetHV2, &AMACv2RegMap::FlagResetHV0, &AMACv2RegMap::FlagResetXLDO, &AMACv2RegMap::FlagResetYLDO, - // LogicReset - &AMACv2RegMap::LogicReset, - // HardReset - &AMACv2RegMap::HardReset, - // CntSet - &AMACv2RegMap::CntSetHV3frq, &AMACv2RegMap::CntSetHV3en, &AMACv2RegMap::CntSetHV2frq, &AMACv2RegMap::CntSetHV2en, &AMACv2RegMap::CntSetHV1frq, &AMACv2RegMap::CntSetHV1en, &AMACv2RegMap::CntSetHV0frq, &AMACv2RegMap::CntSetHV0en, &AMACv2RegMap::CntSetHyLDO2en, &AMACv2RegMap::CntSetHyLDO1en, &AMACv2RegMap::CntSetHyLDO0en, &AMACv2RegMap::CntSetHxLDO2en, &AMACv2RegMap::CntSetHxLDO1en, &AMACv2RegMap::CntSetHxLDO0en, &AMACv2RegMap::CntSetWARN, - // CntSetC - &AMACv2RegMap::CntSetCHV3frq, &AMACv2RegMap::CntSetCHV3en, &AMACv2RegMap::CntSetCHV2frq, &AMACv2RegMap::CntSetCHV2en, &AMACv2RegMap::CntSetCHV1frq, &AMACv2RegMap::CntSetCHV1en, &AMACv2RegMap::CntSetCHV0frq, &AMACv2RegMap::CntSetCHV0en, &AMACv2RegMap::CntSetCHyLDO2en, &AMACv2RegMap::CntSetCHyLDO1en, &AMACv2RegMap::CntSetCHyLDO0en, &AMACv2RegMap::CntSetCHxLDO2en, &AMACv2RegMap::CntSetCHxLDO1en, &AMACv2RegMap::CntSetCHxLDO0en, &AMACv2RegMap::CntSetCWARN, - // DCDCen - &AMACv2RegMap::DCDCAdj, &AMACv2RegMap::DCDCen, - // DCDCenC - &AMACv2RegMap::DCDCAdjC, &AMACv2RegMap::DCDCenC, - // Ilock - &AMACv2RegMap::IlockHx, &AMACv2RegMap::IlockHy, &AMACv2RegMap::IlockHV0, &AMACv2RegMap::IlockHV2, &AMACv2RegMap::IlockDCDC, &AMACv2RegMap::IlockWRN, - // IlockC - &AMACv2RegMap::IlockCHx, &AMACv2RegMap::IlockCHy, &AMACv2RegMap::IlockCHV0, &AMACv2RegMap::IlockCHV2, &AMACv2RegMap::IlockCDCDC, &AMACv2RegMap::IlockCWRN, - // RstCnt - &AMACv2RegMap::RstCntHyHCCresetB, &AMACv2RegMap::RstCntHxHCCresetB, &AMACv2RegMap::RstCntOF, - // RstCntC - &AMACv2RegMap::RstCntCHyHCCresetB, &AMACv2RegMap::RstCntCHxHCCresetB, &AMACv2RegMap::RstCntCOF, - // AMen - &AMACv2RegMap::AMzeroCalib, &AMACv2RegMap::AMen, - // AMenC - &AMACv2RegMap::AMzeroCalibC, &AMACv2RegMap::AMenC, - // AMpwr - &AMACv2RegMap::ClockDisableEn, &AMACv2RegMap::ReqDCDCPGOOD, &AMACv2RegMap::DCDCenToPwrAMAC, - // AMpwrC - &AMACv2RegMap::ReqDCDCPGOODC, &AMACv2RegMap::DCDCenToPwrAMACC, - // BgCnt - &AMACv2RegMap::AMbgen, &AMACv2RegMap::AMbgSW, &AMACv2RegMap::AMbg, &AMACv2RegMap::VDDbgen, &AMACv2RegMap::VDDbgSW, &AMACv2RegMap::VDDbg, - // AMCnt - &AMACv2RegMap::AMCntRg, &AMACv2RegMap::AMintCalib, &AMACv2RegMap::Ch15Mux, &AMACv2RegMap::Ch14Mux, &AMACv2RegMap::Ch13Mux, &AMACv2RegMap::Ch12Mux, &AMACv2RegMap::Ch12AMux, &AMACv2RegMap::Ch5Mux, &AMACv2RegMap::Ch4Mux, &AMACv2RegMap::Ch3Mux, - // DACs0 - &AMACv2RegMap::DACShunty, &AMACv2RegMap::DACShuntx, &AMACv2RegMap::DACCaly, &AMACv2RegMap::DACCalx, - // DACbias - &AMACv2RegMap::DACbias, &AMACv2RegMap::ShuntEn, - // AMACCnt - &AMACv2RegMap::eFusebitSelect, &AMACv2RegMap::HVcurGain, &AMACv2RegMap::DRcomMode, &AMACv2RegMap::DRcurr, &AMACv2RegMap::ClkDis, &AMACv2RegMap::RingOscFrq, - // NTCRange - &AMACv2RegMap::CTAToffset, &AMACv2RegMap::NTCpbCal, &AMACv2RegMap::NTCpbSenseRange, &AMACv2RegMap::NTCy0Cal, &AMACv2RegMap::NTCy0SenseRange, &AMACv2RegMap::NTCx0Cal, &AMACv2RegMap::NTCx0SenseRange, - // LVCurCal - &AMACv2RegMap::DCDCoOffset, &AMACv2RegMap::DCDCoZeroReading, &AMACv2RegMap::DCDCoN, &AMACv2RegMap::DCDCoP, &AMACv2RegMap::DCDCiZeroReading, &AMACv2RegMap::DCDCiRangeSW, &AMACv2RegMap::DCDCiOffset, &AMACv2RegMap::DCDCiP, &AMACv2RegMap::DCDCiN, - // HxICfg - &AMACv2RegMap::HxFlagValid, &AMACv2RegMap::HxFlagValidEn, &AMACv2RegMap::HxFlagsLogic, &AMACv2RegMap::HxFlagsLatch, &AMACv2RegMap::HxLAM, - // HyICfg - &AMACv2RegMap::HyFlagValid, &AMACv2RegMap::HyFlagValidEn, &AMACv2RegMap::HyFlagsLogic, &AMACv2RegMap::HyFlagsLatch, &AMACv2RegMap::HyLAM, - // HV0ICfg - &AMACv2RegMap::HV0FlagValid, &AMACv2RegMap::HV0FlagValidEn, &AMACv2RegMap::HV0FlagsLogic, &AMACv2RegMap::HV0FlagsLatch, &AMACv2RegMap::HV0LAM, - // HV2ICfg - &AMACv2RegMap::HV2FlagValid, &AMACv2RegMap::HV2FlagValidEn, &AMACv2RegMap::HV2FlagsLogic, &AMACv2RegMap::HV2FlagsLatch, &AMACv2RegMap::HV2LAM, - // DCDCICfg - &AMACv2RegMap::DCDCFlagValid, &AMACv2RegMap::DCDCFlagValidEn, &AMACv2RegMap::DCDCFlagsLogic, &AMACv2RegMap::DCDCFlagsLatch, &AMACv2RegMap::DCDCLAM, - // WRNICfg - &AMACv2RegMap::WRNFlagValid, &AMACv2RegMap::WRNFlagValidEn, &AMACv2RegMap::WRNFlagsLogic, &AMACv2RegMap::WRNFlagsLatch, &AMACv2RegMap::WRNLAM, - // HxTLUT - &AMACv2RegMap::HxTlut, - // HxModLUT1 - &AMACv2RegMap::HxModlut1, - // HxModLUT2 - &AMACv2RegMap::HxModlut2, - // HyTLUT - &AMACv2RegMap::HyTlut, - // HyModLUT1 - &AMACv2RegMap::HyModlut1, - // HyModLUT2 - &AMACv2RegMap::HyModlut2, - // HV0TLUT - &AMACv2RegMap::HV0Tlut, - // HV0ModLUT1 - &AMACv2RegMap::HV0Modlut1, - // HV0ModLUT2 - &AMACv2RegMap::HV0Modlut2, - // HV2TLUT - &AMACv2RegMap::HV2Tlut, - // HV2ModLUT1 - &AMACv2RegMap::HV2Modlut1, - // HV2ModLUT2 - &AMACv2RegMap::HV2Modlut2, - // DCDCTLUT - &AMACv2RegMap::DCDCTlut, - // DCDCModLUT1 - &AMACv2RegMap::DCDCModlut1, - // DCDCModLUT2 - &AMACv2RegMap::DCDCModlut2, - // WRNTLUT - &AMACv2RegMap::WRNTlut, - // WRNModLUT1 - &AMACv2RegMap::WRNModlut1, - // WRNModLUT2 - &AMACv2RegMap::WRNModlut2, - // HxFlagEn - &AMACv2RegMap::HxFlagsEnHi, &AMACv2RegMap::HxFlagsEnLo, &AMACv2RegMap::HxILockFlagEn, - // HyFlagEn - &AMACv2RegMap::HyFlagsEnHi, &AMACv2RegMap::HyFlagsEnLo, &AMACv2RegMap::HyILockFlagEn, - // HV0FlagEn - &AMACv2RegMap::HV0FlagsEnHi, &AMACv2RegMap::HV0FlagsEnLo, &AMACv2RegMap::HV0ILockFlagEn, - // HV2FlagEn - &AMACv2RegMap::HV2FlagsEnHi, &AMACv2RegMap::HV2FlagsEnLo, &AMACv2RegMap::HV2ILockFlagEn, - // DCDCFlagEn - &AMACv2RegMap::DCDCFlagsEnHi, &AMACv2RegMap::DCDCFlagsEnLo, &AMACv2RegMap::DCDCILockFlagEn, - // SynFlagEn - &AMACv2RegMap::HyFlagEnSynY, &AMACv2RegMap::HxFlagEnSynX, &AMACv2RegMap::HV2FlagEnSynH2, &AMACv2RegMap::HV0FlagEnSynH0, &AMACv2RegMap::WRNDCDCFlagEnSynW, &AMACv2RegMap::WRNDCDCFlagEnSynDc, &AMACv2RegMap::WRNFlagsEnHi, &AMACv2RegMap::WRNFlagsEnLo, &AMACv2RegMap::WARNILockFlagEn, &AMACv2RegMap::WRNsynFlagEnHi, &AMACv2RegMap::WRNsynFlagEnLo, &AMACv2RegMap::DCDCsynFlagEnHi, &AMACv2RegMap::DCDCsynFlagEnLo, &AMACv2RegMap::HV2synFlagEnHi, &AMACv2RegMap::HV2synFlagEnLo, &AMACv2RegMap::HV0synFlagEnHi, &AMACv2RegMap::HV0synFlagEnLo, &AMACv2RegMap::HysynFlagEnHi, &AMACv2RegMap::HysynFlagEnLo, &AMACv2RegMap::HxsynFlagEnHi, &AMACv2RegMap::HxsynFlagEnLo, - // HxLoTh0 - &AMACv2RegMap::HxLoThCh0, &AMACv2RegMap::HxLoThCh1, &AMACv2RegMap::HxLoThCh2, - // HxLoTh1 - &AMACv2RegMap::HxLoThCh3, &AMACv2RegMap::HxLoThCh4, &AMACv2RegMap::HxLoThCh5, - // HxLoTh2 - &AMACv2RegMap::HxLoThCh6, &AMACv2RegMap::HxLoThCh7, &AMACv2RegMap::HxLoThCh8, - // HxLoTh3 - &AMACv2RegMap::HxLoThCh9, &AMACv2RegMap::HxLoThCh10, &AMACv2RegMap::HxLoThCh11, - // HxLoTh4 - &AMACv2RegMap::HxLoThCh12, &AMACv2RegMap::HxLoThCh13, &AMACv2RegMap::HxLoThCh14, - // HxLoTh5 - &AMACv2RegMap::HxLoThCh15, - // HxHiTh0 - &AMACv2RegMap::HxHiThCh0, &AMACv2RegMap::HxHiThCh1, &AMACv2RegMap::HxHiThCh2, - // HxHiTh1 - &AMACv2RegMap::HxHiThCh3, &AMACv2RegMap::HxHiThCh4, &AMACv2RegMap::HxHiThCh5, - // HxHiTh2 - &AMACv2RegMap::HxHiThCh6, &AMACv2RegMap::HxHiThCh7, &AMACv2RegMap::HxHiThCh8, - // HxHiTh3 - &AMACv2RegMap::HxHiThCh9, &AMACv2RegMap::HxHiThCh10, &AMACv2RegMap::HxHiThCh11, - // HxHiTh4 - &AMACv2RegMap::HxHiThCh12, &AMACv2RegMap::HxHiThCh13, &AMACv2RegMap::HxHiThCh14, - // HxHiTh5 - &AMACv2RegMap::HxHiThCh15, - // HyLoTh0 - &AMACv2RegMap::HyLoThCh0, &AMACv2RegMap::HyLoThCh1, &AMACv2RegMap::HyLoThCh2, - // HyLoTh1 - &AMACv2RegMap::HyLoThCh3, &AMACv2RegMap::HyLoThCh4, &AMACv2RegMap::HyLoThCh5, - // HyLoTh2 - &AMACv2RegMap::HyLoThCh6, &AMACv2RegMap::HyLoThCh7, &AMACv2RegMap::HyLoThCh8, - // HyLoTh3 - &AMACv2RegMap::HyLoThCh9, &AMACv2RegMap::HyLoThCh10, &AMACv2RegMap::HyLoThCh11, - // HyLoTh4 - &AMACv2RegMap::HyLoThCh12, &AMACv2RegMap::HyLoThCh13, &AMACv2RegMap::HyLoThCh14, - // HyLoTh5 - &AMACv2RegMap::HyLoThCh15, - // HyHiTh0 - &AMACv2RegMap::HyHiThCh0, &AMACv2RegMap::HyHiThCh1, &AMACv2RegMap::HyHiThCh2, - // HyHiTh1 - &AMACv2RegMap::HyHiThCh3, &AMACv2RegMap::HyHiThCh4, &AMACv2RegMap::HyHiThCh5, - // HyHiTh2 - &AMACv2RegMap::HyHiThCh6, &AMACv2RegMap::HyHiThCh7, &AMACv2RegMap::HyHiThCh8, - // HyHiTh3 - &AMACv2RegMap::HyHiThCh9, &AMACv2RegMap::HyHiThCh10, &AMACv2RegMap::HyHiThCh11, - // HyHiTh4 - &AMACv2RegMap::HyHiThCh12, &AMACv2RegMap::HyHiThCh13, &AMACv2RegMap::HyHiThCh14, - // HyHiTh5 - &AMACv2RegMap::HyHiThCh15, - // HV0LoTh0 - &AMACv2RegMap::HV0LoThCh0, &AMACv2RegMap::HV0LoThCh1, &AMACv2RegMap::HV0LoThCh2, - // HV0LoTh1 - &AMACv2RegMap::HV0LoThCh3, &AMACv2RegMap::HV0LoThCh4, &AMACv2RegMap::HV0LoThCh5, - // HV0LoTh2 - &AMACv2RegMap::HV0LoThCh6, &AMACv2RegMap::HV0LoThCh7, &AMACv2RegMap::HV0LoThCh8, - // HV0LoTh3 - &AMACv2RegMap::HV0LoThCh9, &AMACv2RegMap::HV0LoThCh10, &AMACv2RegMap::HV0LoThCh11, - // HV0LoTh4 - &AMACv2RegMap::HV0LoThCh12, &AMACv2RegMap::HV0LoThCh13, &AMACv2RegMap::HV0LoThCh14, - // HV0LoTh5 - &AMACv2RegMap::HV0LoThCh15, - // HV0HiTh0 - &AMACv2RegMap::HV0HiThCh0, &AMACv2RegMap::HV0HiThCh1, &AMACv2RegMap::HV0HiThCh2, - // HV0HiTh1 - &AMACv2RegMap::HV0HiThCh3, &AMACv2RegMap::HV0HiThCh4, &AMACv2RegMap::HV0HiThCh5, - // HV0HiTh2 - &AMACv2RegMap::HV0HiThCh6, &AMACv2RegMap::HV0HiThCh7, &AMACv2RegMap::HV0HiThCh8, - // HV0HiTh3 - &AMACv2RegMap::HV0HiThCh9, &AMACv2RegMap::HV0HiThCh10, &AMACv2RegMap::HV0HiThCh11, - // HV0HiTh4 - &AMACv2RegMap::HV0HiThCh12, &AMACv2RegMap::HV0HiThCh13, &AMACv2RegMap::HV0HiThCh14, - // HV0HiTh5 - &AMACv2RegMap::HV0HiThCh15, - // HV2HiTh0 - &AMACv2RegMap::HV2LoThCh0, &AMACv2RegMap::HV2LoThCh1, &AMACv2RegMap::HV2LoThCh2, - // HV2LoTh1 - &AMACv2RegMap::HV2LoThCh3, &AMACv2RegMap::HV2LoThCh4, &AMACv2RegMap::HV2LoThCh5, - // HV2LoTh2 - &AMACv2RegMap::HV2LoThCh6, &AMACv2RegMap::HV2LoThCh7, &AMACv2RegMap::HV2LoThCh8, - // HV2LoTh3 - &AMACv2RegMap::HV2LoThCh9, &AMACv2RegMap::HV2LoThCh10, &AMACv2RegMap::HV2LoThCh11, - // HV2LoTh4 - &AMACv2RegMap::HV2LoThCh12, &AMACv2RegMap::HV2LoThCh13, &AMACv2RegMap::HV2LoThCh14, - // HV2LoTh5 - &AMACv2RegMap::HV2LoThCh15, - // HV2HiTh0 - &AMACv2RegMap::HV2HiThCh0, &AMACv2RegMap::HV2HiThCh1, &AMACv2RegMap::HV2HiThCh2, - // HV2HiTh1 - &AMACv2RegMap::HV2HiThCh3, &AMACv2RegMap::HV2HiThCh4, &AMACv2RegMap::HV2HiThCh5, - // HV2HiTh2 - &AMACv2RegMap::HV2HiThCh6, &AMACv2RegMap::HV2HiThCh7, &AMACv2RegMap::HV2HiThCh8, - // HV2HiTh3 - &AMACv2RegMap::HV2HiThCh9, &AMACv2RegMap::HV2HiThCh10, &AMACv2RegMap::HV2HiThCh11, - // HV2HiTh4 - &AMACv2RegMap::HV2HiThCh12, &AMACv2RegMap::HV2HiThCh13, &AMACv2RegMap::HV2HiThCh14, - // HV2HiTh5 - &AMACv2RegMap::HV2HiThCh15, - // DCDCLoTh0 - &AMACv2RegMap::DCDCLoThCh0, &AMACv2RegMap::DCDCLoThCh1, &AMACv2RegMap::DCDCLoThCh2, - // DCDCLoTh1 - &AMACv2RegMap::DCDCLoThCh3, &AMACv2RegMap::DCDCLoThCh4, &AMACv2RegMap::DCDCLoThCh5, - // DCDCLoTh2 - &AMACv2RegMap::DCDCLoThCh6, &AMACv2RegMap::DCDCLoThCh7, &AMACv2RegMap::DCDCLoThCh8, - // DCDCLoTh3 - &AMACv2RegMap::DCDCLoThCh9, &AMACv2RegMap::DCDCLoThCh10, &AMACv2RegMap::DCDCLoThCh11, - // DCDCLoTh4 - &AMACv2RegMap::DCDCLoThCh12, &AMACv2RegMap::DCDCLoThCh13, &AMACv2RegMap::DCDCLoThCh14, - // DCDCLoTh5 - &AMACv2RegMap::DCDCLoThCh15, - // DCDCHiTh0 - &AMACv2RegMap::DCDCHiThCh0, &AMACv2RegMap::DCDCHiThCh1, &AMACv2RegMap::DCDCHiThCh2, - // DCDCHiTh1 - &AMACv2RegMap::DCDCHiThCh3, &AMACv2RegMap::DCDCHiThCh4, &AMACv2RegMap::DCDCHiThCh5, - // DCDCHiTh2 - &AMACv2RegMap::DCDCHiThCh6, &AMACv2RegMap::DCDCHiThCh7, &AMACv2RegMap::DCDCHiThCh8, - // DCDCHiTh3 - &AMACv2RegMap::DCDCHiThCh9, &AMACv2RegMap::DCDCHiThCh10, &AMACv2RegMap::DCDCHiThCh11, - // DCDCHiTh4 - &AMACv2RegMap::DCDCHiThCh12, &AMACv2RegMap::DCDCHiThCh13, &AMACv2RegMap::DCDCHiThCh14, - // DCDCHiTh5 - &AMACv2RegMap::DCDCHiThCh15, - // WRNLoTh0 - &AMACv2RegMap::WRNLoThCh0, &AMACv2RegMap::WRNLoThCh1, &AMACv2RegMap::WRNLoThCh2, - // WRNLoTh1 - &AMACv2RegMap::WRNLoThCh3, &AMACv2RegMap::WRNLoThCh4, &AMACv2RegMap::WRNLoThCh5, - // WRNLoTh2 - &AMACv2RegMap::WRNLoThCh6, &AMACv2RegMap::WRNLoThCh7, &AMACv2RegMap::WRNLoThCh8, - // WRNLoTh3 - &AMACv2RegMap::WRNLoThCh9, &AMACv2RegMap::WRNLoThCh10, &AMACv2RegMap::WRNLoThCh11, - // WRNLoTh4 - &AMACv2RegMap::WRNLoThCh12, &AMACv2RegMap::WRNLoThCh13, &AMACv2RegMap::WRNLoThCh14, - // WRNLoTh5 - &AMACv2RegMap::WRNLoThCh15, - // WRNHiTh0 - &AMACv2RegMap::WRNHiThCh0, &AMACv2RegMap::WRNHiThCh1, &AMACv2RegMap::WRNHiThCh2, - // WRNHiTh1 - &AMACv2RegMap::WRNHiThCh3, &AMACv2RegMap::WRNHiThCh4, &AMACv2RegMap::WRNHiThCh5, - // WRNHiTh2 - &AMACv2RegMap::WRNHiThCh6, &AMACv2RegMap::WRNHiThCh7, &AMACv2RegMap::WRNHiThCh8, - // WRNHiTh3 - &AMACv2RegMap::WRNHiThCh9, &AMACv2RegMap::WRNHiThCh10, &AMACv2RegMap::WRNHiThCh11, - // WRNHiTh4 - &AMACv2RegMap::WRNHiThCh12, &AMACv2RegMap::WRNHiThCh13, &AMACv2RegMap::WRNHiThCh14, - // WRNHiTh5 - &AMACv2RegMap::WRNHiThCh15 - }; + // + // List of all available fields + m_fields = { + // Status + &AMACv2RegMap::StatusAM, &AMACv2RegMap::StatusWARN, + &AMACv2RegMap::StatusDCDC, &AMACv2RegMap::StatusHV3, + &AMACv2RegMap::StatusHV2, &AMACv2RegMap::StatusHV1, + &AMACv2RegMap::StatusHV0, &AMACv2RegMap::StatusY2LDO, + &AMACv2RegMap::StatusY1LDO, &AMACv2RegMap::StatusY0LDO, + &AMACv2RegMap::StatusX2LDO, &AMACv2RegMap::StatusX1LDO, + &AMACv2RegMap::StatusX0LDO, &AMACv2RegMap::StatusGPI, + &AMACv2RegMap::StatusPGOOD, &AMACv2RegMap::StatusILockWARN, + &AMACv2RegMap::StatusILockDCDC, &AMACv2RegMap::StatusILockHV2, + &AMACv2RegMap::StatusILockHV0, &AMACv2RegMap::StatusILockYLDO, + &AMACv2RegMap::StatusILockxLDO, &AMACv2RegMap::AMACVersion, + // HxFlags + &AMACv2RegMap::HxFlagsHi, &AMACv2RegMap::HxFlagsLo, + &AMACv2RegMap::HxChFlags, + // HyFlags + &AMACv2RegMap::HyFlagsHi, &AMACv2RegMap::HyFlagsLo, + &AMACv2RegMap::HyChFlags, + // HV0Flags + &AMACv2RegMap::HV0FlagsHi, &AMACv2RegMap::HV0FlagsLo, + &AMACv2RegMap::HV0ChFlags, + // HV2Flags + &AMACv2RegMap::HV2FlagsHi, &AMACv2RegMap::HV2FlagsLo, + &AMACv2RegMap::HV2ChFlags, + // DCDCFlags + &AMACv2RegMap::DCDCflagsHi, &AMACv2RegMap::DCDCflagsLo, + &AMACv2RegMap::DCDCChFlags, + // WRNHxFlags + &AMACv2RegMap::WRNflagsHi, &AMACv2RegMap::WRNflagsLo, + &AMACv2RegMap::WRNChFlags, + // SynFlags + &AMACv2RegMap::SynFlagsHx, &AMACv2RegMap::SynFlagsHy, + &AMACv2RegMap::SynFlagsHV0, &AMACv2RegMap::SynFlagsHV2, + &AMACv2RegMap::SynFlagsDCDC, &AMACv2RegMap::SynFlagsWRN, + // Value0 + &AMACv2RegMap::Value0AMen, &AMACv2RegMap::Ch0Value, + &AMACv2RegMap::Ch1Value, &AMACv2RegMap::Ch2Value, + // Value1 + &AMACv2RegMap::Value1AMen, &AMACv2RegMap::Ch3Value, + &AMACv2RegMap::Ch4Value, &AMACv2RegMap::Ch5Value, + // Value2 + &AMACv2RegMap::Value2AMen, &AMACv2RegMap::Ch6Value, + &AMACv2RegMap::Ch7Value, &AMACv2RegMap::Ch8Value, + // Value3 + &AMACv2RegMap::Value3AMen, &AMACv2RegMap::Ch9Value, + &AMACv2RegMap::Ch10Value, &AMACv2RegMap::Ch11Value, + // Value4 + &AMACv2RegMap::Value4AMen, &AMACv2RegMap::Ch12Value, + &AMACv2RegMap::Ch13Value, &AMACv2RegMap::Ch14Value, + &AMACv2RegMap::Ch12S, &AMACv2RegMap::Ch13S, + // Value5 + &AMACv2RegMap::Value5AMen, &AMACv2RegMap::Ch15Value, + &AMACv2RegMap::Ch14S, &AMACv2RegMap::Ch15S, + // SEUstatus + &AMACv2RegMap::SEUStatusLo, &AMACv2RegMap::SEUStatusHi, + // SerNum + &AMACv2RegMap::PadID, &AMACv2RegMap::SerNum, + // FlagResets + &AMACv2RegMap::FlagResetOe, &AMACv2RegMap::FlagResetF, + &AMACv2RegMap::FlagResetS, &AMACv2RegMap::FlagResetWRN, + &AMACv2RegMap::FlagResetDCDC, &AMACv2RegMap::FlagResetHV2, + &AMACv2RegMap::FlagResetHV0, &AMACv2RegMap::FlagResetXLDO, + &AMACv2RegMap::FlagResetYLDO, + // LogicReset + &AMACv2RegMap::LogicReset, + // HardReset + &AMACv2RegMap::HardReset, + // CntSet + &AMACv2RegMap::CntSetHV3frq, &AMACv2RegMap::CntSetHV3en, + &AMACv2RegMap::CntSetHV2frq, &AMACv2RegMap::CntSetHV2en, + &AMACv2RegMap::CntSetHV1frq, &AMACv2RegMap::CntSetHV1en, + &AMACv2RegMap::CntSetHV0frq, &AMACv2RegMap::CntSetHV0en, + &AMACv2RegMap::CntSetHyLDO2en, &AMACv2RegMap::CntSetHyLDO1en, + &AMACv2RegMap::CntSetHyLDO0en, &AMACv2RegMap::CntSetHxLDO2en, + &AMACv2RegMap::CntSetHxLDO1en, &AMACv2RegMap::CntSetHxLDO0en, + &AMACv2RegMap::CntSetWARN, + // CntSetC + &AMACv2RegMap::CntSetCHV3frq, &AMACv2RegMap::CntSetCHV3en, + &AMACv2RegMap::CntSetCHV2frq, &AMACv2RegMap::CntSetCHV2en, + &AMACv2RegMap::CntSetCHV1frq, &AMACv2RegMap::CntSetCHV1en, + &AMACv2RegMap::CntSetCHV0frq, &AMACv2RegMap::CntSetCHV0en, + &AMACv2RegMap::CntSetCHyLDO2en, &AMACv2RegMap::CntSetCHyLDO1en, + &AMACv2RegMap::CntSetCHyLDO0en, &AMACv2RegMap::CntSetCHxLDO2en, + &AMACv2RegMap::CntSetCHxLDO1en, &AMACv2RegMap::CntSetCHxLDO0en, + &AMACv2RegMap::CntSetCWARN, + // DCDCen + &AMACv2RegMap::DCDCAdj, &AMACv2RegMap::DCDCen, + // DCDCenC + &AMACv2RegMap::DCDCAdjC, &AMACv2RegMap::DCDCenC, + // Ilock + &AMACv2RegMap::IlockHx, &AMACv2RegMap::IlockHy, &AMACv2RegMap::IlockHV0, + &AMACv2RegMap::IlockHV2, &AMACv2RegMap::IlockDCDC, + &AMACv2RegMap::IlockWRN, + // IlockC + &AMACv2RegMap::IlockCHx, &AMACv2RegMap::IlockCHy, + &AMACv2RegMap::IlockCHV0, &AMACv2RegMap::IlockCHV2, + &AMACv2RegMap::IlockCDCDC, &AMACv2RegMap::IlockCWRN, + // RstCnt + &AMACv2RegMap::RstCntHyHCCresetB, &AMACv2RegMap::RstCntHxHCCresetB, + &AMACv2RegMap::RstCntOF, + // RstCntC + &AMACv2RegMap::RstCntCHyHCCresetB, &AMACv2RegMap::RstCntCHxHCCresetB, + &AMACv2RegMap::RstCntCOF, + // AMen + &AMACv2RegMap::AMzeroCalib, &AMACv2RegMap::AMen, + // AMenC + &AMACv2RegMap::AMzeroCalibC, &AMACv2RegMap::AMenC, + // AMpwr + &AMACv2RegMap::ClockDisableEn, &AMACv2RegMap::ReqDCDCPGOOD, + &AMACv2RegMap::DCDCenToPwrAMAC, + // AMpwrC + &AMACv2RegMap::ReqDCDCPGOODC, &AMACv2RegMap::DCDCenToPwrAMACC, + // BgCnt + &AMACv2RegMap::AMbgen, &AMACv2RegMap::AMbgSW, &AMACv2RegMap::AMbg, + &AMACv2RegMap::VDDbgen, &AMACv2RegMap::VDDbgSW, &AMACv2RegMap::VDDbg, + // AMCnt + &AMACv2RegMap::AMCntRg, &AMACv2RegMap::AMintCalib, + &AMACv2RegMap::Ch15Mux, &AMACv2RegMap::Ch14Mux, &AMACv2RegMap::Ch13Mux, + &AMACv2RegMap::Ch12Mux, &AMACv2RegMap::Ch12AMux, &AMACv2RegMap::Ch5Mux, + &AMACv2RegMap::Ch4Mux, &AMACv2RegMap::Ch3Mux, + // DACs0 + &AMACv2RegMap::DACShunty, &AMACv2RegMap::DACShuntx, + &AMACv2RegMap::DACCaly, &AMACv2RegMap::DACCalx, + // DACbias + &AMACv2RegMap::DACbias, &AMACv2RegMap::ShuntEn, + // AMACCnt + &AMACv2RegMap::eFusebitSelect, &AMACv2RegMap::HVcurGain, + &AMACv2RegMap::DRcomMode, &AMACv2RegMap::DRcurr, &AMACv2RegMap::ClkDis, + &AMACv2RegMap::RingOscFrq, + // NTCRange + &AMACv2RegMap::CTAToffset, &AMACv2RegMap::NTCpbCal, + &AMACv2RegMap::NTCpbSenseRange, &AMACv2RegMap::NTCy0Cal, + &AMACv2RegMap::NTCy0SenseRange, &AMACv2RegMap::NTCx0Cal, + &AMACv2RegMap::NTCx0SenseRange, + // LVCurCal + &AMACv2RegMap::DCDCoOffset, &AMACv2RegMap::DCDCoZeroReading, + &AMACv2RegMap::DCDCoN, &AMACv2RegMap::DCDCoP, + &AMACv2RegMap::DCDCiZeroReading, &AMACv2RegMap::DCDCiRangeSW, + &AMACv2RegMap::DCDCiOffset, &AMACv2RegMap::DCDCiP, + &AMACv2RegMap::DCDCiN, + // HxICfg + &AMACv2RegMap::HxFlagValid, &AMACv2RegMap::HxFlagValidEn, + &AMACv2RegMap::HxFlagsLogic, &AMACv2RegMap::HxFlagsLatch, + &AMACv2RegMap::HxLAM, + // HyICfg + &AMACv2RegMap::HyFlagValid, &AMACv2RegMap::HyFlagValidEn, + &AMACv2RegMap::HyFlagsLogic, &AMACv2RegMap::HyFlagsLatch, + &AMACv2RegMap::HyLAM, + // HV0ICfg + &AMACv2RegMap::HV0FlagValid, &AMACv2RegMap::HV0FlagValidEn, + &AMACv2RegMap::HV0FlagsLogic, &AMACv2RegMap::HV0FlagsLatch, + &AMACv2RegMap::HV0LAM, + // HV2ICfg + &AMACv2RegMap::HV2FlagValid, &AMACv2RegMap::HV2FlagValidEn, + &AMACv2RegMap::HV2FlagsLogic, &AMACv2RegMap::HV2FlagsLatch, + &AMACv2RegMap::HV2LAM, + // DCDCICfg + &AMACv2RegMap::DCDCFlagValid, &AMACv2RegMap::DCDCFlagValidEn, + &AMACv2RegMap::DCDCFlagsLogic, &AMACv2RegMap::DCDCFlagsLatch, + &AMACv2RegMap::DCDCLAM, + // WRNICfg + &AMACv2RegMap::WRNFlagValid, &AMACv2RegMap::WRNFlagValidEn, + &AMACv2RegMap::WRNFlagsLogic, &AMACv2RegMap::WRNFlagsLatch, + &AMACv2RegMap::WRNLAM, + // HxTLUT + &AMACv2RegMap::HxTlut, + // HxModLUT1 + &AMACv2RegMap::HxModlut1, + // HxModLUT2 + &AMACv2RegMap::HxModlut2, + // HyTLUT + &AMACv2RegMap::HyTlut, + // HyModLUT1 + &AMACv2RegMap::HyModlut1, + // HyModLUT2 + &AMACv2RegMap::HyModlut2, + // HV0TLUT + &AMACv2RegMap::HV0Tlut, + // HV0ModLUT1 + &AMACv2RegMap::HV0Modlut1, + // HV0ModLUT2 + &AMACv2RegMap::HV0Modlut2, + // HV2TLUT + &AMACv2RegMap::HV2Tlut, + // HV2ModLUT1 + &AMACv2RegMap::HV2Modlut1, + // HV2ModLUT2 + &AMACv2RegMap::HV2Modlut2, + // DCDCTLUT + &AMACv2RegMap::DCDCTlut, + // DCDCModLUT1 + &AMACv2RegMap::DCDCModlut1, + // DCDCModLUT2 + &AMACv2RegMap::DCDCModlut2, + // WRNTLUT + &AMACv2RegMap::WRNTlut, + // WRNModLUT1 + &AMACv2RegMap::WRNModlut1, + // WRNModLUT2 + &AMACv2RegMap::WRNModlut2, + // HxFlagEn + &AMACv2RegMap::HxFlagsEnHi, &AMACv2RegMap::HxFlagsEnLo, + &AMACv2RegMap::HxILockFlagEn, + // HyFlagEn + &AMACv2RegMap::HyFlagsEnHi, &AMACv2RegMap::HyFlagsEnLo, + &AMACv2RegMap::HyILockFlagEn, + // HV0FlagEn + &AMACv2RegMap::HV0FlagsEnHi, &AMACv2RegMap::HV0FlagsEnLo, + &AMACv2RegMap::HV0ILockFlagEn, + // HV2FlagEn + &AMACv2RegMap::HV2FlagsEnHi, &AMACv2RegMap::HV2FlagsEnLo, + &AMACv2RegMap::HV2ILockFlagEn, + // DCDCFlagEn + &AMACv2RegMap::DCDCFlagsEnHi, &AMACv2RegMap::DCDCFlagsEnLo, + &AMACv2RegMap::DCDCILockFlagEn, + // SynFlagEn + &AMACv2RegMap::HyFlagEnSynY, &AMACv2RegMap::HxFlagEnSynX, + &AMACv2RegMap::HV2FlagEnSynH2, &AMACv2RegMap::HV0FlagEnSynH0, + &AMACv2RegMap::WRNDCDCFlagEnSynW, &AMACv2RegMap::WRNDCDCFlagEnSynDc, + &AMACv2RegMap::WRNFlagsEnHi, &AMACv2RegMap::WRNFlagsEnLo, + &AMACv2RegMap::WARNILockFlagEn, &AMACv2RegMap::WRNsynFlagEnHi, + &AMACv2RegMap::WRNsynFlagEnLo, &AMACv2RegMap::DCDCsynFlagEnHi, + &AMACv2RegMap::DCDCsynFlagEnLo, &AMACv2RegMap::HV2synFlagEnHi, + &AMACv2RegMap::HV2synFlagEnLo, &AMACv2RegMap::HV0synFlagEnHi, + &AMACv2RegMap::HV0synFlagEnLo, &AMACv2RegMap::HysynFlagEnHi, + &AMACv2RegMap::HysynFlagEnLo, &AMACv2RegMap::HxsynFlagEnHi, + &AMACv2RegMap::HxsynFlagEnLo, + // HxLoTh0 + &AMACv2RegMap::HxLoThCh0, &AMACv2RegMap::HxLoThCh1, + &AMACv2RegMap::HxLoThCh2, + // HxLoTh1 + &AMACv2RegMap::HxLoThCh3, &AMACv2RegMap::HxLoThCh4, + &AMACv2RegMap::HxLoThCh5, + // HxLoTh2 + &AMACv2RegMap::HxLoThCh6, &AMACv2RegMap::HxLoThCh7, + &AMACv2RegMap::HxLoThCh8, + // HxLoTh3 + &AMACv2RegMap::HxLoThCh9, &AMACv2RegMap::HxLoThCh10, + &AMACv2RegMap::HxLoThCh11, + // HxLoTh4 + &AMACv2RegMap::HxLoThCh12, &AMACv2RegMap::HxLoThCh13, + &AMACv2RegMap::HxLoThCh14, + // HxLoTh5 + &AMACv2RegMap::HxLoThCh15, + // HxHiTh0 + &AMACv2RegMap::HxHiThCh0, &AMACv2RegMap::HxHiThCh1, + &AMACv2RegMap::HxHiThCh2, + // HxHiTh1 + &AMACv2RegMap::HxHiThCh3, &AMACv2RegMap::HxHiThCh4, + &AMACv2RegMap::HxHiThCh5, + // HxHiTh2 + &AMACv2RegMap::HxHiThCh6, &AMACv2RegMap::HxHiThCh7, + &AMACv2RegMap::HxHiThCh8, + // HxHiTh3 + &AMACv2RegMap::HxHiThCh9, &AMACv2RegMap::HxHiThCh10, + &AMACv2RegMap::HxHiThCh11, + // HxHiTh4 + &AMACv2RegMap::HxHiThCh12, &AMACv2RegMap::HxHiThCh13, + &AMACv2RegMap::HxHiThCh14, + // HxHiTh5 + &AMACv2RegMap::HxHiThCh15, + // HyLoTh0 + &AMACv2RegMap::HyLoThCh0, &AMACv2RegMap::HyLoThCh1, + &AMACv2RegMap::HyLoThCh2, + // HyLoTh1 + &AMACv2RegMap::HyLoThCh3, &AMACv2RegMap::HyLoThCh4, + &AMACv2RegMap::HyLoThCh5, + // HyLoTh2 + &AMACv2RegMap::HyLoThCh6, &AMACv2RegMap::HyLoThCh7, + &AMACv2RegMap::HyLoThCh8, + // HyLoTh3 + &AMACv2RegMap::HyLoThCh9, &AMACv2RegMap::HyLoThCh10, + &AMACv2RegMap::HyLoThCh11, + // HyLoTh4 + &AMACv2RegMap::HyLoThCh12, &AMACv2RegMap::HyLoThCh13, + &AMACv2RegMap::HyLoThCh14, + // HyLoTh5 + &AMACv2RegMap::HyLoThCh15, + // HyHiTh0 + &AMACv2RegMap::HyHiThCh0, &AMACv2RegMap::HyHiThCh1, + &AMACv2RegMap::HyHiThCh2, + // HyHiTh1 + &AMACv2RegMap::HyHiThCh3, &AMACv2RegMap::HyHiThCh4, + &AMACv2RegMap::HyHiThCh5, + // HyHiTh2 + &AMACv2RegMap::HyHiThCh6, &AMACv2RegMap::HyHiThCh7, + &AMACv2RegMap::HyHiThCh8, + // HyHiTh3 + &AMACv2RegMap::HyHiThCh9, &AMACv2RegMap::HyHiThCh10, + &AMACv2RegMap::HyHiThCh11, + // HyHiTh4 + &AMACv2RegMap::HyHiThCh12, &AMACv2RegMap::HyHiThCh13, + &AMACv2RegMap::HyHiThCh14, + // HyHiTh5 + &AMACv2RegMap::HyHiThCh15, + // HV0LoTh0 + &AMACv2RegMap::HV0LoThCh0, &AMACv2RegMap::HV0LoThCh1, + &AMACv2RegMap::HV0LoThCh2, + // HV0LoTh1 + &AMACv2RegMap::HV0LoThCh3, &AMACv2RegMap::HV0LoThCh4, + &AMACv2RegMap::HV0LoThCh5, + // HV0LoTh2 + &AMACv2RegMap::HV0LoThCh6, &AMACv2RegMap::HV0LoThCh7, + &AMACv2RegMap::HV0LoThCh8, + // HV0LoTh3 + &AMACv2RegMap::HV0LoThCh9, &AMACv2RegMap::HV0LoThCh10, + &AMACv2RegMap::HV0LoThCh11, + // HV0LoTh4 + &AMACv2RegMap::HV0LoThCh12, &AMACv2RegMap::HV0LoThCh13, + &AMACv2RegMap::HV0LoThCh14, + // HV0LoTh5 + &AMACv2RegMap::HV0LoThCh15, + // HV0HiTh0 + &AMACv2RegMap::HV0HiThCh0, &AMACv2RegMap::HV0HiThCh1, + &AMACv2RegMap::HV0HiThCh2, + // HV0HiTh1 + &AMACv2RegMap::HV0HiThCh3, &AMACv2RegMap::HV0HiThCh4, + &AMACv2RegMap::HV0HiThCh5, + // HV0HiTh2 + &AMACv2RegMap::HV0HiThCh6, &AMACv2RegMap::HV0HiThCh7, + &AMACv2RegMap::HV0HiThCh8, + // HV0HiTh3 + &AMACv2RegMap::HV0HiThCh9, &AMACv2RegMap::HV0HiThCh10, + &AMACv2RegMap::HV0HiThCh11, + // HV0HiTh4 + &AMACv2RegMap::HV0HiThCh12, &AMACv2RegMap::HV0HiThCh13, + &AMACv2RegMap::HV0HiThCh14, + // HV0HiTh5 + &AMACv2RegMap::HV0HiThCh15, + // HV2HiTh0 + &AMACv2RegMap::HV2LoThCh0, &AMACv2RegMap::HV2LoThCh1, + &AMACv2RegMap::HV2LoThCh2, + // HV2LoTh1 + &AMACv2RegMap::HV2LoThCh3, &AMACv2RegMap::HV2LoThCh4, + &AMACv2RegMap::HV2LoThCh5, + // HV2LoTh2 + &AMACv2RegMap::HV2LoThCh6, &AMACv2RegMap::HV2LoThCh7, + &AMACv2RegMap::HV2LoThCh8, + // HV2LoTh3 + &AMACv2RegMap::HV2LoThCh9, &AMACv2RegMap::HV2LoThCh10, + &AMACv2RegMap::HV2LoThCh11, + // HV2LoTh4 + &AMACv2RegMap::HV2LoThCh12, &AMACv2RegMap::HV2LoThCh13, + &AMACv2RegMap::HV2LoThCh14, + // HV2LoTh5 + &AMACv2RegMap::HV2LoThCh15, + // HV2HiTh0 + &AMACv2RegMap::HV2HiThCh0, &AMACv2RegMap::HV2HiThCh1, + &AMACv2RegMap::HV2HiThCh2, + // HV2HiTh1 + &AMACv2RegMap::HV2HiThCh3, &AMACv2RegMap::HV2HiThCh4, + &AMACv2RegMap::HV2HiThCh5, + // HV2HiTh2 + &AMACv2RegMap::HV2HiThCh6, &AMACv2RegMap::HV2HiThCh7, + &AMACv2RegMap::HV2HiThCh8, + // HV2HiTh3 + &AMACv2RegMap::HV2HiThCh9, &AMACv2RegMap::HV2HiThCh10, + &AMACv2RegMap::HV2HiThCh11, + // HV2HiTh4 + &AMACv2RegMap::HV2HiThCh12, &AMACv2RegMap::HV2HiThCh13, + &AMACv2RegMap::HV2HiThCh14, + // HV2HiTh5 + &AMACv2RegMap::HV2HiThCh15, + // DCDCLoTh0 + &AMACv2RegMap::DCDCLoThCh0, &AMACv2RegMap::DCDCLoThCh1, + &AMACv2RegMap::DCDCLoThCh2, + // DCDCLoTh1 + &AMACv2RegMap::DCDCLoThCh3, &AMACv2RegMap::DCDCLoThCh4, + &AMACv2RegMap::DCDCLoThCh5, + // DCDCLoTh2 + &AMACv2RegMap::DCDCLoThCh6, &AMACv2RegMap::DCDCLoThCh7, + &AMACv2RegMap::DCDCLoThCh8, + // DCDCLoTh3 + &AMACv2RegMap::DCDCLoThCh9, &AMACv2RegMap::DCDCLoThCh10, + &AMACv2RegMap::DCDCLoThCh11, + // DCDCLoTh4 + &AMACv2RegMap::DCDCLoThCh12, &AMACv2RegMap::DCDCLoThCh13, + &AMACv2RegMap::DCDCLoThCh14, + // DCDCLoTh5 + &AMACv2RegMap::DCDCLoThCh15, + // DCDCHiTh0 + &AMACv2RegMap::DCDCHiThCh0, &AMACv2RegMap::DCDCHiThCh1, + &AMACv2RegMap::DCDCHiThCh2, + // DCDCHiTh1 + &AMACv2RegMap::DCDCHiThCh3, &AMACv2RegMap::DCDCHiThCh4, + &AMACv2RegMap::DCDCHiThCh5, + // DCDCHiTh2 + &AMACv2RegMap::DCDCHiThCh6, &AMACv2RegMap::DCDCHiThCh7, + &AMACv2RegMap::DCDCHiThCh8, + // DCDCHiTh3 + &AMACv2RegMap::DCDCHiThCh9, &AMACv2RegMap::DCDCHiThCh10, + &AMACv2RegMap::DCDCHiThCh11, + // DCDCHiTh4 + &AMACv2RegMap::DCDCHiThCh12, &AMACv2RegMap::DCDCHiThCh13, + &AMACv2RegMap::DCDCHiThCh14, + // DCDCHiTh5 + &AMACv2RegMap::DCDCHiThCh15, + // WRNLoTh0 + &AMACv2RegMap::WRNLoThCh0, &AMACv2RegMap::WRNLoThCh1, + &AMACv2RegMap::WRNLoThCh2, + // WRNLoTh1 + &AMACv2RegMap::WRNLoThCh3, &AMACv2RegMap::WRNLoThCh4, + &AMACv2RegMap::WRNLoThCh5, + // WRNLoTh2 + &AMACv2RegMap::WRNLoThCh6, &AMACv2RegMap::WRNLoThCh7, + &AMACv2RegMap::WRNLoThCh8, + // WRNLoTh3 + &AMACv2RegMap::WRNLoThCh9, &AMACv2RegMap::WRNLoThCh10, + &AMACv2RegMap::WRNLoThCh11, + // WRNLoTh4 + &AMACv2RegMap::WRNLoThCh12, &AMACv2RegMap::WRNLoThCh13, + &AMACv2RegMap::WRNLoThCh14, + // WRNLoTh5 + &AMACv2RegMap::WRNLoThCh15, + // WRNHiTh0 + &AMACv2RegMap::WRNHiThCh0, &AMACv2RegMap::WRNHiThCh1, + &AMACv2RegMap::WRNHiThCh2, + // WRNHiTh1 + &AMACv2RegMap::WRNHiThCh3, &AMACv2RegMap::WRNHiThCh4, + &AMACv2RegMap::WRNHiThCh5, + // WRNHiTh2 + &AMACv2RegMap::WRNHiThCh6, &AMACv2RegMap::WRNHiThCh7, + &AMACv2RegMap::WRNHiThCh8, + // WRNHiTh3 + &AMACv2RegMap::WRNHiThCh9, &AMACv2RegMap::WRNHiThCh10, + &AMACv2RegMap::WRNHiThCh11, + // WRNHiTh4 + &AMACv2RegMap::WRNHiThCh12, &AMACv2RegMap::WRNHiThCh13, + &AMACv2RegMap::WRNHiThCh14, + // WRNHiTh5 + &AMACv2RegMap::WRNHiThCh15}; - for(AMACv2Field AMACv2RegMap::* field : m_fields) - { - //std::cout << "AMACv2RegMap making field " << (this->*field).getName() << std::endl; - m_fieldMap[(this->*field).getName()]=field; - } + for (AMACv2Field AMACv2RegMap::*field : m_fields) { + // std::cout << "AMACv2RegMap making field " << (this->*field).getName() + // << std::endl; + m_fieldMap[(this->*field).getName()] = field; + } } -std::vector<const AMACv2Register*> AMACv2RegMap::getRegisters() const -{ - std::vector<const AMACv2Register*> registers(m_registers.size(), nullptr); - std::transform(m_registers.cbegin(), m_registers.cend(), - registers.begin(), - [this](AMACv2Register AMACv2RegMap::* reg) - { return (&(this->*reg)); }); - return registers; +std::vector<const AMACv2Register*> AMACv2RegMap::getRegisters() const { + std::vector<const AMACv2Register*> registers(m_registers.size(), nullptr); + std::transform( + m_registers.cbegin(), m_registers.cend(), registers.begin(), + [this](AMACv2Register AMACv2RegMap::*reg) { return (&(this->*reg)); }); + return registers; } -std::vector<const AMACv2Field*> AMACv2RegMap::getFields() const -{ - std::vector<const AMACv2Field*> fields; - fields.reserve(m_fieldMap.size()); - for(AMACv2Field AMACv2RegMap::* field : m_fields) fields.push_back(&(this->*field)); - return fields; +std::vector<const AMACv2Field*> AMACv2RegMap::getFields() const { + std::vector<const AMACv2Field*> fields; + fields.reserve(m_fieldMap.size()); + for (AMACv2Field AMACv2RegMap::*field : m_fields) + fields.push_back(&(this->*field)); + return fields; } -AMACv2Field* AMACv2RegMap::findField(AMACv2Field AMACv2RegMap::* ref) -{ - return &(this->*ref); +AMACv2Field* AMACv2RegMap::findField(AMACv2Field AMACv2RegMap::*ref) { + return &(this->*ref); } -AMACv2Field* AMACv2RegMap::findField(const std::string& fieldName) -{ - if(m_fieldMap.find(fieldName) != m_fieldMap.end()) - return &(this->*m_fieldMap[fieldName]); +AMACv2Field* AMACv2RegMap::findField(const std::string& fieldName) { + if (m_fieldMap.find(fieldName) != m_fieldMap.end()) + return &(this->*m_fieldMap[fieldName]); - return nullptr; + return nullptr; } -uint32_t AMACv2RegMap::getField(AMACv2Field AMACv2RegMap::* ref) -{ - return (this->*ref).read(); +uint32_t AMACv2RegMap::getField(AMACv2Field AMACv2RegMap::*ref) { + return (this->*ref).read(); } -uint32_t AMACv2RegMap::getField(const std::string& fieldName) -{ - if(m_fieldMap.find(fieldName) != m_fieldMap.end()) - return(this->*m_fieldMap[fieldName]).read(); - else - std::cerr << " --> Error: Could not find register \""<< fieldName << "\"" << std::endl; - return 0; +uint32_t AMACv2RegMap::getField(const std::string& fieldName) { + if (m_fieldMap.find(fieldName) != m_fieldMap.end()) + return (this->*m_fieldMap[fieldName]).read(); + else + std::cerr << " --> Error: Could not find register \"" << fieldName + << "\"" << std::endl; + return 0; } -uint32_t AMACv2RegMap::getReg(uint32_t reg) -{ - return (this->*m_regAddrMap[reg]).getValue(); +uint32_t AMACv2RegMap::getReg(uint32_t reg) { + return (this->*m_regAddrMap[reg]).getValue(); } -uint32_t AMACv2RegMap::getReg(AMACv2Register AMACv2RegMap::* ref) -{ - return (this->*ref).getValue(); +uint32_t AMACv2RegMap::getReg(AMACv2Register AMACv2RegMap::*ref) { + return (this->*ref).getValue(); } -void AMACv2RegMap::setField(AMACv2Field AMACv2RegMap::* ref, uint32_t value) -{ - (this->*ref).write(value); +void AMACv2RegMap::setField(AMACv2Field AMACv2RegMap::*ref, uint32_t value) { + (this->*ref).write(value); } -void AMACv2RegMap::setField(const std::string& fieldName, uint32_t value) -{ - if(m_fieldMap.find(fieldName) != m_fieldMap.end()) - return(this->*m_fieldMap[fieldName]).write(value); - else - std::cerr << " --> Error: Could not find register \""<< fieldName << "\"" << std::endl; - return; +void AMACv2RegMap::setField(const std::string& fieldName, uint32_t value) { + if (m_fieldMap.find(fieldName) != m_fieldMap.end()) + return (this->*m_fieldMap[fieldName]).write(value); + else + std::cerr << " --> Error: Could not find register \"" << fieldName + << "\"" << std::endl; + return; } -void AMACv2RegMap::setReg(uint32_t reg, uint32_t value) -{ - (this->*(m_regAddrMap[reg])).setValue(value); +void AMACv2RegMap::setReg(uint32_t reg, uint32_t value) { + (this->*(m_regAddrMap[reg])).setValue(value); } -void AMACv2RegMap::setReg(AMACv2Register AMACv2RegMap::* ref, uint32_t value) -{ - (this->*ref).setValue(value); +void AMACv2RegMap::setReg(AMACv2Register AMACv2RegMap::*ref, uint32_t value) { + (this->*ref).setValue(value); } -uint8_t AMACv2RegMap::getAddr(AMACv2Field AMACv2RegMap::* ref) -{ - return (this->*ref).getRegister()->getAddress(); +uint8_t AMACv2RegMap::getAddr(AMACv2Field AMACv2RegMap::*ref) { + return (this->*ref).getRegister()->getAddress(); } -uint8_t AMACv2RegMap::getAddr(const std::string& fieldName) -{ - if(m_fieldMap.find(fieldName) != m_fieldMap.end()) - return (this->*m_fieldMap[fieldName]).getRegister()->getAddress(); - else - std::cerr << " --> Error: Could not find register \""<< fieldName << "\"" << std::endl; - return 0; +uint8_t AMACv2RegMap::getAddr(const std::string& fieldName) { + if (m_fieldMap.find(fieldName) != m_fieldMap.end()) + return (this->*m_fieldMap[fieldName]).getRegister()->getAddress(); + else + std::cerr << " --> Error: Could not find register \"" << fieldName + << "\"" << std::endl; + return 0; } - -bool AMACv2RegMap::canBeWritten(AMACv2Field AMACv2RegMap::* ref) -{ - return (this->*ref).canBeWrittenField(); +bool AMACv2RegMap::canBeWritten(AMACv2Field AMACv2RegMap::*ref) { + return (this->*ref).canBeWrittenField(); } - - - - - diff --git a/pbv3/AMACv2RegMap.h b/pbv3/AMACv2RegMap.h index f3467d4bb4de6bb10e3a2a953a3758874acb3d22..cd5643f0290dbd768ff37b400e27591035070a03 100644 --- a/pbv3/AMACv2RegMap.h +++ b/pbv3/AMACv2RegMap.h @@ -1,901 +1,895 @@ #ifndef AMACREGMAP_H #define AMACREGMAP_H +#include <stdint.h> + +#include <iostream> #include <memory> +#include <string> #include <unordered_map> #include <vector> -#include <iostream> -#include <stdint.h> -#include <string> #include "AMACv2Field.h" - //! AMACv2 register map /** * Contains definition of all fields and registers inside AMAC */ -class AMACv2RegMap -{ -public: - //! Possible AMAC versions - enum class Version { - v2, - star, - unknown - }; - -private: - //! Initialize register map for AMACv2 - void init_v2(); - - //! Initialize register map for AMACstar - void init_star(); - -protected: - //! Initialize helper containers for looking up fields and registers - void init_regmap(Version version); - -public: - AMACv2RegMap(); - - std::vector<const AMACv2Register *> getRegisters() const; - std::vector<const AMACv2Field *> getFields() const; - - AMACv2Field* findField(AMACv2Field AMACv2RegMap::* ref); - AMACv2Field* findField(const std::string& fieldName); - - uint32_t getField(AMACv2Field AMACv2RegMap::* ref); - uint32_t getField(const std::string& fieldName); - - uint32_t getReg(uint32_t reg); - uint32_t getReg(AMACv2Register AMACv2RegMap::* ref); - - void setField(AMACv2Field AMACv2RegMap::* ref, uint32_t value); - void setField(const std::string& fieldName, uint32_t value); - - void setReg(uint32_t reg, uint32_t value); - void setReg(AMACv2Register AMACv2RegMap::* ref, uint32_t value); - - uint8_t getAddr(AMACv2Field AMACv2RegMap::* ref); - uint8_t getAddr(const std::string& fieldName); - - bool canBeWritten(AMACv2Field AMACv2RegMap::* ref); - - /** \name Registers - * @{ */ - AMACv2Register RegisterStatus ; - AMACv2Register RegisterHxFlags ; - AMACv2Register RegisterHyFlags ; - AMACv2Register RegisterHyHxFlags ; - AMACv2Register RegisterHV0Flags ; - AMACv2Register RegisterHV2Flags ; - AMACv2Register RegisterHV2HV0Flags ; - AMACv2Register RegisterDCDCFlags ; - AMACv2Register RegisterWRNHxFlags; - AMACv2Register RegisterWRNDCDCFlags; - AMACv2Register RegisterSynFlags ; - - AMACv2Register RegisterValue0; - AMACv2Register RegisterValue1; - AMACv2Register RegisterValue2; - AMACv2Register RegisterValue3; - AMACv2Register RegisterValue4; - AMACv2Register RegisterValue5; - - AMACv2Register RegisterSEUstatus0; - AMACv2Register RegisterSEUstatus1; - - AMACv2Register RegisterSerNum; - - AMACv2Register RegisterFlagResets; - AMACv2Register RegisterLogicReset; - AMACv2Register RegisterHardReset ; - - AMACv2Register RegisterCntSet ; - AMACv2Register RegisterCntSetC ; - AMACv2Register RegisterDCDCen ; - AMACv2Register RegisterDCDCenC ; - AMACv2Register RegisterIlock ; - AMACv2Register RegisterIlockC ; - AMACv2Register RegisterRstCnt ; - AMACv2Register RegisterRstCntC ; - AMACv2Register RegisterAMen ; - AMACv2Register RegisterAMenC ; - AMACv2Register RegisterAMpwr ; - AMACv2Register RegisterAMpwrC ; - AMACv2Register RegisterBgCnt ; - AMACv2Register RegisterAMCnt ; - AMACv2Register RegisterDACs0 ; - AMACv2Register RegisterDACbias ; - AMACv2Register RegisterAMACCnt ; - AMACv2Register RegisterNTCRange; - AMACv2Register RegisterLVCurCal; - - AMACv2Register RegisterHxICfg ; - AMACv2Register RegisterHyICfg ; - AMACv2Register RegisterHyHxICfg ; - AMACv2Register RegisterHV0ICfg ; - AMACv2Register RegisterHV2ICfg ; - AMACv2Register RegisterHV2HV0ICfg ; - AMACv2Register RegisterDCDCICfg; - AMACv2Register RegisterWRNICfg ; - AMACv2Register RegisterWRNDCDCICfg ; - - AMACv2Register RegisterHxTLUT ; - AMACv2Register RegisterHxModLUT1 ; - AMACv2Register RegisterHxModLUT2 ; - - AMACv2Register RegisterHyTLUT ; - AMACv2Register RegisterHyModLUT1 ; - AMACv2Register RegisterHyModLUT2 ; - - AMACv2Register RegisterHV0TLUT ; - AMACv2Register RegisterHV0ModLUT1 ; - AMACv2Register RegisterHV0ModLUT2 ; - - AMACv2Register RegisterHV2TLUT ; - AMACv2Register RegisterHV2ModLUT1 ; - AMACv2Register RegisterHV2ModLUT2 ; - - AMACv2Register RegisterDCDCTLUT ; - AMACv2Register RegisterDCDCModLUT1; - AMACv2Register RegisterDCDCModLUT2; - - AMACv2Register RegisterWRNTLUT ; - AMACv2Register RegisterWRNModLUT1 ; - AMACv2Register RegisterWRNModLUT2 ; - - AMACv2Register RegisterHxFlagEn ; - AMACv2Register RegisterHyFlagEn ; - AMACv2Register RegisterHyHxFlagEn ; - AMACv2Register RegisterHV0FlagEn ; - AMACv2Register RegisterHV2FlagEn ; - AMACv2Register RegisterHV2HV0FlagEn ; - AMACv2Register RegisterDCDCFlagEn; - AMACv2Register RegisterSynFlagEn ; - AMACv2Register RegisterWRNDCDCFlagEn ; - - AMACv2Register RegisterHxTh0 ; - AMACv2Register RegisterHxTh1 ; - AMACv2Register RegisterHxTh2 ; - AMACv2Register RegisterHxTh3 ; - - AMACv2Register RegisterHyTh0 ; - AMACv2Register RegisterHyTh1 ; - AMACv2Register RegisterHyTh2 ; - AMACv2Register RegisterHyTh3 ; - - AMACv2Register RegisterHV0Th0 ; - AMACv2Register RegisterHV0Th1 ; - AMACv2Register RegisterHV0Th2 ; - AMACv2Register RegisterHV0Th3 ; - - AMACv2Register RegisterHV2Th0 ; - AMACv2Register RegisterHV2Th1 ; - AMACv2Register RegisterHV2Th2 ; - AMACv2Register RegisterHV2Th3 ; - - AMACv2Register RegisterDCDCTh0 ; - AMACv2Register RegisterDCDCTh1 ; - AMACv2Register RegisterDCDCTh2 ; - AMACv2Register RegisterDCDCTh3 ; - - AMACv2Register RegisterWRNTh0 ; - AMACv2Register RegisterWRNTh1 ; - AMACv2Register RegisterWRNTh2 ; - AMACv2Register RegisterWRNTh3 ; - - AMACv2Register RegisterHxLoTh0 ; - AMACv2Register RegisterHxLoTh1 ; - AMACv2Register RegisterHxLoTh2 ; - AMACv2Register RegisterHxLoTh3 ; - AMACv2Register RegisterHxLoTh4 ; - AMACv2Register RegisterHxLoTh5 ; - - AMACv2Register RegisterHxHiTh0 ; - AMACv2Register RegisterHxHiTh1 ; - AMACv2Register RegisterHxHiTh2 ; - AMACv2Register RegisterHxHiTh3 ; - AMACv2Register RegisterHxHiTh4 ; - AMACv2Register RegisterHxHiTh5 ; - - AMACv2Register RegisterHyLoTh0 ; - AMACv2Register RegisterHyLoTh1 ; - AMACv2Register RegisterHyLoTh2 ; - AMACv2Register RegisterHyLoTh3 ; - AMACv2Register RegisterHyLoTh4 ; - AMACv2Register RegisterHyLoTh5 ; - - AMACv2Register RegisterHyHiTh0 ; - AMACv2Register RegisterHyHiTh1 ; - AMACv2Register RegisterHyHiTh2 ; - AMACv2Register RegisterHyHiTh3 ; - AMACv2Register RegisterHyHiTh4 ; - AMACv2Register RegisterHyHiTh5 ; - - AMACv2Register RegisterHV0LoTh0 ; - AMACv2Register RegisterHV0LoTh1 ; - AMACv2Register RegisterHV0LoTh2 ; - AMACv2Register RegisterHV0LoTh3 ; - AMACv2Register RegisterHV0LoTh4 ; - AMACv2Register RegisterHV0LoTh5 ; - - AMACv2Register RegisterHV0HiTh0 ; - AMACv2Register RegisterHV0HiTh1 ; - AMACv2Register RegisterHV0HiTh2 ; - AMACv2Register RegisterHV0HiTh3 ; - AMACv2Register RegisterHV0HiTh4 ; - AMACv2Register RegisterHV0HiTh5 ; - - AMACv2Register RegisterHV2LoTh0 ; - AMACv2Register RegisterHV2LoTh1 ; - AMACv2Register RegisterHV2LoTh2 ; - AMACv2Register RegisterHV2LoTh3 ; - AMACv2Register RegisterHV2LoTh4 ; - AMACv2Register RegisterHV2LoTh5 ; - - AMACv2Register RegisterHV2HiTh0 ; - AMACv2Register RegisterHV2HiTh1 ; - AMACv2Register RegisterHV2HiTh2 ; - AMACv2Register RegisterHV2HiTh3 ; - AMACv2Register RegisterHV2HiTh4 ; - AMACv2Register RegisterHV2HiTh5 ; - - AMACv2Register RegisterDCDCLoTh0; - AMACv2Register RegisterDCDCLoTh1; - AMACv2Register RegisterDCDCLoTh2; - AMACv2Register RegisterDCDCLoTh3; - AMACv2Register RegisterDCDCLoTh4; - AMACv2Register RegisterDCDCLoTh5; - - AMACv2Register RegisterDCDCHiTh0; - AMACv2Register RegisterDCDCHiTh1; - AMACv2Register RegisterDCDCHiTh2; - AMACv2Register RegisterDCDCHiTh3; - AMACv2Register RegisterDCDCHiTh4; - AMACv2Register RegisterDCDCHiTh5; - - AMACv2Register RegisterWRNLoTh0 ; - AMACv2Register RegisterWRNLoTh1 ; - AMACv2Register RegisterWRNLoTh2 ; - AMACv2Register RegisterWRNLoTh3 ; - AMACv2Register RegisterWRNLoTh4 ; - AMACv2Register RegisterWRNLoTh5 ; - - AMACv2Register RegisterWRNHiTh0 ; - AMACv2Register RegisterWRNHiTh1 ; - AMACv2Register RegisterWRNHiTh2 ; - AMACv2Register RegisterWRNHiTh3 ; - AMACv2Register RegisterWRNHiTh4 ; - AMACv2Register RegisterWRNHiTh5 ; - - /** @} */ - - /** \name Fields - * @{ */ - // Status registers - AMACv2Field StatusAM ; - AMACv2Field StatusWARN ; - AMACv2Field StatusDCDC ; - AMACv2Field StatusHV3 ; - AMACv2Field StatusHV2 ; - AMACv2Field StatusHV1 ; - AMACv2Field StatusHV0 ; - AMACv2Field StatusY2LDO ; - AMACv2Field StatusY1LDO ; - AMACv2Field StatusY0LDO ; - AMACv2Field StatusX2LDO ; - AMACv2Field StatusX1LDO ; - AMACv2Field StatusX0LDO ; - AMACv2Field StatusGPI ; - AMACv2Field StatusPGOOD ; - AMACv2Field StatusILockWARN; - AMACv2Field StatusILockDCDC; - AMACv2Field StatusILockHV2 ; - AMACv2Field StatusILockHV0 ; - AMACv2Field StatusILockYLDO; - AMACv2Field StatusILockxLDO; - AMACv2Field AMACVersion ; - // HxFlags - AMACv2Field HxFlagsHi ; - AMACv2Field HxFlagsLo ; - AMACv2Field HxChFlags; - // HyFlags - AMACv2Field HyFlagsHi ; - AMACv2Field HyFlagsLo ; - AMACv2Field HyChFlags; - // HV0Flags - AMACv2Field HV0FlagsHi ; - AMACv2Field HV0FlagsLo ; - AMACv2Field HV0ChFlags; - // HV2Flags - AMACv2Field HV2FlagsHi ; - AMACv2Field HV2FlagsLo ; - AMACv2Field HV2ChFlags; - // DCDCFlags - AMACv2Field DCDCflagsHi; - AMACv2Field DCDCflagsLo; - AMACv2Field DCDCChFlags; - // WRNHxFlags - AMACv2Field WRNflagsHi ; - AMACv2Field WRNflagsLo ; - AMACv2Field WRNChFlags; - // SynFlags - AMACv2Field SynFlagsHx ; - AMACv2Field SynFlagsHy ; - AMACv2Field SynFlagsHV0 ; - AMACv2Field SynFlagsHV2 ; - AMACv2Field SynFlagsDCDC; - AMACv2Field SynFlagsWRN ; - // Value0 - AMACv2Field Value0AMen; - AMACv2Field Ch0Value ; - AMACv2Field Ch1Value ; - AMACv2Field Ch2Value ; - // Value1 - AMACv2Field Value1AMen ; - AMACv2Field Ch3Value ; - AMACv2Field Ch4Value ; - AMACv2Field Ch5Value ; - // Value2 - AMACv2Field Value2AMen ; - AMACv2Field Ch6Value ; - AMACv2Field Ch7Value ; - AMACv2Field Ch8Value ; - // Value3 - AMACv2Field Value3AMen ; - AMACv2Field Ch9Value ; - AMACv2Field Ch10Value ; - AMACv2Field Ch11Value ; - // Value4 - AMACv2Field Value4AMen ; - AMACv2Field Ch12Value ; - AMACv2Field Ch13Value ; - AMACv2Field Ch14Value ; - AMACv2Field Ch12S ; - AMACv2Field Ch13S ; - // Value5 - AMACv2Field Value5AMen ; - AMACv2Field Ch15Value ; - AMACv2Field Ch14S ; - AMACv2Field Ch15S ; - // SEUstatus - AMACv2Field SEUStatusLo ; - AMACv2Field SEUStatusHi ; - // SerNum - AMACv2Field PadID ; - AMACv2Field SerNum ; - // FlagResets - AMACv2Field FlagResetOe ; - AMACv2Field FlagResetF ; - AMACv2Field FlagResetS ; - AMACv2Field FlagResetWRN ; - AMACv2Field FlagResetDCDC ; - AMACv2Field FlagResetHV2 ; - AMACv2Field FlagResetHV0 ; - AMACv2Field FlagResetXLDO ; - AMACv2Field FlagResetYLDO ; - // LogicReset - AMACv2Field LogicReset ; - // HardReset - AMACv2Field HardReset ; - // CntSet - AMACv2Field CntSetHV3frq ; - AMACv2Field CntSetHV3en ; - AMACv2Field CntSetHV2frq ; - AMACv2Field CntSetHV2en ; - AMACv2Field CntSetHV1frq ; - AMACv2Field CntSetHV1en ; - AMACv2Field CntSetHV0frq ; - AMACv2Field CntSetHV0en ; - AMACv2Field CntSetHyLDO2en ; - AMACv2Field CntSetHyLDO1en ; - AMACv2Field CntSetHyLDO0en ; - AMACv2Field CntSetHxLDO2en ; - AMACv2Field CntSetHxLDO1en ; - AMACv2Field CntSetHxLDO0en ; - AMACv2Field CntSetWARN ; - // CntSetC - AMACv2Field CntSetCHV3frq ; - AMACv2Field CntSetCHV3en ; - AMACv2Field CntSetCHV2frq ; - AMACv2Field CntSetCHV2en ; - AMACv2Field CntSetCHV1frq ; - AMACv2Field CntSetCHV1en ; - AMACv2Field CntSetCHV0frq ; - AMACv2Field CntSetCHV0en ; - AMACv2Field CntSetCHyLDO2en ; - AMACv2Field CntSetCHyLDO1en ; - AMACv2Field CntSetCHyLDO0en ; - AMACv2Field CntSetCHxLDO2en ; - AMACv2Field CntSetCHxLDO1en ; - AMACv2Field CntSetCHxLDO0en ; - AMACv2Field CntSetCWARN ; - // DCDCen - AMACv2Field DCDCAdj ; - AMACv2Field DCDCen ; - // DCDCenC - AMACv2Field DCDCAdjC ; - AMACv2Field DCDCenC ; - // Ilock - AMACv2Field IlockHx ; - AMACv2Field IlockHy ; - AMACv2Field IlockHV0 ; - AMACv2Field IlockHV2 ; - AMACv2Field IlockDCDC; - AMACv2Field IlockWRN ; - // IlockC - AMACv2Field IlockCHx ; - AMACv2Field IlockCHy ; - AMACv2Field IlockCHV0 ; - AMACv2Field IlockCHV2 ; - AMACv2Field IlockCDCDC; - AMACv2Field IlockCWRN ; - // RstCnt - AMACv2Field RstCntHyHCCresetB ; - AMACv2Field RstCntHxHCCresetB ; - AMACv2Field RstCntOF ; - // RstCntC - AMACv2Field RstCntCHyHCCresetB ; - AMACv2Field RstCntCHxHCCresetB ; - AMACv2Field RstCntCOF ; - // AMen - AMACv2Field AMzeroCalib ; - AMACv2Field AMen ; - // AMenC - AMACv2Field AMzeroCalibC ; - AMACv2Field AMenC ; - // AMpwr - AMACv2Field ClockDisableEn ; - AMACv2Field ReqDCDCPGOOD ; - AMACv2Field DCDCenToPwrAMAC ; - // AMpwrC - AMACv2Field ReqDCDCPGOODC ; - AMACv2Field DCDCenToPwrAMACC ; - // BgCnt - AMACv2Field AMbgen ; - AMACv2Field AMbgSW ; - AMACv2Field AMbg ; - AMACv2Field VDDbgen ; - AMACv2Field VDDbgSW ; - AMACv2Field VDDbg ; - // AMCnt - AMACv2Field AMCntRg ; - AMACv2Field AMintCalib ; - AMACv2Field Ch15Mux ; - AMACv2Field Ch14Mux ; - AMACv2Field Ch13Mux ; - AMACv2Field Ch12Mux ; - AMACv2Field Ch12AMux ; - AMACv2Field Ch5Mux ; - AMACv2Field Ch4Mux ; - AMACv2Field Ch3Mux ; - // DACs0 - AMACv2Field DACShunty ; - AMACv2Field DACShuntx ; - AMACv2Field DACCaly ; - AMACv2Field DACCalx ; - // DACbias - AMACv2Field DACbias ; - AMACv2Field ShuntEn ; - // AMACCnt - AMACv2Field eFusebitSelect ; - AMACv2Field HVcurGain ; - AMACv2Field DRcomMode ; - AMACv2Field DRcurr ; - AMACv2Field ClkDis ; - AMACv2Field RingOscFrq ; - // NTCRange - AMACv2Field CTAToffset ; - AMACv2Field NTCpbCal ; - AMACv2Field NTCpbSenseRange ; - AMACv2Field NTCy0Cal ; - AMACv2Field NTCy0SenseRange ; - AMACv2Field NTCx0Cal ; - AMACv2Field NTCx0SenseRange ; - // LVCurCal - AMACv2Field DCDCoOffset ; - AMACv2Field DCDCoZeroReading ; - AMACv2Field DCDCoN ; - AMACv2Field DCDCoP ; - AMACv2Field DCDCiZeroReading ; - AMACv2Field DCDCiRangeSW ; - AMACv2Field DCDCiOffset ; - AMACv2Field DCDCiP ; - AMACv2Field DCDCiN ; - // HxICfg - AMACv2Field HxFlagValid ; - AMACv2Field HxFlagValidEn; - AMACv2Field HxFlagsLogic ; - AMACv2Field HxFlagsLatch ; - AMACv2Field HxLAM ; - // HyICfg - AMACv2Field HyFlagValid ; - AMACv2Field HyFlagValidEn; - AMACv2Field HyFlagsLogic ; - AMACv2Field HyFlagsLatch ; - AMACv2Field HyLAM ; - // HV0ICfg - AMACv2Field HV0FlagValid ; - AMACv2Field HV0FlagValidEn; - AMACv2Field HV0FlagsLogic ; - AMACv2Field HV0FlagsLatch ; - AMACv2Field HV0LAM ; - // HV2ICfg - AMACv2Field HV2FlagValid ; - AMACv2Field HV2FlagValidEn; - AMACv2Field HV2FlagsLogic ; - AMACv2Field HV2FlagsLatch ; - AMACv2Field HV2LAM ; - // DCDCICfg - AMACv2Field DCDCFlagValid ; - AMACv2Field DCDCFlagValidEn; - AMACv2Field DCDCFlagsLogic ; - AMACv2Field DCDCFlagsLatch ; - AMACv2Field DCDCLAM ; - // WRNICfg - AMACv2Field WRNFlagValid ; - AMACv2Field WRNFlagValidEn; - AMACv2Field WRNFlagsLogic ; - AMACv2Field WRNFlagsLatch ; - AMACv2Field WRNLAM ; - // HxTLUT - AMACv2Field HxTlut ; - // HxModLUT1 - AMACv2Field HxModlut1 ; - // HxModLUT2 - AMACv2Field HxModlut2 ; - // HyTLUT - AMACv2Field HyTlut ; - // HyModLUT1 - AMACv2Field HyModlut1 ; - // HyModLUT2 - AMACv2Field HyModlut2 ; - // HV0TLUT - AMACv2Field HV0Tlut ; - // HV0ModLUT1 - AMACv2Field HV0Modlut1 ; - // HV0ModLUT2 - AMACv2Field HV0Modlut2 ; - // HV2TLUT - AMACv2Field HV2Tlut ; - // HV2ModLUT1 - AMACv2Field HV2Modlut1 ; - // HV2ModLUT2 - AMACv2Field HV2Modlut2 ; - // DCDCTLUT - AMACv2Field DCDCTlut ; - // DCDCModLUT1 - AMACv2Field DCDCModlut1 ; - // DCDCModLUT2 - AMACv2Field DCDCModlut2 ; - // WRNTLUT - AMACv2Field WRNTlut ; - // WRNModLUT1 - AMACv2Field WRNModlut1 ; - // WRNModLUT2 - AMACv2Field WRNModlut2 ; - // HxFlagEn - AMACv2Field HxFlagsEnHi ; - AMACv2Field HxFlagsEnLo ; - AMACv2Field HxILockFlagEn ; - // HyFlagEn - AMACv2Field HyFlagsEnHi ; - AMACv2Field HyFlagsEnLo ; - AMACv2Field HyILockFlagEn ; - // HV0FlagEn - AMACv2Field HV0FlagsEnHi ; - AMACv2Field HV0FlagsEnLo ; - AMACv2Field HV0ILockFlagEn ; - // HV2FlagEn - AMACv2Field HV2FlagsEnHi ; - AMACv2Field HV2FlagsEnLo ; - AMACv2Field HV2ILockFlagEn ; - // DCDCFlagEn - AMACv2Field DCDCFlagsEnHi ; - AMACv2Field DCDCFlagsEnLo ; - AMACv2Field DCDCILockFlagEn ; - // SynFlagEn - AMACv2Field HyFlagEnSynY ; - AMACv2Field HxFlagEnSynX ; - AMACv2Field HV2FlagEnSynH2 ; - AMACv2Field HV0FlagEnSynH0 ; - AMACv2Field WRNDCDCFlagEnSynW ; - AMACv2Field WRNDCDCFlagEnSynDc ; - AMACv2Field WRNFlagsEnHi ; - AMACv2Field WRNFlagsEnLo ; - AMACv2Field WARNILockFlagEn ; - AMACv2Field WRNsynFlagEnHi ; - AMACv2Field WRNsynFlagEnLo ; - AMACv2Field DCDCsynFlagEnHi ; - AMACv2Field DCDCsynFlagEnLo ; - AMACv2Field HV2synFlagEnHi ; - AMACv2Field HV2synFlagEnLo ; - AMACv2Field HV0synFlagEnHi ; - AMACv2Field HV0synFlagEnLo ; - AMACv2Field HysynFlagEnHi ; - AMACv2Field HysynFlagEnLo ; - AMACv2Field HxsynFlagEnHi ; - AMACv2Field HxsynFlagEnLo ; - // HxLoTh0 - AMACv2Field HxLoThCh0 ; - AMACv2Field HxLoThCh1 ; - AMACv2Field HxLoThCh2 ; - // HxLoTh1 - AMACv2Field HxLoThCh3 ; - AMACv2Field HxLoThCh4 ; - AMACv2Field HxLoThCh5 ; - // HxLoTh2 - AMACv2Field HxLoThCh6 ; - AMACv2Field HxLoThCh7 ; - AMACv2Field HxLoThCh8 ; - // HxLoTh3 - AMACv2Field HxLoThCh9 ; - AMACv2Field HxLoThCh10 ; - AMACv2Field HxLoThCh11 ; - // HxLoTh4 - AMACv2Field HxLoThCh12 ; - AMACv2Field HxLoThCh13 ; - AMACv2Field HxLoThCh14 ; - // HxLoTh5 - AMACv2Field HxLoThCh15 ; - // HxHiTh0 - AMACv2Field HxHiThCh0 ; - AMACv2Field HxHiThCh1 ; - AMACv2Field HxHiThCh2 ; - // HxHiTh1 - AMACv2Field HxHiThCh3 ; - AMACv2Field HxHiThCh4 ; - AMACv2Field HxHiThCh5 ; - // HxHiTh2 - AMACv2Field HxHiThCh6 ; - AMACv2Field HxHiThCh7 ; - AMACv2Field HxHiThCh8 ; - // HxHiTh3 - AMACv2Field HxHiThCh9 ; - AMACv2Field HxHiThCh10 ; - AMACv2Field HxHiThCh11 ; - // HxHiTh4 - AMACv2Field HxHiThCh12 ; - AMACv2Field HxHiThCh13 ; - AMACv2Field HxHiThCh14 ; - // HxHiTh5 - AMACv2Field HxHiThCh15 ; - // HyLoTh0 - AMACv2Field HyLoThCh0 ; - AMACv2Field HyLoThCh1 ; - AMACv2Field HyLoThCh2 ; - // HyLoTh1 - AMACv2Field HyLoThCh3 ; - AMACv2Field HyLoThCh4 ; - AMACv2Field HyLoThCh5 ; - // HyLoTh2 - AMACv2Field HyLoThCh6 ; - AMACv2Field HyLoThCh7 ; - AMACv2Field HyLoThCh8 ; - // HyLoTh3 - AMACv2Field HyLoThCh9 ; - AMACv2Field HyLoThCh10 ; - AMACv2Field HyLoThCh11 ; - // HyLoTh4 - AMACv2Field HyLoThCh12 ; - AMACv2Field HyLoThCh13 ; - AMACv2Field HyLoThCh14 ; - // HyLoTh5 - AMACv2Field HyLoThCh15 ; - // HyHiTh0 - AMACv2Field HyHiThCh0 ; - AMACv2Field HyHiThCh1 ; - AMACv2Field HyHiThCh2 ; - // HyHiTh1 - AMACv2Field HyHiThCh3 ; - AMACv2Field HyHiThCh4 ; - AMACv2Field HyHiThCh5 ; - // HyHiTh2 - AMACv2Field HyHiThCh6 ; - AMACv2Field HyHiThCh7 ; - AMACv2Field HyHiThCh8 ; - // HyHiTh3 - AMACv2Field HyHiThCh9 ; - AMACv2Field HyHiThCh10 ; - AMACv2Field HyHiThCh11 ; - // HyHiTh4 - AMACv2Field HyHiThCh12 ; - AMACv2Field HyHiThCh13 ; - AMACv2Field HyHiThCh14 ; - // HyHiTh5 - AMACv2Field HyHiThCh15 ; - // HV0LoTh0 - AMACv2Field HV0LoThCh0 ; - AMACv2Field HV0LoThCh1 ; - AMACv2Field HV0LoThCh2 ; - // HV0LoTh1 - AMACv2Field HV0LoThCh3 ; - AMACv2Field HV0LoThCh4 ; - AMACv2Field HV0LoThCh5 ; - // HV0LoTh2 - AMACv2Field HV0LoThCh6 ; - AMACv2Field HV0LoThCh7 ; - AMACv2Field HV0LoThCh8 ; - // HV0LoTh3 - AMACv2Field HV0LoThCh9 ; - AMACv2Field HV0LoThCh10 ; - AMACv2Field HV0LoThCh11 ; - // HV0LoTh4 - AMACv2Field HV0LoThCh12 ; - AMACv2Field HV0LoThCh13 ; - AMACv2Field HV0LoThCh14 ; - // HV0LoTh5 - AMACv2Field HV0LoThCh15 ; - // HV0HiTh0 - AMACv2Field HV0HiThCh0 ; - AMACv2Field HV0HiThCh1 ; - AMACv2Field HV0HiThCh2 ; - // HV0HiTh1 - AMACv2Field HV0HiThCh3 ; - AMACv2Field HV0HiThCh4 ; - AMACv2Field HV0HiThCh5 ; - // HV0HiTh2 - AMACv2Field HV0HiThCh6 ; - AMACv2Field HV0HiThCh7 ; - AMACv2Field HV0HiThCh8 ; - // HV0HiTh3 - AMACv2Field HV0HiThCh9 ; - AMACv2Field HV0HiThCh10 ; - AMACv2Field HV0HiThCh11 ; - // HV0HiTh4 - AMACv2Field HV0HiThCh12 ; - AMACv2Field HV0HiThCh13 ; - AMACv2Field HV0HiThCh14 ; - // HV0HiTh5 - AMACv2Field HV0HiThCh15 ; - // HV2HiTh0 - AMACv2Field HV2LoThCh0 ; - AMACv2Field HV2LoThCh1 ; - AMACv2Field HV2LoThCh2 ; - // HV2LoTh1 - AMACv2Field HV2LoThCh3 ; - AMACv2Field HV2LoThCh4 ; - AMACv2Field HV2LoThCh5 ; - // HV2LoTh2 - AMACv2Field HV2LoThCh6 ; - AMACv2Field HV2LoThCh7 ; - AMACv2Field HV2LoThCh8 ; - // HV2LoTh3 - AMACv2Field HV2LoThCh9 ; - AMACv2Field HV2LoThCh10 ; - AMACv2Field HV2LoThCh11 ; - // HV2LoTh4 - AMACv2Field HV2LoThCh12 ; - AMACv2Field HV2LoThCh13 ; - AMACv2Field HV2LoThCh14 ; - // HV2LoTh5 - AMACv2Field HV2LoThCh15 ; - // HV2HiTh0 - AMACv2Field HV2HiThCh0 ; - AMACv2Field HV2HiThCh1 ; - AMACv2Field HV2HiThCh2 ; - // HV2HiTh1 - AMACv2Field HV2HiThCh3 ; - AMACv2Field HV2HiThCh4 ; - AMACv2Field HV2HiThCh5 ; - // HV2HiTh2 - AMACv2Field HV2HiThCh6 ; - AMACv2Field HV2HiThCh7 ; - AMACv2Field HV2HiThCh8 ; - // HV2HiTh3 - AMACv2Field HV2HiThCh9 ; - AMACv2Field HV2HiThCh10 ; - AMACv2Field HV2HiThCh11 ; - // HV2HiTh4 - AMACv2Field HV2HiThCh12 ; - AMACv2Field HV2HiThCh13 ; - AMACv2Field HV2HiThCh14 ; - // HV2HiTh5 - AMACv2Field HV2HiThCh15 ; - // DCDCLoTh0 - AMACv2Field DCDCLoThCh0 ; - AMACv2Field DCDCLoThCh1 ; - AMACv2Field DCDCLoThCh2 ; - // DCDCLoTh1 - AMACv2Field DCDCLoThCh3 ; - AMACv2Field DCDCLoThCh4 ; - AMACv2Field DCDCLoThCh5 ; - // DCDCLoTh2 - AMACv2Field DCDCLoThCh6 ; - AMACv2Field DCDCLoThCh7 ; - AMACv2Field DCDCLoThCh8 ; - // DCDCLoTh3 - AMACv2Field DCDCLoThCh9 ; - AMACv2Field DCDCLoThCh10 ; - AMACv2Field DCDCLoThCh11 ; - // DCDCLoTh4 - AMACv2Field DCDCLoThCh12 ; - AMACv2Field DCDCLoThCh13 ; - AMACv2Field DCDCLoThCh14 ; - // DCDCLoTh5 - AMACv2Field DCDCLoThCh15 ; - // DCDCHiTh0 - AMACv2Field DCDCHiThCh0 ; - AMACv2Field DCDCHiThCh1 ; - AMACv2Field DCDCHiThCh2 ; - // DCDCHiTh1 - AMACv2Field DCDCHiThCh3 ; - AMACv2Field DCDCHiThCh4 ; - AMACv2Field DCDCHiThCh5 ; - // DCDCHiTh2 - AMACv2Field DCDCHiThCh6 ; - AMACv2Field DCDCHiThCh7 ; - AMACv2Field DCDCHiThCh8 ; - // DCDCHiTh3 - AMACv2Field DCDCHiThCh9 ; - AMACv2Field DCDCHiThCh10 ; - AMACv2Field DCDCHiThCh11 ; - // DCDCHiTh4 - AMACv2Field DCDCHiThCh12 ; - AMACv2Field DCDCHiThCh13 ; - AMACv2Field DCDCHiThCh14 ; - // DCDCHiTh5 - AMACv2Field DCDCHiThCh15 ; - // WRNLoTh0 - AMACv2Field WRNLoThCh0 ; - AMACv2Field WRNLoThCh1 ; - AMACv2Field WRNLoThCh2 ; - // WRNLoTh1 - AMACv2Field WRNLoThCh3 ; - AMACv2Field WRNLoThCh4 ; - AMACv2Field WRNLoThCh5 ; - // WRNLoTh2 - AMACv2Field WRNLoThCh6 ; - AMACv2Field WRNLoThCh7 ; - AMACv2Field WRNLoThCh8 ; - // WRNLoTh3 - AMACv2Field WRNLoThCh9 ; - AMACv2Field WRNLoThCh10 ; - AMACv2Field WRNLoThCh11 ; - // WRNLoTh4 - AMACv2Field WRNLoThCh12 ; - AMACv2Field WRNLoThCh13 ; - AMACv2Field WRNLoThCh14 ; - // WRNLoTh5 - AMACv2Field WRNLoThCh15 ; - // WRNHiTh0 - AMACv2Field WRNHiThCh0 ; - AMACv2Field WRNHiThCh1 ; - AMACv2Field WRNHiThCh2 ; - // WRNHiTh1 - AMACv2Field WRNHiThCh3 ; - AMACv2Field WRNHiThCh4 ; - AMACv2Field WRNHiThCh5 ; - // WRNHiTh2 - AMACv2Field WRNHiThCh6 ; - AMACv2Field WRNHiThCh7 ; - AMACv2Field WRNHiThCh8 ; - // WRNHiTh3 - AMACv2Field WRNHiThCh9 ; - AMACv2Field WRNHiThCh10 ; - AMACv2Field WRNHiThCh11 ; - // WRNHiTh4 - AMACv2Field WRNHiThCh12 ; - AMACv2Field WRNHiThCh13 ; - AMACv2Field WRNHiThCh14 ; - // WRNHiTh5 - AMACv2Field WRNHiThCh15 ; - - - /** @} */ - -protected: - //! List of all registers - std::vector<AMACv2Register AMACv2RegMap::*> m_registers; - //! List of all fields - std::vector<AMACv2Field AMACv2RegMap::*> m_fields; - - // - // Name to attribute maps - std::unordered_map<uint8_t , AMACv2Register AMACv2RegMap::*> m_regAddrMap; - std::unordered_map<std::string, AMACv2Register AMACv2RegMap::*> m_regMap; - std::unordered_map<std::string, AMACv2Field AMACv2RegMap::*> m_fieldMap; +class AMACv2RegMap { + public: + //! Possible AMAC versions + enum class Version { v2, star, unknown }; + + private: + //! Initialize register map for AMACv2 + void init_v2(); + + //! Initialize register map for AMACstar + void init_star(); + + protected: + //! Initialize helper containers for looking up fields and registers + void init_regmap(Version version); + + public: + AMACv2RegMap(); + + std::vector<const AMACv2Register*> getRegisters() const; + std::vector<const AMACv2Field*> getFields() const; + + AMACv2Field* findField(AMACv2Field AMACv2RegMap::*ref); + AMACv2Field* findField(const std::string& fieldName); + + uint32_t getField(AMACv2Field AMACv2RegMap::*ref); + uint32_t getField(const std::string& fieldName); + + uint32_t getReg(uint32_t reg); + uint32_t getReg(AMACv2Register AMACv2RegMap::*ref); + + void setField(AMACv2Field AMACv2RegMap::*ref, uint32_t value); + void setField(const std::string& fieldName, uint32_t value); + + void setReg(uint32_t reg, uint32_t value); + void setReg(AMACv2Register AMACv2RegMap::*ref, uint32_t value); + + uint8_t getAddr(AMACv2Field AMACv2RegMap::*ref); + uint8_t getAddr(const std::string& fieldName); + + bool canBeWritten(AMACv2Field AMACv2RegMap::*ref); + + /** \name Registers + * @{ */ + AMACv2Register RegisterStatus; + AMACv2Register RegisterHxFlags; + AMACv2Register RegisterHyFlags; + AMACv2Register RegisterHyHxFlags; + AMACv2Register RegisterHV0Flags; + AMACv2Register RegisterHV2Flags; + AMACv2Register RegisterHV2HV0Flags; + AMACv2Register RegisterDCDCFlags; + AMACv2Register RegisterWRNHxFlags; + AMACv2Register RegisterWRNDCDCFlags; + AMACv2Register RegisterSynFlags; + + AMACv2Register RegisterValue0; + AMACv2Register RegisterValue1; + AMACv2Register RegisterValue2; + AMACv2Register RegisterValue3; + AMACv2Register RegisterValue4; + AMACv2Register RegisterValue5; + + AMACv2Register RegisterSEUstatus0; + AMACv2Register RegisterSEUstatus1; + + AMACv2Register RegisterSerNum; + + AMACv2Register RegisterFlagResets; + AMACv2Register RegisterLogicReset; + AMACv2Register RegisterHardReset; + + AMACv2Register RegisterCntSet; + AMACv2Register RegisterCntSetC; + AMACv2Register RegisterDCDCen; + AMACv2Register RegisterDCDCenC; + AMACv2Register RegisterIlock; + AMACv2Register RegisterIlockC; + AMACv2Register RegisterRstCnt; + AMACv2Register RegisterRstCntC; + AMACv2Register RegisterAMen; + AMACv2Register RegisterAMenC; + AMACv2Register RegisterAMpwr; + AMACv2Register RegisterAMpwrC; + AMACv2Register RegisterBgCnt; + AMACv2Register RegisterAMCnt; + AMACv2Register RegisterDACs0; + AMACv2Register RegisterDACbias; + AMACv2Register RegisterAMACCnt; + AMACv2Register RegisterNTCRange; + AMACv2Register RegisterLVCurCal; + + AMACv2Register RegisterHxICfg; + AMACv2Register RegisterHyICfg; + AMACv2Register RegisterHyHxICfg; + AMACv2Register RegisterHV0ICfg; + AMACv2Register RegisterHV2ICfg; + AMACv2Register RegisterHV2HV0ICfg; + AMACv2Register RegisterDCDCICfg; + AMACv2Register RegisterWRNICfg; + AMACv2Register RegisterWRNDCDCICfg; + + AMACv2Register RegisterHxTLUT; + AMACv2Register RegisterHxModLUT1; + AMACv2Register RegisterHxModLUT2; + + AMACv2Register RegisterHyTLUT; + AMACv2Register RegisterHyModLUT1; + AMACv2Register RegisterHyModLUT2; + + AMACv2Register RegisterHV0TLUT; + AMACv2Register RegisterHV0ModLUT1; + AMACv2Register RegisterHV0ModLUT2; + + AMACv2Register RegisterHV2TLUT; + AMACv2Register RegisterHV2ModLUT1; + AMACv2Register RegisterHV2ModLUT2; + + AMACv2Register RegisterDCDCTLUT; + AMACv2Register RegisterDCDCModLUT1; + AMACv2Register RegisterDCDCModLUT2; + + AMACv2Register RegisterWRNTLUT; + AMACv2Register RegisterWRNModLUT1; + AMACv2Register RegisterWRNModLUT2; + + AMACv2Register RegisterHxFlagEn; + AMACv2Register RegisterHyFlagEn; + AMACv2Register RegisterHyHxFlagEn; + AMACv2Register RegisterHV0FlagEn; + AMACv2Register RegisterHV2FlagEn; + AMACv2Register RegisterHV2HV0FlagEn; + AMACv2Register RegisterDCDCFlagEn; + AMACv2Register RegisterSynFlagEn; + AMACv2Register RegisterWRNDCDCFlagEn; + + AMACv2Register RegisterHxTh0; + AMACv2Register RegisterHxTh1; + AMACv2Register RegisterHxTh2; + AMACv2Register RegisterHxTh3; + + AMACv2Register RegisterHyTh0; + AMACv2Register RegisterHyTh1; + AMACv2Register RegisterHyTh2; + AMACv2Register RegisterHyTh3; + + AMACv2Register RegisterHV0Th0; + AMACv2Register RegisterHV0Th1; + AMACv2Register RegisterHV0Th2; + AMACv2Register RegisterHV0Th3; + + AMACv2Register RegisterHV2Th0; + AMACv2Register RegisterHV2Th1; + AMACv2Register RegisterHV2Th2; + AMACv2Register RegisterHV2Th3; + + AMACv2Register RegisterDCDCTh0; + AMACv2Register RegisterDCDCTh1; + AMACv2Register RegisterDCDCTh2; + AMACv2Register RegisterDCDCTh3; + + AMACv2Register RegisterWRNTh0; + AMACv2Register RegisterWRNTh1; + AMACv2Register RegisterWRNTh2; + AMACv2Register RegisterWRNTh3; + + AMACv2Register RegisterHxLoTh0; + AMACv2Register RegisterHxLoTh1; + AMACv2Register RegisterHxLoTh2; + AMACv2Register RegisterHxLoTh3; + AMACv2Register RegisterHxLoTh4; + AMACv2Register RegisterHxLoTh5; + + AMACv2Register RegisterHxHiTh0; + AMACv2Register RegisterHxHiTh1; + AMACv2Register RegisterHxHiTh2; + AMACv2Register RegisterHxHiTh3; + AMACv2Register RegisterHxHiTh4; + AMACv2Register RegisterHxHiTh5; + + AMACv2Register RegisterHyLoTh0; + AMACv2Register RegisterHyLoTh1; + AMACv2Register RegisterHyLoTh2; + AMACv2Register RegisterHyLoTh3; + AMACv2Register RegisterHyLoTh4; + AMACv2Register RegisterHyLoTh5; + + AMACv2Register RegisterHyHiTh0; + AMACv2Register RegisterHyHiTh1; + AMACv2Register RegisterHyHiTh2; + AMACv2Register RegisterHyHiTh3; + AMACv2Register RegisterHyHiTh4; + AMACv2Register RegisterHyHiTh5; + + AMACv2Register RegisterHV0LoTh0; + AMACv2Register RegisterHV0LoTh1; + AMACv2Register RegisterHV0LoTh2; + AMACv2Register RegisterHV0LoTh3; + AMACv2Register RegisterHV0LoTh4; + AMACv2Register RegisterHV0LoTh5; + + AMACv2Register RegisterHV0HiTh0; + AMACv2Register RegisterHV0HiTh1; + AMACv2Register RegisterHV0HiTh2; + AMACv2Register RegisterHV0HiTh3; + AMACv2Register RegisterHV0HiTh4; + AMACv2Register RegisterHV0HiTh5; + + AMACv2Register RegisterHV2LoTh0; + AMACv2Register RegisterHV2LoTh1; + AMACv2Register RegisterHV2LoTh2; + AMACv2Register RegisterHV2LoTh3; + AMACv2Register RegisterHV2LoTh4; + AMACv2Register RegisterHV2LoTh5; + + AMACv2Register RegisterHV2HiTh0; + AMACv2Register RegisterHV2HiTh1; + AMACv2Register RegisterHV2HiTh2; + AMACv2Register RegisterHV2HiTh3; + AMACv2Register RegisterHV2HiTh4; + AMACv2Register RegisterHV2HiTh5; + + AMACv2Register RegisterDCDCLoTh0; + AMACv2Register RegisterDCDCLoTh1; + AMACv2Register RegisterDCDCLoTh2; + AMACv2Register RegisterDCDCLoTh3; + AMACv2Register RegisterDCDCLoTh4; + AMACv2Register RegisterDCDCLoTh5; + + AMACv2Register RegisterDCDCHiTh0; + AMACv2Register RegisterDCDCHiTh1; + AMACv2Register RegisterDCDCHiTh2; + AMACv2Register RegisterDCDCHiTh3; + AMACv2Register RegisterDCDCHiTh4; + AMACv2Register RegisterDCDCHiTh5; + + AMACv2Register RegisterWRNLoTh0; + AMACv2Register RegisterWRNLoTh1; + AMACv2Register RegisterWRNLoTh2; + AMACv2Register RegisterWRNLoTh3; + AMACv2Register RegisterWRNLoTh4; + AMACv2Register RegisterWRNLoTh5; + + AMACv2Register RegisterWRNHiTh0; + AMACv2Register RegisterWRNHiTh1; + AMACv2Register RegisterWRNHiTh2; + AMACv2Register RegisterWRNHiTh3; + AMACv2Register RegisterWRNHiTh4; + AMACv2Register RegisterWRNHiTh5; + + /** @} */ + + /** \name Fields + * @{ */ + // Status registers + AMACv2Field StatusAM; + AMACv2Field StatusWARN; + AMACv2Field StatusDCDC; + AMACv2Field StatusHV3; + AMACv2Field StatusHV2; + AMACv2Field StatusHV1; + AMACv2Field StatusHV0; + AMACv2Field StatusY2LDO; + AMACv2Field StatusY1LDO; + AMACv2Field StatusY0LDO; + AMACv2Field StatusX2LDO; + AMACv2Field StatusX1LDO; + AMACv2Field StatusX0LDO; + AMACv2Field StatusGPI; + AMACv2Field StatusPGOOD; + AMACv2Field StatusILockWARN; + AMACv2Field StatusILockDCDC; + AMACv2Field StatusILockHV2; + AMACv2Field StatusILockHV0; + AMACv2Field StatusILockYLDO; + AMACv2Field StatusILockxLDO; + AMACv2Field AMACVersion; + // HxFlags + AMACv2Field HxFlagsHi; + AMACv2Field HxFlagsLo; + AMACv2Field HxChFlags; + // HyFlags + AMACv2Field HyFlagsHi; + AMACv2Field HyFlagsLo; + AMACv2Field HyChFlags; + // HV0Flags + AMACv2Field HV0FlagsHi; + AMACv2Field HV0FlagsLo; + AMACv2Field HV0ChFlags; + // HV2Flags + AMACv2Field HV2FlagsHi; + AMACv2Field HV2FlagsLo; + AMACv2Field HV2ChFlags; + // DCDCFlags + AMACv2Field DCDCflagsHi; + AMACv2Field DCDCflagsLo; + AMACv2Field DCDCChFlags; + // WRNHxFlags + AMACv2Field WRNflagsHi; + AMACv2Field WRNflagsLo; + AMACv2Field WRNChFlags; + // SynFlags + AMACv2Field SynFlagsHx; + AMACv2Field SynFlagsHy; + AMACv2Field SynFlagsHV0; + AMACv2Field SynFlagsHV2; + AMACv2Field SynFlagsDCDC; + AMACv2Field SynFlagsWRN; + // Value0 + AMACv2Field Value0AMen; + AMACv2Field Ch0Value; + AMACv2Field Ch1Value; + AMACv2Field Ch2Value; + // Value1 + AMACv2Field Value1AMen; + AMACv2Field Ch3Value; + AMACv2Field Ch4Value; + AMACv2Field Ch5Value; + // Value2 + AMACv2Field Value2AMen; + AMACv2Field Ch6Value; + AMACv2Field Ch7Value; + AMACv2Field Ch8Value; + // Value3 + AMACv2Field Value3AMen; + AMACv2Field Ch9Value; + AMACv2Field Ch10Value; + AMACv2Field Ch11Value; + // Value4 + AMACv2Field Value4AMen; + AMACv2Field Ch12Value; + AMACv2Field Ch13Value; + AMACv2Field Ch14Value; + AMACv2Field Ch12S; + AMACv2Field Ch13S; + // Value5 + AMACv2Field Value5AMen; + AMACv2Field Ch15Value; + AMACv2Field Ch14S; + AMACv2Field Ch15S; + // SEUstatus + AMACv2Field SEUStatusLo; + AMACv2Field SEUStatusHi; + // SerNum + AMACv2Field PadID; + AMACv2Field SerNum; + // FlagResets + AMACv2Field FlagResetOe; + AMACv2Field FlagResetF; + AMACv2Field FlagResetS; + AMACv2Field FlagResetWRN; + AMACv2Field FlagResetDCDC; + AMACv2Field FlagResetHV2; + AMACv2Field FlagResetHV0; + AMACv2Field FlagResetXLDO; + AMACv2Field FlagResetYLDO; + // LogicReset + AMACv2Field LogicReset; + // HardReset + AMACv2Field HardReset; + // CntSet + AMACv2Field CntSetHV3frq; + AMACv2Field CntSetHV3en; + AMACv2Field CntSetHV2frq; + AMACv2Field CntSetHV2en; + AMACv2Field CntSetHV1frq; + AMACv2Field CntSetHV1en; + AMACv2Field CntSetHV0frq; + AMACv2Field CntSetHV0en; + AMACv2Field CntSetHyLDO2en; + AMACv2Field CntSetHyLDO1en; + AMACv2Field CntSetHyLDO0en; + AMACv2Field CntSetHxLDO2en; + AMACv2Field CntSetHxLDO1en; + AMACv2Field CntSetHxLDO0en; + AMACv2Field CntSetWARN; + // CntSetC + AMACv2Field CntSetCHV3frq; + AMACv2Field CntSetCHV3en; + AMACv2Field CntSetCHV2frq; + AMACv2Field CntSetCHV2en; + AMACv2Field CntSetCHV1frq; + AMACv2Field CntSetCHV1en; + AMACv2Field CntSetCHV0frq; + AMACv2Field CntSetCHV0en; + AMACv2Field CntSetCHyLDO2en; + AMACv2Field CntSetCHyLDO1en; + AMACv2Field CntSetCHyLDO0en; + AMACv2Field CntSetCHxLDO2en; + AMACv2Field CntSetCHxLDO1en; + AMACv2Field CntSetCHxLDO0en; + AMACv2Field CntSetCWARN; + // DCDCen + AMACv2Field DCDCAdj; + AMACv2Field DCDCen; + // DCDCenC + AMACv2Field DCDCAdjC; + AMACv2Field DCDCenC; + // Ilock + AMACv2Field IlockHx; + AMACv2Field IlockHy; + AMACv2Field IlockHV0; + AMACv2Field IlockHV2; + AMACv2Field IlockDCDC; + AMACv2Field IlockWRN; + // IlockC + AMACv2Field IlockCHx; + AMACv2Field IlockCHy; + AMACv2Field IlockCHV0; + AMACv2Field IlockCHV2; + AMACv2Field IlockCDCDC; + AMACv2Field IlockCWRN; + // RstCnt + AMACv2Field RstCntHyHCCresetB; + AMACv2Field RstCntHxHCCresetB; + AMACv2Field RstCntOF; + // RstCntC + AMACv2Field RstCntCHyHCCresetB; + AMACv2Field RstCntCHxHCCresetB; + AMACv2Field RstCntCOF; + // AMen + AMACv2Field AMzeroCalib; + AMACv2Field AMen; + // AMenC + AMACv2Field AMzeroCalibC; + AMACv2Field AMenC; + // AMpwr + AMACv2Field ClockDisableEn; + AMACv2Field ReqDCDCPGOOD; + AMACv2Field DCDCenToPwrAMAC; + // AMpwrC + AMACv2Field ReqDCDCPGOODC; + AMACv2Field DCDCenToPwrAMACC; + // BgCnt + AMACv2Field AMbgen; + AMACv2Field AMbgSW; + AMACv2Field AMbg; + AMACv2Field VDDbgen; + AMACv2Field VDDbgSW; + AMACv2Field VDDbg; + // AMCnt + AMACv2Field AMCntRg; + AMACv2Field AMintCalib; + AMACv2Field Ch15Mux; + AMACv2Field Ch14Mux; + AMACv2Field Ch13Mux; + AMACv2Field Ch12Mux; + AMACv2Field Ch12AMux; + AMACv2Field Ch5Mux; + AMACv2Field Ch4Mux; + AMACv2Field Ch3Mux; + // DACs0 + AMACv2Field DACShunty; + AMACv2Field DACShuntx; + AMACv2Field DACCaly; + AMACv2Field DACCalx; + // DACbias + AMACv2Field DACbias; + AMACv2Field ShuntEn; + // AMACCnt + AMACv2Field eFusebitSelect; + AMACv2Field HVcurGain; + AMACv2Field DRcomMode; + AMACv2Field DRcurr; + AMACv2Field ClkDis; + AMACv2Field RingOscFrq; + // NTCRange + AMACv2Field CTAToffset; + AMACv2Field NTCpbCal; + AMACv2Field NTCpbSenseRange; + AMACv2Field NTCy0Cal; + AMACv2Field NTCy0SenseRange; + AMACv2Field NTCx0Cal; + AMACv2Field NTCx0SenseRange; + // LVCurCal + AMACv2Field DCDCoOffset; + AMACv2Field DCDCoZeroReading; + AMACv2Field DCDCoN; + AMACv2Field DCDCoP; + AMACv2Field DCDCiZeroReading; + AMACv2Field DCDCiRangeSW; + AMACv2Field DCDCiOffset; + AMACv2Field DCDCiP; + AMACv2Field DCDCiN; + // HxICfg + AMACv2Field HxFlagValid; + AMACv2Field HxFlagValidEn; + AMACv2Field HxFlagsLogic; + AMACv2Field HxFlagsLatch; + AMACv2Field HxLAM; + // HyICfg + AMACv2Field HyFlagValid; + AMACv2Field HyFlagValidEn; + AMACv2Field HyFlagsLogic; + AMACv2Field HyFlagsLatch; + AMACv2Field HyLAM; + // HV0ICfg + AMACv2Field HV0FlagValid; + AMACv2Field HV0FlagValidEn; + AMACv2Field HV0FlagsLogic; + AMACv2Field HV0FlagsLatch; + AMACv2Field HV0LAM; + // HV2ICfg + AMACv2Field HV2FlagValid; + AMACv2Field HV2FlagValidEn; + AMACv2Field HV2FlagsLogic; + AMACv2Field HV2FlagsLatch; + AMACv2Field HV2LAM; + // DCDCICfg + AMACv2Field DCDCFlagValid; + AMACv2Field DCDCFlagValidEn; + AMACv2Field DCDCFlagsLogic; + AMACv2Field DCDCFlagsLatch; + AMACv2Field DCDCLAM; + // WRNICfg + AMACv2Field WRNFlagValid; + AMACv2Field WRNFlagValidEn; + AMACv2Field WRNFlagsLogic; + AMACv2Field WRNFlagsLatch; + AMACv2Field WRNLAM; + // HxTLUT + AMACv2Field HxTlut; + // HxModLUT1 + AMACv2Field HxModlut1; + // HxModLUT2 + AMACv2Field HxModlut2; + // HyTLUT + AMACv2Field HyTlut; + // HyModLUT1 + AMACv2Field HyModlut1; + // HyModLUT2 + AMACv2Field HyModlut2; + // HV0TLUT + AMACv2Field HV0Tlut; + // HV0ModLUT1 + AMACv2Field HV0Modlut1; + // HV0ModLUT2 + AMACv2Field HV0Modlut2; + // HV2TLUT + AMACv2Field HV2Tlut; + // HV2ModLUT1 + AMACv2Field HV2Modlut1; + // HV2ModLUT2 + AMACv2Field HV2Modlut2; + // DCDCTLUT + AMACv2Field DCDCTlut; + // DCDCModLUT1 + AMACv2Field DCDCModlut1; + // DCDCModLUT2 + AMACv2Field DCDCModlut2; + // WRNTLUT + AMACv2Field WRNTlut; + // WRNModLUT1 + AMACv2Field WRNModlut1; + // WRNModLUT2 + AMACv2Field WRNModlut2; + // HxFlagEn + AMACv2Field HxFlagsEnHi; + AMACv2Field HxFlagsEnLo; + AMACv2Field HxILockFlagEn; + // HyFlagEn + AMACv2Field HyFlagsEnHi; + AMACv2Field HyFlagsEnLo; + AMACv2Field HyILockFlagEn; + // HV0FlagEn + AMACv2Field HV0FlagsEnHi; + AMACv2Field HV0FlagsEnLo; + AMACv2Field HV0ILockFlagEn; + // HV2FlagEn + AMACv2Field HV2FlagsEnHi; + AMACv2Field HV2FlagsEnLo; + AMACv2Field HV2ILockFlagEn; + // DCDCFlagEn + AMACv2Field DCDCFlagsEnHi; + AMACv2Field DCDCFlagsEnLo; + AMACv2Field DCDCILockFlagEn; + // SynFlagEn + AMACv2Field HyFlagEnSynY; + AMACv2Field HxFlagEnSynX; + AMACv2Field HV2FlagEnSynH2; + AMACv2Field HV0FlagEnSynH0; + AMACv2Field WRNDCDCFlagEnSynW; + AMACv2Field WRNDCDCFlagEnSynDc; + AMACv2Field WRNFlagsEnHi; + AMACv2Field WRNFlagsEnLo; + AMACv2Field WARNILockFlagEn; + AMACv2Field WRNsynFlagEnHi; + AMACv2Field WRNsynFlagEnLo; + AMACv2Field DCDCsynFlagEnHi; + AMACv2Field DCDCsynFlagEnLo; + AMACv2Field HV2synFlagEnHi; + AMACv2Field HV2synFlagEnLo; + AMACv2Field HV0synFlagEnHi; + AMACv2Field HV0synFlagEnLo; + AMACv2Field HysynFlagEnHi; + AMACv2Field HysynFlagEnLo; + AMACv2Field HxsynFlagEnHi; + AMACv2Field HxsynFlagEnLo; + // HxLoTh0 + AMACv2Field HxLoThCh0; + AMACv2Field HxLoThCh1; + AMACv2Field HxLoThCh2; + // HxLoTh1 + AMACv2Field HxLoThCh3; + AMACv2Field HxLoThCh4; + AMACv2Field HxLoThCh5; + // HxLoTh2 + AMACv2Field HxLoThCh6; + AMACv2Field HxLoThCh7; + AMACv2Field HxLoThCh8; + // HxLoTh3 + AMACv2Field HxLoThCh9; + AMACv2Field HxLoThCh10; + AMACv2Field HxLoThCh11; + // HxLoTh4 + AMACv2Field HxLoThCh12; + AMACv2Field HxLoThCh13; + AMACv2Field HxLoThCh14; + // HxLoTh5 + AMACv2Field HxLoThCh15; + // HxHiTh0 + AMACv2Field HxHiThCh0; + AMACv2Field HxHiThCh1; + AMACv2Field HxHiThCh2; + // HxHiTh1 + AMACv2Field HxHiThCh3; + AMACv2Field HxHiThCh4; + AMACv2Field HxHiThCh5; + // HxHiTh2 + AMACv2Field HxHiThCh6; + AMACv2Field HxHiThCh7; + AMACv2Field HxHiThCh8; + // HxHiTh3 + AMACv2Field HxHiThCh9; + AMACv2Field HxHiThCh10; + AMACv2Field HxHiThCh11; + // HxHiTh4 + AMACv2Field HxHiThCh12; + AMACv2Field HxHiThCh13; + AMACv2Field HxHiThCh14; + // HxHiTh5 + AMACv2Field HxHiThCh15; + // HyLoTh0 + AMACv2Field HyLoThCh0; + AMACv2Field HyLoThCh1; + AMACv2Field HyLoThCh2; + // HyLoTh1 + AMACv2Field HyLoThCh3; + AMACv2Field HyLoThCh4; + AMACv2Field HyLoThCh5; + // HyLoTh2 + AMACv2Field HyLoThCh6; + AMACv2Field HyLoThCh7; + AMACv2Field HyLoThCh8; + // HyLoTh3 + AMACv2Field HyLoThCh9; + AMACv2Field HyLoThCh10; + AMACv2Field HyLoThCh11; + // HyLoTh4 + AMACv2Field HyLoThCh12; + AMACv2Field HyLoThCh13; + AMACv2Field HyLoThCh14; + // HyLoTh5 + AMACv2Field HyLoThCh15; + // HyHiTh0 + AMACv2Field HyHiThCh0; + AMACv2Field HyHiThCh1; + AMACv2Field HyHiThCh2; + // HyHiTh1 + AMACv2Field HyHiThCh3; + AMACv2Field HyHiThCh4; + AMACv2Field HyHiThCh5; + // HyHiTh2 + AMACv2Field HyHiThCh6; + AMACv2Field HyHiThCh7; + AMACv2Field HyHiThCh8; + // HyHiTh3 + AMACv2Field HyHiThCh9; + AMACv2Field HyHiThCh10; + AMACv2Field HyHiThCh11; + // HyHiTh4 + AMACv2Field HyHiThCh12; + AMACv2Field HyHiThCh13; + AMACv2Field HyHiThCh14; + // HyHiTh5 + AMACv2Field HyHiThCh15; + // HV0LoTh0 + AMACv2Field HV0LoThCh0; + AMACv2Field HV0LoThCh1; + AMACv2Field HV0LoThCh2; + // HV0LoTh1 + AMACv2Field HV0LoThCh3; + AMACv2Field HV0LoThCh4; + AMACv2Field HV0LoThCh5; + // HV0LoTh2 + AMACv2Field HV0LoThCh6; + AMACv2Field HV0LoThCh7; + AMACv2Field HV0LoThCh8; + // HV0LoTh3 + AMACv2Field HV0LoThCh9; + AMACv2Field HV0LoThCh10; + AMACv2Field HV0LoThCh11; + // HV0LoTh4 + AMACv2Field HV0LoThCh12; + AMACv2Field HV0LoThCh13; + AMACv2Field HV0LoThCh14; + // HV0LoTh5 + AMACv2Field HV0LoThCh15; + // HV0HiTh0 + AMACv2Field HV0HiThCh0; + AMACv2Field HV0HiThCh1; + AMACv2Field HV0HiThCh2; + // HV0HiTh1 + AMACv2Field HV0HiThCh3; + AMACv2Field HV0HiThCh4; + AMACv2Field HV0HiThCh5; + // HV0HiTh2 + AMACv2Field HV0HiThCh6; + AMACv2Field HV0HiThCh7; + AMACv2Field HV0HiThCh8; + // HV0HiTh3 + AMACv2Field HV0HiThCh9; + AMACv2Field HV0HiThCh10; + AMACv2Field HV0HiThCh11; + // HV0HiTh4 + AMACv2Field HV0HiThCh12; + AMACv2Field HV0HiThCh13; + AMACv2Field HV0HiThCh14; + // HV0HiTh5 + AMACv2Field HV0HiThCh15; + // HV2HiTh0 + AMACv2Field HV2LoThCh0; + AMACv2Field HV2LoThCh1; + AMACv2Field HV2LoThCh2; + // HV2LoTh1 + AMACv2Field HV2LoThCh3; + AMACv2Field HV2LoThCh4; + AMACv2Field HV2LoThCh5; + // HV2LoTh2 + AMACv2Field HV2LoThCh6; + AMACv2Field HV2LoThCh7; + AMACv2Field HV2LoThCh8; + // HV2LoTh3 + AMACv2Field HV2LoThCh9; + AMACv2Field HV2LoThCh10; + AMACv2Field HV2LoThCh11; + // HV2LoTh4 + AMACv2Field HV2LoThCh12; + AMACv2Field HV2LoThCh13; + AMACv2Field HV2LoThCh14; + // HV2LoTh5 + AMACv2Field HV2LoThCh15; + // HV2HiTh0 + AMACv2Field HV2HiThCh0; + AMACv2Field HV2HiThCh1; + AMACv2Field HV2HiThCh2; + // HV2HiTh1 + AMACv2Field HV2HiThCh3; + AMACv2Field HV2HiThCh4; + AMACv2Field HV2HiThCh5; + // HV2HiTh2 + AMACv2Field HV2HiThCh6; + AMACv2Field HV2HiThCh7; + AMACv2Field HV2HiThCh8; + // HV2HiTh3 + AMACv2Field HV2HiThCh9; + AMACv2Field HV2HiThCh10; + AMACv2Field HV2HiThCh11; + // HV2HiTh4 + AMACv2Field HV2HiThCh12; + AMACv2Field HV2HiThCh13; + AMACv2Field HV2HiThCh14; + // HV2HiTh5 + AMACv2Field HV2HiThCh15; + // DCDCLoTh0 + AMACv2Field DCDCLoThCh0; + AMACv2Field DCDCLoThCh1; + AMACv2Field DCDCLoThCh2; + // DCDCLoTh1 + AMACv2Field DCDCLoThCh3; + AMACv2Field DCDCLoThCh4; + AMACv2Field DCDCLoThCh5; + // DCDCLoTh2 + AMACv2Field DCDCLoThCh6; + AMACv2Field DCDCLoThCh7; + AMACv2Field DCDCLoThCh8; + // DCDCLoTh3 + AMACv2Field DCDCLoThCh9; + AMACv2Field DCDCLoThCh10; + AMACv2Field DCDCLoThCh11; + // DCDCLoTh4 + AMACv2Field DCDCLoThCh12; + AMACv2Field DCDCLoThCh13; + AMACv2Field DCDCLoThCh14; + // DCDCLoTh5 + AMACv2Field DCDCLoThCh15; + // DCDCHiTh0 + AMACv2Field DCDCHiThCh0; + AMACv2Field DCDCHiThCh1; + AMACv2Field DCDCHiThCh2; + // DCDCHiTh1 + AMACv2Field DCDCHiThCh3; + AMACv2Field DCDCHiThCh4; + AMACv2Field DCDCHiThCh5; + // DCDCHiTh2 + AMACv2Field DCDCHiThCh6; + AMACv2Field DCDCHiThCh7; + AMACv2Field DCDCHiThCh8; + // DCDCHiTh3 + AMACv2Field DCDCHiThCh9; + AMACv2Field DCDCHiThCh10; + AMACv2Field DCDCHiThCh11; + // DCDCHiTh4 + AMACv2Field DCDCHiThCh12; + AMACv2Field DCDCHiThCh13; + AMACv2Field DCDCHiThCh14; + // DCDCHiTh5 + AMACv2Field DCDCHiThCh15; + // WRNLoTh0 + AMACv2Field WRNLoThCh0; + AMACv2Field WRNLoThCh1; + AMACv2Field WRNLoThCh2; + // WRNLoTh1 + AMACv2Field WRNLoThCh3; + AMACv2Field WRNLoThCh4; + AMACv2Field WRNLoThCh5; + // WRNLoTh2 + AMACv2Field WRNLoThCh6; + AMACv2Field WRNLoThCh7; + AMACv2Field WRNLoThCh8; + // WRNLoTh3 + AMACv2Field WRNLoThCh9; + AMACv2Field WRNLoThCh10; + AMACv2Field WRNLoThCh11; + // WRNLoTh4 + AMACv2Field WRNLoThCh12; + AMACv2Field WRNLoThCh13; + AMACv2Field WRNLoThCh14; + // WRNLoTh5 + AMACv2Field WRNLoThCh15; + // WRNHiTh0 + AMACv2Field WRNHiThCh0; + AMACv2Field WRNHiThCh1; + AMACv2Field WRNHiThCh2; + // WRNHiTh1 + AMACv2Field WRNHiThCh3; + AMACv2Field WRNHiThCh4; + AMACv2Field WRNHiThCh5; + // WRNHiTh2 + AMACv2Field WRNHiThCh6; + AMACv2Field WRNHiThCh7; + AMACv2Field WRNHiThCh8; + // WRNHiTh3 + AMACv2Field WRNHiThCh9; + AMACv2Field WRNHiThCh10; + AMACv2Field WRNHiThCh11; + // WRNHiTh4 + AMACv2Field WRNHiThCh12; + AMACv2Field WRNHiThCh13; + AMACv2Field WRNHiThCh14; + // WRNHiTh5 + AMACv2Field WRNHiThCh15; + + /** @} */ + + protected: + //! List of all registers + std::vector<AMACv2Register AMACv2RegMap::*> m_registers; + //! List of all fields + std::vector<AMACv2Field AMACv2RegMap::*> m_fields; + + // + // Name to attribute maps + std::unordered_map<uint8_t, AMACv2Register AMACv2RegMap::*> m_regAddrMap; + std::unordered_map<std::string, AMACv2Register AMACv2RegMap::*> m_regMap; + std::unordered_map<std::string, AMACv2Field AMACv2RegMap::*> m_fieldMap; }; -#endif //AMACREGMAP_H +#endif // AMACREGMAP_H diff --git a/pbv3/AMACv2RegMap_star.cpp b/pbv3/AMACv2RegMap_star.cpp index 7f64cb873e5c0edc0069f0a3626f7ef555b637d4..b3b0899d7a399db003053f74316828be30966e12 100644 --- a/pbv3/AMACv2RegMap_star.cpp +++ b/pbv3/AMACv2RegMap_star.cpp @@ -1,10 +1,9 @@ #include "AMACv2RegMap.h" -void AMACv2RegMap::init_star() -{ +void AMACv2RegMap::init_star() { /** \name Registers * @{ */ - //RegisterStatus = {"Status", 0, RO}; + // RegisterStatus = {"Status", 0, RO}; RegisterHyHxFlags = {"HyHxFlags", 1, RO}; RegisterHV2HV0Flags = {"HV2HV0Flags", 2, RO}; RegisterWRNDCDCFlags = {"WRNDCDCFlags", 3, RO}; @@ -83,281 +82,283 @@ void AMACv2RegMap::init_star() /** \name Fields * @{ */ - StatusAM = {"StatusAM", &RegisterStatus, 31, 1, 0x0 }; - StatusWARN = {"StatusWARN", &RegisterStatus, 29, 1, 0x0 }; - StatusDCDC = {"StatusDCDC", &RegisterStatus, 28, 1, 0x0 }; - StatusHV3 = {"StatusHV3", &RegisterStatus, 27, 1, 0x0 }; - StatusHV2 = {"StatusHV2", &RegisterStatus, 26, 1, 0x0 }; - StatusHV1 = {"StatusHV1", &RegisterStatus, 25, 1, 0x0 }; - StatusHV0 = {"StatusHV0", &RegisterStatus, 24, 1, 0x0 }; - StatusY2LDO = {"StatusY2LDO", &RegisterStatus, 22, 1, 0x0 }; - StatusY1LDO = {"StatusY1LDO", &RegisterStatus, 21, 1, 0x0 }; - StatusY0LDO = {"StatusY0LDO", &RegisterStatus, 20, 1, 0x0 }; - StatusX2LDO = {"StatusX2LDO", &RegisterStatus, 18, 1, 0x0 }; - StatusX1LDO = {"StatusX1LDO", &RegisterStatus, 17, 1, 0x0 }; - StatusX0LDO = {"StatusX0LDO", &RegisterStatus, 16, 1, 0x0 }; - StatusGPI = {"StatusGPI", &RegisterStatus, 12, 1, 0x0 }; - StatusPGOOD = {"StatusPGOOD", &RegisterStatus, 8, 1, 0x0 }; - AMACVersion = {"AMACVersion", &RegisterStatus, 6, 2, 0x0 }; - StatusILockWARN = {"StatusILockWARN", &RegisterStatus, 5, 1, 0x0 }; - StatusILockDCDC = {"StatusILockDCDC", &RegisterStatus, 4, 1, 0x0 }; - StatusILockHV2 = {"StatusILockHV2", &RegisterStatus, 3, 1, 0x0 }; - StatusILockHV0 = {"StatusILockHV0", &RegisterStatus, 2, 1, 0x0 }; - StatusILockYLDO = {"StatusILockYLDO", &RegisterStatus, 1, 1, 0x0 }; - StatusILockxLDO = {"StatusILockxLDO", &RegisterStatus, 0, 1, 0x0 }; - SynFlagsHy = {"SynFlagsHy", &RegisterHyHxFlags, 28, 2, 0x0 }; - HyChFlags = {"HyChFlags", &RegisterHyHxFlags, 16, 12, 0x0 }; - SynFlagsHx = {"SynFlagsHx", &RegisterHyHxFlags, 12, 2, 0x0 }; - HxChFlags = {"HxChFlags", &RegisterHyHxFlags, 0, 12, 0x0 }; - SynFlagsHV2 = {"SynFlagsHV2", &RegisterHV2HV0Flags, 28, 2, 0x0 }; - HV2ChFlags = {"HV2ChFlags", &RegisterHV2HV0Flags, 16, 12, 0x0 }; - SynFlagsHV0 = {"SynFlagsHV0", &RegisterHV2HV0Flags, 12, 2, 0x0 }; - HV0ChFlags = {"HV0ChFlags", &RegisterHV2HV0Flags, 0, 12, 0x0 }; - SynFlagsWRN = {"SynFlagsWRN", &RegisterWRNDCDCFlags, 28, 2, 0x0 }; - WRNChFlags = {"WRNChFlags", &RegisterWRNDCDCFlags, 16, 12, 0x0 }; - SynFlagsDCDC = {"SynFlagsDCDC", &RegisterWRNDCDCFlags, 12, 2, 0x0 }; - DCDCChFlags = {"DCDCChFlags", &RegisterWRNDCDCFlags, 0, 12, 0x0 }; - Value0AMen = {"Value0AMen", &RegisterValue0, 31, 1, 0x0 }; - Ch2Value = {"Ch2Value", &RegisterValue0, 20, 10, 0x0 }; - Ch1Value = {"Ch1Value", &RegisterValue0, 10, 10, 0x0 }; - Ch0Value = {"Ch0Value", &RegisterValue0, 0, 10, 0x0 }; - Value1AMen = {"Value1AMen", &RegisterValue1, 31, 1, 0x0 }; - Ch5Value = {"Ch5Value", &RegisterValue1, 20, 10, 0x0 }; - Ch4Value = {"Ch4Value", &RegisterValue1, 10, 10, 0x0 }; - Ch3Value = {"Ch3Value", &RegisterValue1, 0, 10, 0x0 }; - Value2AMen = {"Value2AMen", &RegisterValue2, 31, 1, 0x0 }; - Ch8Value = {"Ch8Value", &RegisterValue2, 20, 10, 0x0 }; - Ch7Value = {"Ch7Value", &RegisterValue2, 10, 10, 0x0 }; - Ch6Value = {"Ch6Value", &RegisterValue2, 0, 10, 0x0 }; - Value3AMen = {"Value3AMen", &RegisterValue3, 31, 1, 0x0 }; - Ch11Value = {"Ch11Value", &RegisterValue3, 20, 10, 0x0 }; - Ch10Value = {"Ch10Value", &RegisterValue3, 10, 10, 0x0 }; - Ch9Value = {"Ch9Value", &RegisterValue3, 0, 10, 0x0 }; - Value4AMen = {"Value4AMen", &RegisterValue4, 31, 1, 0x0 }; - Ch13S = {"Ch13S", &RegisterValue4, 28, 3, 0x0 }; - Ch12S = {"Ch12S", &RegisterValue4, 24, 2, 0x0 }; - Ch13Value = {"Ch13Value", &RegisterValue4, 10, 10, 0x0 }; - Ch12Value = {"Ch12Value", &RegisterValue4, 0, 10, 0x0 }; - Value5AMen = {"Value5AMen", &RegisterValue5, 31, 1, 0x0 }; - Ch15S = {"Ch15S", &RegisterValue5, 28, 3, 0x0 }; - Ch14S = {"Ch14S", &RegisterValue5, 24, 3, 0x0 }; - Ch15Value = {"Ch15Value", &RegisterValue5, 10, 10, 0x0 }; - Ch14Value = {"Ch14Value", &RegisterValue5, 0, 10, 0x0 }; - SEUStatusLo = {"SEUStatusLo", &RegisterSEUstatus0, 0, 32, 0x0 }; - SEUStatusHi = {"SEUStatusHi", &RegisterSEUstatus1, 0, 30, 0x0 }; - FlagResetOe = {"FlagResetOe", &RegisterFlagResets, 24, 1, 0x0 }; - FlagResetS = {"FlagResetS", &RegisterFlagResets, 8, 1, 0x0 }; - FlagResetWRN = {"FlagResetWRN", &RegisterFlagResets, 5, 1, 0x0 }; - FlagResetDCDC = {"FlagResetDCDC", &RegisterFlagResets, 4, 1, 0x0 }; - FlagResetHV2 = {"FlagResetHV2", &RegisterFlagResets, 3, 1, 0x0 }; - FlagResetHV0 = {"FlagResetHV0", &RegisterFlagResets, 2, 1, 0x0 }; - FlagResetYLDO = {"FlagResetYLDO", &RegisterFlagResets, 1, 1, 0x0 }; - FlagResetXLDO = {"FlagResetXLDO", &RegisterFlagResets, 0, 1, 0x0 }; - LogicReset = {"LogicReset", &RegisterLogicReset, 0, 32, 0x0 }; - HardReset = {"HardReset", &RegisterHardReset, 0, 32, 0x0 }; - CntSetHV3frq = {"CntSetHV3frq", &RegisterCntSet, 29, 2, 0x3 }; - CntSetHV3en = {"CntSetHV3en", &RegisterCntSet, 28, 1, 0x0 }; - CntSetHV2frq = {"CntSetHV2frq", &RegisterCntSet, 25, 2, 0x3 }; - CntSetHV2en = {"CntSetHV2en", &RegisterCntSet, 24, 1, 0x0 }; - CntSetHV1frq = {"CntSetHV1frq", &RegisterCntSet, 21, 2, 0x3 }; - CntSetHV1en = {"CntSetHV1en", &RegisterCntSet, 20, 1, 0x0 }; - CntSetHV0frq = {"CntSetHV0frq", &RegisterCntSet, 17, 2, 0x3 }; - CntSetHV0en = {"CntSetHV0en", &RegisterCntSet, 16, 1, 0x0 }; - CntSetHyLDO2en = {"CntSetHyLDO2en", &RegisterCntSet, 14, 1, 0x0 }; - CntSetHyLDO1en = {"CntSetHyLDO1en", &RegisterCntSet, 13, 1, 0x0 }; - CntSetHyLDO0en = {"CntSetHyLDO0en", &RegisterCntSet, 12, 1, 0x0 }; - CntSetHxLDO2en = {"CntSetHxLDO2en", &RegisterCntSet, 10, 1, 0x0 }; - CntSetHxLDO1en = {"CntSetHxLDO1en", &RegisterCntSet, 9, 1, 0x0 }; - CntSetHxLDO0en = {"CntSetHxLDO0en", &RegisterCntSet, 8, 1, 0x0 }; - CntSetWARN = {"CntSetWARN", &RegisterCntSet, 4, 1, 0x0 }; - DCDCAdj = {"DCDCAdj", &RegisterDCDCen, 4, 2, 0x0 }; - DCDCen = {"DCDCen", &RegisterDCDCen, 0, 1, 0x0 }; - IlockWRN = {"IlockWRN", &RegisterIlock, 5, 1, 0x0 }; - IlockDCDC = {"IlockDCDC", &RegisterIlock, 4, 1, 0x0 }; - IlockHV2 = {"IlockHV2", &RegisterIlock, 3, 1, 0x0 }; - IlockHV0 = {"IlockHV0", &RegisterIlock, 2, 1, 0x0 }; - IlockHy = {"IlockHy", &RegisterIlock, 1, 1, 0x0 }; - IlockHx = {"IlockHx", &RegisterIlock, 0, 1, 0x0 }; - RstCntHyHCCresetB = {"RstCntHyHCCresetB", &RegisterRstCnt, 16, 1, 0x0 }; - RstCntHxHCCresetB = {"RstCntHxHCCresetB", &RegisterRstCnt, 8, 1, 0x0 }; - RstCntOF = {"RstCntOF", &RegisterRstCnt, 0, 1, 0x0 }; - AMzeroCalib = {"AMzeroCalib", &RegisterAMen, 8, 1, 0x0 }; - AMen = {"AMen", &RegisterAMen, 0, 1, 0x1 }; - ClockDisableEn = {"ClockDisableEn", &RegisterAMpwr, 16, 1, 0x0 }; - ReqDCDCPGOOD = {"ReqDCDCPGOOD", &RegisterAMpwr, 8, 1, 0x1 }; - DCDCenToPwrAMAC = {"DCDCenToPwrAMAC", &RegisterAMpwr, 0, 1, 0x0 }; - AMbgen = {"AMbgen", &RegisterBgCnt, 24, 1, 0x0 }; - AMbgSW = {"AMbgSW", &RegisterBgCnt, 23, 1, 0x0 }; - AMbg = {"AMbg", &RegisterBgCnt, 16, 5, 0x0 }; - VDDbgen = {"VDDbgen", &RegisterBgCnt, 8, 1, 0x0 }; - VDDbgSW = {"VDDbgSW", &RegisterBgCnt, 7, 1, 0x0 }; - VDDbg = {"VDDbg", &RegisterBgCnt, 0, 5, 0x0 }; - AMCntRg = {"AMCntRg", &RegisterAMCnt, 28, 1, 0x0 }; - AMintCalib = {"AMintCalib", &RegisterAMCnt, 24, 4, 0x0 }; - Ch15Mux = {"Ch15Mux", &RegisterAMCnt, 16, 3, 0x0 }; - Ch14Mux = {"Ch14Mux", &RegisterAMCnt, 12, 3, 0x0 }; - Ch13Mux = {"Ch13Mux", &RegisterAMCnt, 8, 3, 0x0 }; - Ch12AMux = {"Ch12AMux", &RegisterAMCnt, 6, 1, 0x0 }; - Ch12Mux = {"Ch12Mux", &RegisterAMCnt, 4, 2, 0x0 }; - DACShunty = {"DACShunty", &RegisterDACs0, 24, 8, 0x0 }; - DACShuntx = {"DACShuntx", &RegisterDACs0, 16, 8, 0x0 }; - DACCaly = {"DACCaly", &RegisterDACs0, 8, 8, 0x0 }; - DACCalx = {"DACCalx", &RegisterDACs0, 0, 8, 0x0 }; - ShuntEn = {"ShuntEn", &RegisterDACbias, 8, 1, 0x0 }; - DACbias = {"DACbias", &RegisterDACbias, 0, 5, 0xd }; - eFusebitSelect = {"eFusebitSelect", &RegisterAMACCnt, 24, 5, 0x0 }; - HVcurGain = {"HVcurGain", &RegisterAMACCnt, 16, 4, 0x0 }; - DRcomMode = {"DRcomMode", &RegisterAMACCnt, 12, 2, 0x0 }; - DRcurr = {"DRcurr", &RegisterAMACCnt, 8, 3, 0x4 }; - ClkDis = {"ClkDis", &RegisterAMACCnt, 4, 2, 0x0 }; - RingOscFrq = {"RingOscFrq", &RegisterAMACCnt, 0, 3, 0x4 }; - CTAToffset = {"CTAToffset", &RegisterNTCRange, 24, 4, 0x3 }; - NTCpbCal = {"NTCpbCal", &RegisterNTCRange, 19, 1, 0x0 }; - NTCpbSenseRange = {"NTCpbSenseRange", &RegisterNTCRange, 16, 3, 0x4 }; - NTCy0Cal = {"NTCy0Cal", &RegisterNTCRange, 11, 1, 0x0 }; - NTCy0SenseRange = {"NTCy0SenseRange", &RegisterNTCRange, 8, 3, 0x4 }; - NTCx0Cal = {"NTCx0Cal", &RegisterNTCRange, 3, 1, 0x0 }; - NTCx0SenseRange = {"NTCx0SenseRange", &RegisterNTCRange, 0, 3, 0x4 }; - DCDCoZeroReading = {"DCDCoZeroReading", &RegisterLVCurCal, 24, 1, 0x0 }; - DCDCoOffset = {"DCDCoOffset", &RegisterLVCurCal, 20, 4, 0x4 }; - DCDCoN = {"DCDCoN", &RegisterLVCurCal, 18, 2, 0x0 }; - DCDCoP = {"DCDCoP", &RegisterLVCurCal, 16, 2, 0x0 }; - DCDCiZeroReading = {"DCDCiZeroReading", &RegisterLVCurCal, 15, 1, 0x0 }; - DCDCiRangeSW = {"DCDCiRangeSW", &RegisterLVCurCal, 12, 1, 0x1 }; - DCDCiOffset = {"DCDCiOffset", &RegisterLVCurCal, 8, 4, 0x5 }; - DCDCiN = {"DCDCiN", &RegisterLVCurCal, 4, 4, 0x0 }; - DCDCiP = {"DCDCiP", &RegisterLVCurCal, 0, 4, 0x0 }; - HyLAM = {"HyLAM", &RegisterHyHxICfg, 31, 1, 0x0 }; - HyFlagsLatch = {"HyFlagsLatch", &RegisterHyHxICfg, 28, 1, 0x1 }; - HyFlagsLogic = {"HyFlagsLogic", &RegisterHyHxICfg, 24, 1, 0x0 }; - HyFlagValidEn = {"HyFlagValidEn", &RegisterHyHxICfg, 20, 1, 0x0 }; - HyFlagValid = {"HyFlagValid", &RegisterHyHxICfg, 16, 2, 0x0 }; - HxLAM = {"HxLAM", &RegisterHyHxICfg, 15, 1, 0x0 }; - HxFlagsLatch = {"HxFlagsLatch", &RegisterHyHxICfg, 12, 1, 0x1 }; - HxFlagsLogic = {"HxFlagsLogic", &RegisterHyHxICfg, 8, 1, 0x0 }; - HxFlagValidEn = {"HxFlagValidEn", &RegisterHyHxICfg, 4, 1, 0x0 }; - HxFlagValid = {"HxFlagValid", &RegisterHyHxICfg, 0, 2, 0x0 }; - HV2LAM = {"HV2LAM", &RegisterHV2HV0ICfg, 31, 1, 0x0 }; - HV2FlagsLatch = {"HV2FlagsLatch", &RegisterHV2HV0ICfg, 28, 1, 0x1 }; - HV2FlagsLogic = {"HV2FlagsLogic", &RegisterHV2HV0ICfg, 24, 1, 0x0 }; - HV2FlagValidEn = {"HV2FlagValidEn", &RegisterHV2HV0ICfg, 20, 1, 0x0 }; - HV2FlagValid = {"HV2FlagValid", &RegisterHV2HV0ICfg, 16, 2, 0x0 }; - HV0LAM = {"HV0LAM", &RegisterHV2HV0ICfg, 15, 1, 0x0 }; - HV0FlagsLatch = {"HV0FlagsLatch", &RegisterHV2HV0ICfg, 12, 1, 0x1 }; - HV0FlagsLogic = {"HV0FlagsLogic", &RegisterHV2HV0ICfg, 8, 1, 0x0 }; - HV0FlagValidEn = {"HV0FlagValidEn", &RegisterHV2HV0ICfg, 4, 1, 0x0 }; - HV0FlagValid = {"HV0FlagValid", &RegisterHV2HV0ICfg, 0, 2, 0x0 }; - WRNLAM = {"WRNLAM", &RegisterWRNDCDCICfg, 31, 1, 0x0 }; - WRNFlagsLatch = {"WRNFlagsLatch", &RegisterWRNDCDCICfg, 28, 1, 0x1 }; - WRNFlagsLogic = {"WRNFlagsLogic", &RegisterWRNDCDCICfg, 24, 1, 0x0 }; - WRNFlagValidEn = {"WRNFlagValidEn", &RegisterWRNDCDCICfg, 20, 1, 0x0 }; - WRNFlagValid = {"WRNFlagValid", &RegisterWRNDCDCICfg, 16, 2, 0x0 }; - DCDCLAM = {"DCDCLAM", &RegisterWRNDCDCICfg, 15, 1, 0x0 }; - DCDCFlagsLatch = {"DCDCFlagsLatch", &RegisterWRNDCDCICfg, 12, 1, 0x1 }; - DCDCFlagsLogic = {"DCDCFlagsLogic", &RegisterWRNDCDCICfg, 8, 1, 0x0 }; - DCDCFlagValidEn = {"DCDCFlagValidEn", &RegisterWRNDCDCICfg, 4, 1, 0x0 }; - DCDCFlagValid = {"DCDCFlagValid", &RegisterWRNDCDCICfg, 0, 2, 0x0 }; - HxTlut = {"HxTlut", &RegisterHxTLUT, 0, 8, 0x0 }; - HxModlut1 = {"HxModlut1", &RegisterHxModLUT1, 0, 32, 0x0 }; - HxModlut2 = {"HxModlut2", &RegisterHxModLUT2, 0, 32, 0x0 }; - HyTlut = {"HyTlut", &RegisterHyTLUT, 0, 8, 0x0 }; - HyModlut1 = {"HyModlut1", &RegisterHyModLUT1, 0, 32, 0x0 }; - HyModlut2 = {"HyModlut2", &RegisterHyModLUT2, 0, 32, 0x0 }; - HV0Tlut = {"HV0Tlut", &RegisterHV0TLUT, 0, 8, 0x0 }; - HV0Modlut1 = {"HV0Modlut1", &RegisterHV0ModLUT1, 0, 32, 0x0 }; - HV0Modlut2 = {"HV0Modlut2", &RegisterHV0ModLUT2, 0, 32, 0x0 }; - HV2Tlut = {"HV2Tlut", &RegisterHV2TLUT, 0, 8, 0x0 }; - HV2Modlut1 = {"HV2Modlut1", &RegisterHV2ModLUT1, 0, 32, 0x0 }; - HV2Modlut2 = {"HV2Modlut2", &RegisterHV2ModLUT2, 0, 32, 0x0 }; - DCDCTlut = {"DCDCTlut", &RegisterDCDCTLUT, 0, 8, 0x0 }; - DCDCModlut1 = {"DCDCModlut1", &RegisterDCDCModLUT1, 0, 32, 0x0 }; - DCDCModlut2 = {"DCDCModlut2", &RegisterDCDCModLUT2, 0, 32, 0x0 }; - WRNTlut = {"WRNTlut", &RegisterWRNTLUT, 0, 8, 0x0 }; - WRNModlut1 = {"WRNModlut1", &RegisterWRNModLUT1, 0, 32, 0x0 }; - WRNModlut2 = {"WRNModlut2", &RegisterWRNModLUT2, 0, 32, 0x0 }; - HyFlagEnSynY = {"HyFlagEnSynY", &RegisterHyHxFlagEn, 28, 2, 0x0 }; - HyILockFlagEn = {"HyILockFlagEn", &RegisterHyHxFlagEn, 16, 12, 0x0 }; - HxFlagEnSynX = {"HxFlagEnSynX", &RegisterHyHxFlagEn, 12, 2, 0x0 }; - HxILockFlagEn = {"HxILockFlagEn", &RegisterHyHxFlagEn, 0, 12, 0x0 }; - HV2FlagEnSynH2 = {"HV2FlagEnSynH2", &RegisterHV2HV0FlagEn, 28, 2, 0x0 }; - HV2ILockFlagEn = {"HV2ILockFlagEn", &RegisterHV2HV0FlagEn, 16, 12, 0x0 }; - HV0FlagEnSynH0 = {"HV0FlagEnSynH0", &RegisterHV2HV0FlagEn, 12, 2, 0x0 }; - HV0ILockFlagEn = {"HV0ILockFlagEn", &RegisterHV2HV0FlagEn, 0, 12, 0x0 }; - WRNDCDCFlagEnSynW = {"WRNDCDCFlagEnSynW", &RegisterWRNDCDCFlagEn, 28, 2, 0x0 }; - WARNILockFlagEn = {"WARNILockFlagEn", &RegisterWRNDCDCFlagEn, 16, 12, 0x0 }; - WRNDCDCFlagEnSynDc = {"WRNDCDCFlagEnSynDc", &RegisterWRNDCDCFlagEn, 12, 2, 0x0 }; - DCDCILockFlagEn = {"DCDCILockFlagEn", &RegisterWRNDCDCFlagEn, 0, 12, 0x0 }; - HxHiThCh2 = {"HxHiThCh2", &RegisterHxTh0, 20, 10, 0x3ff }; - HxLoThCh1 = {"HxLoThCh1", &RegisterHxTh0, 10, 10, 0x0 }; - HxHiThCh0 = {"HxHiThCh0", &RegisterHxTh0, 0, 10, 0x3ff }; - HxLoThCh5 = {"HxLoThCh5", &RegisterHxTh1, 20, 10, 0x0 }; - HxHiThCh4 = {"HxHiThCh4", &RegisterHxTh1, 10, 10, 0x3ff }; - HxHiThCh3 = {"HxHiThCh3", &RegisterHxTh1, 0, 10, 0x3ff }; - HxHiThCh8 = {"HxHiThCh8", &RegisterHxTh2, 20, 10, 0x3ff }; - HxHiThCh7 = {"HxHiThCh7", &RegisterHxTh2, 10, 10, 0x3ff }; - HxHiThCh6 = {"HxHiThCh6", &RegisterHxTh2, 0, 10, 0x3ff }; - HxHiThCh11 = {"HxHiThCh11", &RegisterHxTh3, 20, 10, 0x3ff }; - HxHiThCh10 = {"HxHiThCh10", &RegisterHxTh3, 10, 10, 0x3ff }; - HxHiThCh9 = {"HxHiThCh9", &RegisterHxTh3, 0, 10, 0x3ff }; - HyHiThCh2 = {"HyHiThCh2", &RegisterHyTh0, 20, 10, 0x3ff }; - HyLoThCh1 = {"HyLoThCh1", &RegisterHyTh0, 10, 10, 0x0 }; - HyHiThCh0 = {"HyHiThCh0", &RegisterHyTh0, 0, 10, 0x3ff }; - HyLoThCh5 = {"HyLoThCh5", &RegisterHyTh1, 20, 10, 0x0 }; - HyHiThCh4 = {"HyHiThCh4", &RegisterHyTh1, 10, 10, 0x3ff }; - HyHiThCh3 = {"HyHiThCh3", &RegisterHyTh1, 0, 10, 0x3ff }; - HyHiThCh8 = {"HyHiThCh8", &RegisterHyTh2, 20, 10, 0x3ff }; - HyHiThCh7 = {"HyHiThCh7", &RegisterHyTh2, 10, 10, 0x3ff }; - HyHiThCh6 = {"HyHiThCh6", &RegisterHyTh2, 0, 10, 0x3ff }; - HyHiThCh11 = {"HyHiThCh11", &RegisterHyTh3, 20, 10, 0x3ff }; - HyHiThCh10 = {"HyHiThCh10", &RegisterHyTh3, 10, 10, 0x3ff }; - HyHiThCh9 = {"HyHiThCh9", &RegisterHyTh3, 0, 10, 0x3ff }; - HV0HiThCh2 = {"HV0HiThCh2", &RegisterHV0Th0, 20, 10, 0x3ff }; - HV0LoThCh1 = {"HV0LoThCh1", &RegisterHV0Th0, 10, 10, 0x0 }; - HV0HiThCh0 = {"HV0HiThCh0", &RegisterHV0Th0, 0, 10, 0x3ff }; - HV0LoThCh5 = {"HV0LoThCh5", &RegisterHV0Th1, 20, 10, 0x0 }; - HV0HiThCh4 = {"HV0HiThCh4", &RegisterHV0Th1, 10, 10, 0x3ff }; - HV0HiThCh3 = {"HV0HiThCh3", &RegisterHV0Th1, 0, 10, 0x3ff }; - HV0HiThCh8 = {"HV0HiThCh8", &RegisterHV0Th2, 20, 10, 0x3ff }; - HV0HiThCh7 = {"HV0HiThCh7", &RegisterHV0Th2, 10, 10, 0x3ff }; - HV0HiThCh6 = {"HV0HiThCh6", &RegisterHV0Th2, 0, 10, 0x3ff }; - HV0HiThCh11 = {"HV0HiThCh11", &RegisterHV0Th3, 20, 10, 0x3ff }; - HV0HiThCh10 = {"HV0HiThCh10", &RegisterHV0Th3, 10, 10, 0x3ff }; - HV0HiThCh9 = {"HV0HiThCh9", &RegisterHV0Th3, 0, 10, 0x3ff }; - HV2HiThCh2 = {"HV2HiThCh2", &RegisterHV2Th0, 20, 10, 0x3ff }; - HV2LoThCh1 = {"HV2LoThCh1", &RegisterHV2Th0, 10, 10, 0x0 }; - HV2HiThCh0 = {"HV2HiThCh0", &RegisterHV2Th0, 0, 10, 0x3ff }; - HV2LoThCh5 = {"HV2LoThCh5", &RegisterHV2Th1, 20, 10, 0x0 }; - HV2HiThCh4 = {"HV2HiThCh4", &RegisterHV2Th1, 10, 10, 0x3ff }; - HV2HiThCh3 = {"HV2HiThCh3", &RegisterHV2Th1, 0, 10, 0x3ff }; - HV2HiThCh8 = {"HV2HiThCh8", &RegisterHV2Th2, 20, 10, 0x3ff }; - HV2HiThCh7 = {"HV2HiThCh7", &RegisterHV2Th2, 10, 10, 0x3ff }; - HV2HiThCh6 = {"HV2HiThCh6", &RegisterHV2Th2, 0, 10, 0x3ff }; - HV2HiThCh11 = {"HV2HiThCh11", &RegisterHV2Th3, 20, 10, 0x3ff }; - HV2HiThCh10 = {"HV2HiThCh10", &RegisterHV2Th3, 10, 10, 0x3ff }; - HV2HiThCh9 = {"HV2HiThCh9", &RegisterHV2Th3, 0, 10, 0x3ff }; - DCDCHiThCh2 = {"DCDCHiThCh2", &RegisterDCDCTh0, 20, 10, 0x3ff }; - DCDCLoThCh1 = {"DCDCLoThCh1", &RegisterDCDCTh0, 10, 10, 0x0 }; - DCDCHiThCh0 = {"DCDCHiThCh0", &RegisterDCDCTh0, 0, 10, 0x3ff }; - DCDCLoThCh5 = {"DCDCLoThCh5", &RegisterDCDCTh1, 20, 10, 0x0 }; - DCDCHiThCh4 = {"DCDCHiThCh4", &RegisterDCDCTh1, 10, 10, 0x3ff }; - DCDCHiThCh3 = {"DCDCHiThCh3", &RegisterDCDCTh1, 0, 10, 0x3ff }; - DCDCHiThCh8 = {"DCDCHiThCh8", &RegisterDCDCTh2, 20, 10, 0x3ff }; - DCDCHiThCh7 = {"DCDCHiThCh7", &RegisterDCDCTh2, 10, 10, 0x3ff }; - DCDCHiThCh6 = {"DCDCHiThCh6", &RegisterDCDCTh2, 0, 10, 0x3ff }; - DCDCHiThCh11 = {"DCDCHiThCh11", &RegisterDCDCTh3, 20, 10, 0x3ff }; - DCDCHiThCh10 = {"DCDCHiThCh10", &RegisterDCDCTh3, 10, 10, 0x3ff }; - DCDCHiThCh9 = {"DCDCHiThCh9", &RegisterDCDCTh3, 0, 10, 0x3ff }; - WRNHiThCh2 = {"WRNHiThCh2", &RegisterWRNTh0, 20, 10, 0x3ff }; - WRNLoThCh1 = {"WRNLoThCh1", &RegisterWRNTh0, 10, 10, 0x0 }; - WRNHiThCh0 = {"WRNHiThCh0", &RegisterWRNTh0, 0, 10, 0x3ff }; - WRNLoThCh5 = {"WRNLoThCh5", &RegisterWRNTh1, 20, 10, 0x0 }; - WRNHiThCh4 = {"WRNHiThCh4", &RegisterWRNTh1, 10, 10, 0x3ff }; - WRNHiThCh3 = {"WRNHiThCh3", &RegisterWRNTh1, 0, 10, 0x3ff }; - WRNHiThCh8 = {"WRNHiThCh8", &RegisterWRNTh2, 20, 10, 0x3ff }; - WRNHiThCh7 = {"WRNHiThCh7", &RegisterWRNTh2, 10, 10, 0x3ff }; - WRNHiThCh6 = {"WRNHiThCh6", &RegisterWRNTh2, 0, 10, 0x3ff }; - WRNHiThCh11 = {"WRNHiThCh11", &RegisterWRNTh3, 20, 10, 0x3ff }; - WRNHiThCh10 = {"WRNHiThCh10", &RegisterWRNTh3, 10, 10, 0x3ff }; - WRNHiThCh9 = {"WRNHiThCh9", &RegisterWRNTh3, 0, 10, 0x3ff }; + StatusAM = {"StatusAM", &RegisterStatus, 31, 1, 0x0}; + StatusWARN = {"StatusWARN", &RegisterStatus, 29, 1, 0x0}; + StatusDCDC = {"StatusDCDC", &RegisterStatus, 28, 1, 0x0}; + StatusHV3 = {"StatusHV3", &RegisterStatus, 27, 1, 0x0}; + StatusHV2 = {"StatusHV2", &RegisterStatus, 26, 1, 0x0}; + StatusHV1 = {"StatusHV1", &RegisterStatus, 25, 1, 0x0}; + StatusHV0 = {"StatusHV0", &RegisterStatus, 24, 1, 0x0}; + StatusY2LDO = {"StatusY2LDO", &RegisterStatus, 22, 1, 0x0}; + StatusY1LDO = {"StatusY1LDO", &RegisterStatus, 21, 1, 0x0}; + StatusY0LDO = {"StatusY0LDO", &RegisterStatus, 20, 1, 0x0}; + StatusX2LDO = {"StatusX2LDO", &RegisterStatus, 18, 1, 0x0}; + StatusX1LDO = {"StatusX1LDO", &RegisterStatus, 17, 1, 0x0}; + StatusX0LDO = {"StatusX0LDO", &RegisterStatus, 16, 1, 0x0}; + StatusGPI = {"StatusGPI", &RegisterStatus, 12, 1, 0x0}; + StatusPGOOD = {"StatusPGOOD", &RegisterStatus, 8, 1, 0x0}; + AMACVersion = {"AMACVersion", &RegisterStatus, 6, 2, 0x0}; + StatusILockWARN = {"StatusILockWARN", &RegisterStatus, 5, 1, 0x0}; + StatusILockDCDC = {"StatusILockDCDC", &RegisterStatus, 4, 1, 0x0}; + StatusILockHV2 = {"StatusILockHV2", &RegisterStatus, 3, 1, 0x0}; + StatusILockHV0 = {"StatusILockHV0", &RegisterStatus, 2, 1, 0x0}; + StatusILockYLDO = {"StatusILockYLDO", &RegisterStatus, 1, 1, 0x0}; + StatusILockxLDO = {"StatusILockxLDO", &RegisterStatus, 0, 1, 0x0}; + SynFlagsHy = {"SynFlagsHy", &RegisterHyHxFlags, 28, 2, 0x0}; + HyChFlags = {"HyChFlags", &RegisterHyHxFlags, 16, 12, 0x0}; + SynFlagsHx = {"SynFlagsHx", &RegisterHyHxFlags, 12, 2, 0x0}; + HxChFlags = {"HxChFlags", &RegisterHyHxFlags, 0, 12, 0x0}; + SynFlagsHV2 = {"SynFlagsHV2", &RegisterHV2HV0Flags, 28, 2, 0x0}; + HV2ChFlags = {"HV2ChFlags", &RegisterHV2HV0Flags, 16, 12, 0x0}; + SynFlagsHV0 = {"SynFlagsHV0", &RegisterHV2HV0Flags, 12, 2, 0x0}; + HV0ChFlags = {"HV0ChFlags", &RegisterHV2HV0Flags, 0, 12, 0x0}; + SynFlagsWRN = {"SynFlagsWRN", &RegisterWRNDCDCFlags, 28, 2, 0x0}; + WRNChFlags = {"WRNChFlags", &RegisterWRNDCDCFlags, 16, 12, 0x0}; + SynFlagsDCDC = {"SynFlagsDCDC", &RegisterWRNDCDCFlags, 12, 2, 0x0}; + DCDCChFlags = {"DCDCChFlags", &RegisterWRNDCDCFlags, 0, 12, 0x0}; + Value0AMen = {"Value0AMen", &RegisterValue0, 31, 1, 0x0}; + Ch2Value = {"Ch2Value", &RegisterValue0, 20, 10, 0x0}; + Ch1Value = {"Ch1Value", &RegisterValue0, 10, 10, 0x0}; + Ch0Value = {"Ch0Value", &RegisterValue0, 0, 10, 0x0}; + Value1AMen = {"Value1AMen", &RegisterValue1, 31, 1, 0x0}; + Ch5Value = {"Ch5Value", &RegisterValue1, 20, 10, 0x0}; + Ch4Value = {"Ch4Value", &RegisterValue1, 10, 10, 0x0}; + Ch3Value = {"Ch3Value", &RegisterValue1, 0, 10, 0x0}; + Value2AMen = {"Value2AMen", &RegisterValue2, 31, 1, 0x0}; + Ch8Value = {"Ch8Value", &RegisterValue2, 20, 10, 0x0}; + Ch7Value = {"Ch7Value", &RegisterValue2, 10, 10, 0x0}; + Ch6Value = {"Ch6Value", &RegisterValue2, 0, 10, 0x0}; + Value3AMen = {"Value3AMen", &RegisterValue3, 31, 1, 0x0}; + Ch11Value = {"Ch11Value", &RegisterValue3, 20, 10, 0x0}; + Ch10Value = {"Ch10Value", &RegisterValue3, 10, 10, 0x0}; + Ch9Value = {"Ch9Value", &RegisterValue3, 0, 10, 0x0}; + Value4AMen = {"Value4AMen", &RegisterValue4, 31, 1, 0x0}; + Ch13S = {"Ch13S", &RegisterValue4, 28, 3, 0x0}; + Ch12S = {"Ch12S", &RegisterValue4, 24, 2, 0x0}; + Ch13Value = {"Ch13Value", &RegisterValue4, 10, 10, 0x0}; + Ch12Value = {"Ch12Value", &RegisterValue4, 0, 10, 0x0}; + Value5AMen = {"Value5AMen", &RegisterValue5, 31, 1, 0x0}; + Ch15S = {"Ch15S", &RegisterValue5, 28, 3, 0x0}; + Ch14S = {"Ch14S", &RegisterValue5, 24, 3, 0x0}; + Ch15Value = {"Ch15Value", &RegisterValue5, 10, 10, 0x0}; + Ch14Value = {"Ch14Value", &RegisterValue5, 0, 10, 0x0}; + SEUStatusLo = {"SEUStatusLo", &RegisterSEUstatus0, 0, 32, 0x0}; + SEUStatusHi = {"SEUStatusHi", &RegisterSEUstatus1, 0, 30, 0x0}; + FlagResetOe = {"FlagResetOe", &RegisterFlagResets, 24, 1, 0x0}; + FlagResetS = {"FlagResetS", &RegisterFlagResets, 8, 1, 0x0}; + FlagResetWRN = {"FlagResetWRN", &RegisterFlagResets, 5, 1, 0x0}; + FlagResetDCDC = {"FlagResetDCDC", &RegisterFlagResets, 4, 1, 0x0}; + FlagResetHV2 = {"FlagResetHV2", &RegisterFlagResets, 3, 1, 0x0}; + FlagResetHV0 = {"FlagResetHV0", &RegisterFlagResets, 2, 1, 0x0}; + FlagResetYLDO = {"FlagResetYLDO", &RegisterFlagResets, 1, 1, 0x0}; + FlagResetXLDO = {"FlagResetXLDO", &RegisterFlagResets, 0, 1, 0x0}; + LogicReset = {"LogicReset", &RegisterLogicReset, 0, 32, 0x0}; + HardReset = {"HardReset", &RegisterHardReset, 0, 32, 0x0}; + CntSetHV3frq = {"CntSetHV3frq", &RegisterCntSet, 29, 2, 0x3}; + CntSetHV3en = {"CntSetHV3en", &RegisterCntSet, 28, 1, 0x0}; + CntSetHV2frq = {"CntSetHV2frq", &RegisterCntSet, 25, 2, 0x3}; + CntSetHV2en = {"CntSetHV2en", &RegisterCntSet, 24, 1, 0x0}; + CntSetHV1frq = {"CntSetHV1frq", &RegisterCntSet, 21, 2, 0x3}; + CntSetHV1en = {"CntSetHV1en", &RegisterCntSet, 20, 1, 0x0}; + CntSetHV0frq = {"CntSetHV0frq", &RegisterCntSet, 17, 2, 0x3}; + CntSetHV0en = {"CntSetHV0en", &RegisterCntSet, 16, 1, 0x0}; + CntSetHyLDO2en = {"CntSetHyLDO2en", &RegisterCntSet, 14, 1, 0x0}; + CntSetHyLDO1en = {"CntSetHyLDO1en", &RegisterCntSet, 13, 1, 0x0}; + CntSetHyLDO0en = {"CntSetHyLDO0en", &RegisterCntSet, 12, 1, 0x0}; + CntSetHxLDO2en = {"CntSetHxLDO2en", &RegisterCntSet, 10, 1, 0x0}; + CntSetHxLDO1en = {"CntSetHxLDO1en", &RegisterCntSet, 9, 1, 0x0}; + CntSetHxLDO0en = {"CntSetHxLDO0en", &RegisterCntSet, 8, 1, 0x0}; + CntSetWARN = {"CntSetWARN", &RegisterCntSet, 4, 1, 0x0}; + DCDCAdj = {"DCDCAdj", &RegisterDCDCen, 4, 2, 0x0}; + DCDCen = {"DCDCen", &RegisterDCDCen, 0, 1, 0x0}; + IlockWRN = {"IlockWRN", &RegisterIlock, 5, 1, 0x0}; + IlockDCDC = {"IlockDCDC", &RegisterIlock, 4, 1, 0x0}; + IlockHV2 = {"IlockHV2", &RegisterIlock, 3, 1, 0x0}; + IlockHV0 = {"IlockHV0", &RegisterIlock, 2, 1, 0x0}; + IlockHy = {"IlockHy", &RegisterIlock, 1, 1, 0x0}; + IlockHx = {"IlockHx", &RegisterIlock, 0, 1, 0x0}; + RstCntHyHCCresetB = {"RstCntHyHCCresetB", &RegisterRstCnt, 16, 1, 0x0}; + RstCntHxHCCresetB = {"RstCntHxHCCresetB", &RegisterRstCnt, 8, 1, 0x0}; + RstCntOF = {"RstCntOF", &RegisterRstCnt, 0, 1, 0x0}; + AMzeroCalib = {"AMzeroCalib", &RegisterAMen, 8, 1, 0x0}; + AMen = {"AMen", &RegisterAMen, 0, 1, 0x1}; + ClockDisableEn = {"ClockDisableEn", &RegisterAMpwr, 16, 1, 0x0}; + ReqDCDCPGOOD = {"ReqDCDCPGOOD", &RegisterAMpwr, 8, 1, 0x1}; + DCDCenToPwrAMAC = {"DCDCenToPwrAMAC", &RegisterAMpwr, 0, 1, 0x0}; + AMbgen = {"AMbgen", &RegisterBgCnt, 24, 1, 0x0}; + AMbgSW = {"AMbgSW", &RegisterBgCnt, 23, 1, 0x0}; + AMbg = {"AMbg", &RegisterBgCnt, 16, 5, 0x0}; + VDDbgen = {"VDDbgen", &RegisterBgCnt, 8, 1, 0x0}; + VDDbgSW = {"VDDbgSW", &RegisterBgCnt, 7, 1, 0x0}; + VDDbg = {"VDDbg", &RegisterBgCnt, 0, 5, 0x0}; + AMCntRg = {"AMCntRg", &RegisterAMCnt, 28, 1, 0x0}; + AMintCalib = {"AMintCalib", &RegisterAMCnt, 24, 4, 0x0}; + Ch15Mux = {"Ch15Mux", &RegisterAMCnt, 16, 3, 0x0}; + Ch14Mux = {"Ch14Mux", &RegisterAMCnt, 12, 3, 0x0}; + Ch13Mux = {"Ch13Mux", &RegisterAMCnt, 8, 3, 0x0}; + Ch12AMux = {"Ch12AMux", &RegisterAMCnt, 6, 1, 0x0}; + Ch12Mux = {"Ch12Mux", &RegisterAMCnt, 4, 2, 0x0}; + DACShunty = {"DACShunty", &RegisterDACs0, 24, 8, 0x0}; + DACShuntx = {"DACShuntx", &RegisterDACs0, 16, 8, 0x0}; + DACCaly = {"DACCaly", &RegisterDACs0, 8, 8, 0x0}; + DACCalx = {"DACCalx", &RegisterDACs0, 0, 8, 0x0}; + ShuntEn = {"ShuntEn", &RegisterDACbias, 8, 1, 0x0}; + DACbias = {"DACbias", &RegisterDACbias, 0, 5, 0xd}; + eFusebitSelect = {"eFusebitSelect", &RegisterAMACCnt, 24, 5, 0x0}; + HVcurGain = {"HVcurGain", &RegisterAMACCnt, 16, 4, 0x0}; + DRcomMode = {"DRcomMode", &RegisterAMACCnt, 12, 2, 0x0}; + DRcurr = {"DRcurr", &RegisterAMACCnt, 8, 3, 0x4}; + ClkDis = {"ClkDis", &RegisterAMACCnt, 4, 2, 0x0}; + RingOscFrq = {"RingOscFrq", &RegisterAMACCnt, 0, 3, 0x4}; + CTAToffset = {"CTAToffset", &RegisterNTCRange, 24, 4, 0x3}; + NTCpbCal = {"NTCpbCal", &RegisterNTCRange, 19, 1, 0x0}; + NTCpbSenseRange = {"NTCpbSenseRange", &RegisterNTCRange, 16, 3, 0x4}; + NTCy0Cal = {"NTCy0Cal", &RegisterNTCRange, 11, 1, 0x0}; + NTCy0SenseRange = {"NTCy0SenseRange", &RegisterNTCRange, 8, 3, 0x4}; + NTCx0Cal = {"NTCx0Cal", &RegisterNTCRange, 3, 1, 0x0}; + NTCx0SenseRange = {"NTCx0SenseRange", &RegisterNTCRange, 0, 3, 0x4}; + DCDCoZeroReading = {"DCDCoZeroReading", &RegisterLVCurCal, 24, 1, 0x0}; + DCDCoOffset = {"DCDCoOffset", &RegisterLVCurCal, 20, 4, 0x4}; + DCDCoN = {"DCDCoN", &RegisterLVCurCal, 18, 2, 0x0}; + DCDCoP = {"DCDCoP", &RegisterLVCurCal, 16, 2, 0x0}; + DCDCiZeroReading = {"DCDCiZeroReading", &RegisterLVCurCal, 15, 1, 0x0}; + DCDCiRangeSW = {"DCDCiRangeSW", &RegisterLVCurCal, 12, 1, 0x1}; + DCDCiOffset = {"DCDCiOffset", &RegisterLVCurCal, 8, 4, 0x5}; + DCDCiN = {"DCDCiN", &RegisterLVCurCal, 4, 4, 0x0}; + DCDCiP = {"DCDCiP", &RegisterLVCurCal, 0, 4, 0x0}; + HyLAM = {"HyLAM", &RegisterHyHxICfg, 31, 1, 0x0}; + HyFlagsLatch = {"HyFlagsLatch", &RegisterHyHxICfg, 28, 1, 0x1}; + HyFlagsLogic = {"HyFlagsLogic", &RegisterHyHxICfg, 24, 1, 0x0}; + HyFlagValidEn = {"HyFlagValidEn", &RegisterHyHxICfg, 20, 1, 0x0}; + HyFlagValid = {"HyFlagValid", &RegisterHyHxICfg, 16, 2, 0x0}; + HxLAM = {"HxLAM", &RegisterHyHxICfg, 15, 1, 0x0}; + HxFlagsLatch = {"HxFlagsLatch", &RegisterHyHxICfg, 12, 1, 0x1}; + HxFlagsLogic = {"HxFlagsLogic", &RegisterHyHxICfg, 8, 1, 0x0}; + HxFlagValidEn = {"HxFlagValidEn", &RegisterHyHxICfg, 4, 1, 0x0}; + HxFlagValid = {"HxFlagValid", &RegisterHyHxICfg, 0, 2, 0x0}; + HV2LAM = {"HV2LAM", &RegisterHV2HV0ICfg, 31, 1, 0x0}; + HV2FlagsLatch = {"HV2FlagsLatch", &RegisterHV2HV0ICfg, 28, 1, 0x1}; + HV2FlagsLogic = {"HV2FlagsLogic", &RegisterHV2HV0ICfg, 24, 1, 0x0}; + HV2FlagValidEn = {"HV2FlagValidEn", &RegisterHV2HV0ICfg, 20, 1, 0x0}; + HV2FlagValid = {"HV2FlagValid", &RegisterHV2HV0ICfg, 16, 2, 0x0}; + HV0LAM = {"HV0LAM", &RegisterHV2HV0ICfg, 15, 1, 0x0}; + HV0FlagsLatch = {"HV0FlagsLatch", &RegisterHV2HV0ICfg, 12, 1, 0x1}; + HV0FlagsLogic = {"HV0FlagsLogic", &RegisterHV2HV0ICfg, 8, 1, 0x0}; + HV0FlagValidEn = {"HV0FlagValidEn", &RegisterHV2HV0ICfg, 4, 1, 0x0}; + HV0FlagValid = {"HV0FlagValid", &RegisterHV2HV0ICfg, 0, 2, 0x0}; + WRNLAM = {"WRNLAM", &RegisterWRNDCDCICfg, 31, 1, 0x0}; + WRNFlagsLatch = {"WRNFlagsLatch", &RegisterWRNDCDCICfg, 28, 1, 0x1}; + WRNFlagsLogic = {"WRNFlagsLogic", &RegisterWRNDCDCICfg, 24, 1, 0x0}; + WRNFlagValidEn = {"WRNFlagValidEn", &RegisterWRNDCDCICfg, 20, 1, 0x0}; + WRNFlagValid = {"WRNFlagValid", &RegisterWRNDCDCICfg, 16, 2, 0x0}; + DCDCLAM = {"DCDCLAM", &RegisterWRNDCDCICfg, 15, 1, 0x0}; + DCDCFlagsLatch = {"DCDCFlagsLatch", &RegisterWRNDCDCICfg, 12, 1, 0x1}; + DCDCFlagsLogic = {"DCDCFlagsLogic", &RegisterWRNDCDCICfg, 8, 1, 0x0}; + DCDCFlagValidEn = {"DCDCFlagValidEn", &RegisterWRNDCDCICfg, 4, 1, 0x0}; + DCDCFlagValid = {"DCDCFlagValid", &RegisterWRNDCDCICfg, 0, 2, 0x0}; + HxTlut = {"HxTlut", &RegisterHxTLUT, 0, 8, 0x0}; + HxModlut1 = {"HxModlut1", &RegisterHxModLUT1, 0, 32, 0x0}; + HxModlut2 = {"HxModlut2", &RegisterHxModLUT2, 0, 32, 0x0}; + HyTlut = {"HyTlut", &RegisterHyTLUT, 0, 8, 0x0}; + HyModlut1 = {"HyModlut1", &RegisterHyModLUT1, 0, 32, 0x0}; + HyModlut2 = {"HyModlut2", &RegisterHyModLUT2, 0, 32, 0x0}; + HV0Tlut = {"HV0Tlut", &RegisterHV0TLUT, 0, 8, 0x0}; + HV0Modlut1 = {"HV0Modlut1", &RegisterHV0ModLUT1, 0, 32, 0x0}; + HV0Modlut2 = {"HV0Modlut2", &RegisterHV0ModLUT2, 0, 32, 0x0}; + HV2Tlut = {"HV2Tlut", &RegisterHV2TLUT, 0, 8, 0x0}; + HV2Modlut1 = {"HV2Modlut1", &RegisterHV2ModLUT1, 0, 32, 0x0}; + HV2Modlut2 = {"HV2Modlut2", &RegisterHV2ModLUT2, 0, 32, 0x0}; + DCDCTlut = {"DCDCTlut", &RegisterDCDCTLUT, 0, 8, 0x0}; + DCDCModlut1 = {"DCDCModlut1", &RegisterDCDCModLUT1, 0, 32, 0x0}; + DCDCModlut2 = {"DCDCModlut2", &RegisterDCDCModLUT2, 0, 32, 0x0}; + WRNTlut = {"WRNTlut", &RegisterWRNTLUT, 0, 8, 0x0}; + WRNModlut1 = {"WRNModlut1", &RegisterWRNModLUT1, 0, 32, 0x0}; + WRNModlut2 = {"WRNModlut2", &RegisterWRNModLUT2, 0, 32, 0x0}; + HyFlagEnSynY = {"HyFlagEnSynY", &RegisterHyHxFlagEn, 28, 2, 0x0}; + HyILockFlagEn = {"HyILockFlagEn", &RegisterHyHxFlagEn, 16, 12, 0x0}; + HxFlagEnSynX = {"HxFlagEnSynX", &RegisterHyHxFlagEn, 12, 2, 0x0}; + HxILockFlagEn = {"HxILockFlagEn", &RegisterHyHxFlagEn, 0, 12, 0x0}; + HV2FlagEnSynH2 = {"HV2FlagEnSynH2", &RegisterHV2HV0FlagEn, 28, 2, 0x0}; + HV2ILockFlagEn = {"HV2ILockFlagEn", &RegisterHV2HV0FlagEn, 16, 12, 0x0}; + HV0FlagEnSynH0 = {"HV0FlagEnSynH0", &RegisterHV2HV0FlagEn, 12, 2, 0x0}; + HV0ILockFlagEn = {"HV0ILockFlagEn", &RegisterHV2HV0FlagEn, 0, 12, 0x0}; + WRNDCDCFlagEnSynW = {"WRNDCDCFlagEnSynW", &RegisterWRNDCDCFlagEn, 28, 2, + 0x0}; + WARNILockFlagEn = {"WARNILockFlagEn", &RegisterWRNDCDCFlagEn, 16, 12, 0x0}; + WRNDCDCFlagEnSynDc = {"WRNDCDCFlagEnSynDc", &RegisterWRNDCDCFlagEn, 12, 2, + 0x0}; + DCDCILockFlagEn = {"DCDCILockFlagEn", &RegisterWRNDCDCFlagEn, 0, 12, 0x0}; + HxHiThCh2 = {"HxHiThCh2", &RegisterHxTh0, 20, 10, 0x3ff}; + HxLoThCh1 = {"HxLoThCh1", &RegisterHxTh0, 10, 10, 0x0}; + HxHiThCh0 = {"HxHiThCh0", &RegisterHxTh0, 0, 10, 0x3ff}; + HxLoThCh5 = {"HxLoThCh5", &RegisterHxTh1, 20, 10, 0x0}; + HxHiThCh4 = {"HxHiThCh4", &RegisterHxTh1, 10, 10, 0x3ff}; + HxHiThCh3 = {"HxHiThCh3", &RegisterHxTh1, 0, 10, 0x3ff}; + HxHiThCh8 = {"HxHiThCh8", &RegisterHxTh2, 20, 10, 0x3ff}; + HxHiThCh7 = {"HxHiThCh7", &RegisterHxTh2, 10, 10, 0x3ff}; + HxHiThCh6 = {"HxHiThCh6", &RegisterHxTh2, 0, 10, 0x3ff}; + HxHiThCh11 = {"HxHiThCh11", &RegisterHxTh3, 20, 10, 0x3ff}; + HxHiThCh10 = {"HxHiThCh10", &RegisterHxTh3, 10, 10, 0x3ff}; + HxHiThCh9 = {"HxHiThCh9", &RegisterHxTh3, 0, 10, 0x3ff}; + HyHiThCh2 = {"HyHiThCh2", &RegisterHyTh0, 20, 10, 0x3ff}; + HyLoThCh1 = {"HyLoThCh1", &RegisterHyTh0, 10, 10, 0x0}; + HyHiThCh0 = {"HyHiThCh0", &RegisterHyTh0, 0, 10, 0x3ff}; + HyLoThCh5 = {"HyLoThCh5", &RegisterHyTh1, 20, 10, 0x0}; + HyHiThCh4 = {"HyHiThCh4", &RegisterHyTh1, 10, 10, 0x3ff}; + HyHiThCh3 = {"HyHiThCh3", &RegisterHyTh1, 0, 10, 0x3ff}; + HyHiThCh8 = {"HyHiThCh8", &RegisterHyTh2, 20, 10, 0x3ff}; + HyHiThCh7 = {"HyHiThCh7", &RegisterHyTh2, 10, 10, 0x3ff}; + HyHiThCh6 = {"HyHiThCh6", &RegisterHyTh2, 0, 10, 0x3ff}; + HyHiThCh11 = {"HyHiThCh11", &RegisterHyTh3, 20, 10, 0x3ff}; + HyHiThCh10 = {"HyHiThCh10", &RegisterHyTh3, 10, 10, 0x3ff}; + HyHiThCh9 = {"HyHiThCh9", &RegisterHyTh3, 0, 10, 0x3ff}; + HV0HiThCh2 = {"HV0HiThCh2", &RegisterHV0Th0, 20, 10, 0x3ff}; + HV0LoThCh1 = {"HV0LoThCh1", &RegisterHV0Th0, 10, 10, 0x0}; + HV0HiThCh0 = {"HV0HiThCh0", &RegisterHV0Th0, 0, 10, 0x3ff}; + HV0LoThCh5 = {"HV0LoThCh5", &RegisterHV0Th1, 20, 10, 0x0}; + HV0HiThCh4 = {"HV0HiThCh4", &RegisterHV0Th1, 10, 10, 0x3ff}; + HV0HiThCh3 = {"HV0HiThCh3", &RegisterHV0Th1, 0, 10, 0x3ff}; + HV0HiThCh8 = {"HV0HiThCh8", &RegisterHV0Th2, 20, 10, 0x3ff}; + HV0HiThCh7 = {"HV0HiThCh7", &RegisterHV0Th2, 10, 10, 0x3ff}; + HV0HiThCh6 = {"HV0HiThCh6", &RegisterHV0Th2, 0, 10, 0x3ff}; + HV0HiThCh11 = {"HV0HiThCh11", &RegisterHV0Th3, 20, 10, 0x3ff}; + HV0HiThCh10 = {"HV0HiThCh10", &RegisterHV0Th3, 10, 10, 0x3ff}; + HV0HiThCh9 = {"HV0HiThCh9", &RegisterHV0Th3, 0, 10, 0x3ff}; + HV2HiThCh2 = {"HV2HiThCh2", &RegisterHV2Th0, 20, 10, 0x3ff}; + HV2LoThCh1 = {"HV2LoThCh1", &RegisterHV2Th0, 10, 10, 0x0}; + HV2HiThCh0 = {"HV2HiThCh0", &RegisterHV2Th0, 0, 10, 0x3ff}; + HV2LoThCh5 = {"HV2LoThCh5", &RegisterHV2Th1, 20, 10, 0x0}; + HV2HiThCh4 = {"HV2HiThCh4", &RegisterHV2Th1, 10, 10, 0x3ff}; + HV2HiThCh3 = {"HV2HiThCh3", &RegisterHV2Th1, 0, 10, 0x3ff}; + HV2HiThCh8 = {"HV2HiThCh8", &RegisterHV2Th2, 20, 10, 0x3ff}; + HV2HiThCh7 = {"HV2HiThCh7", &RegisterHV2Th2, 10, 10, 0x3ff}; + HV2HiThCh6 = {"HV2HiThCh6", &RegisterHV2Th2, 0, 10, 0x3ff}; + HV2HiThCh11 = {"HV2HiThCh11", &RegisterHV2Th3, 20, 10, 0x3ff}; + HV2HiThCh10 = {"HV2HiThCh10", &RegisterHV2Th3, 10, 10, 0x3ff}; + HV2HiThCh9 = {"HV2HiThCh9", &RegisterHV2Th3, 0, 10, 0x3ff}; + DCDCHiThCh2 = {"DCDCHiThCh2", &RegisterDCDCTh0, 20, 10, 0x3ff}; + DCDCLoThCh1 = {"DCDCLoThCh1", &RegisterDCDCTh0, 10, 10, 0x0}; + DCDCHiThCh0 = {"DCDCHiThCh0", &RegisterDCDCTh0, 0, 10, 0x3ff}; + DCDCLoThCh5 = {"DCDCLoThCh5", &RegisterDCDCTh1, 20, 10, 0x0}; + DCDCHiThCh4 = {"DCDCHiThCh4", &RegisterDCDCTh1, 10, 10, 0x3ff}; + DCDCHiThCh3 = {"DCDCHiThCh3", &RegisterDCDCTh1, 0, 10, 0x3ff}; + DCDCHiThCh8 = {"DCDCHiThCh8", &RegisterDCDCTh2, 20, 10, 0x3ff}; + DCDCHiThCh7 = {"DCDCHiThCh7", &RegisterDCDCTh2, 10, 10, 0x3ff}; + DCDCHiThCh6 = {"DCDCHiThCh6", &RegisterDCDCTh2, 0, 10, 0x3ff}; + DCDCHiThCh11 = {"DCDCHiThCh11", &RegisterDCDCTh3, 20, 10, 0x3ff}; + DCDCHiThCh10 = {"DCDCHiThCh10", &RegisterDCDCTh3, 10, 10, 0x3ff}; + DCDCHiThCh9 = {"DCDCHiThCh9", &RegisterDCDCTh3, 0, 10, 0x3ff}; + WRNHiThCh2 = {"WRNHiThCh2", &RegisterWRNTh0, 20, 10, 0x3ff}; + WRNLoThCh1 = {"WRNLoThCh1", &RegisterWRNTh0, 10, 10, 0x0}; + WRNHiThCh0 = {"WRNHiThCh0", &RegisterWRNTh0, 0, 10, 0x3ff}; + WRNLoThCh5 = {"WRNLoThCh5", &RegisterWRNTh1, 20, 10, 0x0}; + WRNHiThCh4 = {"WRNHiThCh4", &RegisterWRNTh1, 10, 10, 0x3ff}; + WRNHiThCh3 = {"WRNHiThCh3", &RegisterWRNTh1, 0, 10, 0x3ff}; + WRNHiThCh8 = {"WRNHiThCh8", &RegisterWRNTh2, 20, 10, 0x3ff}; + WRNHiThCh7 = {"WRNHiThCh7", &RegisterWRNTh2, 10, 10, 0x3ff}; + WRNHiThCh6 = {"WRNHiThCh6", &RegisterWRNTh2, 0, 10, 0x3ff}; + WRNHiThCh11 = {"WRNHiThCh11", &RegisterWRNTh3, 20, 10, 0x3ff}; + WRNHiThCh10 = {"WRNHiThCh10", &RegisterWRNTh3, 10, 10, 0x3ff}; + WRNHiThCh9 = {"WRNHiThCh9", &RegisterWRNTh3, 0, 10, 0x3ff}; /** @} */ } diff --git a/pbv3/AMACv2RegMap_v2.cpp b/pbv3/AMACv2RegMap_v2.cpp index c510f91599d2c5a321e0508a33f511a5522ffb0f..92d85645e26e9dcab7bd06421653eae894acf98b 100644 --- a/pbv3/AMACv2RegMap_v2.cpp +++ b/pbv3/AMACv2RegMap_v2.cpp @@ -1,10 +1,9 @@ #include "AMACv2RegMap.h" -void AMACv2RegMap::init_v2() -{ +void AMACv2RegMap::init_v2() { /** \name Registers * @{ */ - //RegisterStatus = {"Status", 0, RO}; + // RegisterStatus = {"Status", 0, RO}; RegisterHxFlags = {"HxFlags", 1, RO}; RegisterHyFlags = {"HyFlags", 2, RO}; RegisterHV0Flags = {"HV0Flags", 3, RO}; @@ -175,7 +174,7 @@ void AMACv2RegMap::init_v2() StatusILockHV0 = {"StatusILockHV2", &RegisterStatus, 2, 1, 0}; StatusILockYLDO = {"StatusILockYLDO", &RegisterStatus, 1, 1, 0}; StatusILockxLDO = {"StatusILockxLDO", &RegisterStatus, 0, 1, 0}; - AMACVersion = {"AMACVersion", &RegisterStatus, 6, 2, 0 }; + AMACVersion = {"AMACVersion", &RegisterStatus, 6, 2, 0}; // 1 - HxFlags HxFlagsHi = {"HxFlagsHi", &RegisterHxFlags, 16, 16, 0x0}; HxFlagsLo = {"HxFlagsLo", &RegisterHxFlags, 0, 16, 0x0}; @@ -225,7 +224,8 @@ void AMACv2RegMap::init_v2() Value4AMen = {"Value4AMen", &RegisterValue4, 31, 1, 0x0}; Ch12Value = {"Ch12Value", &RegisterValue4, 0, 10, 0x0}; Ch13Value = {"Ch13Value", &RegisterValue4, 10, 10, 0x0}; - Ch14Value = {"Ch14Value", &RegisterValue4, 20, 10, 0x0}; // CH14 is HVret on amac v2. Why it is called Ch14Value? + Ch14Value = {"Ch14Value", &RegisterValue4, 20, 10, + 0x0}; // CH14 is HVret on amac v2. Why it is called Ch14Value? // 15 - Value5 Value5AMen = {"Value5AMen", &RegisterValue5, 31, 1, 0x0}; Ch15Value = {"Ch15Value", &RegisterValue5, 0, 10, 0x0}; diff --git a/pbv3/AMACv2Register.cpp b/pbv3/AMACv2Register.cpp index 361b1810a54923e87e4f05ec4f286ccaad92b01d..8201672a88587383987a7d5b4a3263ea458d54e0 100644 --- a/pbv3/AMACv2Register.cpp +++ b/pbv3/AMACv2Register.cpp @@ -1,23 +1,17 @@ #include "AMACv2Register.h" -AMACv2Register::AMACv2Register(const std::string& name, uint32_t address, rw_t rw) - : m_name(name), m_address(address), m_rw(rw) -{ } +AMACv2Register::AMACv2Register(const std::string& name, uint32_t address, + rw_t rw) + : m_name(name), m_address(address), m_rw(rw) {} -bool AMACv2Register::isValid() const -{ return !m_name.empty(); } +bool AMACv2Register::isValid() const { return !m_name.empty(); } -std::string AMACv2Register::getName() const -{ return m_name; } +std::string AMACv2Register::getName() const { return m_name; } -uint8_t AMACv2Register::getAddress() const -{ return m_address; } +uint8_t AMACv2Register::getAddress() const { return m_address; } -void AMACv2Register::setValue(uint32_t value) -{ m_value=value; } +void AMACv2Register::setValue(uint32_t value) { m_value = value; } -uint32_t AMACv2Register::getValue() const -{ return m_value; } +uint32_t AMACv2Register::getValue() const { return m_value; } -rw_t AMACv2Register::isRW() const -{ return m_rw; } +rw_t AMACv2Register::isRW() const { return m_rw; } diff --git a/pbv3/AMACv2Register.h b/pbv3/AMACv2Register.h index 82429c4a4108f0b62e6cdad89d39e3917a10bcfa..8dd933ab429b3a62f6f2ee3afe488eecd43acba0 100644 --- a/pbv3/AMACv2Register.h +++ b/pbv3/AMACv2Register.h @@ -1,58 +1,57 @@ #ifndef AMACV2REGISTER_H #define AMACV2REGISTER_H -#include <iostream> #include <cstdint> +#include <iostream> -enum rw_t {RO=1, WO=2, RW=3}; +enum rw_t { RO = 1, WO = 2, RW = 3 }; //! \brief Description of an AMACv2 register -class AMACv2Register -{ -public: - //! Create an undefined (invalid) register - AMACv2Register() =default; - - //! Create a named register - /** - * Default register values should be set through field - * operations. - * - * \param name Register name - * \param address Register address - * \param rw Read/write definition - */ - AMACv2Register(const std::string& name, uint32_t address, rw_t rw); - - //! Register defintion is valid - bool isValid() const; - - //! Get the name - std::string getName() const; - - //! Get address - uint8_t getAddress() const; - - //! set value - void setValue(uint32_t value); - - //! Get value - uint32_t getValue() const; - - //! Get RW definition - rw_t isRW() const; - -private: - //! Helpful name for register - std::string m_name = ""; - - //! Register address - uint8_t m_address = 255; - //! Register value - uint32_t m_value = 0; - - //! Read/write mode - rw_t m_rw=RO; +class AMACv2Register { + public: + //! Create an undefined (invalid) register + AMACv2Register() = default; + + //! Create a named register + /** + * Default register values should be set through field + * operations. + * + * \param name Register name + * \param address Register address + * \param rw Read/write definition + */ + AMACv2Register(const std::string& name, uint32_t address, rw_t rw); + + //! Register defintion is valid + bool isValid() const; + + //! Get the name + std::string getName() const; + + //! Get address + uint8_t getAddress() const; + + //! set value + void setValue(uint32_t value); + + //! Get value + uint32_t getValue() const; + + //! Get RW definition + rw_t isRW() const; + + private: + //! Helpful name for register + std::string m_name = ""; + + //! Register address + uint8_t m_address = 255; + //! Register value + uint32_t m_value = 0; + + //! Read/write mode + rw_t m_rw = RO; }; -#endif // AMACV2REGISTER_H +#endif // AMACV2REGISTER_H diff --git a/pbv3/CircuitPP2.cpp b/pbv3/CircuitPP2.cpp index f4acf84259ebcdc122357f880ce0fd246c6926fd..ba1fc295fef19c19456b14e28a2721fce3fd3fde 100644 --- a/pbv3/CircuitPP2.cpp +++ b/pbv3/CircuitPP2.cpp @@ -1,55 +1,63 @@ #include "CircuitPP2.h" -struct MeanSigma CircuitPP2::readInputCurrent (AMACv2& amac, unsigned n_reads) { - std::pair<float, float> cur10V = amac.readAMChan(&AMACv2RegMap::Ch13Value, {{&AMACv2::Ch13Mux, 0}}, n_reads); +struct MeanSigma CircuitPP2::readInputCurrent(AMACv2& amac, unsigned n_reads) { + std::pair<float, float> cur10V = amac.readAMChan( + &AMACv2RegMap::Ch13Value, {{&AMACv2::Ch13Mux, 0}}, n_reads); struct MeanSigma res; - res.mean = cur10V.first * 0.033 / 10.4; // curcuitry params, from itsdaq - res.sigma = cur10V.second * 0.033 / 10.4; // curcuitry params, from itsdaq + res.mean = cur10V.first * 0.033 / 10.4; // curcuitry params, from itsdaq + res.sigma = cur10V.second * 0.033 / 10.4; // curcuitry params, from itsdaq return res; } -struct MeanSigma CircuitPP2::readOutputCurrent (AMACv2& amac, unsigned n_reads) { - std::pair<float, float> cur10V = amac.readAMChan(&AMACv2RegMap::Ch8Value, {}, n_reads); +struct MeanSigma CircuitPP2::readOutputCurrent(AMACv2& amac, unsigned n_reads) { + std::pair<float, float> cur10V = + amac.readAMChan(&AMACv2RegMap::Ch8Value, {}, n_reads); struct MeanSigma res; - res.mean = cur10V.first / 100.; + res.mean = cur10V.first / 100.; res.sigma = cur10V.second / 100.; return res; } -struct MeanSigma CircuitPP2::readSense11V (AMACv2& amac, unsigned n_reads) { - std::pair<float, float> sense11V = amac.readAMChan(&AMACv2RegMap::Ch9Value, {}, n_reads); +struct MeanSigma CircuitPP2::readSense11V(AMACv2& amac, unsigned n_reads) { + std::pair<float, float> sense11V = + amac.readAMChan(&AMACv2RegMap::Ch9Value, {}, n_reads); struct MeanSigma res; - res.mean = sense11V.first * 110.2 / 8.2 / 1000; + res.mean = sense11V.first * 110.2 / 8.2 / 1000; res.sigma = sense11V.second * 110.2 / 8.2 / 1000; return res; } -struct MeanSigma CircuitPP2::readReference11V (AMACv2& amac, unsigned n_reads) { - std::pair<float, float> ref11V = amac.readAMChan(&AMACv2RegMap::Ch10Value, {}, n_reads); +struct MeanSigma CircuitPP2::readReference11V(AMACv2& amac, unsigned n_reads) { + std::pair<float, float> ref11V = + amac.readAMChan(&AMACv2RegMap::Ch10Value, {}, n_reads); struct MeanSigma res; - res.mean = ref11V.first * 110.2 / 8.2 / 1000; + res.mean = ref11V.first * 110.2 / 8.2 / 1000; res.sigma = ref11V.second * 110.2 / 8.2 / 1000; return res; } -struct MeanSigma CircuitPP2::readInputVoltage48 (AMACv2& amac, unsigned n_reads) { - std::pair<float, float> inp48V = amac.readAMChan(&AMACv2RegMap::Ch1Value, {}, n_reads); +struct MeanSigma CircuitPP2::readInputVoltage48(AMACv2& amac, + unsigned n_reads) { + std::pair<float, float> inp48V = + amac.readAMChan(&AMACv2RegMap::Ch1Value, {}, n_reads); struct MeanSigma res; - res.mean = inp48V.first * 203.9 / 3.9 / 1000; + res.mean = inp48V.first * 203.9 / 3.9 / 1000; res.sigma = inp48V.second * 203.9 / 3.9 / 1000; return res; } -struct MeanSigma CircuitPP2::readOutputVoltage11V (AMACv2& amac, unsigned n_reads) { - std::pair<float, float> out11V = amac.readAMChan(&AMACv2RegMap::Ch11Value, {}, n_reads); +struct MeanSigma CircuitPP2::readOutputVoltage11V(AMACv2& amac, + unsigned n_reads) { + std::pair<float, float> out11V = + amac.readAMChan(&AMACv2RegMap::Ch11Value, {}, n_reads); struct MeanSigma res; - res.mean = out11V.first * 149.1 / 9.1 / 1000; + res.mean = out11V.first * 149.1 / 9.1 / 1000; res.sigma = out11V.second * 149.1 / 9.1 / 1000; return res; } diff --git a/pbv3/CircuitPP2.h b/pbv3/CircuitPP2.h index 1c3e2281c280d9f48c33afbcb9da99e9d714117f..c286a26f771c90d4d41811c3756706e19efa0822 100644 --- a/pbv3/CircuitPP2.h +++ b/pbv3/CircuitPP2.h @@ -7,10 +7,11 @@ * @brief Functions for AMAC measurements in PP2 cuircuitry. * @version 0.1 * @date 2022-10-03 - * + * * @copyright Copyright (c) 2022 - * - * should be the same as ITSDAQ: macros/AMACStar_tests.cpp in the PP2 branch on utpc11 + * + * should be the same as ITSDAQ: macros/AMACStar_tests.cpp in the PP2 branch on + * utpc11 */ #include <utility> @@ -19,33 +20,40 @@ #include "Logger.h" struct MeanSigma { - float mean=0.; - float sigma=1.; + float mean = 0.; + float sigma = 1.; }; //* \brief read* functions return mean and std deviation of measurements namespace CircuitPP2 { - //* \brief "PP2 use: Inpuit 48 V current" in AMACStar spec, channel 13 subchannel 0 - struct MeanSigma readInputCurrent (AMACv2& amac, unsigned n_reads=1); +//* \brief "PP2 use: Inpuit 48 V current" in AMACStar spec, channel 13 +//subchannel 0 +struct MeanSigma readInputCurrent(AMACv2& amac, unsigned n_reads = 1); - //* \brief "PP2 use: Power return for 12 V supply to the front-end electronics (V12RET)" in AMACStar spec, channel 8 subchannel 0 - struct MeanSigma readOutputCurrent (AMACv2& amac, unsigned n_reads=1); +//* \brief "PP2 use: Power return for 12 V supply to the front-end electronics +//(V12RET)" in AMACStar spec, channel 8 subchannel 0 +struct MeanSigma readOutputCurrent(AMACv2& amac, unsigned n_reads = 1); - //* \brief "PP2 use: 12 V voltage sense from PP1 (V12SENSE)" in AMACStar spec, channel 9 subchannel 0 - struct MeanSigma readSense11V (AMACv2& amac, unsigned n_reads=1); +//* \brief "PP2 use: 12 V voltage sense from PP1 (V12SENSE)" in AMACStar spec, +//channel 9 subchannel 0 +struct MeanSigma readSense11V(AMACv2& amac, unsigned n_reads = 1); - //* \brief "PP2 use: 12 V power return sense from PP1(V12RETSENSE)" in AMACStar spec, channel 10 subchannel 0 - struct MeanSigma readReference11V (AMACv2& amac, unsigned n_reads=1); +//* \brief "PP2 use: 12 V power return sense from PP1(V12RETSENSE)" in AMACStar +//spec, channel 10 subchannel 0 +struct MeanSigma readReference11V(AMACv2& amac, unsigned n_reads = 1); - //* \brief "PP2 use: Input 48 V through external divider" in AMACStar spec, channel 1 subchannel 0 - struct MeanSigma readInputVoltage48 (AMACv2& amac, unsigned n_reads=1); +//* \brief "PP2 use: Input 48 V through external divider" in AMACStar spec, +//channel 1 subchannel 0 +struct MeanSigma readInputVoltage48(AMACv2& amac, unsigned n_reads = 1); - //* \brief "PP2 use: Local measurement of 12 V power to the front-end electrronics through external divider" in AMACStar spec, channel 11 subchannel 0 - struct MeanSigma readOutputVoltage11V (AMACv2& amac, unsigned n_reads=1); +//* \brief "PP2 use: Local measurement of 12 V power to the front-end +//electrronics through external divider" in AMACStar spec, channel 11 subchannel +//0 +struct MeanSigma readOutputVoltage11V(AMACv2& amac, unsigned n_reads = 1); - //* \brief measure everything from CircuitPP2 namespace and print to stdout - void measure_amac(AMACv2& amac, unsigned n_reads=3); -} +//* \brief measure everything from CircuitPP2 namespace and print to stdout +void measure_amac(AMACv2& amac, unsigned n_reads = 3); +} // namespace CircuitPP2 #endif diff --git a/pbv3/Elinks.cpp b/pbv3/Elinks.cpp index 3c01761b23b7367fc10bd241a2a51b5666ec4f26..e86d012e919765c02b0cc75d07b51c48f31368bc 100644 --- a/pbv3/Elinks.cpp +++ b/pbv3/Elinks.cpp @@ -1,145 +1,157 @@ //#include <unistd.h> -#include <sys/file.h> // flock -#include <string.h> // strerror -#include <unistd.h> // close fd -#include <fstream> +#include "Elinks.h" #include <Logger.h> +#include <string.h> // strerror +#include <sys/file.h> // flock +#include <unistd.h> // close fd -#include "EndeavourComException.h" -#include "Elinks.h" - +#include <fstream> #include <nlohmann/json.hpp> -address_Elinks central_json_cfg_address_Elinks( - std::string elinks_json_path) +#include "EndeavourComException.h" + +address_Elinks central_json_cfg_address_Elinks(std::string elinks_json_path) { - logger(logDEBUG) << "central_json_cfg_address_Elinks with config file: " << elinks_json_path; + logger(logDEBUG) << "central_json_cfg_address_Elinks with config file: " + << elinks_json_path; - address_Elinks addr = address_Elinks(); // init with hard-coded defaults - // try to get the config from the file - // if no -- warn and return the defaults + address_Elinks addr = address_Elinks(); // init with hard-coded defaults + // try to get the config from the file + // if no -- warn and return the defaults - nlohmann::json ctrlCfg; + nlohmann::json ctrlCfg; - // try to open the file and parse json from it - std::ifstream controllerFile(elinks_json_path); + // try to open the file and parse json from it + std::ifstream controllerFile(elinks_json_path); - if(controllerFile.is_open()) - { - //ctrlCfg = json::parse(controllerFile); + if (controllerFile.is_open()) { + // ctrlCfg = json::parse(controllerFile); - try - { ctrlCfg = nlohmann::json::parse(controllerFile); } + try { + ctrlCfg = nlohmann::json::parse(controllerFile); + } - catch (nlohmann::json::parse_error &e) - { logger(logERROR) << "central_json_cfg_address_Elinks could not parse Elinks elinks config: " << e.what(); } + catch (nlohmann::json::parse_error &e) { + logger(logERROR) << "central_json_cfg_address_Elinks could not " + "parse Elinks elinks config: " + << e.what(); + } } - else - { - logger(logWARNING) << "central_json_cfg_address_Elinks unable to open Elinks elinks config file, proceed with defaults"; - // if no config file -- return defaults - return addr; + else { + logger(logWARNING) + << "central_json_cfg_address_Elinks unable to open Elinks elinks " + "config file, proceed with defaults"; + // if no config file -- return defaults + return addr; } - logger(logDEBUG) << "central_json_cfg_address_Elinks parsed Elinks elinks config"; - - // check the json - // and get the data to configure Elinks elinks - - if (ctrlCfg.contains("ec_elinks")) - { - auto cfg = ctrlCfg["ec_elinks"]; - - if (cfg.contains("rx_elink_n")) - { addr.rx_elink_n = cfg["rx_elink_n"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_Elinks elinks config has no rx_elink_n"; } - - if (cfg.contains("tx_elink_n")) - { addr.tx_elink_n = cfg["tx_elink_n"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_Elinks elinks config has no tx_elink_n"; } - - if (cfg.contains("lock_filename")) - { addr.lock_filename = cfg["lock_filename"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_Elinks elinks config has no lock_filename"; } + logger(logDEBUG) + << "central_json_cfg_address_Elinks parsed Elinks elinks config"; + + // check the json + // and get the data to configure Elinks elinks + + if (ctrlCfg.contains("ec_elinks")) { + auto cfg = ctrlCfg["ec_elinks"]; + + if (cfg.contains("rx_elink_n")) { + addr.rx_elink_n = cfg["rx_elink_n"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_Elinks elinks config " + "has no rx_elink_n"; + } + + if (cfg.contains("tx_elink_n")) { + addr.tx_elink_n = cfg["tx_elink_n"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_Elinks elinks config " + "has no tx_elink_n"; + } + + if (cfg.contains("lock_filename")) { + addr.lock_filename = cfg["lock_filename"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_Elinks elinks config " + "has no lock_filename"; + } } - else - { logger(logDEBUG) << "central_json_cfg_address_Elinks no elinks config"; } - + else { + logger(logDEBUG) << "central_json_cfg_address_Elinks no elinks config"; + } - return addr; + return addr; } - - - Elinks::Elinks( - //unsigned int rx_elink_n, - //unsigned int tx_elink_n, - //std::string lock_filename) - address_Elinks address) + // unsigned int rx_elink_n, + // unsigned int tx_elink_n, + // std::string lock_filename) + address_Elinks address) { - m_rx_elink_n = address.rx_elink_n; - m_tx_elink_n = address.tx_elink_n; - m_ec_lock_filename = address.lock_filename; + m_rx_elink_n = address.rx_elink_n; + m_tx_elink_n = address.tx_elink_n; + m_ec_lock_filename = address.lock_filename; - m_connection_locked = false; + m_connection_locked = false; - logger(logDEBUG) << "Elinks::Elinks on Rx=" << m_rx_elink_n << " Tx=" << m_tx_elink_n << " lock file " << m_ec_lock_filename; + logger(logDEBUG) << "Elinks::Elinks on Rx=" << m_rx_elink_n + << " Tx=" << m_tx_elink_n << " lock file " + << m_ec_lock_filename; - //lockConnection(); + // lockConnection(); } -Elinks::Elinks(std::string cfg_json_filename) : Elinks(central_json_cfg_address_Elinks(cfg_json_filename)) -{ } - +Elinks::Elinks(std::string cfg_json_filename) + : Elinks(central_json_cfg_address_Elinks(cfg_json_filename)) {} -Elinks::~Elinks() -{ - //unlockConnection(); +Elinks::~Elinks() { + // unlockConnection(); } -void Elinks::lockConnection() -{ - logger(logDEBUG) << "Elinks::lockConnection locking the file " << m_ec_lock_filename; - // lock the EC file to indicate the EC link as busy for other processes - m_fd_ec_lock = open(m_ec_lock_filename.c_str(), O_RDWR); - if (m_fd_ec_lock == -1) { - throw EndeavourComException("Elinks::lockConnection could not open the lock file " + m_ec_lock_filename + ":" - + " (" + std::to_string(errno) + ") " - + std::string(strerror(errno))); +void Elinks::lockConnection() { + logger(logDEBUG) << "Elinks::lockConnection locking the file " + << m_ec_lock_filename; + // lock the EC file to indicate the EC link as busy for other processes + m_fd_ec_lock = open(m_ec_lock_filename.c_str(), O_RDWR); + if (m_fd_ec_lock == -1) { + throw EndeavourComException( + "Elinks::lockConnection could not open the lock file " + + m_ec_lock_filename + ":" + " (" + std::to_string(errno) + ") " + + std::string(strerror(errno))); } - if (flock(m_fd_ec_lock, LOCK_EX) == -1) { - throw EndeavourComException("Elinks::lockConnection could not lock " + m_ec_lock_filename); + if (flock(m_fd_ec_lock, LOCK_EX) == -1) { + throw EndeavourComException("Elinks::lockConnection could not lock " + + m_ec_lock_filename); } - m_connection_locked = true; - logger(logDEBUG) << "Elinks::lockConnection locked"; + m_connection_locked = true; + logger(logDEBUG) << "Elinks::lockConnection locked"; } -void Elinks::unlockConnection() -{ - logger(logDEBUG) << "Elinks::unlockConnection unlocking " + m_ec_lock_filename; - // unlock the file to indicate the EC link is free - if (flock(m_fd_ec_lock, LOCK_UN) == -1) { - // TODO: figure out if it is better to throw here - //throw EndeavourComException("Elinks could not unlock " + m_ec_lock_filename); - logger(logERROR) << "Elinks::unlockConnection could not unlock " + m_ec_lock_filename; +void Elinks::unlockConnection() { + logger(logDEBUG) << "Elinks::unlockConnection unlocking " + + m_ec_lock_filename; + // unlock the file to indicate the EC link is free + if (flock(m_fd_ec_lock, LOCK_UN) == -1) { + // TODO: figure out if it is better to throw here + // throw EndeavourComException("Elinks could not unlock " + + // m_ec_lock_filename); + logger(logERROR) << "Elinks::unlockConnection could not unlock " + + m_ec_lock_filename; } - // and close the file - if (close(m_fd_ec_lock) == -1) { - logger(logERROR) << "Elinks::unlockConnection could not close " + m_ec_lock_filename << " " << strerror(errno); + // and close the file + if (close(m_fd_ec_lock) == -1) { + logger(logERROR) << "Elinks::unlockConnection could not close " + + m_ec_lock_filename + << " " << strerror(errno); } - m_connection_locked = false; - logger(logDEBUG) << "Elinks::unlockConnection unlocked"; + m_connection_locked = false; + logger(logDEBUG) << "Elinks::unlockConnection unlocked"; } - diff --git a/pbv3/Elinks.h b/pbv3/Elinks.h index 5d633d3a28f53d32c80ce8e6deb9a7a861dfafb7..0d5d9b17c7795b6236b6d533a2f59686fe60edc9 100644 --- a/pbv3/Elinks.h +++ b/pbv3/Elinks.h @@ -2,72 +2,75 @@ #define ELINKS_H #include <stdint.h> -#include <vector> + #include <string> +#include <vector> -#define FALLBACK_EC_LINK_LOCK_FILE "/opt/atlas/etc/atlas_itk_strips_EC" // "/run/lock/atlas_itk_strips_EC"); +#define FALLBACK_EC_LINK_LOCK_FILE \ + "/opt/atlas/etc/atlas_itk_strips_EC" // "/run/lock/atlas_itk_strips_EC"); typedef std::vector<bool> BitStream; typedef struct { - unsigned int rx_elink_n = 0x1c; - unsigned int tx_elink_n = 0x14; - std::string lock_filename = FALLBACK_EC_LINK_LOCK_FILE; + unsigned int rx_elink_n = 0x1c; + unsigned int tx_elink_n = 0x14; + std::string lock_filename = FALLBACK_EC_LINK_LOCK_FILE; } address_Elinks; -address_Elinks central_json_cfg_address_Elinks(std::string json_path = "/opt/atlas/etc/cfg_Elinks_address.json"); - -class Elinks -{ -public: - //Elinks(); // TODO: a default constructor? - //Elinks() : - // m_rx_elink_n(0x1c), - // m_tx_elink_n(0x14), - // m_ec_lock_filename(FALLBACK_EC_LINK_LOCK_FILE) - //{ }; +address_Elinks central_json_cfg_address_Elinks( + std::string json_path = "/opt/atlas/etc/cfg_Elinks_address.json"); - Elinks( // TODO: add flx hostname & ports? - //unsigned int rx_elink_n = 0x1c, - //unsigned int tx_elink_n = 0x14, - //std::string lock_filename = FALLBACK_EC_LINK_LOCK_FILE); - address_Elinks params=address_Elinks()); // no params defaults to hardcoded value - // will the constructor above work as Elinks() ? nope +class Elinks { + public: + // Elinks(); // TODO: a default constructor? + // Elinks() : + // m_rx_elink_n(0x1c), + // m_tx_elink_n(0x14), + // m_ec_lock_filename(FALLBACK_EC_LINK_LOCK_FILE) + //{ }; - Elinks(std::string cfg_json_filename); + Elinks( // TODO: add flx hostname & ports? + // unsigned int rx_elink_n = 0x1c, + // unsigned int tx_elink_n = 0x14, + // std::string lock_filename = FALLBACK_EC_LINK_LOCK_FILE); + address_Elinks params = + address_Elinks()); // no params defaults to hardcoded value + // will the constructor above work as Elinks() ? nope - virtual ~Elinks(); + Elinks(std::string cfg_json_filename); - virtual std::vector<uint8_t> readData() = 0; - virtual int sendBitstream(BitStream) = 0; - virtual int sendByteStream(std::vector<uint8_t>) = 0; + virtual ~Elinks(); - virtual void disconnect(void) {}; - virtual void connect(void) {}; + virtual std::vector<uint8_t> readData() = 0; + virtual int sendBitstream(BitStream) = 0; + virtual int sendByteStream(std::vector<uint8_t>) = 0; - void lockConnection(); - void unlockConnection(); + virtual void disconnect(void){}; + virtual void connect(void){}; -protected: - // elink config + void lockConnection(); + void unlockConnection(); - // TODO: explicit flx server? - // string hostname - // port + protected: + // elink config - // elink IDs - unsigned int m_rx_elink_n, m_tx_elink_n; + // TODO: explicit flx server? + // string hostname + // port - //std::vector<uint8_t> m_elink_buffer_data; // elinks return this buffer from readData, they don't hold it + // elink IDs + unsigned int m_rx_elink_n, m_tx_elink_n; - // elinks lock file - std::string m_ec_lock_filename; - int m_fd_ec_lock; - bool m_connection_locked = false; - bool m_dontWaitReply = false; + // std::vector<uint8_t> m_elink_buffer_data; // elinks return this buffer + // from readData, they don't hold it -private: + // elinks lock file + std::string m_ec_lock_filename; + int m_fd_ec_lock; + bool m_connection_locked = false; + bool m_dontWaitReply = false; + private: }; -#endif //ELINKS_H +#endif // ELINKS_H diff --git a/pbv3/ElinksICNETIO.cpp b/pbv3/ElinksICNETIO.cpp index 98e8b58328ee7e0b9ef47e2b2b2b1becad8c4a67..eae4341e4363fc7ef95096ada84aece7f11886de 100644 --- a/pbv3/ElinksICNETIO.cpp +++ b/pbv3/ElinksICNETIO.cpp @@ -1,19 +1,17 @@ //#include "EndeavourRawElinks.h" #include "ElinksICNETIO.h" -#include "EndeavourComException.h" - #include <Logger.h> +#include <string.h> -#include "DeviceCom.h" - +#include <chrono> +#include <fstream> #include <memory> -#include <string.h> -#include <sstream> // against invalid use of incomplete type ‘std::string’ +#include <sstream> // against invalid use of incomplete type ‘std::string’ #include <thread> -#include <fstream> -#include <chrono> +#include "DeviceCom.h" +#include "EndeavourComException.h" using Clock = std::chrono::steady_clock; //#include "ic-over-netio/connectionHandler.h" // class ConnectionHandler; @@ -21,93 +19,108 @@ using Clock = std::chrono::steady_clock; #include <nlohmann/json.hpp> -address_ICNETIO central_json_cfg_address_ICNETIO( - std::string icnetio_json_path) +address_ICNETIO central_json_cfg_address_ICNETIO(std::string icnetio_json_path) { - logger(logDEBUG) << "central_json_cfg_address_ICNETIO with config file: " << icnetio_json_path; + logger(logDEBUG) << "central_json_cfg_address_ICNETIO with config file: " + << icnetio_json_path; - address_ICNETIO addr = address_ICNETIO(); // init with hard-coded defaults - // try to get the config from the file - // if no -- warn and return the defaults + address_ICNETIO addr = address_ICNETIO(); // init with hard-coded defaults + // try to get the config from the file + // if no -- warn and return the defaults - nlohmann::json ctrlCfg; + nlohmann::json ctrlCfg; - // try to open the file and parse json from it - std::ifstream controllerFile(icnetio_json_path); + // try to open the file and parse json from it + std::ifstream controllerFile(icnetio_json_path); - if(controllerFile.is_open()) - { - //ctrlCfg = json::parse(controllerFile); + if (controllerFile.is_open()) { + // ctrlCfg = json::parse(controllerFile); - try - { ctrlCfg = nlohmann::json::parse(controllerFile); } + try { + ctrlCfg = nlohmann::json::parse(controllerFile); + } - catch (nlohmann::json::parse_error &e) - { logger(logERROR) << "central_json_cfg_address_ICNETIO could not parse ICNETIO icnetio config: " << e.what(); } + catch (nlohmann::json::parse_error& e) { + logger(logERROR) << "central_json_cfg_address_ICNETIO could not " + "parse ICNETIO icnetio config: " + << e.what(); + } } - else - { - logger(logWARNING) << "central_json_cfg_address_ICNETIO unable to open ICNETIO icnetio config file, proceed with defaults"; - // if no config file -- return defaults - return addr; + else { + logger(logWARNING) + << "central_json_cfg_address_ICNETIO unable to open ICNETIO " + "icnetio config file, proceed with defaults"; + // if no config file -- return defaults + return addr; } - logger(logDEBUG) << "central_json_cfg_address_ICNETIO parsed ICNETIO icnetio config"; - - // check the json - // and get the data to configure ICNETIO icnetio - - if (ctrlCfg.contains("icnetio")) - { - auto cfg = ctrlCfg["icnetio"]; - - if (cfg.contains("flxHost")) - { addr.flxHost = cfg["flxHost"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_ICNETIO icnetio config has no flxHost"; } - - if (cfg.contains("portFromHost")) - { addr.portFromHost = cfg["portFromHost"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_ICNETIO icnetio config has no portFromHost"; } - - if (cfg.contains("portToHost")) - { addr.portToHost = cfg["portToHost"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_ICNETIO icnetio config has no portToHost"; } + logger(logDEBUG) + << "central_json_cfg_address_ICNETIO parsed ICNETIO icnetio config"; + + // check the json + // and get the data to configure ICNETIO icnetio + + if (ctrlCfg.contains("icnetio")) { + auto cfg = ctrlCfg["icnetio"]; + + if (cfg.contains("flxHost")) { + addr.flxHost = cfg["flxHost"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_ICNETIO icnetio " + "config has no flxHost"; + } + + if (cfg.contains("portFromHost")) { + addr.portFromHost = cfg["portFromHost"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_ICNETIO icnetio " + "config has no portFromHost"; + } + + if (cfg.contains("portToHost")) { + addr.portToHost = cfg["portToHost"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_ICNETIO icnetio " + "config has no portToHost"; + } } - else - { logger(logDEBUG) << "central_json_cfg_address_ICNETIO no icnetio config"; } - + else { + logger(logDEBUG) + << "central_json_cfg_address_ICNETIO no icnetio config"; + } - return addr; + return addr; } - /* // we need HwController to configure and get to the Rx-Tx Cores // the IO operates on the cores -#include "libYarr/include/AllHwControllers.h" // the sub-lib with different access systems to the Rx-Tx Cores = HwController +#include "libYarr/include/AllHwControllers.h" // the sub-lib with different +access systems to the Rx-Tx Cores = HwController //#include "DeviceCom.h" -//#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController -// TxCore does not have sendBitstream -- the patch from Olivier to send bytes over Netio +//#include "libYarr/include/TxCore.h" // the communication cores on the YARR +HwController +// TxCore does not have sendBitstream -- the patch from Olivier to send bytes +over Netio // but it defines the interface class for NetioTx -#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController #include "libNetioHW/include/NetioTxCore.h" // -#include "libYarr/include/RxCore.h" // #include "libYarr/include/RawData.h" // the GBT read buffer -//#include "libUtil/include/BitStream.h" // Endeavour protocol not there in the new YAR +#include "libYarr/include/RxCore.h" // +#include "libYarr/include/TxCore.h" // the communication cores on the YARR +HwController +//#include "libUtil/include/BitStream.h" // Endeavour protocol not there in the +new YAR void addToBitStream(BitStream & bs, uint8_t byte){ - //Use the value from the LSB + //Use the value from the LSB for(uint32_t i=0;i<8;i++) - bs.push_back((byte>>(8-i-1))&1); + bs.push_back((byte>>(8-i-1))&1); } */ @@ -116,51 +129,50 @@ void addToBitStream(BitStream & bs, uint8_t byte){ BitStream invert(BitStream msg) { BitStream inverted; - for (int32_t bit = msg.GetNbits()-1; bit>=0; --bit) + for (int32_t bit = msg.GetNbits()-1; bit>=0; --bit) inverted.Add(1, msg.Get(bit)); return inverted; } */ // TODO: remove this? or make some general endianness functions -bool bit_in_endian_bytes(uint32_t input, unsigned int bit_index) -{ - unsigned int bit_i = bit_index & 0x7; - unsigned int byte_i = bit_index >> 3; // reminder devision by 8 +bool bit_in_endian_bytes(uint32_t input, unsigned int bit_index) { + unsigned int bit_i = bit_index & 0x7; + unsigned int byte_i = bit_index >> 3; // reminder devision by 8 char byte = (input >> byte_i * 8) & 0xFF; return (byte << bit_i) & 0x80; } /** \brief swaps the endianness in the word */ -uint32_t swap_byte_endiannes(uint32_t input) -{ - uint8_t byte1 = (input & 0x000000ff) >> 0; - uint8_t byte2 = (input & 0x0000ff00) >> 8; +uint32_t swap_byte_endiannes(uint32_t input) { + uint8_t byte1 = (input & 0x000000ff) >> 0; + uint8_t byte2 = (input & 0x0000ff00) >> 8; uint8_t byte3 = (input & 0x00ff0000) >> 16; uint8_t byte4 = (input & 0xff000000) >> 24; - uint32_t swapped = 0; swapped = swapped | byte1; - swapped <<= 8; swapped = swapped | byte2; - swapped <<= 8; swapped = swapped | byte3; - swapped <<= 8; swapped = swapped | byte4; + uint32_t swapped = 0; + swapped = swapped | byte1; + swapped <<= 8; + swapped = swapped | byte2; + swapped <<= 8; + swapped = swapped | byte3; + swapped <<= 8; + swapped = swapped | byte4; return swapped; } -union word32bit8bit -{ +union word32bit8bit { std::uint32_t theDWord; std::uint8_t theBytes[4]; }; - - /* ElinksICNETIO::ElinksICNETIO( - unsigned int rx_elink_n, - unsigned int tx_elink_n, - std::string ec_lock_filename) + unsigned int rx_elink_n, + unsigned int tx_elink_n, + std::string ec_lock_filename) : ElinksICNETIO::ElinksICNETIO(rx_elink_n, tx_elink_n, @@ -171,263 +183,278 @@ ElinksICNETIO::ElinksICNETIO( */ ElinksICNETIO::ElinksICNETIO( - //unsigned int rx_elink_n, - //unsigned int tx_elink_n, - //std::string ec_lock_filename, - address_Elinks address_elinks, - - //std::string flxHost, - //unsigned int portFromHost, - //unsigned int portToHost, - address_ICNETIO address_netio, - - bool dontWaitReply, bool resubscribeValue) - -: - Elinks(address_elinks), - m_maxRetries{2}, - m_resubscribe{resubscribeValue}, //set to true if you want to resubscribe upon failure to receive message - m_flxHost{address_netio.flxHost}, - m_portFromHost{address_netio.portFromHost}, - m_portToHost{address_netio.portToHost}, - m_elinkID_rx{address_elinks.rx_elink_n}, - m_elinkID_tx{address_elinks.tx_elink_n}, - m_connHandler{ConnectionHandler::getInstance()} + // unsigned int rx_elink_n, + // unsigned int tx_elink_n, + // std::string ec_lock_filename, + address_Elinks address_elinks, + + // std::string flxHost, + // unsigned int portFromHost, + // unsigned int portToHost, + address_ICNETIO address_netio, + + bool dontWaitReply, bool resubscribeValue) + + : Elinks(address_elinks), + m_maxRetries{2}, + m_resubscribe{ + resubscribeValue}, // set to true if you want to resubscribe upon + // failure to receive message + m_flxHost{address_netio.flxHost}, + m_portFromHost{address_netio.portFromHost}, + m_portToHost{address_netio.portToHost}, + m_elinkID_rx{address_elinks.rx_elink_n}, + m_elinkID_tx{address_elinks.tx_elink_n}, + m_connHandler{ConnectionHandler::getInstance()} { - logger(logDEBUG) << "ElinksICNETIO::ElinksICNETIO using ConnectionHandler to " - << m_flxHost - << ":{Rx=" << m_portToHost << "," << m_elinkID_rx - << " Tx=" << m_portFromHost << "," << m_elinkID_tx << "}"; + logger(logDEBUG) + << "ElinksICNETIO::ElinksICNETIO using ConnectionHandler to " + << m_flxHost << ":{Rx=" << m_portToHost << "," << m_elinkID_rx + << " Tx=" << m_portFromHost << "," << m_elinkID_tx << "}"; - m_dontWaitReply = dontWaitReply; + m_dontWaitReply = dontWaitReply; - //m_connHandler = nullptr; - //m_connHandler = new ConnectionHandler(); - //connect(); + // m_connHandler = nullptr; + // m_connHandler = new ConnectionHandler(); + // connect(); } -void ElinksICNETIO::disconnect(void) -{ - logger(logDEBUG) << "ElinksICNETIO::disconnect disconnecting"; +void ElinksICNETIO::disconnect(void) { + logger(logDEBUG) << "ElinksICNETIO::disconnect disconnecting"; + + if (!m_connection_locked) { + logger(logDEBUG) << "ElinksICNETIO::disconnect already done"; + return; + } - if (!m_connection_locked) + // if (m_connHandler != nullptr) { - logger(logDEBUG) << "ElinksICNETIO::disconnect already done"; - return; + // delete m_connHandler; + // m_connHandler = nullptr; + // m_connHandler->freeConnections(); + // m_connHandler.freeConnections(); + m_connHandler.disconnect(); // stop the event_loop and freeConnections + + unlockConnection(); + logger(logDEBUG) << "ElinksICNETIO::disconnect unlockedConnections " + "<---------------------"; } - //if (m_connHandler != nullptr) - { - //delete m_connHandler; - //m_connHandler = nullptr; - //m_connHandler->freeConnections(); - //m_connHandler.freeConnections(); - m_connHandler.disconnect(); // stop the event_loop and freeConnections + logger(logDEBUG) << "ElinksICNETIO::disconnect done"; +} - unlockConnection(); - logger(logDEBUG) << "ElinksICNETIO::disconnect unlockedConnections <---------------------"; - } +void ElinksICNETIO::connect(void) { + logger(logDEBUG) << "ElinksICNETIO::connect m_connHandler"; - logger(logDEBUG) << "ElinksICNETIO::disconnect done"; -} + if (m_connection_locked) { + logger(logDEBUG) << "ElinksICNETIO::connect already done"; + return; + } -void ElinksICNETIO::connect(void) -{ - logger(logDEBUG) << "ElinksICNETIO::connect m_connHandler"; + // if (m_connHandler != nullptr) + // { + // logger(logDEBUG) << "ElinksICNETIO::connect already done: m_connHandler + // is not nullptr"; return; + // } + + logger(logDEBUG) + << "ElinksICNETIO::connect locking connection <---------------------"; + lockConnection(); + try { + // m_connHandler = new ConnectionHandler(); + // test the connection + // auto m_connInfo = m_connHandler->getConnection(m_flxHost, + // m_portFromHost, m_portToHost, m_elinkID_rx); std::cerr << + // "ElinksICNETIO::connect m_connHandler.connect()" << std::endl; + m_connHandler.lockConnection(); // this does connect by default + // m_connHandler.connect(); // this one hits the already + // connected and unlocks it + auto m_connInfo = m_connHandler.getConnection( + m_flxHost, m_portFromHost, m_portToHost, m_elinkID_rx); + } - if (m_connection_locked) - { - logger(logDEBUG) << "ElinksICNETIO::connect already done"; - return; + catch (const std::exception& e) { // unlock the EC file and re-throw + logger(logDEBUG) << "ElinksICNETIO::connect EXCEPT " << e.what(); + // delete m_connHandler; + // m_connHandler = nullptr; + // m_connHandler->freeConnections(); + // m_connHandler.freeConnections(); + // m_connHandler.unlockConnection(); + m_connHandler.disconnect( + false); // false: do not lock the connection handler connection -- + // it must be locked by connect + unlockConnection(); + throw; } - //if (m_connHandler != nullptr) - // { - // logger(logDEBUG) << "ElinksICNETIO::connect already done: m_connHandler is not nullptr"; - // return; - // } - - logger(logDEBUG) << "ElinksICNETIO::connect locking connection <---------------------"; - lockConnection(); - try { - //m_connHandler = new ConnectionHandler(); - // test the connection - //auto m_connInfo = m_connHandler->getConnection(m_flxHost, m_portFromHost, m_portToHost, m_elinkID_rx); - //std::cerr << "ElinksICNETIO::connect m_connHandler.connect()" << std::endl; - m_connHandler.lockConnection(); // this does connect by default - //m_connHandler.connect(); // this one hits the already connected and unlocks it - auto m_connInfo = m_connHandler.getConnection(m_flxHost, m_portFromHost, m_portToHost, m_elinkID_rx); - } - - catch (const std::exception& e) { // unlock the EC file and re-throw - logger(logDEBUG) << "ElinksICNETIO::connect EXCEPT " << e.what(); - //delete m_connHandler; - //m_connHandler = nullptr; - //m_connHandler->freeConnections(); - //m_connHandler.freeConnections(); - //m_connHandler.unlockConnection(); - m_connHandler.disconnect(false); // false: do not lock the connection handler connection -- it must be locked by connect - unlockConnection(); - throw; - } - - m_connHandler.unlockConnection(); + m_connHandler.unlockConnection(); } +ElinksICNETIO::~ElinksICNETIO() { + logger(logDEBUG) << "ElinksICNETIO::~ElinksICNETIO closing the connection"; -ElinksICNETIO::~ElinksICNETIO() -{ - logger(logDEBUG) << "ElinksICNETIO::~ElinksICNETIO closing the connection"; - - disconnect(); - //delete m_connHandler; m_connHandler = nullptr; + disconnect(); + // delete m_connHandler; m_connHandler = nullptr; } -#define NETIO_REPLY_HEADER_SIZE 8 // bytes +#define NETIO_REPLY_HEADER_SIZE 8 // bytes + +std::vector<uint8_t> ElinksICNETIO::readData() { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + logger(logDEBUG) << "ElinksICNETIO::readData read what's there on netio"; + std::vector<uint8_t> reply; + + try { + m_connHandler.lockConnection(); + auto m_connInfo = m_connHandler.getConnection( + m_flxHost, m_portFromHost, m_portToHost, m_elinkID_rx); + reply = m_connInfo.replySocket->getReply(); + m_connInfo.replySocket->resetReply(); // flag for the connHandler that + // the reply can be cleared + // the handler overwrites the reply as needed when it receives new data + } -std::vector<uint8_t> ElinksICNETIO::readData() -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - logger(logDEBUG) << "ElinksICNETIO::readData read what's there on netio"; - std::vector<uint8_t> reply; - - try { - m_connHandler.lockConnection(); - auto m_connInfo = m_connHandler.getConnection(m_flxHost, m_portFromHost, m_portToHost, m_elinkID_rx); - reply = m_connInfo.replySocket->getReply(); - m_connInfo.replySocket->resetReply(); // flag for the connHandler that the reply can be cleared - // the handler overwrites the reply as needed when it receives new data - } - - catch (const std::exception& e) { // unlock the EC file and re-throw - logger(logDEBUG) << "ElinksICNETIO::readData EXCEPT " << e.what(); - m_connHandler.disconnect(false); // false: do not lock the connection handler connection -- it must be locked by connect - unlockConnection(); - throw; - } - - m_connHandler.unlockConnection(); - logger(logDEBUG) << "ElinksICNETIO::readData got " << reply.size() << " bytes"; - - //for (int i=0; i<1000; i++) - // { - // auto reply = m_connInfo.replySocket->getReply(); - // m_connInfo.replySocket->resetReply(); // flag for the connHandler that the reply can be cleared - // } - logger(logDEBUG) << "ElinksICNETIO::readData flushed 0 times ................................................."; - - if (reply.size() > 0) - { - // pop the netio header - // TODO: check the elink ID! - for (unsigned int i = 0; i<NETIO_REPLY_HEADER_SIZE; i++) - //{ reply.pop_front(); } - { reply.erase(reply.begin()); } + catch (const std::exception& e) { // unlock the EC file and re-throw + logger(logDEBUG) << "ElinksICNETIO::readData EXCEPT " << e.what(); + m_connHandler.disconnect( + false); // false: do not lock the connection handler connection -- + // it must be locked by connect + unlockConnection(); + throw; + } + + m_connHandler.unlockConnection(); + logger(logDEBUG) << "ElinksICNETIO::readData got " << reply.size() + << " bytes"; + + // for (int i=0; i<1000; i++) + // { + // auto reply = m_connInfo.replySocket->getReply(); + // m_connInfo.replySocket->resetReply(); // flag for the connHandler that + // the reply can be cleared + // } + logger(logDEBUG) << "ElinksICNETIO::readData flushed 0 times " + "................................................."; + + if (reply.size() > 0) { + // pop the netio header + // TODO: check the elink ID! + for (unsigned int i = 0; i < NETIO_REPLY_HEADER_SIZE; i++) + //{ reply.pop_front(); } + { + reply.erase(reply.begin()); + } } - //else + // else //{ return {}; } - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "ElinksICNETIO::readData time " << diagnostic_time.count() << " us"; + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "ElinksICNETIO::readData time " + << diagnostic_time.count() << " us"; - return reply; + return reply; } -int ElinksICNETIO::sendBitstream(BitStream outdata) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - - // pad with zeroes (!) up to bytes and send bytes - - std::vector<uint8_t> bytes; - uint8_t current_byte = 0; - unsigned int bit_counter = 0; - - while (outdata.size() > 0) - { - bit_counter += 1; - // load the bit into the current byte - bool bit = outdata[0]; - outdata.erase(outdata.begin()); // pop_front - current_byte = (current_byte << 1) | bit; - - // save the byte - // if it is ready or there are no more bits - if (bit_counter == 8 || outdata.size() == 0) - { - bytes.push_back(current_byte); - bit_counter = 0; - current_byte = 0; - } - } - - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "ElinksICNETIO::sendBitstream time " << diagnostic_time.count() << " us"; - - return sendByteStream(bytes); -} +int ElinksICNETIO::sendBitstream(BitStream outdata) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + + // pad with zeroes (!) up to bytes and send bytes + + std::vector<uint8_t> bytes; + uint8_t current_byte = 0; + unsigned int bit_counter = 0; + + while (outdata.size() > 0) { + bit_counter += 1; + // load the bit into the current byte + bool bit = outdata[0]; + outdata.erase(outdata.begin()); // pop_front + current_byte = (current_byte << 1) | bit; + + // save the byte + // if it is ready or there are no more bits + if (bit_counter == 8 || outdata.size() == 0) { + bytes.push_back(current_byte); + bit_counter = 0; + current_byte = 0; + } + } -int ElinksICNETIO::sendByteStream(std::vector<uint8_t> outdata) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - - // prepare the netio frame - //std::vector<unsigned char> netioFrame = prepareNetioFrame(true, regs[i], vector_size1, m_i2cAddr); - felix::base::ToFELIXHeader header; - std::vector<unsigned char> netioFrame ( sizeof(header) + outdata.size()); - - header.length = netioFrame.size() - sizeof(header); - header.reserved = 0; - header.elinkid = m_elinkID_tx; - - std::copy( - reinterpret_cast<uint8_t*>(&header), - reinterpret_cast<uint8_t*>(&header)+sizeof(header), - netioFrame.begin() ); - - memcpy(&netioFrame[sizeof header], outdata.data(), outdata.size()); - - /* - // debug printout - for(unsigned int i = 0; i < netioFrame.size(); ++i) - { - if (i == sizeof(header)) - logger(logDEBUG) << "<<< header " << sizeof(header) << " | payload " << outdata.size() << " >>>"; - logger(logDEBUG) << i << ": " << std::hex << netioFrame[i] << std::dec << netioFrame[i]; - } - */ - logger(logDEBUG) << "ElinksICNETIO::sendByteStream" - << std::hex - << " header=" << sizeof(header) - << " body=" << outdata.size() - << " total=" << netioFrame.size(); - - try { - m_connHandler.lockConnection(); - auto m_connInfo = m_connHandler.getConnection(m_flxHost, m_portFromHost, m_portToHost, m_elinkID_rx); - m_connInfo.requestSocket->sendNetioMessage(netioFrame, m_connInfo.replySocket, m_maxRetries+1, m_resubscribe, m_dontWaitReply); - } - - catch (const std::exception& e) { // unlock the EC file and re-throw - logger(logDEBUG) << "ElinksICNETIO::sendByteStream EXCEPT " << e.what(); - m_connHandler.disconnect(false); // false: do not lock the connection handler connection -- it must be locked by connect - unlockConnection(); - throw; - } - - m_connHandler.unlockConnection(); - - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "ElinksICNETIO::sendByteStream time " << diagnostic_time.count() << " us"; - - return 0; + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "ElinksICNETIO::sendBitstream time " + << diagnostic_time.count() << " us"; + + return sendByteStream(bytes); } +int ElinksICNETIO::sendByteStream(std::vector<uint8_t> outdata) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + + // prepare the netio frame + // std::vector<unsigned char> netioFrame = prepareNetioFrame(true, regs[i], + // vector_size1, m_i2cAddr); + felix::base::ToFELIXHeader header; + std::vector<unsigned char> netioFrame(sizeof(header) + outdata.size()); + + header.length = netioFrame.size() - sizeof(header); + header.reserved = 0; + header.elinkid = m_elinkID_tx; + + std::copy(reinterpret_cast<uint8_t*>(&header), + reinterpret_cast<uint8_t*>(&header) + sizeof(header), + netioFrame.begin()); + + memcpy(&netioFrame[sizeof header], outdata.data(), outdata.size()); + + /* + // debug printout + for(unsigned int i = 0; i < netioFrame.size(); ++i) + { + if (i == sizeof(header)) + logger(logDEBUG) << "<<< header " << sizeof(header) << " | + payload " << outdata.size() << " >>>"; logger(logDEBUG) << i << ": " << + std::hex << netioFrame[i] << std::dec << netioFrame[i]; + } + */ + logger(logDEBUG) << "ElinksICNETIO::sendByteStream" << std::hex + << " header=" << sizeof(header) + << " body=" << outdata.size() + << " total=" << netioFrame.size(); + + try { + m_connHandler.lockConnection(); + auto m_connInfo = m_connHandler.getConnection( + m_flxHost, m_portFromHost, m_portToHost, m_elinkID_rx); + m_connInfo.requestSocket->sendNetioMessage( + netioFrame, m_connInfo.replySocket, m_maxRetries + 1, m_resubscribe, + m_dontWaitReply); + } + + catch (const std::exception& e) { // unlock the EC file and re-throw + logger(logDEBUG) << "ElinksICNETIO::sendByteStream EXCEPT " << e.what(); + m_connHandler.disconnect( + false); // false: do not lock the connection handler connection -- + // it must be locked by connect + unlockConnection(); + throw; + } + + m_connHandler.unlockConnection(); + + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "ElinksICNETIO::sendByteStream time " + << diagnostic_time.count() << " us"; + + return 0; +} diff --git a/pbv3/ElinksICNETIO.h b/pbv3/ElinksICNETIO.h index 2f7f22d2cb03f94ea37a4701d25f6a975421963e..e1d321cce10d017cbcc8a0b6d6d6873294b0cac1 100644 --- a/pbv3/ElinksICNETIO.h +++ b/pbv3/ElinksICNETIO.h @@ -9,64 +9,64 @@ //#include <memory> // shared_ptr #include "Elinks.h" - #include "connectionHandler.h" -//class ConnectionHandler; // ic-over-netio' handler of netio -//class ConnectionInfo; +// class ConnectionHandler; // ic-over-netio' handler of netio +// class ConnectionInfo; typedef struct { - std::string flxHost = "pcatlitkflx03"; - unsigned int portFromHost = 12340; - unsigned int portToHost = 12350; + std::string flxHost = "pcatlitkflx03"; + unsigned int portFromHost = 12340; + unsigned int portToHost = 12350; } address_ICNETIO; -address_ICNETIO central_json_cfg_address_ICNETIO(std::string json_path = "/opt/atlas/etc/cfg_ICNETIO_address.json"); - -class ElinksICNETIO : public Elinks -{ -public: - //ElinksICNETIO( - // unsigned int rx_elink_n, - // unsigned int tx_elink_n, - // std::string ec_lock_filename); - - ElinksICNETIO( - //unsigned int rx_elink_n = 0x1c, - //unsigned int tx_elink_n = 0x14, - //std::string ec_lock_filename = FALLBACK_EC_LINK_LOCK_FILE, - address_Elinks = address_Elinks(), - - //std::string flxHost = "pcatlitkflx03", - //unsigned int portFromHost = 12340, // Tx - //unsigned int portToHost = 12350, // Rx - address_ICNETIO = address_ICNETIO(), - bool dontWaitReply = false, - bool resubscribeValue = false); // TODO do we need this? - - //IChandler(std::string flxHost, unsigned int portToGBTx, unsigned int portFromGBTx, uint32_t elinkID, uint32_t elinkID_requestSocket, uint8_t i2cAddr = 127, IC_DEV ic_dev_id=IC_DEV_GBTx, bool resubscribeValue = false); - - ~ElinksICNETIO(); - - virtual void disconnect(void); - virtual void connect(void); - - // actual io methods - std::vector<uint8_t> readData(); - int sendBitstream(BitStream); - int sendByteStream(std::vector<uint8_t>); - -private: - //ConnectionHandler* m_connHandler; - ConnectionHandler& m_connHandler; - - int m_maxRetries; - bool m_resubscribe; - std::string m_flxHost; - unsigned int m_portFromHost; - unsigned int m_portToHost; - uint32_t m_elinkID_rx; - uint32_t m_elinkID_tx; - +address_ICNETIO central_json_cfg_address_ICNETIO( + std::string json_path = "/opt/atlas/etc/cfg_ICNETIO_address.json"); + +class ElinksICNETIO : public Elinks { + public: + // ElinksICNETIO( + // unsigned int rx_elink_n, + // unsigned int tx_elink_n, + // std::string ec_lock_filename); + + ElinksICNETIO( + // unsigned int rx_elink_n = 0x1c, + // unsigned int tx_elink_n = 0x14, + // std::string ec_lock_filename = FALLBACK_EC_LINK_LOCK_FILE, + address_Elinks = address_Elinks(), + + // std::string flxHost = "pcatlitkflx03", + // unsigned int portFromHost = 12340, // Tx + // unsigned int portToHost = 12350, // Rx + address_ICNETIO = address_ICNETIO(), bool dontWaitReply = false, + bool resubscribeValue = false); // TODO do we need this? + + // IChandler(std::string flxHost, unsigned int portToGBTx, unsigned int + // portFromGBTx, uint32_t elinkID, uint32_t elinkID_requestSocket, uint8_t + // i2cAddr = 127, IC_DEV ic_dev_id=IC_DEV_GBTx, bool resubscribeValue = + // false); + + ~ElinksICNETIO(); + + virtual void disconnect(void); + virtual void connect(void); + + // actual io methods + std::vector<uint8_t> readData(); + int sendBitstream(BitStream); + int sendByteStream(std::vector<uint8_t>); + + private: + // ConnectionHandler* m_connHandler; + ConnectionHandler& m_connHandler; + + int m_maxRetries; + bool m_resubscribe; + std::string m_flxHost; + unsigned int m_portFromHost; + unsigned int m_portToHost; + uint32_t m_elinkID_rx; + uint32_t m_elinkID_tx; }; -#endif //ELINKSICNETIO_H +#endif // ELINKSICNETIO_H diff --git a/pbv3/ElinksYARR.cpp b/pbv3/ElinksYARR.cpp index 478f8b3b9798a6290f2b30c82a1685583f302017..ee5536c0836118c98575bde35e0ee6408453bda8 100644 --- a/pbv3/ElinksYARR.cpp +++ b/pbv3/ElinksYARR.cpp @@ -1,101 +1,108 @@ //#include "EndeavourRawElinks.h" #include "ElinksYARR.h" -#include "EndeavourComException.h" - #include <Logger.h> +#include <string.h> -#include "DeviceCom.h" - +#include <chrono> #include <memory> -#include <string.h> -#include <sstream> // against invalid use of incomplete type ‘std::string’ +#include <sstream> // against invalid use of incomplete type ‘std::string’ #include <thread> -#include <chrono> +#include "DeviceCom.h" +#include "EndeavourComException.h" using Clock = std::chrono::steady_clock; - -#include <nlohmann/json.hpp> // HwController's configuration is saved in a json +#include <nlohmann/json.hpp> // HwController's configuration is saved in a json // we need HwController to configure and get to the Rx-Tx Cores // the IO operates on the cores -#include "libYarr/include/AllHwControllers.h" // the sub-lib with different access systems to the Rx-Tx Cores = HwController +#include "libYarr/include/AllHwControllers.h" // the sub-lib with different access systems to the Rx-Tx Cores = HwController //#include "DeviceCom.h" -//#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController -// TxCore does not have sendBitstream -- the patch from Olivier to send bytes over Netio -// but it defines the interface class for NetioTx -#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController -#include "libNetioHW/include/NetioTxCore.h" // -#include "libYarr/include/RxCore.h" // -#include "libYarr/include/RawData.h" // the GBT read buffer -//#include "libUtil/include/BitStream.h" // Endeavour protocol not there in the new YAR - - -address_YARR central_json_cfg_address_YARR( - std::string hwcontroller_json_path) +//#include "libYarr/include/TxCore.h" // the communication cores on the YARR +//HwController +// TxCore does not have sendBitstream -- the patch from Olivier to send bytes +// over Netio but it defines the interface class for NetioTx +#include "libNetioHW/include/NetioTxCore.h" // +#include "libYarr/include/RawData.h" // the GBT read buffer +#include "libYarr/include/RxCore.h" // +#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController +//#include "libUtil/include/BitStream.h" // Endeavour protocol not there in the +//new YAR + +address_YARR central_json_cfg_address_YARR(std::string hwcontroller_json_path) { - logger(logDEBUG) << "central_json_cfg_address_YARR with config file: " << hwcontroller_json_path; + logger(logDEBUG) << "central_json_cfg_address_YARR with config file: " + << hwcontroller_json_path; - address_YARR addr = address_YARR(); // init with hard-coded defaults - // try to get the config from the file - // if no -- warn and return the defaults + address_YARR addr = address_YARR(); // init with hard-coded defaults + // try to get the config from the file + // if no -- warn and return the defaults - nlohmann::json ctrlCfg; + nlohmann::json ctrlCfg; - // try to open the file and parse json from it - std::ifstream controllerFile(hwcontroller_json_path); + // try to open the file and parse json from it + std::ifstream controllerFile(hwcontroller_json_path); - if(controllerFile.is_open()) - { - //ctrlCfg = json::parse(controllerFile); + if (controllerFile.is_open()) { + // ctrlCfg = json::parse(controllerFile); - try - { ctrlCfg = nlohmann::json::parse(controllerFile); } + try { + ctrlCfg = nlohmann::json::parse(controllerFile); + } - catch (nlohmann::json::parse_error &e) - { logger(logERROR) << "central_json_cfg_address_YARR could not parse YARR hwcontroller config: " << e.what(); } + catch (nlohmann::json::parse_error &e) { + logger(logERROR) << "central_json_cfg_address_YARR could not parse " + "YARR hwcontroller config: " + << e.what(); + } } - else - { - logger(logWARNING) << "central_json_cfg_address_YARR unable to open YARR hwcontroller config file, proceed with defaults"; - // if no config file -- return defaults - return addr; + else { + logger(logWARNING) + << "central_json_cfg_address_YARR unable to open YARR hwcontroller " + "config file, proceed with defaults"; + // if no config file -- return defaults + return addr; } - logger(logDEBUG) << "central_json_cfg_address_YARR parsed YARR hwcontroller config"; + logger(logDEBUG) + << "central_json_cfg_address_YARR parsed YARR hwcontroller config"; - // check the json - // and get the data to configure YARR hwcontroller + // check the json + // and get the data to configure YARR hwcontroller - if (ctrlCfg.contains("yarr_hwcontroller")) - { - auto cfg = ctrlCfg["yarr_hwcontroller"]; + if (ctrlCfg.contains("yarr_hwcontroller")) { + auto cfg = ctrlCfg["yarr_hwcontroller"]; - if (cfg.contains("hwcontroller_type")) - { addr.hwcontroller_type = cfg["hwcontroller_type"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_YARR hwcontroller config has no hwcontroller_type"; } + if (cfg.contains("hwcontroller_type")) { + addr.hwcontroller_type = cfg["hwcontroller_type"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_YARR hwcontroller " + "config has no hwcontroller_type"; + } - if (cfg.contains("config")) - { addr.config = cfg["config"]; } - else - { logger(logDEBUG) << "central_json_cfg_address_YARR hwcontroller config has no config"; } + if (cfg.contains("config")) { + addr.config = cfg["config"]; + } else { + logger(logDEBUG) << "central_json_cfg_address_YARR hwcontroller " + "config has no config"; + } } - else - { logger(logDEBUG) << "central_json_cfg_address_YARR no yarr_hwcontroller config"; } + else { + logger(logDEBUG) + << "central_json_cfg_address_YARR no yarr_hwcontroller config"; + } - return addr; + return addr; } -void addToBitStream(BitStream & bs, uint8_t byte){ - //Use the value from the LSB - for(uint32_t i=0;i<8;i++) - bs.push_back((byte>>(8-i-1))&1); +void addToBitStream(BitStream &bs, uint8_t byte) { + // Use the value from the LSB + for (uint32_t i = 0; i < 8; i++) bs.push_back((byte >> (8 - i - 1)) & 1); } /* @@ -103,51 +110,50 @@ void addToBitStream(BitStream & bs, uint8_t byte){ BitStream invert(BitStream msg) { BitStream inverted; - for (int32_t bit = msg.GetNbits()-1; bit>=0; --bit) + for (int32_t bit = msg.GetNbits()-1; bit>=0; --bit) inverted.Add(1, msg.Get(bit)); return inverted; } */ // TODO: remove this? or make some general endianness functions -bool bit_in_endian_bytes(uint32_t input, unsigned int bit_index) -{ - unsigned int bit_i = bit_index & 0x7; - unsigned int byte_i = bit_index >> 3; // reminder devision by 8 +bool bit_in_endian_bytes(uint32_t input, unsigned int bit_index) { + unsigned int bit_i = bit_index & 0x7; + unsigned int byte_i = bit_index >> 3; // reminder devision by 8 char byte = (input >> byte_i * 8) & 0xFF; return (byte << bit_i) & 0x80; } /** \brief swaps the endianness in the word */ -uint32_t swap_byte_endiannes(uint32_t input) -{ - uint8_t byte1 = (input & 0x000000ff) >> 0; - uint8_t byte2 = (input & 0x0000ff00) >> 8; +uint32_t swap_byte_endiannes(uint32_t input) { + uint8_t byte1 = (input & 0x000000ff) >> 0; + uint8_t byte2 = (input & 0x0000ff00) >> 8; uint8_t byte3 = (input & 0x00ff0000) >> 16; uint8_t byte4 = (input & 0xff000000) >> 24; - uint32_t swapped = 0; swapped = swapped | byte1; - swapped <<= 8; swapped = swapped | byte2; - swapped <<= 8; swapped = swapped | byte3; - swapped <<= 8; swapped = swapped | byte4; + uint32_t swapped = 0; + swapped = swapped | byte1; + swapped <<= 8; + swapped = swapped | byte2; + swapped <<= 8; + swapped = swapped | byte3; + swapped <<= 8; + swapped = swapped | byte4; return swapped; } -union word32bit8bit -{ +union word32bit8bit { std::uint32_t theDWord; std::uint8_t theBytes[4]; }; - - /* ElinksYARR::ElinksYARR( - unsigned int rx_elink_n, - unsigned int tx_elink_n, - std::string ec_lock_filename) + unsigned int rx_elink_n, + unsigned int tx_elink_n, + std::string ec_lock_filename) : ElinksYARR::ElinksYARR(rx_elink_n, tx_elink_n, @@ -158,242 +164,256 @@ ElinksYARR::ElinksYARR( */ ElinksYARR::ElinksYARR( - //unsigned int rx_elink_n, unsigned int tx_elink_n, - //std::string ec_lock_filename, - address_Elinks address_elinks, + // unsigned int rx_elink_n, unsigned int tx_elink_n, + // std::string ec_lock_filename, + address_Elinks address_elinks, - //const std::string& hwcontroller_type, - //const std::string& config - address_YARR address_yarr - ) + // const std::string& hwcontroller_type, + // const std::string& config + address_YARR address_yarr) -: - //Elinks(rx_elink_n, tx_elink_n, ec_lock_filename) - Elinks(address_elinks) + : // Elinks(rx_elink_n, tx_elink_n, ec_lock_filename) + Elinks(address_elinks) { - logger(logDEBUG) << "ElinksYARR::ElinksYARR Configure YARR HwController " - << address_yarr.hwcontroller_type - << " with " - << address_yarr.config; - - json ctrlCfg; - std::ifstream controllerFile(address_yarr.config); - - if(controllerFile.is_open()) - { - //ctrlCfg = json::parse(controllerFile); - - try - { ctrlCfg = json::parse(controllerFile); } - catch (json::parse_error &e) - { logger(logERROR) << "Could not parse YARR controller config: " << e.what(); } - //logger(logDEBUG) << "Parsed YARR controller config."; + logger(logDEBUG) << "ElinksYARR::ElinksYARR Configure YARR HwController " + << address_yarr.hwcontroller_type << " with " + << address_yarr.config; + + json ctrlCfg; + std::ifstream controllerFile(address_yarr.config); + + if (controllerFile.is_open()) { + // ctrlCfg = json::parse(controllerFile); + + try { + ctrlCfg = json::parse(controllerFile); + } catch (json::parse_error &e) { + logger(logERROR) + << "Could not parse YARR controller config: " << e.what(); + } + // logger(logDEBUG) << "Parsed YARR controller config."; } - else - { logger(logERROR) << "Unable to open YARR config file: " << address_yarr.config; } + else { + logger(logERROR) << "Unable to open YARR config file: " + << address_yarr.config; + } - // here we just set up the info for the connection - // the actual netio connection to Felixcore/Felixstar is not performed yet - gbt_hwCtrl = StdDict::getHwController(address_yarr.hwcontroller_type); - gbt_hwCtrl->loadConfig(ctrlCfg["ctrlCfg"]["cfg"]); + // here we just set up the info for the connection + // the actual netio connection to Felixcore/Felixstar is not performed yet + gbt_hwCtrl = StdDict::getHwController(address_yarr.hwcontroller_type); + gbt_hwCtrl->loadConfig(ctrlCfg["ctrlCfg"]["cfg"]); - gbt_rx_core = dynamic_cast<RxCore*>(&*gbt_hwCtrl); - //gbt_tx_core = dynamic_cast<TxCore*>(&*gbt_hwCtrl); - gbt_tx_core = dynamic_cast<NetioTxCore*>(&*gbt_hwCtrl); + gbt_rx_core = dynamic_cast<RxCore *>(&*gbt_hwCtrl); + // gbt_tx_core = dynamic_cast<TxCore*>(&*gbt_hwCtrl); + gbt_tx_core = dynamic_cast<NetioTxCore *>(&*gbt_hwCtrl); - connect(); - logger(logDEBUG) << "ElinksYARR::ElinksYARR done"; - //logger(logDEBUG) << "ElinksYARR, enabled 1 e-links to listen, 1 to send commands."; + connect(); + logger(logDEBUG) << "ElinksYARR::ElinksYARR done"; + // logger(logDEBUG) << "ElinksYARR, enabled 1 e-links to listen, 1 to send + // commands."; } -ElinksYARR::~ElinksYARR() -{ - // unsibscribe from NetIO - //gbt_hwCtrl.reset(); // <- the same as delete *obj for shared_ptr - //gbt_hwCtrl = nullptr; - //unlockConnection(); - disconnect(); +ElinksYARR::~ElinksYARR() { + // unsibscribe from NetIO + // gbt_hwCtrl.reset(); // <- the same as delete *obj for shared_ptr + // gbt_hwCtrl = nullptr; + // unlockConnection(); + disconnect(); } -void ElinksYARR::disconnect(void) -{ - logger(logDEBUG) << "ElinksYARR::disconnect disconnecting"; +void ElinksYARR::disconnect(void) { + logger(logDEBUG) << "ElinksYARR::disconnect disconnecting"; - if (!m_connection_locked) - { - logger(logDEBUG) << "ElinksYARR::disconnect already done"; - return; + if (!m_connection_locked) { + logger(logDEBUG) << "ElinksYARR::disconnect already done"; + return; } - { - // close the connection - gbt_hwCtrl.reset(); // <- the same as delete *obj for shared_ptr - gbt_hwCtrl = nullptr; + { + // close the connection + gbt_hwCtrl.reset(); // <- the same as delete *obj for shared_ptr + gbt_hwCtrl = nullptr; - unlockConnection(); - logger(logDEBUG) << "ElinksYARR::disconnect unlockedConnections <---------------------"; - } + unlockConnection(); + logger(logDEBUG) << "ElinksYARR::disconnect unlockedConnections " + "<---------------------"; + } - logger(logDEBUG) << "ElinksYARR::disconnect done"; + logger(logDEBUG) << "ElinksYARR::disconnect done"; } -void ElinksYARR::connect(void) -{ - logger(logDEBUG) << "ElinksYARR::connect"; +void ElinksYARR::connect(void) { + logger(logDEBUG) << "ElinksYARR::connect"; - if (m_connection_locked) - { - logger(logDEBUG) << "ElinksYARR::connect already done"; - return; + if (m_connection_locked) { + logger(logDEBUG) << "ElinksYARR::connect already done"; + return; } - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - - logger(logDEBUG) << "ElinksYARR::connect locking connection <---------------------"; - lockConnection(); - - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "ElinksYARR::connect lock time " << diagnostic_time.count() << " us"; + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - try { - // here the actual netio connection to Felixcore/Felixstar must be done - gbt_rx_core -> setRxEnable(m_rx_elink_n); //63); // (28); // 0 in IU - gbt_tx_core -> setCmdEnable(m_tx_elink_n); //63); // (32); // it is 20 in IU - logger(logDEBUG) << "ElinksYARR::connect Connected to e-links RX=" << std::hex << m_rx_elink_n << " & TX=" << m_tx_elink_n << std::dec; + logger(logDEBUG) + << "ElinksYARR::connect locking connection <---------------------"; + lockConnection(); - diagnostic_time_end = Clock::now(); + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "ElinksYARR::connect time " << diagnostic_time.count() << " us"; - } - - catch (const std::exception& e) { // unlock the EC file and re-throw - logger(logWARNING) << "ElinksYARR::connect EXCEPT " << e.what(); - //delete m_connHandler; - gbt_hwCtrl.reset(); gbt_hwCtrl = nullptr; - unlockConnection(); - throw; - } -} - - -std::vector<uint8_t> ElinksYARR::readData() -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - - std::vector<RawData*> gbt_buffer_data; // we can have multiple reads from YARR's netio controller - RawData *data = nullptr; - - //RawDataContainer several_buffers_data; - unsigned int max_reads = 10; // we can receive several messages at once - unsigned int microseconds_of_delay_between_reads = 10; + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "ElinksYARR::connect lock time " + << diagnostic_time.count() << " us"; + + try { + // here the actual netio connection to Felixcore/Felixstar must be done + gbt_rx_core->setRxEnable(m_rx_elink_n); // 63); // (28); // 0 in IU + gbt_tx_core->setCmdEnable( + m_tx_elink_n); // 63); // (32); // it is 20 in IU + logger(logDEBUG) << "ElinksYARR::connect Connected to e-links RX=" + << std::hex << m_rx_elink_n << " & TX=" << m_tx_elink_n + << std::dec; + + diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "ElinksYARR::connect time " + << diagnostic_time.count() << " us"; + } - for (uint32_t i = 0; i < max_reads; ++i) - { - data = gbt_rx_core->readData(); - if (data == nullptr) - { - if (gbt_buffer_data.size() > 0) break; // if something is already found and there is no data then it must be the end of the message sequence - std::this_thread::sleep_for(std::chrono::microseconds(microseconds_of_delay_between_reads)); - } - else - { - gbt_buffer_data.push_back(data); // stack the response messages - } + catch (const std::exception &e) { // unlock the EC file and re-throw + logger(logWARNING) << "ElinksYARR::connect EXCEPT " << e.what(); + // delete m_connHandler; + gbt_hwCtrl.reset(); + gbt_hwCtrl = nullptr; + unlockConnection(); + throw; } +} - // convert RawData into vector<uint8> and return it - std::vector<std::vector<uint8_t>> all_reads; +std::vector<uint8_t> ElinksYARR::readData() { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - // loop over all reads from YARR - for(unsigned int i=0; i<gbt_buffer_data.size(); i++) - { - // the YARR data comes in 32-bit words - // 1 RawData buffer is a bunch of such words - RawData* buffer_data = gbt_buffer_data[i]; - std::vector<uint8_t> data_bytes; - - //if (buffer_data->words > 2) - // { - // logger(logDEBUG) << "received more than 64 bits of an AMAC message in one NetIO buffer: " << buffer_data->words; - // } - - unsigned int n_words = buffer_data->words; // 2; // buffer_data->words - logger(logDEBUG) << "ElinksYARR::readData received n_words= " << n_words; - - for (uint32_t j=0; j < n_words; ++j) - { - // a 32-bit word - uint32_t n = buffer_data->buf[j]; - logger(logDEBUG) << "ElinksYARR::readData word=" << j << " is " << std::hex << n; - - // swap endianness in the word: the order of bytes - bool to_swap = false; // TODO: expose the endianness swapping optionm somehow - uint32_t n_endianned = to_swap ? swap_byte_endiannes(n) : n; - - // convert it to bytes - word32bit8bit word_bytes; - word_bytes.theDWord = n_endianned; - - data_bytes.push_back(word_bytes.theBytes[0]); // <- and I can swap endianness here - data_bytes.push_back(word_bytes.theBytes[1]); - data_bytes.push_back(word_bytes.theBytes[2]); - data_bytes.push_back(word_bytes.theBytes[3]); - } - - // if it is 8 bytes (64 bits) -- drop the last two (to 48 bit) - // = AMAC response to READ & READNEXT - if (data_bytes.size() == 8) - { data_bytes.pop_back(); data_bytes.pop_back(); } - - // if it is 4 bytes (32 bits) -- drop the last three (to 8 bits) - // = AMAC response to WRITE & SETID - else if (data_bytes.size() == 4) - { data_bytes.pop_back(); data_bytes.pop_back(); data_bytes.pop_back(); } - - all_reads.push_back(data_bytes); + std::vector<RawData *> gbt_buffer_data; // we can have multiple reads from + // YARR's netio controller + RawData *data = nullptr; + + // RawDataContainer several_buffers_data; + unsigned int max_reads = 10; // we can receive several messages at once + unsigned int microseconds_of_delay_between_reads = 10; + + for (uint32_t i = 0; i < max_reads; ++i) { + data = gbt_rx_core->readData(); + if (data == nullptr) { + if (gbt_buffer_data.size() > 0) + break; // if something is already found and there is no data + // then it must be the end of the message sequence + std::this_thread::sleep_for( + std::chrono::microseconds(microseconds_of_delay_between_reads)); + } else { + gbt_buffer_data.push_back(data); // stack the response messages + } } - logger(logDEBUG) << "ElinksYARR::readData processed " << all_reads.size() << " messages"; - //std::vector<uint8_t> data_out = all_reads[0]; + // convert RawData into vector<uint8> and return it + std::vector<std::vector<uint8_t>> all_reads; + + // loop over all reads from YARR + for (unsigned int i = 0; i < gbt_buffer_data.size(); i++) { + // the YARR data comes in 32-bit words + // 1 RawData buffer is a bunch of such words + RawData *buffer_data = gbt_buffer_data[i]; + std::vector<uint8_t> data_bytes; + + // if (buffer_data->words > 2) + // { + // logger(logDEBUG) << "received more than 64 bits of an AMAC message + // in one NetIO buffer: " << buffer_data->words; + // } + + unsigned int n_words = buffer_data->words; // 2; // buffer_data->words + logger(logDEBUG) << "ElinksYARR::readData received n_words= " + << n_words; + + for (uint32_t j = 0; j < n_words; ++j) { + // a 32-bit word + uint32_t n = buffer_data->buf[j]; + logger(logDEBUG) + << "ElinksYARR::readData word=" << j << " is " << std::hex << n; + + // swap endianness in the word: the order of bytes + bool to_swap = + false; // TODO: expose the endianness swapping optionm somehow + uint32_t n_endianned = to_swap ? swap_byte_endiannes(n) : n; + + // convert it to bytes + word32bit8bit word_bytes; + word_bytes.theDWord = n_endianned; + + data_bytes.push_back( + word_bytes.theBytes[0]); // <- and I can swap endianness here + data_bytes.push_back(word_bytes.theBytes[1]); + data_bytes.push_back(word_bytes.theBytes[2]); + data_bytes.push_back(word_bytes.theBytes[3]); + } + + // if it is 8 bytes (64 bits) -- drop the last two (to 48 bit) + // = AMAC response to READ & READNEXT + if (data_bytes.size() == 8) { + data_bytes.pop_back(); + data_bytes.pop_back(); + } + + // if it is 4 bytes (32 bits) -- drop the last three (to 8 bits) + // = AMAC response to WRITE & SETID + else if (data_bytes.size() == 4) { + data_bytes.pop_back(); + data_bytes.pop_back(); + data_bytes.pop_back(); + } + + all_reads.push_back(data_bytes); + } - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "ElinksYARR::readData time " << diagnostic_time.count() << " us"; + logger(logDEBUG) << "ElinksYARR::readData processed " << all_reads.size() + << " messages"; + // std::vector<uint8_t> data_out = all_reads[0]; - if (all_reads.size() > 0) - { return all_reads[0]; } - else - { return {}; } + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "ElinksYARR::readData time " << diagnostic_time.count() + << " us"; + + if (all_reads.size() > 0) { + return all_reads[0]; + } else { + return {}; + } } -int ElinksYARR::sendBitstream(BitStream outdata) -{ +int ElinksYARR::sendBitstream(BitStream outdata) { std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); gbt_tx_core->sendBitstream(outdata); std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "ElinksYARR::sendBitstream time " << diagnostic_time.count() << " us"; + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "ElinksYARR::sendBitstream time " + << diagnostic_time.count() << " us"; return 0; } -int ElinksYARR::sendByteStream(std::vector<uint8_t> outdata) -{ - BitStream bits; - for(unsigned int i=0; i<outdata.size(); i++) - { - addToBitStream(bits, outdata[i]); - } +int ElinksYARR::sendByteStream(std::vector<uint8_t> outdata) { + BitStream bits; + for (unsigned int i = 0; i < outdata.size(); i++) { + addToBitStream(bits, outdata[i]); + } - return sendBitstream(bits); + return sendBitstream(bits); } - diff --git a/pbv3/ElinksYARR.h b/pbv3/ElinksYARR.h index b545ff073e89bac2e924c0dc70543b0e43ec7047..f6a2d5b78e3216a19c22ee93039dcba5ca7623cb 100644 --- a/pbv3/ElinksYARR.h +++ b/pbv3/ElinksYARR.h @@ -1,63 +1,65 @@ #ifndef ELINKSYARR_H #define ELINKSYARR_H +#include <memory> // shared_ptr #include <string> -#include <memory> // shared_ptr #include "Elinks.h" -#define FALLBACK_YARR_NETIO_CONFIG_PATH "/opt/atlas/configs_yarr/controller/netio_amac.json" +#define FALLBACK_YARR_NETIO_CONFIG_PATH \ + "/opt/atlas/configs_yarr/controller/netio_amac.json" // YARR classes class HwController; class RxCore; -//class TxCore; +// class TxCore; class NetioTxCore; class RawData; -//class BitStream; +// class BitStream; typedef struct { - std::string hwcontroller_type = "Netio"; - std::string config = FALLBACK_YARR_NETIO_CONFIG_PATH; + std::string hwcontroller_type = "Netio"; + std::string config = FALLBACK_YARR_NETIO_CONFIG_PATH; } address_YARR; -address_YARR central_json_cfg_address_YARR(std::string json_path = "/opt/atlas/etc/cfg_YARR_hwcontroller_address.json"); +address_YARR central_json_cfg_address_YARR( + std::string json_path = + "/opt/atlas/etc/cfg_YARR_hwcontroller_address.json"); -class ElinksYARR : public Elinks -{ -public: - //ElinksYARR( - // unsigned int rx_elink_n, - // unsigned int tx_elink_n, - // std::string ec_lock_filename); +class ElinksYARR : public Elinks { + public: + // ElinksYARR( + // unsigned int rx_elink_n, + // unsigned int tx_elink_n, + // std::string ec_lock_filename); - ElinksYARR( - //unsigned int rx_elink_n, unsigned int tx_elink_n, - //std::string ec_lock_filename = FALLBACK_EC_LINK_LOCK_FILE, - address_Elinks = address_Elinks(), + ElinksYARR( + // unsigned int rx_elink_n, unsigned int tx_elink_n, + // std::string ec_lock_filename = FALLBACK_EC_LINK_LOCK_FILE, + address_Elinks = address_Elinks(), - //const std::string& hwcontroller_type = "Netio", - //const std::string& config = FALLBACK_YARR_NETIO_CONFIG_PATH - address_YARR = address_YARR() - ); + // const std::string& hwcontroller_type = "Netio", + // const std::string& config = FALLBACK_YARR_NETIO_CONFIG_PATH + address_YARR = address_YARR()); - ~ElinksYARR(); + ~ElinksYARR(); - virtual void disconnect(void); - virtual void connect(void); + virtual void disconnect(void); + virtual void connect(void); - // do I need to declare them here? - std::vector<uint8_t> readData(); - int sendBitstream(BitStream); - int sendByteStream(std::vector<uint8_t>); + // do I need to declare them here? + std::vector<uint8_t> readData(); + int sendBitstream(BitStream); + int sendByteStream(std::vector<uint8_t>); -private: - std::shared_ptr<HwController> gbt_hwCtrl; - RxCore* gbt_rx_core; - //TxCore* gbt_tx_core; - NetioTxCore* gbt_tx_core; + private: + std::shared_ptr<HwController> gbt_hwCtrl; + RxCore* gbt_rx_core; + // TxCore* gbt_tx_core; + NetioTxCore* gbt_tx_core; - //std::vector<RawData*> gbt_buffer_data; // elinks do not hold any temporary data, they just return it from readData + // std::vector<RawData*> gbt_buffer_data; // elinks do not hold any + // temporary data, they just return it from readData }; -#endif //ELINKSYARR_H +#endif // ELINKSYARR_H diff --git a/pbv3/EndeavourCom.cpp b/pbv3/EndeavourCom.cpp index 91b405ca8160ef44a9f60bbcd96c4c34e64c7955..555e6deff71cd39b745fdc221d8e59f0b3ee9788 100644 --- a/pbv3/EndeavourCom.cpp +++ b/pbv3/EndeavourCom.cpp @@ -1,458 +1,479 @@ #include "EndeavourCom.h" -#include "EndeavourComException.h" -#include "EndeavourRawElinks.h" #include <Logger.h> +#include <unistd.h> +#include <chrono> #include <iostream> #include <memory> #include <thread> -#include <unistd.h> -#include <chrono> +#include "EndeavourComException.h" +#include "EndeavourRawElinks.h" using Clock = std::chrono::steady_clock; // the typical latency to read 1 register in SR1 is 5ms -// we use a for loop that checks for the RX data N times, waiting TIMEOUT_UNITus us between iterations -#define TIMEOUT_UNITus 1000 // used to be 10 microseconds -#define TIMEOUT_N 1000 +// we use a for loop that checks for the RX data N times, waiting TIMEOUT_UNITus +// us between iterations +#define TIMEOUT_UNITus 1000 // used to be 10 microseconds +#define TIMEOUT_N 1000 #define TIMEOUT_N_SETID 1000 #define TIMEOUT_N_WRITE 1200 -EndeavourCom::EndeavourCom(unsigned short amacid, bool use_icnetio, std::string config_file, bool dontWaitReply) -{ - m_config_file = config_file; - m_raw = std::make_shared<EndeavourRawElinks>(use_icnetio, m_config_file, dontWaitReply); +EndeavourCom::EndeavourCom(unsigned short amacid, bool use_icnetio, + std::string config_file, bool dontWaitReply) { + m_config_file = config_file; + m_raw = std::make_shared<EndeavourRawElinks>(use_icnetio, m_config_file, + dontWaitReply); } -void EndeavourCom::reset_raw(bool use_icnetio, std::string config_file) -{ - m_raw.reset(); - m_config_file = config_file; - m_raw = std::make_shared<EndeavourRawElinks>(use_icnetio, m_config_file); +void EndeavourCom::reset_raw(bool use_icnetio, std::string config_file) { + m_raw.reset(); + m_config_file = config_file; + m_raw = std::make_shared<EndeavourRawElinks>(use_icnetio, m_config_file); } -EndeavourCom::EndeavourCom(unsigned short amacid, std::shared_ptr<EndeavourRaw> raw) - //: m_amacid(amacid&0x1F) +EndeavourCom::EndeavourCom(unsigned short amacid, + std::shared_ptr<EndeavourRaw> raw) +//: m_amacid(amacid&0x1F) { - m_raw = raw; + m_raw = raw; } -EndeavourCom::EndeavourCom(unsigned short amacid, std::unique_ptr<EndeavourRaw> raw_unique) -{ - m_raw = std::move(raw_unique); +EndeavourCom::EndeavourCom(unsigned short amacid, + std::unique_ptr<EndeavourRaw> raw_unique) { + m_raw = std::move(raw_unique); } -const std::shared_ptr<EndeavourRaw>& EndeavourCom::raw() -{ return m_raw; } +const std::shared_ptr<EndeavourRaw>& EndeavourCom::raw() { return m_raw; } -void EndeavourCom::enableSeqNum(bool enableSeqNum) -{ m_enableSeqNum=enableSeqNum; } +void EndeavourCom::enableSeqNum(bool enableSeqNum) { + m_enableSeqNum = enableSeqNum; +} -void EndeavourCom::reset() -{ - m_raw->reset(); - m_seqnum=0; +void EndeavourCom::reset() { + m_raw->reset(); + m_seqnum = 0; } -void EndeavourCom::_set_amacid(unsigned short amacid) -{ - //m_amacid = amacid; +void EndeavourCom::_set_amacid(unsigned short amacid) { + // m_amacid = amacid; } -//void EndeavourCom::setid(REFMODE mode, unsigned int refid, unsigned short amacid) +// void EndeavourCom::setid(REFMODE mode, unsigned int refid, unsigned short +// amacid) //{ // m_amacid = amacid; // setid(mode, refid); //} -void EndeavourCom::setid(unsigned short c_amacid, REFMODE mode, unsigned int refid) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - - logger(logDEBUG) << "EndeavourCom::setid REFMODE " << mode << " refid " << refid << " to amacid " << c_amacid; - // Want to send 1's 1000 times, to avoid hysteresis issues - // where the voltages on the n and p sides of CMDIN are swapped. - // With ~15 foot cables, we needed ~500 1's for this to work - // properly, so let's send 1000 of them to be safe! - //m_raw->sendData(0xFF,8); - - // to give space between our hysteresis 1's and the actual SETID - //std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus));; // TODO: this is probably not needed - - unsigned long long int databits=0; - - //{3'b110, 5'b11111, 3'b111, newamacid[4:0], 4'b1111, efuseid[19:0], 3'b111, idpads[4:0], crc[7:0]} - - // SETID - 3'b110 - databits<<=3; - databits|=0b110; - - // 3'b11111 - databits<<=5; - databits|=0b11111; - - // 3'b111 - databits<<=3; - databits|=0b111; - - // newamacid[4:0] - databits<<=5; - databits|=(c_amacid&0x1F); - - // 4'b1111 - databits<<=4; - databits|=0b1111; - - // efuseid[19:0] - databits<<=20; - if(mode==REFMODE::EfuseId) - databits|=(refid&0xFFFFF); - else - databits|=0xFFFFF; - - // 3'b111 - databits<<=3; - databits|=0b111; - - // idpads[4:0] - databits<<=5; - if(mode==IDPads) - databits|=(refid&0x1F); - else - databits|=0x1F; - - // crc[7:0] - unsigned int crc=calc_crc(databits); - databits<<=8; - databits|=(crc&0xFF); - - if (m_raw == nullptr) std::cerr << "\033[1;31mEndeavourCom::setid set m_raw =\033[0m" << m_raw << std::endl; - - // send data - m_raw->sendData(databits, 56); - m_seqnum++; - - // wait for response ( poll :( ) - uint tryidx=0; - for(tryidx=0;tryidx<TIMEOUT_N_SETID;tryidx++) - { - std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus));; - if(m_raw->isDataValid()) break; +void EndeavourCom::setid(unsigned short c_amacid, REFMODE mode, + unsigned int refid) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + + logger(logDEBUG) << "EndeavourCom::setid REFMODE " << mode << " refid " + << refid << " to amacid " << c_amacid; + // Want to send 1's 1000 times, to avoid hysteresis issues + // where the voltages on the n and p sides of CMDIN are swapped. + // With ~15 foot cables, we needed ~500 1's for this to work + // properly, so let's send 1000 of them to be safe! + // m_raw->sendData(0xFF,8); + + // to give space between our hysteresis 1's and the actual SETID + // std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus));; + // // TODO: this is probably not needed + + unsigned long long int databits = 0; + + //{3'b110, 5'b11111, 3'b111, newamacid[4:0], 4'b1111, efuseid[19:0], 3'b111, + //idpads[4:0], crc[7:0]} + + // SETID - 3'b110 + databits <<= 3; + databits |= 0b110; + + // 3'b11111 + databits <<= 5; + databits |= 0b11111; + + // 3'b111 + databits <<= 3; + databits |= 0b111; + + // newamacid[4:0] + databits <<= 5; + databits |= (c_amacid & 0x1F); + + // 4'b1111 + databits <<= 4; + databits |= 0b1111; + + // efuseid[19:0] + databits <<= 20; + if (mode == REFMODE::EfuseId) + databits |= (refid & 0xFFFFF); + else + databits |= 0xFFFFF; + + // 3'b111 + databits <<= 3; + databits |= 0b111; + + // idpads[4:0] + databits <<= 5; + if (mode == IDPads) + databits |= (refid & 0x1F); + else + databits |= 0x1F; + + // crc[7:0] + unsigned int crc = calc_crc(databits); + databits <<= 8; + databits |= (crc & 0xFF); + + if (m_raw == nullptr) + std::cerr << "\033[1;31mEndeavourCom::setid set m_raw =\033[0m" << m_raw + << std::endl; + + // send data + m_raw->sendData(databits, 56); + m_seqnum++; + + // wait for response ( poll :( ) + uint tryidx = 0; + for (tryidx = 0; tryidx < TIMEOUT_N_SETID; tryidx++) { + std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus)); + ; + if (m_raw->isDataValid()) break; } - if(tryidx==TIMEOUT_N_SETID) - { - //m_raw.reset(); - throw EndeavourComException("SETID timeout"); + if (tryidx == TIMEOUT_N_SETID) { + // m_raw.reset(); + throw EndeavourComException("SETID timeout"); } - // Parse the response - unsigned long long int read_data; - unsigned int read_nbits; - m_raw->readData(read_data,read_nbits); - //std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex << read_data << std::dec << std::endl; - - if(read_nbits==9) - { - read_data>>=1; - read_nbits--; + // Parse the response + unsigned long long int read_data; + unsigned int read_nbits; + m_raw->readData(read_data, read_nbits); + // std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex + // << read_data << std::dec << std::endl; + + if (read_nbits == 9) { + read_data >>= 1; + read_nbits--; } - if(read_nbits!=8) - { - //m_raw.reset(); - throw EndeavourComException("SETID recieved wrong number of bits: %d (expected 8)",read_nbits); + if (read_nbits != 8) { + // m_raw.reset(); + throw EndeavourComException( + "SETID recieved wrong number of bits: %d (expected 8)", read_nbits); } - unsigned short int seqnum=read_data&0b111; - if(m_enableSeqNum && seqnum!=m_seqnum) - { - //m_raw.reset(); - throw EndeavourComException("SETID recieved wrong sequence: %d (expected %d)",seqnum,m_seqnum); + unsigned short int seqnum = read_data & 0b111; + if (m_enableSeqNum && seqnum != m_seqnum) { + // m_raw.reset(); + throw EndeavourComException( + "SETID recieved wrong sequence: %d (expected %d)", seqnum, + m_seqnum); } - unsigned short int amacid=(read_data>>3)&0b11111; - if(amacid!=c_amacid) - { - //m_raw.reset(); - throw EndeavourComException("SETID recieved wrong amacid: %d (expected %d)",amacid,c_amacid); + unsigned short int amacid = (read_data >> 3) & 0b11111; + if (amacid != c_amacid) { + // m_raw.reset(); + throw EndeavourComException( + "SETID recieved wrong amacid: %d (expected %d)", amacid, c_amacid); } - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "EndeavourCom::setid time " << diagnostic_time.count() << " us -- to amacid " << c_amacid; + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "EndeavourCom::setid time " << diagnostic_time.count() + << " us -- to amacid " << c_amacid; } -void EndeavourCom::write_reg(unsigned short c_amacid, unsigned int address, unsigned int data) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); +void EndeavourCom::write_reg(unsigned short c_amacid, unsigned int address, + unsigned int data) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - logger(logDEBUG) << "EndeavourCom::write_reg " << std::hex << c_amacid << " " << address << " " << data << std::dec; - unsigned long long int databits=0; + logger(logDEBUG) << "EndeavourCom::write_reg " << std::hex << c_amacid + << " " << address << " " << data << std::dec; + unsigned long long int databits = 0; - //{3'b111, amacid[4:0], addr[7:0], data[31:0], crc[7:0]} + //{3'b111, amacid[4:0], addr[7:0], data[31:0], crc[7:0]} - // WRITE - 3'b110 - databits<<=3; - databits|=0b111; + // WRITE - 3'b110 + databits <<= 3; + databits |= 0b111; - // amacid[4:0] - databits<<=5; - databits|=(c_amacid&0x1F); + // amacid[4:0] + databits <<= 5; + databits |= (c_amacid & 0x1F); - // addr[7:0] - databits<<=8; - databits|=(address&0xFF); + // addr[7:0] + databits <<= 8; + databits |= (address & 0xFF); - // data[31:0] - databits<<=32; - databits|=(data&0xFFFFFFFF); + // data[31:0] + databits <<= 32; + databits |= (data & 0xFFFFFFFF); - // crc[7:0] - unsigned int crc=calc_crc(databits); - databits<<=8; - databits|=(crc&0xFF); + // crc[7:0] + unsigned int crc = calc_crc(databits); + databits <<= 8; + databits |= (crc & 0xFF); - if (m_raw == nullptr) std::cerr << "\033[1;31mEndeavourCom::write_reg set m_raw =\033[0m" << m_raw << std::endl; + if (m_raw == nullptr) + std::cerr << "\033[1;31mEndeavourCom::write_reg set m_raw =\033[0m" + << m_raw << std::endl; - // send data - m_raw->sendData(databits, 56); + // send data + m_raw->sendData(databits, 56); - // wait for response ( poll :( ) - uint tryidx=0; - for(tryidx=0;tryidx<TIMEOUT_N_WRITE;tryidx++) - { - std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus)); - if(m_raw->isDataValid()) break; + // wait for response ( poll :( ) + uint tryidx = 0; + for (tryidx = 0; tryidx < TIMEOUT_N_WRITE; tryidx++) { + std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus)); + if (m_raw->isDataValid()) break; } - if(tryidx==TIMEOUT_N_WRITE) - { - //m_raw.reset(); - throw EndeavourComException("WRITE timeout"); + if (tryidx == TIMEOUT_N_WRITE) { + // m_raw.reset(); + throw EndeavourComException("WRITE timeout"); } - // Parse the response - unsigned long long int read_data; - unsigned int read_nbits; - m_raw->readData(read_data,read_nbits); - //std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex << read_data << std::dec << std::endl; - m_seqnum++; - - if(read_nbits==9) - { - read_data>>=1; - read_nbits--; + // Parse the response + unsigned long long int read_data; + unsigned int read_nbits; + m_raw->readData(read_data, read_nbits); + // std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex + // << read_data << std::dec << std::endl; + m_seqnum++; + + if (read_nbits == 9) { + read_data >>= 1; + read_nbits--; } - if(read_nbits!=8) - { - //m_raw.reset(); - throw EndeavourComException("WRITE recieved wrong number of bits: %d (expected 8)",read_nbits); + if (read_nbits != 8) { + // m_raw.reset(); + throw EndeavourComException( + "WRITE recieved wrong number of bits: %d (expected 8)", read_nbits); } - unsigned short int seqnum=read_data&0b111; - if(m_enableSeqNum && seqnum!=m_seqnum) - { - //m_raw.reset(); - throw EndeavourComException("WRITE recieved wrong sequence: %d (expected %d)",seqnum,m_seqnum); + unsigned short int seqnum = read_data & 0b111; + if (m_enableSeqNum && seqnum != m_seqnum) { + // m_raw.reset(); + throw EndeavourComException( + "WRITE recieved wrong sequence: %d (expected %d)", seqnum, + m_seqnum); } - unsigned short int amacid=(read_data>>3)&0b11111; - if(amacid!=c_amacid) - { - //m_raw.reset(); - throw EndeavourComException("WRITE recieved wrong amacid: %d (expected %d)",amacid,c_amacid); + unsigned short int amacid = (read_data >> 3) & 0b11111; + if (amacid != c_amacid) { + // m_raw.reset(); + throw EndeavourComException( + "WRITE recieved wrong amacid: %d (expected %d)", amacid, c_amacid); } - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "EndeavourCom::write_reg amacid " << c_amacid << " reg " << std::to_string(address) << " time " << diagnostic_time.count() << " us"; + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "EndeavourCom::write_reg amacid " << c_amacid << " reg " + << std::to_string(address) << " time " + << diagnostic_time.count() << " us"; } -unsigned int EndeavourCom::read_reg(unsigned short c_amacid, unsigned int address) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); +unsigned int EndeavourCom::read_reg(unsigned short c_amacid, + unsigned int address) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - logger(logDEBUG) << "EndeavourCom::read_reg " << std::hex << address << std::dec << " on amacid " << c_amacid; - unsigned long long int databits=0; + logger(logDEBUG) << "EndeavourCom::read_reg " << std::hex << address + << std::dec << " on amacid " << c_amacid; + unsigned long long int databits = 0; - //{3'b101, amacid[4:0], addr[7:0]} + //{3'b101, amacid[4:0], addr[7:0]} - // READ - 3'b101 - databits<<=3; - databits|=0b101; + // READ - 3'b101 + databits <<= 3; + databits |= 0b101; - // amacid[4:0] - databits<<=5; - databits|=(c_amacid&0x1F); + // amacid[4:0] + databits <<= 5; + databits |= (c_amacid & 0x1F); - // addr[7:0] - databits<<=8; - databits|=(address&0xFF); + // addr[7:0] + databits <<= 8; + databits |= (address & 0xFF); - if (m_raw == nullptr) std::cerr << "\033[1;31mEndeavourCom::read_reg set m_raw =\033[0m" << m_raw << std::endl; + if (m_raw == nullptr) + std::cerr << "\033[1;31mEndeavourCom::read_reg set m_raw =\033[0m" + << m_raw << std::endl; - // send data - m_raw->sendData(databits, 16); + // send data + m_raw->sendData(databits, 16); - // wait for response ( poll :( ) - uint tryidx=0; - for(tryidx=0;tryidx<TIMEOUT_N;tryidx++) - { - logger(logDEBUG) << "EndeavourCom::read_reg delay "<< TIMEOUT_UNITus<<" microseconds and check the data on amacid " << c_amacid; - std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus)); - if(m_raw->isDataValid()) break; + // wait for response ( poll :( ) + uint tryidx = 0; + for (tryidx = 0; tryidx < TIMEOUT_N; tryidx++) { + logger(logDEBUG) << "EndeavourCom::read_reg delay " << TIMEOUT_UNITus + << " microseconds and check the data on amacid " + << c_amacid; + std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus)); + if (m_raw->isDataValid()) break; } - if(tryidx==TIMEOUT_N) - { - //m_raw.reset(); - throw EndeavourComException("READ timeout"); + if (tryidx == TIMEOUT_N) { + // m_raw.reset(); + throw EndeavourComException("READ timeout"); } - //std::cout << "Recieved READ response after " << tryidx+1 << " tries." << std::endl; - - // Parse the response - unsigned long long int read_data; - unsigned int read_nbits; - m_raw->readData(read_data,read_nbits); - //std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex << read_data << std::dec << std::endl; - m_seqnum++; - - if(read_nbits==49) - { - read_data>>=1; - read_nbits--; + // std::cout << "Recieved READ response after " << tryidx+1 << " tries." << + // std::endl; + + // Parse the response + unsigned long long int read_data; + unsigned int read_nbits; + m_raw->readData(read_data, read_nbits); + // std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex + // << read_data << std::dec << std::endl; + m_seqnum++; + + if (read_nbits == 49) { + read_data >>= 1; + read_nbits--; } - if(read_nbits!=48) - { - //m_raw.reset(); - throw EndeavourComException("READ recieved wrong number of bits: %d (expected 48)",read_nbits); + if (read_nbits != 48) { + // m_raw.reset(); + throw EndeavourComException( + "READ recieved wrong number of bits: %d (expected 48)", read_nbits); } - unsigned int data=read_data&0xFFFFFFFF; + unsigned int data = read_data & 0xFFFFFFFF; - unsigned short int retaddress=(read_data>>32)&0xFF; - if(retaddress!=address) - { - //m_raw.reset(); - throw EndeavourComException("READ recieved wrong address: 0x%08X (expected %08X)",retaddress,address); + unsigned short int retaddress = (read_data >> 32) & 0xFF; + if (retaddress != address) { + // m_raw.reset(); + throw EndeavourComException( + "READ recieved wrong address: 0x%08X (expected %08X)", retaddress, + address); } - unsigned short int seqnum=(read_data>>40)&0b111; - if(m_enableSeqNum && seqnum!=m_seqnum) - { - //m_raw.reset(); - throw EndeavourComException("READ recieved wrong sequence: %d (expected %d)",seqnum,m_seqnum); + unsigned short int seqnum = (read_data >> 40) & 0b111; + if (m_enableSeqNum && seqnum != m_seqnum) { + // m_raw.reset(); + throw EndeavourComException( + "READ recieved wrong sequence: %d (expected %d)", seqnum, m_seqnum); } - unsigned short int amacid=(read_data>>43)&0b11111; - if(amacid!=c_amacid) - { - //m_raw.reset(); - throw EndeavourComException("READ recieved wrong amacid: %d (expected %d)",amacid,c_amacid); + unsigned short int amacid = (read_data >> 43) & 0b11111; + if (amacid != c_amacid) { + // m_raw.reset(); + throw EndeavourComException( + "READ recieved wrong amacid: %d (expected %d)", amacid, c_amacid); } - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "EndeavourCom::read_reg amacid " << c_amacid << " reg " << std::to_string(address) << " time " << diagnostic_time.count() << " us"; + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "EndeavourCom::read_reg amacid " << c_amacid << " reg " + << std::to_string(address) << " time " + << diagnostic_time.count() << " us"; - return data; + return data; } -unsigned int EndeavourCom::readnext_reg(unsigned short c_amacid) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); +unsigned int EndeavourCom::readnext_reg(unsigned short c_amacid) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - unsigned long long int databits=0; + unsigned long long int databits = 0; - //{3'b100, amacid[4:0]} + //{3'b100, amacid[4:0]} - // READNEXT - 3'b100 - databits<<=3; - databits|=0b100; + // READNEXT - 3'b100 + databits <<= 3; + databits |= 0b100; - // amacid[4:0] - databits<<=5; - databits|=(c_amacid&0x1F); + // amacid[4:0] + databits <<= 5; + databits |= (c_amacid & 0x1F); - if (m_raw == nullptr) std::cerr << "\033[1;31mEndeavourCom::readnext_reg set m_raw =\033[0m" << m_raw << std::endl; + if (m_raw == nullptr) + std::cerr << "\033[1;31mEndeavourCom::readnext_reg set m_raw =\033[0m" + << m_raw << std::endl; - // send data - m_raw->sendData(databits, 8); + // send data + m_raw->sendData(databits, 8); - // wait for response ( poll :( ) - uint tryidx=0; - for(tryidx=0;tryidx<TIMEOUT_N;tryidx++) - { - std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus)); - if(m_raw->isDataValid()) break; + // wait for response ( poll :( ) + uint tryidx = 0; + for (tryidx = 0; tryidx < TIMEOUT_N; tryidx++) { + std::this_thread::sleep_for(std::chrono::microseconds(TIMEOUT_UNITus)); + if (m_raw->isDataValid()) break; } - if(tryidx==TIMEOUT_N) - { - //m_raw.reset(); - throw EndeavourComException("READNEXT timeout"); + if (tryidx == TIMEOUT_N) { + // m_raw.reset(); + throw EndeavourComException("READNEXT timeout"); } - // Parse the response - unsigned long long int read_data; - unsigned int read_nbits; - m_raw->readData(read_data,read_nbits); - //std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex << read_data << std::dec << std::endl; - m_seqnum++; - - if(read_nbits==49) - { - read_data>>=1; - read_nbits--; + // Parse the response + unsigned long long int read_data; + unsigned int read_nbits; + m_raw->readData(read_data, read_nbits); + // std::cout << m_raw->isDataValid() << " " << read_nbits << " " << std::hex + // << read_data << std::dec << std::endl; + m_seqnum++; + + if (read_nbits == 49) { + read_data >>= 1; + read_nbits--; } - if(read_nbits!=48) - { - //m_raw.reset(); - throw EndeavourComException("READNEXT recieved wrong number of bits: %d (expected 48)",read_nbits); + if (read_nbits != 48) { + // m_raw.reset(); + throw EndeavourComException( + "READNEXT recieved wrong number of bits: %d (expected 48)", + read_nbits); } - unsigned int data=read_data&0xFFFFFFFF; + unsigned int data = read_data & 0xFFFFFFFF; - //unsigned short int retaddress=(read_data>>32)&0xFF; + // unsigned short int retaddress=(read_data>>32)&0xFF; - unsigned short int seqnum=(read_data>>40)&0b111; - if(m_enableSeqNum && seqnum!=m_seqnum) - { - //m_raw.reset(); - throw EndeavourComException("READNEXT recieved wrong sequence: %d (expected %d)",seqnum,m_seqnum); + unsigned short int seqnum = (read_data >> 40) & 0b111; + if (m_enableSeqNum && seqnum != m_seqnum) { + // m_raw.reset(); + throw EndeavourComException( + "READNEXT recieved wrong sequence: %d (expected %d)", seqnum, + m_seqnum); } - unsigned short int amacid=(read_data>>43)&0b11111; - if(amacid!=c_amacid) - { - //m_raw.reset(); - throw EndeavourComException("READ recieved wrong amacid: %d (expected %d)",amacid,c_amacid); + unsigned short int amacid = (read_data >> 43) & 0b11111; + if (amacid != c_amacid) { + // m_raw.reset(); + throw EndeavourComException( + "READ recieved wrong amacid: %d (expected %d)", amacid, c_amacid); } - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "EndeavourCom::readnext_reg amacid " << c_amacid << " " << " time " << diagnostic_time.count() << " us"; + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "EndeavourCom::readnext_reg amacid " << c_amacid + << " " + << " time " << diagnostic_time.count() << " us"; - return data; + return data; } -unsigned int EndeavourCom::calc_crc(unsigned long long int data) const -{ - unsigned crc=0; - for(unsigned int i=0;i<8;i++) - { - crc|=(( ((data>>(8*0+i))&1) ^ - ((data>>(8*1+i))&1) ^ - ((data>>(8*2+i))&1) ^ - ((data>>(8*3+i))&1) ^ - ((data>>(8*4+i))&1) ^ - ((data>>(8*5+i))&1) )<<i); +unsigned int EndeavourCom::calc_crc(unsigned long long int data) const { + unsigned crc = 0; + for (unsigned int i = 0; i < 8; i++) { + crc |= ((((data >> (8 * 0 + i)) & 1) ^ ((data >> (8 * 1 + i)) & 1) ^ + ((data >> (8 * 2 + i)) & 1) ^ ((data >> (8 * 3 + i)) & 1) ^ + ((data >> (8 * 4 + i)) & 1) ^ ((data >> (8 * 5 + i)) & 1)) + << i); } - return crc; + return crc; } diff --git a/pbv3/EndeavourCom.h b/pbv3/EndeavourCom.h index 84d24fe7f7b26c945d39d90a6ce67ec1ce6d6d55..23135536e60cf622ff0cdcb9123577d9669a0154 100644 --- a/pbv3/EndeavourCom.h +++ b/pbv3/EndeavourCom.h @@ -7,63 +7,70 @@ #include "DeviceCom.h" #include "EndeavourRaw.h" -class EndeavourCom // : public DeviceCom +class EndeavourCom // : public DeviceCom { -public: - enum REFMODE {IDPads, EfuseId}; + public: + enum REFMODE { IDPads, EfuseId }; - EndeavourCom() {}; - EndeavourCom(unsigned short amacid, std::shared_ptr<EndeavourRaw> raw); - EndeavourCom(unsigned short amacid, std::unique_ptr<EndeavourRaw> raw); - EndeavourCom(unsigned short amacid, bool use_icnetio, std::string config_file, bool dontWaitReply=false); + EndeavourCom(){}; + EndeavourCom(unsigned short amacid, std::shared_ptr<EndeavourRaw> raw); + EndeavourCom(unsigned short amacid, std::unique_ptr<EndeavourRaw> raw); + EndeavourCom(unsigned short amacid, bool use_icnetio, + std::string config_file, bool dontWaitReply = false); - const std::shared_ptr<EndeavourRaw>& raw(); - void reset_raw(std::shared_ptr<EndeavourRaw> raw) {m_raw.reset(); m_raw = raw;}; - void reset_raw(bool use_icnetio, std::string config_file); + const std::shared_ptr<EndeavourRaw>& raw(); + void reset_raw(std::shared_ptr<EndeavourRaw> raw) { + m_raw.reset(); + m_raw = raw; + }; + void reset_raw(bool use_icnetio, std::string config_file); - void enableSeqNum(bool enableSeqNum); + void enableSeqNum(bool enableSeqNum); - //! \brief connect the EndeavourRaw backend - virtual void connect() {m_raw-> connect();}; - //! \brief disconnect the EndeavourRaw backend - virtual void disconnect() {m_raw-> disconnect();}; + //! \brief connect the EndeavourRaw backend + virtual void connect() { m_raw->connect(); }; + //! \brief disconnect the EndeavourRaw backend + virtual void disconnect() { m_raw->disconnect(); }; - void reset(); + void reset(); - void _set_amacid(unsigned short amacid); - //unsigned short _get_amacid() {return m_amacid;}; + void _set_amacid(unsigned short amacid); + // unsigned short _get_amacid() {return m_amacid;}; - // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw - //virtual void setid(REFMODE mode, unsigned int refid); - virtual void setid(unsigned short amacid, REFMODE mode, unsigned int refid); + // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw + // virtual void setid(REFMODE mode, unsigned int refid); + virtual void setid(unsigned short amacid, REFMODE mode, unsigned int refid); - virtual void write_reg(unsigned short amacid, unsigned int address, unsigned int data); - virtual unsigned int read_reg(unsigned short amacid, unsigned int address); - virtual unsigned int readnext_reg(unsigned short amacid); + virtual void write_reg(unsigned short amacid, unsigned int address, + unsigned int data); + virtual unsigned int read_reg(unsigned short amacid, unsigned int address); + virtual unsigned int readnext_reg(unsigned short amacid); - //implemented in DeviceCom // <- TODO remove these?? - virtual void write_reg(std::vector<unsigned int> data_vec){}; - virtual void write_data(uint8_t data){}; + // implemented in DeviceCom // <- TODO remove these?? + virtual void write_reg(std::vector<unsigned int> data_vec){}; + virtual void write_data(uint8_t data){}; - virtual void read_reg(unsigned int address, uint8_t* data, unsigned int len){}; - virtual void read_reg(uint8_t* data_in, uint8_t* data_out, unsigned int len){}; + virtual void read_reg(unsigned int address, uint8_t* data, + unsigned int len){}; + virtual void read_reg(uint8_t* data_in, uint8_t* data_out, + unsigned int len){}; - // the basic parameters of the commandline backend - // let's just keep them here for simplicity for now - // later it will probably turn into the addresses of m_raw - std::string m_paths = "endeavour"; - int m_channel = 0; + // the basic parameters of the commandline backend + // let's just keep them here for simplicity for now + // later it will probably turn into the addresses of m_raw + std::string m_paths = "endeavour"; + int m_channel = 0; -private: - //unsigned short m_amacid; + private: + // unsigned short m_amacid; - bool m_enableSeqNum =false; - unsigned short m_seqnum =0; + bool m_enableSeqNum = false; + unsigned short m_seqnum = 0; - std::shared_ptr<EndeavourRaw> m_raw; - std::string m_config_file = "/opt/atlas/etc/cfg_endeavour.json"; + std::shared_ptr<EndeavourRaw> m_raw; + std::string m_config_file = "/opt/atlas/etc/cfg_endeavour.json"; - unsigned int calc_crc(unsigned long long int data) const; + unsigned int calc_crc(unsigned long long int data) const; }; -#endif //ENDEAVOURCOM_H +#endif // ENDEAVOURCOM_H diff --git a/pbv3/EndeavourComComline.cpp b/pbv3/EndeavourComComline.cpp index 0609ede5dd3abe5b81ee86e2cd9606080e97bd1c..73bd329a1e0fe70956fea5a2ecdb1e626a0fda07 100644 --- a/pbv3/EndeavourComComline.cpp +++ b/pbv3/EndeavourComComline.cpp @@ -1,225 +1,236 @@ #include "EndeavourComComline.h" -#include "EndeavourComException.h" #include <Logger.h> +#include <chrono> #include <cstring> #include <vector> -#include <chrono> + +#include "EndeavourComException.h" using Clock = std::chrono::steady_clock; -EndeavourComComline::EndeavourComComline(std::string paths, int channel) -{ - m_paths = paths; - m_channel = channel; +EndeavourComComline::EndeavourComComline(std::string paths, int channel) { + m_paths = paths; + m_channel = channel; } -void EndeavourComComline:: connect() {;}; -void EndeavourComComline::disconnect() {;}; +void EndeavourComComline::connect() { ; }; +void EndeavourComComline::disconnect() { ; }; // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw -//virtual void setid(REFMODE mode, unsigned int refid); - -void EndeavourComComline::setid(unsigned short amacid, EndeavourCom::REFMODE mode, unsigned int refid) -{ - std::string setid_mode_code = "setid_bond"; - if (mode != EndeavourCom::REFMODE::IDPads) - {setid_mode_code = "setid_fuse";} - //{setID_bond(amacid, refid);} - //else - //{setID_fuse(amacid, refid);} - logger(logDEBUG) << "EndeavourComComline::setid " << m_channel << " " << amacid << ": " << setid_mode_code << " " << mode << " " << refid; - - // - snprintf(temp_command, sizeof(temp_command), - "%s --channel %d %s %d %d", - m_paths.c_str(), m_channel, setid_mode_code.c_str(), - amacid, refid); - std::cerr<<"EndeavourComComline::setid command setit = "<<temp_command<<std::endl; //the final command - - FILE *pipe; // pipe declared to use popen command - pipe = popen(temp_command, "r"); - - /* - // dump the contents of the pipe (otherwise it prints everything to stdout - // and parse into tokens - char readbuf[100]; - std::vector<char*> field_vect; - if (pipe == NULL) - { - perror("ERROR, EndeavourComComline::read_reg"); - //return {.status=2, .val=0}; - throw EndeavourComException("EndeavourComComline::read_reg could not call commandline"); - } - - else - { - while(!feof(pipe)) // for some reason - { - if(fgets(readbuf, 100, pipe) == NULL) - field_vect.push_back(readbuf); - } - } - - std::vector <std::string> tokens={}; - std::stringstream ss(field_vect[0]); - std::string intermediate; - - //std::cerr << "EndeavourComComline::read_reg parsed tokens:"; - while(getline(ss, intermediate, ' ')) - { - //std::cerr << " " << intermediate; - tokens.push_back(intermediate); - } - //std::cerr << std::endl; - */ - // tokens are not used here yet -- it seems there is no way to distinguish whether setid failed or no here - - pclose(pipe); +// virtual void setid(REFMODE mode, unsigned int refid); + +void EndeavourComComline::setid(unsigned short amacid, + EndeavourCom::REFMODE mode, + unsigned int refid) { + std::string setid_mode_code = "setid_bond"; + if (mode != EndeavourCom::REFMODE::IDPads) { + setid_mode_code = "setid_fuse"; + } + //{setID_bond(amacid, refid);} + // else + //{setID_fuse(amacid, refid);} + logger(logDEBUG) << "EndeavourComComline::setid " << m_channel << " " + << amacid << ": " << setid_mode_code << " " << mode << " " + << refid; + + // + snprintf(temp_command, sizeof(temp_command), "%s --channel %d %s %d %d", + m_paths.c_str(), m_channel, setid_mode_code.c_str(), amacid, + refid); + std::cerr << "EndeavourComComline::setid command setit = " << temp_command + << std::endl; // the final command + + FILE *pipe; // pipe declared to use popen command + pipe = popen(temp_command, "r"); + + /* + // dump the contents of the pipe (otherwise it prints everything to stdout + // and parse into tokens + char readbuf[100]; + std::vector<char*> field_vect; + if (pipe == NULL) + { + perror("ERROR, EndeavourComComline::read_reg"); + //return {.status=2, .val=0}; + throw EndeavourComException("EndeavourComComline::read_reg could not + call commandline"); + } + + else + { + while(!feof(pipe)) // for some reason + { + if(fgets(readbuf, 100, pipe) == NULL) + field_vect.push_back(readbuf); + } + } + + std::vector <std::string> tokens={}; + std::stringstream ss(field_vect[0]); + std::string intermediate; + + //std::cerr << "EndeavourComComline::read_reg parsed tokens:"; + while(getline(ss, intermediate, ' ')) + { + //std::cerr << " " << intermediate; + tokens.push_back(intermediate); + } + //std::cerr << std::endl; + */ + // tokens are not used here yet -- it seems there is no way to distinguish + // whether setid failed or no here + + pclose(pipe); } -struct amac_return_statusOnly EndeavourComComline::setID_fuse(unsigned short amacid, unsigned int fuse_val) -{ - setid(amacid, EndeavourCom::REFMODE::EfuseId, fuse_val); - logger(logDEBUG) << "EndeavourComComline::setID_fuse " << amacid << " " << fuse_val; - return {0}; +struct amac_return_statusOnly EndeavourComComline::setID_fuse( + unsigned short amacid, unsigned int fuse_val) { + setid(amacid, EndeavourCom::REFMODE::EfuseId, fuse_val); + logger(logDEBUG) << "EndeavourComComline::setID_fuse " << amacid << " " + << fuse_val; + return {0}; } -struct amac_return_statusOnly EndeavourComComline::setID_bond(unsigned short amacid, unsigned int bond_val) -{ - setid(amacid, EndeavourCom::REFMODE::IDPads, bond_val); - logger(logDEBUG) << "EndeavourComComline::setID_bond " << amacid << " " << bond_val; - //throw EndeavourComException("EndeavourComComline::read_reg failed" + std::to_string(m_channel) + " " std::to_string(amacid)); - return {0}; +struct amac_return_statusOnly EndeavourComComline::setID_bond( + unsigned short amacid, unsigned int bond_val) { + setid(amacid, EndeavourCom::REFMODE::IDPads, bond_val); + logger(logDEBUG) << "EndeavourComComline::setID_bond " << amacid << " " + << bond_val; + // throw EndeavourComException("EndeavourComComline::read_reg failed" + + // std::to_string(m_channel) + " " std::to_string(amacid)); + return {0}; } -//virtual void write_reg(unsigned short amacid, unsigned int address, unsigned int data); -//struct amac_return_statusOnly writeReg(unsigned int reg_num, unsigned int val_num) -void EndeavourComComline::write_reg(unsigned short amacid, unsigned int reg_num, unsigned int reg_val) -{ - logger(logDEBUG) << "EndeavourComComline::write_reg " << amacid << " " << reg_num << " " << reg_val; - - snprintf(temp_command, sizeof(temp_command), - //"%s --channel %s write %d %s 0x%s", - "%s --channel %d write %d %d %d", - m_paths.c_str(), m_channel, - amacid, reg_num, reg_val); - // MWMW debug - //command = '/home/ITkDAQ/AMAC/itsdaq-sw-AMACv2_test_master_final/bin/endeavourTest --ip 192.168.222.25 --channel 15 write 1 46 99'; - //std::cerr<<"writeReg: MWMW debug "<<m_channel<<std::endl; - std::cerr << "EndeavourComComline::write_reg writeReg: command = "<<temp_command<<std::endl; //the final command - - FILE *pipe; - pipe = popen(temp_command, "r"); - - char readbuf[100]; - std::vector<char*> field_vect; - if (pipe == NULL) - { - perror("ERROR, EndeavourComComline::write_reg"); - //return {.status=2, .val=0}; - throw EndeavourComException("EndeavourComComline::write_reg could not call commandline"); - return; - } - - else - { - while(!feof(pipe)) - { - if(fgets(readbuf, 100, pipe) == NULL) - field_vect.push_back(readbuf); - } - } - - pclose(pipe); - std::cerr << "EndeavourComComline::write_reg done" << std::endl; +// virtual void write_reg(unsigned short amacid, unsigned int address, unsigned +// int data); struct amac_return_statusOnly writeReg(unsigned int reg_num, +// unsigned int val_num) +void EndeavourComComline::write_reg(unsigned short amacid, unsigned int reg_num, + unsigned int reg_val) { + logger(logDEBUG) << "EndeavourComComline::write_reg " << amacid << " " + << reg_num << " " << reg_val; + + snprintf(temp_command, sizeof(temp_command), + //"%s --channel %s write %d %s 0x%s", + "%s --channel %d write %d %d %d", m_paths.c_str(), m_channel, + amacid, reg_num, reg_val); + // MWMW debug + // command = + // '/home/ITkDAQ/AMAC/itsdaq-sw-AMACv2_test_master_final/bin/endeavourTest + // --ip 192.168.222.25 --channel 15 write 1 46 99'; std::cerr<<"writeReg: + // MWMW debug "<<m_channel<<std::endl; + std::cerr << "EndeavourComComline::write_reg writeReg: command = " + << temp_command << std::endl; // the final command + + FILE *pipe; + pipe = popen(temp_command, "r"); + + char readbuf[100]; + std::vector<char *> field_vect; + if (pipe == NULL) { + perror("ERROR, EndeavourComComline::write_reg"); + // return {.status=2, .val=0}; + throw EndeavourComException( + "EndeavourComComline::write_reg could not call commandline"); + return; + } + + else { + while (!feof(pipe)) { + if (fgets(readbuf, 100, pipe) == NULL) + field_vect.push_back(readbuf); + } + } + + pclose(pipe); + std::cerr << "EndeavourComComline::write_reg done" << std::endl; } -//virtual unsigned int read_reg(unsigned short amacid, unsigned int address); -//struct amac_return_statusNlongint readReg(unsigned int reg_num) -unsigned int EndeavourComComline::read_reg(unsigned short amacid, unsigned int reg_num) -{ - logger(logDEBUG) << "EndeavourComComline::read_reg " << amacid << " " << reg_num; - - snprintf(temp_command, sizeof(temp_command), - "%s --channel %d read %d %d", - m_paths.c_str(), m_channel, - amacid, reg_num); - // MWMW debug - //command = '/home/ITkDAQ/AMAC/itsdaq-sw-AMACv2_test_master_final/bin/endeavourTest --ip 192.168.222.25 --channel 15 read 1 46'; - logger(logDEBUG) <<"EndeavourComComline::read_reg command = "<<temp_command; //the final command - //std::cerr <<"EndeavourComComline::read_reg command = "<<temp_command <<std::endl; - // TODO: switch to logger - // logger(logDEBUG) << "AMACv2::circuit_set " << param << " to " << std::to_string(value); - - FILE *pipe; - pipe = popen(temp_command, "r"); - - char readbuf[100]; - std::vector<char*> field_vect; - if (pipe == NULL) - { - perror("ERROR, EndeavourComComline::read_reg"); - //return {.status=2, .val=0}; - throw EndeavourComException("EndeavourComComline::read_reg could not call commandline"); - return 0; - } - - else - { - while(!feof(pipe)) - { - if(fgets(readbuf, 100, pipe) == NULL) - field_vect.push_back(readbuf); - } - } - - std::vector <std::string> tokens={}; - std::stringstream ss(field_vect[0]); - std::string intermediate; - - //std::cerr << "EndeavourComComline::read_reg parsed tokens:"; - while(getline(ss, intermediate, ' ')) - { - //std::cerr << " " << intermediate; - tokens.push_back(intermediate); - } - //std::cerr << std::endl; - - std::string regvalue(""); - for (int i=0; i<tokens.size(); i++) - { - if (tokens[i]=="val") - { - regvalue = tokens[i+1]; - } - } - - pclose(pipe); - - long unsigned int val = 99999; - if (tokens.back() == "done\n") - { - val = std::stoll(regvalue); - logger(logDEBUG) << "\033[1;31mEndeavourComComline::read_reg done\033[0m " << m_channel << " " << amacid << " " << reg_num << " = " << val; - } - - else - { - throw EndeavourComException("EndeavourComComline::read_reg failed bus=" + std::to_string(m_channel) + " amacid=" + std::to_string(amacid)); - } - - field_vect.clear(); - tokens.clear(); - //return {.status=0, .val=val}; - return val; +// virtual unsigned int read_reg(unsigned short amacid, unsigned int address); +// struct amac_return_statusNlongint readReg(unsigned int reg_num) +unsigned int EndeavourComComline::read_reg(unsigned short amacid, + unsigned int reg_num) { + logger(logDEBUG) << "EndeavourComComline::read_reg " << amacid << " " + << reg_num; + + snprintf(temp_command, sizeof(temp_command), "%s --channel %d read %d %d", + m_paths.c_str(), m_channel, amacid, reg_num); + // MWMW debug + // command = + // '/home/ITkDAQ/AMAC/itsdaq-sw-AMACv2_test_master_final/bin/endeavourTest + // --ip 192.168.222.25 --channel 15 read 1 46'; + logger(logDEBUG) << "EndeavourComComline::read_reg command = " + << temp_command; // the final command + // std::cerr <<"EndeavourComComline::read_reg command = "<<temp_command + // <<std::endl; + // TODO: switch to logger + // logger(logDEBUG) << "AMACv2::circuit_set " << param << " to " << + // std::to_string(value); + + FILE *pipe; + pipe = popen(temp_command, "r"); + + char readbuf[100]; + std::vector<char *> field_vect; + if (pipe == NULL) { + perror("ERROR, EndeavourComComline::read_reg"); + // return {.status=2, .val=0}; + throw EndeavourComException( + "EndeavourComComline::read_reg could not call commandline"); + return 0; + } + + else { + while (!feof(pipe)) { + if (fgets(readbuf, 100, pipe) == NULL) + field_vect.push_back(readbuf); + } + } + + std::vector<std::string> tokens = {}; + std::stringstream ss(field_vect[0]); + std::string intermediate; + + // std::cerr << "EndeavourComComline::read_reg parsed tokens:"; + while (getline(ss, intermediate, ' ')) { + // std::cerr << " " << intermediate; + tokens.push_back(intermediate); + } + // std::cerr << std::endl; + + std::string regvalue(""); + for (int i = 0; i < tokens.size(); i++) { + if (tokens[i] == "val") { + regvalue = tokens[i + 1]; + } + } + + pclose(pipe); + + long unsigned int val = 99999; + if (tokens.back() == "done\n") { + val = std::stoll(regvalue); + logger(logDEBUG) + << "\033[1;31mEndeavourComComline::read_reg done\033[0m " + << m_channel << " " << amacid << " " << reg_num << " = " << val; + } + + else { + throw EndeavourComException( + "EndeavourComComline::read_reg failed bus=" + + std::to_string(m_channel) + " amacid=" + std::to_string(amacid)); + } + + field_vect.clear(); + tokens.clear(); + // return {.status=0, .val=val}; + return val; } -unsigned int EndeavourComComline::readnext_reg(unsigned short amacid) -{ - logger(logDEBUG) << "EndeavourComComline::readnext_reg " << amacid; - throw EndeavourComException("EndeavourComComline::readnext_reg is not implemented yet!"); +unsigned int EndeavourComComline::readnext_reg(unsigned short amacid) { + logger(logDEBUG) << "EndeavourComComline::readnext_reg " << amacid; + throw EndeavourComException( + "EndeavourComComline::readnext_reg is not implemented yet!"); - return 0; + return 0; } - diff --git a/pbv3/EndeavourComComline.h b/pbv3/EndeavourComComline.h index 5c6111b2954daa95186558d2a059ad0c5b00f221..877ec43cbdc1caf44bc8cbe0316a3a88ce0f5f43 100644 --- a/pbv3/EndeavourComComline.h +++ b/pbv3/EndeavourComComline.h @@ -7,61 +7,67 @@ #include <memory> //#include "DeviceCom.h" +#include <stdio.h> // FILE, popen + #include "EndeavourCom.h" #include "EndeavourRaw.h" -#include <stdio.h> // FILE, popen // the return values from the communication utilities struct amac_return_statusOnly { - int status; + int status; }; struct amac_return_statusNlongint { - int status; - long int val; + int status; + long int val; }; -class EndeavourComComline : public EndeavourCom -{ -public: - enum REFMODE {IDPads, EfuseId}; +class EndeavourComComline : public EndeavourCom { + public: + enum REFMODE { IDPads, EfuseId }; - //EndeavourCom(unsigned short amacid, std::shared_ptr<EndeavourRaw> raw); - EndeavourComComline(void) {}; - EndeavourComComline(std::string paths, int channel); + // EndeavourCom(unsigned short amacid, std::shared_ptr<EndeavourRaw> raw); + EndeavourComComline(void){}; + EndeavourComComline(std::string paths, int channel); - const std::shared_ptr<EndeavourRaw>& raw(); + const std::shared_ptr<EndeavourRaw>& raw(); - void reset() {;}; - void connect(void); - void disconnect(void); + void reset() { ; }; + void connect(void); + void disconnect(void); - //void enableSeqNum(bool enableSeqNum); + // void enableSeqNum(bool enableSeqNum); - // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw - //virtual void setid(REFMODE mode, unsigned int refid); - void setid(unsigned short amacid, EndeavourCom::REFMODE mode, unsigned int refid); + // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw + // virtual void setid(REFMODE mode, unsigned int refid); + void setid(unsigned short amacid, EndeavourCom::REFMODE mode, + unsigned int refid); - void write_reg(unsigned short amacid, unsigned int address, unsigned int data); - unsigned int read_reg(unsigned short amacid, unsigned int address); - unsigned int readnext_reg(unsigned short amacid); + void write_reg(unsigned short amacid, unsigned int address, + unsigned int data); + unsigned int read_reg(unsigned short amacid, unsigned int address); + unsigned int readnext_reg(unsigned short amacid); -protected: - struct amac_return_statusOnly setID_fuse(unsigned short amacid, unsigned int fuse_val); - struct amac_return_statusOnly setID_bond(unsigned short amacid, unsigned int bond_val); - //unsigned short m_amacid; + protected: + struct amac_return_statusOnly setID_fuse(unsigned short amacid, + unsigned int fuse_val); + struct amac_return_statusOnly setID_bond(unsigned short amacid, + unsigned int bond_val); + // unsigned short m_amacid; - //bool m_enableSeqNum =false; - //unsigned short m_seqnum =0; + // bool m_enableSeqNum =false; + // unsigned short m_seqnum =0; - std::shared_ptr<EndeavourRaw> m_raw = nullptr; + std::shared_ptr<EndeavourRaw> m_raw = nullptr; - //unsigned int calc_crc(unsigned long long int data) const; + // unsigned int calc_crc(unsigned long long int data) const; - // parameters of the ITSDAQ' endeavourTest - //command = '/home/ITkDAQ/AMAC/itsdaq-sw-AMACv2_test_master_final/bin/endeavourTest --ip 192.168.222.25 --channel 15 setid_bond 1 1'; - //command = '<paths> --channel <channel_temp> setid_bond <arg amacid> <arg bondid> - char temp_command[512]; //the final command line + // parameters of the ITSDAQ' endeavourTest + // command = + // '/home/ITkDAQ/AMAC/itsdaq-sw-AMACv2_test_master_final/bin/endeavourTest + // --ip 192.168.222.25 --channel 15 setid_bond 1 1'; command = '<paths> + // --channel <channel_temp> setid_bond <arg amacid> <arg bondid> + char temp_command[512]; // the final command line }; -#endif //ENDEAVOURCOMCOMLINE_H +#endif // ENDEAVOURCOMCOMLINE_H diff --git a/pbv3/EndeavourComComline2.cpp b/pbv3/EndeavourComComline2.cpp index 542d4d589430d6e75980795b5c7d90e9a85f31cb..a815c9f283500421ca019fccddd3fc6f392c902e 100644 --- a/pbv3/EndeavourComComline2.cpp +++ b/pbv3/EndeavourComComline2.cpp @@ -1,148 +1,156 @@ #include "EndeavourComComline2.h" -#include "EndeavourComException.h" #include <Logger.h> +#include <chrono> #include <cstring> #include <vector> -#include <chrono> + +#include "EndeavourComException.h" using Clock = std::chrono::steady_clock; -EndeavourComComline2::EndeavourComComline2(std::string paths) -{ - m_paths = paths; +EndeavourComComline2::EndeavourComComline2(std::string paths) { + m_paths = paths; } // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw -//virtual void setid(REFMODE mode, unsigned int refid); +// virtual void setid(REFMODE mode, unsigned int refid); -struct amac_return_statusOnly EndeavourComComline2::setID_fuse(unsigned short amacid, unsigned int fuse_val) -{ - logger(logDEBUG) << "EndeavourComComline2::setID_fuse " << amacid << " " << fuse_val; +struct amac_return_statusOnly EndeavourComComline2::setID_fuse( + unsigned short amacid, unsigned int fuse_val) { + logger(logDEBUG) << "EndeavourComComline2::setID_fuse " << amacid << " " + << fuse_val; - // - // the commandline call - snprintf(temp_command, sizeof(temp_command), - "%s -i %d setid efuse %d", - m_paths.c_str(), amacid, fuse_val); - std::cerr<<"setID_fuse: command = " << temp_command << std::endl; //the final command + // + // the commandline call + snprintf(temp_command, sizeof(temp_command), "%s -i %d setid efuse %d", + m_paths.c_str(), amacid, fuse_val); + std::cerr << "setID_fuse: command = " << temp_command + << std::endl; // the final command - FILE *pipe; // pipe declared to use popen command - pipe = popen(temp_command,"w"); - pclose(pipe); + FILE *pipe; // pipe declared to use popen command + pipe = popen(temp_command, "w"); + pclose(pipe); - return {0}; + return {0}; } -struct amac_return_statusOnly EndeavourComComline2::setID_bond(unsigned short amacid, unsigned int bond_val) -{ - logger(logDEBUG) << "EndeavourComComline2::setID_bond " << amacid << " " << bond_val; +struct amac_return_statusOnly EndeavourComComline2::setID_bond( + unsigned short amacid, unsigned int bond_val) { + logger(logDEBUG) << "EndeavourComComline2::setID_bond " << amacid << " " + << bond_val; - snprintf(temp_command, sizeof(temp_command), - "%s -i %d setid idpads %d", - m_paths.c_str(), amacid, bond_val); - std::cerr<<"setID_bond: command = " << temp_command << std::endl; //the final command + snprintf(temp_command, sizeof(temp_command), "%s -i %d setid idpads %d", + m_paths.c_str(), amacid, bond_val); + std::cerr << "setID_bond: command = " << temp_command + << std::endl; // the final command - // - // capture the output - FILE *pipe; - pipe = popen(temp_command, "r"); - pclose(pipe); + // + // capture the output + FILE *pipe; + pipe = popen(temp_command, "r"); + pclose(pipe); - return {0}; + return {0}; } -//virtual void write_reg(unsigned short amacid, unsigned int address, unsigned int data); -//struct amac_return_statusOnly writeReg(unsigned int reg_num, unsigned int val_num) -void EndeavourComComline2::write_reg(unsigned short amacid, unsigned int reg_num, unsigned int reg_val) -{ - logger(logDEBUG) << "EndeavourComComline2::write_reg " << amacid << " " << reg_num << " " << reg_val; - - // - // the commandline call - snprintf(temp_command, sizeof(temp_command), - "%s -i %d write %d %d 2> /dev/null", - m_paths.c_str(), amacid, reg_num, reg_val); - - std::cerr<<"writeReg: command = "<<temp_command<<std::endl; //the final command - - FILE *pipe; - pipe = popen(temp_command,"w"); - pclose(pipe); +// virtual void write_reg(unsigned short amacid, unsigned int address, unsigned +// int data); struct amac_return_statusOnly writeReg(unsigned int reg_num, +// unsigned int val_num) +void EndeavourComComline2::write_reg(unsigned short amacid, + unsigned int reg_num, + unsigned int reg_val) { + logger(logDEBUG) << "EndeavourComComline2::write_reg " << amacid << " " + << reg_num << " " << reg_val; + + // + // the commandline call + snprintf(temp_command, sizeof(temp_command), + "%s -i %d write %d %d 2> /dev/null", m_paths.c_str(), amacid, + reg_num, reg_val); + + std::cerr << "writeReg: command = " << temp_command + << std::endl; // the final command + + FILE *pipe; + pipe = popen(temp_command, "w"); + pclose(pipe); } -//virtual unsigned int read_reg(unsigned short amacid, unsigned int address); -//struct amac_return_statusNlongint readReg(unsigned int reg_num) -unsigned int EndeavourComComline2::read_reg(unsigned short amacid, unsigned int reg_num) -{ - logger(logDEBUG) << "EndeavourComComline2::read_reg " << amacid << " " << reg_num; - - // - // the commandline call - snprintf(temp_command, sizeof(temp_command), - "%s -i %d read %d 2> /dev/null", // FIXME: check if powertools understands decimal register IDs - m_paths.c_str(), amacid, reg_num); - - std::cerr<<"readReg: command = "<<temp_command<<std::endl; //the final command - - FILE *pipe; - pipe = popen(temp_command, "r"); - - char readbuf[100]; - std::vector<char*> field_vect; - if (pipe == NULL) - { - perror("ERROR, AMACInterface_ITSDAQCommandline::readReg"); - //return {.status=2, .val=0}; - throw EndeavourComException("EndeavourComComline2::read_reg could not call commandline"); - return 0; - } - - else - { - while(!feof(pipe)) - { - if(fgets(readbuf, 100, pipe) == NULL) - field_vect.push_back(readbuf); - } - } - - logger(logDEBUG) << "EndeavourComComline2::read_reg got " << readbuf; - - // tokenize the read output - std::vector <std::string> tokens={}; - std::stringstream ss(field_vect[0]); - std::string intermediate; - - while(getline(ss, intermediate, ' ')) - {tokens.push_back(intermediate);} - - char regvalue[10]; - for (int i=0; i<tokens.size(); i++) - { - if (tokens[i]=="val") - {strncpy(regvalue, (tokens[i+1]).c_str(), sizeof(regvalue)); - std::cerr<<"readReg: value = "<<regvalue<<std::endl;} - } - - std::stringstream val_str(regvalue); - long unsigned int val =0.; - - val_str>>val; - - pclose(pipe); - - field_vect.clear(); - tokens.clear(); - //return {.status=0, .val=val}; - return val; +// virtual unsigned int read_reg(unsigned short amacid, unsigned int address); +// struct amac_return_statusNlongint readReg(unsigned int reg_num) +unsigned int EndeavourComComline2::read_reg(unsigned short amacid, + unsigned int reg_num) { + logger(logDEBUG) << "EndeavourComComline2::read_reg " << amacid << " " + << reg_num; + + // + // the commandline call + snprintf( + temp_command, sizeof(temp_command), + "%s -i %d read %d 2> /dev/null", // FIXME: check if powertools + // understands decimal register IDs + m_paths.c_str(), amacid, reg_num); + + std::cerr << "readReg: command = " << temp_command + << std::endl; // the final command + + FILE *pipe; + pipe = popen(temp_command, "r"); + + char readbuf[100]; + std::vector<char *> field_vect; + if (pipe == NULL) { + perror("ERROR, AMACInterface_ITSDAQCommandline::readReg"); + // return {.status=2, .val=0}; + throw EndeavourComException( + "EndeavourComComline2::read_reg could not call commandline"); + return 0; + } + + else { + while (!feof(pipe)) { + if (fgets(readbuf, 100, pipe) == NULL) + field_vect.push_back(readbuf); + } + } + + logger(logDEBUG) << "EndeavourComComline2::read_reg got " << readbuf; + + // tokenize the read output + std::vector<std::string> tokens = {}; + std::stringstream ss(field_vect[0]); + std::string intermediate; + + while (getline(ss, intermediate, ' ')) { + tokens.push_back(intermediate); + } + + char regvalue[10]; + for (int i = 0; i < tokens.size(); i++) { + if (tokens[i] == "val") { + strncpy(regvalue, (tokens[i + 1]).c_str(), sizeof(regvalue)); + std::cerr << "readReg: value = " << regvalue << std::endl; + } + } + + std::stringstream val_str(regvalue); + long unsigned int val = 0.; + + val_str >> val; + + pclose(pipe); + + field_vect.clear(); + tokens.clear(); + // return {.status=0, .val=val}; + return val; } -unsigned int EndeavourComComline2::readnext_reg(unsigned short amacid) -{ - logger(logDEBUG) << "EndeavourComComline2::readnext_reg " << amacid; - throw EndeavourComException("EndeavourComComline2::readnext_reg is not implemented yet!"); +unsigned int EndeavourComComline2::readnext_reg(unsigned short amacid) { + logger(logDEBUG) << "EndeavourComComline2::readnext_reg " << amacid; + throw EndeavourComException( + "EndeavourComComline2::readnext_reg is not implemented yet!"); - return 0; + return 0; } - diff --git a/pbv3/EndeavourComComline2.h b/pbv3/EndeavourComComline2.h index 14083ebc99d5268222b359fae4e3360aded961a4..9d83331b6d6f1d35173aa00a1db0f323d75db932 100644 --- a/pbv3/EndeavourComComline2.h +++ b/pbv3/EndeavourComComline2.h @@ -8,25 +8,28 @@ #include "EndeavourComComline.h" -class EndeavourComComline2 : public EndeavourComComline -{ -public: - EndeavourComComline2(std::string paths); - - //void enableSeqNum(bool enableSeqNum); - void connect() {;}; - void disconnect() {;}; - - // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw - //void setid(unsigned short amacid, EndeavourCom::REFMODE mode, unsigned int refid); - - void write_reg(unsigned short amacid, unsigned int address, unsigned int data); - unsigned int read_reg(unsigned short amacid, unsigned int address); - unsigned int readnext_reg(unsigned short amacid); - -protected: - struct amac_return_statusOnly setID_fuse(unsigned short amacid, unsigned int fuse_val); - struct amac_return_statusOnly setID_bond(unsigned short amacid, unsigned int bond_val); +class EndeavourComComline2 : public EndeavourComComline { + public: + EndeavourComComline2(std::string paths); + + // void enableSeqNum(bool enableSeqNum); + void connect() { ; }; + void disconnect() { ; }; + + // HW calls to implement, if inherited, otherwise - calls to EndeavourRaw + // void setid(unsigned short amacid, EndeavourCom::REFMODE mode, unsigned + // int refid); + + void write_reg(unsigned short amacid, unsigned int address, + unsigned int data); + unsigned int read_reg(unsigned short amacid, unsigned int address); + unsigned int readnext_reg(unsigned short amacid); + + protected: + struct amac_return_statusOnly setID_fuse(unsigned short amacid, + unsigned int fuse_val); + struct amac_return_statusOnly setID_bond(unsigned short amacid, + unsigned int bond_val); }; -#endif //ENDEAVOURCOMCOMLINE2_H +#endif // ENDEAVOURCOMCOMLINE2_H diff --git a/pbv3/EndeavourComException.cpp b/pbv3/EndeavourComException.cpp index 85dd213de72e3872b549366b43ad8041ed02fef7..4c173a852f757efac67811c24f8768be613a19ea 100644 --- a/pbv3/EndeavourComException.cpp +++ b/pbv3/EndeavourComException.cpp @@ -1,20 +1,19 @@ #include "EndeavourComException.h" EndeavourComException::EndeavourComException(const std::string& msg) - : m_msg("EndeavourCom: "+msg) -{ } + : m_msg("EndeavourCom: " + msg) {} -EndeavourComException::EndeavourComException(const char *format, ...) -{ - char buffer[256]; +EndeavourComException::EndeavourComException(const char* format, ...) { + char buffer[256]; - va_list args; - va_start( args, format ); - vsnprintf( buffer, 256, format, args ); - va_end( args ); + va_list args; + va_start(args, format); + vsnprintf(buffer, 256, format, args); + va_end(args); - m_msg=std::string("EndeavourCom: ")+buffer; + m_msg = std::string("EndeavourCom: ") + buffer; } -const char* EndeavourComException::what() const throw() -{ return m_msg.c_str(); } +const char* EndeavourComException::what() const throw() { + return m_msg.c_str(); +} diff --git a/pbv3/EndeavourComException.h b/pbv3/EndeavourComException.h index df28f1aa823015cf4f67d161f18be65f7357c761..c777561cff5751d0005b1ee5ba4ad088b50d8003 100644 --- a/pbv3/EndeavourComException.h +++ b/pbv3/EndeavourComException.h @@ -7,16 +7,15 @@ #include "ComException.h" -class EndeavourComException : public ComException -{ -public: - EndeavourComException(const std::string& msg); - EndeavourComException(const char *format, ...); +class EndeavourComException : public ComException { + public: + EndeavourComException(const std::string& msg); + EndeavourComException(const char* format, ...); - virtual const char* what() const throw(); + virtual const char* what() const throw(); -private: - std::string m_msg; + private: + std::string m_msg; }; -#endif // ENDEAVOURCOMEXCEPTION_H +#endif // ENDEAVOURCOMEXCEPTION_H diff --git a/pbv3/EndeavourRaw.cpp b/pbv3/EndeavourRaw.cpp index 6984bb29f76173366e210dc865a8ffa0dfc8d6e9..366206c5f9b66b2ddc466cd64714d8e73283a191 100644 --- a/pbv3/EndeavourRaw.cpp +++ b/pbv3/EndeavourRaw.cpp @@ -1,4 +1,3 @@ #include "EndeavourRaw.h" -EndeavourRaw::EndeavourRaw() -{ } +EndeavourRaw::EndeavourRaw() {} diff --git a/pbv3/EndeavourRaw.h b/pbv3/EndeavourRaw.h index 3cd0f167c27fb34fbbaef88ed1f6b5abfa88d49d..ef6b8d5484509206ebeae3a7b2fe63adf160c3b2 100644 --- a/pbv3/EndeavourRaw.h +++ b/pbv3/EndeavourRaw.h @@ -5,49 +5,48 @@ #include "DeviceCom.h" -class EndeavourRaw -{ -public: - EndeavourRaw(); - virtual ~EndeavourRaw() {}; +class EndeavourRaw { + public: + EndeavourRaw(); + virtual ~EndeavourRaw(){}; - virtual void setDitMin(uint32_t DIT_MIN) =0; - virtual uint32_t getDitMin() =0; + virtual void setDitMin(uint32_t DIT_MIN) = 0; + virtual uint32_t getDitMin() = 0; - virtual void setDitMid(uint32_t DIT_MID) =0; - virtual uint32_t getDitMid() =0; + virtual void setDitMid(uint32_t DIT_MID) = 0; + virtual uint32_t getDitMid() = 0; - virtual void setDitMax(uint32_t DIT_MAX) =0; - virtual uint32_t getDitMax() =0; + virtual void setDitMax(uint32_t DIT_MAX) = 0; + virtual uint32_t getDitMax() = 0; - virtual void setDahMin(uint32_t DAH_MIN) =0; - virtual uint32_t getDahMin() =0; + virtual void setDahMin(uint32_t DAH_MIN) = 0; + virtual uint32_t getDahMin() = 0; - virtual void setDahMid(uint32_t DAH_MID) =0; - virtual uint32_t getDahMid() =0; + virtual void setDahMid(uint32_t DAH_MID) = 0; + virtual uint32_t getDahMid() = 0; - virtual void setDahMax(uint32_t DAH_MAX) =0; - virtual uint32_t getDahMax() =0; + virtual void setDahMax(uint32_t DAH_MAX) = 0; + virtual uint32_t getDahMax() = 0; - virtual void setBitGapMin(uint32_t BITGAP_MIN) =0; - virtual uint32_t getBitGapMin() =0; + virtual void setBitGapMin(uint32_t BITGAP_MIN) = 0; + virtual uint32_t getBitGapMin() = 0; - virtual void setBitGapMid(uint32_t BITGAP_MID) =0; - virtual uint32_t getBitGapMid() =0; + virtual void setBitGapMid(uint32_t BITGAP_MID) = 0; + virtual uint32_t getBitGapMid() = 0; - virtual void setBitGapMax(uint32_t BITGAP_MAX) =0; - virtual uint32_t getBitGapMax() =0; - - virtual void reset() =0; + virtual void setBitGapMax(uint32_t BITGAP_MAX) = 0; + virtual uint32_t getBitGapMax() = 0; - virtual void sendData(unsigned long long int data, unsigned int size) =0; + virtual void reset() = 0; - virtual bool isError() =0; - virtual bool isDataValid() =0; - virtual void readData(unsigned long long int& data, unsigned int& size) =0; + virtual void sendData(unsigned long long int data, unsigned int size) = 0; - virtual void disconnect() {}; - virtual void connect() {}; + virtual bool isError() = 0; + virtual bool isDataValid() = 0; + virtual void readData(unsigned long long int& data, unsigned int& size) = 0; + + virtual void disconnect(){}; + virtual void connect(){}; }; -#endif //ENDEAVOURRAW_H +#endif // ENDEAVOURRAW_H diff --git a/pbv3/EndeavourRawDummy.cpp b/pbv3/EndeavourRawDummy.cpp index 47fd6a71df69332362afd3ccc78e2bbc1fcf105d..bce1c9990cf38d568e23f0dc5b99c3bd4862bf21 100644 --- a/pbv3/EndeavourRawDummy.cpp +++ b/pbv3/EndeavourRawDummy.cpp @@ -1,70 +1,66 @@ #include "EndeavourRawDummy.h" -#include "EndeavourComException.h" - #include <Logger.h> +#include <stdint.h> +#include <unistd.h> -#include <thread> - -#include <cstdint> -#include <iostream> -#include <iomanip> #include <bitset> -#include <unistd.h> -#include <stdint.h> +#include <cstdint> #include <fstream> +#include <iomanip> +#include <iostream> +#include <thread> -//#include <nlohmann/json.hpp> // HwController's configuration is saved in a json +#include "EndeavourComException.h" -static int tensec = 10e6; +//#include <nlohmann/json.hpp> // HwController's configuration is +//saved in a json +static int tensec = 10e6; -EndeavourRawDummy::EndeavourRawDummy() -{ - logger(logDEBUG) << "EndeavourRawDummy::EndeavourRawDummy construct"; +EndeavourRawDummy::EndeavourRawDummy() { + logger(logDEBUG) << "EndeavourRawDummy::EndeavourRawDummy construct"; } -EndeavourRawDummy::~EndeavourRawDummy() -{ - logger(logDEBUG) << "EndeavourRawDummy::EndeavourRawDummy destruct"; +EndeavourRawDummy::~EndeavourRawDummy() { + logger(logDEBUG) << "EndeavourRawDummy::EndeavourRawDummy destruct"; } /* * EndeavourCom uses this to send databits */ -void EndeavourRawDummy::sendData(unsigned long long int data, unsigned int size) -{ - logger(logDEBUG) << "EndeavourRawDummy::sendData data" - << " 0x" << std::hex << data - << " size " << std::dec << size; - - m_just_sent_data = data; - m_just_sent_data_size = size; +void EndeavourRawDummy::sendData(unsigned long long int data, + unsigned int size) { + logger(logDEBUG) << "EndeavourRawDummy::sendData data" + << " 0x" << std::hex << data << " size " << std::dec + << size; + + m_just_sent_data = data; + m_just_sent_data_size = size; } -bool EndeavourRawDummy::isDataValid() -{ - logger(logDEBUG) << "EndeavourRawDummy::isDataValid"; - return true; +bool EndeavourRawDummy::isDataValid() { + logger(logDEBUG) << "EndeavourRawDummy::isDataValid"; + return true; } -/** \brief readData parses the messages stored in the gbt_buffer_data, the buffer is filled on isDataValid -*/ -void EndeavourRawDummy::readData(unsigned long long int& data, unsigned int& size) -{ - logger(logDEBUG) << "EndeavourRawDummy::readData final data 0x" - << std::hex << data - << " size " - << std::dec << size; +/** \brief readData parses the messages stored in the gbt_buffer_data, the + * buffer is filled on isDataValid + */ +void EndeavourRawDummy::readData(unsigned long long int& data, + unsigned int& size) { + logger(logDEBUG) << "EndeavourRawDummy::readData final data 0x" << std::hex + << data << " size " << std::dec << size; - m_just_read_data = data; - m_just_read_data_size = size; + m_just_read_data = data; + m_just_read_data_size = size; } -void EndeavourRawDummy::_set_read_data(unsigned long long int data, unsigned int size) -{ - logger(logDEBUG) << "EndeavourRawDummy::_set_read_data " << data << " " << size; +void EndeavourRawDummy::_set_read_data(unsigned long long int data, + unsigned int size) { + logger(logDEBUG) << "EndeavourRawDummy::_set_read_data " << data << " " + << size; - m_just_read_data = data; - m_just_read_data_size = size; + m_just_read_data = data; + m_just_read_data_size = size; } diff --git a/pbv3/EndeavourRawDummy.h b/pbv3/EndeavourRawDummy.h index 99fd91554f63bc9e27cbc8761f03d3ccb4b93e90..93959ad67e831e8fca7f6952d541cee744928b9b 100644 --- a/pbv3/EndeavourRawDummy.h +++ b/pbv3/EndeavourRawDummy.h @@ -1,70 +1,71 @@ #ifndef ENDEAVOURRAWDummy_H #define ENDEAVOURRAWDummy_H -#include <memory> #include <string.h> -// the abstract data class to communicate with AMAC over the endeavour protocol -// the EndeavourRawDummy class implements it on GPT Rx-Tx Cores taken from the Dummy HwControllers -#include "EndeavourRaw.h" - -class EndeavourRawDummy : public EndeavourRaw -{ -public: - EndeavourRawDummy(); - ~EndeavourRawDummy(); +#include <memory> - void setDitMin(uint32_t DIT_MIN) { m_DIT_MIN=DIT_MIN; }; - uint32_t getDitMin() { return m_DIT_MIN; }; +// the abstract data class to communicate with AMAC over the endeavour protocol +// the EndeavourRawDummy class implements it on GPT Rx-Tx Cores taken from the +// Dummy HwControllers +#include "EndeavourRaw.h" - void setDitMid(uint32_t DIT_MID) { m_DIT_MID=DIT_MID; }; - uint32_t getDitMid() { return m_DIT_MID; }; +class EndeavourRawDummy : public EndeavourRaw { + public: + EndeavourRawDummy(); + ~EndeavourRawDummy(); - void setDitMax(uint32_t DIT_MAX) { m_DIT_MAX=DIT_MAX; }; - uint32_t getDitMax() { return m_DIT_MAX; }; + void setDitMin(uint32_t DIT_MIN) { m_DIT_MIN = DIT_MIN; }; + uint32_t getDitMin() { return m_DIT_MIN; }; - void setDahMin(uint32_t DAH_MIN) { m_DAH_MIN=DAH_MIN; }; - uint32_t getDahMin() { return m_DAH_MIN; }; + void setDitMid(uint32_t DIT_MID) { m_DIT_MID = DIT_MID; }; + uint32_t getDitMid() { return m_DIT_MID; }; - void setDahMid(uint32_t DAH_MID) { m_DAH_MID=DAH_MID; }; - uint32_t getDahMid() { return m_DAH_MID; }; + void setDitMax(uint32_t DIT_MAX) { m_DIT_MAX = DIT_MAX; }; + uint32_t getDitMax() { return m_DIT_MAX; }; - void setDahMax(uint32_t DAH_MAX) { m_DAH_MAX=DAH_MAX; }; - uint32_t getDahMax() { return m_DAH_MAX; }; + void setDahMin(uint32_t DAH_MIN) { m_DAH_MIN = DAH_MIN; }; + uint32_t getDahMin() { return m_DAH_MIN; }; - void setBitGapMin(uint32_t BITGAP_MIN) { m_BITGAP_MIN=BITGAP_MIN; }; - uint32_t getBitGapMin() { return m_BITGAP_MIN; }; + void setDahMid(uint32_t DAH_MID) { m_DAH_MID = DAH_MID; }; + uint32_t getDahMid() { return m_DAH_MID; }; - void setBitGapMid(uint32_t BITGAP_MID) { m_BITGAP_MID=BITGAP_MID; }; - uint32_t getBitGapMid() { return m_BITGAP_MID; }; + void setDahMax(uint32_t DAH_MAX) { m_DAH_MAX = DAH_MAX; }; + uint32_t getDahMax() { return m_DAH_MAX; }; - void setBitGapMax(uint32_t BITGAP_MAX) { m_BITGAP_MAX=BITGAP_MAX; }; - uint32_t getBitGapMax() { return m_BITGAP_MAX; }; + void setBitGapMin(uint32_t BITGAP_MIN) { m_BITGAP_MIN = BITGAP_MIN; }; + uint32_t getBitGapMin() { return m_BITGAP_MIN; }; + void setBitGapMid(uint32_t BITGAP_MID) { m_BITGAP_MID = BITGAP_MID; }; + uint32_t getBitGapMid() { return m_BITGAP_MID; }; - void reset() { }; + void setBitGapMax(uint32_t BITGAP_MAX) { m_BITGAP_MAX = BITGAP_MAX; }; + uint32_t getBitGapMax() { return m_BITGAP_MAX; }; - bool isError() { return false; }; + void reset(){}; - bool isDataValid(void); - void readData(unsigned long long int& data, unsigned int& size); - void sendData(unsigned long long int data, unsigned int size); + bool isError() { return false; }; - void _set_read_data(unsigned long long int data, unsigned int size); + bool isDataValid(void); + void readData(unsigned long long int& data, unsigned int& size); + void sendData(unsigned long long int data, unsigned int size); -protected: + void _set_read_data(unsigned long long int data, unsigned int size); -private: - unsigned long long int m_just_sent_data; - unsigned int m_just_sent_data_size; - unsigned long long int m_just_read_data; - unsigned int m_just_read_data_size; + protected: + private: + unsigned long long int m_just_sent_data; + unsigned int m_just_sent_data_size; + unsigned long long int m_just_read_data; + unsigned int m_just_read_data_size; - #define _ENDVMS 160 // it was 30 originally - uint32_t m_DIT_MIN = 6*_ENDVMS/40,m_DIT_MID = 14*_ENDVMS/40,m_DIT_MAX = 22*_ENDVMS/40; - uint32_t m_DAH_MIN = 29*_ENDVMS/40,m_DAH_MID = 76*_ENDVMS/40,m_DAH_MAX =124*_ENDVMS/40; - uint32_t m_BITGAP_MIN= 11*_ENDVMS/40,m_BITGAP_MID= 43*_ENDVMS/40,m_BITGAP_MAX= 75*_ENDVMS/40; +#define _ENDVMS 160 // it was 30 originally + uint32_t m_DIT_MIN = 6 * _ENDVMS / 40, m_DIT_MID = 14 * _ENDVMS / 40, + m_DIT_MAX = 22 * _ENDVMS / 40; + uint32_t m_DAH_MIN = 29 * _ENDVMS / 40, m_DAH_MID = 76 * _ENDVMS / 40, + m_DAH_MAX = 124 * _ENDVMS / 40; + uint32_t m_BITGAP_MIN = 11 * _ENDVMS / 40, m_BITGAP_MID = 43 * _ENDVMS / 40, + m_BITGAP_MAX = 75 * _ENDVMS / 40; }; -#endif //ENDEAVOURRAWDummy_H - +#endif // ENDEAVOURRAWDummy_H diff --git a/pbv3/EndeavourRawElinks.cpp b/pbv3/EndeavourRawElinks.cpp index d6e63942392ca8b5eaa445d682a019021a11606d..fd597a6f1a16d5ed3e939a132278bad8b126f5d4 100644 --- a/pbv3/EndeavourRawElinks.cpp +++ b/pbv3/EndeavourRawElinks.cpp @@ -1,27 +1,25 @@ #include "EndeavourRawElinks.h" -#include "EndeavourComException.h" - #include <Logger.h> +#include <stdint.h> +#include <unistd.h> -#include <thread> - -#include <cstdint> -#include <iostream> -#include <iomanip> #include <bitset> -#include <unistd.h> -#include <stdint.h> +#include <chrono> +#include <cstdint> #include <fstream> +#include <iomanip> +#include <iostream> +#include <thread> -#include <chrono> +#include "EndeavourComException.h" using Clock = std::chrono::steady_clock; #ifdef ELINKS_YARR - #include "ElinksYARR.h" +#include "ElinksYARR.h" -#elif ELINKS_ICNETIO - #include "ElinksICNETIO.h" +#elif ELINKS_ICNETIO +#include "ElinksICNETIO.h" #endif #define CHUNK_SIZE 65535 @@ -30,488 +28,497 @@ using Clock = std::chrono::steady_clock; static int tensec = 10e6; -EndeavourRawElinks::EndeavourRawElinks( - Elinks* elinks_connection_backend - ) +EndeavourRawElinks::EndeavourRawElinks(Elinks* elinks_connection_backend) { - m_elinks = elinks_connection_backend; + m_elinks = elinks_connection_backend; - logger(logDEBUG) << "EndeavourRawElinks::EndeavourRawElinks connected"; + logger(logDEBUG) << "EndeavourRawElinks::EndeavourRawElinks connected"; } /* EndeavourRawElinks::EndeavourRawElinks( - //const std::string& hwcontroller_type, - //const std::string& config, - - //unsigned int rx_elink_n, - //unsigned int tx_elink_n, - //std::string ec_lock_filename - address_Elinks address_elinks - ) + //const std::string& hwcontroller_type, + //const std::string& config, + + //unsigned int rx_elink_n, + //unsigned int tx_elink_n, + //std::string ec_lock_filename + address_Elinks address_elinks + ) */ -EndeavourRawElinks::EndeavourRawElinks( - bool use_icnetio, - std::string cfg_file, - bool dontWaitReply - ) +EndeavourRawElinks::EndeavourRawElinks(bool use_icnetio, std::string cfg_file, + bool dontWaitReply) { - logger(logDEBUG) << "EndeavourRawElinks::EndeavourRawElinks connect to endeavor via FLX elinks"; - - // if the user has not provided a backend - // initialize and configure it with the central json configs - // or defaults - - if (use_icnetio) - { - #ifdef ELINKS_ICNETIO - m_elinks = new ElinksICNETIO( - //rx_elink_n, tx_elink_n, ec_lock_filename - //address_Elinks(), - central_json_cfg_address_Elinks(cfg_file), - - // this one takes the hostname & ports - //"pcatlitkflx03", 12340, 12350 - //{.flxHost = "pcatlitkflx03", .portFromHost=12340, .portToHost=12350} - central_json_cfg_address_ICNETIO(cfg_file), - dontWaitReply - ); - - #else - throw EndeavourComException("EndeavourRawElinks was not built with ICNETIO backend, but the user requests it"); - #endif + logger(logDEBUG) << "EndeavourRawElinks::EndeavourRawElinks connect to " + "endeavor via FLX elinks"; + + // if the user has not provided a backend + // initialize and configure it with the central json configs + // or defaults + + if (use_icnetio) { +#ifdef ELINKS_ICNETIO + m_elinks = new ElinksICNETIO( + // rx_elink_n, tx_elink_n, ec_lock_filename + // address_Elinks(), + central_json_cfg_address_Elinks(cfg_file), + + // this one takes the hostname & ports + //"pcatlitkflx03", 12340, 12350 + //{.flxHost = "pcatlitkflx03", .portFromHost=12340, + //.portToHost=12350} + central_json_cfg_address_ICNETIO(cfg_file), dontWaitReply); + +#else + throw EndeavourComException( + "EndeavourRawElinks was not built with ICNETIO backend, but the " + "user requests it"); +#endif } - else { - #ifdef ELINKS_YARR - //m_elinks = new ElinksYARR(rx_elink_n, tx_elink_n, ec_lock_filename); - //m_elinks = new ElinksYARR(address_elinks); - //m_elinks = new ElinksYARR(address_elinks, - // {.hwcontroller_type = "Netio", .config = "/opt/atlas/configs_yarr/controller/netio_amac.json"}); - - //m_elinks = new ElinksYARR(address_Elinks(), central_json_cfg_address_YARR(cfg_file)); - m_elinks = new ElinksYARR( - central_json_cfg_address_Elinks(cfg_file), - central_json_cfg_address_YARR(cfg_file)); - - #elif ELINKS_ICNETIO - m_elinks = new ElinksICNETIO( - //rx_elink_n, tx_elink_n, ec_lock_filename - //address_Elinks(), - central_json_cfg_address_Elinks(cfg_file), - - // this one takes the hostname & ports - //"pcatlitkflx03", 12340, 12350 - //{.flxHost = "pcatlitkflx03", .portFromHost=12340, .portToHost=12350} - central_json_cfg_address_ICNETIO(cfg_file), - dontWaitReply - ); - - #else - throw EndeavourComException("EndeavourRawElinks was built with no elink backend (YARR or any netio)"); - #endif + else { +#ifdef ELINKS_YARR + // m_elinks = new ElinksYARR(rx_elink_n, tx_elink_n, ec_lock_filename); + // m_elinks = new ElinksYARR(address_elinks); + // m_elinks = new ElinksYARR(address_elinks, + // {.hwcontroller_type = "Netio", .config = + // "/opt/atlas/configs_yarr/controller/netio_amac.json"}); + + // m_elinks = new ElinksYARR(address_Elinks(), + // central_json_cfg_address_YARR(cfg_file)); + m_elinks = new ElinksYARR(central_json_cfg_address_Elinks(cfg_file), + central_json_cfg_address_YARR(cfg_file)); + +#elif ELINKS_ICNETIO + m_elinks = new ElinksICNETIO( + // rx_elink_n, tx_elink_n, ec_lock_filename + // address_Elinks(), + central_json_cfg_address_Elinks(cfg_file), + + // this one takes the hostname & ports + //"pcatlitkflx03", 12340, 12350 + //{.flxHost = "pcatlitkflx03", .portFromHost=12340, + //.portToHost=12350} + central_json_cfg_address_ICNETIO(cfg_file), dontWaitReply); + +#else + throw EndeavourComException( + "EndeavourRawElinks was built with no elink backend (YARR or any " + "netio)"); +#endif } - logger(logDEBUG) << "EndeavourRawElinks::EndeavourRawElinks constructed"; + logger(logDEBUG) << "EndeavourRawElinks::EndeavourRawElinks constructed"; } -EndeavourRawElinks::~EndeavourRawElinks() -{ - // delete the elinks engine - delete m_elinks; +EndeavourRawElinks::~EndeavourRawElinks() { + // delete the elinks engine + delete m_elinks; } /** \brief gets first 32-bit word from 64-bit AMAC message */ -uint32_t first_32_bits(unsigned long long int input) -{ - uint32_t ret = input >> 32; - return ret; +uint32_t first_32_bits(unsigned long long int input) { + uint32_t ret = input >> 32; + return ret; } /** \brief gets second 32-bit word from 64-bit AMAC message */ -uint32_t second_32_bits(unsigned long long int input) -{ - uint32_t ret = input; - return ret; +uint32_t second_32_bits(unsigned long long int input) { + uint32_t ret = input; + return ret; } /* // in YARR the input signature is BitStream::Add(uint32_t size, uint32_t value) // therefore a hack to add 64-long messages // TODO: abandon BitStream & just manipulate bits? -void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, unsigned int size) +void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, +unsigned int size) { if (size > 32) { - msg.Add(size-32, first_32_bits(data)); + msg.Add(size-32, first_32_bits(data)); size=32; } - msg.Add(size, second_32_bits(data)); + msg.Add(size, second_32_bits(data)); } */ -BitStream addToBitStream(BitStream & bs, uint32_t size, uint32_t value){ - //Use the value from the LSB - for(uint32_t i=0;i<size;i++) - bs.push_back((value>>(size-i-1))&1); - return bs; +BitStream addToBitStream(BitStream& bs, uint32_t size, uint32_t value) { + // Use the value from the LSB + for (uint32_t i = 0; i < size; i++) + bs.push_back((value >> (size - i - 1)) & 1); + return bs; } -void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, unsigned int size) -{ - if (size > 32) - { - //msg.Add(size-32, first_32_bits(data)); - addToBitStream(msg, size-32, first_32_bits(data)); - size=32; +void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, + unsigned int size) { + if (size > 32) { + // msg.Add(size-32, first_32_bits(data)); + addToBitStream(msg, size - 32, first_32_bits(data)); + size = 32; } - //msg.Add(size, second_32_bits(data)); - addToBitStream(msg, size, second_32_bits(data)); + // msg.Add(size, second_32_bits(data)); + addToBitStream(msg, size, second_32_bits(data)); } /* * EndeavourCom uses this to send databits */ -void EndeavourRawElinks::sendData(unsigned long long int data, unsigned int size) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - - auto data_bits = std::bitset<64>(data); - unsigned n_payload_bytes = size / 8; - // prepare the Endeavour message - logger(logDEBUG) << "EndeavourRawElinks::sendData data" - << " 0x" << std::hex << data << "\t" << data_bits - << " size " << std::dec << size << " nbytes " << n_payload_bytes; - - //logger(logDEBUG) << "EndeavourRawElinks::sendData data_bits " - // << data_bits[0] << data_bits[1] << " " - // << data_bits[62] << data_bits[63]; - - BitStream msg; - - //// Dan's header - //addToBitStream(msg, 24, 0x010101); - //addToBitStream(msg, 8, n_payload_bytes); - - add_64bits_to_BitStream(msg, data, size); // TODO: this thing is needed, it adds bits into BitStream correctly, without any 64-bit padding - // I temporary repeat it 4 times to get rid of 32-bit padding in YARR - - //// footer - //addToBitStream(msg, 8, 0x00); - - /* - // the usual byte order - addToBitStream(msg, 24, 0x010101); - addToBitStream(msg, 8, 2); // n payload bytes - addToBitStream(msg, 16, 0xa02a); // payload 2 bytes - addToBitStream(msg, 8, 0x00); - - //// the inverted byte order - //addToBitStream(msg, 8, 0x00); - //addToBitStream(msg, 16, 0x2aa0); // payload 2 bytes - //addToBitStream(msg, 8, 2); // n payload bytes - //addToBitStream(msg, 24, 0x010101); - */ - - std::string msg_str(msg.begin(), msg.end()); - //logger(logDEBUG) << "EndeavourRawElinks::sendData msg " << msg.ToString() << " size " << msg.GetNbits(); - logger(logDEBUG) << "EndeavourRawElinks::sendData msg " << msg_str << " size " << msg.size(); - - //add_64bits_to_BitStream(msg, data, size); - //add_64bits_to_BitStream(msg, data, size); - //add_64bits_to_BitStream(msg, data, size); - //logger(logDEBUG) << "EndeavourRawElinks::sendData msg " << msg.ToString() << " size " << msg.GetNbits(); - - //add_64bits_to_BitStream(msg, data, size); - // OUTDATED: some hack in the current firmware for FLX709, msg must be sent twice - - //logger(logDEBUG) << "EndeavourRawElinks::sendData msg full " << msg.ToString() << " size " << msg.GetNbits(); - - // don't invert - //msg = invert(msg); - - //// Pack splits the bit array into 32-bit words, which are send on NetIO - //// but it does it starting from the end - //// NetIO needs thw words from the beginning - //// therefore, let's pad the end with zeros - //// 32 - reminder from div 32 - // - //uint32_t n_zeros_to_add = (msg.GetNbits() & 0x1f) ? - // 32 - msg.GetNbits() & 0x1f - // : 0; - //msg.Add(n_zeros_to_add, 0); - //msg.Pack(); - //logger(logDEBUG) << "EndeavourRawElinks::sendData msg pack " << msg.ToString() << " size " << msg.GetNbits(); - - // send it - //gbt_tx_core->sendBitstream(msg); // Elinks: - m_elinks->sendBitstream(msg); - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "EndeavourRawElinks::sendData sent Bitstream time " << diagnostic_time.count() << " us"; - - /* - for (uint32_t i = 0; i < msg.GetSize(); ++i) - //for (int32_t i = msg.GetSize()-1; i >= 0; --i) - { - logger(logDEBUG) << "EndeavourRawElinks::sendData msg word " << i << " " << std::hex << msg.GetWord(i) << std::dec; - gbt_tx_core->writeFifo(msg.GetWord(i)); - } - gbt_tx_core->releaseFifo(); - */ - - // OUTDATED: the following repetition is a work-around - // for the double-command issue in old Phase1 Felix FW - // periodically, in about 1 per 6 reads, - // the AMAC response was not sent out from FW - // if there is no response, just send the command 1 more time - if (!isDataValid()) - { - unsigned int repeat_n = 0; +void EndeavourRawElinks::sendData(unsigned long long int data, + unsigned int size) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + + auto data_bits = std::bitset<64>(data); + unsigned n_payload_bytes = size / 8; + // prepare the Endeavour message + logger(logDEBUG) << "EndeavourRawElinks::sendData data" + << " 0x" << std::hex << data << "\t" << data_bits + << " size " << std::dec << size << " nbytes " + << n_payload_bytes; + + // logger(logDEBUG) << "EndeavourRawElinks::sendData data_bits " + // << data_bits[0] << data_bits[1] << " " + // << data_bits[62] << data_bits[63]; + + BitStream msg; + + //// Dan's header + // addToBitStream(msg, 24, 0x010101); + // addToBitStream(msg, 8, n_payload_bytes); + + add_64bits_to_BitStream( + msg, data, size); // TODO: this thing is needed, it adds bits into + // BitStream correctly, without any 64-bit padding + // I temporary repeat it 4 times to get rid of 32-bit padding in YARR + + //// footer + // addToBitStream(msg, 8, 0x00); + + /* + // the usual byte order + addToBitStream(msg, 24, 0x010101); + addToBitStream(msg, 8, 2); // n payload bytes + addToBitStream(msg, 16, 0xa02a); // payload 2 bytes + addToBitStream(msg, 8, 0x00); + + //// the inverted byte order + //addToBitStream(msg, 8, 0x00); + //addToBitStream(msg, 16, 0x2aa0); // payload 2 bytes + //addToBitStream(msg, 8, 2); // n payload bytes + //addToBitStream(msg, 24, 0x010101); + */ - for (uint32_t i = 0; i < repeat_n; ++i) - //while (repeat_n > 0) + std::string msg_str(msg.begin(), msg.end()); + // logger(logDEBUG) << "EndeavourRawElinks::sendData msg " << msg.ToString() + // << " size " << msg.GetNbits(); + logger(logDEBUG) << "EndeavourRawElinks::sendData msg " << msg_str + << " size " << msg.size(); + + // add_64bits_to_BitStream(msg, data, size); + // add_64bits_to_BitStream(msg, data, size); + // add_64bits_to_BitStream(msg, data, size); + // logger(logDEBUG) << "EndeavourRawElinks::sendData msg " << msg.ToString() + // << " size " << msg.GetNbits(); + + // add_64bits_to_BitStream(msg, data, size); + // OUTDATED: some hack in the current firmware for FLX709, msg must be sent + // twice + + // logger(logDEBUG) << "EndeavourRawElinks::sendData msg full " << + // msg.ToString() << " size " << msg.GetNbits(); + + // don't invert + // msg = invert(msg); + + //// Pack splits the bit array into 32-bit words, which are send on NetIO + //// but it does it starting from the end + //// NetIO needs thw words from the beginning + //// therefore, let's pad the end with zeros + //// 32 - reminder from div 32 + // + // uint32_t n_zeros_to_add = (msg.GetNbits() & 0x1f) ? + // 32 - msg.GetNbits() & 0x1f + // : 0; + // msg.Add(n_zeros_to_add, 0); + // msg.Pack(); + // logger(logDEBUG) << "EndeavourRawElinks::sendData msg pack " << + // msg.ToString() << " size " << msg.GetNbits(); + + // send it + // gbt_tx_core->sendBitstream(msg); // Elinks: + m_elinks->sendBitstream(msg); + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "EndeavourRawElinks::sendData sent Bitstream time " + << diagnostic_time.count() << " us"; + + /* + for (uint32_t i = 0; i < msg.GetSize(); ++i) + //for (int32_t i = msg.GetSize()-1; i >= 0; --i) { - //logger(logDEBUG) << "EndeavourRawElinks, sendData repeat " << repeat_n; - //gbt_tx_core->sendBitstream(msg); - m_elinks->sendBitstream(msg); + logger(logDEBUG) << "EndeavourRawElinks::sendData msg word " << i << " " + << std::hex << msg.GetWord(i) << std::dec; + gbt_tx_core->writeFifo(msg.GetWord(i)); + } + gbt_tx_core->releaseFifo(); + */ - /* - for (uint32_t i = 0; i < msg.GetSize(); ++i) + // OUTDATED: the following repetition is a work-around + // for the double-command issue in old Phase1 Felix FW + // periodically, in about 1 per 6 reads, + // the AMAC response was not sent out from FW + // if there is no response, just send the command 1 more time + if (!isDataValid()) { + unsigned int repeat_n = 0; + + for (uint32_t i = 0; i < repeat_n; ++i) + // while (repeat_n > 0) { - gbt_tx_core->writeFifo(msg.GetWord(i)); + // logger(logDEBUG) << "EndeavourRawElinks, sendData repeat " << + // repeat_n; gbt_tx_core->sendBitstream(msg); + m_elinks->sendBitstream(msg); + + /* + for (uint32_t i = 0; i < msg.GetSize(); ++i) + { + gbt_tx_core->writeFifo(msg.GetWord(i)); + } + gbt_tx_core->releaseFifo(); + */ } - gbt_tx_core->releaseFifo(); - */ - } } - diagnostic_time_end = Clock::now(); - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "EndeavourRawElinks::sendData time " << diagnostic_time.count() << " us"; + diagnostic_time_end = Clock::now(); + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "EndeavourRawElinks::sendData time " + << diagnostic_time.count() << " us"; } -bool EndeavourRawElinks::isDataValid() -{ - logger(logDEBUG) << "EndeavourRawElinks::isDataValid"; - - //RawData *data = nullptr; - std::vector<uint8_t> data; - - //RawDataContainer several_buffers_data; - unsigned int max_reads = 3; // we can receive several messages at once - unsigned int microseconds_of_delay_between_reads = 10; - - for (uint32_t i = 0; i < max_reads; ++i) - { - //data = gbt_rx_core->readData(); - data = m_elinks->readData(); - - //if (data == nullptr) - if (data.size() == 0) - { - // if something is already found and there is no data then it must be the end of the message sequence - //if (gbt_buffer_data.size() > 0) break; - if (m_elink_buffer_data.size() > 0) break; - std::this_thread::sleep_for(std::chrono::microseconds(microseconds_of_delay_between_reads)); - } - else - { - //gbt_buffer_data.push_back(data); // stack the response messages - m_elink_buffer_data.push_back(data); // stack the response messages - } +bool EndeavourRawElinks::isDataValid() { + logger(logDEBUG) << "EndeavourRawElinks::isDataValid"; + + // RawData *data = nullptr; + std::vector<uint8_t> data; + + // RawDataContainer several_buffers_data; + unsigned int max_reads = 3; // we can receive several messages at once + unsigned int microseconds_of_delay_between_reads = 10; + + for (uint32_t i = 0; i < max_reads; ++i) { + // data = gbt_rx_core->readData(); + data = m_elinks->readData(); + + // if (data == nullptr) + if (data.size() == 0) { + // if something is already found and there is no data then it must + // be the end of the message sequence + // if (gbt_buffer_data.size() > 0) break; + if (m_elink_buffer_data.size() > 0) break; + std::this_thread::sleep_for( + std::chrono::microseconds(microseconds_of_delay_between_reads)); + } else { + // gbt_buffer_data.push_back(data); // stack the response messages + m_elink_buffer_data.push_back(data); // stack the response messages + } } - //if (gbt_buffer_data.size() == 0) - if (m_elink_buffer_data.size() == 0) - { - return false; - } - else - { - return true; + // if (gbt_buffer_data.size() == 0) + if (m_elink_buffer_data.size() == 0) { + return false; + } else { + return true; } } -/** \brief readData parses the messages stored in the m_elink_buffer_data, the buffer is filled on isDataValid -*/ -void EndeavourRawElinks::readData(unsigned long long int& data, unsigned int& size) -{ - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); +/** \brief readData parses the messages stored in the m_elink_buffer_data, the + * buffer is filled on isDataValid + */ +void EndeavourRawElinks::readData(unsigned long long int& data, + unsigned int& size) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); + + logger(logDEBUG) << "EndeavourRawElinks::readData"; + std::vector<unsigned long long int> parsed_messages; + std::vector<unsigned int> parsed_messages_length; + + // get the AMAC messages from the NetIO buffers + // for(unsigned int i=0; i<gbt_buffer_data.size(); i++) + for (unsigned int i = 0; i < m_elink_buffer_data.size(); i++) { + // should be one decoded message from AMAC + // RawData* buffer_data = gbt_buffer_data[i]; + std::vector<uint8_t>& buffer_data = m_elink_buffer_data[i]; + unsigned long long int parsed_message_int = 0; + + if (buffer_data.size() > 8) // 8 bytes = 64 bits + { + logger(logDEBUG) << "received more than 8 bytes of an AMAC message " + "in one NetIO buffer: " + << buffer_data.size(); + } - logger(logDEBUG) << "EndeavourRawElinks::readData"; - std::vector<unsigned long long int> parsed_messages; - std::vector<unsigned int> parsed_messages_length; + unsigned int msg_len = 0; + unsigned int n_bytes = buffer_data.size(); // 2; // buffer_data->words + logger(logDEBUG) << "EndeavourRawElinks::readData received n_bytes= " + << n_bytes; + + for (uint32_t j = 0; j < n_bytes; ++j) { + // a byte + uint8_t n = buffer_data[j]; + parsed_message_int <<= 8; + parsed_message_int = parsed_message_int | n; + msg_len += 8; + } - // get the AMAC messages from the NetIO buffers - //for(unsigned int i=0; i<gbt_buffer_data.size(); i++) - for(unsigned int i=0; i<m_elink_buffer_data.size(); i++) - { - // should be one decoded message from AMAC - //RawData* buffer_data = gbt_buffer_data[i]; - std::vector<uint8_t>& buffer_data = m_elink_buffer_data[i]; - unsigned long long int parsed_message_int = 0; + // strip the last zeroes + // the AMAC response messages are: + // 48 bit for READ, READNEXT + // 8 bit for WRITE, SETID + // From the spec: + // * In response to a READ command, AMAC sends the 48-bit response + // {amacid[4:0], seqnum[2:0], addr[7:0], data[31:0]}, + // where data[31:0] is the contents of the addressed register. + // * [For READNEXT] The response is the same as to a READ command. + // * In response to a WRITE command, + // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. + // * In response to the SETID command, + // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. + // the words from NetIO are 32 bit long + + // 2021-08-02 fw phaseII regmap5, FW returns x86 byte order, no need to + // swap but it is wrong order for the network, i.e. in netio AMAC + // message looks like: 10 00 00 00 1c 00 00 00 2a aa 00 00 01 00 00 00 + // msg_len = 48; + + /* 2021-08-20 fw phaseII regmap5, I do not strip the bytes, because fw + returns it in 32-bit messages + // TODO: now I am stripping 2 0-bytes from 64 bit messages + // and 3 0-bytes from 32 bit + // - check if there is always a 1 bit at the end of AMAC message + if (msg_len == 64 || msg_len == 32) + { + unsigned int max_bytes_to_strip = msg_len == 64 ? 2 : 3; + + uint8_t last_byte = 0; + while ((last_byte = parsed_message_int & 0xff) == 0 && + max_bytes_to_strip-- > 0) + { + parsed_message_int >>= 8; + msg_len -= 8; + } + } + */ + + parsed_messages.push_back(parsed_message_int); + parsed_messages_length.push_back(msg_len); + } - if (buffer_data.size() > 8) // 8 bytes = 64 bits + // clear the buffer after parsing + // for (unsigned int i=0; i<gbt_buffer_data.size(); i++) + // { + // delete gbt_buffer_data[i]; // to not leak the items + // } + + logger(logDEBUG) + << "EndeavourRawElinks::readData m_elink_buffer_data.size() " + << m_elink_buffer_data.size() << " parsed_messages:"; + for (unsigned int i = 0; i < parsed_messages.size(); i++) { + logger(logDEBUG) << " 0x" << std::setfill('0') << std::setw(12) + << std::right // 6 bytes = 12 hex is max + << std::hex << parsed_messages[i] << " size " + << std::dec << parsed_messages_length[i]; + } + // gbt_buffer_data.clear(); + m_elink_buffer_data.clear(); + + /* TODO: re-implement the printout somehow? + // printout messages for debugging + for (uint32_t message_i = 0; message_i < parsed_messages.size(); + ++message_i) { - logger(logDEBUG) << "received more than 8 bytes of an AMAC message in one NetIO buffer: " << buffer_data.size(); - } + unsigned long long int& msg = parsed_messages[message_i]; + unsigned int& msg_len = parsed_messages_length[message_i]; - unsigned int msg_len = 0; - unsigned int n_bytes = buffer_data.size(); // 2; // buffer_data->words - logger(logDEBUG) << "EndeavourRawElinks::readData received n_bytes= " << n_bytes; + if (msg_len == 49) + { + // shift the message to pop the last bit + msg >>= 1; + msg_len--; + } - for (uint32_t j=0; j < n_bytes; ++j) - { - // a byte - uint8_t n = buffer_data[j]; - parsed_message_int <<= 8; - parsed_message_int = parsed_message_int | n; - msg_len += 8; - } + // strip the last zeroes + // the AMAC response messages are: + // 48 bit for READ, READNEXT + // 8 bit for WRITE, SETID - // strip the last zeroes - // the AMAC response messages are: - // 48 bit for READ, READNEXT - // 8 bit for WRITE, SETID - // From the spec: - // * In response to a READ command, AMAC sends the 48-bit response - // {amacid[4:0], seqnum[2:0], addr[7:0], data[31:0]}, - // where data[31:0] is the contents of the addressed register. - // * [For READNEXT] The response is the same as to a READ command. - // * In response to a WRITE command, - // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. - // * In response to the SETID command, - // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. - // the words from NetIO are 32 bit long - - // 2021-08-02 fw phaseII regmap5, FW returns x86 byte order, no need to swap - // but it is wrong order for the network, i.e. in netio AMAC message looks like: - // 10 00 00 00 1c 00 00 00 2a aa 00 00 01 00 00 00 - //msg_len = 48; - - /* 2021-08-20 fw phaseII regmap5, I do not strip the bytes, because fw returns it in 32-bit messages - // TODO: now I am stripping 2 0-bytes from 64 bit messages - // and 3 0-bytes from 32 bit - // - check if there is always a 1 bit at the end of AMAC message - if (msg_len == 64 || msg_len == 32) - { - unsigned int max_bytes_to_strip = msg_len == 64 ? 2 : 3; + if (msg_len > 48) + { + // shift the message to pop the last bits + msg >>= msg_len - 48; + msg_len = 48; + } - uint8_t last_byte = 0; - while ((last_byte = parsed_message_int & 0xff) == 0 && max_bytes_to_strip-- > 0) + else if (msg_len > 8) { - parsed_message_int >>= 8; - msg_len -= 8; + // shift the message to pop the last bits + msg >>= msg_len - 8; + msg_len = 8; } + + //logger(logDEBUG) << "EndeavourRawElinks::readData " + // << "message len " << std::dec << msg_len << "bits" + // << " 0x" << std::hex << msg << "\t" << + std::bitset<64>(msg); } */ - parsed_messages.push_back(parsed_message_int); - parsed_messages_length.push_back(msg_len); - } - - // clear the buffer after parsing - //for (unsigned int i=0; i<gbt_buffer_data.size(); i++) - // { - // delete gbt_buffer_data[i]; // to not leak the items - // } - - logger(logDEBUG) << "EndeavourRawElinks::readData m_elink_buffer_data.size() " << m_elink_buffer_data.size() - << " parsed_messages:"; - for (unsigned int i=0; i<parsed_messages.size(); i++) - { - logger(logDEBUG) << " 0x" - << std::setfill('0') << std::setw(12) << std::right // 6 bytes = 12 hex is max - << std::hex << parsed_messages[i] - << " size " << std::dec << parsed_messages_length[i]; - } - //gbt_buffer_data.clear(); - m_elink_buffer_data.clear(); + //// output the last message from all that were received in isDataValid + // size = parsed_messages_length.back(); + // data = parsed_messages.back(); - /* TODO: re-implement the printout somehow? - // printout messages for debugging - for (uint32_t message_i = 0; message_i < parsed_messages.size(); ++message_i) - { - unsigned long long int& msg = parsed_messages[message_i]; - unsigned int& msg_len = parsed_messages_length[message_i]; + // merge last message or two + size = parsed_messages_length[0]; + data = parsed_messages[0]; - if (msg_len == 49) + // when swap endianness in the word, this might be needed + /* + if (parsed_messages.size()>1) { - // shift the message to pop the last bit - msg >>= 1; - msg_len--; - } + unsigned full_msg_size = 48; // whatever + unsigned n_remaining_bits = (full_msg_size - size); + data <<= n_remaining_bits; // make space for the rest of bits - // strip the last zeroes - // the AMAC response messages are: - // 48 bit for READ, READNEXT - // 8 bit for WRITE, SETID - - if (msg_len > 48) - { - // shift the message to pop the last bits - msg >>= msg_len - 48; - msg_len = 48; + unsigned long long one_more_msg = parsed_messages[1]; + data |= (one_more_msg >> (parsed_messages_length[1] - n_remaining_bits)); + size = full_msg_size; } - else if (msg_len > 8) + else // it is a 8-bit response, from setid or write { - // shift the message to pop the last bits - msg >>= msg_len - 8; - msg_len = 8; + unsigned full_msg_size = 8; + unsigned n_spurious_bits = (size - full_msg_size); + data >>= n_spurious_bits; // leave only the leading 8 bits + size = full_msg_size; } + */ - //logger(logDEBUG) << "EndeavourRawElinks::readData " - // << "message len " << std::dec << msg_len << "bits" - // << " 0x" << std::hex << msg << "\t" << std::bitset<64>(msg); - } - */ - - //// output the last message from all that were received in isDataValid - //size = parsed_messages_length.back(); - //data = parsed_messages.back(); - - // merge last message or two - size = parsed_messages_length[0]; - data = parsed_messages[0]; - - // when swap endianness in the word, this might be needed - /* - if (parsed_messages.size()>1) - { - unsigned full_msg_size = 48; // whatever - unsigned n_remaining_bits = (full_msg_size - size); - data <<= n_remaining_bits; // make space for the rest of bits - - unsigned long long one_more_msg = parsed_messages[1]; - data |= (one_more_msg >> (parsed_messages_length[1] - n_remaining_bits)); - size = full_msg_size; - } - - else // it is a 8-bit response, from setid or write - { - unsigned full_msg_size = 8; - unsigned n_spurious_bits = (size - full_msg_size); - data >>= n_spurious_bits; // leave only the leading 8 bits - size = full_msg_size; - } - */ - - logger(logDEBUG) << "EndeavourRawElinks::readData final data 0x" - << std::setfill('0') << std::setw(12) << std::right // 6 bytes = 12 hex is max - << std::hex << data - << " size " << std::dec << size; - - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "EndeavourRawElinks::readData time " << diagnostic_time.count() << " us"; + logger(logDEBUG) << "EndeavourRawElinks::readData final data 0x" + << std::setfill('0') << std::setw(12) + << std::right // 6 bytes = 12 hex is max + << std::hex << data << " size " << std::dec << size; + + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "EndeavourRawElinks::readData time " + << diagnostic_time.count() << " us"; } diff --git a/pbv3/EndeavourRawElinks.h b/pbv3/EndeavourRawElinks.h index 432ce38caf35c96ff71cfb669bf7854d602e0bcd..1725915144df7437455615a227d654a32be33551 100644 --- a/pbv3/EndeavourRawElinks.h +++ b/pbv3/EndeavourRawElinks.h @@ -1,114 +1,127 @@ #ifndef ENDEAVOURRAWELINKS_H #define ENDEAVOURRAWELINKS_H -#include <memory> #include <string.h> -#include <sstream> // against invalid use of incomplete type ‘std::string’ + +#include <memory> +#include <sstream> // against invalid use of incomplete type ‘std::string’ // the abstract data class to communicate with AMAC over the endeavour protocol -// the EndeavourRawElinks class implements it on GPT Rx-Tx Cores taken from the YARR HwControllers -#include "EndeavourRaw.h" -#include "Elinks.h" +// the EndeavourRawElinks class implements it on GPT Rx-Tx Cores taken from the +// YARR HwControllers +#include "Elinks.h" +#include "EndeavourRaw.h" //// YARR classes -//class HwController; -//class RxCore; +// class HwController; +// class RxCore; ////class TxCore; -//class NetioTxCore; -//class RawData; +// class NetioTxCore; +// class RawData; ////class BitStream; -//TODO: #include "Elinks.h" - -//const std::string default_ec_lock_filename = std::string(); //="/run/lock/atlas_itk_strips_EC"; - -class EndeavourRawElinks : public EndeavourRaw -{ -public: - //EndeavourRawElinks(); - //EndeavourRawElinks( - // const std::string& hwcontroller_type, // nope - // const std::string& config_file_path, - // std::string ec_lock_filename = "/opt/atlas/etc/atlas_itk_strips_EC"); // "/run/lock/atlas_itk_strips_EC"); - - //EndeavourRawElinks( - // unsigned int rx_elink_n = 0x1c, - // unsigned int tx_elink_n = 0x14, - // std::string ec_lock_filename = FALLBACK_EC_LINK_LOCK_FILE); // "/run/lock/atlas_itk_strips_EC"); - - //EndeavourRawElinks( address_Elinks = address_Elinks() ); - EndeavourRawElinks( Elinks* elinks_connection ); - //EndeavourRawElinks( address_Elinks = address_Elinks() ); - EndeavourRawElinks( bool use_icnetio=false, std::string config_file="/opt/atlas/etc/cfg_endeavour.json", bool dontWaitReply=false ); - // TODO: change it to shared or even uniq ptr -- I don't expect any other object to use it - - // TODO: figure out how to pass a dynamic config like what Karol does here - // but without the pain of an implicit json file. - // The point is that we want to choose the engine dynamically. - // Therefore we make a directory of objects. - // And to pass their initialization arguments dynamically we use JSON. - // But moreover, we use a file with JSON. - // Maybe we can just get rid of the need for a file? - // - // For now I'll set the engine at build time. - // What we (kind of) want is to set all engine options at build time. - // That can be used dynamically later. - - ~EndeavourRawElinks(); - - // TODO: these were for software-defined Endeavour - let's reimplement it & keep around somewhere? - void setDitMin(uint32_t DIT_MIN) { m_DIT_MIN=DIT_MIN; }; - uint32_t getDitMin() { return m_DIT_MIN; }; - - void setDitMid(uint32_t DIT_MID) { m_DIT_MID=DIT_MID; }; - uint32_t getDitMid() { return m_DIT_MID; }; - - void setDitMax(uint32_t DIT_MAX) { m_DIT_MAX=DIT_MAX; }; - uint32_t getDitMax() { return m_DIT_MAX; }; - - void setDahMin(uint32_t DAH_MIN) { m_DAH_MIN=DAH_MIN; }; - uint32_t getDahMin() { return m_DAH_MIN; }; - - void setDahMid(uint32_t DAH_MID) { m_DAH_MID=DAH_MID; }; - uint32_t getDahMid() { return m_DAH_MID; }; - - void setDahMax(uint32_t DAH_MAX) { m_DAH_MAX=DAH_MAX; }; - uint32_t getDahMax() { return m_DAH_MAX; }; - - void setBitGapMin(uint32_t BITGAP_MIN) { m_BITGAP_MIN=BITGAP_MIN; }; - uint32_t getBitGapMin() { return m_BITGAP_MIN; }; - - void setBitGapMid(uint32_t BITGAP_MID) { m_BITGAP_MID=BITGAP_MID; }; - uint32_t getBitGapMid() { return m_BITGAP_MID; }; - - void setBitGapMax(uint32_t BITGAP_MAX) { m_BITGAP_MAX=BITGAP_MAX; }; - uint32_t getBitGapMax() { return m_BITGAP_MAX; }; - - void reset() { }; - - bool isError() { return false; }; - - // the actual functional methods - bool isDataValid(void); - void readData(unsigned long long int& data, unsigned int& size); - void sendData(unsigned long long int data, unsigned int size); - - void disconnect() {m_elinks->disconnect();}; - void connect() {m_elinks-> connect();}; - -protected: - //std::vector<RawData*> gbt_buffer_data; - std::vector<std::vector<uint8_t>> m_elink_buffer_data; // internal elink data, used between isDataValid & readData - Elinks* m_elinks; - //std::string m_ec_lock_filename; - //int m_fd_ec_lock; - -private: - #define _ENDVMS 160 // it was 30 originally - uint32_t m_DIT_MIN = 6*_ENDVMS/40,m_DIT_MID = 14*_ENDVMS/40,m_DIT_MAX = 22*_ENDVMS/40; - uint32_t m_DAH_MIN = 29*_ENDVMS/40,m_DAH_MID = 76*_ENDVMS/40,m_DAH_MAX =124*_ENDVMS/40; - uint32_t m_BITGAP_MIN= 11*_ENDVMS/40,m_BITGAP_MID= 43*_ENDVMS/40,m_BITGAP_MAX= 75*_ENDVMS/40; +// TODO: #include "Elinks.h" + +// const std::string default_ec_lock_filename = std::string(); +// //="/run/lock/atlas_itk_strips_EC"; + +class EndeavourRawElinks : public EndeavourRaw { + public: + // EndeavourRawElinks(); + // EndeavourRawElinks( + // const std::string& hwcontroller_type, // nope + // const std::string& config_file_path, + // std::string ec_lock_filename = "/opt/atlas/etc/atlas_itk_strips_EC"); // + // "/run/lock/atlas_itk_strips_EC"); + + // EndeavourRawElinks( + // unsigned int rx_elink_n = 0x1c, + // unsigned int tx_elink_n = 0x14, + // std::string ec_lock_filename = FALLBACK_EC_LINK_LOCK_FILE); // + // "/run/lock/atlas_itk_strips_EC"); + + // EndeavourRawElinks( address_Elinks = address_Elinks() ); + EndeavourRawElinks(Elinks* elinks_connection); + // EndeavourRawElinks( address_Elinks = address_Elinks() ); + EndeavourRawElinks( + bool use_icnetio = false, + std::string config_file = "/opt/atlas/etc/cfg_endeavour.json", + bool dontWaitReply = false); + // TODO: change it to shared or even uniq ptr -- I don't expect any other + // object to use it + + // TODO: figure out how to pass a dynamic config like what Karol does here + // but without the pain of an implicit json file. + // The point is that we want to choose the engine dynamically. + // Therefore we make a directory of objects. + // And to pass their initialization arguments dynamically we use JSON. + // But moreover, we use a file with JSON. + // Maybe we can just get rid of the need for a file? + // + // For now I'll set the engine at build time. + // What we (kind of) want is to set all engine options at build time. + // That can be used dynamically later. + + ~EndeavourRawElinks(); + + // TODO: these were for software-defined Endeavour - let's reimplement it & + // keep around somewhere? + void setDitMin(uint32_t DIT_MIN) { m_DIT_MIN = DIT_MIN; }; + uint32_t getDitMin() { return m_DIT_MIN; }; + + void setDitMid(uint32_t DIT_MID) { m_DIT_MID = DIT_MID; }; + uint32_t getDitMid() { return m_DIT_MID; }; + + void setDitMax(uint32_t DIT_MAX) { m_DIT_MAX = DIT_MAX; }; + uint32_t getDitMax() { return m_DIT_MAX; }; + + void setDahMin(uint32_t DAH_MIN) { m_DAH_MIN = DAH_MIN; }; + uint32_t getDahMin() { return m_DAH_MIN; }; + + void setDahMid(uint32_t DAH_MID) { m_DAH_MID = DAH_MID; }; + uint32_t getDahMid() { return m_DAH_MID; }; + + void setDahMax(uint32_t DAH_MAX) { m_DAH_MAX = DAH_MAX; }; + uint32_t getDahMax() { return m_DAH_MAX; }; + + void setBitGapMin(uint32_t BITGAP_MIN) { m_BITGAP_MIN = BITGAP_MIN; }; + uint32_t getBitGapMin() { return m_BITGAP_MIN; }; + + void setBitGapMid(uint32_t BITGAP_MID) { m_BITGAP_MID = BITGAP_MID; }; + uint32_t getBitGapMid() { return m_BITGAP_MID; }; + + void setBitGapMax(uint32_t BITGAP_MAX) { m_BITGAP_MAX = BITGAP_MAX; }; + uint32_t getBitGapMax() { return m_BITGAP_MAX; }; + + void reset(){}; + + bool isError() { return false; }; + + // the actual functional methods + bool isDataValid(void); + void readData(unsigned long long int& data, unsigned int& size); + void sendData(unsigned long long int data, unsigned int size); + + void disconnect() { m_elinks->disconnect(); }; + void connect() { m_elinks->connect(); }; + + protected: + // std::vector<RawData*> gbt_buffer_data; + std::vector<std::vector<uint8_t>> + m_elink_buffer_data; // internal elink data, used between isDataValid & + // readData + Elinks* m_elinks; + // std::string m_ec_lock_filename; + // int m_fd_ec_lock; + + private: +#define _ENDVMS 160 // it was 30 originally + uint32_t m_DIT_MIN = 6 * _ENDVMS / 40, m_DIT_MID = 14 * _ENDVMS / 40, + m_DIT_MAX = 22 * _ENDVMS / 40; + uint32_t m_DAH_MIN = 29 * _ENDVMS / 40, m_DAH_MID = 76 * _ENDVMS / 40, + m_DAH_MAX = 124 * _ENDVMS / 40; + uint32_t m_BITGAP_MIN = 11 * _ENDVMS / 40, m_BITGAP_MID = 43 * _ENDVMS / 40, + m_BITGAP_MAX = 75 * _ENDVMS / 40; }; -#endif //ENDEAVOURRAWELINKS_H - +#endif // ENDEAVOURRAWELINKS_H diff --git a/pbv3/EndeavourRawFTDI.cpp b/pbv3/EndeavourRawFTDI.cpp index 170a8cf23d0e1e42456a1009938405774023f2fe..aa783f3f73f237eb06447a7d91b603c8e3e70639 100644 --- a/pbv3/EndeavourRawFTDI.cpp +++ b/pbv3/EndeavourRawFTDI.cpp @@ -1,358 +1,325 @@ #include "EndeavourRawFTDI.h" -#include "EndeavourComException.h" +#include <libftdi1/ftdi.h> +#include <stdint.h> +#include <unistd.h> -#include "MCP4801.h" -#include "MAX11619.h" +#include <bitset> +#include <cstdint> +#include <iomanip> +#include <iostream> +#include "EndeavourComException.h" #include "LinearCalibration.h" - +#include "MAX11619.h" +#include "MCP4801.h" #include "ftdihelp.h" -#include <libftdi1/ftdi.h> -#include <cstdint> -#include <iostream> -#include <iomanip> -#include <bitset> -#include <unistd.h> -#include <stdint.h> - #define CHUNK_SIZE 65535 #define LATENCY_MS 4 #define USB_TIMEOUT 120000 +EndeavourRawFTDI::EndeavourRawFTDI(const std::string& description, + const std::string& serial) { + int ret; + if ((m_ftdi = ftdi_new()) == 0) + throw EndeavourComException("Unable to open FTDI"); -EndeavourRawFTDI::EndeavourRawFTDI(const std::string& description, const std::string& serial) -{ - int ret; - if((m_ftdi=ftdi_new())==0) - throw EndeavourComException("Unable to open FTDI"); - - if((ret=ftdi_usb_open_desc(m_ftdi, - 0x0403,0x6014, - (description.empty())?NULL:description.c_str(), - (serial.empty())?NULL:serial.c_str() - ))<0) - throw EndeavourComException("Unable to find FTDI device: " + std::string(ftdi_get_error_string(m_ftdi))); - - // - // Configure device for MPSSE - - // Reset USB device - ftdi_usb_reset(m_ftdi); - - // Set USB request transfer sizes to 64K - ftdi_write_data_set_chunksize(m_ftdi, CHUNK_SIZE); - ftdi_read_data_set_chunksize (m_ftdi, CHUNK_SIZE); - - // Disable event and error characters - ftdi_set_event_char(m_ftdi, 0, false); - ftdi_set_error_char(m_ftdi, 0, false); - - // Sets the read and write timeouts in milliseconds - m_ftdi->usb_read_timeout = USB_TIMEOUT; - m_ftdi->usb_write_timeout = USB_TIMEOUT; - - // Set the latency timer to 1mS (default is 16mS) - ftdi_set_latency_timer(m_ftdi, LATENCY_MS); - - // Turn on flow control to synchronize IN requests - ftdi_setflowctrl(m_ftdi, SIO_RTS_CTS_HS); - - // Reset controller - ftdi_set_bitmode(m_ftdi, 0x0, BITMODE_RESET); - - // Enable MPSSE mode - ftdi_set_bitmode(m_ftdi, 0x0, BITMODE_MPSSE); - - // Purge buffers - ftdi_usb_purge_buffers(m_ftdi); - - // Set default state of pins - std::vector<uint8_t> data={0x80, 0x00, 0xFB}; - ftdi_write_data(m_ftdi, &data[0], data.size()); - - // Disable 5x clock divisor - data={0x8A}; - ftdi_write_data(m_ftdi, &data[0], data.size()); - - // Set clock to 30MHz (max) - data={0x86, 0x00, 0x00}; - ftdi_write_data(m_ftdi, &data[0], data.size()); - - // initialize high bytes values - data={0x82, 0x0C, 0xDF}; - ftdi_write_data(m_ftdi, &data[0], data.size()); - - // SPI devices - m_spiADC=std::make_shared<PBv3CommPatchSPICom>(m_ftdi, 2); - m_spiDAC=std::make_shared<PBv3CommPatchSPICom>(m_ftdi, 3); - - m_dac=std::make_shared<MCP4801 >(m_spiDAC); - m_dac->setCalibration(std::make_shared<LinearCalibration>(1.024,0xFF)); - m_adc=std::make_shared<MAX11619>(2.5, m_spiADC); - // setOF(true); - - // std::vector<uint8_t> spidata={0x3F,0xF0}; - // m_spiDAC->write_block(spidata); - - // // - // // Run something related to SPI ADC - // // - // m_spiADC->write_block({0x18, 0xF9}); - - // data.resize(2*4); - // m_spiADC->read_block(data); - // for(uint8_t i=0; i<4;i++) - // { - // uint16_t reading=(data[2*i+0]<<8)|(data[2*i+1]<<0); - // std::cout << "CH" << i << ": " << ((reading>>2)&0x3FF) << std::endl; - // } -} + if ((ret = ftdi_usb_open_desc( + m_ftdi, 0x0403, 0x6014, + (description.empty()) ? NULL : description.c_str(), + (serial.empty()) ? NULL : serial.c_str())) < 0) + throw EndeavourComException("Unable to find FTDI device: " + + std::string(ftdi_get_error_string(m_ftdi))); -EndeavourRawFTDI::~EndeavourRawFTDI() -{ - ftdi_usb_close(m_ftdi); - ftdi_free(m_ftdi); -} + // + // Configure device for MPSSE + + // Reset USB device + ftdi_usb_reset(m_ftdi); + + // Set USB request transfer sizes to 64K + ftdi_write_data_set_chunksize(m_ftdi, CHUNK_SIZE); + ftdi_read_data_set_chunksize(m_ftdi, CHUNK_SIZE); -void EndeavourRawFTDI::setDitMin(uint32_t DIT_MIN) -{ m_DIT_MIN=DIT_MIN; } + // Disable event and error characters + ftdi_set_event_char(m_ftdi, 0, false); + ftdi_set_error_char(m_ftdi, 0, false); -uint32_t EndeavourRawFTDI::getDitMin() -{ return m_DIT_MIN; } + // Sets the read and write timeouts in milliseconds + m_ftdi->usb_read_timeout = USB_TIMEOUT; + m_ftdi->usb_write_timeout = USB_TIMEOUT; -void EndeavourRawFTDI::setDitMid(uint32_t DIT_MID) -{ m_DIT_MID=DIT_MID; } + // Set the latency timer to 1mS (default is 16mS) + ftdi_set_latency_timer(m_ftdi, LATENCY_MS); -uint32_t EndeavourRawFTDI::getDitMid() -{ return m_DIT_MID; } + // Turn on flow control to synchronize IN requests + ftdi_setflowctrl(m_ftdi, SIO_RTS_CTS_HS); -void EndeavourRawFTDI::setDitMax(uint32_t DIT_MAX) -{ m_DIT_MAX=DIT_MAX; } + // Reset controller + ftdi_set_bitmode(m_ftdi, 0x0, BITMODE_RESET); -uint32_t EndeavourRawFTDI::getDitMax() -{ return m_DIT_MAX; } + // Enable MPSSE mode + ftdi_set_bitmode(m_ftdi, 0x0, BITMODE_MPSSE); -void EndeavourRawFTDI::setDahMin(uint32_t DAH_MIN) -{ m_DAH_MIN=DAH_MIN; } + // Purge buffers + ftdi_usb_purge_buffers(m_ftdi); -uint32_t EndeavourRawFTDI::getDahMin() -{ return m_DAH_MIN; } + // Set default state of pins + std::vector<uint8_t> data = {0x80, 0x00, 0xFB}; + ftdi_write_data(m_ftdi, &data[0], data.size()); -void EndeavourRawFTDI::setDahMid(uint32_t DAH_MID) -{ m_DAH_MID=DAH_MID; } + // Disable 5x clock divisor + data = {0x8A}; + ftdi_write_data(m_ftdi, &data[0], data.size()); -uint32_t EndeavourRawFTDI::getDahMid() -{ return m_DAH_MID; } + // Set clock to 30MHz (max) + data = {0x86, 0x00, 0x00}; + ftdi_write_data(m_ftdi, &data[0], data.size()); -void EndeavourRawFTDI::setDahMax(uint32_t DAH_MAX) -{ m_DAH_MAX=DAH_MAX; } + // initialize high bytes values + data = {0x82, 0x0C, 0xDF}; + ftdi_write_data(m_ftdi, &data[0], data.size()); -uint32_t EndeavourRawFTDI::getDahMax() -{ return m_DAH_MAX; } + // SPI devices + m_spiADC = std::make_shared<PBv3CommPatchSPICom>(m_ftdi, 2); + m_spiDAC = std::make_shared<PBv3CommPatchSPICom>(m_ftdi, 3); -void EndeavourRawFTDI::setBitGapMin(uint32_t BITGAP_MIN) -{ m_BITGAP_MIN=BITGAP_MIN; } + m_dac = std::make_shared<MCP4801>(m_spiDAC); + m_dac->setCalibration(std::make_shared<LinearCalibration>(1.024, 0xFF)); + m_adc = std::make_shared<MAX11619>(2.5, m_spiADC); + // setOF(true); -uint32_t EndeavourRawFTDI::getBitGapMin() -{ return m_BITGAP_MIN; } + // std::vector<uint8_t> spidata={0x3F,0xF0}; + // m_spiDAC->write_block(spidata); -void EndeavourRawFTDI::setBitGapMid(uint32_t BITGAP_MID) -{ m_BITGAP_MID=BITGAP_MID; } + // // + // // Run something related to SPI ADC + // // + // m_spiADC->write_block({0x18, 0xF9}); -uint32_t EndeavourRawFTDI::getBitGapMid() -{ return m_BITGAP_MID; } + // data.resize(2*4); + // m_spiADC->read_block(data); + // for(uint8_t i=0; i<4;i++) + // { + // uint16_t reading=(data[2*i+0]<<8)|(data[2*i+1]<<0); + // std::cout << "CH" << i << ": " << ((reading>>2)&0x3FF) << std::endl; + // } +} -void EndeavourRawFTDI::setBitGapMax(uint32_t BITGAP_MAX) -{ m_BITGAP_MAX=BITGAP_MAX; } +EndeavourRawFTDI::~EndeavourRawFTDI() { + ftdi_usb_close(m_ftdi); + ftdi_free(m_ftdi); +} -uint32_t EndeavourRawFTDI::getBitGapMax() -{ return m_BITGAP_MAX; } +void EndeavourRawFTDI::setDitMin(uint32_t DIT_MIN) { m_DIT_MIN = DIT_MIN; } -void EndeavourRawFTDI::reset() -{ } +uint32_t EndeavourRawFTDI::getDitMin() { return m_DIT_MIN; } -bool EndeavourRawFTDI::isError() -{ return false; } +void EndeavourRawFTDI::setDitMid(uint32_t DIT_MID) { m_DIT_MID = DIT_MID; } -bool EndeavourRawFTDI::isDataValid() -{ return m_readSize>0; } +uint32_t EndeavourRawFTDI::getDitMid() { return m_DIT_MID; } -void EndeavourRawFTDI::sendData(unsigned long long int data, unsigned int size) -{ - std::vector<uint8_t> ftdidata; - - uint8_t bytecounter=0, byte=0; - for(uint32_t bit=size;bit>0;bit--) - { - bool value=(data>>(bit-1))&1; +void EndeavourRawFTDI::setDitMax(uint32_t DIT_MAX) { m_DIT_MAX = DIT_MAX; } - // Add 1's for data - for(uint32_t i=0;i<((value)?m_DAH_MID:m_DIT_MID);i++) - { - byte<<=1; - byte|=1; - bytecounter++; - if(bytecounter==8) - { - ftdidata.push_back(byte); - byte=0; - bytecounter=0; - } - } +uint32_t EndeavourRawFTDI::getDitMax() { return m_DIT_MAX; } - // Add 0's for interbit gap - for(uint32_t i=0;i<m_BITGAP_MID;i++) - { - byte<<=1; - bytecounter++; - if(bytecounter==8) - { - ftdidata.push_back(byte); - byte=0; - bytecounter=0; - } - } - } +void EndeavourRawFTDI::setDahMin(uint32_t DAH_MIN) { m_DAH_MIN = DAH_MIN; } + +uint32_t EndeavourRawFTDI::getDahMin() { return m_DAH_MIN; } + +void EndeavourRawFTDI::setDahMid(uint32_t DAH_MID) { m_DAH_MID = DAH_MID; } + +uint32_t EndeavourRawFTDI::getDahMid() { return m_DAH_MID; } + +void EndeavourRawFTDI::setDahMax(uint32_t DAH_MAX) { m_DAH_MAX = DAH_MAX; } + +uint32_t EndeavourRawFTDI::getDahMax() { return m_DAH_MAX; } - // Pad rest of the bits - ftdidata.resize(1024-3-20,0); - - // Prepare send package - uint16_t Length=ftdidata.size()-1; - ftdidata.insert(ftdidata.begin(),0x31); - ftdidata.insert(ftdidata.begin()+1,(Length>>0)&0xFF); - ftdidata.insert(ftdidata.begin()+2,(Length>>8)&0xFF); - for(uint32_t s=0; s<20; s++) // Padding of zero's to initialize the connection - ftdidata.insert(ftdidata.begin()+3+s,0x00); - //std::cout << "Command header: " << std::hex << (uint32_t)ftdidata[0] << " " << (uint32_t)ftdidata[1] << " " << (uint32_t)ftdidata[2] << std::dec << std::endl; - - // - // Start dealing with the FTDI - - // Make sure all buffers are clean - ftdi_usb_purge_buffers(m_ftdi); - - // Send the data - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - /* - std::cout << "writing" << std::hex << std::endl; - for(const uint16_t& x : ftdidata) - std::cout << std::setw(2) << std::setfill('0') << (uint32_t)x << std::endl; - std::cout << std::dec; - */ - - // Read back any response - ftdi_read_alldata(m_ftdi, ftdidata, 1021); - // std::cout << "reading" << std::hex << std::endl; - // for(const auto& x : ftdidata) - // std::cout << (uint32_t)x << std::endl; - // std::cout << std::dec; - - // - // Convert the stream into bits - std::bitset<1024*8> thebits; - uint32_t thebitssize=0; - - for(const uint8_t& x : ftdidata) - { - for(uint8_t i=8;i>0;i--) - { - bool bit=(x>>(i-1))&0x1; - thebits.set(thebitssize,bit); - thebitssize++; - } +void EndeavourRawFTDI::setBitGapMin(uint32_t BITGAP_MIN) { + m_BITGAP_MIN = BITGAP_MIN; +} + +uint32_t EndeavourRawFTDI::getBitGapMin() { return m_BITGAP_MIN; } + +void EndeavourRawFTDI::setBitGapMid(uint32_t BITGAP_MID) { + m_BITGAP_MID = BITGAP_MID; +} + +uint32_t EndeavourRawFTDI::getBitGapMid() { return m_BITGAP_MID; } + +void EndeavourRawFTDI::setBitGapMax(uint32_t BITGAP_MAX) { + m_BITGAP_MAX = BITGAP_MAX; +} + +uint32_t EndeavourRawFTDI::getBitGapMax() { return m_BITGAP_MAX; } + +void EndeavourRawFTDI::reset() {} + +bool EndeavourRawFTDI::isError() { return false; } + +bool EndeavourRawFTDI::isDataValid() { return m_readSize > 0; } + +void EndeavourRawFTDI::sendData(unsigned long long int data, + unsigned int size) { + std::vector<uint8_t> ftdidata; + + uint8_t bytecounter = 0, byte = 0; + for (uint32_t bit = size; bit > 0; bit--) { + bool value = (data >> (bit - 1)) & 1; + + // Add 1's for data + for (uint32_t i = 0; i < ((value) ? m_DAH_MID : m_DIT_MID); i++) { + byte <<= 1; + byte |= 1; + bytecounter++; + if (bytecounter == 8) { + ftdidata.push_back(byte); + byte = 0; + bytecounter = 0; + } + } + + // Add 0's for interbit gap + for (uint32_t i = 0; i < m_BITGAP_MID; i++) { + byte <<= 1; + bytecounter++; + if (bytecounter == 8) { + ftdidata.push_back(byte); + byte = 0; + bytecounter = 0; + } + } } - // - // Deglitch the stream - for(uint32_t i=1;i<thebitssize-1;i++) - if(thebits[i-1]==thebits[i+1]) - thebits.set(i,thebits[i+1]); - - // - // Parse the stream - m_readData=0; - m_readSize=0; - uint32_t countbit=0; - bool lastBit=0; - bool dataStarted=false; - //std::cout << "reading" << std::hex << std::endl; - for(uint32_t i=0;i<thebitssize;i++) - { - bool bit=thebits[i]; - if(bit!=lastBit) // something new is happening - { - if(lastBit==1) // Finished an endeavour bit - { - if(!dataStarted) - { // The first will be a long string of 1's - dataStarted=true; - } - else if(m_DIT_MIN<countbit && countbit<m_DIT_MAX) - { - m_readData<<=1; - m_readData|=0; - m_readSize++; - } - else if(m_DAH_MIN<countbit && countbit<m_DAH_MAX) - { - m_readData<<=1; - m_readData|=1; - m_readSize++; - } - else if(200<countbit) - { // Big stream at the end, potentially interrupted by noise - break; - } - } - countbit=0; - } - countbit++; - lastBit=bit; + // Pad rest of the bits + ftdidata.resize(1024 - 3 - 20, 0); + + // Prepare send package + uint16_t Length = ftdidata.size() - 1; + ftdidata.insert(ftdidata.begin(), 0x31); + ftdidata.insert(ftdidata.begin() + 1, (Length >> 0) & 0xFF); + ftdidata.insert(ftdidata.begin() + 2, (Length >> 8) & 0xFF); + for (uint32_t s = 0; s < 20; + s++) // Padding of zero's to initialize the connection + ftdidata.insert(ftdidata.begin() + 3 + s, 0x00); + // std::cout << "Command header: " << std::hex << (uint32_t)ftdidata[0] << " + // " << (uint32_t)ftdidata[1] << " " << (uint32_t)ftdidata[2] << std::dec << + // std::endl; + + // + // Start dealing with the FTDI + + // Make sure all buffers are clean + ftdi_usb_purge_buffers(m_ftdi); + + // Send the data + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + /* + std::cout << "writing" << std::hex << std::endl; + for(const uint16_t& x : ftdidata) + std::cout << std::setw(2) << std::setfill('0') << (uint32_t)x << + std::endl; std::cout << std::dec; + */ + + // Read back any response + ftdi_read_alldata(m_ftdi, ftdidata, 1021); + // std::cout << "reading" << std::hex << std::endl; + // for(const auto& x : ftdidata) + // std::cout << (uint32_t)x << std::endl; + // std::cout << std::dec; + + // + // Convert the stream into bits + std::bitset<1024 * 8> thebits; + uint32_t thebitssize = 0; + + for (const uint8_t& x : ftdidata) { + for (uint8_t i = 8; i > 0; i--) { + bool bit = (x >> (i - 1)) & 0x1; + thebits.set(thebitssize, bit); + thebitssize++; + } } -/* - // - // ReadSize = 0 is weird, since we alawys expect a response. Debug. - - if(m_readSize<8) - { - std::cout << "=== ZERO READ SIZE ===" << std::endl; - for(uint32_t i=0;i<1021;i++) - { - std::cout << std::hex; - std::cout << std::setw(2) << std::setfill('0') << (uint32_t)ftdidatain[i+3] << "\t" << std::setw(2) << std::setfill('0') << (uint32_t)ftdidata[i]; - std::cout << std::dec << std::endl; - } + + // + // Deglitch the stream + for (uint32_t i = 1; i < thebitssize - 1; i++) + if (thebits[i - 1] == thebits[i + 1]) thebits.set(i, thebits[i + 1]); + + // + // Parse the stream + m_readData = 0; + m_readSize = 0; + uint32_t countbit = 0; + bool lastBit = 0; + bool dataStarted = false; + // std::cout << "reading" << std::hex << std::endl; + for (uint32_t i = 0; i < thebitssize; i++) { + bool bit = thebits[i]; + if (bit != lastBit) // something new is happening + { + if (lastBit == 1) // Finished an endeavour bit + { + if (!dataStarted) { // The first will be a long string of 1's + dataStarted = true; + } else if (m_DIT_MIN < countbit && countbit < m_DIT_MAX) { + m_readData <<= 1; + m_readData |= 0; + m_readSize++; + } else if (m_DAH_MIN < countbit && countbit < m_DAH_MAX) { + m_readData <<= 1; + m_readData |= 1; + m_readSize++; + } else if (200 < + countbit) { // Big stream at the end, potentially + // interrupted by noise + break; + } + } + countbit = 0; + } + countbit++; + lastBit = bit; } -*/ + /* + // + // ReadSize = 0 is weird, since we alawys expect a response. Debug. + + if(m_readSize<8) + { + std::cout << "=== ZERO READ SIZE ===" << std::endl; + for(uint32_t i=0;i<1021;i++) + { + std::cout << std::hex; + std::cout << std::setw(2) << std::setfill('0') << + (uint32_t)ftdidatain[i+3] << "\t" << std::setw(2) << std::setfill('0') << + (uint32_t)ftdidata[i]; std::cout << std::dec << std::endl; + } + } + */ } -void EndeavourRawFTDI::readData(unsigned long long int& data, unsigned int& size) -{ - data=m_readData; - size=m_readSize; +void EndeavourRawFTDI::readData(unsigned long long int& data, + unsigned int& size) { + data = m_readData; + size = m_readSize; } -void EndeavourRawFTDI::setOF(bool value) -{ - std::vector<uint8_t> data; +void EndeavourRawFTDI::setOF(bool value) { + std::vector<uint8_t> data; - data={0x83}; - ftdi_write_data(m_ftdi, &data[0], data.size()); - ftdi_read_alldata(m_ftdi, data, 1); - uint8_t hbyte=data[0]; - - hbyte=(value)?(hbyte|(1<<0)):(hbyte&~(1<<0)); + data = {0x83}; + ftdi_write_data(m_ftdi, &data[0], data.size()); + ftdi_read_alldata(m_ftdi, data, 1); + uint8_t hbyte = data[0]; - data={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &data[0], data.size()); -} + hbyte = (value) ? (hbyte | (1 << 0)) : (hbyte & ~(1 << 0)); -std::shared_ptr<DACDevice> EndeavourRawFTDI::getDAC() const -{ return m_dac; } + data = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &data[0], data.size()); +} -std::shared_ptr<ADCDevice> EndeavourRawFTDI::getADC() const -{ return m_adc; } +std::shared_ptr<DACDevice> EndeavourRawFTDI::getDAC() const { return m_dac; } +std::shared_ptr<ADCDevice> EndeavourRawFTDI::getADC() const { return m_adc; } diff --git a/pbv3/EndeavourRawFTDI.h b/pbv3/EndeavourRawFTDI.h index 454a4a11b9efa1c99fece3e0b55e2576e6b7897d..41402f669751a20096bb778fc57a37f7d210fadb 100644 --- a/pbv3/EndeavourRawFTDI.h +++ b/pbv3/EndeavourRawFTDI.h @@ -3,85 +3,88 @@ #include <memory> -#include "DACDevice.h" #include "ADCDevice.h" - +#include "DACDevice.h" #include "EndeavourRaw.h" #include "PBv3CommPatchSPICom.h" -class EndeavourRawFTDI : public EndeavourRaw -{ -public: - /** - * \param description Product description used to identify device to open communication with (leave blank for none) - * \param serial Serial number used to identify device to open communication with (leave blank for none) - */ - EndeavourRawFTDI(const std::string& description="", const std::string& serial=""); - ~EndeavourRawFTDI(); +class EndeavourRawFTDI : public EndeavourRaw { + public: + /** + * \param description Product description used to identify device to open + * communication with (leave blank for none) \param serial Serial number + * used to identify device to open communication with (leave blank for none) + */ + EndeavourRawFTDI(const std::string& description = "", + const std::string& serial = ""); + ~EndeavourRawFTDI(); + + // + // Endeavour communication + void setDitMin(uint32_t DIT_MIN); + uint32_t getDitMin(); - // - // Endeavour communication - void setDitMin(uint32_t DIT_MIN); - uint32_t getDitMin(); + void setDitMid(uint32_t DIT_MID); + uint32_t getDitMid(); - void setDitMid(uint32_t DIT_MID); - uint32_t getDitMid(); + void setDitMax(uint32_t DIT_MAX); + uint32_t getDitMax(); - void setDitMax(uint32_t DIT_MAX); - uint32_t getDitMax(); + void setDahMin(uint32_t DAH_MIN); + uint32_t getDahMin(); - void setDahMin(uint32_t DAH_MIN); - uint32_t getDahMin(); + void setDahMid(uint32_t DAH_MID); + uint32_t getDahMid(); - void setDahMid(uint32_t DAH_MID); - uint32_t getDahMid(); + void setDahMax(uint32_t DAH_MAX); + uint32_t getDahMax(); - void setDahMax(uint32_t DAH_MAX); - uint32_t getDahMax(); + void setBitGapMin(uint32_t BITGAP_MIN); + uint32_t getBitGapMin(); - void setBitGapMin(uint32_t BITGAP_MIN); - uint32_t getBitGapMin(); + void setBitGapMid(uint32_t BITGAP_MID); + uint32_t getBitGapMid(); - void setBitGapMid(uint32_t BITGAP_MID); - uint32_t getBitGapMid(); + void setBitGapMax(uint32_t BITGAP_MAX); + uint32_t getBitGapMax(); - void setBitGapMax(uint32_t BITGAP_MAX); - uint32_t getBitGapMax(); - - void reset(); + void reset(); - void sendData(unsigned long long int data, unsigned int size); + void sendData(unsigned long long int data, unsigned int size); - bool isError(); - bool isDataValid(); - void readData(unsigned long long int& data, unsigned int& size); + bool isError(); + bool isDataValid(); + void readData(unsigned long long int& data, unsigned int& size); - // - // GPIO pins - void setOF(bool value); + // + // GPIO pins + void setOF(bool value); - // - // SPI devices - std::shared_ptr<DACDevice> getDAC() const; - std::shared_ptr<ADCDevice> getADC() const; + // + // SPI devices + std::shared_ptr<DACDevice> getDAC() const; + std::shared_ptr<ADCDevice> getADC() const; -private: - uint32_t m_DIT_MIN = 6*30/40,m_DIT_MID = 14*30/40,m_DIT_MAX = 22*30/40; - uint32_t m_DAH_MIN = 29*30/40,m_DAH_MID = 76*30/40,m_DAH_MAX =124*30/40; - uint32_t m_BITGAP_MIN= 11*30/40,m_BITGAP_MID= 43*30/40,m_BITGAP_MAX= 75*30/40; + private: + uint32_t m_DIT_MIN = 6 * 30 / 40, m_DIT_MID = 14 * 30 / 40, + m_DIT_MAX = 22 * 30 / 40; + uint32_t m_DAH_MIN = 29 * 30 / 40, m_DAH_MID = 76 * 30 / 40, + m_DAH_MAX = 124 * 30 / 40; + uint32_t m_BITGAP_MIN = 11 * 30 / 40, m_BITGAP_MID = 43 * 30 / 40, + m_BITGAP_MAX = 75 * 30 / 40; - struct ftdi_context *m_ftdi; + struct ftdi_context* m_ftdi; - // Last returned data - unsigned long long int m_readData; - unsigned int m_readSize; + // Last returned data + unsigned long long int m_readData; + unsigned int m_readSize; - // SPI devices - std::shared_ptr<PBv3CommPatchSPICom> m_spiADC; - std::shared_ptr<PBv3CommPatchSPICom> m_spiDAC; + // SPI devices + std::shared_ptr<PBv3CommPatchSPICom> m_spiADC; + std::shared_ptr<PBv3CommPatchSPICom> m_spiDAC; - std::shared_ptr<DACDevice> m_dac; - std::shared_ptr<ADCDevice> m_adc; + std::shared_ptr<DACDevice> m_dac; + std::shared_ptr<ADCDevice> m_adc; }; -#endif //ENDEAVOURRAWFTDI_H +#endif // ENDEAVOURRAWFTDI_H diff --git a/pbv3/EndeavourRawITSDAQ.cpp b/pbv3/EndeavourRawITSDAQ.cpp index cb807fcae1e947cc34d6a4edc219d14942c5a115..7217d147444005ea108f8ef6f7e217153aa8570a 100644 --- a/pbv3/EndeavourRawITSDAQ.cpp +++ b/pbv3/EndeavourRawITSDAQ.cpp @@ -1,184 +1,190 @@ #include "EndeavourRawITSDAQ.h" +#include <iomanip> +#include <iostream> + #include "EndeavourComException.h" #include "NotSupportedException.h" -#include <iostream> -#include <iomanip> - // More info on the ITSDAQ op-codes // https://twiki.cern.ch/twiki/bin/view/Atlas/ITSDAQDataFormat#EMORSE #define CMD_SETID 0b110 #define CMD_WRITE 0b111 -#define CMD_READ 0b101 +#define CMD_READ 0b101 EndeavourRawITSDAQ::EndeavourRawITSDAQ(std::shared_ptr<ITSDAQCom> com) - : m_com(com) -{ } + : m_com(com) {} -EndeavourRawITSDAQ::~EndeavourRawITSDAQ() -{ } +EndeavourRawITSDAQ::~EndeavourRawITSDAQ() {} -void EndeavourRawITSDAQ::setDitMin(uint32_t DIT_MIN) -{ throw NotSupportedException("Variable length dits not supported."); } +void EndeavourRawITSDAQ::setDitMin(uint32_t DIT_MIN) { + throw NotSupportedException("Variable length dits not supported."); +} -uint32_t EndeavourRawITSDAQ::getDitMin() -{ throw NotSupportedException("Variable length dits not supported."); } +uint32_t EndeavourRawITSDAQ::getDitMin() { + throw NotSupportedException("Variable length dits not supported."); +} -void EndeavourRawITSDAQ::setDitMid(uint32_t DIT_MID) -{ throw NotSupportedException("Variable length dits not supported."); } +void EndeavourRawITSDAQ::setDitMid(uint32_t DIT_MID) { + throw NotSupportedException("Variable length dits not supported."); +} -uint32_t EndeavourRawITSDAQ::getDitMid() -{ throw NotSupportedException("Variable length dits not supported."); } +uint32_t EndeavourRawITSDAQ::getDitMid() { + throw NotSupportedException("Variable length dits not supported."); +} -void EndeavourRawITSDAQ::setDitMax(uint32_t DIT_MAX) -{ throw NotSupportedException("Variable length dits not supported."); } +void EndeavourRawITSDAQ::setDitMax(uint32_t DIT_MAX) { + throw NotSupportedException("Variable length dits not supported."); +} -uint32_t EndeavourRawITSDAQ::getDitMax() -{ throw NotSupportedException("Variable length dits not supported."); } +uint32_t EndeavourRawITSDAQ::getDitMax() { + throw NotSupportedException("Variable length dits not supported."); +} -void EndeavourRawITSDAQ::setDahMin(uint32_t DAH_MIN) -{ throw NotSupportedException("Variable length dahs not supported."); } +void EndeavourRawITSDAQ::setDahMin(uint32_t DAH_MIN) { + throw NotSupportedException("Variable length dahs not supported."); +} -uint32_t EndeavourRawITSDAQ::getDahMin() -{ throw NotSupportedException("Variable length dahs not supported."); } +uint32_t EndeavourRawITSDAQ::getDahMin() { + throw NotSupportedException("Variable length dahs not supported."); +} -void EndeavourRawITSDAQ::setDahMid(uint32_t DAH_MID) -{ throw NotSupportedException("Variable length dahs not supported."); } +void EndeavourRawITSDAQ::setDahMid(uint32_t DAH_MID) { + throw NotSupportedException("Variable length dahs not supported."); +} -uint32_t EndeavourRawITSDAQ::getDahMid() -{ throw NotSupportedException("Variable length dahs not supported."); } +uint32_t EndeavourRawITSDAQ::getDahMid() { + throw NotSupportedException("Variable length dahs not supported."); +} -void EndeavourRawITSDAQ::setDahMax(uint32_t DAH_MAX) -{ throw NotSupportedException("Variable length dahs not supported."); } +void EndeavourRawITSDAQ::setDahMax(uint32_t DAH_MAX) { + throw NotSupportedException("Variable length dahs not supported."); +} -uint32_t EndeavourRawITSDAQ::getDahMax() -{ throw NotSupportedException("Variable length dahs not supported."); } +uint32_t EndeavourRawITSDAQ::getDahMax() { + throw NotSupportedException("Variable length dahs not supported."); +} -void EndeavourRawITSDAQ::setBitGapMin(uint32_t BITGAP_MIN) -{ throw NotSupportedException("Variable length bit gap not supported."); } +void EndeavourRawITSDAQ::setBitGapMin(uint32_t BITGAP_MIN) { + throw NotSupportedException("Variable length bit gap not supported."); +} -uint32_t EndeavourRawITSDAQ::getBitGapMin() -{ throw NotSupportedException("Variable length bit gap not supported."); } +uint32_t EndeavourRawITSDAQ::getBitGapMin() { + throw NotSupportedException("Variable length bit gap not supported."); +} -void EndeavourRawITSDAQ::setBitGapMid(uint32_t BITGAP_MID) -{ throw NotSupportedException("Variable length bit gap not supported."); } +void EndeavourRawITSDAQ::setBitGapMid(uint32_t BITGAP_MID) { + throw NotSupportedException("Variable length bit gap not supported."); +} -uint32_t EndeavourRawITSDAQ::getBitGapMid() -{ throw NotSupportedException("Variable length bit gap not supported."); } +uint32_t EndeavourRawITSDAQ::getBitGapMid() { + throw NotSupportedException("Variable length bit gap not supported."); +} -void EndeavourRawITSDAQ::setBitGapMax(uint32_t BITGAP_MAX) -{ throw NotSupportedException("Variable length bit gap not supported."); } +void EndeavourRawITSDAQ::setBitGapMax(uint32_t BITGAP_MAX) { + throw NotSupportedException("Variable length bit gap not supported."); +} -uint32_t EndeavourRawITSDAQ::getBitGapMax() -{ throw NotSupportedException("Variable length bit gap not supported."); } +uint32_t EndeavourRawITSDAQ::getBitGapMax() { + throw NotSupportedException("Variable length bit gap not supported."); +} -void EndeavourRawITSDAQ::reset() -{ } +void EndeavourRawITSDAQ::reset() {} -bool EndeavourRawITSDAQ::isError() -{ return m_error; } +bool EndeavourRawITSDAQ::isError() { return m_error; } -bool EndeavourRawITSDAQ::isDataValid() -{ return m_valid; } +bool EndeavourRawITSDAQ::isDataValid() { return m_valid; } -void EndeavourRawITSDAQ::sendData(unsigned long long int data, unsigned int size) -{ - m_valid=false; - m_error=false; +void EndeavourRawITSDAQ::sendData(unsigned long long int data, + unsigned int size) { + m_valid = false; + m_error = false; - // Determine command type (â—”_â—”) - uint8_t cmd=(data>>(size-3))&0x7; - if(cmd!=CMD_SETID && cmd!=CMD_WRITE && cmd!=CMD_READ) - throw EndeavourComException("Trying to send an unknown command: %02x",cmd); + // Determine command type (â—”_â—”) + uint8_t cmd = (data >> (size - 3)) & 0x7; + if (cmd != CMD_SETID && cmd != CMD_WRITE && cmd != CMD_READ) + throw EndeavourComException("Trying to send an unknown command: %02x", + cmd); - // - // Build network packet - // - // Send data - std::vector<uint16_t> inBuffer(7); + // + // Build network packet + // + // Send data + std::vector<uint16_t> inBuffer(7); - // header - uint16_t chan=0; // TODO unhardcode - inBuffer[0]=0x0000; //version - inBuffer[1]=chan & 0xf; //control - inBuffer[2]=0x0000; //spare + // header + uint16_t chan = 0; // TODO unhardcode + inBuffer[0] = 0x0000; // version + inBuffer[1] = chan & 0xf; // control + inBuffer[2] = 0x0000; // spare - // packet data - uint64_t dataBlock=data|(((uint64_t)(cmd==CMD_READ))<<56); - inBuffer[3]=((dataBlock>>48)&0xFFFF); - inBuffer[4]=((dataBlock>>32)&0xFFFF); - inBuffer[5]=((dataBlock>>16)&0xFFFF); - inBuffer[6]=((dataBlock>> 0)&0xFFFF); + // packet data + uint64_t dataBlock = data | (((uint64_t)(cmd == CMD_READ)) << 56); + inBuffer[3] = ((dataBlock >> 48) & 0xFFFF); + inBuffer[4] = ((dataBlock >> 32) & 0xFFFF); + inBuffer[5] = ((dataBlock >> 16) & 0xFFFF); + inBuffer[6] = ((dataBlock >> 0) & 0xFFFF); - ITSDAQPacket packet(0, {ITSDAQOpCode(0, ITSDAQ_OPCODE_EMORSE, inBuffer)}); - m_com->send(packet); + ITSDAQPacket packet(0, {ITSDAQOpCode(0, ITSDAQ_OPCODE_EMORSE, inBuffer)}); + m_com->send(packet); - // - // Receive data - packet=m_com->receive(); + // + // Receive data + packet = m_com->receive(); - if(packet.nOpcodes()==0) - throw EndeavourComException("ITSDAQ returned no data"); + if (packet.nOpcodes() == 0) + throw EndeavourComException("ITSDAQ returned no data"); - // Parse result - ITSDAQOpCode opcode=packet.opcode(0); - std::vector<uint16_t> payload=opcode.payload(); + // Parse result + ITSDAQOpCode opcode = packet.opcode(0); + std::vector<uint16_t> payload = opcode.payload(); - // - // Reconstruct the AMAC response - uint64_t code=(payload[3]>>12)&0x0F; //timeout or error - uint64_t amac=(payload[4]>>11)&0x1F; - uint64_t addr=(payload[4]>> 0)&0xFF; - uint64_t regv=(((uint64_t)payload[5])<<16 | payload[6]); + // + // Reconstruct the AMAC response + uint64_t code = (payload[3] >> 12) & 0x0F; // timeout or error + uint64_t amac = (payload[4] >> 11) & 0x1F; + uint64_t addr = (payload[4] >> 0) & 0xFF; + uint64_t regv = (((uint64_t)payload[5]) << 16 | payload[6]); - if(code==0xF) // Timeout! + if (code == 0xF) // Timeout! { - m_valid=false; - return; + m_valid = false; + return; } - switch(cmd) - { - case CMD_SETID: - { - uint64_t retid=(payload[6]>>3)&0x1F; - m_readData=(retid<<3)|(((uint64_t)0)<<0); - m_readSize=8; - m_valid=true; - m_error=false; - } - break; - case CMD_WRITE: - { - // ITSDAQ firmware does not return AMAC ID - amac=(((data>>8)>>32)>>8)&0x1F; - m_readData=(amac<<3)|(((uint64_t)0)<<0); - m_readSize=8; - m_valid=true; - m_error=false; - } - break; - case CMD_READ: - { - m_readData=(amac<<43)|(((uint64_t)0)<<40)|(addr<<32)|(regv<< 0); - m_readSize=48; - m_valid=true; - m_error=false; - } - break; - default: - { - m_valid=false; - m_error=true; - } - break; + switch (cmd) { + case CMD_SETID: { + uint64_t retid = (payload[6] >> 3) & 0x1F; + m_readData = (retid << 3) | (((uint64_t)0) << 0); + m_readSize = 8; + m_valid = true; + m_error = false; + } break; + case CMD_WRITE: { + // ITSDAQ firmware does not return AMAC ID + amac = (((data >> 8) >> 32) >> 8) & 0x1F; + m_readData = (amac << 3) | (((uint64_t)0) << 0); + m_readSize = 8; + m_valid = true; + m_error = false; + } break; + case CMD_READ: { + m_readData = (amac << 43) | (((uint64_t)0) << 40) | (addr << 32) | + (regv << 0); + m_readSize = 48; + m_valid = true; + m_error = false; + } break; + default: { + m_valid = false; + m_error = true; + } break; } } -void EndeavourRawITSDAQ::readData(unsigned long long int& data, unsigned int& size) -{ - data=m_readData; - size=m_readSize; +void EndeavourRawITSDAQ::readData(unsigned long long int& data, + unsigned int& size) { + data = m_readData; + size = m_readSize; } diff --git a/pbv3/EndeavourRawITSDAQ.h b/pbv3/EndeavourRawITSDAQ.h index 925c93fa871e641020805d86f39de040a693c515..45ad1f8a63e60f4b023518da0018a7cf773c2148 100644 --- a/pbv3/EndeavourRawITSDAQ.h +++ b/pbv3/EndeavourRawITSDAQ.h @@ -3,64 +3,62 @@ #include <memory> +#include "EndeavourRaw.h" #include "ITSDAQCom.h" -#include "EndeavourRaw.h" +class EndeavourRawITSDAQ : public EndeavourRaw { + public: + EndeavourRawITSDAQ(std::shared_ptr<ITSDAQCom> com); + ~EndeavourRawITSDAQ(); -class EndeavourRawITSDAQ : public EndeavourRaw -{ -public: - EndeavourRawITSDAQ(std::shared_ptr<ITSDAQCom> com); - ~EndeavourRawITSDAQ(); + // + // Endeavour communication + void setDitMin(uint32_t DIT_MIN); + uint32_t getDitMin(); - // - // Endeavour communication - void setDitMin(uint32_t DIT_MIN); - uint32_t getDitMin(); + void setDitMid(uint32_t DIT_MID); + uint32_t getDitMid(); - void setDitMid(uint32_t DIT_MID); - uint32_t getDitMid(); + void setDitMax(uint32_t DIT_MAX); + uint32_t getDitMax(); - void setDitMax(uint32_t DIT_MAX); - uint32_t getDitMax(); + void setDahMin(uint32_t DAH_MIN); + uint32_t getDahMin(); - void setDahMin(uint32_t DAH_MIN); - uint32_t getDahMin(); + void setDahMid(uint32_t DAH_MID); + uint32_t getDahMid(); - void setDahMid(uint32_t DAH_MID); - uint32_t getDahMid(); + void setDahMax(uint32_t DAH_MAX); + uint32_t getDahMax(); - void setDahMax(uint32_t DAH_MAX); - uint32_t getDahMax(); + void setBitGapMin(uint32_t BITGAP_MIN); + uint32_t getBitGapMin(); - void setBitGapMin(uint32_t BITGAP_MIN); - uint32_t getBitGapMin(); + void setBitGapMid(uint32_t BITGAP_MID); + uint32_t getBitGapMid(); - void setBitGapMid(uint32_t BITGAP_MID); - uint32_t getBitGapMid(); + void setBitGapMax(uint32_t BITGAP_MAX); + uint32_t getBitGapMax(); - void setBitGapMax(uint32_t BITGAP_MAX); - uint32_t getBitGapMax(); - - void reset(); + void reset(); - void sendData(unsigned long long int data, unsigned int size); + void sendData(unsigned long long int data, unsigned int size); - bool isError(); - bool isDataValid(); - void readData(unsigned long long int& data, unsigned int& size); + bool isError(); + bool isDataValid(); + void readData(unsigned long long int& data, unsigned int& size); -private: - // Last returned data - bool m_valid=false; - bool m_error=false; + private: + // Last returned data + bool m_valid = false; + bool m_error = false; - unsigned long long int m_readData; - unsigned int m_readSize; + unsigned long long int m_readData; + unsigned int m_readSize; - // ITSDAQ communication - std::shared_ptr<ITSDAQCom> m_com=nullptr; - uint16_t m_seqnum=0; + // ITSDAQ communication + std::shared_ptr<ITSDAQCom> m_com = nullptr; + uint16_t m_seqnum = 0; }; -#endif //ENDEAVOURRAWITSDAQ_H +#endif // ENDEAVOURRAWITSDAQ_H diff --git a/pbv3/EndeavourRawUIO.cpp b/pbv3/EndeavourRawUIO.cpp index 1e63db852bc2f9d4771ade0ea6663891b399a2b9..9f32087131706737edca61799673e3866594d2a8 100644 --- a/pbv3/EndeavourRawUIO.cpp +++ b/pbv3/EndeavourRawUIO.cpp @@ -1,158 +1,148 @@ #include "EndeavourRawUIO.h" EndeavourRawUIO::EndeavourRawUIO(std::shared_ptr<DeviceCom> fpgaCom) - : m_fpgaCom(fpgaCom) -{ - // Initialize default values (Note: FPGA clock = 100MHz, AMACv2 clock = 40MHz) - setDitMin( 6*100./40.); - setDitMid( 14*100./40.); - setDitMax( 22*100./40.); - - setDahMin( 29*100./40.); - setDahMid( 76*100./40.); - setDahMax(124*100./40.); - - setBitGapMin( 11*100./40.); - setBitGapMid( 43*100./40.); - setBitGapMax( 75*100./40.); - + : m_fpgaCom(fpgaCom) { + // Initialize default values (Note: FPGA clock = 100MHz, AMACv2 clock = + // 40MHz) + setDitMin(6 * 100. / 40.); + setDitMid(14 * 100. / 40.); + setDitMax(22 * 100. / 40.); + + setDahMin(29 * 100. / 40.); + setDahMid(76 * 100. / 40.); + setDahMax(124 * 100. / 40.); + + setBitGapMin(11 * 100. / 40.); + setBitGapMid(43 * 100. / 40.); + setBitGapMax(75 * 100. / 40.); } -void EndeavourRawUIO::setDitMin(uint32_t DIT_MIN) -{ - uint32_t val=m_fpgaCom->read_reg32(7); - val=(val&0xFFFFFF00)|((DIT_MIN&0x0FF)<< 0); - m_fpgaCom->write_reg32(7, val); +void EndeavourRawUIO::setDitMin(uint32_t DIT_MIN) { + uint32_t val = m_fpgaCom->read_reg32(7); + val = (val & 0xFFFFFF00) | ((DIT_MIN & 0x0FF) << 0); + m_fpgaCom->write_reg32(7, val); } -uint32_t EndeavourRawUIO::getDitMin() -{ return (m_fpgaCom->read_reg32(7)>> 0)&0x0FF; } +uint32_t EndeavourRawUIO::getDitMin() { + return (m_fpgaCom->read_reg32(7) >> 0) & 0x0FF; +} -void EndeavourRawUIO::setDitMid(uint32_t DIT_MID) -{ - uint32_t val=m_fpgaCom->read_reg32(7); - val=(val&0xFFF000FF)|((DIT_MID&0xFFF)<< 8); - m_fpgaCom->write_reg32(7, val); +void EndeavourRawUIO::setDitMid(uint32_t DIT_MID) { + uint32_t val = m_fpgaCom->read_reg32(7); + val = (val & 0xFFF000FF) | ((DIT_MID & 0xFFF) << 8); + m_fpgaCom->write_reg32(7, val); } -uint32_t EndeavourRawUIO::getDitMid() -{ return (m_fpgaCom->read_reg32(7)>> 8)&0xFFF; } +uint32_t EndeavourRawUIO::getDitMid() { + return (m_fpgaCom->read_reg32(7) >> 8) & 0xFFF; +} -void EndeavourRawUIO::setDitMax(uint32_t DIT_MAX) -{ - uint32_t val=m_fpgaCom->read_reg32(7); - val=(val&0x000FFFFF)|((DIT_MAX&0xFFF)<<20); - m_fpgaCom->write_reg32(7, val); +void EndeavourRawUIO::setDitMax(uint32_t DIT_MAX) { + uint32_t val = m_fpgaCom->read_reg32(7); + val = (val & 0x000FFFFF) | ((DIT_MAX & 0xFFF) << 20); + m_fpgaCom->write_reg32(7, val); } -uint32_t EndeavourRawUIO::getDitMax() -{ return (m_fpgaCom->read_reg32(7)>>16)&0xFFF; } +uint32_t EndeavourRawUIO::getDitMax() { + return (m_fpgaCom->read_reg32(7) >> 16) & 0xFFF; +} -void EndeavourRawUIO::setDahMin(uint32_t DAH_MIN) -{ - uint32_t val=m_fpgaCom->read_reg32(8); - val=(val&0xFFFFFF00)|((DAH_MIN&0x0FF)<< 0); - m_fpgaCom->write_reg32(8, val); +void EndeavourRawUIO::setDahMin(uint32_t DAH_MIN) { + uint32_t val = m_fpgaCom->read_reg32(8); + val = (val & 0xFFFFFF00) | ((DAH_MIN & 0x0FF) << 0); + m_fpgaCom->write_reg32(8, val); } -uint32_t EndeavourRawUIO::getDahMin() -{ return (m_fpgaCom->read_reg32(8)>> 0)&0x0FF; } +uint32_t EndeavourRawUIO::getDahMin() { + return (m_fpgaCom->read_reg32(8) >> 0) & 0x0FF; +} -void EndeavourRawUIO::setDahMid(uint32_t DAH_MID) -{ - uint32_t val=m_fpgaCom->read_reg32(8); - val=(val&0xFFF000FF)|((DAH_MID&0xFFF)<< 8); - m_fpgaCom->write_reg32(8, val); +void EndeavourRawUIO::setDahMid(uint32_t DAH_MID) { + uint32_t val = m_fpgaCom->read_reg32(8); + val = (val & 0xFFF000FF) | ((DAH_MID & 0xFFF) << 8); + m_fpgaCom->write_reg32(8, val); } -uint32_t EndeavourRawUIO::getDahMid() -{ return (m_fpgaCom->read_reg32(8)>> 8)&0xFFF; } +uint32_t EndeavourRawUIO::getDahMid() { + return (m_fpgaCom->read_reg32(8) >> 8) & 0xFFF; +} -void EndeavourRawUIO::setDahMax(uint32_t DAH_MAX) -{ - uint32_t val=m_fpgaCom->read_reg32(8); - val=(val&0x000FFFFF)|((DAH_MAX&0xFFF)<<20); - m_fpgaCom->write_reg32(8, val); +void EndeavourRawUIO::setDahMax(uint32_t DAH_MAX) { + uint32_t val = m_fpgaCom->read_reg32(8); + val = (val & 0x000FFFFF) | ((DAH_MAX & 0xFFF) << 20); + m_fpgaCom->write_reg32(8, val); } -uint32_t EndeavourRawUIO::getDahMax() -{ return (m_fpgaCom->read_reg32(8)>>16)&0xFFF; } +uint32_t EndeavourRawUIO::getDahMax() { + return (m_fpgaCom->read_reg32(8) >> 16) & 0xFFF; +} -void EndeavourRawUIO::setBitGapMin(uint32_t BITGAP_MIN) -{ - uint32_t val=m_fpgaCom->read_reg32(9); - val=(val&0xFFFFFF00)|((BITGAP_MIN&0x0FF)<< 0); - m_fpgaCom->write_reg32(9, val); +void EndeavourRawUIO::setBitGapMin(uint32_t BITGAP_MIN) { + uint32_t val = m_fpgaCom->read_reg32(9); + val = (val & 0xFFFFFF00) | ((BITGAP_MIN & 0x0FF) << 0); + m_fpgaCom->write_reg32(9, val); } -uint32_t EndeavourRawUIO::getBitGapMin() -{ return (m_fpgaCom->read_reg32(9)>> 0)&0x0FF; } +uint32_t EndeavourRawUIO::getBitGapMin() { + return (m_fpgaCom->read_reg32(9) >> 0) & 0x0FF; +} -void EndeavourRawUIO::setBitGapMid(uint32_t BITGAP_MID) -{ - uint32_t val=m_fpgaCom->read_reg32(9); - val=(val&0xFFF000FF)|((BITGAP_MID&0xFFF)<< 8); - m_fpgaCom->write_reg32(9, val); +void EndeavourRawUIO::setBitGapMid(uint32_t BITGAP_MID) { + uint32_t val = m_fpgaCom->read_reg32(9); + val = (val & 0xFFF000FF) | ((BITGAP_MID & 0xFFF) << 8); + m_fpgaCom->write_reg32(9, val); } -uint32_t EndeavourRawUIO::getBitGapMid() -{ return (m_fpgaCom->read_reg32(9)>> 8)&0xFFF; } +uint32_t EndeavourRawUIO::getBitGapMid() { + return (m_fpgaCom->read_reg32(9) >> 8) & 0xFFF; +} -void EndeavourRawUIO::setBitGapMax(uint32_t BITGAP_MAX) -{ - uint32_t val=m_fpgaCom->read_reg32(9); - val=(val&0x000FFFFF)|((BITGAP_MAX&0xFFF)<<20); - m_fpgaCom->write_reg32(9, val); +void EndeavourRawUIO::setBitGapMax(uint32_t BITGAP_MAX) { + uint32_t val = m_fpgaCom->read_reg32(9); + val = (val & 0x000FFFFF) | ((BITGAP_MAX & 0xFFF) << 20); + m_fpgaCom->write_reg32(9, val); } -uint32_t EndeavourRawUIO::getBitGapMax() -{ return (m_fpgaCom->read_reg32(9)>>16)&0xFFF; } +uint32_t EndeavourRawUIO::getBitGapMax() { + return (m_fpgaCom->read_reg32(9) >> 16) & 0xFFF; +} -void EndeavourRawUIO::invertCMDin(bool value) -{ - uint32_t curval=m_fpgaCom->read_reg32(10); - curval=(curval&0xFFFFFFFE)|(value<<0); - m_fpgaCom->write_reg32(10,curval); +void EndeavourRawUIO::invertCMDin(bool value) { + uint32_t curval = m_fpgaCom->read_reg32(10); + curval = (curval & 0xFFFFFFFE) | (value << 0); + m_fpgaCom->write_reg32(10, curval); } -void EndeavourRawUIO::invertCMDout(bool value) -{ - uint32_t curval=m_fpgaCom->read_reg32(10); - curval=(curval&0xFFFFFFFD)|(value<<1); - m_fpgaCom->write_reg32(10,curval); +void EndeavourRawUIO::invertCMDout(bool value) { + uint32_t curval = m_fpgaCom->read_reg32(10); + curval = (curval & 0xFFFFFFFD) | (value << 1); + m_fpgaCom->write_reg32(10, curval); } -void EndeavourRawUIO::reset() -{ m_fpgaCom->write_reg32(0, 0x1); } +void EndeavourRawUIO::reset() { m_fpgaCom->write_reg32(0, 0x1); } -bool EndeavourRawUIO::isError() -{ return (m_fpgaCom->read_reg32(0)>>2)&1; } +bool EndeavourRawUIO::isError() { return (m_fpgaCom->read_reg32(0) >> 2) & 1; } -bool EndeavourRawUIO::isDataValid() -{ - return (m_fpgaCom->read_reg32(0)>>1)&1; +bool EndeavourRawUIO::isDataValid() { + return (m_fpgaCom->read_reg32(0) >> 1) & 1; } -void EndeavourRawUIO::sendData(unsigned long long int data, unsigned int size) -{ - m_fpgaCom->write_reg32(1, size); - m_fpgaCom->write_reg32(2, (data>>0 )&0xFFFFFFFF); - m_fpgaCom->write_reg32(3, (data>>32)&0xFFFFFFFF); - m_fpgaCom->write_reg32(0, 0x2); +void EndeavourRawUIO::sendData(unsigned long long int data, unsigned int size) { + m_fpgaCom->write_reg32(1, size); + m_fpgaCom->write_reg32(2, (data >> 0) & 0xFFFFFFFF); + m_fpgaCom->write_reg32(3, (data >> 32) & 0xFFFFFFFF); + m_fpgaCom->write_reg32(0, 0x2); } -void EndeavourRawUIO::readData(unsigned long long int& data, unsigned int& size) -{ - if(isDataValid()) - { - size=m_fpgaCom->read_reg32(4); - data=m_fpgaCom->read_reg32(6); - data<<=32; - data|=m_fpgaCom->read_reg32(5); - } - else - { - size=0; - data=0; +void EndeavourRawUIO::readData(unsigned long long int& data, + unsigned int& size) { + if (isDataValid()) { + size = m_fpgaCom->read_reg32(4); + data = m_fpgaCom->read_reg32(6); + data <<= 32; + data |= m_fpgaCom->read_reg32(5); + } else { + size = 0; + data = 0; } } diff --git a/pbv3/EndeavourRawUIO.h b/pbv3/EndeavourRawUIO.h index a7b24159ad65f6baf916754bfaaf89091a73c43d..86943159cd8dcf75fdd921c47b238bd940824c3d 100644 --- a/pbv3/EndeavourRawUIO.h +++ b/pbv3/EndeavourRawUIO.h @@ -6,62 +6,61 @@ #include "DeviceCom.h" #include "EndeavourRaw.h" -class EndeavourRawUIO : public EndeavourRaw -{ -public: - EndeavourRawUIO(std::shared_ptr<DeviceCom> fpgaCom); +class EndeavourRawUIO : public EndeavourRaw { + public: + EndeavourRawUIO(std::shared_ptr<DeviceCom> fpgaCom); - void setDitMin(uint32_t DIT_MIN); - uint32_t getDitMin(); + void setDitMin(uint32_t DIT_MIN); + uint32_t getDitMin(); - void setDitMid(uint32_t DIT_MID); - uint32_t getDitMid(); + void setDitMid(uint32_t DIT_MID); + uint32_t getDitMid(); - void setDitMax(uint32_t DIT_MAX); - uint32_t getDitMax(); + void setDitMax(uint32_t DIT_MAX); + uint32_t getDitMax(); - void setDahMin(uint32_t DAH_MIN); - uint32_t getDahMin(); + void setDahMin(uint32_t DAH_MIN); + uint32_t getDahMin(); - void setDahMid(uint32_t DAH_MID); - uint32_t getDahMid(); + void setDahMid(uint32_t DAH_MID); + uint32_t getDahMid(); - void setDahMax(uint32_t DAH_MAX); - uint32_t getDahMax(); + void setDahMax(uint32_t DAH_MAX); + uint32_t getDahMax(); - void setBitGapMin(uint32_t BITGAP_MIN); - uint32_t getBitGapMin(); + void setBitGapMin(uint32_t BITGAP_MIN); + uint32_t getBitGapMin(); - void setBitGapMid(uint32_t BITGAP_MID); - uint32_t getBitGapMid(); + void setBitGapMid(uint32_t BITGAP_MID); + uint32_t getBitGapMid(); - void setBitGapMax(uint32_t BITGAP_MAX); - uint32_t getBitGapMax(); + void setBitGapMax(uint32_t BITGAP_MAX); + uint32_t getBitGapMax(); - /** - * Invert poliary of the CMDin lines - * - * \param value True if invert, false otherwise - */ - void invertCMDin (bool value); + /** + * Invert poliary of the CMDin lines + * + * \param value True if invert, false otherwise + */ + void invertCMDin(bool value); - /** - * Invert poliary of the CMDout lines - * - * \param value True if invert, false otherwise - */ - void invertCMDout(bool value); - - void reset(); + /** + * Invert poliary of the CMDout lines + * + * \param value True if invert, false otherwise + */ + void invertCMDout(bool value); - void sendData(unsigned long long int data, unsigned int size); + void reset(); - bool isError(); - bool isDataValid(); - void readData(unsigned long long int& data, unsigned int& size); + void sendData(unsigned long long int data, unsigned int size); -private: - std::shared_ptr<DeviceCom> m_fpgaCom; + bool isError(); + bool isDataValid(); + void readData(unsigned long long int& data, unsigned int& size); + + private: + std::shared_ptr<DeviceCom> m_fpgaCom; }; -#endif //ENDEAVOURRAWUIO_H +#endif // ENDEAVOURRAWUIO_H diff --git a/pbv3/EndeavourRawYARR.cpp b/pbv3/EndeavourRawYARR.cpp index bc04c57fd695498d55e20f2a34e93a4bf4681573..cedf26c97de24685264419a67c66ef0b777a0726 100644 --- a/pbv3/EndeavourRawYARR.cpp +++ b/pbv3/EndeavourRawYARR.cpp @@ -1,36 +1,35 @@ #include "EndeavourRawYARR.h" -#include "EndeavourComException.h" - #include <Logger.h> +#include <stdint.h> +#include <sys/file.h> // flock +#include <unistd.h> -#include <thread> - -#include <cstdint> -#include <iostream> -#include <iomanip> #include <bitset> -#include <unistd.h> -#include <stdint.h> +#include <cstdint> #include <fstream> +#include <iomanip> +#include <iostream> +#include <nlohmann/json.hpp> // HwController's configuration is saved in a json +#include <thread> -#include <sys/file.h> // flock - -#include <nlohmann/json.hpp> // HwController's configuration is saved in a json +#include "EndeavourComException.h" // we need HwController to configure and get to the Rx-Tx Cores // the IO operates on the cores -#include "libYarr/include/AllHwControllers.h" // the sub-lib with different access systems to the Rx-Tx Cores = HwController +#include "libYarr/include/AllHwControllers.h" // the sub-lib with different access systems to the Rx-Tx Cores = HwController //#include "DeviceCom.h" -//#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController -// TxCore does not have sendBitstream -- the patch from Olivier to send bytes over Netio -// but it defines the interface class for NetioTx -#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController -#include "libNetioHW/include/NetioTxCore.h" // -#include "libYarr/include/RxCore.h" // -#include "libYarr/include/RawData.h" // the GBT read buffer -//#include "libUtil/include/BitStream.h" // Endeavour protocol not there in the new YAR +//#include "libYarr/include/TxCore.h" // the communication cores on the YARR +//HwController +// TxCore does not have sendBitstream -- the patch from Olivier to send bytes +// over Netio but it defines the interface class for NetioTx +#include "libNetioHW/include/NetioTxCore.h" // +#include "libYarr/include/RawData.h" // the GBT read buffer +#include "libYarr/include/RxCore.h" // +#include "libYarr/include/TxCore.h" // the communication cores on the YARR HwController +//#include "libUtil/include/BitStream.h" // Endeavour protocol not there in the +//new YAR #define CHUNK_SIZE 65535 #define LATENCY_MS 4 @@ -40,132 +39,144 @@ static int tensec = 10e6; typedef std::vector<bool> BitStream; -BitStream addToBitStream(BitStream & bs, uint32_t size, uint32_t value){ - //Use the value from the LSB - for(uint32_t i=0;i<size;i++) - bs.push_back((value>>(size-i-1))&1); - return bs; +BitStream addToBitStream(BitStream& bs, uint32_t size, uint32_t value) { + // Use the value from the LSB + for (uint32_t i = 0; i < size; i++) + bs.push_back((value >> (size - i - 1)) & 1); + return bs; } - -EndeavourRawYARR::EndeavourRawYARR(const std::string& hwcontroller_type, const std::string& config, std::string ec_lock_filename) - : m_ec_lock_filename(ec_lock_filename) -//const std::string default_ec_lock_filename = std::string(); //="/run/lock/atlas_itk_strips_EC"; +EndeavourRawYARR::EndeavourRawYARR(const std::string& hwcontroller_type, + const std::string& config, + std::string ec_lock_filename) + : m_ec_lock_filename(ec_lock_filename) +// const std::string default_ec_lock_filename = std::string(); +// //="/run/lock/atlas_itk_strips_EC"; { - logger(logDEBUG) << "EndeavourRawYARR::EndeavourRawYARR Configure YARR HwController with " << config; - // - //load JSON object from file - //std::ifstream i(hardwareConfigFile); - - // lock the EC file to indicate the EC link as busy for other processes - m_fd_ec_lock = open(m_ec_lock_filename.c_str(), O_RDWR); - if (m_fd_ec_lock == -1) { - throw EndeavourComException("EndeavourRawYARR could not open the lock file " + m_ec_lock_filename + ":" - + " (" + std::to_string(errno) + ") " - + std::string(strerror(errno))); + logger(logDEBUG) << "EndeavourRawYARR::EndeavourRawYARR Configure YARR " + "HwController with " + << config; + // + // load JSON object from file + // std::ifstream i(hardwareConfigFile); + + // lock the EC file to indicate the EC link as busy for other processes + m_fd_ec_lock = open(m_ec_lock_filename.c_str(), O_RDWR); + if (m_fd_ec_lock == -1) { + throw EndeavourComException( + "EndeavourRawYARR could not open the lock file " + + m_ec_lock_filename + ":" + " (" + std::to_string(errno) + ") " + + std::string(strerror(errno))); } - logger(logDEBUG) << "EndeavourRawYARR::EndeavourRawYARR locking the file " << m_ec_lock_filename; - if (flock(m_fd_ec_lock, LOCK_EX) == -1) { - throw EndeavourComException("EndeavourRawYARR could not lock " + m_ec_lock_filename); + logger(logDEBUG) << "EndeavourRawYARR::EndeavourRawYARR locking the file " + << m_ec_lock_filename; + if (flock(m_fd_ec_lock, LOCK_EX) == -1) { + throw EndeavourComException("EndeavourRawYARR could not lock " + + m_ec_lock_filename); } - json ctrlCfg; - std::ifstream controllerFile(config); + json ctrlCfg; + std::ifstream controllerFile(config); - if(controllerFile.is_open()) - { - //ctrlCfg = json::parse(controllerFile); + if (controllerFile.is_open()) { + // ctrlCfg = json::parse(controllerFile); - try - { - ctrlCfg = json::parse(controllerFile); - } - catch (json::parse_error &e) - { - logger(logERROR) << "Could not parse NetIO controller config: " << e.what(); - } - //logger(logDEBUG) << "Parsed NetIO controller config."; + try { + ctrlCfg = json::parse(controllerFile); + } catch (json::parse_error& e) { + logger(logERROR) + << "Could not parse NetIO controller config: " << e.what(); + } + // logger(logDEBUG) << "Parsed NetIO controller config."; + } else { + logger(logERROR) << "Unable to open NetIO config file: " << config; } - else - { logger(logERROR) << "Unable to open NetIO config file: " << config; } - - gbt_hwCtrl = StdDict::getHwController(hwcontroller_type); - gbt_hwCtrl->loadConfig(ctrlCfg["ctrlCfg"]["cfg"]); - gbt_rx_core = dynamic_cast<RxCore*>(&*gbt_hwCtrl); - //gbt_tx_core = dynamic_cast<TxCore*>(&*gbt_hwCtrl); - gbt_tx_core = dynamic_cast<NetioTxCore*>(&*gbt_hwCtrl); - - //unsigned int rx_elink_n = 0x3f, tx_elink_n = 0x3f; // 2021-11 the latest fw? - unsigned int rx_elink_n = 0x1c, tx_elink_n = 0x14; // 2021-08 phase 2 from Chris, reg map 5 - //unsigned int rx_elink_n = 0x3f, tx_elink_n = 0x3f; // 2021-08 old vldb+ reg 4 version - gbt_rx_core -> setRxEnable(rx_elink_n); //63); // (28); // 0 in IU - gbt_tx_core -> setCmdEnable(tx_elink_n); //63); // (32); // it is 20 in IU TODO: export it to the config! - - logger(logDEBUG) << "EndeavourRawYARR::EndeavourRawYARR Connected to e-links RX=" << std::hex << rx_elink_n << " & TX=" << tx_elink_n << std::dec; - //logger(logDEBUG) << "EndeavourRawYARR, enabled 1 e-links to listen, 1 to send commands."; + gbt_hwCtrl = StdDict::getHwController(hwcontroller_type); + gbt_hwCtrl->loadConfig(ctrlCfg["ctrlCfg"]["cfg"]); + + gbt_rx_core = dynamic_cast<RxCore*>(&*gbt_hwCtrl); + // gbt_tx_core = dynamic_cast<TxCore*>(&*gbt_hwCtrl); + gbt_tx_core = dynamic_cast<NetioTxCore*>(&*gbt_hwCtrl); + + // unsigned int rx_elink_n = 0x3f, tx_elink_n = 0x3f; // 2021-11 the latest + // fw? + unsigned int rx_elink_n = 0x1c, + tx_elink_n = 0x14; // 2021-08 phase 2 from Chris, reg map 5 + // unsigned int rx_elink_n = 0x3f, tx_elink_n = 0x3f; // 2021-08 old vldb+ + // reg 4 version + gbt_rx_core->setRxEnable(rx_elink_n); // 63); // (28); // 0 in IU + gbt_tx_core->setCmdEnable(tx_elink_n); // 63); // (32); // it is 20 in IU + // TODO: export it to the config! + + logger(logDEBUG) + << "EndeavourRawYARR::EndeavourRawYARR Connected to e-links RX=" + << std::hex << rx_elink_n << " & TX=" << tx_elink_n << std::dec; + // logger(logDEBUG) << "EndeavourRawYARR, enabled 1 e-links to listen, 1 to + // send commands."; } -EndeavourRawYARR::~EndeavourRawYARR() -{ - // unsibscribe from NetIO - gbt_hwCtrl.reset(); gbt_hwCtrl = nullptr; - - // unlock the file to indicate the EC link is free - if (flock(m_fd_ec_lock, LOCK_UN) == -1) { - //throw EndeavourComException("EndeavourRawYARR could not unlock " + m_ec_lock_filename); - logger(logERROR) << "EndeavourRawYARR could not unlock " + m_ec_lock_filename; +EndeavourRawYARR::~EndeavourRawYARR() { + // unsibscribe from NetIO + gbt_hwCtrl.reset(); + gbt_hwCtrl = nullptr; + + // unlock the file to indicate the EC link is free + if (flock(m_fd_ec_lock, LOCK_UN) == -1) { + // throw EndeavourComException("EndeavourRawYARR could not unlock " + + // m_ec_lock_filename); + logger(logERROR) << "EndeavourRawYARR could not unlock " + + m_ec_lock_filename; } - // and close the file - if (close(m_fd_ec_lock) == -1) { - logger(logERROR) << "EndeavourRawYARR could not close " + m_ec_lock_filename << " " << strerror(errno); + // and close the file + if (close(m_fd_ec_lock) == -1) { + logger(logERROR) << "EndeavourRawYARR could not close " + + m_ec_lock_filename + << " " << strerror(errno); } } - /** \brief gets first 32-bit word from 64-bit AMAC message */ -uint32_t first_32_bits(unsigned long long int input) -{ - uint32_t ret = input >> 32; - return ret; +uint32_t first_32_bits(unsigned long long int input) { + uint32_t ret = input >> 32; + return ret; } /** \brief gets second 32-bit word from 64-bit AMAC message */ -uint32_t second_32_bits(unsigned long long int input) -{ - uint32_t ret = input; - return ret; +uint32_t second_32_bits(unsigned long long int input) { + uint32_t ret = input; + return ret; } /* // in YARR the input signature is BitStream::Add(uint32_t size, uint32_t value) // therefore a hack to add 64-long messages // TODO: abandon BitStream & just manipulate bits? -void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, unsigned int size) +void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, +unsigned int size) { if (size > 32) { - msg.Add(size-32, first_32_bits(data)); + msg.Add(size-32, first_32_bits(data)); size=32; } - msg.Add(size, second_32_bits(data)); + msg.Add(size, second_32_bits(data)); } */ -void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, unsigned int size) -{ - if (size > 32) - { - //msg.Add(size-32, first_32_bits(data)); - addToBitStream(msg, size-32, first_32_bits(data)); - size=32; +void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, + unsigned int size) { + if (size > 32) { + // msg.Add(size-32, first_32_bits(data)); + addToBitStream(msg, size - 32, first_32_bits(data)); + size = 32; } - //msg.Add(size, second_32_bits(data)); - addToBitStream(msg, size, second_32_bits(data)); + // msg.Add(size, second_32_bits(data)); + addToBitStream(msg, size, second_32_bits(data)); } /* @@ -173,7 +184,7 @@ void add_64bits_to_BitStream(BitStream& msg, unsigned long long int data, unsign BitStream invert(BitStream msg) { BitStream inverted; - for (int32_t bit = msg.GetNbits()-1; bit>=0; --bit) + for (int32_t bit = msg.GetNbits()-1; bit>=0; --bit) inverted.Add(1, msg.Get(bit)); return inverted; } @@ -182,313 +193,320 @@ BitStream invert(BitStream msg) /* * EndeavourCom uses this to send databits */ -void EndeavourRawYARR::sendData(unsigned long long int data, unsigned int size) -{ - auto data_bits = std::bitset<64>(data); - // prepare the Endeavour message - logger(logDEBUG) << "EndeavourRawYARR::sendData data" - << " 0x" << std::hex << data << "\t" << data_bits - << " size " << std::dec << size; - - //logger(logDEBUG) << "EndeavourRawYARR::sendData data_bits " - // << data_bits[0] << data_bits[1] << " " - // << data_bits[62] << data_bits[63]; - - BitStream msg; - - //logger(logDEBUG) << "EndeavourRawYARR::sendData first_32_bits " << std::hex << first_32_bits(data); - //logger(logDEBUG) << "EndeavourRawYARR::sendData second_32_bits " << std::hex << second_32_bits(data); - add_64bits_to_BitStream(msg, data, size); // TODO: this thing is needed, it adds bits into BitStream correctly, without any 64-bit padding - // I temporary repeat it 4 times to get rid of 32-bit padding in YARR - - std::string msg_str(msg.begin(), msg.end()); - //logger(logDEBUG) << "EndeavourRawYARR::sendData msg " << msg.ToString() << " size " << msg.GetNbits(); - logger(logDEBUG) << "EndeavourRawYARR::sendData msg " << msg_str << " size " << msg.size(); - - //add_64bits_to_BitStream(msg, data, size); - //add_64bits_to_BitStream(msg, data, size); - //add_64bits_to_BitStream(msg, data, size); - //logger(logDEBUG) << "EndeavourRawYARR::sendData msg " << msg.ToString() << " size " << msg.GetNbits(); - - //add_64bits_to_BitStream(msg, data, size); - // OUTDATED: some hack in the current firmware for FLX709, msg must be sent twice - - //logger(logDEBUG) << "EndeavourRawYARR::sendData msg full " << msg.ToString() << " size " << msg.GetNbits(); - - // don't invert - //msg = invert(msg); - - //// Pack splits the bit array into 32-bit words, which are send on NetIO - //// but it does it starting from the end - //// NetIO needs thw words from the beginning - //// therefore, let's pad the end with zeros - //// 32 - reminder from div 32 - // - //uint32_t n_zeros_to_add = (msg.GetNbits() & 0x1f) ? - // 32 - msg.GetNbits() & 0x1f - // : 0; - //msg.Add(n_zeros_to_add, 0); - //msg.Pack(); - //logger(logDEBUG) << "EndeavourRawYARR::sendData msg pack " << msg.ToString() << " size " << msg.GetNbits(); - - // send it - gbt_tx_core->sendBitstream(msg); - /* - for (uint32_t i = 0; i < msg.GetSize(); ++i) - //for (int32_t i = msg.GetSize()-1; i >= 0; --i) - { - logger(logDEBUG) << "EndeavourRawYARR::sendData msg word " << i << " " << std::hex << msg.GetWord(i) << std::dec; - gbt_tx_core->writeFifo(msg.GetWord(i)); - } - gbt_tx_core->releaseFifo(); - */ - - // OUTDATED: the following repetition is a work-around - // for the double-command issue in old Phase1 Felix FW - // periodically, in about 1 per 6 reads, - // the AMAC response was not sent out from FW - // if there is no response, just send the command 1 more time - if (!isDataValid()) - { - unsigned int repeat_n = 0; - - while (repeat_n-- > 0) +void EndeavourRawYARR::sendData(unsigned long long int data, + unsigned int size) { + auto data_bits = std::bitset<64>(data); + // prepare the Endeavour message + logger(logDEBUG) << "EndeavourRawYARR::sendData data" + << " 0x" << std::hex << data << "\t" << data_bits + << " size " << std::dec << size; + + // logger(logDEBUG) << "EndeavourRawYARR::sendData data_bits " + // << data_bits[0] << data_bits[1] << " " + // << data_bits[62] << data_bits[63]; + + BitStream msg; + + // logger(logDEBUG) << "EndeavourRawYARR::sendData first_32_bits " << + // std::hex << first_32_bits(data); logger(logDEBUG) << + // "EndeavourRawYARR::sendData second_32_bits " << std::hex << + // second_32_bits(data); + add_64bits_to_BitStream( + msg, data, size); // TODO: this thing is needed, it adds bits into + // BitStream correctly, without any 64-bit padding + // I temporary repeat it 4 times to get rid of 32-bit padding in YARR + + std::string msg_str(msg.begin(), msg.end()); + // logger(logDEBUG) << "EndeavourRawYARR::sendData msg " << msg.ToString() + // << " size " << msg.GetNbits(); + logger(logDEBUG) << "EndeavourRawYARR::sendData msg " << msg_str << " size " + << msg.size(); + + // add_64bits_to_BitStream(msg, data, size); + // add_64bits_to_BitStream(msg, data, size); + // add_64bits_to_BitStream(msg, data, size); + // logger(logDEBUG) << "EndeavourRawYARR::sendData msg " << msg.ToString() + // << " size " << msg.GetNbits(); + + // add_64bits_to_BitStream(msg, data, size); + // OUTDATED: some hack in the current firmware for FLX709, msg must be sent + // twice + + // logger(logDEBUG) << "EndeavourRawYARR::sendData msg full " << + // msg.ToString() << " size " << msg.GetNbits(); + + // don't invert + // msg = invert(msg); + + //// Pack splits the bit array into 32-bit words, which are send on NetIO + //// but it does it starting from the end + //// NetIO needs thw words from the beginning + //// therefore, let's pad the end with zeros + //// 32 - reminder from div 32 + // + // uint32_t n_zeros_to_add = (msg.GetNbits() & 0x1f) ? + // 32 - msg.GetNbits() & 0x1f + // : 0; + // msg.Add(n_zeros_to_add, 0); + // msg.Pack(); + // logger(logDEBUG) << "EndeavourRawYARR::sendData msg pack " << + // msg.ToString() << " size " << msg.GetNbits(); + + // send it + gbt_tx_core->sendBitstream(msg); + /* + for (uint32_t i = 0; i < msg.GetSize(); ++i) + //for (int32_t i = msg.GetSize()-1; i >= 0; --i) { - //logger(logDEBUG) << "EndeavourRawYARR, sendData repeat " << repeat_n; - gbt_tx_core->sendBitstream(msg); + logger(logDEBUG) << "EndeavourRawYARR::sendData msg word " << i << " " << + std::hex << msg.GetWord(i) << std::dec; + gbt_tx_core->writeFifo(msg.GetWord(i)); + } + gbt_tx_core->releaseFifo(); + */ - /* - for (uint32_t i = 0; i < msg.GetSize(); ++i) - { - gbt_tx_core->writeFifo(msg.GetWord(i)); + // OUTDATED: the following repetition is a work-around + // for the double-command issue in old Phase1 Felix FW + // periodically, in about 1 per 6 reads, + // the AMAC response was not sent out from FW + // if there is no response, just send the command 1 more time + if (!isDataValid()) { + unsigned int repeat_n = 0; + + while (repeat_n-- > 0) { + // logger(logDEBUG) << "EndeavourRawYARR, sendData repeat " << + // repeat_n; + gbt_tx_core->sendBitstream(msg); + + /* + for (uint32_t i = 0; i < msg.GetSize(); ++i) + { + gbt_tx_core->writeFifo(msg.GetWord(i)); + } + gbt_tx_core->releaseFifo(); + */ } - gbt_tx_core->releaseFifo(); - */ - } } } -bool EndeavourRawYARR::isDataValid() -{ - RawData *data = nullptr; - - //RawDataContainer several_buffers_data; - unsigned int max_reads = 10; // we can receive several messages at once - unsigned int microseconds_of_delay_between_reads = 10000; - - for (uint32_t i = 0; i < max_reads; ++i) - { - data = gbt_rx_core->readData(); - if (data == nullptr) - { - if (gbt_buffer_data.size() > 0) break; // if something is already found and there is no data then it must be the end of the message sequence - std::this_thread::sleep_for(std::chrono::microseconds(microseconds_of_delay_between_reads)); - } - else - { - gbt_buffer_data.push_back(data); // stack the response messages - } +bool EndeavourRawYARR::isDataValid() { + RawData* data = nullptr; + + // RawDataContainer several_buffers_data; + unsigned int max_reads = 10; // we can receive several messages at once + unsigned int microseconds_of_delay_between_reads = 10000; + + for (uint32_t i = 0; i < max_reads; ++i) { + data = gbt_rx_core->readData(); + if (data == nullptr) { + if (gbt_buffer_data.size() > 0) + break; // if something is already found and there is no data + // then it must be the end of the message sequence + std::this_thread::sleep_for( + std::chrono::microseconds(microseconds_of_delay_between_reads)); + } else { + gbt_buffer_data.push_back(data); // stack the response messages + } } - if (gbt_buffer_data.size() == 0) - { - return false; - } - else - { - return true; + if (gbt_buffer_data.size() == 0) { + return false; + } else { + return true; } } // TODO: remove this? or make some general endianness functions -bool bit_in_endian_bytes(uint32_t input, unsigned int bit_index) -{ - unsigned int bit_i = bit_index & 0x7; - unsigned int byte_i = bit_index >> 3; // reminder devision by 8 +bool bit_in_endian_bytes(uint32_t input, unsigned int bit_index) { + unsigned int bit_i = bit_index & 0x7; + unsigned int byte_i = bit_index >> 3; // reminder devision by 8 char byte = (input >> byte_i * 8) & 0xFF; return (byte << bit_i) & 0x80; } /** \brief swaps the endianness in the word */ -uint32_t swap_byte_endiannes(uint32_t input) -{ - uint8_t byte1 = (input & 0x000000ff) >> 0; - uint8_t byte2 = (input & 0x0000ff00) >> 8; +uint32_t swap_byte_endiannes(uint32_t input) { + uint8_t byte1 = (input & 0x000000ff) >> 0; + uint8_t byte2 = (input & 0x0000ff00) >> 8; uint8_t byte3 = (input & 0x00ff0000) >> 16; uint8_t byte4 = (input & 0xff000000) >> 24; - uint32_t swapped = 0; swapped = swapped | byte1; - swapped <<= 8; swapped = swapped | byte2; - swapped <<= 8; swapped = swapped | byte3; - swapped <<= 8; swapped = swapped | byte4; + uint32_t swapped = 0; + swapped = swapped | byte1; + swapped <<= 8; + swapped = swapped | byte2; + swapped <<= 8; + swapped = swapped | byte3; + swapped <<= 8; + swapped = swapped | byte4; return swapped; } -/** \brief readData parses the messages stored in the gbt_buffer_data, the buffer is filled on isDataValid -*/ -void EndeavourRawYARR::readData(unsigned long long int& data, unsigned int& size) -{ - std::vector<unsigned long long int> parsed_messages; - std::vector<unsigned int> parsed_messages_length; - - // get the AMAC messages from the NetIO buffers - for(unsigned int i=0; i<gbt_buffer_data.size(); i++) - { - // should be one decoded message from AMAC - RawData* buffer_data = gbt_buffer_data[i]; - unsigned long long int parsed_message_int = 0; - - if (buffer_data->words > 2) - { - logger(logDEBUG) << "received more than 64 bits of an AMAC message in one NetIO buffer: " << buffer_data->words; - } - - unsigned int msg_len = 0; - unsigned int n_words = buffer_data->words; // 2; // buffer_data->words - logger(logDEBUG) << "EndeavourRawYARR::readData received n_words= " << n_words; - - for (uint32_t j=0; j < n_words; ++j) - { - // a 32-bit word - uint32_t n = buffer_data->buf[j]; - logger(logDEBUG) << "EndeavourRawYARR::readData word=" << j << " is " << std::hex << n; +/** \brief readData parses the messages stored in the gbt_buffer_data, the + * buffer is filled on isDataValid + */ +void EndeavourRawYARR::readData(unsigned long long int& data, + unsigned int& size) { + std::vector<unsigned long long int> parsed_messages; + std::vector<unsigned int> parsed_messages_length; + + // get the AMAC messages from the NetIO buffers + for (unsigned int i = 0; i < gbt_buffer_data.size(); i++) { + // should be one decoded message from AMAC + RawData* buffer_data = gbt_buffer_data[i]; + unsigned long long int parsed_message_int = 0; + + if (buffer_data->words > 2) { + logger(logDEBUG) << "received more than 64 bits of an AMAC message " + "in one NetIO buffer: " + << buffer_data->words; + } - // swap endianness in the word: the order of bytes - bool to_swap = true; - uint32_t n_endianned = to_swap ? swap_byte_endiannes(n) : n; + unsigned int msg_len = 0; + unsigned int n_words = buffer_data->words; // 2; // buffer_data->words + logger(logDEBUG) << "EndeavourRawYARR::readData received n_words= " + << n_words; - // stuff it into the 64-bit message - parsed_message_int <<= 32; - parsed_message_int = parsed_message_int | n_endianned; + for (uint32_t j = 0; j < n_words; ++j) { + // a 32-bit word + uint32_t n = buffer_data->buf[j]; + logger(logDEBUG) << "EndeavourRawYARR::readData word=" << j + << " is " << std::hex << n; - msg_len += 32; - } + // swap endianness in the word: the order of bytes + bool to_swap = true; + uint32_t n_endianned = to_swap ? swap_byte_endiannes(n) : n; - // strip the last zeroes - // the AMAC response messages are: - // 48 bit for READ, READNEXT - // 8 bit for WRITE, SETID - // From the spec: - // * In response to a READ command, AMAC sends the 48-bit response - // {amacid[4:0], seqnum[2:0], addr[7:0], data[31:0]}, - // where data[31:0] is the contents of the addressed register. - // * [For READNEXT] The response is the same as to a READ command. - // * In response to a WRITE command, - // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. - // * In response to the SETID command, - // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. - // the words from NetIO are 32 bit long - - // 2021-08-02 fw phaseII regmap5, FW returns x86 byte order, no need to swap - // but it is wrong order for the network, i.e. in netio AMAC message looks like: - // 10 00 00 00 1c 00 00 00 2a aa 00 00 01 00 00 00 - //msg_len = 48; - - /* 2021-08-20 fw phaseII regmap5, I do not strip the bytes, because fw returns it in 32-bit messages - // TODO: now I am stripping 2 0-bytes from 64 bit messages - // and 3 0-bytes from 32 bit - // - check if there is always a 1 bit at the end of AMAC message - if (msg_len == 64 || msg_len == 32) - { - unsigned int max_bytes_to_strip = msg_len == 64 ? 2 : 3; + // stuff it into the 64-bit message + parsed_message_int <<= 32; + parsed_message_int = parsed_message_int | n_endianned; - uint8_t last_byte = 0; - while ((last_byte = parsed_message_int & 0xff) == 0 && max_bytes_to_strip-- > 0) - { - parsed_message_int >>= 8; - msg_len -= 8; + msg_len += 32; } - } - */ - parsed_messages.push_back(parsed_message_int); - parsed_messages_length.push_back(msg_len); + // strip the last zeroes + // the AMAC response messages are: + // 48 bit for READ, READNEXT + // 8 bit for WRITE, SETID + // From the spec: + // * In response to a READ command, AMAC sends the 48-bit response + // {amacid[4:0], seqnum[2:0], addr[7:0], data[31:0]}, + // where data[31:0] is the contents of the addressed register. + // * [For READNEXT] The response is the same as to a READ command. + // * In response to a WRITE command, + // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. + // * In response to the SETID command, + // AMAC sends the 8-bit response {amacid[4:0], seqnum[2:0]}. + // the words from NetIO are 32 bit long + + // 2021-08-02 fw phaseII regmap5, FW returns x86 byte order, no need to + // swap but it is wrong order for the network, i.e. in netio AMAC + // message looks like: 10 00 00 00 1c 00 00 00 2a aa 00 00 01 00 00 00 + // msg_len = 48; + + /* 2021-08-20 fw phaseII regmap5, I do not strip the bytes, because fw + returns it in 32-bit messages + // TODO: now I am stripping 2 0-bytes from 64 bit messages + // and 3 0-bytes from 32 bit + // - check if there is always a 1 bit at the end of AMAC message + if (msg_len == 64 || msg_len == 32) + { + unsigned int max_bytes_to_strip = msg_len == 64 ? 2 : 3; + + uint8_t last_byte = 0; + while ((last_byte = parsed_message_int & 0xff) == 0 && + max_bytes_to_strip-- > 0) + { + parsed_message_int >>= 8; + msg_len -= 8; + } + } + */ + + parsed_messages.push_back(parsed_message_int); + parsed_messages_length.push_back(msg_len); } - // clear the buffer after parsing - for (unsigned int i=0; i<gbt_buffer_data.size(); i++) - { - delete gbt_buffer_data[i]; // to not leak the items + // clear the buffer after parsing + for (unsigned int i = 0; i < gbt_buffer_data.size(); i++) { + delete gbt_buffer_data[i]; // to not leak the items } - logger(logDEBUG) << "EndeavourRawYARR::readData gbt_buffer_data.size() " << gbt_buffer_data.size() - << " parsed_messages:"; - for (unsigned int i=0; i<parsed_messages.size(); i++) - { - logger(logDEBUG) << " 0x" << std::hex << parsed_messages[i] - << " size " << std::dec << parsed_messages_length[i]; + logger(logDEBUG) << "EndeavourRawYARR::readData gbt_buffer_data.size() " + << gbt_buffer_data.size() << " parsed_messages:"; + for (unsigned int i = 0; i < parsed_messages.size(); i++) { + logger(logDEBUG) << " 0x" << std::hex << parsed_messages[i] << " size " + << std::dec << parsed_messages_length[i]; } - gbt_buffer_data.clear(); - - // printout messages for debugging - for (uint32_t message_i = 0; message_i < parsed_messages.size(); ++message_i) - { - unsigned long long int& msg = parsed_messages[message_i]; - unsigned int& msg_len = parsed_messages_length[message_i]; - - if (msg_len == 49) - { - // shift the message to pop the last bit - msg >>= 1; - msg_len--; - } + gbt_buffer_data.clear(); + + // printout messages for debugging + for (uint32_t message_i = 0; message_i < parsed_messages.size(); + ++message_i) { + unsigned long long int& msg = parsed_messages[message_i]; + unsigned int& msg_len = parsed_messages_length[message_i]; + + if (msg_len == 49) { + // shift the message to pop the last bit + msg >>= 1; + msg_len--; + } - // strip the last zeroes - // the AMAC response messages are: - // 48 bit for READ, READNEXT - // 8 bit for WRITE, SETID + // strip the last zeroes + // the AMAC response messages are: + // 48 bit for READ, READNEXT + // 8 bit for WRITE, SETID - if (msg_len > 48) - { - // shift the message to pop the last bits - msg >>= msg_len - 48; - msg_len = 48; - } + if (msg_len > 48) { + // shift the message to pop the last bits + msg >>= msg_len - 48; + msg_len = 48; + } - else if (msg_len > 8) - { - // shift the message to pop the last bits - msg >>= msg_len - 8; - msg_len = 8; - } + else if (msg_len > 8) { + // shift the message to pop the last bits + msg >>= msg_len - 8; + msg_len = 8; + } - //logger(logDEBUG) << "EndeavourRawYARR::readData " - // << "message len " << std::dec << msg_len << "bits" - // << " 0x" << std::hex << msg << "\t" << std::bitset<64>(msg); + // logger(logDEBUG) << "EndeavourRawYARR::readData " + // << "message len " << std::dec << msg_len << "bits" + // << " 0x" << std::hex << msg << "\t" << + // std::bitset<64>(msg); } - //// output the last message from all that were received in isDataValid - //size = parsed_messages_length.back(); - //data = parsed_messages.back(); + //// output the last message from all that were received in isDataValid + // size = parsed_messages_length.back(); + // data = parsed_messages.back(); - // merge last message or two - size = parsed_messages_length[0]; - data = parsed_messages[0]; + // merge last message or two + size = parsed_messages_length[0]; + data = parsed_messages[0]; - // when swap endianness in the word, this might be needed - /* - if (parsed_messages.size()>1) - { - unsigned full_msg_size = 48; // whatever - unsigned n_remaining_bits = (full_msg_size - size); - data <<= n_remaining_bits; // make space for the rest of bits + // when swap endianness in the word, this might be needed + /* + if (parsed_messages.size()>1) + { + unsigned full_msg_size = 48; // whatever + unsigned n_remaining_bits = (full_msg_size - size); + data <<= n_remaining_bits; // make space for the rest of bits - unsigned long long one_more_msg = parsed_messages[1]; - data |= (one_more_msg >> (parsed_messages_length[1] - n_remaining_bits)); - size = full_msg_size; - } + unsigned long long one_more_msg = parsed_messages[1]; + data |= (one_more_msg >> (parsed_messages_length[1] - n_remaining_bits)); + size = full_msg_size; + } - else // it is a 8-bit response, from setid or write - { - unsigned full_msg_size = 8; - unsigned n_spurious_bits = (size - full_msg_size); - data >>= n_spurious_bits; // leave only the leading 8 bits - size = full_msg_size; - } - */ + else // it is a 8-bit response, from setid or write + { + unsigned full_msg_size = 8; + unsigned n_spurious_bits = (size - full_msg_size); + data >>= n_spurious_bits; // leave only the leading 8 bits + size = full_msg_size; + } + */ - logger(logDEBUG) << "EndeavourRawYARR::readData final data 0x" << std::hex << data - << " size " << std::dec << size; + logger(logDEBUG) << "EndeavourRawYARR::readData final data 0x" << std::hex + << data << " size " << std::dec << size; } diff --git a/pbv3/EndeavourRawYARR.h b/pbv3/EndeavourRawYARR.h index 4dd6f23376c10e65baf83d55fb533b0625248942..72c64a39d75b3d7d2d40731915d421685ba8bbc8 100644 --- a/pbv3/EndeavourRawYARR.h +++ b/pbv3/EndeavourRawYARR.h @@ -1,85 +1,90 @@ #ifndef ENDEAVOURRAWYARR_H #define ENDEAVOURRAWYARR_H -#include <memory> #include <string.h> -#include <sstream> // against invalid use of incomplete type ‘std::string’ + +#include <memory> +#include <sstream> // against invalid use of incomplete type ‘std::string’ // the abstract data class to communicate with AMAC over the endeavour protocol -// the EndeavourRawYARR class implements it on GPT Rx-Tx Cores taken from the YARR HwControllers -#include "EndeavourRaw.h" +// the EndeavourRawYARR class implements it on GPT Rx-Tx Cores taken from the +// YARR HwControllers +#include "EndeavourRaw.h" // YARR classes class HwController; class RxCore; -//class TxCore; +// class TxCore; class NetioTxCore; class RawData; -//class BitStream; +// class BitStream; -//const std::string default_ec_lock_filename = std::string(); //="/run/lock/atlas_itk_strips_EC"; +// const std::string default_ec_lock_filename = std::string(); +// //="/run/lock/atlas_itk_strips_EC"; -class EndeavourRawYARR : public EndeavourRaw -{ -public: - EndeavourRawYARR(); - EndeavourRawYARR( - const std::string& hwcontroller_type, - const std::string& config_file_path, - std::string ec_lock_filename = "/opt/atlas/etc/atlas_itk_strips_EC"); // "/run/lock/atlas_itk_strips_EC"); - ~EndeavourRawYARR(); +class EndeavourRawYARR : public EndeavourRaw { + public: + EndeavourRawYARR(); + EndeavourRawYARR( + const std::string& hwcontroller_type, + const std::string& config_file_path, + std::string ec_lock_filename = + "/opt/atlas/etc/atlas_itk_strips_EC"); // "/run/lock/atlas_itk_strips_EC"); + ~EndeavourRawYARR(); - void setDitMin(uint32_t DIT_MIN) { m_DIT_MIN=DIT_MIN; }; - uint32_t getDitMin() { return m_DIT_MIN; }; + void setDitMin(uint32_t DIT_MIN) { m_DIT_MIN = DIT_MIN; }; + uint32_t getDitMin() { return m_DIT_MIN; }; - void setDitMid(uint32_t DIT_MID) { m_DIT_MID=DIT_MID; }; - uint32_t getDitMid() { return m_DIT_MID; }; + void setDitMid(uint32_t DIT_MID) { m_DIT_MID = DIT_MID; }; + uint32_t getDitMid() { return m_DIT_MID; }; - void setDitMax(uint32_t DIT_MAX) { m_DIT_MAX=DIT_MAX; }; - uint32_t getDitMax() { return m_DIT_MAX; }; + void setDitMax(uint32_t DIT_MAX) { m_DIT_MAX = DIT_MAX; }; + uint32_t getDitMax() { return m_DIT_MAX; }; - void setDahMin(uint32_t DAH_MIN) { m_DAH_MIN=DAH_MIN; }; - uint32_t getDahMin() { return m_DAH_MIN; }; + void setDahMin(uint32_t DAH_MIN) { m_DAH_MIN = DAH_MIN; }; + uint32_t getDahMin() { return m_DAH_MIN; }; - void setDahMid(uint32_t DAH_MID) { m_DAH_MID=DAH_MID; }; - uint32_t getDahMid() { return m_DAH_MID; }; + void setDahMid(uint32_t DAH_MID) { m_DAH_MID = DAH_MID; }; + uint32_t getDahMid() { return m_DAH_MID; }; - void setDahMax(uint32_t DAH_MAX) { m_DAH_MAX=DAH_MAX; }; - uint32_t getDahMax() { return m_DAH_MAX; }; + void setDahMax(uint32_t DAH_MAX) { m_DAH_MAX = DAH_MAX; }; + uint32_t getDahMax() { return m_DAH_MAX; }; - void setBitGapMin(uint32_t BITGAP_MIN) { m_BITGAP_MIN=BITGAP_MIN; }; - uint32_t getBitGapMin() { return m_BITGAP_MIN; }; + void setBitGapMin(uint32_t BITGAP_MIN) { m_BITGAP_MIN = BITGAP_MIN; }; + uint32_t getBitGapMin() { return m_BITGAP_MIN; }; - void setBitGapMid(uint32_t BITGAP_MID) { m_BITGAP_MID=BITGAP_MID; }; - uint32_t getBitGapMid() { return m_BITGAP_MID; }; + void setBitGapMid(uint32_t BITGAP_MID) { m_BITGAP_MID = BITGAP_MID; }; + uint32_t getBitGapMid() { return m_BITGAP_MID; }; - void setBitGapMax(uint32_t BITGAP_MAX) { m_BITGAP_MAX=BITGAP_MAX; }; - uint32_t getBitGapMax() { return m_BITGAP_MAX; }; + void setBitGapMax(uint32_t BITGAP_MAX) { m_BITGAP_MAX = BITGAP_MAX; }; + uint32_t getBitGapMax() { return m_BITGAP_MAX; }; - void reset() { }; + void reset(){}; - bool isError() { return false; }; + bool isError() { return false; }; - bool isDataValid(void); - void readData(unsigned long long int& data, unsigned int& size); - void sendData(unsigned long long int data, unsigned int size); + bool isDataValid(void); + void readData(unsigned long long int& data, unsigned int& size); + void sendData(unsigned long long int data, unsigned int size); -protected: - std::shared_ptr<HwController> gbt_hwCtrl; - RxCore* gbt_rx_core; - //TxCore* gbt_tx_core; - NetioTxCore* gbt_tx_core; - std::vector<RawData*> gbt_buffer_data; + protected: + std::shared_ptr<HwController> gbt_hwCtrl; + RxCore* gbt_rx_core; + // TxCore* gbt_tx_core; + NetioTxCore* gbt_tx_core; + std::vector<RawData*> gbt_buffer_data; -private: - std::string m_ec_lock_filename; - int m_fd_ec_lock; + private: + std::string m_ec_lock_filename; + int m_fd_ec_lock; - #define _ENDVMS 160 // it was 30 originally - uint32_t m_DIT_MIN = 6*_ENDVMS/40,m_DIT_MID = 14*_ENDVMS/40,m_DIT_MAX = 22*_ENDVMS/40; - uint32_t m_DAH_MIN = 29*_ENDVMS/40,m_DAH_MID = 76*_ENDVMS/40,m_DAH_MAX =124*_ENDVMS/40; - uint32_t m_BITGAP_MIN= 11*_ENDVMS/40,m_BITGAP_MID= 43*_ENDVMS/40,m_BITGAP_MAX= 75*_ENDVMS/40; +#define _ENDVMS 160 // it was 30 originally + uint32_t m_DIT_MIN = 6 * _ENDVMS / 40, m_DIT_MID = 14 * _ENDVMS / 40, + m_DIT_MAX = 22 * _ENDVMS / 40; + uint32_t m_DAH_MIN = 29 * _ENDVMS / 40, m_DAH_MID = 76 * _ENDVMS / 40, + m_DAH_MAX = 124 * _ENDVMS / 40; + uint32_t m_BITGAP_MIN = 11 * _ENDVMS / 40, m_BITGAP_MID = 43 * _ENDVMS / 40, + m_BITGAP_MAX = 75 * _ENDVMS / 40; }; -#endif //ENDEAVOURRAWYARR_H - +#endif // ENDEAVOURRAWYARR_H diff --git a/pbv3/ITSDAQCom.cpp b/pbv3/ITSDAQCom.cpp index 01d22d17741e4eb2b971572c0201e57785a4e7af..6127fe05b4de8b5b414f77ec1e7712256e95f30a 100644 --- a/pbv3/ITSDAQCom.cpp +++ b/pbv3/ITSDAQCom.cpp @@ -1,98 +1,97 @@ #include "ITSDAQCom.h" -#include "ITSDAQComException.h" - -#include <sys/types.h> /* See NOTES */ -#include <sys/socket.h> #include <arpa/inet.h> #include <string.h> +#include <sys/socket.h> +#include <sys/types.h> /* See NOTES */ #include <unistd.h> #include <cstring> -#include <iostream> #include <iomanip> +#include <iostream> + +#include "ITSDAQComException.h" -ITSDAQCom::ITSDAQCom(const std::string& addr, uint32_t port) -{ - // socket creation - m_socket=socket(AF_INET, SOCK_DGRAM, 0); - if(m_socket<0) - throw ITSDAQComException("socket creation failed"); - - // sending data - memset(&m_fpgaaddr, 0, sizeof(m_fpgaaddr)); - m_fpgaaddr.sin_family = AF_INET; - m_fpgaaddr.sin_port = htons(port); - m_fpgaaddr.sin_addr.s_addr= inet_addr(addr.c_str()); - - // receiveing responses - struct sockaddr_in myaddr; - memset(&myaddr, 0, sizeof(myaddr)); - myaddr.sin_family = AF_INET; - myaddr.sin_port = htons(port); - myaddr.sin_addr.s_addr = htonl(INADDR_ANY); - - if(bind(m_socket, (struct sockaddr*)&myaddr, sizeof(myaddr))<0) - throw ITSDAQComException("failed to bind UDP socket"); - - int32_t enable = 1; - setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int32_t)); +ITSDAQCom::ITSDAQCom(const std::string& addr, uint32_t port) { + // socket creation + m_socket = socket(AF_INET, SOCK_DGRAM, 0); + if (m_socket < 0) throw ITSDAQComException("socket creation failed"); + + // sending data + memset(&m_fpgaaddr, 0, sizeof(m_fpgaaddr)); + m_fpgaaddr.sin_family = AF_INET; + m_fpgaaddr.sin_port = htons(port); + m_fpgaaddr.sin_addr.s_addr = inet_addr(addr.c_str()); + + // receiveing responses + struct sockaddr_in myaddr; + memset(&myaddr, 0, sizeof(myaddr)); + myaddr.sin_family = AF_INET; + myaddr.sin_port = htons(port); + myaddr.sin_addr.s_addr = htonl(INADDR_ANY); + + if (bind(m_socket, (struct sockaddr*)&myaddr, sizeof(myaddr)) < 0) + throw ITSDAQComException("failed to bind UDP socket"); + + int32_t enable = 1; + setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int32_t)); } -ITSDAQCom::~ITSDAQCom() -{ if(m_socket>0) close(m_socket); } +ITSDAQCom::~ITSDAQCom() { + if (m_socket > 0) close(m_socket); +} -void ITSDAQCom::send(const ITSDAQPacket& packet) -{ - const std::vector<uint16_t> &prawdata=packet.rawdata(); +void ITSDAQCom::send(const ITSDAQPacket& packet) { + const std::vector<uint16_t>& prawdata = packet.rawdata(); - std::vector<uint8_t> rawdata(prawdata.size()*2); - for(uint32_t i=0;i<prawdata.size();i++) - { - rawdata[2*i+0]=((prawdata[i]>>8)&0xFF); - rawdata[2*i+1]=((prawdata[i]>>0)&0xFF); + std::vector<uint8_t> rawdata(prawdata.size() * 2); + for (uint32_t i = 0; i < prawdata.size(); i++) { + rawdata[2 * i + 0] = ((prawdata[i] >> 8) & 0xFF); + rawdata[2 * i + 1] = ((prawdata[i] >> 0) & 0xFF); } - /* - std::cout << "start send" << std::endl; - for(uint8_t x : rawdata) - std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (uint32_t)x << std::dec << std::endl; - std::cout << "end send" << std::endl; - */ - - ssize_t ssize=::sendto(m_socket, &rawdata[0], rawdata.size(), 0, (struct sockaddr*)&m_fpgaaddr, sizeof(m_fpgaaddr)); - if(ssize<0) - throw ITSDAQComException("send error: %s",std::strerror(errno)); + /* + std::cout << "start send" << std::endl; + for(uint8_t x : rawdata) + std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << + (uint32_t)x << std::dec << std::endl; std::cout << "end send" << std::endl; + */ + + ssize_t ssize = ::sendto(m_socket, &rawdata[0], rawdata.size(), 0, + (struct sockaddr*)&m_fpgaaddr, sizeof(m_fpgaaddr)); + if (ssize < 0) + throw ITSDAQComException("send error: %s", std::strerror(errno)); } -ITSDAQPacket ITSDAQCom::receive() -{ - // Wait for response - fd_set selList; - FD_ZERO(&selList); - FD_SET(m_socket, &selList); - - timeval timeOutVal; - timeOutVal.tv_sec = 0; - timeOutVal.tv_usec = 1000 * 100; // 100 ms - - int32_t result = select(m_socket + 1, &selList, NULL, NULL, &timeOutVal); - if(result!=1) - throw ITSDAQComException("No or too many replies from FPGA: "+std::to_string(result)); - - std::vector<uint8_t> buffer(128); - ssize_t rsize=::recv(m_socket, &buffer[0], 128, 0); - if(rsize<0) - throw ITSDAQComException("recv error: %s",std::strerror(errno)); - - std::vector<uint16_t> rawdata(rsize/2); - for(uint32_t i=0;i<rsize/2;i++) - rawdata[i]=(buffer[2*i+0]<<8)|(buffer[2*i+1]<<0); - - /*std::cout << "start receive" << std::endl; - for(uint16_t x : rawdata) - std::cout << "0x" << std::hex << std::setw(4) << std::setfill('0') << (uint32_t)x << std::dec << std::endl; - std::cout << "end receive" << std::endl;*/ - - return ITSDAQPacket(rawdata); +ITSDAQPacket ITSDAQCom::receive() { + // Wait for response + fd_set selList; + FD_ZERO(&selList); + FD_SET(m_socket, &selList); + + timeval timeOutVal; + timeOutVal.tv_sec = 0; + timeOutVal.tv_usec = 1000 * 100; // 100 ms + + int32_t result = select(m_socket + 1, &selList, NULL, NULL, &timeOutVal); + if (result != 1) + throw ITSDAQComException("No or too many replies from FPGA: " + + std::to_string(result)); + + std::vector<uint8_t> buffer(128); + ssize_t rsize = ::recv(m_socket, &buffer[0], 128, 0); + if (rsize < 0) + throw ITSDAQComException("recv error: %s", std::strerror(errno)); + + std::vector<uint16_t> rawdata(rsize / 2); + for (uint32_t i = 0; i < rsize / 2; i++) + rawdata[i] = (buffer[2 * i + 0] << 8) | (buffer[2 * i + 1] << 0); + + /*std::cout << "start receive" << std::endl; + for(uint16_t x : rawdata) + std::cout << "0x" << std::hex << std::setw(4) << std::setfill('0') << + (uint32_t)x << std::dec << std::endl; std::cout << "end receive" << + std::endl;*/ + + return ITSDAQPacket(rawdata); } diff --git a/pbv3/ITSDAQCom.h b/pbv3/ITSDAQCom.h index 13921f85dfd4348605f6824cf5d2dd47cd91961a..fc3e2a78711a99c56ccf7218b6d81b6b4249f7df 100644 --- a/pbv3/ITSDAQCom.h +++ b/pbv3/ITSDAQCom.h @@ -1,25 +1,24 @@ #ifndef ITSDAQCOM_H_ #define ITSDAQCOM_H_ -#include <string> -#include <cstdint> - #include <netinet/in.h> +#include <cstdint> +#include <string> + #include "ITSDAQPacket.h" -class ITSDAQCom -{ -public: - ITSDAQCom(const std::string& addr, uint32_t port); - ~ITSDAQCom(); +class ITSDAQCom { + public: + ITSDAQCom(const std::string& addr, uint32_t port); + ~ITSDAQCom(); - void send(const ITSDAQPacket& packet); - ITSDAQPacket receive(); + void send(const ITSDAQPacket& packet); + ITSDAQPacket receive(); -private: - int32_t m_socket=0; - struct sockaddr_in m_fpgaaddr; + private: + int32_t m_socket = 0; + struct sockaddr_in m_fpgaaddr; }; -#endif // ITSDAQCom +#endif // ITSDAQCom diff --git a/pbv3/ITSDAQComException.cpp b/pbv3/ITSDAQComException.cpp index 155d338292b09b8b8c0213fba917dcfc221367fe..bfb120887a6e53098f23ffbbc1a0f772feae35c1 100644 --- a/pbv3/ITSDAQComException.cpp +++ b/pbv3/ITSDAQComException.cpp @@ -1,20 +1,17 @@ #include "ITSDAQComException.h" ITSDAQComException::ITSDAQComException(const std::string& msg) - : m_msg("ITSDAQCom: "+msg) -{ } + : m_msg("ITSDAQCom: " + msg) {} -ITSDAQComException::ITSDAQComException(const char *format, ...) -{ - char buffer[256]; +ITSDAQComException::ITSDAQComException(const char* format, ...) { + char buffer[256]; - va_list args; - va_start( args, format ); - vsnprintf( buffer, 256, format, args ); - va_end( args ); + va_list args; + va_start(args, format); + vsnprintf(buffer, 256, format, args); + va_end(args); - m_msg=std::string("ITSDAQCom: ")+buffer; + m_msg = std::string("ITSDAQCom: ") + buffer; } -const char* ITSDAQComException::what() const throw() -{ return m_msg.c_str(); } +const char* ITSDAQComException::what() const throw() { return m_msg.c_str(); } diff --git a/pbv3/ITSDAQComException.h b/pbv3/ITSDAQComException.h index ff258804bd5fc87bd74eba69c6c567129be17f10..dacfb4a74051556ebbc7ebdae7b5065ab0fcb6c5 100644 --- a/pbv3/ITSDAQComException.h +++ b/pbv3/ITSDAQComException.h @@ -7,16 +7,15 @@ #include "ComException.h" -class ITSDAQComException : public ComException -{ -public: - ITSDAQComException(const std::string& msg); - ITSDAQComException(const char *format, ...); +class ITSDAQComException : public ComException { + public: + ITSDAQComException(const std::string& msg); + ITSDAQComException(const char* format, ...); - virtual const char* what() const throw(); + virtual const char* what() const throw(); -private: - std::string m_msg; + private: + std::string m_msg; }; -#endif // ITSDAQCOMEXCEPTION_H +#endif // ITSDAQCOMEXCEPTION_H diff --git a/pbv3/ITSDAQI2CCom.cpp b/pbv3/ITSDAQI2CCom.cpp index 76fe1fb338b8e6043815a4301205b3d06cb355fc..f11de0e899669772646be78bb0de435728f33fcc 100644 --- a/pbv3/ITSDAQI2CCom.cpp +++ b/pbv3/ITSDAQI2CCom.cpp @@ -1,432 +1,446 @@ #include "ITSDAQI2CCom.h" -#include "ComIOException.h" +#include <unistd.h> -#include <iostream> #include <iomanip> +#include <iostream> -#include <unistd.h> +#include "ComIOException.h" ITSDAQI2CCom::ITSDAQI2CCom(uint8_t deviceAddr, std::shared_ptr<ITSDAQCom> com) - : I2CCom(deviceAddr), m_com(com) -{ } - -ITSDAQI2CCom::~ITSDAQI2CCom() -{ } - -void ITSDAQI2CCom::write_reg32(uint32_t address, uint32_t data) -{ - std::vector<uint16_t> command(7); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|(address&0xFF); - command[3]=ITSDAQ_I2C_CMD_SEND1|((data>>24)&0xFF); - command[4]=ITSDAQ_I2C_CMD_SEND1|((data>>16)&0xFF); - command[5]=ITSDAQ_I2C_CMD_SEND1|((data>> 8)&0xFF); - command[6]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg32 failed: no opcode reply"); + : I2CCom(deviceAddr), m_com(com) {} + +ITSDAQI2CCom::~ITSDAQI2CCom() {} + +void ITSDAQI2CCom::write_reg32(uint32_t address, uint32_t data) { + std::vector<uint16_t> command(7); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | (address & 0xFF); + command[3] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 24) & 0xFF); + command[4] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 16) & 0xFF); + command[5] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 8) & 0xFF); + command[6] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_reg32 failed: no opcode reply"); } -void ITSDAQI2CCom::write_reg24(uint32_t address, uint32_t data) -{ - std::vector<uint16_t> command(6); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|(address&0xFF); - command[3]=ITSDAQ_I2C_CMD_SEND1|((data>>16)&0xFF); - command[4]=ITSDAQ_I2C_CMD_SEND1|((data>> 8)&0xFF); - command[5]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg16 failed: no opcode reply"); +void ITSDAQI2CCom::write_reg24(uint32_t address, uint32_t data) { + std::vector<uint16_t> command(6); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | (address & 0xFF); + command[3] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 16) & 0xFF); + command[4] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 8) & 0xFF); + command[5] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_reg16 failed: no opcode reply"); } -void ITSDAQI2CCom::write_reg16(uint32_t address, uint16_t data) -{ - std::vector<uint16_t> command(5); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|(address&0xFF); - command[3]=ITSDAQ_I2C_CMD_SEND1|((data>> 8)&0xFF); - command[4]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg16 failed: no opcode reply"); +void ITSDAQI2CCom::write_reg16(uint32_t address, uint16_t data) { + std::vector<uint16_t> command(5); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | (address & 0xFF); + command[3] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 8) & 0xFF); + command[4] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_reg16 failed: no opcode reply"); } -void ITSDAQI2CCom::write_reg8 (uint32_t address, uint8_t data) -{ - std::vector<uint16_t> command(4); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|(address&0xFF); - command[3]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg8 failed: no opcode reply"); +void ITSDAQI2CCom::write_reg8(uint32_t address, uint8_t data) { + std::vector<uint16_t> command(4); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | (address & 0xFF); + command[3] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom write_reg8 failed: no opcode reply"); } -void ITSDAQI2CCom::write_reg32(uint32_t data) -{ - std::vector<uint16_t> command(6); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|((data>>24)&0xFF); - command[3]=ITSDAQ_I2C_CMD_SEND1|((data>>16)&0xFF); - command[4]=ITSDAQ_I2C_CMD_SEND1|((data>> 8)&0xFF); - command[5]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg32 failed: no opcode reply"); +void ITSDAQI2CCom::write_reg32(uint32_t data) { + std::vector<uint16_t> command(6); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 24) & 0xFF); + command[3] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 16) & 0xFF); + command[4] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 8) & 0xFF); + command[5] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_reg32 failed: no opcode reply"); } -void ITSDAQI2CCom::write_reg24(uint32_t data) -{ - std::vector<uint16_t> command(5); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|((data>>16)&0xFF); - command[3]=ITSDAQ_I2C_CMD_SEND1|((data>> 8)&0xFF); - command[4]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg32 failed: no opcode reply"); +void ITSDAQI2CCom::write_reg24(uint32_t data) { + std::vector<uint16_t> command(5); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 16) & 0xFF); + command[3] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 8) & 0xFF); + command[4] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_reg32 failed: no opcode reply"); } -void ITSDAQI2CCom::write_reg16(uint16_t data) -{ - std::vector<uint16_t> command(4); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|((data>> 8)&0xFF); - command[3]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg16 failed: no opcode reply"); +void ITSDAQI2CCom::write_reg16(uint16_t data) { + std::vector<uint16_t> command(4); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | ((data >> 8) & 0xFF); + command[3] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_reg16 failed: no opcode reply"); } -void ITSDAQI2CCom::write_reg8 (uint8_t data) -{ - std::vector<uint16_t> command(3); - - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1|((data>> 0)&0xFF)|ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_reg8 failed: no opcode reply"); +void ITSDAQI2CCom::write_reg8(uint8_t data) { + std::vector<uint16_t> command(3); + + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = + ITSDAQ_I2C_CMD_SEND1 | ((data >> 0) & 0xFF) | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom write_reg8 failed: no opcode reply"); } -void ITSDAQI2CCom::write_block(uint32_t address, const std::vector<uint8_t>& data) -{ - std::vector<uint16_t> command(3+data.size()); - - uint32_t cmdidx=0; - command[cmdidx++]=0x0000 | 15; - command[cmdidx++]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[cmdidx++]=ITSDAQ_I2C_CMD_SEND1|(address&0xFF); - for(uint8_t byte : data) - command[cmdidx++]=ITSDAQ_I2C_CMD_SEND1|byte; - command[cmdidx-1]|=ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_block failed: no opcode reply"); +void ITSDAQI2CCom::write_block(uint32_t address, + const std::vector<uint8_t>& data) { + std::vector<uint16_t> command(3 + data.size()); + + uint32_t cmdidx = 0; + command[cmdidx++] = 0x0000 | 15; + command[cmdidx++] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[cmdidx++] = ITSDAQ_I2C_CMD_SEND1 | (address & 0xFF); + for (uint8_t byte : data) command[cmdidx++] = ITSDAQ_I2C_CMD_SEND1 | byte; + command[cmdidx - 1] |= ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_block failed: no opcode reply"); } -void ITSDAQI2CCom::write_block(const std::vector<uint8_t>& data) -{ - std::vector<uint16_t> command(2+data.size()); - - uint32_t cmdidx=0; - command[cmdidx++]=0x0000 | 15; - command[cmdidx++]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - for(uint8_t byte : data) - command[cmdidx++]=ITSDAQ_I2C_CMD_SEND1|byte; - command[cmdidx-1]|=ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom write_block failed: no opcode reply"); +void ITSDAQI2CCom::write_block(const std::vector<uint8_t>& data) { + std::vector<uint16_t> command(2 + data.size()); + + uint32_t cmdidx = 0; + command[cmdidx++] = 0x0000 | 15; + command[cmdidx++] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + for (uint8_t byte : data) command[cmdidx++] = ITSDAQ_I2C_CMD_SEND1 | byte; + command[cmdidx - 1] |= ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException( + "ITSDAQI2CCom write_block failed: no opcode reply"); } -uint32_t ITSDAQI2CCom::read_reg32(uint32_t address) -{ - std::vector<uint16_t> command(6); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1 | address&0xFF; - command[3]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[4]=ITSDAQ_I2C_CMD_READ2; - command[5]=ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return (retopcode.payload()[2]<<16)|(retopcode.payload()[3]<< 0); +uint32_t ITSDAQI2CCom::read_reg32(uint32_t address) { + std::vector<uint16_t> command(6); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | address & 0xFF; + command[3] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[4] = ITSDAQ_I2C_CMD_READ2; + command[5] = ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return (retopcode.payload()[2] << 16) | (retopcode.payload()[3] << 0); } -uint32_t ITSDAQI2CCom::read_reg24(uint32_t address) -{ - std::vector<uint16_t> command(5); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1 | address&0xFF; - command[3]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[4]=ITSDAQ_I2C_CMD_READ1; - command[5]=ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return (retopcode.payload()[2]<<16)|(retopcode.payload()[3]<< 0); +uint32_t ITSDAQI2CCom::read_reg24(uint32_t address) { + std::vector<uint16_t> command(5); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | address & 0xFF; + command[3] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[4] = ITSDAQ_I2C_CMD_READ1; + command[5] = ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return (retopcode.payload()[2] << 16) | (retopcode.payload()[3] << 0); } -uint16_t ITSDAQI2CCom::read_reg16(uint32_t address) -{ - std::vector<uint16_t> command(5); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1 | address&0xFF; - command[3]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[4]=ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg16 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return retopcode.payload()[2]; +uint16_t ITSDAQI2CCom::read_reg16(uint32_t address) { + std::vector<uint16_t> command(5); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | address & 0xFF; + command[3] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[4] = ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg16 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return retopcode.payload()[2]; } -uint8_t ITSDAQI2CCom::read_reg8 (uint32_t address) -{ - std::vector<uint16_t> command(5); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[2]=ITSDAQ_I2C_CMD_SEND1 | address&0xFF; - command[3]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[4]=ITSDAQ_I2C_CMD_READ1 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg8 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return retopcode.payload()[2]&0xFF; +uint8_t ITSDAQI2CCom::read_reg8(uint32_t address) { + std::vector<uint16_t> command(5); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[2] = ITSDAQ_I2C_CMD_SEND1 | address & 0xFF; + command[3] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[4] = ITSDAQ_I2C_CMD_READ1 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg8 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return retopcode.payload()[2] & 0xFF; } -uint32_t ITSDAQI2CCom::read_reg32() -{ - std::vector<uint16_t> command(4); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[2]=ITSDAQ_I2C_CMD_READ2; - command[3]=ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return (retopcode.payload()[2]<<16)|(retopcode.payload()[3]<< 0); +uint32_t ITSDAQI2CCom::read_reg32() { + std::vector<uint16_t> command(4); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[2] = ITSDAQ_I2C_CMD_READ2; + command[3] = ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return (retopcode.payload()[2] << 16) | (retopcode.payload()[3] << 0); } -uint32_t ITSDAQI2CCom::read_reg24() -{ - std::vector<uint16_t> command(4); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[2]=ITSDAQ_I2C_CMD_READ1; - command[3]=ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return (retopcode.payload()[2]<<16)|(retopcode.payload()[3]<< 0); +uint32_t ITSDAQI2CCom::read_reg24() { + std::vector<uint16_t> command(4); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[2] = ITSDAQ_I2C_CMD_READ1; + command[3] = ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg32 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return (retopcode.payload()[2] << 16) | (retopcode.payload()[3] << 0); } -uint16_t ITSDAQI2CCom::read_reg16() -{ - std::vector<uint16_t> command(3); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[2]=ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg16 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return retopcode.payload()[2]; +uint16_t ITSDAQI2CCom::read_reg16() { + std::vector<uint16_t> command(3); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[2] = ITSDAQ_I2C_CMD_READ2 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg16 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return retopcode.payload()[2]; } -uint8_t ITSDAQI2CCom::read_reg8 () -{ - std::vector<uint16_t> command(3); - command[0]=0x0000 | 15; - command[1]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - command[2]=ITSDAQ_I2C_CMD_READ1 | ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_reg8 failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - return (retopcode.payload()[2]&0xFF); +uint8_t ITSDAQI2CCom::read_reg8() { + std::vector<uint16_t> command(3); + command[0] = 0x0000 | 15; + command[1] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + command[2] = ITSDAQ_I2C_CMD_READ1 | ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_reg8 failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + return (retopcode.payload()[2] & 0xFF); } -void ITSDAQI2CCom::read_block(uint32_t address, std::vector<uint8_t>& data) -{ - uint32_t n2reads=data.size()/2; - uint32_t n1reads=data.size()%2; - - std::vector<uint16_t> command(4+n2reads+n1reads); - - uint32_t cmdidx=0; - command[cmdidx++]=0x0000 | 15; - command[cmdidx++]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 0; - command[cmdidx++]=ITSDAQ_I2C_CMD_SEND1 | address&0xFF; - command[cmdidx++]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - for(uint32_t i=0;i<n2reads;i++) - command[cmdidx++]=ITSDAQ_I2C_CMD_READ2; - for(uint32_t i=0;i<n1reads;i++) - command[cmdidx++]=ITSDAQ_I2C_CMD_READ1; - command[cmdidx-1]|=ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_block failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - - cmdidx=0; - uint32_t pidx=2; - for(uint32_t i=0;i<n2reads;i++) - { - data[cmdidx++]=(retopcode.payload()[pidx ]>>8)&0xFF; - data[cmdidx++]=(retopcode.payload()[pidx++]>>0)&0xFF; +void ITSDAQI2CCom::read_block(uint32_t address, std::vector<uint8_t>& data) { + uint32_t n2reads = data.size() / 2; + uint32_t n1reads = data.size() % 2; + + std::vector<uint16_t> command(4 + n2reads + n1reads); + + uint32_t cmdidx = 0; + command[cmdidx++] = 0x0000 | 15; + command[cmdidx++] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 0; + command[cmdidx++] = ITSDAQ_I2C_CMD_SEND1 | address & 0xFF; + command[cmdidx++] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + for (uint32_t i = 0; i < n2reads; i++) + command[cmdidx++] = ITSDAQ_I2C_CMD_READ2; + for (uint32_t i = 0; i < n1reads; i++) + command[cmdidx++] = ITSDAQ_I2C_CMD_READ1; + command[cmdidx - 1] |= ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_block failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + + cmdidx = 0; + uint32_t pidx = 2; + for (uint32_t i = 0; i < n2reads; i++) { + data[cmdidx++] = (retopcode.payload()[pidx] >> 8) & 0xFF; + data[cmdidx++] = (retopcode.payload()[pidx++] >> 0) & 0xFF; } - for(uint32_t i=0;i<n1reads;i++) - { - data[cmdidx++]=(retopcode.payload()[pidx++]>>0)&0xFF; + for (uint32_t i = 0; i < n1reads; i++) { + data[cmdidx++] = (retopcode.payload()[pidx++] >> 0) & 0xFF; } } -void ITSDAQI2CCom::read_block(std::vector<uint8_t>& data) -{ - uint32_t n2reads=data.size()/2; - uint32_t n1reads=data.size()%2; - - std::vector<uint16_t> command(2+n2reads+n1reads); - - uint32_t cmdidx=0; - command[cmdidx++]=0x0000 | 15; - command[cmdidx++]=ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr()<<1) | 1; - for(uint32_t i=0;i<n2reads;i++) - command[cmdidx++]=ITSDAQ_I2C_CMD_READ2; - for(uint32_t i=0;i<n1reads;i++) - command[cmdidx++]=ITSDAQ_I2C_CMD_READ1; - command[cmdidx-1]|=ITSDAQ_I2C_CMD_STOP; - - ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); - ITSDAQPacket packet(0, {opcode}); - m_com->send(packet); - packet=m_com->receive(); - if(packet.nOpcodes()!=1) - throw ComIOException("ITSDAQI2CCom read_block failed: no opcode reply"); - - ITSDAQOpCode retopcode=packet.opcode(0); - - cmdidx=0; - uint32_t pidx=2; - for(uint32_t i=0;i<n2reads;i++) - { - data[cmdidx++]=(retopcode.payload()[pidx ]>>8)&0xFF; - data[cmdidx++]=(retopcode.payload()[pidx++]>>0)&0xFF; +void ITSDAQI2CCom::read_block(std::vector<uint8_t>& data) { + uint32_t n2reads = data.size() / 2; + uint32_t n1reads = data.size() % 2; + + std::vector<uint16_t> command(2 + n2reads + n1reads); + + uint32_t cmdidx = 0; + command[cmdidx++] = 0x0000 | 15; + command[cmdidx++] = + ITSDAQ_I2C_CMD_START | ITSDAQ_I2C_CMD_SEND1 | (deviceAddr() << 1) | 1; + for (uint32_t i = 0; i < n2reads; i++) + command[cmdidx++] = ITSDAQ_I2C_CMD_READ2; + for (uint32_t i = 0; i < n1reads; i++) + command[cmdidx++] = ITSDAQ_I2C_CMD_READ1; + command[cmdidx - 1] |= ITSDAQ_I2C_CMD_STOP; + + ITSDAQOpCode opcode(0, ITSDAQ_OPCODE_TWOWIRE, command); + ITSDAQPacket packet(0, {opcode}); + m_com->send(packet); + packet = m_com->receive(); + if (packet.nOpcodes() != 1) + throw ComIOException("ITSDAQI2CCom read_block failed: no opcode reply"); + + ITSDAQOpCode retopcode = packet.opcode(0); + + cmdidx = 0; + uint32_t pidx = 2; + for (uint32_t i = 0; i < n2reads; i++) { + data[cmdidx++] = (retopcode.payload()[pidx] >> 8) & 0xFF; + data[cmdidx++] = (retopcode.payload()[pidx++] >> 0) & 0xFF; } - for(uint32_t i=0;i<n1reads;i++) - { - data[cmdidx++]=(retopcode.payload()[pidx++]>>0)&0xFF; + for (uint32_t i = 0; i < n1reads; i++) { + data[cmdidx++] = (retopcode.payload()[pidx++] >> 0) & 0xFF; } } diff --git a/pbv3/ITSDAQI2CCom.h b/pbv3/ITSDAQI2CCom.h index 709c96bbdfe0f6ff0e306faaec314238333c1eba..79c3bdb2690cd3b9964be0b83f1fc4f3e3de28cb 100644 --- a/pbv3/ITSDAQI2CCom.h +++ b/pbv3/ITSDAQI2CCom.h @@ -1,55 +1,55 @@ #ifndef ITSDAQI2CCOM_H #define ITSDAQI2CCOM_H +#include <memory> + #include "I2CCom.h" #include "ITSDAQCom.h" -#include <memory> - #define ITSDAQ_I2C_CMD_START 0x0800 -#define ITSDAQ_I2C_CMD_STOP 0x1000 +#define ITSDAQ_I2C_CMD_STOP 0x1000 #define ITSDAQ_I2C_CMD_SEND1 0x0400 #define ITSDAQ_I2C_CMD_READ1 0x0100 #define ITSDAQ_I2C_CMD_READ2 0x0200 -class ITSDAQI2CCom : public I2CCom -{ -public: - ITSDAQI2CCom(uint8_t deviceAddr, std::shared_ptr<ITSDAQCom> com); - virtual ~ITSDAQI2CCom(); - - // - // Write commands - virtual void write_reg32(uint32_t address, uint32_t data); - virtual void write_reg24(uint32_t address, uint32_t data); - virtual void write_reg16(uint32_t address, uint16_t data); - virtual void write_reg8 (uint32_t address, uint8_t data); - - virtual void write_reg32(uint32_t data); - virtual void write_reg24(uint32_t data); - virtual void write_reg16(uint16_t data); - virtual void write_reg8 (uint8_t data); - - virtual void write_block(uint32_t address, const std::vector<uint8_t>& data); - virtual void write_block(const std::vector<uint8_t>& data); - - // - // Read commands - virtual uint32_t read_reg32(uint32_t address); - virtual uint32_t read_reg24(uint32_t address); - virtual uint16_t read_reg16(uint32_t address); - virtual uint8_t read_reg8 (uint32_t address); - - virtual uint32_t read_reg32(); - virtual uint32_t read_reg24(); - virtual uint16_t read_reg16(); - virtual uint8_t read_reg8 (); - - virtual void read_block(uint32_t address, std::vector<uint8_t>& data); - virtual void read_block(std::vector<uint8_t>& data); - -private: - std::shared_ptr<ITSDAQCom> m_com; +class ITSDAQI2CCom : public I2CCom { + public: + ITSDAQI2CCom(uint8_t deviceAddr, std::shared_ptr<ITSDAQCom> com); + virtual ~ITSDAQI2CCom(); + + // + // Write commands + virtual void write_reg32(uint32_t address, uint32_t data); + virtual void write_reg24(uint32_t address, uint32_t data); + virtual void write_reg16(uint32_t address, uint16_t data); + virtual void write_reg8(uint32_t address, uint8_t data); + + virtual void write_reg32(uint32_t data); + virtual void write_reg24(uint32_t data); + virtual void write_reg16(uint16_t data); + virtual void write_reg8(uint8_t data); + + virtual void write_block(uint32_t address, + const std::vector<uint8_t>& data); + virtual void write_block(const std::vector<uint8_t>& data); + + // + // Read commands + virtual uint32_t read_reg32(uint32_t address); + virtual uint32_t read_reg24(uint32_t address); + virtual uint16_t read_reg16(uint32_t address); + virtual uint8_t read_reg8(uint32_t address); + + virtual uint32_t read_reg32(); + virtual uint32_t read_reg24(); + virtual uint16_t read_reg16(); + virtual uint8_t read_reg8(); + + virtual void read_block(uint32_t address, std::vector<uint8_t>& data); + virtual void read_block(std::vector<uint8_t>& data); + + private: + std::shared_ptr<ITSDAQCom> m_com; }; -#endif // ITSDAQI2CCOM_H +#endif // ITSDAQI2CCOM_H diff --git a/pbv3/ITSDAQOpCode.cpp b/pbv3/ITSDAQOpCode.cpp index c0ad051b00e635d1f7859b51db529215e96b7184..b7def43485108c0342365244fe9044008d3e302f 100644 --- a/pbv3/ITSDAQOpCode.cpp +++ b/pbv3/ITSDAQOpCode.cpp @@ -1,21 +1,18 @@ #include "ITSDAQOpCode.h" -ITSDAQOpCode::ITSDAQOpCode(uint16_t seqNum, uint16_t opcode, const std::vector<uint16_t>& payload) - : m_seqNum(seqNum), m_opcode(opcode), m_payload(payload) -{ } +ITSDAQOpCode::ITSDAQOpCode(uint16_t seqNum, uint16_t opcode, + const std::vector<uint16_t>& payload) + : m_seqNum(seqNum), m_opcode(opcode), m_payload(payload) {} -uint16_t ITSDAQOpCode::opcode() const -{ return m_opcode; } +uint16_t ITSDAQOpCode::opcode() const { return m_opcode; } -std::vector<uint16_t> ITSDAQOpCode::payload() const -{ return m_payload; } +std::vector<uint16_t> ITSDAQOpCode::payload() const { return m_payload; } -std::vector<uint16_t> ITSDAQOpCode::data() const -{ - std::vector<uint16_t> rawdata(3+m_payload.size()); - rawdata[0]=m_opcode; - rawdata[1]=m_seqNum; - rawdata[2]=m_payload.size()*2; - std::copy(m_payload.begin(),m_payload.end(), rawdata.begin()+3); - return rawdata; +std::vector<uint16_t> ITSDAQOpCode::data() const { + std::vector<uint16_t> rawdata(3 + m_payload.size()); + rawdata[0] = m_opcode; + rawdata[1] = m_seqNum; + rawdata[2] = m_payload.size() * 2; + std::copy(m_payload.begin(), m_payload.end(), rawdata.begin() + 3); + return rawdata; } diff --git a/pbv3/ITSDAQOpCode.h b/pbv3/ITSDAQOpCode.h index 27c41a6dd9acfef1110751a03ed57b23b8b7fd06..ac27d3a4e1dfb7052fb792775ee0ef78d049fa26 100644 --- a/pbv3/ITSDAQOpCode.h +++ b/pbv3/ITSDAQOpCode.h @@ -4,24 +4,24 @@ #include <cstdint> #include <vector> -#define ITSDAQ_OPCODE_ECHO 0x0003 +#define ITSDAQ_OPCODE_ECHO 0x0003 #define ITSDAQ_OPCODE_TWOWIRE 0x0080 -#define ITSDAQ_OPCODE_EMORSE 0x008E +#define ITSDAQ_OPCODE_EMORSE 0x008E -class ITSDAQOpCode -{ -public: - ITSDAQOpCode(uint16_t seqnum, uint16_t opcode, const std::vector<uint16_t>& payload); +class ITSDAQOpCode { + public: + ITSDAQOpCode(uint16_t seqnum, uint16_t opcode, + const std::vector<uint16_t>& payload); - uint16_t opcode() const; - std::vector<uint16_t> payload() const; + uint16_t opcode() const; + std::vector<uint16_t> payload() const; - std::vector<uint16_t> data() const; + std::vector<uint16_t> data() const; -private: - uint16_t m_seqNum; - uint16_t m_opcode; - std::vector<uint16_t> m_payload; + private: + uint16_t m_seqNum; + uint16_t m_opcode; + std::vector<uint16_t> m_payload; }; -#endif // ITSDAQOPCODE +#endif // ITSDAQOPCODE diff --git a/pbv3/ITSDAQPacket.cpp b/pbv3/ITSDAQPacket.cpp index d75c11acbb2ccfc5ef4d70118f1a32db1b61350d..ead415d11310b3d07516168ce62cef60f6a60663 100644 --- a/pbv3/ITSDAQPacket.cpp +++ b/pbv3/ITSDAQPacket.cpp @@ -1,151 +1,147 @@ #include "ITSDAQPacket.h" -#include "ITSDAQComException.h" - -#include <iostream> #include <iomanip> +#include <iostream> + +#include "ITSDAQComException.h" static uint16_t crcTable[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0}; + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, + 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, + 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, + 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, + 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, + 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, + 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, + 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, + 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, + 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 0x6ca6, 0x7c87, 0x4ce4, + 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, + 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, + 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, + 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, + 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, + 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, + 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0, + 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, + 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, + 0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, + 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, + 0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, + 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, + 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, + 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, + 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0}; ITSDAQPacket::ITSDAQPacket(const std::vector<uint16_t>& rawdata) - : m_packet(rawdata) -{ - // Size check - if(rawdata.size()<5) - throw ITSDAQComException("Packet needs to have at least 5 fields. Found %d",rawdata.size()); - - // Magic check - uint16_t magic=rawdata[0]; - if((magic&0xFFF0)!=0x8760) - throw ITSDAQComException("Wrong magic number. Found %04x.",magic); - - // Length check - uint16_t length=rawdata[2]; - if(length!=2*rawdata.size()) - throw ITSDAQComException("Wrong packet length! Got %d bytes, expected %d bytes.",rawdata.size()*2,length); - - // CRC check - uint16_t checksum=rawdata[rawdata.size()-1]; - if(checksum!=0x0c7c) // Fixed for UDP transition, since the internal UDP CRC is used instead - throw ITSDAQComException("Checksum failed! Got %04x, expected 0x0c7c.",checksum); - - // Opcode parsing - uint16_t numOpcodes=rawdata[3]; - m_opcodes.clear(); - std::vector<uint16_t>::const_iterator rawiter=rawdata.cbegin()+4; - for(uint16_t i=0;i<numOpcodes;i++) - { - uint16_t opcodeid=(*rawiter); - rawiter++; - uint16_t opseqnum=(*rawiter); - rawiter++; - uint16_t oplength=(*rawiter); - rawiter++; - std::vector<uint16_t> payload(oplength/2); - std::copy(rawiter,rawiter+oplength/2,payload.begin()); - m_opcodes.push_back(ITSDAQOpCode(opseqnum, opcodeid, payload)); + : m_packet(rawdata) { + // Size check + if (rawdata.size() < 5) + throw ITSDAQComException( + "Packet needs to have at least 5 fields. Found %d", rawdata.size()); + + // Magic check + uint16_t magic = rawdata[0]; + if ((magic & 0xFFF0) != 0x8760) + throw ITSDAQComException("Wrong magic number. Found %04x.", magic); + + // Length check + uint16_t length = rawdata[2]; + if (length != 2 * rawdata.size()) + throw ITSDAQComException( + "Wrong packet length! Got %d bytes, expected %d bytes.", + rawdata.size() * 2, length); + + // CRC check + uint16_t checksum = rawdata[rawdata.size() - 1]; + if (checksum != 0x0c7c) // Fixed for UDP transition, since the internal UDP + // CRC is used instead + throw ITSDAQComException("Checksum failed! Got %04x, expected 0x0c7c.", + checksum); + + // Opcode parsing + uint16_t numOpcodes = rawdata[3]; + m_opcodes.clear(); + std::vector<uint16_t>::const_iterator rawiter = rawdata.cbegin() + 4; + for (uint16_t i = 0; i < numOpcodes; i++) { + uint16_t opcodeid = (*rawiter); + rawiter++; + uint16_t opseqnum = (*rawiter); + rawiter++; + uint16_t oplength = (*rawiter); + rawiter++; + std::vector<uint16_t> payload(oplength / 2); + std::copy(rawiter, rawiter + oplength / 2, payload.begin()); + m_opcodes.push_back(ITSDAQOpCode(opseqnum, opcodeid, payload)); } } -ITSDAQPacket::ITSDAQPacket(uint16_t seqNum, const std::vector<ITSDAQOpCode>& opcodes) - : m_opcodes(opcodes) -{ - // - // Build the packet - m_packet=std::vector<uint16_t>(4); +ITSDAQPacket::ITSDAQPacket(uint16_t seqNum, + const std::vector<ITSDAQOpCode>& opcodes) + : m_opcodes(opcodes) { + // + // Build the packet + m_packet = std::vector<uint16_t>(4); - // magic number - m_packet[0]=0x8765; + // magic number + m_packet[0] = 0x8765; - // sequence number - m_packet[1]=seqNum; + // sequence number + m_packet[1] = seqNum; - // length (end) - m_packet[2]=0; + // length (end) + m_packet[2] = 0; - // opcode count - m_packet[3]=opcodes.size(); + // opcode count + m_packet[3] = opcodes.size(); - // the opcodes - for(const ITSDAQOpCode& opcode : opcodes) - { - const std::vector<uint16_t>& opdata=opcode.data(); - m_packet.insert(m_packet.end(),opdata.begin(),opdata.end()); + // the opcodes + for (const ITSDAQOpCode& opcode : opcodes) { + const std::vector<uint16_t>& opdata = opcode.data(); + m_packet.insert(m_packet.end(), opdata.begin(), opdata.end()); } - // CRC - m_packet.push_back(checksum()); + // CRC + m_packet.push_back(checksum()); - // length - m_packet[2]=m_packet.size()*2; + // length + m_packet[2] = m_packet.size() * 2; - /* - std::cout << "Packet is " << std::endl; - for(uint16_t x : m_packet) - std::cout << "0x" << std::hex << std::setw(4) << std::setfill('0') << x << std::dec << std::endl; - */ + /* + std::cout << "Packet is " << std::endl; + for(uint16_t x : m_packet) + std::cout << "0x" << std::hex << std::setw(4) << std::setfill('0') << x << + std::dec << std::endl; + */ } -uint16_t ITSDAQPacket::nOpcodes() const -{ return m_opcodes.size(); } - -ITSDAQOpCode ITSDAQPacket::opcode(uint16_t idx) const -{ return m_opcodes.at(idx); } +uint16_t ITSDAQPacket::nOpcodes() const { return m_opcodes.size(); } +ITSDAQOpCode ITSDAQPacket::opcode(uint16_t idx) const { + return m_opcodes.at(idx); +} -std::vector<uint16_t> ITSDAQPacket::rawdata() const -{ return m_packet; } +std::vector<uint16_t> ITSDAQPacket::rawdata() const { return m_packet; } -uint16_t ITSDAQPacket::checksum() const -{ - uint16_t checksum = 0x0; +uint16_t ITSDAQPacket::checksum() const { + uint16_t checksum = 0x0; - for(uint32_t i=0; i<m_packet.size(); i++) - { - uint16_t newData=m_packet[i]; + for (uint32_t i = 0; i < m_packet.size(); i++) { + uint16_t newData = m_packet[i]; - uint8_t byte; + uint8_t byte; - byte=(newData>>8)&0xFF; - byte=((checksum >> 8)^byte); - checksum=(checksum<<8) ^ crcTable[byte]; + byte = (newData >> 8) & 0xFF; + byte = ((checksum >> 8) ^ byte); + checksum = (checksum << 8) ^ crcTable[byte]; - byte=(newData>>0)&0xFF; - byte=((checksum >> 8)^byte); - checksum=(checksum<<8) ^ crcTable[byte]; + byte = (newData >> 0) & 0xFF; + byte = ((checksum >> 8) ^ byte); + checksum = (checksum << 8) ^ crcTable[byte]; } - return checksum; + return checksum; } diff --git a/pbv3/ITSDAQPacket.h b/pbv3/ITSDAQPacket.h index 1cd33849cf533e1cbc31cd15a1b646a7972a0d64..b5073f2b1dd91204941982c58da94c9e02cd3269 100644 --- a/pbv3/ITSDAQPacket.h +++ b/pbv3/ITSDAQPacket.h @@ -1,29 +1,26 @@ #ifndef ITSDAQPACKET_H_ #define ITSDAQPACKET_H_ -#include <vector> #include <cstdint> +#include <vector> #include "ITSDAQOpCode.h" -class ITSDAQPacket -{ -public: - ITSDAQPacket(const std::vector<uint16_t>& rawdata); - ITSDAQPacket(uint16_t seqNum, const std::vector<ITSDAQOpCode>& opcodes); +class ITSDAQPacket { + public: + ITSDAQPacket(const std::vector<uint16_t>& rawdata); + ITSDAQPacket(uint16_t seqNum, const std::vector<ITSDAQOpCode>& opcodes); + uint16_t checksum() const; - uint16_t checksum() const; + std::vector<uint16_t> rawdata() const; - std::vector<uint16_t> rawdata() const; + uint16_t nOpcodes() const; + ITSDAQOpCode opcode(uint16_t idx) const; - uint16_t nOpcodes() const; - ITSDAQOpCode opcode(uint16_t idx) const; - - -private: - std::vector<uint16_t> m_packet; - std::vector<ITSDAQOpCode> m_opcodes; + private: + std::vector<uint16_t> m_packet; + std::vector<ITSDAQOpCode> m_opcodes; }; -#endif // ITSDAQPACKET_H_ +#endif // ITSDAQPACKET_H_ diff --git a/pbv3/PBv3CarrierTools.cpp b/pbv3/PBv3CarrierTools.cpp index f18517e61d90986092cbc256c86fdce630a1638d..c636b4805252da9c3112d6c8f009b7a0e98bf4f1 100644 --- a/pbv3/PBv3CarrierTools.cpp +++ b/pbv3/PBv3CarrierTools.cpp @@ -1,22 +1,23 @@ #include "PBv3CarrierTools.h" -#include "PBv3Utils.h" -#include "ComException.h" - #include <memory> #include <thread> +#include "ComException.h" +#include "PBv3Utils.h" + using namespace nlohmann; -namespace PBv3CarrierTools -{ - json testLvEnable(std::shared_ptr<PBv3TBMassive> tb) - { - logger(logINFO) << "## LV Enable test ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +namespace PBv3CarrierTools { +json testLvEnable(std::shared_ptr<PBv3TBMassive> tb) { + logger(logINFO) << "## LV Enable test ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "LV_ENABLE"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = false; tb->powerLVOn(); @@ -25,15 +26,17 @@ namespace PBv3CarrierTools std::this_thread::sleep_for(std::chrono::milliseconds(500)); // read interesting values - double Iin = tb->getLVPS()->measureCurrent(); - double Vin = tb->getLVPS()->measureVoltage(); + double Iin = tb->getLVPS()->measureCurrent(); + double Vin = tb->getLVPS()->measureVoltage(); - testSum["passed"] = (Iin<5e-3); + testSum["passed"] = (Iin < 5e-3); - if(testSum["passed"]) - logger(logINFO) << " --> Reading " << Iin << "A with " << Vin << "V supplied"; + if (testSum["passed"]) + logger(logINFO) << " --> Reading " << Iin << "A with " << Vin + << "V supplied"; else - logger(logERROR) << " --> Reading " << Iin << "A with " << Vin << "V supplied"; + logger(logERROR) << " --> Reading " << Iin << "A with " << Vin + << "V supplied"; testSum["results"]["VIN"] = Vin; testSum["results"]["IIN"] = Iin; @@ -41,39 +44,43 @@ namespace PBv3CarrierTools tb->powerLVOff(); return testSum; - } +} - json testMuxes(std::shared_ptr<PBv3TBMassive> tb) - { - logger(logINFO) << "## Multiplexer test test ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +json testMuxes(std::shared_ptr<PBv3TBMassive> tb) { + logger(logINFO) << "## Multiplexer test test ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "MUXCOM"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = false; - std::cout << "PBNUM" << "\t" << "OUTPUT" << "\t" << "VALUE" << std::endl; - for(uint32_t i=0; i<10; i++) - { - float out=0; - bool commok=true; - try - { - out=tb->readCarrierOutput(i, PBv3TB::LINPOL1V4); - } - catch(const ComException& e) - { - logger(logERROR) << "Error switching multiplexers!"; - commok=false; - } - std::cout << i << "\t" << "LINPOL1V4" << "\t" << out << std::endl; - testSum["results"]["PBNUM" ][i] = i; - testSum["results"]["OUTPUT"][i] = "LINPOL1V4"; - testSum["results"]["VALUE" ][i] = out; - testSum["results"]["COMMOK"][i] = commok; - testSum["passed"] = ((out<50e-3) || testSum["passed"]); - } + std::cout << "PBNUM" + << "\t" + << "OUTPUT" + << "\t" + << "VALUE" << std::endl; + for (uint32_t i = 0; i < 10; i++) { + float out = 0; + bool commok = true; + try { + out = tb->readCarrierOutput(i, PBv3TB::LINPOL1V4); + } catch (const ComException& e) { + logger(logERROR) << "Error switching multiplexers!"; + commok = false; + } + std::cout << i << "\t" + << "LINPOL1V4" + << "\t" << out << std::endl; + testSum["results"]["PBNUM"][i] = i; + testSum["results"]["OUTPUT"][i] = "LINPOL1V4"; + testSum["results"]["VALUE"][i] = out; + testSum["results"]["COMMOK"][i] = commok; + testSum["passed"] = ((out < 50e-3) || testSum["passed"]); + } return testSum; - } } +} // namespace PBv3CarrierTools diff --git a/pbv3/PBv3CarrierTools.h b/pbv3/PBv3CarrierTools.h index 273f4adcf1161daa9c3698a3c124b14945fe46ef..46a785cb145c5d6d818f55ffe0e2d66d1fe1dc3b 100644 --- a/pbv3/PBv3CarrierTools.h +++ b/pbv3/PBv3CarrierTools.h @@ -1,42 +1,41 @@ #ifndef PBV3CARRIERTOOLS_H #define PBV3CARRIERTOOLS_H -#include "PBv3TBMassive.h" - #include <nlohmann/json.hpp> +#include "PBv3TBMassive.h" + /** * \brief Module defining several tests for a plain carrier card * * - All tests return a JSON format that can be directly * uploaded to the ITk Production Database */ -namespace PBv3CarrierTools -{ +namespace PBv3CarrierTools { - //! \brief LV_ENABLE Check current with 11V on - /** - * Pass: Input current is below 5 mA. - * - * \param tb Testbench object - * - * \return json object with test results - */ - nlohmann::json testLvEnable(std::shared_ptr<PBv3TBMassive> tb); +//! \brief LV_ENABLE Check current with 11V on +/** + * Pass: Input current is below 5 mA. + * + * \param tb Testbench object + * + * \return json object with test results + */ +nlohmann::json testLvEnable(std::shared_ptr<PBv3TBMassive> tb); - //! \brief MUXCOM Test communication with multiplexers - /** - * This really test communication with the IO expander used to - * select the multiplexers. - * - * Pass: Toggling of all 10 multiplexers works and all return <50 mV - * - * \param tb Testbench object - * - * \return json object with test results - */ - nlohmann::json testMuxes(std::shared_ptr<PBv3TBMassive> tb); +//! \brief MUXCOM Test communication with multiplexers +/** + * This really test communication with the IO expander used to + * select the multiplexers. + * + * Pass: Toggling of all 10 multiplexers works and all return <50 mV + * + * \param tb Testbench object + * + * \return json object with test results + */ +nlohmann::json testMuxes(std::shared_ptr<PBv3TBMassive> tb); -} +} // namespace PBv3CarrierTools -#endif // PBV3CARRIERTOOLS_H +#endif // PBV3CARRIERTOOLS_H diff --git a/pbv3/PBv3CommPatchSPICom.cpp b/pbv3/PBv3CommPatchSPICom.cpp index 17c62b22fe5f493892c756d92c39c7c8f7e279dd..4799aa251399bab1d53b31beb03abb5d3dae9da8 100644 --- a/pbv3/PBv3CommPatchSPICom.cpp +++ b/pbv3/PBv3CommPatchSPICom.cpp @@ -1,243 +1,219 @@ #include "PBv3CommPatchSPICom.h" -#include "ftdihelp.h" - #include <libftdi1/ftdi.h> #include <chrono> #include <thread> -PBv3CommPatchSPICom::PBv3CommPatchSPICom(struct ftdi_context *ftdi, uint8_t csbit) - : m_ftdi(ftdi), m_csbit(csbit) -{ } +#include "ftdihelp.h" -PBv3CommPatchSPICom::~PBv3CommPatchSPICom() -{ } +PBv3CommPatchSPICom::PBv3CommPatchSPICom(struct ftdi_context* ftdi, + uint8_t csbit) + : m_ftdi(ftdi), m_csbit(csbit) {} -void PBv3CommPatchSPICom::write_reg32(uint32_t address, uint32_t data) -{ - write_reg32(address); - write_block({static_cast<uint8_t>((data>>24)&0xFF), - static_cast<uint8_t>((data>>16)&0xFF), - static_cast<uint8_t>((data>> 8)&0xFF), - static_cast<uint8_t>((data>> 0)&0xFF)}); +PBv3CommPatchSPICom::~PBv3CommPatchSPICom() {} + +void PBv3CommPatchSPICom::write_reg32(uint32_t address, uint32_t data) { + write_reg32(address); + write_block({static_cast<uint8_t>((data >> 24) & 0xFF), + static_cast<uint8_t>((data >> 16) & 0xFF), + static_cast<uint8_t>((data >> 8) & 0xFF), + static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_reg24(uint32_t address, uint32_t data) -{ - write_reg32(address); - write_block({static_cast<uint8_t>((data>>16)&0xFF), - static_cast<uint8_t>((data>> 8)&0xFF), - static_cast<uint8_t>((data>> 0)&0xFF)}); +void PBv3CommPatchSPICom::write_reg24(uint32_t address, uint32_t data) { + write_reg32(address); + write_block({static_cast<uint8_t>((data >> 16) & 0xFF), + static_cast<uint8_t>((data >> 8) & 0xFF), + static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_reg16(uint32_t address, uint16_t data) -{ - write_reg32(address); - write_block({static_cast<uint8_t>((data>> 8)&0xFF), - static_cast<uint8_t>((data>> 0)&0xFF)}); +void PBv3CommPatchSPICom::write_reg16(uint32_t address, uint16_t data) { + write_reg32(address); + write_block({static_cast<uint8_t>((data >> 8) & 0xFF), + static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_reg8 (uint32_t address, uint8_t data) -{ - write_reg32(address); - write_block({static_cast<uint8_t>((data>> 0)&0xFF)}); +void PBv3CommPatchSPICom::write_reg8(uint32_t address, uint8_t data) { + write_reg32(address); + write_block({static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_reg32(uint32_t data) -{ - write_block({static_cast<uint8_t>((data>>24)&0xFF), - static_cast<uint8_t>((data>>16)&0xFF), - static_cast<uint8_t>((data>> 8)&0xFF), - static_cast<uint8_t>((data>> 0)&0xFF)}); +void PBv3CommPatchSPICom::write_reg32(uint32_t data) { + write_block({static_cast<uint8_t>((data >> 24) & 0xFF), + static_cast<uint8_t>((data >> 16) & 0xFF), + static_cast<uint8_t>((data >> 8) & 0xFF), + static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_reg24(uint32_t data) -{ - write_block({static_cast<uint8_t>((data>>16)&0xFF), - static_cast<uint8_t>((data>> 8)&0xFF), - static_cast<uint8_t>((data>> 0)&0xFF)}); +void PBv3CommPatchSPICom::write_reg24(uint32_t data) { + write_block({static_cast<uint8_t>((data >> 16) & 0xFF), + static_cast<uint8_t>((data >> 8) & 0xFF), + static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_reg16(uint16_t data) -{ - write_block({static_cast<uint8_t>((data>> 8)&0xFF), - static_cast<uint8_t>((data>> 0)&0xFF)}); +void PBv3CommPatchSPICom::write_reg16(uint16_t data) { + write_block({static_cast<uint8_t>((data >> 8) & 0xFF), + static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_reg8 (uint8_t data) -{ - write_block({static_cast<uint8_t>((data>> 0)&0xFF)}); +void PBv3CommPatchSPICom::write_reg8(uint8_t data) { + write_block({static_cast<uint8_t>((data >> 0) & 0xFF)}); } -void PBv3CommPatchSPICom::write_block(uint32_t address, const std::vector<uint8_t>& data) -{ - write_reg32(address); - write_block(data); +void PBv3CommPatchSPICom::write_block(uint32_t address, + const std::vector<uint8_t>& data) { + write_reg32(address); + write_block(data); } -void PBv3CommPatchSPICom::write_block(const std::vector<uint8_t>& data) -{ - ftdi_usb_purge_buffers(m_ftdi); +void PBv3CommPatchSPICom::write_block(const std::vector<uint8_t>& data) { + ftdi_usb_purge_buffers(m_ftdi); - std::vector<uint8_t> ftdidata; + std::vector<uint8_t> ftdidata; - ftdidata={0x83}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - ftdi_read_alldata(m_ftdi, ftdidata, 1); - uint8_t hbyte=ftdidata[0]; - - // set CS low - hbyte&=~(1<<m_csbit); - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + ftdidata = {0x83}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + ftdi_read_alldata(m_ftdi, ftdidata, 1); + uint8_t hbyte = ftdidata[0]; - // Let's do a data write - for(uint32_t byte : data) - { - for(uint8_t nbit=8;nbit>0;nbit--) - { - bool bit=((byte>>(nbit-1))&1); + // set CS low + hbyte &= ~(1 << m_csbit); + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - // clock low and load data - hbyte&=0x7F; - hbyte=(bit)?(hbyte|(1<<6)):(hbyte&~(1<<6)); + // Let's do a data write + for (uint32_t byte : data) { + for (uint8_t nbit = 8; nbit > 0; nbit--) { + bool bit = ((byte >> (nbit - 1)) & 1); - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // clock low and load data + hbyte &= 0x7F; + hbyte = (bit) ? (hbyte | (1 << 6)) : (hbyte & ~(1 << 6)); - // clock high - hbyte|=0x80; - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // clock low - hbyte&=0x7F; - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - } - } + // clock high + hbyte |= 0x80; + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // set CS high - hbyte|=(1<<m_csbit); - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + // clock low + hbyte &= 0x7F; + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + } + } + // set CS high + hbyte |= (1 << m_csbit); + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); } -uint32_t PBv3CommPatchSPICom::read_reg32(uint32_t address) -{ - write_reg32(address); - return read_reg32(); +uint32_t PBv3CommPatchSPICom::read_reg32(uint32_t address) { + write_reg32(address); + return read_reg32(); } -uint32_t PBv3CommPatchSPICom::read_reg24(uint32_t address) -{ - write_reg24(address); - return read_reg24(); +uint32_t PBv3CommPatchSPICom::read_reg24(uint32_t address) { + write_reg24(address); + return read_reg24(); } -uint16_t PBv3CommPatchSPICom::read_reg16(uint32_t address) -{ - write_reg32(address); - return read_reg16(); +uint16_t PBv3CommPatchSPICom::read_reg16(uint32_t address) { + write_reg32(address); + return read_reg16(); } -uint8_t PBv3CommPatchSPICom::read_reg8 (uint32_t address) -{ - write_reg32(address); - return read_reg8(); +uint8_t PBv3CommPatchSPICom::read_reg8(uint32_t address) { + write_reg32(address); + return read_reg8(); } -uint32_t PBv3CommPatchSPICom::read_reg32() -{ - std::vector<uint8_t> data={0x00,0x00,0x00,0x00}; - read_block(data); - return (data[0]<<24)|(data[1]<<16)|(data[2]<< 8)|(data[3]<< 0); +uint32_t PBv3CommPatchSPICom::read_reg32() { + std::vector<uint8_t> data = {0x00, 0x00, 0x00, 0x00}; + read_block(data); + return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | (data[3] << 0); } -uint32_t PBv3CommPatchSPICom::read_reg24() -{ - std::vector<uint8_t> data={0x00,0x00,0x00}; - read_block(data); - return (data[0]<<16)|(data[1]<< 8)|(data[2]<< 0); +uint32_t PBv3CommPatchSPICom::read_reg24() { + std::vector<uint8_t> data = {0x00, 0x00, 0x00}; + read_block(data); + return (data[0] << 16) | (data[1] << 8) | (data[2] << 0); } -uint16_t PBv3CommPatchSPICom::read_reg16() -{ - std::vector<uint8_t> data={0x00,0x00}; - read_block(data); - return (data[0]<< 8)|(data[1]<< 0); +uint16_t PBv3CommPatchSPICom::read_reg16() { + std::vector<uint8_t> data = {0x00, 0x00}; + read_block(data); + return (data[0] << 8) | (data[1] << 0); } -uint8_t PBv3CommPatchSPICom::read_reg8 () -{ - std::vector<uint8_t> data={0x00}; - read_block(data); - return data[0]; +uint8_t PBv3CommPatchSPICom::read_reg8() { + std::vector<uint8_t> data = {0x00}; + read_block(data); + return data[0]; } -void PBv3CommPatchSPICom::read_block(uint32_t address, std::vector<uint8_t>& data) -{ - write_reg32(address); - read_block(data); +void PBv3CommPatchSPICom::read_block(uint32_t address, + std::vector<uint8_t>& data) { + write_reg32(address); + read_block(data); } -void PBv3CommPatchSPICom::read_block(std::vector<uint8_t>& data) -{ - ftdi_usb_purge_buffers(m_ftdi); +void PBv3CommPatchSPICom::read_block(std::vector<uint8_t>& data) { + ftdi_usb_purge_buffers(m_ftdi); + + std::vector<uint8_t> ftdidata; + + ftdidata = {0x83}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + ftdi_read_alldata(m_ftdi, ftdidata, 1); + uint8_t hbyte = ftdidata[0]; + + // set CS low + hbyte &= ~(1 << m_csbit); + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - std::vector<uint8_t> ftdidata; + // Let's do a data read + for (uint ibyte = 0; ibyte < data.size(); ibyte++) { + uint8_t byte = 0; + for (uint ibit = 0; ibit < 8; ibit++) { + // clock low + hbyte &= 0x7F; + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); - ftdidata={0x83}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - ftdi_read_alldata(m_ftdi, ftdidata, 1); - uint8_t hbyte=ftdidata[0]; - - // set CS low - hbyte&=~(1<<m_csbit); - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + // clock high + hbyte |= 0x80; + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // Let's do a data read - for(uint ibyte=0;ibyte<data.size();ibyte++) - { - uint8_t byte=0; - for(uint ibit=0;ibit<8;ibit++) - { - // clock low - hbyte&=0x7F; - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // read bit + ftdidata = {0x83}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + ftdi_read_alldata(m_ftdi, ftdidata, 1); - // clock high - hbyte|=0x80; - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + byte <<= 1; + byte |= ((ftdidata[0] >> 5) & 1); - // read bit - ftdidata={0x83}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - ftdi_read_alldata(m_ftdi, ftdidata, 1); + // clock low + hbyte &= 0x7F; + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + } - byte<<=1; - byte|=((ftdidata[0]>>5)&1); - - // clock low - hbyte&=0x7F; - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); - } - - data[ibyte]=byte; + data[ibyte] = byte; } - // set CS high - hbyte|=(1<<m_csbit); - ftdidata={0x82, hbyte, 0xDF}; - ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); + // set CS high + hbyte |= (1 << m_csbit); + ftdidata = {0x82, hbyte, 0xDF}; + ftdi_write_data(m_ftdi, &ftdidata[0], ftdidata.size()); } diff --git a/pbv3/PBv3CommPatchSPICom.h b/pbv3/PBv3CommPatchSPICom.h index bbf701d7e2b05a6ebc6d2b9fcd98d7cd37e62359..ca31943513a971d5b62d2aa8794e3aee719f8b30 100644 --- a/pbv3/PBv3CommPatchSPICom.h +++ b/pbv3/PBv3CommPatchSPICom.h @@ -3,46 +3,44 @@ #include "SPICom.h" -class PBv3CommPatchSPICom : public SPICom -{ -public: - PBv3CommPatchSPICom(struct ftdi_context *ftdi, uint8_t csbit); - virtual ~PBv3CommPatchSPICom(); - - // - // Write commands - void write_reg32(uint32_t address, uint32_t data); - void write_reg24(uint32_t address, uint32_t data); - void write_reg16(uint32_t address, uint16_t data); - void write_reg8 (uint32_t address, uint8_t data); - - void write_reg32(uint32_t data); - void write_reg24(uint32_t data); - void write_reg16(uint16_t data); - void write_reg8 (uint8_t data); - - void write_block(uint32_t address, const std::vector<uint8_t>& data); - void write_block(const std::vector<uint8_t>& data); - - - // - // Read commands - uint32_t read_reg32(uint32_t address); - uint32_t read_reg24(uint32_t address); - uint16_t read_reg16(uint32_t address); - uint8_t read_reg8 (uint32_t address); - - uint32_t read_reg32(); - uint32_t read_reg24(); - uint16_t read_reg16(); - uint8_t read_reg8 (); - - void read_block(uint32_t address, std::vector<uint8_t>& data); - void read_block(std::vector<uint8_t>& data); - -private: - struct ftdi_context *m_ftdi; - uint8_t m_csbit; +class PBv3CommPatchSPICom : public SPICom { + public: + PBv3CommPatchSPICom(struct ftdi_context* ftdi, uint8_t csbit); + virtual ~PBv3CommPatchSPICom(); + + // + // Write commands + void write_reg32(uint32_t address, uint32_t data); + void write_reg24(uint32_t address, uint32_t data); + void write_reg16(uint32_t address, uint16_t data); + void write_reg8(uint32_t address, uint8_t data); + + void write_reg32(uint32_t data); + void write_reg24(uint32_t data); + void write_reg16(uint16_t data); + void write_reg8(uint8_t data); + + void write_block(uint32_t address, const std::vector<uint8_t>& data); + void write_block(const std::vector<uint8_t>& data); + + // + // Read commands + uint32_t read_reg32(uint32_t address); + uint32_t read_reg24(uint32_t address); + uint16_t read_reg16(uint32_t address); + uint8_t read_reg8(uint32_t address); + + uint32_t read_reg32(); + uint32_t read_reg24(); + uint16_t read_reg16(); + uint8_t read_reg8(); + + void read_block(uint32_t address, std::vector<uint8_t>& data); + void read_block(std::vector<uint8_t>& data); + + private: + struct ftdi_context* m_ftdi; + uint8_t m_csbit; }; -#endif // PBV3COMMPATCHSPICOM_H +#endif // PBV3COMMPATCHSPICOM_H diff --git a/pbv3/PBv3ConfigTools.cpp b/pbv3/PBv3ConfigTools.cpp index 81457dc44f8750a10d81d7396377cd74ff0cc89c..53b940dbd936574e08c9815e9e786f3d96623af4 100644 --- a/pbv3/PBv3ConfigTools.cpp +++ b/pbv3/PBv3ConfigTools.cpp @@ -3,584 +3,589 @@ #include "EndeavourComException.h" #ifdef FTDI #include "EndeavourRawFTDI.h" -#endif // FTDI +#endif // FTDI -#include <algorithm> #include <unistd.h> -#include <fstream> +#include <algorithm> #include <chrono> +#include <fstream> using Clock = std::chrono::steady_clock; typedef std::chrono::time_point<Clock> timep; -namespace PBv3ConfigTools -{ +namespace PBv3ConfigTools { - bool config_to_amac_circuit_data(const json& config, std::shared_ptr<AMACv2> amac) - { - logger(logDEBUG) << "PBv3ConfigTools::config_to_amac_circuit_data " << amac->_get_amacid(); +bool config_to_amac_circuit_data(const json& config, + std::shared_ptr<AMACv2> amac) { + logger(logDEBUG) << "PBv3ConfigTools::config_to_amac_circuit_data " + << amac->_get_amacid(); - //// Check if "config" key is present, in which case we are using a test result output - //const json& cfgtop=(config.count("config"))?config.at("config"):config; + //// Check if "config" key is present, in which case we are using a test + ///result output + // const json& cfgtop=(config.count("config"))?config.at("config"):config; - // - // Configure the circuit data - //if(cfgtop.count("circuit_data")) - // { - //for(auto field : cfgtop["circuit_data"].items()) // it must be a map + // + // Configure the circuit data + // if(cfgtop.count("circuit_data")) + // { + // for(auto field : cfgtop["circuit_data"].items()) // it must be a map - for(auto field : config.items()) // it must be a map + for (auto field : config.items()) // it must be a map { - amac->circuit_set(field.key(), field.value()); + amac->circuit_set(field.key(), field.value()); } - // } + // } - return true; - } + return true; +} - json amac_circuit_data_to_config(std::shared_ptr<AMACv2> amac) - { - logger(logDEBUG) << "PBv3ConfigTools::amac_circuit_data_to_config " << amac->_get_amacid(); +json amac_circuit_data_to_config(std::shared_ptr<AMACv2> amac) { + logger(logDEBUG) << "PBv3ConfigTools::amac_circuit_data_to_config " + << amac->_get_amacid(); - json config; + json config; - for (auto i = amac->m_circuit.begin(); i != amac->m_circuit.end(); i++) - { - //cfgtop["circuit_data"][i->first] = i->second; - config[i->first] = i->second; + for (auto i = amac->m_circuit.begin(); i != amac->m_circuit.end(); i++) { + // cfgtop["circuit_data"][i->first] = i->second; + config[i->first] = i->second; } - return config; - } + return config; +} - bool configAMAC_file(std::shared_ptr<AMACv2> amac, const std::string& calib_cfg, bool write) - { - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); +bool configAMAC_file(std::shared_ptr<AMACv2> amac, const std::string& calib_cfg, + bool write) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC_file " << amac->_get_amacid() << " with " << calib_cfg; + logger(logDEBUG) << "PBv3ConfigTools::configAMAC_file " + << amac->_get_amacid() << " with " << calib_cfg; - nlohmann::json calibCfg; + nlohmann::json calibCfg; - // try to open the file and parse json from it - std::ifstream controllerFile(calib_cfg); + // try to open the file and parse json from it + std::ifstream controllerFile(calib_cfg); - if(controllerFile.is_open()) - { - //calibCfg = json::parse(controllerFile); + if (controllerFile.is_open()) { + // calibCfg = json::parse(controllerFile); - try - { calibCfg = nlohmann::json::parse(controllerFile); } + try { + calibCfg = nlohmann::json::parse(controllerFile); + } - catch (nlohmann::json::parse_error &e) - { - logger(logERROR) << "PBv3ConfigTools::configAMAC_file could not parse calibration config: " << e.what(); - //throw std::string("PBv3ConfigTools::configAMAC could not parse calibration config") + e.what(); - return false; - } + catch (nlohmann::json::parse_error& e) { + logger(logERROR) << "PBv3ConfigTools::configAMAC_file could not " + "parse calibration config: " + << e.what(); + // throw std::string("PBv3ConfigTools::configAMAC could not parse + // calibration config") + e.what(); + return false; + } } - else - { - logger(logERROR) << "PBv3ConfigTools::configAMAC_file unable to open the config file " << calib_cfg; - //throw std::string("PBv3ConfigTools::configAMAC unable to open the config file"); - return false; + else { + logger(logERROR) << "PBv3ConfigTools::configAMAC_file unable to open " + "the config file " + << calib_cfg; + // throw std::string("PBv3ConfigTools::configAMAC unable to open the + // config file"); + return false; } - logger(logDEBUG) << "PBv3ConfigTools::configAMAC_file parsed the calibration json"; + logger(logDEBUG) + << "PBv3ConfigTools::configAMAC_file parsed the calibration json"; - configAMAC(amac, calibCfg, write); + configAMAC(amac, calibCfg, write); - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC_file time " << diagnostic_time.count() << " us"; + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC_file time " + << diagnostic_time.count() << " us"; - return true; - } - - bool configAMAC_default(std::shared_ptr<AMACv2> amac, bool use_int_calib, bool write) - { - std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - - std::string default_amac_calibration_path = "/opt/atlas/etc/calibrations_amac/default/"; - if (use_int_calib) - default_amac_calibration_path += "int/"; - else - default_amac_calibration_path += "bg/"; - - auto amac_padid = amac->getPADID(); - default_amac_calibration_path += std::string("calibrations_test_amac_pads_") + - std::to_string(amac_padid) + - std::string(".json"); - - logger(logDEBUG) << "PBv3ConfigTools::configAMAC_default with " << default_amac_calibration_path; + return true; +} - std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); - std::chrono::microseconds diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>(diagnostic_time_end - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC_default time " << diagnostic_time.count() << " us"; +bool configAMAC_default(std::shared_ptr<AMACv2> amac, bool use_int_calib, + bool write) { + std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); - return configAMAC_file(amac, default_amac_calibration_path, write); - } + std::string default_amac_calibration_path = + "/opt/atlas/etc/calibrations_amac/default/"; + if (use_int_calib) + default_amac_calibration_path += "int/"; + else + default_amac_calibration_path += "bg/"; + + auto amac_padid = amac->getPADID(); + default_amac_calibration_path += + std::string("calibrations_test_amac_pads_") + + std::to_string(amac_padid) + std::string(".json"); + + logger(logDEBUG) << "PBv3ConfigTools::configAMAC_default with " + << default_amac_calibration_path; + + std::chrono::time_point<Clock> diagnostic_time_end = Clock::now(); + std::chrono::microseconds diagnostic_time = + std::chrono::duration_cast<std::chrono::microseconds>( + diagnostic_time_end - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC_default time " + << diagnostic_time.count() << " us"; + + return configAMAC_file(amac, default_amac_calibration_path, write); +} - void configAMAC(std::shared_ptr<AMACv2> amac, const json& config, bool write) - { +void configAMAC(std::shared_ptr<AMACv2> amac, const json& config, bool write) { std::chrono::time_point<Clock> diagnostic_time_start = Clock::now(); std::chrono::microseconds diagnostic_time; - // Check if "config" key is present, in which case we are using a test result output - const json& cfgtop=(config.count("config"))?config.at("config"):config; + // Check if "config" key is present, in which case we are using a test + // result output + const json& cfgtop = + (config.count("config")) ? config.at("config") : config; // // Configure the circuit data - if(cfgtop.count("circuit_data")) - { - config_to_amac_circuit_data(cfgtop["circuit_data"], amac); - } + if (cfgtop.count("circuit_data")) { + config_to_amac_circuit_data(cfgtop["circuit_data"], amac); + } - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC circ time " << diagnostic_time.count() << " us"; + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC circ time " + << diagnostic_time.count() << " us"; // // Configure registers - if(cfgtop.count("properties")) - { - for(auto field : cfgtop["properties"].items()) - { - AMACv2Field *fref=amac->findField(field.key()); - if(fref==nullptr) - { - logger(logWARNING) << "Skipping non-existent field " << field.key(); - continue; - } - - fref->setDefaultVal(field.value().get<uint32_t>()); - if(write) - amac->wrField (field.key(), field.value().get<uint32_t>()); - } - } + if (cfgtop.count("properties")) { + for (auto field : cfgtop["properties"].items()) { + AMACv2Field* fref = amac->findField(field.key()); + if (fref == nullptr) { + logger(logWARNING) + << "Skipping non-existent field " << field.key(); + continue; + } + + fref->setDefaultVal(field.value().get<uint32_t>()); + if (write) + amac->wrField(field.key(), field.value().get<uint32_t>()); + } + } - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC regs time " << diagnostic_time.count() << " us"; + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC regs time " + << diagnostic_time.count() << " us"; // - //Set PADID - if(cfgtop.count("results") && cfgtop["results"].count("PADID")) - { - amac->setPADID(cfgtop["results"]["PADID"].get<uint8_t>()); - } + // Set PADID + if (cfgtop.count("results") && cfgtop["results"].count("PADID")) { + amac->setPADID(cfgtop["results"]["PADID"].get<uint8_t>()); + } - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC PADI time " << diagnostic_time.count() << " us"; + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC PADI time " + << diagnostic_time.count() << " us"; // // Configure ADC calibration - if(cfgtop.count("results") && cfgtop["results"].count("AMSLOPE")) - { - amac->setADCslope(cfgtop["results"]["AMSLOPE"].get<double>()); - } + if (cfgtop.count("results") && cfgtop["results"].count("AMSLOPE")) { + amac->setADCslope(cfgtop["results"]["AMSLOPE"].get<double>()); + } - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC AMSL time " << diagnostic_time.count() << " us"; + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC AMSL time " + << diagnostic_time.count() << " us"; // // Configure ADC offset - if(cfgtop.count("results") && cfgtop["results"].count("AMOFFSET")) - { - for(uint i=0; i<cfgtop["results"]["AMOFFSET"].size(); i++) - if(!cfgtop["results"]["AMOFFSET"][i].is_null()) - amac->setADCoffset(i, cfgtop["results"]["AMOFFSET"][i].get<uint32_t>()); - } + if (cfgtop.count("results") && cfgtop["results"].count("AMOFFSET")) { + for (uint i = 0; i < cfgtop["results"]["AMOFFSET"].size(); i++) + if (!cfgtop["results"]["AMOFFSET"][i].is_null()) + amac->setADCoffset( + i, cfgtop["results"]["AMOFFSET"][i].get<uint32_t>()); + } - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC AMOF time " << diagnostic_time.count() << " us"; + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC AMOF time " + << diagnostic_time.count() << " us"; // // Configure temperature calibrations - if(cfgtop.count("results")) - { - if(cfgtop["results"].count("NTCX" )) - amac->setNTCxCal (cfgtop["results"]["NTCX" ].get<double>()); + if (cfgtop.count("results")) { + if (cfgtop["results"].count("NTCX")) + amac->setNTCxCal(cfgtop["results"]["NTCX"].get<double>()); - if(cfgtop["results"].count("NTCY" )) - amac->setNTCyCal (cfgtop["results"]["NTCY" ].get<double>()); + if (cfgtop["results"].count("NTCY")) + amac->setNTCyCal(cfgtop["results"]["NTCY"].get<double>()); - if(cfgtop["results"].count("NTCPB")) - amac->setNTCpbCal(cfgtop["results"]["NTCPB"].get<double>()); + if (cfgtop["results"].count("NTCPB")) + amac->setNTCpbCal(cfgtop["results"]["NTCPB"].get<double>()); - if(cfgtop["results"].count("PTAT0")) - amac->setPTAT0(cfgtop["results"]["PTAT0"].get<double>()); + if (cfgtop["results"].count("PTAT0")) + amac->setPTAT0(cfgtop["results"]["PTAT0"].get<double>()); - if(cfgtop["results"].count("CTAT0")) - { - for(uint i=0; i<cfgtop["results"]["CTAT0"].size(); i++) - if(!cfgtop["results"]["CTAT0"][i].is_null()) - amac->setCTAT0(i, cfgtop["results"]["CTAT0"][i].get<double>()); - } - } + if (cfgtop["results"].count("CTAT0")) { + for (uint i = 0; i < cfgtop["results"]["CTAT0"].size(); i++) + if (!cfgtop["results"]["CTAT0"][i].is_null()) + amac->setCTAT0(i, + cfgtop["results"]["CTAT0"][i].get<double>()); + } + } // // Configure current measurement offsets - if(cfgtop.count("results")) - { - if(cfgtop["results"].count("CUR1VOFFSET" )) - amac->setCur1VOffset (cfgtop["results"]["CUR1VOFFSET" ].get<double>()); - - if(cfgtop["results"].count("CUR10VOFFSET" )) - amac->setCur10VOffset (cfgtop["results"]["CUR10VOFFSET" ].get<double>()); - } - + if (cfgtop.count("results")) { + if (cfgtop["results"].count("CUR1VOFFSET")) + amac->setCur1VOffset( + cfgtop["results"]["CUR1VOFFSET"].get<double>()); + + if (cfgtop["results"].count("CUR10VOFFSET")) + amac->setCur10VOffset( + cfgtop["results"]["CUR10VOFFSET"].get<double>()); + } - diagnostic_time = - std::chrono::duration_cast<std::chrono::microseconds>((timep) Clock::now() - diagnostic_time_start); - logger(logDEBUG) << "PBv3ConfigTools::configAMAC end time " << diagnostic_time.count() << " us"; - } + diagnostic_time = std::chrono::duration_cast<std::chrono::microseconds>( + (timep)Clock::now() - diagnostic_time_start); + logger(logDEBUG) << "PBv3ConfigTools::configAMAC end time " + << diagnostic_time.count() << " us"; +} - void saveConfigAMAC(std::shared_ptr<AMACv2> amac, json& config) - { +void saveConfigAMAC(std::shared_ptr<AMACv2> amac, json& config) { // // Get register values - for(const AMACv2Field* field : amac->getFields()) - { - if(field->isReadWrite()) - config["properties"][field->getName()]=field->read(); - } - } - - void decorateConfig(json& config) - { - config["testType"]="CONFIG"; - config["institution"]="LBNL_STRIP_POWERBOARDS"; + for (const AMACv2Field* field : amac->getFields()) { + if (field->isReadWrite()) + config["properties"][field->getName()] = field->read(); + } +} - std::string runNumber="0-0"; - if(config.count("runNumber")>0) - { - // Parse the existing version string - std::istringstream ss(config["runNumber"].get<std::string>()); - std::vector<int32_t> tokens; - std::string token; - while(std::getline(ss, token, '-')) - tokens.push_back(std::stoi(token)); // TODO: try-catch bad format - - // Update version - if(tokens.size()>0) - { - runNumber=""; - for(uint32_t i=0;i<tokens.size();i++) - { - if(i!=0) runNumber+="-"; - runNumber+=(i!=tokens.size()-1)?(std::to_string(tokens[i])):(std::to_string(tokens[i]+1)); - } - } - } - config["runNumber"]=runNumber; - } +void decorateConfig(json& config) { + config["testType"] = "CONFIG"; + config["institution"] = "LBNL_STRIP_POWERBOARDS"; + + std::string runNumber = "0-0"; + if (config.count("runNumber") > 0) { + // Parse the existing version string + std::istringstream ss(config["runNumber"].get<std::string>()); + std::vector<int32_t> tokens; + std::string token; + while (std::getline(ss, token, '-')) + tokens.push_back(std::stoi(token)); // TODO: try-catch bad format + + // Update version + if (tokens.size() > 0) { + runNumber = ""; + for (uint32_t i = 0; i < tokens.size(); i++) { + if (i != 0) runNumber += "-"; + runNumber += (i != tokens.size() - 1) + ? (std::to_string(tokens[i])) + : (std::to_string(tokens[i] + 1)); + } + } + } + config["runNumber"] = runNumber; +} - json tuneVDDBG(std::shared_ptr<AMACv2> amac) - { +json tuneVDDBG(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "## Tuning VDDREG ##"; json config; amac->wrField(&AMACv2RegMap::VDDbgen, 1); // Run the test - double bestVDDREG=0; - uint32_t bestVDDbg=0; + double bestVDDREG = 0; + uint32_t bestVDDbg = 0; - for(uint VDDbg=0;VDDbg<pow(2,4);VDDbg++) - { - amac->wrField(&AMACv2RegMap::VDDbg, VDDbg); - usleep(5e3); - - double VDDREG=amac->getVDDREG(); - - logger(logDEBUG) << "VDDbg = " << VDDbg << ", VDDREG = " << VDDREG; - - if(fabs(VDDREG-1200)<fabs(bestVDDREG-1200)) - { - bestVDDREG=VDDREG; - bestVDDbg=VDDbg; - } - } + for (uint VDDbg = 0; VDDbg < pow(2, 4); VDDbg++) { + amac->wrField(&AMACv2RegMap::VDDbg, VDDbg); + usleep(5e3); + + double VDDREG = amac->getVDDREG(); + + logger(logDEBUG) << "VDDbg = " << VDDbg << ", VDDREG = " << VDDREG; + + if (fabs(VDDREG - 1200) < fabs(bestVDDREG - 1200)) { + bestVDDREG = VDDREG; + bestVDDbg = VDDbg; + } + } logger(logINFO) << "\tVDDbg = " << bestVDDbg; - logger(logINFO) << "\tVDDREG = " << bestVDDREG/1e3 << " V"; + logger(logINFO) << "\tVDDREG = " << bestVDDREG / 1e3 << " V"; - config["properties"]["VDDbgen"]=1; - config["properties"]["VDDbg"] =bestVDDbg; - config["results"]["VDDREG"] =bestVDDREG; + config["properties"]["VDDbgen"] = 1; + config["properties"]["VDDbg"] = bestVDDbg; + config["results"]["VDDREG"] = bestVDDREG; configAMAC(amac, config, true); return config; - } +} - json tuneAMBG(std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac) - { +json tuneAMBG(std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac) { logger(logINFO) << "## Tuning AMBG ##"; json config; // Run the test - double bestAM=0; - uint32_t bestAMbg=0; + double bestAM = 0; + uint32_t bestAMbg = 0; json bestSlope, bestOffset; amac->wrField(&AMACv2RegMap::AMbgen, 1); - for(uint AMbg=0;AMbg<pow(2,4);AMbg++) - { - amac->wrField(&AMACv2RegMap::AMbg, AMbg); - usleep(5e3); - json slope =calibrateSlope (amac, CALdac); - json offset=calibrateOffset(amac); - - double AM=amac->getAM600(); - - logger(logDEBUG) << "AMbg = " << AMbg << ", AM = " << AM; - - if(fabs(AM-600)<fabs(bestAM-600)) - { - bestAM =AM; - bestAMbg =AMbg; - bestSlope =slope; - bestOffset=offset; - } - } + for (uint AMbg = 0; AMbg < pow(2, 4); AMbg++) { + amac->wrField(&AMACv2RegMap::AMbg, AMbg); + usleep(5e3); + json slope = calibrateSlope(amac, CALdac); + json offset = calibrateOffset(amac); + + double AM = amac->getAM600(); + + logger(logDEBUG) << "AMbg = " << AMbg << ", AM = " << AM; + + if (fabs(AM - 600) < fabs(bestAM - 600)) { + bestAM = AM; + bestAMbg = AMbg; + bestSlope = slope; + bestOffset = offset; + } + } logger(logINFO) << "\tAMbg = " << bestAMbg; logger(logINFO) << "\tAM = " << bestAM << " mV"; - config["properties"]["AMbgen"]=1; - config["properties"]["AMbg" ]=bestAMbg; - config["results" ]["AM" ]=bestAM; - config.merge_patch(bestSlope ); + config["properties"]["AMbgen"] = 1; + config["properties"]["AMbg"] = bestAMbg; + config["results"]["AM"] = bestAM; + config.merge_patch(bestSlope); config.merge_patch(bestOffset); configAMAC(amac, config, true); return config; - } +} - json tuneRampGain(std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac) - { +json tuneRampGain(std::shared_ptr<AMACv2> amac, + std::shared_ptr<DACDevice> CALdac) { logger(logINFO) << "## Tuning Ramp Gain ##"; json config; // Run the test - uint32_t bestAMintCalib=0; + uint32_t bestAMintCalib = 0; json bestSlope; - amac->wrField(&AMACv2RegMap::Ch4Mux , 1); // Set Ch4 mux to CAL input - for(uint32_t AMintCalib=0; - AMintCalib<16; - AMintCalib++) - { - amac->wrField(&AMACv2RegMap::AMintCalib, AMintCalib); - logger(logINFO) << "Set AMintCalib = " << AMintCalib; + amac->wrField(&AMACv2RegMap::Ch4Mux, 1); // Set Ch4 mux to CAL input + for (uint32_t AMintCalib = 0; AMintCalib < 16; AMintCalib++) { + amac->wrField(&AMACv2RegMap::AMintCalib, AMintCalib); + logger(logINFO) << "Set AMintCalib = " << AMintCalib; - json slope=calibrateSlope(amac, CALdac); + json slope = calibrateSlope(amac, CALdac); - if(bestSlope.is_null() || fabs(slope["results"]["AMSLOPE"].get<double>()-1)<fabs(bestSlope["results"]["AMSLOPE"].get<double>()-1)) - { - bestSlope=slope; - bestAMintCalib=AMintCalib; - } - } + if (bestSlope.is_null() || + fabs(slope["results"]["AMSLOPE"].get<double>() - 1) < + fabs(bestSlope["results"]["AMSLOPE"].get<double>() - 1)) { + bestSlope = slope; + bestAMintCalib = AMintCalib; + } + } amac->wrField(&AMACv2RegMap::AMintCalib, bestAMintCalib); - json bestOffset=calibrateOffset(amac); + json bestOffset = calibrateOffset(amac); logger(logINFO) << "\tAMintCalib = " << bestAMintCalib; - logger(logINFO) << "\tslope = " << bestSlope["results"]["AMSLOPE"].get<double>()*1e3 << " mV/count"; + logger(logINFO) << "\tslope = " + << bestSlope["results"]["AMSLOPE"].get<double>() * 1e3 + << " mV/count"; - config["properties"]["AMintCalib"]=bestAMintCalib; - config.merge_patch(bestSlope ); + config["properties"]["AMintCalib"] = bestAMintCalib; + config.merge_patch(bestSlope); config.merge_patch(bestOffset); configAMAC(amac, config, true); return config; - } +} - json tuneRampGain_multiSlope(std::vector<std::shared_ptr<AMACv2>> amacs, std::shared_ptr<DACDevice> CALdac) - { +json tuneRampGain_multiSlope(std::vector<std::shared_ptr<AMACv2>> amacs, + std::shared_ptr<DACDevice> CALdac) { logger(logINFO) << "## Tuning Ramp Gain on multiple AMACs ##"; // Run the test - //uint32_t bestAMintCalib=0; - //json bestSlope; + // uint32_t bestAMintCalib=0; + // json bestSlope; std::vector<uint32_t> bestAMintCalib = {}; - std::vector<json> bestSlope = {}; - - for (auto amac : amacs) - { - amac->wrField(&AMACv2RegMap::Ch4Mux , 1); // Set Ch4 mux to CAL input - //config[std::to_string(amac->getPADID())]["AMintCalib"] = 0; //bestAMintCalib - bestAMintCalib.push_back(0); - json slope; - bestSlope.push_back(slope); - } - - for(uint32_t AMintCalib=0; - AMintCalib<16; - AMintCalib++) - { - logger(logDEBUG) << "Set AMintCalib = " << AMintCalib; - for (auto amac : amacs) amac->wrField(&AMACv2RegMap::AMintCalib, AMintCalib); - - std::vector<json> slopes = calibrateMultiSlope(amacs, CALdac); + std::vector<json> bestSlope = {}; + + for (auto amac : amacs) { + amac->wrField(&AMACv2RegMap::Ch4Mux, 1); // Set Ch4 mux to CAL input + // config[std::to_string(amac->getPADID())]["AMintCalib"] = 0; + // //bestAMintCalib + bestAMintCalib.push_back(0); + json slope; + bestSlope.push_back(slope); + } - for (int i=0; i<amacs.size(); i++) - { - if (bestSlope[i].is_null() || - fabs(slopes[i]["results"]["AMSLOPE"].get<double>()-1)<fabs(bestSlope[i]["results"]["AMSLOPE"].get<double>()-1)) - { - bestSlope[i] = slopes[i]; - bestAMintCalib[i]=AMintCalib; - } - } - } + for (uint32_t AMintCalib = 0; AMintCalib < 16; AMintCalib++) { + logger(logDEBUG) << "Set AMintCalib = " << AMintCalib; + for (auto amac : amacs) + amac->wrField(&AMACv2RegMap::AMintCalib, AMintCalib); + + std::vector<json> slopes = calibrateMultiSlope(amacs, CALdac); + + for (int i = 0; i < amacs.size(); i++) { + if (bestSlope[i].is_null() || + fabs(slopes[i]["results"]["AMSLOPE"].get<double>() - 1) < + fabs(bestSlope[i]["results"]["AMSLOPE"].get<double>() - + 1)) { + bestSlope[i] = slopes[i]; + bestAMintCalib[i] = AMintCalib; + } + } + } std::vector<json> bestOffset; - for (int i=0; i<amacs.size(); i++) - { - amacs[i]->wrField(&AMACv2RegMap::AMintCalib, bestAMintCalib[i]); - bestOffset.push_back(calibrateOffset(amacs[i])); - } + for (int i = 0; i < amacs.size(); i++) { + amacs[i]->wrField(&AMACv2RegMap::AMintCalib, bestAMintCalib[i]); + bestOffset.push_back(calibrateOffset(amacs[i])); + } // put everything into 1 json output // amac_padid: {properties:..., results:...} json config; - for (int i=0; i<amacs.size(); i++) - { - auto amac_padid = std::to_string(amacs[i]->getPADID()); + for (int i = 0; i < amacs.size(); i++) { + auto amac_padid = std::to_string(amacs[i]->getPADID()); - logger(logINFO) << "\t" << amac_padid << " AMintCalib = " << bestAMintCalib[i]; - logger(logINFO) << "\t" << amac_padid << " slope = " << bestSlope[i]["results"]["AMSLOPE"].get<double>()*1e3 << " mV/count"; + logger(logINFO) << "\t" << amac_padid + << " AMintCalib = " << bestAMintCalib[i]; + logger(logINFO) << "\t" << amac_padid << " slope = " + << bestSlope[i]["results"]["AMSLOPE"].get<double>() * + 1e3 + << " mV/count"; - config[amac_padid]["properties"]["AMintCalib"] = bestAMintCalib[i]; - config[amac_padid].merge_patch(bestSlope[i] ); - config[amac_padid].merge_patch(bestOffset[i]); + config[amac_padid]["properties"]["AMintCalib"] = bestAMintCalib[i]; + config[amac_padid].merge_patch(bestSlope[i]); + config[amac_padid].merge_patch(bestOffset[i]); - configAMAC(amacs[i], config[amac_padid], true); - } + configAMAC(amacs[i], config[amac_padid], true); + } return config; - } +} - json tuneCur10V(std::shared_ptr<AMACv2> amac) - { +json tuneCur10V(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "## Tuning input current monitor block ##"; json config; - if(amac->rdField(&AMACv2RegMap::DCDCen)==1) - { - logger(logWARNING) << "tuneCur10V run with DCDCen=1"; - } + if (amac->rdField(&AMACv2RegMap::DCDCen) == 1) { + logger(logWARNING) << "tuneCur10V run with DCDCen=1"; + } // // Save the current state - uint32_t DCDCiZeroReading_curr=amac->rdField(&AMACv2RegMap::DCDCiZeroReading); - uint32_t Ch12Mux_curr =amac->rdField(&AMACv2RegMap::Ch12Mux ); + uint32_t DCDCiZeroReading_curr = + amac->rdField(&AMACv2RegMap::DCDCiZeroReading); + uint32_t Ch12Mux_curr = amac->rdField(&AMACv2RegMap::Ch12Mux); // // Buffer offsets - amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 1); // Short the DCDCi inputs + amac->wrField(&AMACv2RegMap::DCDCiZeroReading, + 1); // Short the DCDCi inputs logger(logDEBUG) << "Measuring relative buffer offset"; - static const uint32_t BOtests=4; // Defines number of samples per test point + static const uint32_t BOtests = + 4; // Defines number of samples per test point - //amac->wrField(&AMACv2RegMap::Ch12Mux , 1); // Read the low point - //double VtestLZero=0; - //for(uint32_t i=0;i<BOtests;i++) + // amac->wrField(&AMACv2RegMap::Ch12Mux , 1); // Read the low point + // double VtestLZero=0; + // for(uint32_t i=0;i<BOtests;i++) // { // std::this_thread::sleep_for(std::chrono::milliseconds(1)); // VtestLZero+=amac->getADC(12)/BOtests; // } double VtestLZero = amac->getCur10VTPL(BOtests); - //amac->wrField(&AMACv2RegMap::Ch12Mux , 2); // Read the high point - //double VtestHZero=0; - //for(uint32_t i=0;i<BOtests;i++) + // amac->wrField(&AMACv2RegMap::Ch12Mux , 2); // Read the high point + // double VtestHZero=0; + // for(uint32_t i=0;i<BOtests;i++) // { // std::this_thread::sleep_for(std::chrono::milliseconds(1)); // VtestHZero+=amac->getADC(12)/BOtests; // } double VtestHZero = amac->getCur10VTPH(BOtests); - double VtestHLZero=VtestHZero-VtestLZero; + double VtestHLZero = VtestHZero - VtestLZero; logger(logINFO) << "\tBuffer offset = " << VtestHLZero << " mV"; // // Tune the current mirrors (does not do anything other than write values) - amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 0); // Separate the DCDCi inputs + amac->wrField(&AMACv2RegMap::DCDCiZeroReading, + 0); // Separate the DCDCi inputs logger(logDEBUG) << "Tuning input CM mirror"; - double bestCMDV=-666; // Best attanable match - uint32_t bestidcdcP=0, bestidcdcN=0; - - static const uint32_t trails=100; // Number of trails per point - for(uint32_t idcdcP=0;idcdcP<pow(2,3);idcdcP++) - { - amac->wrField(&AMACv2RegMap::DCDCiP, idcdcP); - for(uint32_t idcdcN=0;idcdcN<pow(2,3);idcdcN++) - { - amac->wrField(&AMACv2RegMap::DCDCiN, idcdcN); - - double Vout = amac->getCur10V(trails); - //amac->wrField(&AMACv2RegMap::Ch12Mux , 0); // Read the mid point - //double Vout=0; - //for(uint i=0;i<trails;i++) - // { - // std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // Vout+=amac->getADC(12); - // } - //Vout/=trails; - - double VtestL = amac->getCur10VTPL(trails); - //amac->wrField(&AMACv2RegMap::Ch12Mux , 1); // Read the low point - //double VtestL=0; - //for(uint i=0;i<trails;i++) - // { - // std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // VtestL+=amac->getADC(12); - // } - //VtestL/=trails; - - double VtestH = amac->getCur10VTPH(trails); - //amac->wrField(&AMACv2RegMap::Ch12Mux , 2); // Read the high point - //double VtestH=0; - //for(uint i=0;i<trails;i++) - // { - // std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // VtestH+=amac->getADC(12); - // } - //VtestH/=trails; - - logger(logDEBUG) << "idcdcP,idcdcN,Vout,VtestL,VtestH = " << idcdcP << "\t" << idcdcN << "\t" << Vout << "\t" << VtestL << "\t" << VtestH; - - double CMDV=VtestH-VtestL-VtestHLZero; - if(bestCMDV==-666 || fabs(CMDV-0)<fabs(bestCMDV-0)) - { - bestCMDV=CMDV; - bestidcdcP=idcdcP; - bestidcdcN=idcdcN; - } - } - } + double bestCMDV = -666; // Best attanable match + uint32_t bestidcdcP = 0, bestidcdcN = 0; + + static const uint32_t trails = 100; // Number of trails per point + for (uint32_t idcdcP = 0; idcdcP < pow(2, 3); idcdcP++) { + amac->wrField(&AMACv2RegMap::DCDCiP, idcdcP); + for (uint32_t idcdcN = 0; idcdcN < pow(2, 3); idcdcN++) { + amac->wrField(&AMACv2RegMap::DCDCiN, idcdcN); + + double Vout = amac->getCur10V(trails); + // amac->wrField(&AMACv2RegMap::Ch12Mux , 0); // Read the mid point + // double Vout=0; + // for(uint i=0;i<trails;i++) + // { + // std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // Vout+=amac->getADC(12); + // } + // Vout/=trails; + + double VtestL = amac->getCur10VTPL(trails); + // amac->wrField(&AMACv2RegMap::Ch12Mux , 1); // Read the low point + // double VtestL=0; + // for(uint i=0;i<trails;i++) + // { + // std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // VtestL+=amac->getADC(12); + // } + // VtestL/=trails; + + double VtestH = amac->getCur10VTPH(trails); + // amac->wrField(&AMACv2RegMap::Ch12Mux , 2); // Read the high point + // double VtestH=0; + // for(uint i=0;i<trails;i++) + // { + // std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // VtestH+=amac->getADC(12); + // } + // VtestH/=trails; + + logger(logDEBUG) + << "idcdcP,idcdcN,Vout,VtestL,VtestH = " << idcdcP << "\t" + << idcdcN << "\t" << Vout << "\t" << VtestL << "\t" << VtestH; + + double CMDV = VtestH - VtestL - VtestHLZero; + if (bestCMDV == -666 || fabs(CMDV - 0) < fabs(bestCMDV - 0)) { + bestCMDV = CMDV; + bestidcdcP = idcdcP; + bestidcdcN = idcdcN; + } + } + } - logger(logINFO) << "\tDCDCiP/NidcdcP/N = " << bestidcdcP<<","<<bestidcdcN; + logger(logINFO) << "\tDCDCiP/NidcdcP/N = " << bestidcdcP << "," + << bestidcdcN; logger(logINFO) << "\tCM offset = " << bestCMDV << " mV"; // @@ -588,41 +593,42 @@ namespace PBv3ConfigTools // amac->wrField(&AMACv2RegMap::DCDCiP, bestidcdcP); amac->wrField(&AMACv2RegMap::DCDCiN, bestidcdcN); - //amac->wrField(&AMACv2RegMap::Ch12Mux , 0); // not really needed anymore - getCur10V etc set mux themselves + // amac->wrField(&AMACv2RegMap::Ch12Mux , 0); // not really needed anymore + // - getCur10V etc set mux themselves // also, getCur10V calibrates the raw data according to AM offsets and slope // // Full Chain logger(logDEBUG) << "Tuning amplifier offset, \"Full Chain\""; - amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 0); // Separate the DCDCi inputs + amac->wrField(&AMACv2RegMap::DCDCiZeroReading, + 0); // Separate the DCDCi inputs - double bestDVFullChain=-1; - uint32_t bestOffset=0; - for(uint i=0;i<pow(2,4);i++) - { - amac->wrField(&AMACv2RegMap::DCDCiOffset, i); - //std::this_thread::sleep_for(std::chrono::milliseconds(2)); // we get ~4ms delay over netio anyway - //double DV=amac->getADC(12); - double DV=amac->getCur10V(trails); - - logger(logDEBUG) << " DCDCiOffset = " << i << ", DV = " << DV << " mV"; - if(bestDVFullChain==-1 || fabs(DV-200)<fabs(bestDVFullChain-200)) - { - bestDVFullChain=DV; - bestOffset=i; - } - } + double bestDVFullChain = -1; + uint32_t bestOffset = 0; + for (uint i = 0; i < pow(2, 4); i++) { + amac->wrField(&AMACv2RegMap::DCDCiOffset, i); + // std::this_thread::sleep_for(std::chrono::milliseconds(2)); // we get + // ~4ms delay over netio anyway double DV=amac->getADC(12); + double DV = amac->getCur10V(trails); + + logger(logDEBUG) << " DCDCiOffset = " << i << ", DV = " << DV << " mV"; + if (bestDVFullChain == -1 || + fabs(DV - 200) < fabs(bestDVFullChain - 200)) { + bestDVFullChain = DV; + bestOffset = i; + } + } // set the best found offset setting amac->wrField(&AMACv2RegMap::DCDCiOffset, bestOffset); - //bestDVFullChain=0; - //for(uint i=0; i<100; i++) + // bestDVFullChain=0; + // for(uint i=0; i<100; i++) // { // std::this_thread::sleep_for(std::chrono::milliseconds(1)); // bestDVFullChain+=amac->getADC(12); // } - //bestDVFullChain/=100; + // bestDVFullChain/=100; // and measure it more times bestDVFullChain = amac->getCur10V(1000); @@ -632,63 +638,64 @@ namespace PBv3ConfigTools // // Zero Mode logger(logDEBUG) << "Tuning amplifier offset, \"Zero Mode\""; - amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 1); // Short the DCDCi inputs + amac->wrField(&AMACv2RegMap::DCDCiZeroReading, + 1); // Short the DCDCi inputs - double bestDVZeroMode=-1; + double bestDVZeroMode = -1; /** Code to tune in "Zero Mode" uint32_t bestOffset=0; for(uint i=0;i<pow(2,4);i++) { - amac->wrField(&AMACv2RegMap::DCDCiOffset, i); - std::this_thread::sleep_for(std::chrono::milliseconds(2)); - double DV=amac->getADC(12); - logger(logDEBUG) << " DCDCiOffset = " << i << ", DV = " << DV << " mV"; - if(bestDVZeroMode==-1 || fabs(DV-250)<fabs(bestDVZeroMode-250)) - { - bestDVZeroMode=DV; - bestOffset=i; - } + amac->wrField(&AMACv2RegMap::DCDCiOffset, i); + std::this_thread::sleep_for(std::chrono::milliseconds(2)); + double DV=amac->getADC(12); + logger(logDEBUG) << " DCDCiOffset = " << i << ", DV = " << DV << " mV"; + if(bestDVZeroMode==-1 || fabs(DV-250)<fabs(bestDVZeroMode-250)) + { + bestDVZeroMode=DV; + bestOffset=i; + } } */ - //amac->wrField(&AMACv2RegMap::DCDCiOffset, bestOffset); - //bestDVZeroMode=0; - //for(uint i=0; i<100; i++) + // amac->wrField(&AMACv2RegMap::DCDCiOffset, bestOffset); + // bestDVZeroMode=0; + // for(uint i=0; i<100; i++) // { // std::this_thread::sleep_for(std::chrono::milliseconds(1)); // bestDVZeroMode+=amac->getADC(12); // } - //bestDVZeroMode/=100; + // bestDVZeroMode/=100; bestDVZeroMode = amac->getCur10V(1000); logger(logINFO) << "\toffset zero = " << bestDVZeroMode << " mV"; // Save values config["properties"]["DCDCiOffset"] = bestOffset; - config["properties"]["DCDCiP" ] = bestidcdcP; - config["properties"]["DCDCiN" ] = bestidcdcN; + config["properties"]["DCDCiP"] = bestidcdcP; + config["properties"]["DCDCiN"] = bestidcdcN; config["results"]["CUR10VOFFSETZERO"] = bestDVZeroMode; - config["results"]["CUR10VCM" ] = bestCMDV; - config["results"]["CUR10VOFFSET" ] = bestDVFullChain; + config["results"]["CUR10VCM"] = bestCMDV; + config["results"]["CUR10VOFFSET"] = bestDVFullChain; configAMAC(amac, config, true); // Revert to old state amac->wrField(&AMACv2RegMap::DCDCiZeroReading, DCDCiZeroReading_curr); - amac->wrField(&AMACv2RegMap::Ch12Mux , Ch12Mux_curr ); + amac->wrField(&AMACv2RegMap::Ch12Mux, Ch12Mux_curr); return config; - } +} - json tuneCur1V(std::shared_ptr<AMACv2> amac) - { - static const uint32_t trails=100; // Number of trails per point +json tuneCur1V(std::shared_ptr<AMACv2> amac) { + static const uint32_t trails = 100; // Number of trails per point logger(logINFO) << "## Tuning output current monitor block ## " << trails; json config; - uint32_t DCDCen_curr =amac->rdField(&AMACv2RegMap::DCDCen ); - uint32_t DCDCoZeroReading_curr=amac->rdField(&AMACv2RegMap::DCDCoZeroReading); - uint32_t Ch13Mux_curr =amac->rdField(&AMACv2RegMap::Ch13Mux ); + uint32_t DCDCen_curr = amac->rdField(&AMACv2RegMap::DCDCen); + uint32_t DCDCoZeroReading_curr = + amac->rdField(&AMACv2RegMap::DCDCoZeroReading); + uint32_t Ch13Mux_curr = amac->rdField(&AMACv2RegMap::Ch13Mux); // Power on the current mirrors amac->wrField(&AMACv2RegMap::DCDCen, 1); @@ -696,84 +703,90 @@ namespace PBv3ConfigTools // // Buffer offsets - amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 1); // Short the DCDCo inputs + amac->wrField(&AMACv2RegMap::DCDCoZeroReading, + 1); // Short the DCDCo inputs logger(logDEBUG) << "Measuring relative buffer offset"; - double VtestLZero=amac->getCur1VTPL(trails); - double VtestHZero=amac->getCur1VTPH(trails); - double VtestHLZero=VtestHZero-VtestLZero; + double VtestLZero = amac->getCur1VTPL(trails); + double VtestHZero = amac->getCur1VTPH(trails); + double VtestHLZero = VtestHZero - VtestLZero; logger(logINFO) << "\tBuffer offset = " << VtestHLZero << " mV"; - amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 0); // Separate the DCDCi inputs + amac->wrField(&AMACv2RegMap::DCDCoZeroReading, + 0); // Separate the DCDCi inputs // // Tune the current mirrors (does not do anything other than write values) logger(logDEBUG) << "Tuning output CM mirror"; - double bestCMDV=-666; // Best attanable match - uint32_t bestodcdcP=0, bestodcdcN=0; - - //amac->wrField(&AMACv2RegMap::Ch13Mux , 0); // Read the mid point - //amac->wrField(&AMACv2RegMap::DCDCoOffset, 0); // Read the mid point - - for(uint32_t odcdcP=0;odcdcP<pow(2,1);odcdcP++) - { - amac->wrField(&AMACv2RegMap::DCDCoP, odcdcP); - for(uint32_t odcdcN=0;odcdcN<pow(2,1);odcdcN++) - { - amac->wrField(&AMACv2RegMap::DCDCoN, odcdcN); - - //// Separate the DCDCo inputs - //// When matched, the difference should be zero - //amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 0); - //double Vout0=0; - //for(uint i=0;i<trails;i++) - // { - // std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // Vout0+=amac->getADC(13); - // } - //Vout0/=trails; - - //// Separate the DCDCo inputs - //// When matched, the difference should be zero - //amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 1); - //double Vout1=0; - //for(uint i=0;i<trails;i++) - // { - // std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // Vout1+=amac->getADC(13); - // } - //Vout1/=trails; - - //double CMDV=Vout1-Vout0; - //logger(logDEBUG) << "odcdcP,odcdcN,Vout0,Vout1,CMDV = " << odcdcP << "\t" << odcdcN << "\t" << Vout0 << "\t" << Vout1 << "\t" << CMDV; - - // it seems the old scheme was to match getCur1V when DCDCoZeroReading is set to 0 and 1 + double bestCMDV = -666; // Best attanable match + uint32_t bestodcdcP = 0, bestodcdcN = 0; + + // amac->wrField(&AMACv2RegMap::Ch13Mux , 0); // Read the mid point + // amac->wrField(&AMACv2RegMap::DCDCoOffset, 0); // Read the mid point + + for (uint32_t odcdcP = 0; odcdcP < pow(2, 1); odcdcP++) { + amac->wrField(&AMACv2RegMap::DCDCoP, odcdcP); + for (uint32_t odcdcN = 0; odcdcN < pow(2, 1); odcdcN++) { + amac->wrField(&AMACv2RegMap::DCDCoN, odcdcN); + + //// Separate the DCDCo inputs + //// When matched, the difference should be zero + // amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 0); + // double Vout0=0; + // for(uint i=0;i<trails;i++) + // { + // std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // Vout0+=amac->getADC(13); + // } + // Vout0/=trails; + + //// Separate the DCDCo inputs + //// When matched, the difference should be zero + // amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 1); + // double Vout1=0; + // for(uint i=0;i<trails;i++) + // { + // std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // Vout1+=amac->getADC(13); + // } + // Vout1/=trails; + + // double CMDV=Vout1-Vout0; + // logger(logDEBUG) << "odcdcP,odcdcN,Vout0,Vout1,CMDV = " << odcdcP + // << "\t" << odcdcN << "\t" << Vout0 << "\t" << Vout1 << "\t" << + // CMDV; + + // it seems the old scheme was to match getCur1V when + // DCDCoZeroReading is set to 0 and 1 // // the new scheme: // match the |getCur1VTPH - getCur1VTPL| with DCDCoZeroReading = 1 - // to their difference when DCDCoZeroReading = 0 -- relative buffer offset + // to their difference when DCDCoZeroReading = 0 -- relative buffer + // offset // - double Vout =amac->getCur1V(trails); - double VtestL=amac->getCur1VTPL(trails); - double VtestH=amac->getCur1VTPH(trails); + double Vout = amac->getCur1V(trails); + double VtestL = amac->getCur1VTPL(trails); + double VtestH = amac->getCur1VTPH(trails); - logger(logDEBUG) << "odcdcP,odcdcN,Vout,VtestL,VtestH = " << odcdcP << "\t" << odcdcN << "\t" << Vout << "\t" << VtestL << "\t" << VtestH; + logger(logDEBUG) + << "odcdcP,odcdcN,Vout,VtestL,VtestH = " << odcdcP << "\t" + << odcdcN << "\t" << Vout << "\t" << VtestL << "\t" << VtestH; // When matched, the difference should be zero - double CMDV=VtestH-VtestL-VtestHLZero; - if(bestCMDV==-666 || fabs(CMDV-0)<fabs(bestCMDV-0)) - { - bestCMDV=CMDV; - bestodcdcP=odcdcP; - bestodcdcN=odcdcN; - } - } - } + double CMDV = VtestH - VtestL - VtestHLZero; + if (bestCMDV == -666 || fabs(CMDV - 0) < fabs(bestCMDV - 0)) { + bestCMDV = CMDV; + bestodcdcP = odcdcP; + bestodcdcN = odcdcN; + } + } + } - logger(logINFO) << "\tDCDCoP/NodcdcP/N = " << bestodcdcP << "," << bestodcdcN; + logger(logINFO) << "\tDCDCoP/NodcdcP/N = " << bestodcdcP << "," + << bestodcdcN; logger(logINFO) << "\tCM offset = " << bestCMDV << " mV"; // @@ -781,30 +794,31 @@ namespace PBv3ConfigTools // amac->wrField(&AMACv2RegMap::DCDCoP, bestodcdcP); amac->wrField(&AMACv2RegMap::DCDCoN, bestodcdcN); - //amac->wrField(&AMACv2RegMap::Ch13Mux , 0); // not needed? + // amac->wrField(&AMACv2RegMap::Ch13Mux , 0); // not needed? - uint32_t bestOffset=0; + uint32_t bestOffset = 0; // // Zero Mode logger(logDEBUG) << "Tuning amplifier offset, \"Zero Mode\""; - amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 1); // Short the DCDCo inputs + amac->wrField(&AMACv2RegMap::DCDCoZeroReading, + 1); // Short the DCDCo inputs - double bestDVZeroMode=-1; + double bestDVZeroMode = -1; /** Code to tune in "Zero Mode" for(uint i=0;i<pow(2,4);i++) { - amac->wrField(&AMACv2RegMap::DCDCoOffset, i); - //std::this_thread::sleep_for(std::chrono::milliseconds(2)); - //double DV=amac->getADC(13); + amac->wrField(&AMACv2RegMap::DCDCoOffset, i); + //std::this_thread::sleep_for(std::chrono::milliseconds(2)); + //double DV=amac->getADC(13); double DV=amac->getCur1V(trails); - logger(logDEBUG) << " DCDCoOffset = " << i << ", DV = " << DV << " mV"; - if(bestDVZeroMode==-1 || fabs(DV-200)<fabs(bestDVZeroMode-200)) - { - bestDVZeroMode=DV; - bestOffset=i; - } + logger(logDEBUG) << " DCDCoOffset = " << i << ", DV = " << DV << " mV"; + if(bestDVZeroMode==-1 || fabs(DV-200)<fabs(bestDVZeroMode-200)) + { + bestDVZeroMode=DV; + bestOffset=i; + } } amac->wrField(&AMACv2RegMap::DCDCoOffset, bestOffset); @@ -819,337 +833,334 @@ namespace PBv3ConfigTools // Full Chain logger(logDEBUG) << "Tuning amplifier offset, \"Full Chain\""; - amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 0); // Separate the DCDCo inputs + amac->wrField(&AMACv2RegMap::DCDCoZeroReading, + 0); // Separate the DCDCo inputs - double bestDVFullChain=-1; + double bestDVFullChain = -1; // Code to tune to offset to full chain - for(uint i=0;i<pow(2,4);i++) - { + for (uint i = 0; i < pow(2, 4); i++) { amac->wrField(&AMACv2RegMap::DCDCoOffset, i); - //std::this_thread::sleep_for(std::chrono::milliseconds(2)); - //double DV=amac->getADC(12); + // std::this_thread::sleep_for(std::chrono::milliseconds(2)); + // double DV=amac->getADC(12); double DV = amac->getCur1V(trails); - logger(logDEBUG) << " DCDCoOffset = " << i << ", DV = " << DV << " mV"; - if(bestDVFullChain==-1 || fabs(DV-100)<fabs(bestDVFullChain-100)) - { - bestDVFullChain = DV; - bestOffset = i; - } - } + logger(logDEBUG) << " DCDCoOffset = " << i << ", DV = " << DV << " mV"; + if (bestDVFullChain == -1 || + fabs(DV - 100) < fabs(bestDVFullChain - 100)) { + bestDVFullChain = DV; + bestOffset = i; + } + } - amac->wrField(&AMACv2RegMap::DCDCoOffset, bestOffset); // set the best found offset - bestDVFullChain = amac->getCur1V(1000); // and measure the current there 1000 times + amac->wrField(&AMACv2RegMap::DCDCoOffset, + bestOffset); // set the best found offset + bestDVFullChain = + amac->getCur1V(1000); // and measure the current there 1000 times logger(logINFO) << "\toffset = " << bestDVFullChain << " mV"; // Save values config["properties"]["DCDCoOffset"] = bestOffset; - config["properties"]["DCDCoP" ] = bestodcdcP; - config["properties"]["DCDCoN" ] = bestodcdcN; + config["properties"]["DCDCoP"] = bestodcdcP; + config["properties"]["DCDCoN"] = bestodcdcN; config["results"]["CUR1VOFFSETZERO"] = bestDVZeroMode; - config["results"]["CUR1VCM" ] = bestCMDV; - config["results"]["CUR1VOFFSET" ] = bestDVFullChain; + config["results"]["CUR1VCM"] = bestCMDV; + config["results"]["CUR1VOFFSET"] = bestDVFullChain; configAMAC(amac, config, true); // Revert to old state amac->wrField(&AMACv2RegMap::DCDCoZeroReading, DCDCoZeroReading_curr); - amac->wrField(&AMACv2RegMap::Ch13Mux , Ch13Mux_curr ); - amac->wrField(&AMACv2RegMap::DCDCen , DCDCen_curr); - amac->wrField(&AMACv2RegMap::DCDCenC , DCDCen_curr); + amac->wrField(&AMACv2RegMap::Ch13Mux, Ch13Mux_curr); + amac->wrField(&AMACv2RegMap::DCDCen, DCDCen_curr); + amac->wrField(&AMACv2RegMap::DCDCenC, DCDCen_curr); return config; - } +} - json tuneNTC(std::shared_ptr<AMACv2> amac) - { +json tuneNTC(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "## Tuning NTC range ##"; json config; // NTCx - uint32_t bestNTCx =0; - uint32_t bestNTCxValue =1024; - uint32_t bestNTCy =0; - uint32_t bestNTCyValue =1024; - uint32_t bestNTCpb =0; - uint32_t bestNTCpbValue=1024; - for(uint32_t i=0; i<8; i++) - { - amac->wrField(&AMACv2::NTCx0SenseRange, i); - amac->wrField(&AMACv2::NTCy0SenseRange, i); - amac->wrField(&AMACv2::NTCpbSenseRange, i); - usleep(10e3); - - //uint32_t NTCx = amac->rdField(&AMACv2::Ch7Value); - //uint32_t NTCy = amac->rdField(&AMACv2::Ch8Value); - //uint32_t NTCpb = amac->rdField(&AMACv2::Ch9Value); - - uint32_t NTCx = amac->readAM(AMACv2::AM::NTCX); - uint32_t NTCy = amac->readAM(AMACv2::AM::NTCY); - uint32_t NTCpb = amac->readAM(AMACv2::AM::NTCPB); - - logger(logDEBUG) << "Testing Range Setting " << i; - logger(logDEBUG) << "NTCx,y,pb = " << NTCx << ", " << NTCy << ", " << NTCpb ; - - uint32_t NTCxValue =(NTCx >500)?abs(NTCx -500):abs(500-NTCx ); - uint32_t NTCyValue =(NTCy >500)?abs(NTCy -500):abs(500-NTCy ); - uint32_t NTCpbValue=(NTCpb>500)?abs(NTCpb-500):abs(500-NTCpb); - - if(NTCxValue <bestNTCxValue || (i==7 && NTCx ==1023)) - { - bestNTCxValue =NTCxValue; - bestNTCx =i; - } - - if(NTCyValue <bestNTCyValue || (i==7 && NTCy ==1023)) - { - bestNTCyValue =NTCyValue; - bestNTCy =i; - } - - if(NTCpbValue<bestNTCpbValue || (i==7 && NTCpb==1023)) - { - bestNTCpbValue=NTCpbValue; - bestNTCpb=i; - } - } + uint32_t bestNTCx = 0; + uint32_t bestNTCxValue = 1024; + uint32_t bestNTCy = 0; + uint32_t bestNTCyValue = 1024; + uint32_t bestNTCpb = 0; + uint32_t bestNTCpbValue = 1024; + for (uint32_t i = 0; i < 8; i++) { + amac->wrField(&AMACv2::NTCx0SenseRange, i); + amac->wrField(&AMACv2::NTCy0SenseRange, i); + amac->wrField(&AMACv2::NTCpbSenseRange, i); + usleep(10e3); + + // uint32_t NTCx = amac->rdField(&AMACv2::Ch7Value); + // uint32_t NTCy = amac->rdField(&AMACv2::Ch8Value); + // uint32_t NTCpb = amac->rdField(&AMACv2::Ch9Value); + + uint32_t NTCx = amac->readAM(AMACv2::AM::NTCX); + uint32_t NTCy = amac->readAM(AMACv2::AM::NTCY); + uint32_t NTCpb = amac->readAM(AMACv2::AM::NTCPB); + + logger(logDEBUG) << "Testing Range Setting " << i; + logger(logDEBUG) << "NTCx,y,pb = " << NTCx << ", " << NTCy << ", " + << NTCpb; + + uint32_t NTCxValue = (NTCx > 500) ? abs(NTCx - 500) : abs(500 - NTCx); + uint32_t NTCyValue = (NTCy > 500) ? abs(NTCy - 500) : abs(500 - NTCy); + uint32_t NTCpbValue = + (NTCpb > 500) ? abs(NTCpb - 500) : abs(500 - NTCpb); + + if (NTCxValue < bestNTCxValue || (i == 7 && NTCx == 1023)) { + bestNTCxValue = NTCxValue; + bestNTCx = i; + } - config["properties"]["NTCx0SenseRange"] = bestNTCx ; - config["properties"]["NTCy0SenseRange"] = bestNTCy ; + if (NTCyValue < bestNTCyValue || (i == 7 && NTCy == 1023)) { + bestNTCyValue = NTCyValue; + bestNTCy = i; + } + + if (NTCpbValue < bestNTCpbValue || (i == 7 && NTCpb == 1023)) { + bestNTCpbValue = NTCpbValue; + bestNTCpb = i; + } + } + + config["properties"]["NTCx0SenseRange"] = bestNTCx; + config["properties"]["NTCy0SenseRange"] = bestNTCy; config["properties"]["NTCpbSenseRange"] = bestNTCpb; - logger(logDEBUG) << "Choosing NTCx,y,pb = " << bestNTCx << ", " << bestNTCy << ", " << bestNTCpb ; + logger(logDEBUG) << "Choosing NTCx,y,pb = " << bestNTCx << ", " << bestNTCy + << ", " << bestNTCpb; configAMAC(amac, config, true); return config; - } +} - json calibrateSlope(std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac) - { +json calibrateSlope(std::shared_ptr<AMACv2> amac, + std::shared_ptr<DACDevice> CALdac) { logger(logINFO) << "## Calibrating AMAC slope ##"; json config; - + // Run the test - double CALact=0; - uint32_t CALamac=0; + double CALact = 0; + uint32_t CALamac = 0; - //amac->wrField(&AMACv2RegMap::Ch4Mux , 1); // Set Ch4 mux to CAL input + // amac->wrField(&AMACv2RegMap::Ch4Mux , 1); // Set Ch4 mux to CAL input // Run ramp - std::vector<double> x,y; - uint n=0; + std::vector<double> x, y; + uint n = 0; // Longer wait for the first value due to RC constant CALdac->set(0); usleep(10e3); - for(double CALin=0; CALin<1.01; CALin+=0.05) - { - // actual voltage to be compared against digitized value - CALact=CALdac->set(CALin); - - // digital about - usleep(5e3); - //CALamac = amac->rdField(&AMACv2RegMap::Ch4Value); - CALamac = amac->readAM(AMACv2::AM::CAL); - if(CALamac==1023) break; //saturated, don't include - if(750<CALamac && CALamac<760) continue; //Switch point - - x.push_back(CALamac); - y.push_back(CALact ); - n++; - - logger(logDEBUG) << "\t" << x.back() << "\t" << y.back(); - logger(logINFO) << "## Calibrating AMAC slope ## CALact " << CALact << " CALamac " << CALamac;; - } + for (double CALin = 0; CALin < 1.01; CALin += 0.05) { + // actual voltage to be compared against digitized value + CALact = CALdac->set(CALin); + + // digital about + usleep(5e3); + // CALamac = amac->rdField(&AMACv2RegMap::Ch4Value); + CALamac = amac->readAM(AMACv2::AM::CAL); + if (CALamac == 1023) break; // saturated, don't include + if (750 < CALamac && CALamac < 760) continue; // Switch point + + x.push_back(CALamac); + y.push_back(CALact); + n++; + + logger(logDEBUG) << "\t" << x.back() << "\t" << y.back(); + logger(logINFO) << "## Calibrating AMAC slope ## CALact " << CALact + << " CALamac " << CALamac; + ; + } - double xavg=std::accumulate(x.begin(), x.end(), 0.)/n; - double yavg=std::accumulate(y.begin(), y.end(), 0.)/n; + double xavg = std::accumulate(x.begin(), x.end(), 0.) / n; + double yavg = std::accumulate(y.begin(), y.end(), 0.) / n; - double num=0; - double den=0; - for(uint i=0;i<x.size();i++) - { - num+=(x[i]-xavg)*(y[i]-yavg); - den+=(x[i]-xavg)*(x[i]-xavg); - } - double m=num/den; - double b=yavg-m*xavg; + double num = 0; + double den = 0; + for (uint i = 0; i < x.size(); i++) { + num += (x[i] - xavg) * (y[i] - yavg); + den += (x[i] - xavg) * (x[i] - xavg); + } + double m = num / den; + double b = yavg - m * xavg; logger(logDEBUG) << "\tm = " << m << ", b = " << b; - config["results"]["AMSLOPE"]=m*1e3; + config["results"]["AMSLOPE"] = m * 1e3; configAMAC(amac, config, true); return config; - } +} - std::vector<json> calibrateMultiSlope(std::vector<std::shared_ptr<AMACv2>> amacs, std::shared_ptr<DACDevice> CALdac) - { - logger(logINFO) << "## Calibrating #" << std::to_string(amacs.size()) << " AMAC slope ##"; +std::vector<json> calibrateMultiSlope( + std::vector<std::shared_ptr<AMACv2>> amacs, + std::shared_ptr<DACDevice> CALdac) { + logger(logINFO) << "## Calibrating #" << std::to_string(amacs.size()) + << " AMAC slope ##"; // per-AMAC run ramps - std::vector<std::vector<double>> xs,ys; - //std::vector<std::vector<uint32_t>> xs; + std::vector<std::vector<double>> xs, ys; + // std::vector<std::vector<uint32_t>> xs; std::vector<uint> ns; // the test parameters - //double CALact=0; - //std::vector<uint32_t> CALamac; - - for (int i=0; i<amacs.size(); i++) - { - //amacs[i]->wrField(&AMACv2RegMap::Ch4Mux , 1); // Set Ch4 mux to CAL input - amacs[i]->wrField("Ch4Mux" , 1); - ns.push_back(0); - xs.push_back({}); - ys.push_back({}); - //CALamac[i] = 0; - } + // double CALact=0; + // std::vector<uint32_t> CALamac; + + for (int i = 0; i < amacs.size(); i++) { + // amacs[i]->wrField(&AMACv2RegMap::Ch4Mux , 1); // Set Ch4 mux to CAL + // input + amacs[i]->wrField("Ch4Mux", 1); + ns.push_back(0); + xs.push_back({}); + ys.push_back({}); + // CALamac[i] = 0; + } // Longer wait for the first value due to RC constant CALdac->set(0); usleep(10e3); - for(double CALin=0; CALin<1.01; CALin+=0.05) - { - // actual voltage to be compared against digitized value - double CALact=CALdac->set(CALin); + for (double CALin = 0; CALin < 1.01; CALin += 0.05) { + // actual voltage to be compared against digitized value + double CALact = CALdac->set(CALin); - // digital about - usleep(5e3); + // digital about + usleep(5e3); - for (int i=0; i<amacs.size(); i++) - { - //uint32_t CALamac = amacs[i]->rdField(&AMACv2RegMap::Ch4Value); - //uint32_t CALamac = amacs[i]->rdField("Ch4Value"); - uint32_t CALamac = amacs[i]->readAM(AMACv2::AM::CAL); - if(CALamac==1023) break; //saturated, don't include - if(750<CALamac && CALamac<760) continue; //Switch point + for (int i = 0; i < amacs.size(); i++) { + // uint32_t CALamac = amacs[i]->rdField(&AMACv2RegMap::Ch4Value); + // uint32_t CALamac = amacs[i]->rdField("Ch4Value"); + uint32_t CALamac = amacs[i]->readAM(AMACv2::AM::CAL); + if (CALamac == 1023) break; // saturated, don't include + if (750 < CALamac && CALamac < 760) continue; // Switch point - xs[i].push_back(CALamac); - ys[i].push_back(CALact ); - ns[i]++; + xs[i].push_back(CALamac); + ys[i].push_back(CALact); + ns[i]++; - logger(logDEBUG) << "\tpadid=" << std::to_string(amacs[i]->getPADID()) << "\t" << xs[i].back() << "\t" << ys[i].back(); - } - } + logger(logDEBUG) + << "\tpadid=" << std::to_string(amacs[i]->getPADID()) << "\t" + << xs[i].back() << "\t" << ys[i].back(); + } + } // per-AMAC configs std::vector<json> configs; // calculate slope averages and save them in configs - for (int am_i=0; am_i<amacs.size(); am_i++) - { - auto& x = xs[am_i]; - auto& y = ys[am_i]; - auto& n = ns[am_i]; + for (int am_i = 0; am_i < amacs.size(); am_i++) { + auto& x = xs[am_i]; + auto& y = ys[am_i]; + auto& n = ns[am_i]; - json config; + json config; - double xavg=std::accumulate(x.begin(), x.end(), 0.)/n; - double yavg=std::accumulate(y.begin(), y.end(), 0.)/n; + double xavg = std::accumulate(x.begin(), x.end(), 0.) / n; + double yavg = std::accumulate(y.begin(), y.end(), 0.) / n; - double num=0; - double den=0; - for(uint i=0;i<x.size();i++) - { - num += (x[i]-xavg)*(y[i]-yavg); - den += (x[i]-xavg)*(x[i]-xavg); + double num = 0; + double den = 0; + for (uint i = 0; i < x.size(); i++) { + num += (x[i] - xavg) * (y[i] - yavg); + den += (x[i] - xavg) * (x[i] - xavg); } - double m = num/den; - double b = yavg-m*xavg; + double m = num / den; + double b = yavg - m * xavg; - logger(logDEBUG) << "\t" << std::to_string(amacs[am_i]->getPADID()) << "\tm = " << m << ", b = " << b; + logger(logDEBUG) << "\t" << std::to_string(amacs[am_i]->getPADID()) + << "\tm = " << m << ", b = " << b; - config["results"]["AMSLOPE"]=m*1e3; + config["results"]["AMSLOPE"] = m * 1e3; - configAMAC(amacs[am_i], config, true); - configs.push_back(config); - } + configAMAC(amacs[am_i], config, true); + configs.push_back(config); + } return configs; - } - +} - json calibrateOffset(std::shared_ptr<AMACv2> amac) - { +json calibrateOffset(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "## Calibrating AMAC offset ##"; json config; // Enable offset calibration - amac->wrField(&AMACv2RegMap::AMzeroCalib , 1); + amac->wrField(&AMACv2RegMap::AMzeroCalib, 1); amac->wrField(&AMACv2RegMap::AMzeroCalibC, 1); usleep(5e3); // Calculate the calibration uint32_t counts; - counts=amac->rdField(&AMACv2RegMap::Ch0Value ); - config["results"]["AMOFFSET"][ 0] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch0Value); + config["results"]["AMOFFSET"][0] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch1Value ); - config["results"]["AMOFFSET"][ 1] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch1Value); + config["results"]["AMOFFSET"][1] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch2Value ); - config["results"]["AMOFFSET"][ 2] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch2Value); + config["results"]["AMOFFSET"][2] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch3Value ); - config["results"]["AMOFFSET"][ 3] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch3Value); + config["results"]["AMOFFSET"][3] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch4Value ); - config["results"]["AMOFFSET"][ 4] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch4Value); + config["results"]["AMOFFSET"][4] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch5Value ); - config["results"]["AMOFFSET"][ 5] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch5Value); + config["results"]["AMOFFSET"][5] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch6Value ); - config["results"]["AMOFFSET"][ 6] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch6Value); + config["results"]["AMOFFSET"][6] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch7Value ); - config["results"]["AMOFFSET"][ 7] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch7Value); + config["results"]["AMOFFSET"][7] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch8Value ); - config["results"]["AMOFFSET"][ 8] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch8Value); + config["results"]["AMOFFSET"][8] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch9Value ); - config["results"]["AMOFFSET"][ 9] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch9Value); + config["results"]["AMOFFSET"][9] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch10Value); + counts = amac->rdField(&AMACv2RegMap::Ch10Value); config["results"]["AMOFFSET"][10] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch11Value); + counts = amac->rdField(&AMACv2RegMap::Ch11Value); config["results"]["AMOFFSET"][11] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch12Value); + counts = amac->rdField(&AMACv2RegMap::Ch12Value); config["results"]["AMOFFSET"][12] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch13Value); + counts = amac->rdField(&AMACv2RegMap::Ch13Value); config["results"]["AMOFFSET"][13] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch14Value); + counts = amac->rdField(&AMACv2RegMap::Ch14Value); config["results"]["AMOFFSET"][14] = counts; - counts=amac->rdField(&AMACv2RegMap::Ch15Value); + counts = amac->rdField(&AMACv2RegMap::Ch15Value); config["results"]["AMOFFSET"][15] = counts; logger(logDEBUG) << config["results"]["AMOFFSET"]; - // Disable offset calibration - amac->wrField(&AMACv2RegMap::AMzeroCalib , 0); + amac->wrField(&AMACv2RegMap::AMzeroCalib, 0); amac->wrField(&AMACv2RegMap::AMzeroCalibC, 0); configAMAC(amac, config, true); return config; - } +} - json calibrateNTC(std::shared_ptr<AMACv2> amac) - { +json calibrateNTC(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "## Calibrating NTCs ##"; json config; @@ -1160,17 +1171,17 @@ namespace PBv3ConfigTools logger(logINFO) << "## Calibrating NTCs waiting ##"; std::this_thread::sleep_for(std::chrono::milliseconds(100)); - double NTCx =amac->getNTCx (); - double NTCy =amac->getNTCy (); - double NTCpb=amac->getNTCpb(); + double NTCx = amac->getNTCx(); + double NTCy = amac->getNTCy(); + double NTCpb = amac->getNTCpb(); logger(logDEBUG) << "NTCx = " << NTCx << " mV"; logger(logDEBUG) << "NTCy = " << NTCy << " mV"; - logger(logDEBUG) << "NTCpb= " << NTCpb<< " mV"; + logger(logDEBUG) << "NTCpb= " << NTCpb << " mV"; - config["results"]["NTCX"] = NTCx ; - config["results"]["NTCY"] = NTCy ; - config["results"]["NTCPB"]= NTCpb; + config["results"]["NTCX"] = NTCx; + config["results"]["NTCY"] = NTCy; + config["results"]["NTCPB"] = NTCpb; // Disable NTC calibration amac->disableNTCCalibration(); @@ -1178,68 +1189,70 @@ namespace PBv3ConfigTools configAMAC(amac, config, true); return config; - } +} - /* - json calibrateCur10V(std::shared_ptr<AMACv2> amac) - { - logger(logINFO) << "## Calibrating input current monitor block ##"; +/* +json calibrateCur10V(std::shared_ptr<AMACv2> amac) +{ + logger(logINFO) << "## Calibrating input current monitor block ##"; - json config; + json config; - amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 1); // Short the DCDCi inputs + amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 1); // Short the DCDCi inputs - amac->wrField(&AMACv2RegMap::Ch12Mux , 0); + amac->wrField(&AMACv2RegMap::Ch12Mux , 0); - //double DV=0; - //for(uint i=0; i<100; i++) - // { - // std::this_thread::sleep_for(std::chrono::milliseconds(1)); - // //DV+=amac->getADC(12); - // DV+=amac->getCur10V(); - // } - //DV/=100; - double DV = amac->getCur10V(100); + //double DV=0; + //for(uint i=0; i<100; i++) + // { + // std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // //DV+=amac->getADC(12); + // DV+=amac->getCur10V(); + // } + //DV/=100; + double DV = amac->getCur10V(100); - config["results"]["CUR10VOFFSETZERO"] = DV; - configAMAC(amac, config, true); + config["results"]["CUR10VOFFSETZERO"] = DV; + configAMAC(amac, config, true); - amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 0); // Separate the DCDCi inputs + amac->wrField(&AMACv2RegMap::DCDCiZeroReading , 0); // Separate the DCDCi +inputs - return config; - } + return config; +} - json calibrateCur1V(std::shared_ptr<AMACv2> amac) - { - logger(logINFO) << "## Calibrating output current monitor block ##"; +json calibrateCur1V(std::shared_ptr<AMACv2> amac) +{ + logger(logINFO) << "## Calibrating output current monitor block ##"; - json config; + json config; - amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 1); // Short the DCDCo inputs + amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 1); // Short the DCDCo inputs - // this is not really needed - it is done down in getCur1V -> readAM - amac->wrField(&AMACv2RegMap::Ch13Mux , 0); + // this is not really needed - it is done down in getCur1V -> readAM + amac->wrField(&AMACv2RegMap::Ch13Mux , 0); - //double DV=0; - //for(uint i=0; i<100; i++) - // { - // usleep(5e3); - // //DV+=amac->getADC(13); - // DV+=amac->getCur1V(); - // } - //DV/=100; - double DV = amac->getCur1V(100); + //double DV=0; + //for(uint i=0; i<100; i++) + // { + // usleep(5e3); + // //DV+=amac->getADC(13); + // DV+=amac->getCur1V(); + // } + //DV/=100; + double DV = amac->getCur1V(100); - config["results"]["CUR1VOFFSET"] = DV; - configAMAC(amac, config, true); + config["results"]["CUR1VOFFSET"] = DV; + configAMAC(amac, config, true); - amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 0); // Separate the DCDCo inputs + amac->wrField(&AMACv2RegMap::DCDCoZeroReading , 0); // Separate the DCDCo +inputs - return config; - } - */ + return config; +} +*/ - json calibrateCur10V(std::shared_ptr<AMACv2> amac) { +json calibrateCur10V(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "### Calibrating input current monitor block 10V ###"; json config; @@ -1260,15 +1273,17 @@ namespace PBv3ConfigTools config["results"]["CUR10VOFFSETZERO"] = DV; configAMAC(amac, config, true); - logger(logINFO) << "### Calibrating output current monitor block 10V CUR10VOFFSETZERO = " << DV << " ###"; + logger(logINFO) << "### Calibrating output current monitor block 10V " + "CUR10VOFFSETZERO = " + << DV << " ###"; amac->wrField(&AMACv2RegMap::DCDCiZeroReading, 0); // Separate the DCDCi inputs return config; - } +} - json calibrateCur1V(std::shared_ptr<AMACv2> amac) { +json calibrateCur1V(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "### Calibrating output current monitor block 1V ###"; json config; @@ -1292,52 +1307,50 @@ namespace PBv3ConfigTools 0); // Separate the DCDCo inputs return config; - } +} - json calibrateTemperature (std::shared_ptr<AMACv2> amac) - { +json calibrateTemperature(std::shared_ptr<AMACv2> amac) { logger(logINFO) << "## Calibrating the temperature scale ##"; json config; - uint32_t DCDCen_curr =amac->rdField(&AMACv2::DCDCen); - uint32_t CTAToffset_curr=amac->rdField(&AMACv2RegMap::CTAToffset); + uint32_t DCDCen_curr = amac->rdField(&AMACv2::DCDCen); + uint32_t CTAToffset_curr = amac->rdField(&AMACv2RegMap::CTAToffset); // // Check if bPOL is enabled, heating everything up - if(DCDCen_curr>0) - { - amac->wrField(&AMACv2::DCDCen , 0); - amac->wrField(&AMACv2::DCDCenC, 0); // TODO: check is it ok for Star? - } + if (DCDCen_curr > 0) { + amac->wrField(&AMACv2::DCDCen, 0); + amac->wrField(&AMACv2::DCDCenC, 0); // TODO: check is it ok for Star? + } // // Wait until PTAT stabilizes - //uint32_t cPTAT = amac->rdField(&AMACv2::Ch15Value); - uint32_t cPTAT = amac->readAM(AMACv2::AM::PTAT); + // uint32_t cPTAT = amac->rdField(&AMACv2::Ch15Value); + uint32_t cPTAT = amac->readAM(AMACv2::AM::PTAT); uint32_t cPTATp = 0; - while(abs(cPTAT-cPTATp)>1) - { - logger(logDEBUG) << "Cooling... PTAT = " << cPTAT << ", NTCpb = " << amac->temperaturePB() << "C"; + while (abs(cPTAT - cPTATp) > 1) { + logger(logDEBUG) << "Cooling... PTAT = " << cPTAT + << ", NTCpb = " << amac->temperaturePB() << "C"; - // This will take a while... - std::this_thread::sleep_for(std::chrono::seconds(1)); + // This will take a while... + std::this_thread::sleep_for(std::chrono::seconds(1)); - // Update tempreature - cPTATp=cPTAT; - cPTAT = amac->readAM(AMACv2::AM::PTAT); - } + // Update tempreature + cPTATp = cPTAT; + cPTAT = amac->readAM(AMACv2::AM::PTAT); + } // // Measure temperatures - double PTAT = amac->getPTAT(); + double PTAT = amac->getPTAT(); double NTCpb = amac->temperaturePB(); // Assume // m = 8.5mV/C (FEAST datasheet) // Tnow = from NTCpb, in C // PTAT(Tnow) = m * Tnow + PTAT0 - //double PTAT0 = PTAT - 8.5 * NTCpb; + // double PTAT0 = PTAT - 8.5 * NTCpb; // Now: // m = 4.85mV/C (bPOL datasheet) @@ -1346,72 +1359,70 @@ namespace PBv3ConfigTools double PTAT0 = PTAT - 4.85 * NTCpb; logger(logDEBUG) << "PTAT0 = " << PTAT0; - config["results"]["PTAT0"]=PTAT0; + config["results"]["PTAT0"] = PTAT0; // // Calibrate CTAT's - for(uint32_t CTAToffset_set=0; CTAToffset_set<16; CTAToffset_set++) - { - amac->wrField(&AMACv2RegMap::CTAToffset, CTAToffset_set); - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + for (uint32_t CTAToffset_set = 0; CTAToffset_set < 16; CTAToffset_set++) { + amac->wrField(&AMACv2RegMap::CTAToffset, CTAToffset_set); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); - double CTAT = amac->getCTAT(); - double CTAT0 = CTAT + 1.5 * NTCpb; + double CTAT = amac->getCTAT(); + double CTAT0 = CTAT + 1.5 * NTCpb; - config["results"]["CTAT0"][CTAToffset_set]=CTAT0; - logger(logDEBUG) << "CTAT0[" << CTAToffset_set << "] = " << CTAT0; - } + config["results"]["CTAT0"][CTAToffset_set] = CTAT0; + logger(logDEBUG) << "CTAT0[" << CTAToffset_set << "] = " << CTAT0; + } // // Re-enable DC/DC - if(DCDCen_curr>0) - { - amac->wrField(&AMACv2::DCDCen , 1); - amac->wrField(&AMACv2::DCDCenC, 1); - } - amac->wrField(&AMACv2RegMap::CTAToffset, CTAToffset_curr ); + if (DCDCen_curr > 0) { + amac->wrField(&AMACv2::DCDCen, 1); + amac->wrField(&AMACv2::DCDCenC, 1); + } + amac->wrField(&AMACv2RegMap::CTAToffset, CTAToffset_curr); configAMAC(amac, config, true); return config; - } - - /* - json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) - { - logger(logINFO) << "## Determining AMAC PADID ##"; +} - json config; +/* +json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) +{ + logger(logINFO) << "## Determining AMAC PADID ##"; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); + json config; - //Power cycle AMAC if the ID is already set - if(amac->isCommIDSet()) { - tb->setOFin(pbNum, true); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - tb->setOFin(pbNum, false); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } + std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - for(uint8_t i=0; i<=16; i++) { - try { - amac->setid(EndeavourCom::REFMODE::IDPads, i); - config["results"]["PADID"]=i; - } catch(EndeavourComException &e) { - if(i==16) { - logger(logERROR) << "Could not determine PADID"; - } - } - } - - //Power cycle AMAC to allow for resetting of the ID + //Power cycle AMAC if the ID is already set + if(amac->isCommIDSet()) { tb->setOFin(pbNum, true); std::this_thread::sleep_for(std::chrono::milliseconds(200)); tb->setOFin(pbNum, false); std::this_thread::sleep_for(std::chrono::milliseconds(200)); + } - return config; + for(uint8_t i=0; i<=16; i++) { + try { + amac->setid(EndeavourCom::REFMODE::IDPads, i); + config["results"]["PADID"]=i; + } catch(EndeavourComException &e) { + if(i==16) { + logger(logERROR) << "Could not determine PADID"; + } + } } - */ + //Power cycle AMAC to allow for resetting of the ID + tb->setOFin(pbNum, true); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + tb->setOFin(pbNum, false); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + + return config; } +*/ + +} // namespace PBv3ConfigTools diff --git a/pbv3/PBv3ConfigTools.h b/pbv3/PBv3ConfigTools.h index b9c6112dc09394241ab80ebeb195c1c961e241bb..dac96f6fe679488db3ce94029455d65654aacd0b 100644 --- a/pbv3/PBv3ConfigTools.h +++ b/pbv3/PBv3ConfigTools.h @@ -7,11 +7,11 @@ #include <DACDevice.h> #include <chrono> -#include <thread> -#include <nlohmann/json.hpp> #include <iomanip> -#include <string> #include <memory> +#include <nlohmann/json.hpp> +#include <string> +#include <thread> #include "Logger.h" @@ -25,324 +25,340 @@ using nlohmann::json; * - Finding the optimal settings for an AMAC (tune) * - Determining the AMAC response to input using fixed settings (calibrate) * - * All tune/calibrate functions modify the state of the AMAC object based on the result. + * All tune/calibrate functions modify the state of the AMAC object based on the + * result. * * All functions return a consistent configuration for the chip. For example, - * tunning the AM bandgap changes the ADC response. Thus the result of the tuneAMBG - * also contains updated calibration. + * tunning the AM bandgap changes the ADC response. Thus the result of the + * tuneAMBG also contains updated calibration. * * The output format is compatible with the CONFIG test type in the ITk PD. */ -namespace PBv3ConfigTools -{ - // - // Copy JSON configuration to AMAC - - /** - * \brief load the circuit data from config to amac - */ - bool config_to_amac_circuit_data(json& config, std::shared_ptr<AMACv2> amac); - - /** - * \brief load the circuit data from amac to config - */ - //bool amac_circuit_data_to_config(std::shared_ptr<AMACv2> amac, json& config); - json amac_circuit_data_to_config(std::shared_ptr<AMACv2> amac); - - /** \brief Configure an AMAC with the given calibration file - */ - bool configAMAC_file(std::shared_ptr<AMACv2> amac, const std::string& calib_cfg, bool write); - - /** - * \brief Configure an AMAC using the default calibration files on the system. - * - * Configuration of registers means changing the default values. - * - * The format of the JSON configuration assumes the following: - * - key "properties" points to a dictionary where the key is the field name and value the value to be set - * - key "results" contains a dictionary with calibration values - * - * If the JSON contains a "config" key, then the properties and results are looked for there. Other - * wise they are accessed from the top-level of the JSON object. - * - * \param amac Pointer to the AMACv2 object - * \param bool use_int_calib -- use int slope calibration or bg - * \param write Write the results to the AMACv2 chip in addition to updating the default values - * - * \return bool of success or no (found/no the calibration files) - */ - bool configAMAC_default(std::shared_ptr<AMACv2> amac, bool use_int_calib, bool write); - - /** - * \brief Configure an AMAC using the contents of a JSON file. - * - * Configuration of registers means changing the default values. - * - * The format of the JSON configuration assumes the following: - * - key "properties" points to a dictionary where the key is the field name and value the value to be set - * - key "results" contains a dictionary with calibration values - * - * If the JSON contains a "config" key, then the properties and results are looked for there. Other - * wise they are accessed from the top-level of the JSON object. - * - * \param amac Pointer to the AMACv2 object - * \param config JSON configuration to apply - * \param write Write the results to the AMACv2 chip in addition to updating the default values - */ - void configAMAC(std::shared_ptr<AMACv2> amac, const json& config, bool write); - - /** - * \brief Read current AMAC configuration and save it to a JSON object - * - * \param amac Pointer to the AMACv2 object - * \param config JSON configuration to update - */ - void saveConfigAMAC(std::shared_ptr<AMACv2> amac, json& config); - - /** - * \brief Decorate a JSON config object with information that can be saved to a database - * - * Adds the following fields: - * - testType: "CONFIG" - * - institution: "LBL" - * - runNumber: "0-0" by default, increment lower number by 1 if already exists - * - * \param config JSON configuration to update - */ - void decorateConfig(json& config); - - // - // All helper functions for tuning the AMAC settings - - /** - * \brief Find the VDDbg setting for VDDREG to be 1.2V - * - * Assumes that the AMACv2 is correctly calibrated. - * - * Modifes the following registers: - * - VDDbg - * - VDDbgen - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json configuration - */ - json tuneVDDBG (std::shared_ptr<AMACv2> amac); - - /** - * \brief Find the AMbg setting for AM bandgap to be 600 mV - * - * Modifes the following registers: - * - AMbg - * - AMbgen - * - * Updates the ADC calibration. - * - * \param amac Pointer to the AMACv2 object - * \param CALdac Pointer to the DAC that drives the CAL line - * - * \return updated json configuration and calibration - */ - json tuneAMBG (std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac); - - /** - * \brief Find the ramp gain for ADC response of 1mV / count - * - * Modifes the following registers: - * - AMintCalib - * - * Updates the ADC calibration. - * - * \param amac Pointer to the AMACv2 object - * \param CALdac Pointer to the DAC that drives the CAL line - * - * \return updated json configuration and calibration - */ - json tuneRampGain(std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac); - - /** - * \brief Find the ramp gain for ADC response of 1mV / count for multiple AMACs in one sweep - */ - json tuneRampGain_multiSlope(std::vector<std::shared_ptr<AMACv2>> amacs, std::shared_ptr<DACDevice> CALdac); - - std::vector<json> calibrateMultiSlope(std::vector<std::shared_ptr<AMACv2>> amac, std::shared_ptr<DACDevice> CALdac); - - /** - * \brief Tune the offset for the input current monitor block - * - * This procedure requires that there is no load on the input current. This - * means that the bPOL must be disabled. If it is enabled, a warning is - * printed and the function returns. - * - * Step 1: Measure the buffer offset difference - * Shorts the low and high connections and measures the buffered value - * at the low and high test points. The test points are disconnected - * after this step. - * - * Step 2: - * Measures the difference between the two current mirrors as a function - * of the DCDCiN/P register settings by comparing the test point values. The - * offset from step 1 is subtracted from the High-Low TP difference. - - * The value that gives a difference closest to zero is chosen as the tuning. - * - * Step 3: - * Measures the final amplifier output with the High/Low connections shorted - * as a function of the DCDCiOffset value. The offset with the High/Low - * connections disconnected at the tuned value is also measured. - * - * The value giving an offset closest to 250 mV is closen as the tuning. - * - * The following results are saved in the resulting JSON object: - * - DCDCiOffset: Offset giving the closest "zero reading" to 250 mV - * - DCDCiP: Low current mirror setting giving the closest match - * - DCDCiN: High current mirror setting giving the closest match - * - * The following properties are saved in the resulting JSON object: - * - CUR10VOFFSETZERO: Buffer offset in "zero reading" mode at `DCDCiOffset` - * - CUR10VCM: Current mirror mismatch at `DCDCiP`/`DCDCiN` - * - CUR10VOFFSET: Buffer offset mode at `DCDCiOffset` "zero" current - * - * Modifes the following registers: - * - Ch12Mux - * - DCDCiP - * - DCDCiN - * - DCDCiOffset - * - DCDCiZeroReading - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json configuration and calibration - */ - json tuneCur10V(std::shared_ptr<AMACv2> amac); - - /** - * \brief Tune the offset for the output current monitor block - * - * Scans through all settings for the DCDCoOffset register until it finds - * a configuration where the ADC reads ~100 mV when the two measurements - * shorted together. - * - * Also prints values for the current monitor test point values - * when the zero calibration is disabled, but does not do anything with them. - * - * Modifes the following registers: - * - DCDCoOffset - * - * Updates the current offset calibration based on 100 readings. - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json configuration and calibration - */ - json tuneCur1V(std::shared_ptr<AMACv2> amac); - - /** - * \brief Find the NTC sense range setting for the current temperature - * - * Best setting is defined as the value that gives the reading closest - * to 500 counts - * - * Modifes the following registers: - * - NTCx0SenseRange - * - NTCy0SenseRange - * - NTCpbSenseRange - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json configuration - */ - json tuneNTC(std::shared_ptr<AMACv2> amac); - - // - // All helper functions for calibration of the AMAC - - /** - * \brief Calibrate the ADC response slope - * - * Updates the ADC calibration slope in mV/count. - * - * \param amac Pointer to the AMACv2 object - * \param CALdac Pointer to the DAC that drives the CAL line - * - * \return updated json calibration - */ - json calibrateSlope (std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac); - - /** - * \brief Calibrate the ADC response offsets - * - * Updates the ADC calibration offsets in counts. - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json calibration - */ - json calibrateOffset(std::shared_ptr<AMACv2> amac); - - /** - * \brief Calibrate the NTC reference voltage - * - * Updates the NTC reference voltages (pb,x,y) in mV. - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json calibration - */ - json calibrateNTC(std::shared_ptr<AMACv2> amac); - - /** - * \brief Calibrate the input Current Monitor offset - * - * Updates the offset calibration for input CM - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json calibration - */ - json calibrateCur10V(std::shared_ptr<AMACv2> amac); - - /** - * \brief Calibrate the output Current Monitor offset - * - * Updates the offset calibration for output CM - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json calibration - */ - json calibrateCur1V(std::shared_ptr<AMACv2> amac); - - /** - * \brief Calibrate the absolute temperature scale - * - * Calibrates the PTAT and CTAT by comparing the temperature - * with the DC/DC converter in OFF state. Since there is no - * major power usage, this assumes that the temperature in - * this state is uniform across the board. - * - * If the DC/DC converter is turned on, it is disabled and - * the program waits until PTAT stabilizes. - * - * For CTAT, all offset settings are scanned. - * - * \param amac Pointer to the AMACv2 object - * - * \return updated json calibration - */ - json calibrateTemperature(std::shared_ptr<AMACv2> amac); - - /** - * \brief Determine the AMAC PADID - * - * The implementation requires the AMAC ID to be set again even if it was not previously. - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench with all control classes - * - * \return updated json configuration - */ - //json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); // we do not use it anywhere and it pulls a lot of labremote dependencies through PBv3TB -} +namespace PBv3ConfigTools { +// +// Copy JSON configuration to AMAC + +/** + * \brief load the circuit data from config to amac + */ +bool config_to_amac_circuit_data(json& config, std::shared_ptr<AMACv2> amac); + +/** + * \brief load the circuit data from amac to config + */ +// bool amac_circuit_data_to_config(std::shared_ptr<AMACv2> amac, json& config); +json amac_circuit_data_to_config(std::shared_ptr<AMACv2> amac); + +/** \brief Configure an AMAC with the given calibration file + */ +bool configAMAC_file(std::shared_ptr<AMACv2> amac, const std::string& calib_cfg, + bool write); + +/** + * \brief Configure an AMAC using the default calibration files on the system. + * + * Configuration of registers means changing the default values. + * + * The format of the JSON configuration assumes the following: + * - key "properties" points to a dictionary where the key is the field name + * and value the value to be set + * - key "results" contains a dictionary with calibration values + * + * If the JSON contains a "config" key, then the properties and results are + * looked for there. Other wise they are accessed from the top-level of the JSON + * object. + * + * \param amac Pointer to the AMACv2 object + * \param bool use_int_calib -- use int slope calibration or bg + * \param write Write the results to the AMACv2 chip in addition to updating the + * default values + * + * \return bool of success or no (found/no the calibration files) + */ +bool configAMAC_default(std::shared_ptr<AMACv2> amac, bool use_int_calib, + bool write); + +/** + * \brief Configure an AMAC using the contents of a JSON file. + * + * Configuration of registers means changing the default values. + * + * The format of the JSON configuration assumes the following: + * - key "properties" points to a dictionary where the key is the field name + * and value the value to be set + * - key "results" contains a dictionary with calibration values + * + * If the JSON contains a "config" key, then the properties and results are + * looked for there. Other wise they are accessed from the top-level of the JSON + * object. + * + * \param amac Pointer to the AMACv2 object + * \param config JSON configuration to apply + * \param write Write the results to the AMACv2 chip in addition to updating the + * default values + */ +void configAMAC(std::shared_ptr<AMACv2> amac, const json& config, bool write); + +/** + * \brief Read current AMAC configuration and save it to a JSON object + * + * \param amac Pointer to the AMACv2 object + * \param config JSON configuration to update + */ +void saveConfigAMAC(std::shared_ptr<AMACv2> amac, json& config); + +/** + * \brief Decorate a JSON config object with information that can be saved to a + * database + * + * Adds the following fields: + * - testType: "CONFIG" + * - institution: "LBL" + * - runNumber: "0-0" by default, increment lower number by 1 if already exists + * + * \param config JSON configuration to update + */ +void decorateConfig(json& config); + +// +// All helper functions for tuning the AMAC settings + +/** + * \brief Find the VDDbg setting for VDDREG to be 1.2V + * + * Assumes that the AMACv2 is correctly calibrated. + * + * Modifes the following registers: + * - VDDbg + * - VDDbgen + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json configuration + */ +json tuneVDDBG(std::shared_ptr<AMACv2> amac); + +/** + * \brief Find the AMbg setting for AM bandgap to be 600 mV + * + * Modifes the following registers: + * - AMbg + * - AMbgen + * + * Updates the ADC calibration. + * + * \param amac Pointer to the AMACv2 object + * \param CALdac Pointer to the DAC that drives the CAL line + * + * \return updated json configuration and calibration + */ +json tuneAMBG(std::shared_ptr<AMACv2> amac, std::shared_ptr<DACDevice> CALdac); + +/** + * \brief Find the ramp gain for ADC response of 1mV / count + * + * Modifes the following registers: + * - AMintCalib + * + * Updates the ADC calibration. + * + * \param amac Pointer to the AMACv2 object + * \param CALdac Pointer to the DAC that drives the CAL line + * + * \return updated json configuration and calibration + */ +json tuneRampGain(std::shared_ptr<AMACv2> amac, + std::shared_ptr<DACDevice> CALdac); + +/** + * \brief Find the ramp gain for ADC response of 1mV / count for multiple AMACs + * in one sweep + */ +json tuneRampGain_multiSlope(std::vector<std::shared_ptr<AMACv2>> amacs, + std::shared_ptr<DACDevice> CALdac); + +std::vector<json> calibrateMultiSlope(std::vector<std::shared_ptr<AMACv2>> amac, + std::shared_ptr<DACDevice> CALdac); + +/** + * \brief Tune the offset for the input current monitor block + * + * This procedure requires that there is no load on the input current. This + * means that the bPOL must be disabled. If it is enabled, a warning is + * printed and the function returns. + * + * Step 1: Measure the buffer offset difference + * Shorts the low and high connections and measures the buffered value + * at the low and high test points. The test points are disconnected + * after this step. + * + * Step 2: + * Measures the difference between the two current mirrors as a function + * of the DCDCiN/P register settings by comparing the test point values. The + * offset from step 1 is subtracted from the High-Low TP difference. + + * The value that gives a difference closest to zero is chosen as the tuning. + * + * Step 3: + * Measures the final amplifier output with the High/Low connections shorted + * as a function of the DCDCiOffset value. The offset with the High/Low + * connections disconnected at the tuned value is also measured. + * + * The value giving an offset closest to 250 mV is closen as the tuning. + * + * The following results are saved in the resulting JSON object: + * - DCDCiOffset: Offset giving the closest "zero reading" to 250 mV + * - DCDCiP: Low current mirror setting giving the closest match + * - DCDCiN: High current mirror setting giving the closest match + * + * The following properties are saved in the resulting JSON object: + * - CUR10VOFFSETZERO: Buffer offset in "zero reading" mode at `DCDCiOffset` + * - CUR10VCM: Current mirror mismatch at `DCDCiP`/`DCDCiN` + * - CUR10VOFFSET: Buffer offset mode at `DCDCiOffset` "zero" current + * + * Modifes the following registers: + * - Ch12Mux + * - DCDCiP + * - DCDCiN + * - DCDCiOffset + * - DCDCiZeroReading + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json configuration and calibration + */ +json tuneCur10V(std::shared_ptr<AMACv2> amac); + +/** + * \brief Tune the offset for the output current monitor block + * + * Scans through all settings for the DCDCoOffset register until it finds + * a configuration where the ADC reads ~100 mV when the two measurements + * shorted together. + * + * Also prints values for the current monitor test point values + * when the zero calibration is disabled, but does not do anything with them. + * + * Modifes the following registers: + * - DCDCoOffset + * + * Updates the current offset calibration based on 100 readings. + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json configuration and calibration + */ +json tuneCur1V(std::shared_ptr<AMACv2> amac); + +/** + * \brief Find the NTC sense range setting for the current temperature + * + * Best setting is defined as the value that gives the reading closest + * to 500 counts + * + * Modifes the following registers: + * - NTCx0SenseRange + * - NTCy0SenseRange + * - NTCpbSenseRange + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json configuration + */ +json tuneNTC(std::shared_ptr<AMACv2> amac); + +// +// All helper functions for calibration of the AMAC + +/** + * \brief Calibrate the ADC response slope + * + * Updates the ADC calibration slope in mV/count. + * + * \param amac Pointer to the AMACv2 object + * \param CALdac Pointer to the DAC that drives the CAL line + * + * \return updated json calibration + */ +json calibrateSlope(std::shared_ptr<AMACv2> amac, + std::shared_ptr<DACDevice> CALdac); + +/** + * \brief Calibrate the ADC response offsets + * + * Updates the ADC calibration offsets in counts. + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json calibration + */ +json calibrateOffset(std::shared_ptr<AMACv2> amac); + +/** + * \brief Calibrate the NTC reference voltage + * + * Updates the NTC reference voltages (pb,x,y) in mV. + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json calibration + */ +json calibrateNTC(std::shared_ptr<AMACv2> amac); + +/** + * \brief Calibrate the input Current Monitor offset + * + * Updates the offset calibration for input CM + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json calibration + */ +json calibrateCur10V(std::shared_ptr<AMACv2> amac); + +/** + * \brief Calibrate the output Current Monitor offset + * + * Updates the offset calibration for output CM + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json calibration + */ +json calibrateCur1V(std::shared_ptr<AMACv2> amac); + +/** + * \brief Calibrate the absolute temperature scale + * + * Calibrates the PTAT and CTAT by comparing the temperature + * with the DC/DC converter in OFF state. Since there is no + * major power usage, this assumes that the temperature in + * this state is uniform across the board. + * + * If the DC/DC converter is turned on, it is disabled and + * the program waits until PTAT stabilizes. + * + * For CTAT, all offset settings are scanned. + * + * \param amac Pointer to the AMACv2 object + * + * \return updated json calibration + */ +json calibrateTemperature(std::shared_ptr<AMACv2> amac); + +/** + * \brief Determine the AMAC PADID + * + * The implementation requires the AMAC ID to be set again even if it was not + * previously. + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench with all control classes + * + * \return updated json configuration + */ +// json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); // we do not use +// it anywhere and it pulls a lot of labremote dependencies through PBv3TB +} // namespace PBv3ConfigTools #endif diff --git a/pbv3/PBv3QCFlow.cpp b/pbv3/PBv3QCFlow.cpp index 34702d0a325d9be08168de34ef5497eea64572a9..efb20aa6c1f4e7311b0700b1879529b2bda9b58f 100644 --- a/pbv3/PBv3QCFlow.cpp +++ b/pbv3/PBv3QCFlow.cpp @@ -7,209 +7,211 @@ using namespace nlohmann; -PBv3QCFlow::PBv3QCFlow(uint8_t num, bool doHV) - : m_num(num), m_doHV(doHV) -{ } - -uint8_t PBv3QCFlow::num() const -{ return m_num; } - -std::string PBv3QCFlow::serial() const -{ return m_serial; } - -void PBv3QCFlow::setSerial(const std::string& serial) -{ m_serial=serial; } - -json PBv3QCFlow::runAliveTests(std::shared_ptr<PBv3TB> tb) -{ - // Reset test states - m_passAlive=false; - m_passCom =false; - m_passOF =false; - - // Run the tests! - std::cout << std::endl; - logger(logINFO) << "### Performing alive tests on powerboard " << m_num << " ###"; - - // Output structure - uint32_t test=0; - json diagSum; - - diagSum["config"]["component"] = m_serial; - diagSum["config"]["institution"] = "LBNL_STRIP_POWERBOARDS"; - diagSum["pbNum"] = m_num; - diagSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - diagSum["tests"][test++] = PBv3TestTools::testOF(m_num, tb); - m_passOF=diagSum["tests"][test-1]["passed"]; - - if(!m_passOF) - { - logger(logERROR) << "linPOL for powerboard " << m_num << " is non-operational. Skipping to next board."; - } +PBv3QCFlow::PBv3QCFlow(uint8_t num, bool doHV) : m_num(num), m_doHV(doHV) {} + +uint8_t PBv3QCFlow::num() const { return m_num; } + +std::string PBv3QCFlow::serial() const { return m_serial; } + +void PBv3QCFlow::setSerial(const std::string& serial) { m_serial = serial; } + +json PBv3QCFlow::runAliveTests(std::shared_ptr<PBv3TB> tb) { + // Reset test states + m_passAlive = false; + m_passCom = false; + m_passOF = false; + + // Run the tests! + std::cout << std::endl; + logger(logINFO) << "### Performing alive tests on powerboard " << m_num + << " ###"; + + // Output structure + uint32_t test = 0; + json diagSum; - diagSum["tests"][test++]=PBv3TestTools::scanPADID(m_num, tb); - - m_passCom=true; - if(diagSum["tests"][test-1]["passed"]) - { - // Init com - logger(logINFO) << "Init AMAC"; - std::shared_ptr<AMACv2> amac=tb->getPB(m_num); - amac->init(); - - diagSum["tests"][test++]=PBv3TestTools::runBER(amac); - if(!diagSum["tests"][test-1]["passed"]) - { - m_passCom=false; - logger(logERROR) << "BER test failed for pb " << m_num << ". AMAC read/write not working. Will not perform full test on this board."; - } + diagSum["config"]["component"] = m_serial; + diagSum["config"]["institution"] = "LBNL_STRIP_POWERBOARDS"; + diagSum["pbNum"] = m_num; + diagSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + diagSum["tests"][test++] = PBv3TestTools::testOF(m_num, tb); + m_passOF = diagSum["tests"][test - 1]["passed"]; + + if (!m_passOF) { + logger(logERROR) << "linPOL for powerboard " << m_num + << " is non-operational. Skipping to next board."; } - else - { - m_passCom=false; - logger(logERROR) << "PADID test failed for pb " << m_num << ". AMAC read/write not working. Will not perform full test on this board."; + + diagSum["tests"][test++] = PBv3TestTools::scanPADID(m_num, tb); + + m_passCom = true; + if (diagSum["tests"][test - 1]["passed"]) { + // Init com + logger(logINFO) << "Init AMAC"; + std::shared_ptr<AMACv2> amac = tb->getPB(m_num); + amac->init(); + + diagSum["tests"][test++] = PBv3TestTools::runBER(amac); + if (!diagSum["tests"][test - 1]["passed"]) { + m_passCom = false; + logger(logERROR) << "BER test failed for pb " << m_num + << ". AMAC read/write not working. Will not " + "perform full test on this board."; + } + } else { + m_passCom = false; + logger(logERROR) << "PADID test failed for pb " << m_num + << ". AMAC read/write not working. Will not perform " + "full test on this board."; } - // Save output - diagSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + // Save output + diagSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - m_passAlive=true; - for(const auto& test : diagSum["tests"]) - m_passAlive &= test.value<bool>("passed", false); + m_passAlive = true; + for (const auto& test : diagSum["tests"]) + m_passAlive &= test.value<bool>("passed", false); - return diagSum; + return diagSum; } -nlohmann::json PBv3QCFlow::runTuning(std::shared_ptr<PBv3TB> tb) -{ - m_config.clear(); - m_config["component"]=m_serial; +nlohmann::json PBv3QCFlow::runTuning(std::shared_ptr<PBv3TB> tb) { + m_config.clear(); + m_config["component"] = m_serial; - if(!m_passCom) - { - logger(logWARNING) << "### Skip tuning of powerboard " << m_num << " ###"; - return m_config; + if (!m_passCom) { + logger(logWARNING) << "### Skip tuning of powerboard " << m_num + << " ###"; + return m_config; } - logger(logINFO) << "### Tuning powerboard " << m_num << " ###"; + logger(logINFO) << "### Tuning powerboard " << m_num << " ###"; - std::shared_ptr<AMACv2> amac=tb->getPB(m_num); + std::shared_ptr<AMACv2> amac = tb->getPB(m_num); - m_config.merge_patch(PBv3ConfigTools::tuneVDDBG (amac)); - m_config.merge_patch(PBv3ConfigTools::tuneAMBG (amac, tb->getCalDAC())); - m_config.merge_patch(PBv3ConfigTools::tuneRampGain (amac, tb->getCalDAC())); - m_config.merge_patch(PBv3ConfigTools::tuneCur10V (amac)); - m_config.merge_patch(PBv3ConfigTools::tuneCur1V (amac)); - m_config.merge_patch(PBv3ConfigTools::calibrateNTC (amac)); - m_config.merge_patch(PBv3ConfigTools::calibrateSlope (amac, tb->getCalDAC())); - m_config.merge_patch(PBv3ConfigTools::calibrateOffset(amac)); + m_config.merge_patch(PBv3ConfigTools::tuneVDDBG(amac)); + m_config.merge_patch(PBv3ConfigTools::tuneAMBG(amac, tb->getCalDAC())); + m_config.merge_patch(PBv3ConfigTools::tuneRampGain(amac, tb->getCalDAC())); + m_config.merge_patch(PBv3ConfigTools::tuneCur10V(amac)); + m_config.merge_patch(PBv3ConfigTools::tuneCur1V(amac)); + m_config.merge_patch(PBv3ConfigTools::calibrateNTC(amac)); + m_config.merge_patch( + PBv3ConfigTools::calibrateSlope(amac, tb->getCalDAC())); + m_config.merge_patch(PBv3ConfigTools::calibrateOffset(amac)); - PBv3ConfigTools::configAMAC(amac, m_config, false); - PBv3ConfigTools::saveConfigAMAC(amac, m_config); - amac->initRegisters(); + PBv3ConfigTools::configAMAC(amac, m_config, false); + PBv3ConfigTools::saveConfigAMAC(amac, m_config); + amac->initRegisters(); - PBv3ConfigTools::decorateConfig(m_config); + PBv3ConfigTools::decorateConfig(m_config); - return m_config; + return m_config; } -json PBv3QCFlow::runBasicTests(std::shared_ptr<PBv3TB> tb) -{ - m_passBasic=false; - - // Output structure - json testSum; - testSum["pbNum"] = m_num; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - if(!m_passCom) - { - logger(logWARNING) << "### Skip basic tests for powerboard " << m_num << " ###"; - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - return testSum; +json PBv3QCFlow::runBasicTests(std::shared_ptr<PBv3TB> tb) { + m_passBasic = false; + + // Output structure + json testSum; + testSum["pbNum"] = m_num; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + if (!m_passCom) { + logger(logWARNING) << "### Skip basic tests for powerboard " << m_num + << " ###"; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + return testSum; } - // Run tuning if needed - if(!m_config.contains("properties")) - runTuning(tb); - testSum["config"] = m_config; + // Run tuning if needed + if (!m_config.contains("properties")) runTuning(tb); + testSum["config"] = m_config; - std::cout << std::endl; - logger(logINFO) << "### Performing basic tests on powerboard " << m_num << " ###"; + std::cout << std::endl; + logger(logINFO) << "### Performing basic tests on powerboard " << m_num + << " ###"; - std::shared_ptr<AMACv2> amac=tb->getPB(m_num); + std::shared_ptr<AMACv2> amac = tb->getPB(m_num); - // Output structure - uint32_t test=0; + // Output structure + uint32_t test = 0; - // The tests - testSum["tests"][test++]=PBv3TestTools::toggleOutput(m_num, tb); - testSum["tests"][test++]=PBv3TestTools::testDCDCAdj(m_num, tb); - testSum["tests"][test++]=PBv3TestTools::temperature (amac ); + // The tests + testSum["tests"][test++] = PBv3TestTools::toggleOutput(m_num, tb); + testSum["tests"][test++] = PBv3TestTools::testDCDCAdj(m_num, tb); + testSum["tests"][test++] = PBv3TestTools::temperature(amac); - testSum["tests"][test++]=PBv3TestTools::testLvEnable(m_num, tb); - m_passLV=testSum["tests"][test-1]["passed"]; + testSum["tests"][test++] = PBv3TestTools::testLvEnable(m_num, tb); + m_passLV = testSum["tests"][test - 1]["passed"]; - if(m_doHV) - { - testSum["tests"][test++]=PBv3TestTools::testHvEnable(m_num, tb); - m_passHV=testSum["tests"][test-1]["passed"]; - } - else - { - m_passHV=false; + if (m_doHV) { + testSum["tests"][test++] = PBv3TestTools::testHvEnable(m_num, tb); + m_passHV = testSum["tests"][test - 1]["passed"]; + } else { + m_passHV = false; } - // Save output - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + // Save output + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - m_passBasic=true; - for(const auto& test : testSum["tests"]) - m_passBasic &= test.value<bool>("passed", false); + m_passBasic = true; + for (const auto& test : testSum["tests"]) + m_passBasic &= test.value<bool>("passed", false); - return testSum; + return testSum; } -nlohmann::json PBv3QCFlow::runAdvancedTests(std::shared_ptr<PBv3TB> tb) -{ - // Output structure - json testSum; - testSum["pbNum"] = m_num; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - if(!m_passCom) - { - logger(logWARNING) << "### Skip advanced tests for powerboard " << m_num << " ###"; - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - return testSum; +nlohmann::json PBv3QCFlow::runAdvancedTests(std::shared_ptr<PBv3TB> tb) { + // Output structure + json testSum; + testSum["pbNum"] = m_num; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + if (!m_passCom) { + logger(logWARNING) << "### Skip advanced tests for powerboard " << m_num + << " ###"; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + return testSum; } - - // Run tuning if needed - if(!m_config.contains("properties")) - runTuning(tb); - testSum["config"] = m_config; - - logger(logINFO) << "### Performing advanced tests on powerboard " << m_num << " ###"; - - std::shared_ptr<AMACv2> amac=tb->getPB(m_num); - - // Start testing - uint32_t test=0; - - testSum["tests"][test++] = PBv3TestTools::calibVinResponse(amac, tb->getLVPS()); - if(m_passHV) - testSum["tests"][test++] = PBv3TestTools::measureHvSense (m_num, tb); - if(m_passLV) - testSum["tests"][test++] = PBv3TestTools::measureEfficiency(m_num, tb, 0.1, 0.0, 3.6); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACoffset(amac, false); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACslope (m_num, tb, 0.01, false); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACCur10V(m_num, tb, 10); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACCur1V (m_num, tb, 10); - testSum["tests"][test++] = PBv3TestTools::temperatureNTC (amac); - testSum["tests"][test++] = PBv3TestTools::temperatureCTAT(amac); - - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - return testSum; + + // Run tuning if needed + if (!m_config.contains("properties")) runTuning(tb); + testSum["config"] = m_config; + + logger(logINFO) << "### Performing advanced tests on powerboard " << m_num + << " ###"; + + std::shared_ptr<AMACv2> amac = tb->getPB(m_num); + + // Start testing + uint32_t test = 0; + + testSum["tests"][test++] = + PBv3TestTools::calibVinResponse(amac, tb->getLVPS()); + if (m_passHV) + testSum["tests"][test++] = PBv3TestTools::measureHvSense(m_num, tb); + if (m_passLV) + testSum["tests"][test++] = + PBv3TestTools::measureEfficiency(m_num, tb, 0.1, 0.0, 3.6); + testSum["tests"][test++] = PBv3TestTools::calibrateAMACoffset(amac, false); + testSum["tests"][test++] = + PBv3TestTools::calibrateAMACslope(m_num, tb, 0.01, false); + testSum["tests"][test++] = + PBv3TestTools::calibrateAMACCur10V(m_num, tb, 10); + testSum["tests"][test++] = PBv3TestTools::calibrateAMACCur1V(m_num, tb, 10); + testSum["tests"][test++] = PBv3TestTools::temperatureNTC(amac); + testSum["tests"][test++] = PBv3TestTools::temperatureCTAT(amac); + + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + return testSum; } diff --git a/pbv3/PBv3QCFlow.h b/pbv3/PBv3QCFlow.h index cfba8ee7f05987b347393ffefd6cf4ee2508520c..8edf64a3ec6d9d976fea84a0bee4ee2e1525d4de 100644 --- a/pbv3/PBv3QCFlow.h +++ b/pbv3/PBv3QCFlow.h @@ -2,9 +2,8 @@ #define PBV3QCFLOW_H #include <memory> -#include <string> - #include <nlohmann/json.hpp> +#include <string> #include "PBv3TB.h" @@ -15,8 +14,8 @@ * - position in the test system * - serial number * - pass status of key tests - * - * The pass status of key tests (linPOL, BER, LV and HV) is used to + * + * The pass status of key tests (linPOL, BER, LV and HV) is used to * decide which subsequent tests to run in the QC flow. * * The class does not save any results to a file. Instead JSON objects @@ -24,145 +23,143 @@ * then be decorated with test run information and saved to the right location * by the calling program. */ -class PBv3QCFlow -{ -public: - /** - * \param pbNum Powerboard position on a panel - * \param doHV Enable running tests involving the HV power supply - */ - PBv3QCFlow(uint8_t num=0, bool doHV=true); - - //! \brief Get position of Powerboard on panel - uint8_t num() const; - - - //! \brief Get serial number - std::string serial() const; - - //! \brief Set serial number - void setSerial(const std::string& serial); - - // - // Test runners - - //! \brief Runs a set of tests to check whether Powerboards are alive - /** - * An "alive" Powerboard requires a working linPOL and reliable - * communication with the AMAC chap. - * - * The alive set of tests is defined as follows: - * 1) Check if linPOL voltage is correct - * - Stop on error - * 2) Check that the AMAC ID is correct - * 3) Check that communication with AMAC is OK via BER - * - Stop on error - * - * This test should be run before any other tests as it - * determine whether they can be run reliably. - * - * \param tb Testbench for controlling the powerboards - * - * \return Test result in json format. - */ - nlohmann::json runAliveTests(std::shared_ptr<PBv3TB> tb); - - //! \brief Runs a set of tests to check basic functionality of a Powerboard - /** - * No tests are run if the BER test failed during basic tests. - * - * The basic set of tests is defined as follows: - * 1) Test output of all pads - * 2) Test DC/DC output voltage - * - Record problem with LV on error - * 3) Test toggling of HVmux - * - Record problem with HV on error - * - * Tuning of the AMACv2 will be run, if necessary. - * - * This test should be run before any advanced functionality - * tests as it enables/disables advanced LV/HV tests based - * on their basic functionality check. By default, they are - * disabled. - * - * HV tests can be disabled by `doHV`. - * - * \param tb Testbench for controlling the powerboards - * - * \return Test result in json format. - */ - nlohmann::json runBasicTests(std::shared_ptr<PBv3TB> tb); - - //! \brief Runs a set of tests to character the powerboard - /** - * No tests are run if the BER test failed during basic tests. - * - * The following set of tests is rung: - * 1) Vin response scan - * 2) (if HV basic test passed) HV scan - * 3) (if LV basic test passed) DC/DC efficiency scan - * 4) AMAC AM offset - * 5) AMAC AM slope - * 6) AMAC AM Cur10V monitor - * 7) AMAC AM Cur1V monitor - * - * Tuning of the AMACv2 will be run, if necessary. - * - * \param tb Testbench for controlling the powerboards - * - * \return Test result in json format. - */ - nlohmann::json runAdvancedTests(std::shared_ptr<PBv3TB> tb); - - //! \brief Tune the powerboard settings - /** - * No tests are run if the BER test failed during basic tests. - * - * The tuning is also saved in the PBv3QCFlow instance and - * appended to any test results. - * - * \param tb Testbench for controlling the powerboards - * - * \return Configuration file in json format - */ - nlohmann::json runTuning(std::shared_ptr<PBv3TB> tb); - -private: - // - // Test configuration - - //! \brief Powerboard position on test panel - uint32_t m_num=0; - - //! \brief Run HV tests - bool m_doHV=true; - - //! \brief Serial number of powerboard - std::string m_serial; - - // - // Test pass information - - //! \brief Last available AMAC configuration - nlohmann::json m_config; - - //! \brief Passed alive funtionality tests - bool m_passAlive=false; - - //! \brief Passed basic funtionality tests - bool m_passBasic=false; - - //! \brief Passed OF test (AMAC is alive) - bool m_passOF=false; - - //! \brief Passed communication test (BER and PADID) - bool m_passCom=false; - - //! \brief Passed LV test - bool m_passLV=false; - - //! \brief Passed HV test - bool m_passHV=false; +class PBv3QCFlow { + public: + /** + * \param pbNum Powerboard position on a panel + * \param doHV Enable running tests involving the HV power supply + */ + PBv3QCFlow(uint8_t num = 0, bool doHV = true); + + //! \brief Get position of Powerboard on panel + uint8_t num() const; + + //! \brief Get serial number + std::string serial() const; + + //! \brief Set serial number + void setSerial(const std::string& serial); + + // + // Test runners + + //! \brief Runs a set of tests to check whether Powerboards are alive + /** + * An "alive" Powerboard requires a working linPOL and reliable + * communication with the AMAC chap. + * + * The alive set of tests is defined as follows: + * 1) Check if linPOL voltage is correct + * - Stop on error + * 2) Check that the AMAC ID is correct + * 3) Check that communication with AMAC is OK via BER + * - Stop on error + * + * This test should be run before any other tests as it + * determine whether they can be run reliably. + * + * \param tb Testbench for controlling the powerboards + * + * \return Test result in json format. + */ + nlohmann::json runAliveTests(std::shared_ptr<PBv3TB> tb); + + //! \brief Runs a set of tests to check basic functionality of a Powerboard + /** + * No tests are run if the BER test failed during basic tests. + * + * The basic set of tests is defined as follows: + * 1) Test output of all pads + * 2) Test DC/DC output voltage + * - Record problem with LV on error + * 3) Test toggling of HVmux + * - Record problem with HV on error + * + * Tuning of the AMACv2 will be run, if necessary. + * + * This test should be run before any advanced functionality + * tests as it enables/disables advanced LV/HV tests based + * on their basic functionality check. By default, they are + * disabled. + * + * HV tests can be disabled by `doHV`. + * + * \param tb Testbench for controlling the powerboards + * + * \return Test result in json format. + */ + nlohmann::json runBasicTests(std::shared_ptr<PBv3TB> tb); + + //! \brief Runs a set of tests to character the powerboard + /** + * No tests are run if the BER test failed during basic tests. + * + * The following set of tests is rung: + * 1) Vin response scan + * 2) (if HV basic test passed) HV scan + * 3) (if LV basic test passed) DC/DC efficiency scan + * 4) AMAC AM offset + * 5) AMAC AM slope + * 6) AMAC AM Cur10V monitor + * 7) AMAC AM Cur1V monitor + * + * Tuning of the AMACv2 will be run, if necessary. + * + * \param tb Testbench for controlling the powerboards + * + * \return Test result in json format. + */ + nlohmann::json runAdvancedTests(std::shared_ptr<PBv3TB> tb); + + //! \brief Tune the powerboard settings + /** + * No tests are run if the BER test failed during basic tests. + * + * The tuning is also saved in the PBv3QCFlow instance and + * appended to any test results. + * + * \param tb Testbench for controlling the powerboards + * + * \return Configuration file in json format + */ + nlohmann::json runTuning(std::shared_ptr<PBv3TB> tb); + + private: + // + // Test configuration + + //! \brief Powerboard position on test panel + uint32_t m_num = 0; + + //! \brief Run HV tests + bool m_doHV = true; + + //! \brief Serial number of powerboard + std::string m_serial; + + // + // Test pass information + + //! \brief Last available AMAC configuration + nlohmann::json m_config; + + //! \brief Passed alive funtionality tests + bool m_passAlive = false; + + //! \brief Passed basic funtionality tests + bool m_passBasic = false; + + //! \brief Passed OF test (AMAC is alive) + bool m_passOF = false; + + //! \brief Passed communication test (BER and PADID) + bool m_passCom = false; + + //! \brief Passed LV test + bool m_passLV = false; + + //! \brief Passed HV test + bool m_passHV = false; }; -#endif // PBV3QCFLOW_H +#endif // PBV3QCFLOW_H diff --git a/pbv3/PBv3TB.cpp b/pbv3/PBv3TB.cpp index 9acd9ee696e69843e96968cc5d77868ea239fdc8..2ffa786d2cf14b303c056a72416b2e57271b032f 100644 --- a/pbv3/PBv3TB.cpp +++ b/pbv3/PBv3TB.cpp @@ -2,64 +2,40 @@ #include <stdexcept> -PBv3TB::PBv3TB() -{ } +PBv3TB::PBv3TB() {} -PBv3TB::~PBv3TB() -{ } +PBv3TB::~PBv3TB() {} -void PBv3TB::setConfiguration(const nlohmann::json& config) -{ } +void PBv3TB::setConfiguration(const nlohmann::json& config) {} -void PBv3TB::setCalDAC(std::shared_ptr<DACDevice> CalDAC) -{ m_CalDAC=CalDAC; } +void PBv3TB::setCalDAC(std::shared_ptr<DACDevice> CalDAC) { m_CalDAC = CalDAC; } -std::shared_ptr<DACDevice> PBv3TB::getCalDAC() -{ return m_CalDAC; } +std::shared_ptr<DACDevice> PBv3TB::getCalDAC() { return m_CalDAC; } -void PBv3TB::setLVPS(std::shared_ptr<PowerSupplyChannel> ps) -{ m_lv=ps; } +void PBv3TB::setLVPS(std::shared_ptr<PowerSupplyChannel> ps) { m_lv = ps; } -std::shared_ptr<PowerSupplyChannel> PBv3TB::getLVPS() -{ return m_lv; } +std::shared_ptr<PowerSupplyChannel> PBv3TB::getLVPS() { return m_lv; } -void PBv3TB::setHVPS(std::shared_ptr<PowerSupplyChannel> ps) -{ m_hv=ps; } +void PBv3TB::setHVPS(std::shared_ptr<PowerSupplyChannel> ps) { m_hv = ps; } -std::shared_ptr<PowerSupplyChannel> PBv3TB::getHVPS() -{ return m_hv; } +std::shared_ptr<PowerSupplyChannel> PBv3TB::getHVPS() { return m_hv; } -void PBv3TB::powerLVOn() -{ - m_lv->setVoltageLevel(11.0); - m_lv->setCurrentProtect(2.0); - m_lv->turnOn(); +void PBv3TB::powerLVOn() { + m_lv->setVoltageLevel(11.0); + m_lv->setCurrentProtect(2.0); + m_lv->turnOn(); } -void PBv3TB::powerLVOff() -{ - m_lv->turnOff(); -} +void PBv3TB::powerLVOff() { m_lv->turnOff(); } -void PBv3TB::setVin(double Vout) -{ - m_lv->setVoltageLevel(Vout); -} +void PBv3TB::setVin(double Vout) { m_lv->setVoltageLevel(Vout); } -double PBv3TB::getVinCurrent() -{ - return m_lv->measureCurrent(); -} - -void PBv3TB::powerHVOn() -{ - m_hv->setCurrentLevel(1e-3); - m_hv->setVoltageProtect(500); - m_hv->turnOn(); -} +double PBv3TB::getVinCurrent() { return m_lv->measureCurrent(); } -void PBv3TB::powerHVOff() -{ - m_hv->turnOff(); +void PBv3TB::powerHVOn() { + m_hv->setCurrentLevel(1e-3); + m_hv->setVoltageProtect(500); + m_hv->turnOn(); } +void PBv3TB::powerHVOff() { m_hv->turnOff(); } diff --git a/pbv3/PBv3TB.h b/pbv3/PBv3TB.h index 0f61cc67957eb19a201b25e8fa4b338886c7610b..8114cce59e1e5ae8cf28bec96bf8e38134ef275e 100644 --- a/pbv3/PBv3TB.h +++ b/pbv3/PBv3TB.h @@ -1,16 +1,15 @@ #ifndef PBV3TB_H #define PBV3TB_H -#include <memory> - #include <DACDevice.h> -#include "AMACv2.h" +#include <memory> -#include "Logger.h" +#include "AMACv2.h" #include "EquipConf.h" +#include "Logger.h" -//! An abstract description of a Powerboard testbench. +//! An abstract description of a Powerboard testbench. /** * A testbench consists of * - low voltage power supply @@ -18,169 +17,170 @@ * - N loads connected to powerboards * - N powerboards */ -class PBv3TB -{ -public: - //! \brief Possible outputs of the carrier card on the common analogue output value bus - enum CARRIER_OUTPUT { - LINPOL1V4=0, - LINPOL3V3=1, - VOUT =11, - OFout =8, - LDx0EN =9, - LDx1EN =12, - LDx2EN =13, - HRSTBx =10, - SHUNTx =14, - CALx =15, - LDy0EN =7, - LDy1EN =5, - LDy2EN =4, - HRSTBy =6, - CALy =2, - SHUNTy =3 - }; - - /* - * Constructor - */ - PBv3TB(); - - /* - * Destructor - */ - virtual ~PBv3TB(); - - /** \name Initialization functions - * @{ */ - - /** \brief Store JSON hardware configuration - * - * \param config JSON configuration for the given testbench - */ - virtual void setConfiguration(const nlohmann::json& config); - - /** \brief Initialize testbench - * - * Initialize communication and control of the testbench. - * - * This function should only perform initialization necessary to communicate - * with the testbench. The state should not be reset to allow reading from an - * already active testbench. - */ - virtual void init() =0; - - /** @} */ - - /** \name Control functions - * Control and measurements of the lower voltage power input - * @{ - */ - - //! \brief Return communication object for powerboard pbNum - virtual std::shared_ptr<AMACv2> getPB(uint8_t pbNum) =0; - - //! \brief Return the DAC object driving the CAL line - std::shared_ptr<DACDevice> getCalDAC(); - - //! \brief Set the OFin for a board - virtual void setOFin(uint8_t pbNum, bool value) =0; - - //! \brief Get multiplexer values - virtual double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value) =0; - - /** @} */ - - /** \name Low Voltage - * Control and measurements of the lower voltage power input - * @{ - */ - - //! \brief Set the the low voltage power supply object - void setLVPS(std::shared_ptr<PowerSupplyChannel> ps); - - //! \brief Get the low voltage power supply object - std::shared_ptr<PowerSupplyChannel> getLVPS(); - - //! \brief Get voltage on the low voltage (V) power supply - virtual double getVin() =0; - - /** \brief Enable LV power - * - * Output set is set to 11V with 2A current protect. - */ - void powerLVOn(); - - //! \brief Disable LV power - void powerLVOff(); - - //! \brief Get current (A) supplied by the low voltage power supply - double getVinCurrent(); - - //! \brief Set voltage on the low voltage (V) power supply - void setVin(double Vin); - - /** @} */ - - /** \name Variable Load - * Control and measurement of the DC/DC load - * @{ - */ - - //! \brief Enable load for PB pbNum - virtual void loadOn(uint8_t pbNum) =0; - - //! \brief Disable load for PB pbNum - virtual void loadOff(uint8_t pbNum) =0; - - //! \brief Set load on PB pbNum to load Amps - virtual double setLoad(uint8_t pbNum, double load) =0; - - //! \brief Get load on PB pbNum - virtual double getLoad(uint8_t pbNum) =0; - - //! \brief Get PB pbNum DC/DC converter output value - virtual double getVout(uint8_t pbNum) =0; - - //! \brief Get loaded current - virtual double getIload(uint8_t pbNum) =0; - - /** @} */ - - /** \name High Voltage - * Control and measurements of the high voltage - * @{ - */ - - //! \brief Set the high voltage power supply object - void setHVPS(std::shared_ptr<PowerSupplyChannel> ps); - - //! \brief Get the high voltage power supply object - std::shared_ptr<PowerSupplyChannel> getHVPS(); - - /** \brief Enable HV power - * - * Output set is set to 1mA, with 500V voltage protect - */ - virtual void powerHVOn(); - - //! \brief Disable HV power - virtual void powerHVOff(); - - //! \brief Get PB pbNum HV output current - virtual double getHVoutCurrent(uint8_t pbNum) =0; - - /** @} */ - -protected: - //! \brief Set the CAL DAC device - void setCalDAC(std::shared_ptr<DACDevice> CalDAC); - -private: - std::shared_ptr<DACDevice> m_CalDAC; - - std::shared_ptr<PowerSupplyChannel> m_lv =nullptr; - std::shared_ptr<PowerSupplyChannel> m_hv =nullptr; +class PBv3TB { + public: + //! \brief Possible outputs of the carrier card on the common analogue + //! output value bus + enum CARRIER_OUTPUT { + LINPOL1V4 = 0, + LINPOL3V3 = 1, + VOUT = 11, + OFout = 8, + LDx0EN = 9, + LDx1EN = 12, + LDx2EN = 13, + HRSTBx = 10, + SHUNTx = 14, + CALx = 15, + LDy0EN = 7, + LDy1EN = 5, + LDy2EN = 4, + HRSTBy = 6, + CALy = 2, + SHUNTy = 3 + }; + + /* + * Constructor + */ + PBv3TB(); + + /* + * Destructor + */ + virtual ~PBv3TB(); + + /** \name Initialization functions + * @{ */ + + /** \brief Store JSON hardware configuration + * + * \param config JSON configuration for the given testbench + */ + virtual void setConfiguration(const nlohmann::json& config); + + /** \brief Initialize testbench + * + * Initialize communication and control of the testbench. + * + * This function should only perform initialization necessary to communicate + * with the testbench. The state should not be reset to allow reading from + * an already active testbench. + */ + virtual void init() = 0; + + /** @} */ + + /** \name Control functions + * Control and measurements of the lower voltage power input + * @{ + */ + + //! \brief Return communication object for powerboard pbNum + virtual std::shared_ptr<AMACv2> getPB(uint8_t pbNum) = 0; + + //! \brief Return the DAC object driving the CAL line + std::shared_ptr<DACDevice> getCalDAC(); + + //! \brief Set the OFin for a board + virtual void setOFin(uint8_t pbNum, bool value) = 0; + + //! \brief Get multiplexer values + virtual double readCarrierOutput(uint32_t pbNum, + PBv3TB::CARRIER_OUTPUT value) = 0; + + /** @} */ + + /** \name Low Voltage + * Control and measurements of the lower voltage power input + * @{ + */ + + //! \brief Set the the low voltage power supply object + void setLVPS(std::shared_ptr<PowerSupplyChannel> ps); + + //! \brief Get the low voltage power supply object + std::shared_ptr<PowerSupplyChannel> getLVPS(); + + //! \brief Get voltage on the low voltage (V) power supply + virtual double getVin() = 0; + + /** \brief Enable LV power + * + * Output set is set to 11V with 2A current protect. + */ + void powerLVOn(); + + //! \brief Disable LV power + void powerLVOff(); + + //! \brief Get current (A) supplied by the low voltage power supply + double getVinCurrent(); + + //! \brief Set voltage on the low voltage (V) power supply + void setVin(double Vin); + + /** @} */ + + /** \name Variable Load + * Control and measurement of the DC/DC load + * @{ + */ + + //! \brief Enable load for PB pbNum + virtual void loadOn(uint8_t pbNum) = 0; + + //! \brief Disable load for PB pbNum + virtual void loadOff(uint8_t pbNum) = 0; + + //! \brief Set load on PB pbNum to load Amps + virtual double setLoad(uint8_t pbNum, double load) = 0; + + //! \brief Get load on PB pbNum + virtual double getLoad(uint8_t pbNum) = 0; + + //! \brief Get PB pbNum DC/DC converter output value + virtual double getVout(uint8_t pbNum) = 0; + + //! \brief Get loaded current + virtual double getIload(uint8_t pbNum) = 0; + + /** @} */ + + /** \name High Voltage + * Control and measurements of the high voltage + * @{ + */ + + //! \brief Set the high voltage power supply object + void setHVPS(std::shared_ptr<PowerSupplyChannel> ps); + + //! \brief Get the high voltage power supply object + std::shared_ptr<PowerSupplyChannel> getHVPS(); + + /** \brief Enable HV power + * + * Output set is set to 1mA, with 500V voltage protect + */ + virtual void powerHVOn(); + + //! \brief Disable HV power + virtual void powerHVOff(); + + //! \brief Get PB pbNum HV output current + virtual double getHVoutCurrent(uint8_t pbNum) = 0; + + /** @} */ + + protected: + //! \brief Set the CAL DAC device + void setCalDAC(std::shared_ptr<DACDevice> CalDAC); + + private: + std::shared_ptr<DACDevice> m_CalDAC; + + std::shared_ptr<PowerSupplyChannel> m_lv = nullptr; + std::shared_ptr<PowerSupplyChannel> m_hv = nullptr; }; -#endif // PBV3TB_H +#endif // PBV3TB_H diff --git a/pbv3/PBv3TBConf.cpp b/pbv3/PBv3TBConf.cpp index 564455b349d37a95d14fbde4f6ba3313e97612f9..04403810b3d1801ddf5d7e21f0bfe041644d5caa 100644 --- a/pbv3/PBv3TBConf.cpp +++ b/pbv3/PBv3TBConf.cpp @@ -11,92 +11,83 @@ // Configuration //////////////////// -PBv3TBConf::PBv3TBConf() -{ } +PBv3TBConf::PBv3TBConf() {} -PBv3TBConf::~PBv3TBConf() -{ } +PBv3TBConf::~PBv3TBConf() {} -PBv3TBConf::PBv3TBConf(const std::string& hardwareConfigFile) -{ - setHardwareConfig(hardwareConfigFile); +PBv3TBConf::PBv3TBConf(const std::string& hardwareConfigFile) { + setHardwareConfig(hardwareConfigFile); } -PBv3TBConf::PBv3TBConf(const json& hardwareConfig) -{ - setHardwareConfig(hardwareConfig); +PBv3TBConf::PBv3TBConf(const json& hardwareConfig) { + setHardwareConfig(hardwareConfig); } -void PBv3TBConf::setHardwareConfig(const std::string& hardwareConfigFile) -{ - //load JSON object from file - std::ifstream i(hardwareConfigFile); - if(i.is_open()) - i >> m_hardwareConfig; - else - { logger(logERROR) << "Unable to open hardware config: " << hardwareConfigFile; } +void PBv3TBConf::setHardwareConfig(const std::string& hardwareConfigFile) { + // load JSON object from file + std::ifstream i(hardwareConfigFile); + if (i.is_open()) + i >> m_hardwareConfig; + else { + logger(logERROR) << "Unable to open hardware config: " + << hardwareConfigFile; + } - m_hw.setHardwareConfig(m_hardwareConfig); + m_hw.setHardwareConfig(m_hardwareConfig); } -void PBv3TBConf::setHardwareConfig(const json& hardwareConfig) -{ - //store JSON config file - m_hardwareConfig = hardwareConfig; +void PBv3TBConf::setHardwareConfig(const json& hardwareConfig) { + // store JSON config file + m_hardwareConfig = hardwareConfig; - m_hw.setHardwareConfig(m_hardwareConfig); + m_hw.setHardwareConfig(m_hardwareConfig); } -json PBv3TBConf::getPBv3TBConf(const std::string& label) -{ - for (const auto& hw : m_hardwareConfig["testbenches"].items()) - { - //check label - if (hw.key() == label) return hw.value(); +json PBv3TBConf::getPBv3TBConf(const std::string& label) { + for (const auto& hw : m_hardwareConfig["testbenches"].items()) { + // check label + if (hw.key() == label) return hw.value(); } - return json(); + return json(); } //////////////////// // General private //////////////////// - -std::shared_ptr<PBv3TB> PBv3TBConf::getPBv3TB(const std::string& label) -{ - // first check if an object with the same label/type is already available (was already instantiated) - if (m_listPBv3TB.find(label) != m_listPBv3TB.end()) - return m_listPBv3TB[label]; - - // Otherwise, create the object - // check first if hardware configuration is available - json reqConf = getPBv3TBConf(label); - if (reqConf.empty()) - { - std::cerr << "Requested device not found in input configuration file: " << label << std::endl; - return nullptr; +std::shared_ptr<PBv3TB> PBv3TBConf::getPBv3TB(const std::string& label) { + // first check if an object with the same label/type is already available + // (was already instantiated) + if (m_listPBv3TB.find(label) != m_listPBv3TB.end()) + return m_listPBv3TB[label]; + + // Otherwise, create the object + // check first if hardware configuration is available + json reqConf = getPBv3TBConf(label); + if (reqConf.empty()) { + std::cerr << "Requested device not found in input configuration file: " + << label << std::endl; + return nullptr; } - // setup device - std::shared_ptr<PBv3TB> tb = PBv3TBRegistry::createPBv3TB(reqConf["type"]); + // setup device + std::shared_ptr<PBv3TB> tb = PBv3TBRegistry::createPBv3TB(reqConf["type"]); - // configure the testbench - tb->setConfiguration(reqConf); + // configure the testbench + tb->setConfiguration(reqConf); - // get low voltage - std::shared_ptr<PowerSupplyChannel> lv=m_hw.getPowerSupplyChannel("Vin"); - if(lv==nullptr) - logger(logWARNING) << "No LV power supply available!"; - tb->setLVPS(lv); + // get low voltage + std::shared_ptr<PowerSupplyChannel> lv = m_hw.getPowerSupplyChannel("Vin"); + if (lv == nullptr) logger(logWARNING) << "No LV power supply available!"; + tb->setLVPS(lv); - // get high voltage - std::shared_ptr<PowerSupplyChannel> hv=m_hw.getPowerSupplyChannel("HVin"); - if(hv==nullptr) - logger(logWARNING) << "No HV power supply available!"; - tb->setHVPS(hv); + // get high voltage + std::shared_ptr<PowerSupplyChannel> hv = m_hw.getPowerSupplyChannel("HVin"); + if (hv == nullptr) logger(logWARNING) << "No HV power supply available!"; + tb->setHVPS(hv); - // initialize it - tb->init(); + // initialize it + tb->init(); - return tb; + return tb; } diff --git a/pbv3/PBv3TBConf.h b/pbv3/PBv3TBConf.h index 8365e3e9ff39d5473078e98c2c9dd8fcd295964f..fb1d6e1ee46dbe73fa0220d9d6fcc92af2e91f82 100644 --- a/pbv3/PBv3TBConf.h +++ b/pbv3/PBv3TBConf.h @@ -1,12 +1,11 @@ #ifndef PBV3TBCONF_H #define PBV3TBCONF_H -#include <string> -#include <unordered_map> +#include <EquipConf.h> #include <nlohmann/json.hpp> - -#include <EquipConf.h> +#include <string> +#include <unordered_map> using json = nlohmann::json; @@ -22,73 +21,75 @@ using json = nlohmann::json; * and associating PowerSupplyChannel objects to the testbenches. Currently, * the Vin and HVin channels are added to all testbenches. */ -class PBv3TBConf -{ -public: - /** Configuration @{ */ - - /** Constructor */ - PBv3TBConf(); - - /** Constructor - * \param hardwareConfigFile input JSON file with list of hardware resources and options - */ - PBv3TBConf(const std::string& hardwareConfigFile); - - /** Constructor - * \param hardwareConfig JSON object with list of hardware sources and options - */ - PBv3TBConf(const json& hardwareConfig); - - ~PBv3TBConf(); - - /** Set input hardware list file - * \param hardwareConfigFile input JSON file with list of hardware resources and options - */ - void setHardwareConfig(const std::string& hardwareConfigFile); - - /** Set input hardware list file - * \param hardwareConfig input JSON object with list of hardware resources and options - */ - void setHardwareConfig(const json& hardwareConfig); - - /** Get testbench JSON configuration - \param label testbench name - \return device JSON configuration (by reference) - */ - json getPBv3TBConf(const std::string& label); - - /** @} */ - -public: - /** Get (or create) testbenches (by label) - * @{ - */ - - /** Get PBv3TB object corresponding to name - * - * If this is the first time the testbench is requested: - * 1. Create the testbench - * 2. Configure the testbench - * 3. Initialize the testbench - * - * \param name label for the hardware object in JSON configuration file - */ - std::shared_ptr<PBv3TB> getPBv3TB(const std::string& name); - - /** @} */ - -private: - - //! JSON file with hardware list and options (see example input-hw.json file for syntax) - json m_hardwareConfig; - - //! Power supply factory - EquipConf m_hw; - - //! Stored handles of IPowerSupply pointers created - std::unordered_map<std::string, std::shared_ptr<PBv3TB>> m_listPBv3TB; - +class PBv3TBConf { + public: + /** Configuration @{ */ + + /** Constructor */ + PBv3TBConf(); + + /** Constructor + * \param hardwareConfigFile input JSON file with list of hardware resources + * and options + */ + PBv3TBConf(const std::string& hardwareConfigFile); + + /** Constructor + * \param hardwareConfig JSON object with list of hardware sources and + * options + */ + PBv3TBConf(const json& hardwareConfig); + + ~PBv3TBConf(); + + /** Set input hardware list file + * \param hardwareConfigFile input JSON file with list of hardware resources + * and options + */ + void setHardwareConfig(const std::string& hardwareConfigFile); + + /** Set input hardware list file + * \param hardwareConfig input JSON object with list of hardware resources + * and options + */ + void setHardwareConfig(const json& hardwareConfig); + + /** Get testbench JSON configuration + \param label testbench name + \return device JSON configuration (by reference) + */ + json getPBv3TBConf(const std::string& label); + + /** @} */ + + public: + /** Get (or create) testbenches (by label) + * @{ + */ + + /** Get PBv3TB object corresponding to name + * + * If this is the first time the testbench is requested: + * 1. Create the testbench + * 2. Configure the testbench + * 3. Initialize the testbench + * + * \param name label for the hardware object in JSON configuration file + */ + std::shared_ptr<PBv3TB> getPBv3TB(const std::string& name); + + /** @} */ + + private: + //! JSON file with hardware list and options (see example input-hw.json file + //! for syntax) + json m_hardwareConfig; + + //! Power supply factory + EquipConf m_hw; + + //! Stored handles of IPowerSupply pointers created + std::unordered_map<std::string, std::shared_ptr<PBv3TB>> m_listPBv3TB; }; #endif diff --git a/pbv3/PBv3TBDummy.h b/pbv3/PBv3TBDummy.h index 2b1da2d02522bb7710517a7c5a2effd179737fc1..2f6c3d558db7681dc352483819ed05f9cf27bbe0 100644 --- a/pbv3/PBv3TBDummy.h +++ b/pbv3/PBv3TBDummy.h @@ -1,18 +1,19 @@ #ifndef PBV3TBDUMMY_H #define PBV3TBDUMMY_H -#include <memory> +#include <OutOfRangeException.h> -#include "PBv3TB.h" +#include <memory> #include "Logger.h" -#include <OutOfRangeException.h> +#include "PBv3TB.h" #define DUMMY_DOUBLE 0. -#define DUMMY_METHOD(name, return_statement) \ - logger(logWARNING) << "Method " #name " is not setup for dummy testbench."; \ - return_statement; +#define DUMMY_METHOD(name, return_statement) \ + logger(logWARNING) << "Method " #name \ + " is not setup for dummy testbench."; \ + return_statement; /** \brief Abstract Class for dummy testbenches that contain only AMAC. * @@ -20,57 +21,56 @@ * All other methods return some pre-defined values. */ -class PBv3TBDummy : public PBv3TB -{ -public: - /** - * Constructor - */ - PBv3TBDummy() : PBv3TB() {}; +class PBv3TBDummy : public PBv3TB { + public: + /** + * Constructor + */ + PBv3TBDummy() : PBv3TB(){}; - virtual ~PBv3TBDummy() {}; + virtual ~PBv3TBDummy(){}; + /** \brief Initialize testbench + * + * Initialize your PB communication object of AMACv2 class. + */ + virtual void init() = 0; - /** \brief Initialize testbench - * - * Initialize your PB communication object of AMACv2 class. - */ - virtual void init() = 0; + std::shared_ptr<AMACv2> getPB(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); + return m_pb; + } - std::shared_ptr<AMACv2> getPB(uint8_t pbNum) { - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); - return m_pb; - } + /** \brief Configure on JSON object for your PB communication object. + * + * \param config JSON configuration + */ + virtual void setConfiguration(const nlohmann::json& config){}; - /** \brief Configure on JSON object for your PB communication object. - * - * \param config JSON configuration - */ - virtual void setConfiguration(const nlohmann::json& config) {}; + // + // dummy methods - // - // dummy methods + void setOFin(uint8_t pbNum, bool value){DUMMY_METHOD(setOFin, )}; - void setOFin(uint8_t pbNum, bool value) {DUMMY_METHOD(setOFin,)}; + double getVin(){DUMMY_METHOD(getVin, return DUMMY_DOUBLE)}; + double getVout(uint8_t pbNum){DUMMY_METHOD(getVout, return DUMMY_DOUBLE)}; - double getVin() {DUMMY_METHOD(getVin, return DUMMY_DOUBLE)}; - double getVout(uint8_t pbNum) {DUMMY_METHOD(getVout, return DUMMY_DOUBLE)}; + double getIload(uint8_t pbNum){DUMMY_METHOD(getIload, return DUMMY_DOUBLE)}; - double getIload(uint8_t pbNum) {DUMMY_METHOD(getIload, return DUMMY_DOUBLE)}; + void loadOn(uint8_t pbNum){DUMMY_METHOD(loadOn, )}; + void loadOff(uint8_t pbNum){DUMMY_METHOD(loadOff, )}; + double setLoad(uint8_t pbNum, + double load){DUMMY_METHOD(setLoad, return DUMMY_DOUBLE)}; + double getLoad(uint8_t pbNum){DUMMY_METHOD(getLoad, return DUMMY_DOUBLE)}; - void loadOn(uint8_t pbNum) {DUMMY_METHOD(loadOn,)}; - void loadOff(uint8_t pbNum) {DUMMY_METHOD(loadOff,)}; - double setLoad(uint8_t pbNum, double load) {DUMMY_METHOD(setLoad, return DUMMY_DOUBLE)}; - double getLoad(uint8_t pbNum) {DUMMY_METHOD(getLoad, return DUMMY_DOUBLE)}; + double getHVoutCurrent(uint8_t pbNum){ + DUMMY_METHOD(getHVoutCurrent, return DUMMY_DOUBLE)}; - double getHVoutCurrent(uint8_t pbNum) {DUMMY_METHOD(getHVoutCurrent, return DUMMY_DOUBLE)}; + double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value){ + DUMMY_METHOD(readCarrierOutput, return DUMMY_DOUBLE)}; - double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value) {DUMMY_METHOD(readCarrierOutput, return DUMMY_DOUBLE)}; - -protected: - std::shared_ptr<AMACv2> m_pb =nullptr; // the PB communication object + protected: + std::shared_ptr<AMACv2> m_pb = nullptr; // the PB communication object }; -#endif // PBV3TBDUMMY_H - +#endif // PBV3TBDUMMY_H diff --git a/pbv3/PBv3TBMassive.cpp b/pbv3/PBv3TBMassive.cpp index 46b230cb1a551f7aa7a97505245a390642afc3b6..80ec9a380976be2c39c84c6d1fe4e940ecb8f801 100644 --- a/pbv3/PBv3TBMassive.cpp +++ b/pbv3/PBv3TBMassive.cpp @@ -1,24 +1,21 @@ #include "PBv3TBMassive.h" -#include <cmath> #include <chrono> +#include <cmath> #include <thread> -#include "Logger.h" - -#include "UIOCom.h" #include "EndeavourRawUIO.h" - #include "I2CDevCom.h" +#include "Logger.h" #include "PCA9548ACom.h" - #include "SPIDevCom.h" +#include "UIOCom.h" // ADCs #include "AD799X.h" +#include "LTC2451.h" #include "MCP3425.h" #include "MCP3428.h" -#include "LTC2451.h" // DACs #include "DAC5571.h" @@ -28,499 +25,493 @@ #include "MCP23017.h" // Multiplexers -#include "PGA11x.h" +#include <OutOfRangeException.h> -#include "LinearCalibration.h" #include "DeviceCalibration.h" #include "FileCalibration.h" +#include "LinearCalibration.h" +#include "PGA11x.h" -#include <OutOfRangeException.h> - -//Register test bench +// Register test bench #include "PBv3TBRegistry.h" REGISTER_PBV3TB(PBv3TBMassive) -PBv3TBMassive::PBv3TBMassive() - : PBv3TB() -{ } - -void PBv3TBMassive::setConfiguration(const nlohmann::json& config) -{ - for (const auto &kv : config.items()) - { - if(kv.key()=="i2cdev") - { - m_i2cdev=kv.value(); - } - } +PBv3TBMassive::PBv3TBMassive() : PBv3TB() {} - PBv3TB::setConfiguration(config); -} +void PBv3TBMassive::setConfiguration(const nlohmann::json& config) { + for (const auto& kv : config.items()) { + if (kv.key() == "i2cdev") { + m_i2cdev = kv.value(); + } + } -void PBv3TBMassive::init() -{ - initDevices(); + PBv3TB::setConfiguration(config); } -void PBv3TBMassive::initDevices() -{ - // - // Create the I2C mappings - - // Multiplexers - m_i2c_root=std::make_shared<I2CDevCom>(0x70, m_i2cdev); - - m_i2c_analogue=std::make_shared<PCA9548ACom>(0x4c, 1, m_i2c_root); - m_mux_hv=std::make_shared<PGA11x>(std::make_shared<SPIDevCom>("/dev/spidev1.0")); - - // - // ADCs - m_adc_pwr=std::make_shared<AD799X>(3.3, AD799X::AD7993, std::make_shared<PCA9548ACom>(0x21, 7, m_i2c_root)); - m_adc_lv0=std::make_shared<AD799X>(3.3, AD799X::AD7997, std::make_shared<PCA9548ACom>(0x21, 5, m_i2c_root)); - m_adc_lv1=std::make_shared<AD799X>(3.3, AD799X::AD7997, std::make_shared<PCA9548ACom>(0x22, 5, m_i2c_root)); - - m_adc_lvset0=std::make_shared<MCP3428>(std::make_shared<PCA9548ACom>(0x68, 5, m_i2c_root)); - m_adc_lvset1=std::make_shared<MCP3428>(std::make_shared<PCA9548ACom>(0x6C, 5, m_i2c_root)); - m_adc_lvset2=std::make_shared<MCP3428>(std::make_shared<PCA9548ACom>(0x6A, 5, m_i2c_root)); - - //Returns current - std::dynamic_pointer_cast<MCP3428>(m_adc_lvset0)->setGain(MCP3428::Gain::x4); - std::dynamic_pointer_cast<MCP3428>(m_adc_lvset1)->setGain(MCP3428::Gain::x4); - std::dynamic_pointer_cast<MCP3428>(m_adc_lvset2)->setGain(MCP3428::Gain::x4); - - float loadmax=2.048/4/100e-3; - m_adc_lvset0->setCalibration(std::make_shared<LinearCalibration>(loadmax, 0x7FFF)); - m_adc_lvset1->setCalibration(std::make_shared<LinearCalibration>(loadmax, 0x7FFF)); - m_adc_lvset2->setCalibration(std::make_shared<LinearCalibration>(loadmax, 0x7FFF)); - - m_adc_hv=std::make_shared<LTC2451>(3.25/3.24e3, std::make_shared<PCA9548ACom>(0x14, 0, m_i2c_root)); - - // Common PB output - m_adc_common =std::make_shared<MCP3425>(std::make_shared<PCA9548ACom>(0x68, 1, m_i2c_root)); - - m_sel_out =std::make_shared<MCP23017>(std::make_shared<PCA9548ACom>(0x20, 2, m_i2c_root)); - m_sel_of =std::make_shared<MCP23017>(std::make_shared<PCA9548ACom>(0x21, 2, m_i2c_root)); - - m_sel_of ->setIO(0x0); - m_sel_out->setIO(0x0); - - m_sel_out->write(0xFF03); // disable carrier card multiplexers (active low enable) - - // - // DACs - double maxcurr=3.25*16.9/(100+16.9)/100e-3; - m_dac_0=std::make_shared<DAC5574>(maxcurr, std::make_shared<PCA9548ACom>(0x4C, 5, m_i2c_root)); - m_dac_1=std::make_shared<DAC5574>(maxcurr, std::make_shared<PCA9548ACom>(0x4D, 5, m_i2c_root)); - m_dac_2=std::make_shared<DAC5574>(maxcurr, std::make_shared<PCA9548ACom>(0x4E, 5, m_i2c_root)); - - m_dac_0->setCalibration(std::make_shared<LinearCalibration>(maxcurr,0xFF)); - m_dac_1->setCalibration(std::make_shared<LinearCalibration>(maxcurr,0xFF)); - m_dac_2->setCalibration(std::make_shared<LinearCalibration>(maxcurr,0xFF)); - - // - // PBs - for(uint32_t pbNum=0;pbNum<10;pbNum++) - m_pbs[pbNum]=std::make_shared<AMACv2>(0, - std::shared_ptr<EndeavourRaw>(new EndeavourRawUIO(std::make_shared<UIOCom>("/dev/uio"+std::to_string(pbNum), - 0x10000) - ) - ) - ); - - // Invert polarities - for(uint32_t pbNum=0;pbNum<5;pbNum++) - { - dynamic_cast<EndeavourRawUIO*>(m_pbs[pbNum]->raw().get())->invertCMDin (true); - dynamic_cast<EndeavourRawUIO*>(m_pbs[pbNum]->raw().get())->invertCMDout(true); +void PBv3TBMassive::init() { initDevices(); } + +void PBv3TBMassive::initDevices() { + // + // Create the I2C mappings + + // Multiplexers + m_i2c_root = std::make_shared<I2CDevCom>(0x70, m_i2cdev); + + m_i2c_analogue = std::make_shared<PCA9548ACom>(0x4c, 1, m_i2c_root); + m_mux_hv = + std::make_shared<PGA11x>(std::make_shared<SPIDevCom>("/dev/spidev1.0")); + + // + // ADCs + m_adc_pwr = std::make_shared<AD799X>( + 3.3, AD799X::AD7993, + std::make_shared<PCA9548ACom>(0x21, 7, m_i2c_root)); + m_adc_lv0 = std::make_shared<AD799X>( + 3.3, AD799X::AD7997, + std::make_shared<PCA9548ACom>(0x21, 5, m_i2c_root)); + m_adc_lv1 = std::make_shared<AD799X>( + 3.3, AD799X::AD7997, + std::make_shared<PCA9548ACom>(0x22, 5, m_i2c_root)); + + m_adc_lvset0 = std::make_shared<MCP3428>( + std::make_shared<PCA9548ACom>(0x68, 5, m_i2c_root)); + m_adc_lvset1 = std::make_shared<MCP3428>( + std::make_shared<PCA9548ACom>(0x6C, 5, m_i2c_root)); + m_adc_lvset2 = std::make_shared<MCP3428>( + std::make_shared<PCA9548ACom>(0x6A, 5, m_i2c_root)); + + // Returns current + std::dynamic_pointer_cast<MCP3428>(m_adc_lvset0) + ->setGain(MCP3428::Gain::x4); + std::dynamic_pointer_cast<MCP3428>(m_adc_lvset1) + ->setGain(MCP3428::Gain::x4); + std::dynamic_pointer_cast<MCP3428>(m_adc_lvset2) + ->setGain(MCP3428::Gain::x4); + + float loadmax = 2.048 / 4 / 100e-3; + m_adc_lvset0->setCalibration( + std::make_shared<LinearCalibration>(loadmax, 0x7FFF)); + m_adc_lvset1->setCalibration( + std::make_shared<LinearCalibration>(loadmax, 0x7FFF)); + m_adc_lvset2->setCalibration( + std::make_shared<LinearCalibration>(loadmax, 0x7FFF)); + + m_adc_hv = std::make_shared<LTC2451>( + 3.25 / 3.24e3, std::make_shared<PCA9548ACom>(0x14, 0, m_i2c_root)); + + // Common PB output + m_adc_common = std::make_shared<MCP3425>( + std::make_shared<PCA9548ACom>(0x68, 1, m_i2c_root)); + + m_sel_out = std::make_shared<MCP23017>( + std::make_shared<PCA9548ACom>(0x20, 2, m_i2c_root)); + m_sel_of = std::make_shared<MCP23017>( + std::make_shared<PCA9548ACom>(0x21, 2, m_i2c_root)); + + m_sel_of->setIO(0x0); + m_sel_out->setIO(0x0); + + m_sel_out->write( + 0xFF03); // disable carrier card multiplexers (active low enable) + + // + // DACs + double maxcurr = 3.25 * 16.9 / (100 + 16.9) / 100e-3; + m_dac_0 = std::make_shared<DAC5574>( + maxcurr, std::make_shared<PCA9548ACom>(0x4C, 5, m_i2c_root)); + m_dac_1 = std::make_shared<DAC5574>( + maxcurr, std::make_shared<PCA9548ACom>(0x4D, 5, m_i2c_root)); + m_dac_2 = std::make_shared<DAC5574>( + maxcurr, std::make_shared<PCA9548ACom>(0x4E, 5, m_i2c_root)); + + m_dac_0->setCalibration(std::make_shared<LinearCalibration>(maxcurr, 0xFF)); + m_dac_1->setCalibration(std::make_shared<LinearCalibration>(maxcurr, 0xFF)); + m_dac_2->setCalibration(std::make_shared<LinearCalibration>(maxcurr, 0xFF)); + + // + // PBs + for (uint32_t pbNum = 0; pbNum < 10; pbNum++) + m_pbs[pbNum] = std::make_shared<AMACv2>( + 0, std::shared_ptr<EndeavourRaw>( + new EndeavourRawUIO(std::make_shared<UIOCom>( + "/dev/uio" + std::to_string(pbNum), 0x10000)))); + + // Invert polarities + for (uint32_t pbNum = 0; pbNum < 5; pbNum++) { + dynamic_cast<EndeavourRawUIO*>(m_pbs[pbNum]->raw().get()) + ->invertCMDin(true); + dynamic_cast<EndeavourRawUIO*>(m_pbs[pbNum]->raw().get()) + ->invertCMDout(true); } - // - // CAL DAC - setCalDAC(std::make_shared<DAC5571>(1.085, m_i2c_analogue)); - - // - // Load calibrations for the different channels - m_adc_pwr->setCalibration(PBV3_ADC_CH_VIN , std::make_shared<LinearCalibration>(3.25*(35+90.9)/35,0x3FF)); - m_adc_pwr->setCalibration(PBV3_ADC_CH_VIN_CURR, std::make_shared<LinearCalibration>(3.25/(50*0.005) ,0x3FF)); - m_adc_pwr->setCalibration(PBV3_ADC_CH_P5V_CURR, std::make_shared<LinearCalibration>(3.25/(50*0.1) ,0x3FF)); - m_adc_pwr->setCalibration(PBV3_ADC_CH_M5V_CURR, std::make_shared<LinearCalibration>(3.25/(50*0.1) ,0x3FF)); + // + // CAL DAC + setCalDAC(std::make_shared<DAC5571>(1.085, m_i2c_analogue)); + + // + // Load calibrations for the different channels + m_adc_pwr->setCalibration( + PBV3_ADC_CH_VIN, + std::make_shared<LinearCalibration>(3.25 * (35 + 90.9) / 35, 0x3FF)); + m_adc_pwr->setCalibration( + PBV3_ADC_CH_VIN_CURR, + std::make_shared<LinearCalibration>(3.25 / (50 * 0.005), 0x3FF)); + m_adc_pwr->setCalibration( + PBV3_ADC_CH_P5V_CURR, + std::make_shared<LinearCalibration>(3.25 / (50 * 0.1), 0x3FF)); + m_adc_pwr->setCalibration( + PBV3_ADC_CH_M5V_CURR, + std::make_shared<LinearCalibration>(3.25 / (50 * 0.1), 0x3FF)); } -void PBv3TBMassive::setOFin(uint8_t pbNum, bool value) -{ - if(pbNum>=m_pbs.size()) - throw OutOfRangeException(pbNum,0,m_pbs.size()-1); +void PBv3TBMassive::setOFin(uint8_t pbNum, bool value) { + if (pbNum >= m_pbs.size()) + throw OutOfRangeException(pbNum, 0, m_pbs.size() - 1); - // Select the enable bit - uint32_t bit=(pbNum>1)?(pbNum+6):(pbNum); - uint32_t bitvalue= (value << bit); - uint32_t bitmask =~( 1 << bit); + // Select the enable bit + uint32_t bit = (pbNum > 1) ? (pbNum + 6) : (pbNum); + uint32_t bitvalue = (value << bit); + uint32_t bitmask = ~(1 << bit); - uint32_t selval=m_sel_of ->read(); - selval=(selval&bitmask)|bitvalue; - m_sel_of ->write(selval); + uint32_t selval = m_sel_of->read(); + selval = (selval & bitmask) | bitvalue; + m_sel_of->write(selval); } -double PBv3TBMassive::getVin() -{ - return m_adc_pwr->read(PBV3_ADC_CH_VIN); -} +double PBv3TBMassive::getVin() { return m_adc_pwr->read(PBV3_ADC_CH_VIN); } -double PBv3TBMassive::getP5VCurrent() -{ - return m_adc_pwr->read(PBV3_ADC_CH_P5V_CURR); +double PBv3TBMassive::getP5VCurrent() { + return m_adc_pwr->read(PBV3_ADC_CH_P5V_CURR); } -double PBv3TBMassive::getM5VCurrent() -{ - return m_adc_pwr->read(PBV3_ADC_CH_M5V_CURR); +double PBv3TBMassive::getM5VCurrent() { + return m_adc_pwr->read(PBV3_ADC_CH_M5V_CURR); } -double PBv3TBMassive::getNTC(uint8_t ntc) -{ - // NTC properties - static const double R25=10e3; - static const double B =(3601+3650)/2; - static const double T25=298.15; - static const double T0 =273.15; - - double tempvolt=m_adc_lv1->read(ntc); - double tempres =10e3/(tempvolt/3.3)-10e3; - - return 1/(log(tempres/R25)/B+1/T25)-T0; +double PBv3TBMassive::getNTC(uint8_t ntc) { + // NTC properties + static const double R25 = 10e3; + static const double B = (3601 + 3650) / 2; + static const double T25 = 298.15; + static const double T0 = 273.15; + + double tempvolt = m_adc_lv1->read(ntc); + double tempres = 10e3 / (tempvolt / 3.3) - 10e3; + + return 1 / (log(tempres / R25) / B + 1 / T25) - T0; } -std::shared_ptr<AMACv2> PBv3TBMassive::getPB(uint8_t pbNum) -{ - if(pbNum>=m_pbs.size()) - throw OutOfRangeException(pbNum,0,m_pbs.size()-1); - return m_pbs[pbNum]; +std::shared_ptr<AMACv2> PBv3TBMassive::getPB(uint8_t pbNum) { + if (pbNum >= m_pbs.size()) + throw OutOfRangeException(pbNum, 0, m_pbs.size() - 1); + return m_pbs[pbNum]; } -void PBv3TBMassive::loadOn(uint8_t pbNum) -{ } +void PBv3TBMassive::loadOn(uint8_t pbNum) {} -void PBv3TBMassive::loadOff(uint8_t pbNum) -{ - setLoad(pbNum, 0); -} +void PBv3TBMassive::loadOff(uint8_t pbNum) { setLoad(pbNum, 0); } + +double PBv3TBMassive::setLoad(uint8_t pbNum, double load) { + switch (pbNum) { + case 0: + return m_dac_0->set(DAC_CH_LOAD_PB0, load); + break; + + case 1: + return m_dac_0->set(DAC_CH_LOAD_PB1, load); + break; + + case 2: + return m_dac_0->set(DAC_CH_LOAD_PB2, load); + break; + + case 3: + return m_dac_0->set(DAC_CH_LOAD_PB3, load); + break; + + case 4: + return m_dac_1->set(DAC_CH_LOAD_PB4, load); + break; -double PBv3TBMassive::setLoad(uint8_t pbNum, double load) -{ - switch ( pbNum ) - { - case 0 : - return m_dac_0->set(DAC_CH_LOAD_PB0, load); - break; - - case 1 : - return m_dac_0->set(DAC_CH_LOAD_PB1, load); - break; - - case 2 : - return m_dac_0->set(DAC_CH_LOAD_PB2, load); - break; - - case 3 : - return m_dac_0->set(DAC_CH_LOAD_PB3, load); - break; - - case 4 : - return m_dac_1->set(DAC_CH_LOAD_PB4, load); - break; - - case 5 : - return m_dac_1->set(DAC_CH_LOAD_PB5, load); - break; - - case 6 : - return m_dac_1->set(DAC_CH_LOAD_PB6, load); - break; - - case 7 : - return m_dac_1->set(DAC_CH_LOAD_PB7, load); - break; - - case 8 : - return m_dac_2->set(DAC_CH_LOAD_PB8, load); - break; - - case 9 : - return m_dac_2->set(DAC_CH_LOAD_PB9, load); - break; - - default: - // TODO throw exception - return 0.; + case 5: + return m_dac_1->set(DAC_CH_LOAD_PB5, load); + break; + + case 6: + return m_dac_1->set(DAC_CH_LOAD_PB6, load); + break; + + case 7: + return m_dac_1->set(DAC_CH_LOAD_PB7, load); + break; + + case 8: + return m_dac_2->set(DAC_CH_LOAD_PB8, load); + break; + + case 9: + return m_dac_2->set(DAC_CH_LOAD_PB9, load); + break; + + default: + // TODO throw exception + return 0.; } } -void PBv3TBMassive::setLoadCounts(uint8_t pbNum, uint32_t counts) -{ - switch ( pbNum ) - { - case 0 : - m_dac_0->setCount(DAC_CH_LOAD_PB0, counts); - break; - - case 1 : - m_dac_0->setCount(DAC_CH_LOAD_PB1, counts); - break; - - case 2 : - m_dac_0->setCount(DAC_CH_LOAD_PB2, counts); - break; - - case 3 : - m_dac_0->setCount(DAC_CH_LOAD_PB3, counts); - break; - - case 4 : - m_dac_1->setCount(DAC_CH_LOAD_PB4, counts); - break; - - case 5 : - m_dac_1->setCount(DAC_CH_LOAD_PB5, counts); - break; - - case 6 : - m_dac_1->setCount(DAC_CH_LOAD_PB6, counts); - break; - - case 7 : - m_dac_1->setCount(DAC_CH_LOAD_PB7, counts); - break; - - case 8 : - m_dac_2->setCount(DAC_CH_LOAD_PB8, counts); - break; - - case 9 : - m_dac_2->setCount(DAC_CH_LOAD_PB9, counts); - break; - - default: - // TODO throw exception - break; +void PBv3TBMassive::setLoadCounts(uint8_t pbNum, uint32_t counts) { + switch (pbNum) { + case 0: + m_dac_0->setCount(DAC_CH_LOAD_PB0, counts); + break; + + case 1: + m_dac_0->setCount(DAC_CH_LOAD_PB1, counts); + break; + + case 2: + m_dac_0->setCount(DAC_CH_LOAD_PB2, counts); + break; + + case 3: + m_dac_0->setCount(DAC_CH_LOAD_PB3, counts); + break; + + case 4: + m_dac_1->setCount(DAC_CH_LOAD_PB4, counts); + break; + + case 5: + m_dac_1->setCount(DAC_CH_LOAD_PB5, counts); + break; + + case 6: + m_dac_1->setCount(DAC_CH_LOAD_PB6, counts); + break; + + case 7: + m_dac_1->setCount(DAC_CH_LOAD_PB7, counts); + break; + + case 8: + m_dac_2->setCount(DAC_CH_LOAD_PB8, counts); + break; + + case 9: + m_dac_2->setCount(DAC_CH_LOAD_PB9, counts); + break; + + default: + // TODO throw exception + break; } } -double PBv3TBMassive::getLoad(uint8_t pbNum) -{ - return 0.; // TODO implement +double PBv3TBMassive::getLoad(uint8_t pbNum) { + return 0.; // TODO implement } -double PBv3TBMassive::getVout(uint8_t pbNum) -{ - if(pbNum>=m_pbs.size()) - throw OutOfRangeException(pbNum,0,m_pbs.size()-1); +double PBv3TBMassive::getVout(uint8_t pbNum) { + if (pbNum >= m_pbs.size()) + throw OutOfRangeException(pbNum, 0, m_pbs.size() - 1); - // select 1.5V output on carrier card mux - setCarrierOutput(CARRIER_OUTPUT::VOUT); + // select 1.5V output on carrier card mux + setCarrierOutput(CARRIER_OUTPUT::VOUT); - // Enable the output for the requested powerboard - setCarrierOutputEnable(pbNum, true); + // Enable the output for the requested powerboard + setCarrierOutputEnable(pbNum, true); - // Read the value - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - double value=m_adc_common->read(); + // Read the value + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + double value = m_adc_common->read(); - // Disable the output for the requested powerboard - setCarrierOutputEnable(pbNum, false); + // Disable the output for the requested powerboard + setCarrierOutputEnable(pbNum, false); - return value; + return value; } -uint32_t PBv3TBMassive::getVoutCount(uint8_t pbNum) -{ - switch ( pbNum ) - { - case 0 : - return m_adc_lv0->readCount(ADC_VOUT_PB0); - break; - - case 1 : - return m_adc_lv0->readCount(ADC_VOUT_PB1); - break; - - case 2 : - return m_adc_lv0->readCount(ADC_VOUT_PB2); - break; - - case 3 : - return m_adc_lv0->readCount(ADC_VOUT_PB3); - break; - - case 4 : - return m_adc_lv0->readCount(ADC_VOUT_PB4); - break; - - case 5 : - return m_adc_lv0->readCount(ADC_VOUT_PB5); - break; - - case 6 : - return m_adc_lv1->readCount(ADC_VOUT_PB6); - break; - - case 7 : - return m_adc_lv1->readCount(ADC_VOUT_PB7); - break; - - case 8 : - return m_adc_lv1->readCount(ADC_VOUT_PB8); - break; - - case 9 : - return m_adc_lv1->readCount(ADC_VOUT_PB9); - break; - - default: - // TODO throw exception - return 0.; - } +uint32_t PBv3TBMassive::getVoutCount(uint8_t pbNum) { + switch (pbNum) { + case 0: + return m_adc_lv0->readCount(ADC_VOUT_PB0); + break; + + case 1: + return m_adc_lv0->readCount(ADC_VOUT_PB1); + break; + + case 2: + return m_adc_lv0->readCount(ADC_VOUT_PB2); + break; + + case 3: + return m_adc_lv0->readCount(ADC_VOUT_PB3); + break; + case 4: + return m_adc_lv0->readCount(ADC_VOUT_PB4); + break; + + case 5: + return m_adc_lv0->readCount(ADC_VOUT_PB5); + break; + + case 6: + return m_adc_lv1->readCount(ADC_VOUT_PB6); + break; + + case 7: + return m_adc_lv1->readCount(ADC_VOUT_PB7); + break; + + case 8: + return m_adc_lv1->readCount(ADC_VOUT_PB8); + break; + + case 9: + return m_adc_lv1->readCount(ADC_VOUT_PB9); + break; + + default: + // TODO throw exception + return 0.; + } } -double PBv3TBMassive::getIload(uint8_t pbNum) -{ - switch ( pbNum ) - { - case 0 : - return m_adc_lvset0->read(ADC_ILOAD_PB0); - break; - - case 1 : - return m_adc_lvset0->read(ADC_ILOAD_PB1); - break; - - case 2 : - return m_adc_lvset0->read(ADC_ILOAD_PB2); - break; - - case 3 : - return m_adc_lvset0->read(ADC_ILOAD_PB3); - break; - - case 4 : - return m_adc_lvset1->read(ADC_ILOAD_PB4); - break; - - case 5 : - return m_adc_lvset1->read(ADC_ILOAD_PB5); - break; - - case 6 : - return m_adc_lvset1->read(ADC_ILOAD_PB6); - break; - - case 7 : - return m_adc_lvset1->read(ADC_ILOAD_PB7); - break; - - case 8 : - return m_adc_lvset2->read(ADC_ILOAD_PB8); - break; - - case 9 : - return m_adc_lvset2->read(ADC_ILOAD_PB9); - break; - - default: - // TODO throw exception - return 0.; +double PBv3TBMassive::getIload(uint8_t pbNum) { + switch (pbNum) { + case 0: + return m_adc_lvset0->read(ADC_ILOAD_PB0); + break; + + case 1: + return m_adc_lvset0->read(ADC_ILOAD_PB1); + break; + + case 2: + return m_adc_lvset0->read(ADC_ILOAD_PB2); + break; + + case 3: + return m_adc_lvset0->read(ADC_ILOAD_PB3); + break; + + case 4: + return m_adc_lvset1->read(ADC_ILOAD_PB4); + break; + + case 5: + return m_adc_lvset1->read(ADC_ILOAD_PB5); + break; + + case 6: + return m_adc_lvset1->read(ADC_ILOAD_PB6); + break; + + case 7: + return m_adc_lvset1->read(ADC_ILOAD_PB7); + break; + + case 8: + return m_adc_lvset2->read(ADC_ILOAD_PB8); + break; + + case 9: + return m_adc_lvset2->read(ADC_ILOAD_PB9); + break; + + default: + // TODO throw exception + return 0.; } } -double PBv3TBMassive::getHVoutCurrent(uint8_t pbNum) -{ - if(pbNum>=m_pbs.size()) - throw OutOfRangeException(pbNum,0,m_pbs.size()-1); - - switch ( pbNum ) - { - case 0 : - m_mux_hv->select(5); - break; - - case 1 : - m_mux_hv->select(4); - break; - - case 2 : - m_mux_hv->select(3); - break; - - case 3 : - m_mux_hv->select(2); - break; - - case 4 : - m_mux_hv->select(1); - break; - - case 5 : - m_mux_hv->select(0); - break; - - case 6 : - m_mux_hv->select(7); - break; - - case 7 : - m_mux_hv->select(6); - break; - - case 8 : - m_mux_hv->select(9); - break; - - case 9 : - m_mux_hv->select(8); - break; - - default: - throw OutOfRangeException(pbNum,0,m_pbs.size()-1); - return 0.; +double PBv3TBMassive::getHVoutCurrent(uint8_t pbNum) { + if (pbNum >= m_pbs.size()) + throw OutOfRangeException(pbNum, 0, m_pbs.size() - 1); + + switch (pbNum) { + case 0: + m_mux_hv->select(5); + break; + + case 1: + m_mux_hv->select(4); + break; + + case 2: + m_mux_hv->select(3); + break; + + case 3: + m_mux_hv->select(2); + break; + + case 4: + m_mux_hv->select(1); + break; + + case 5: + m_mux_hv->select(0); + break; + + case 6: + m_mux_hv->select(7); + break; + + case 7: + m_mux_hv->select(6); + break; + + case 8: + m_mux_hv->select(9); + break; + + case 9: + m_mux_hv->select(8); + break; + + default: + throw OutOfRangeException(pbNum, 0, m_pbs.size() - 1); + return 0.; } - return m_adc_hv->read(); + return m_adc_hv->read(); } -void PBv3TBMassive::setCarrierOutput(PBv3TB::CARRIER_OUTPUT value) -{ - uint32_t selval=m_sel_out->read(); - selval=(selval&0xFF0F)|((value<<4)&0x00F0); - m_sel_out->write(selval); +void PBv3TBMassive::setCarrierOutput(PBv3TB::CARRIER_OUTPUT value) { + uint32_t selval = m_sel_out->read(); + selval = (selval & 0xFF0F) | ((value << 4) & 0x00F0); + m_sel_out->write(selval); } -void PBv3TBMassive::setCarrierOutputEnable(uint32_t pbNum, bool value) -{ - // Select the enable bit - uint32_t bit=(pbNum>1)?(pbNum+6):(pbNum); - uint32_t bitvalue=~(value << bit); +void PBv3TBMassive::setCarrierOutputEnable(uint32_t pbNum, bool value) { + // Select the enable bit + uint32_t bit = (pbNum > 1) ? (pbNum + 6) : (pbNum); + uint32_t bitvalue = ~(value << bit); - uint32_t selval=m_sel_out->read(); - selval=(selval&0x00F0)|((bitvalue)&0xFF0F); - m_sel_out->write(selval); + uint32_t selval = m_sel_out->read(); + selval = (selval & 0x00F0) | ((bitvalue)&0xFF0F); + m_sel_out->write(selval); - // Select the GND value - selval=m_sel_of->read(); - selval=(selval&0xFF0F)|((pbNum<<4)&0x00F0); - m_sel_of->write(selval); + // Select the GND value + selval = m_sel_of->read(); + selval = (selval & 0xFF0F) | ((pbNum << 4) & 0x00F0); + m_sel_of->write(selval); } -double PBv3TBMassive::readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value) -{ - // Selection mux value and enable output - setCarrierOutput(value); - setCarrierOutputEnable(pbNum, true); +double PBv3TBMassive::readCarrierOutput(uint32_t pbNum, + PBv3TB::CARRIER_OUTPUT value) { + // Selection mux value and enable output + setCarrierOutput(value); + setCarrierOutputEnable(pbNum, true); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - double volts=m_adc_common->read(); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + double volts = m_adc_common->read(); - // Disable the output for the requested powerboard - setCarrierOutputEnable(pbNum, false); + // Disable the output for the requested powerboard + setCarrierOutputEnable(pbNum, false); - return volts; + return volts; } diff --git a/pbv3/PBv3TBMassive.h b/pbv3/PBv3TBMassive.h index 60e3d63d71ab605993718c98ec14381a0c0fe5cf..712021a1c762394e89e59d35a478f4a0252222e8 100644 --- a/pbv3/PBv3TBMassive.h +++ b/pbv3/PBv3TBMassive.h @@ -3,13 +3,12 @@ #include <memory> -#include "PBv3TB.h" - -#include "I2CCom.h" #include "ADCDevice.h" #include "DACDevice.h" +#include "I2CCom.h" #include "IOExpander.h" #include "MuxDevice.h" +#include "PBv3TB.h" #define PBV3_ADC_CH_VIN 3 #define PBV3_ADC_CH_VIN_CURR 0 @@ -22,7 +21,7 @@ #define DAC_CH_LOAD_PB3 3 #define DAC_CH_LOAD_PB4 1 #define DAC_CH_LOAD_PB5 2 -#define DAC_CH_LOAD_PB6 0 +#define DAC_CH_LOAD_PB6 0 #define DAC_CH_LOAD_PB7 3 #define DAC_CH_LOAD_PB8 1 #define DAC_CH_LOAD_PB9 2 @@ -77,104 +76,103 @@ #define AMP_HV_PB8 7 #define AMP_HV_PB9 8 -class PBv3TBMassive : public PBv3TB -{ -public: - PBv3TBMassive(std::shared_ptr<PowerSupplyChannel> lv, std::shared_ptr<PowerSupplyChannel> hv); - PBv3TBMassive(std::shared_ptr<EquipConf> hw); - PBv3TBMassive(); - ~PBv3TBMassive() =default; - - /** \brief Configure on JSON object - * - * Valid keys: - * - `i2cdev`: Path to I2C device - * - * \param config JSON configuration - */ - virtual void setConfiguration(const nlohmann::json& config); - - /** \brief Initialize testbench - * - * Calls `initDevices` - */ - virtual void init(); - - std::shared_ptr<AMACv2> getPB(uint8_t pb); - - void setOFin(uint8_t pbNum, bool value); - - double getVin(); - double getP5VCurrent(); - double getM5VCurrent(); - - double getNTC(uint8_t ntc); - - void loadOn(uint8_t pbNum); - void loadOff(uint8_t pbNum); - double setLoad (uint8_t pbNum, double load); - void setLoadCounts(uint8_t pbNum, uint32_t counts); - double getLoad(uint8_t pbNum); - - double getVout(uint8_t pbNum); - double getIload(uint8_t pbNum); - uint32_t getVoutCount(uint8_t pbNum); - - double getHVoutCurrent(uint8_t pbNum); - - void setCarrierOutput(PBv3TB::CARRIER_OUTPUT value); - void setCarrierOutputEnable(uint32_t pbNum, bool value); - - /* - * Reads the value of the multiplexed carrier output. - * The multiplexer is enable and then disabled after - * the value is read. - * - * \param value The channel to read - * - * \return Measured value in volts - */ - double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value); - -private: - // - // initialization functions - - /** \brief Initialize devices on the active board - */ - void initDevices(); - - //! i2cdev Linux device to serve as I2C root - std::string m_i2cdev = "/dev/i2c-0"; - - // - // I2C multiplexers - std::shared_ptr<I2CCom> m_i2c_root; - - std::shared_ptr<I2CCom> m_i2c_analogue; - - //SPI device - std::shared_ptr<MuxDevice> m_mux_hv; - - //I2C devices - std::shared_ptr<ADCDevice> m_adc_pwr; - std::shared_ptr<ADCDevice> m_adc_lv0; - std::shared_ptr<ADCDevice> m_adc_lv1; - std::shared_ptr<ADCDevice> m_adc_lvset0; - std::shared_ptr<ADCDevice> m_adc_lvset1; - std::shared_ptr<ADCDevice> m_adc_lvset2; - std::shared_ptr<ADCDevice> m_adc_hv; - std::shared_ptr<ADCDevice> m_adc_common; - - std::shared_ptr<DACDevice> m_dac_0; - std::shared_ptr<DACDevice> m_dac_1; - std::shared_ptr<DACDevice> m_dac_2; - - std::shared_ptr<IOExpander> m_sel_out; - std::shared_ptr<IOExpander> m_sel_of; - - - std::vector<std::shared_ptr<AMACv2>> m_pbs{10}; +class PBv3TBMassive : public PBv3TB { + public: + PBv3TBMassive(std::shared_ptr<PowerSupplyChannel> lv, + std::shared_ptr<PowerSupplyChannel> hv); + PBv3TBMassive(std::shared_ptr<EquipConf> hw); + PBv3TBMassive(); + ~PBv3TBMassive() = default; + + /** \brief Configure on JSON object + * + * Valid keys: + * - `i2cdev`: Path to I2C device + * + * \param config JSON configuration + */ + virtual void setConfiguration(const nlohmann::json& config); + + /** \brief Initialize testbench + * + * Calls `initDevices` + */ + virtual void init(); + + std::shared_ptr<AMACv2> getPB(uint8_t pb); + + void setOFin(uint8_t pbNum, bool value); + + double getVin(); + double getP5VCurrent(); + double getM5VCurrent(); + + double getNTC(uint8_t ntc); + + void loadOn(uint8_t pbNum); + void loadOff(uint8_t pbNum); + double setLoad(uint8_t pbNum, double load); + void setLoadCounts(uint8_t pbNum, uint32_t counts); + double getLoad(uint8_t pbNum); + + double getVout(uint8_t pbNum); + double getIload(uint8_t pbNum); + uint32_t getVoutCount(uint8_t pbNum); + + double getHVoutCurrent(uint8_t pbNum); + + void setCarrierOutput(PBv3TB::CARRIER_OUTPUT value); + void setCarrierOutputEnable(uint32_t pbNum, bool value); + + /* + * Reads the value of the multiplexed carrier output. + * The multiplexer is enable and then disabled after + * the value is read. + * + * \param value The channel to read + * + * \return Measured value in volts + */ + double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value); + + private: + // + // initialization functions + + /** \brief Initialize devices on the active board + */ + void initDevices(); + + //! i2cdev Linux device to serve as I2C root + std::string m_i2cdev = "/dev/i2c-0"; + + // + // I2C multiplexers + std::shared_ptr<I2CCom> m_i2c_root; + + std::shared_ptr<I2CCom> m_i2c_analogue; + + // SPI device + std::shared_ptr<MuxDevice> m_mux_hv; + + // I2C devices + std::shared_ptr<ADCDevice> m_adc_pwr; + std::shared_ptr<ADCDevice> m_adc_lv0; + std::shared_ptr<ADCDevice> m_adc_lv1; + std::shared_ptr<ADCDevice> m_adc_lvset0; + std::shared_ptr<ADCDevice> m_adc_lvset1; + std::shared_ptr<ADCDevice> m_adc_lvset2; + std::shared_ptr<ADCDevice> m_adc_hv; + std::shared_ptr<ADCDevice> m_adc_common; + + std::shared_ptr<DACDevice> m_dac_0; + std::shared_ptr<DACDevice> m_dac_1; + std::shared_ptr<DACDevice> m_dac_2; + + std::shared_ptr<IOExpander> m_sel_out; + std::shared_ptr<IOExpander> m_sel_of; + + std::vector<std::shared_ptr<AMACv2>> m_pbs{10}; }; -#endif // PBV3TBMASSIVE_H +#endif // PBV3TBMASSIVE_H diff --git a/pbv3/PBv3TBModule.cpp b/pbv3/PBv3TBModule.cpp index 192084c225be7bbdfc0dfc86c715141b90217ef5..93872b3543a50215ae66898464bda09ba4a60419 100644 --- a/pbv3/PBv3TBModule.cpp +++ b/pbv3/PBv3TBModule.cpp @@ -1,145 +1,122 @@ #include "PBv3TBModule.h" -#include <cmath> #include <chrono> +#include <cmath> #include <thread> -#include "Logger.h" - +#include "AD56X9.h" #include "EndeavourRawITSDAQ.h" #include "ITSDAQI2CCom.h" - -#include "AD56X9.h" - +#include "Logger.h" #include "OutOfRangeException.h" -//Register test bench +// Register test bench #include "PBv3TBRegistry.h" REGISTER_PBV3TB(PBv3TBModule) PBv3TBModule::PBv3TBModule(const std::string& ip, uint32_t port) - : PBv3TB(), m_ip(ip), m_port(port) -{ } - -PBv3TBModule::~PBv3TBModule() -{ } - -void PBv3TBModule::setConfiguration(const nlohmann::json& config) -{ - for (const auto &kv : config.items()) - { - if(kv.key()=="ip") - { - m_ip=kv.value(); - } - else if(kv.key()=="port") - { - m_port=kv.value(); - } - else if(kv.key()=="pbs") - { - for(const auto &pb : kv.value()) - { - m_pb_idpads.push_back(pb.value("idpads",0)); - m_pb_commid.push_back(pb.value("commid",0)); - } - } - + : PBv3TB(), m_ip(ip), m_port(port) {} + +PBv3TBModule::~PBv3TBModule() {} + +void PBv3TBModule::setConfiguration(const nlohmann::json& config) { + for (const auto& kv : config.items()) { + if (kv.key() == "ip") { + m_ip = kv.value(); + } else if (kv.key() == "port") { + m_port = kv.value(); + } else if (kv.key() == "pbs") { + for (const auto& pb : kv.value()) { + m_pb_idpads.push_back(pb.value("idpads", 0)); + m_pb_commid.push_back(pb.value("commid", 0)); + } + } } - PBv3TB::setConfiguration(config); -} - -void PBv3TBModule::init() -{ - // PB com - m_com=std::make_shared<ITSDAQCom>(m_ip, m_port); - for(uint32_t i=0; i<m_pb_commid.size(); i++) - { - m_pbs.push_back( - std::make_shared<AMACv2>(m_pb_commid[i], - std::shared_ptr<EndeavourRawITSDAQ>(new EndeavourRawITSDAQ(m_com)) - ) - ); - m_pbs.back()->setPADID(m_pb_idpads[i]); + PBv3TB::setConfiguration(config); +} + +void PBv3TBModule::init() { + // PB com + m_com = std::make_shared<ITSDAQCom>(m_ip, m_port); + for (uint32_t i = 0; i < m_pb_commid.size(); i++) { + m_pbs.push_back(std::make_shared<AMACv2>( + m_pb_commid[i], std::shared_ptr<EndeavourRawITSDAQ>( + new EndeavourRawITSDAQ(m_com)))); + m_pbs.back()->setPADID(m_pb_idpads[i]); } - // CAL - std::shared_ptr<I2CCom> i2c=std::make_shared<ITSDAQI2CCom>(0x56, m_com); - setCalDAC(std::make_shared<AD56X9>(1.5, AD56X9::Model::AD5629, i2c)); + // CAL + std::shared_ptr<I2CCom> i2c = std::make_shared<ITSDAQI2CCom>(0x56, m_com); + setCalDAC(std::make_shared<AD56X9>(1.5, AD56X9::Model::AD5629, i2c)); } -void PBv3TBModule::setOFin(uint8_t pbNum, bool value) -{ - logger(logWARNING) << "OFin not implemented on module yet."; +void PBv3TBModule::setOFin(uint8_t pbNum, bool value) { + logger(logWARNING) << "OFin not implemented on module yet."; } -double PBv3TBModule::getVin() -{ - logger(logWARNING) << "LV is monitored externally on the module."; - return 0.; +double PBv3TBModule::getVin() { + logger(logWARNING) << "LV is monitored externally on the module."; + return 0.; } -std::shared_ptr<AMACv2> PBv3TBModule::getPB(uint8_t pbNum) -{ - if(pbNum>=m_pbs.size()) - throw OutOfRangeException(pbNum,0,m_pbs.size()-1); - return m_pbs[pbNum]; +std::shared_ptr<AMACv2> PBv3TBModule::getPB(uint8_t pbNum) { + if (pbNum >= m_pbs.size()) + throw OutOfRangeException(pbNum, 0, m_pbs.size() - 1); + return m_pbs[pbNum]; } -void PBv3TBModule::loadOn(uint8_t pbNum) -{ logger(logWARNING) << "No load on module."; } +void PBv3TBModule::loadOn(uint8_t pbNum) { + logger(logWARNING) << "No load on module."; +} -void PBv3TBModule::loadOff(uint8_t pbNum) -{ logger(logWARNING) << "No load on module."; } +void PBv3TBModule::loadOff(uint8_t pbNum) { + logger(logWARNING) << "No load on module."; +} -double PBv3TBModule::setLoad(uint8_t pbNum, double load) -{ - logger(logWARNING) << "No load on module."; - return 0.; +double PBv3TBModule::setLoad(uint8_t pbNum, double load) { + logger(logWARNING) << "No load on module."; + return 0.; } -double PBv3TBModule::getLoad(uint8_t pbNum) -{ - logger(logWARNING) << "No load on module."; - return 0.; +double PBv3TBModule::getLoad(uint8_t pbNum) { + logger(logWARNING) << "No load on module."; + return 0.; } -double PBv3TBModule::getVout(uint8_t pbNum) -{ - logger(logWARNING) << "No DC/DC monitoring on module."; - return 0.; +double PBv3TBModule::getVout(uint8_t pbNum) { + logger(logWARNING) << "No DC/DC monitoring on module."; + return 0.; } -double PBv3TBModule::getIload(uint8_t pbNum) -{ - logger(logWARNING) << "No load on module."; - return 0.; +double PBv3TBModule::getIload(uint8_t pbNum) { + logger(logWARNING) << "No load on module."; + return 0.; } -//Measure the high voltage -double PBv3TBModule::getHVout(uint8_t pbNum) -{ - logger(logWARNING) << "HV is monitored externally on module."; - return 0.; +// Measure the high voltage +double PBv3TBModule::getHVout(uint8_t pbNum) { + logger(logWARNING) << "HV is monitored externally on module."; + return 0.; } -void PBv3TBModule::powerHVOn() -{ logger(logWARNING) << "HV is controlled externally on module."; } +void PBv3TBModule::powerHVOn() { + logger(logWARNING) << "HV is controlled externally on module."; +} -void PBv3TBModule::powerHVOff() -{ logger(logWARNING) << "HV is controlled externally on module."; } +void PBv3TBModule::powerHVOff() { + logger(logWARNING) << "HV is controlled externally on module."; +} -double PBv3TBModule::getHVoutCurrent(uint8_t pbNum) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +double PBv3TBModule::getHVoutCurrent(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); - return 0.; // TODO implement + return 0.; // TODO implement } -double PBv3TBModule::readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value) -{ - logger(logWARNING) << "Powerboard output reading not setup for single testbench."; +double PBv3TBModule::readCarrierOutput(uint32_t pbNum, + PBv3TB::CARRIER_OUTPUT value) { + logger(logWARNING) + << "Powerboard output reading not setup for single testbench."; - return 0.; + return 0.; } diff --git a/pbv3/PBv3TBModule.h b/pbv3/PBv3TBModule.h index de91132e54ba805a00ef97cb68dec9faf87e0710..57faefeb69ebe3091836dd884a88ebf46c7067b1 100644 --- a/pbv3/PBv3TBModule.h +++ b/pbv3/PBv3TBModule.h @@ -3,73 +3,72 @@ #include <memory> -#include "PBv3TB.h" - #include "ITSDAQCom.h" +#include "PBv3TB.h" -class PBv3TBModule : public PBv3TB -{ -public: - PBv3TBModule(const std::string& ip="192.168.222.16", uint32_t port=60003); - virtual ~PBv3TBModule(); - - /** \brief Configure on JSON object - * - * Valid keys: - * - `ip`: IP address of the ITSDAQ firmware - * - `port`: Port to access the ITSDAQ firmware - * - * \param config JSON configuration - */ - virtual void setConfiguration(const nlohmann::json& config); - - /** \brief Initialize testbench - * - * Initializes I2C communication with CAL DAC and creates the - * AMACv2 object assuming padid 0. - */ - virtual void init(); - - std::shared_ptr<AMACv2> getPB(uint8_t pb); - - void setOFin(uint8_t pbNum, bool value); - - double getVin(); - void loadOn(uint8_t pbNum); - void loadOff(uint8_t pbNum); - double setLoad(uint8_t pbNum, double load); - double getLoad(uint8_t pbNum); - - double getVout(uint8_t pbNum); - double getIload(uint8_t pbNum); - - void powerHVOn(); - void powerHVOff(); - double getHVout(uint8_t pbNum); - - double getHVoutCurrent(uint8_t pbNum); - - double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value); - -private: - /** \name Configuration - * @{ */ - - //! IP address of the ITSDAQ firmware - std::string m_ip="192.168.222.16"; - //! Port to access the ITSDAQ firmware - uint32_t m_port=60003; - - //! AMAC padid - std::vector<uint8_t> m_pb_idpads; - //! Comm ID - std::vector<uint8_t> m_pb_commid; - - /** @} */ - - // Objects - std::shared_ptr<ITSDAQCom> m_com; - std::vector<std::shared_ptr<AMACv2>> m_pbs; +class PBv3TBModule : public PBv3TB { + public: + PBv3TBModule(const std::string& ip = "192.168.222.16", + uint32_t port = 60003); + virtual ~PBv3TBModule(); + + /** \brief Configure on JSON object + * + * Valid keys: + * - `ip`: IP address of the ITSDAQ firmware + * - `port`: Port to access the ITSDAQ firmware + * + * \param config JSON configuration + */ + virtual void setConfiguration(const nlohmann::json& config); + + /** \brief Initialize testbench + * + * Initializes I2C communication with CAL DAC and creates the + * AMACv2 object assuming padid 0. + */ + virtual void init(); + + std::shared_ptr<AMACv2> getPB(uint8_t pb); + + void setOFin(uint8_t pbNum, bool value); + + double getVin(); + void loadOn(uint8_t pbNum); + void loadOff(uint8_t pbNum); + double setLoad(uint8_t pbNum, double load); + double getLoad(uint8_t pbNum); + + double getVout(uint8_t pbNum); + double getIload(uint8_t pbNum); + + void powerHVOn(); + void powerHVOff(); + double getHVout(uint8_t pbNum); + + double getHVoutCurrent(uint8_t pbNum); + + double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value); + + private: + /** \name Configuration + * @{ */ + + //! IP address of the ITSDAQ firmware + std::string m_ip = "192.168.222.16"; + //! Port to access the ITSDAQ firmware + uint32_t m_port = 60003; + + //! AMAC padid + std::vector<uint8_t> m_pb_idpads; + //! Comm ID + std::vector<uint8_t> m_pb_commid; + + /** @} */ + + // Objects + std::shared_ptr<ITSDAQCom> m_com; + std::vector<std::shared_ptr<AMACv2>> m_pbs; }; -#endif // PBV3TBMODULE_H +#endif // PBV3TBMODULE_H diff --git a/pbv3/PBv3TBNetIO.cpp b/pbv3/PBv3TBNetIO.cpp index 27f7e3ee7e530b32ce975dbd0cd13877ba5116f2..1e1c0be0a91a1d36149cefcc7417bd8360cdf201 100644 --- a/pbv3/PBv3TBNetIO.cpp +++ b/pbv3/PBv3TBNetIO.cpp @@ -1,48 +1,46 @@ #include "PBv3TBNetIO.h" -#include "EndeavourRawYARR.h" #include <NotSupportedException.h> -//Register test bench +#include "EndeavourRawYARR.h" + +// Register test bench #include "PBv3TBRegistry.h" REGISTER_PBV3TB(PBv3TBNetIO) -PBv3TBNetIO::PBv3TBNetIO() -: PBv3TBDummy() -{ } - -PBv3TBNetIO::~PBv3TBNetIO() -{ } - -void PBv3TBNetIO::setConfiguration(const nlohmann::json& config) -{ - // get the path to the netio config json and the amac id - for (const auto &kv : config.items()) - { - if(kv.key()=="config") - { - m_config_path=kv.value(); - } - if(kv.key()=="amacid") - { - m_amacid=kv.value(); - } +PBv3TBNetIO::PBv3TBNetIO() : PBv3TBDummy() {} + +PBv3TBNetIO::~PBv3TBNetIO() {} + +void PBv3TBNetIO::setConfiguration(const nlohmann::json& config) { + // get the path to the netio config json and the amac id + for (const auto& kv : config.items()) { + if (kv.key() == "config") { + m_config_path = kv.value(); + } + if (kv.key() == "amacid") { + m_amacid = kv.value(); + } } - PBv3TB::setConfiguration(config); + PBv3TB::setConfiguration(config); } -void PBv3TBNetIO::init() -{ - // - // Configure the connection to AMAC over the YARR NetIO +void PBv3TBNetIO::init() { + // + // Configure the connection to AMAC over the YARR NetIO #ifdef ENABLE_YARR_NETIO - m_pb=std::make_shared<AMACv2>(m_amacid, std::shared_ptr<EndeavourRaw>(new EndeavourRawYARR("Netio", m_config_path))); -//m_pb=std::make_shared<AMACv2>( amacid, std::shared_ptr<EndeavourRaw>(new EndeavourRawFTDI())); - - //setCalDAC(dynamic_cast<EndeavourRawYARR*>(m_pb->raw().get())->getDAC()); // not implemented, kept it just in case + m_pb = std::make_shared<AMACv2>( + m_amacid, std::shared_ptr<EndeavourRaw>( + new EndeavourRawYARR("Netio", m_config_path))); + // m_pb=std::make_shared<AMACv2>( amacid, std::shared_ptr<EndeavourRaw>(new + // EndeavourRawFTDI())); + + // setCalDAC(dynamic_cast<EndeavourRawYARR*>(m_pb->raw().get())->getDAC()); + // // not implemented, kept it just in case #else - throw NotSupportedException("PB communication not supported without YARR NETIO."); + throw NotSupportedException( + "PB communication not supported without YARR NETIO."); #endif } diff --git a/pbv3/PBv3TBNetIO.h b/pbv3/PBv3TBNetIO.h index 3baea3e005e9ccb13b2f040cda9ef131bfb22034..a4a4c06465bd738e474a1470ff523d0adae0b2b7 100644 --- a/pbv3/PBv3TBNetIO.h +++ b/pbv3/PBv3TBNetIO.h @@ -3,26 +3,25 @@ #include "PBv3TBDummy.h" -/** \brief Testbench for controlling a Powerboard with only an AMAC chip, connected via the GBT elinks, Felix board, and the Felixcore switch to NetIO. +/** \brief Testbench for controlling a Powerboard with only an AMAC chip, + * connected via the GBT elinks, Felix board, and the Felixcore switch to NetIO. * * It consists of an AMAC chip only. */ -class PBv3TBNetIO : public PBv3TBDummy -{ -public: - PBv3TBNetIO(); - ~PBv3TBNetIO(); +class PBv3TBNetIO : public PBv3TBDummy { + public: + PBv3TBNetIO(); + ~PBv3TBNetIO(); - void init(); - void setConfiguration(const nlohmann::json& config); + void init(); + void setConfiguration(const nlohmann::json& config); -private: - // the path to the netio config.json - std::string m_config_path = "./netio_config.json"; - // the amac ID - uint16_t m_amacid = 0x0; + private: + // the path to the netio config.json + std::string m_config_path = "./netio_config.json"; + // the amac ID + uint16_t m_amacid = 0x0; }; -#endif // PBV3TBNETIO_H - +#endif // PBV3TBNETIO_H diff --git a/pbv3/PBv3TBRegistry.cpp b/pbv3/PBv3TBRegistry.cpp index f254b2ab3a6ce8e62ce2a137850e2594324c1ed8..394c0c954b7ab1bc626e4684e915a9ed7e5b9142 100644 --- a/pbv3/PBv3TBRegistry.cpp +++ b/pbv3/PBv3TBRegistry.cpp @@ -3,39 +3,32 @@ #include <iostream> //#include "LabUtils/ClassRegistry.h" -//extern namespace EquipRegistry; +// extern namespace EquipRegistry; #include <ClassRegistry.h> using namespace EquipRegistry; -namespace PBv3TBRegistry -{ +namespace PBv3TBRegistry { - //typedef EquipRegistry::ClassRegistry<PBv3TB> RegistryPBv3TB; - typedef ClassRegistry<PBv3TB> RegistryPBv3TB; +// typedef EquipRegistry::ClassRegistry<PBv3TB> RegistryPBv3TB; +typedef ClassRegistry<PBv3TB> RegistryPBv3TB; - static RegistryPBv3TB ®istry() - { +static RegistryPBv3TB& registry() { static RegistryPBv3TB instance; return instance; - } +} - bool registerPBv3TB(const std::string& type, std::function<std::shared_ptr<PBv3TB>()> f) - { +bool registerPBv3TB(const std::string& type, + std::function<std::shared_ptr<PBv3TB>()> f) { return registry().registerClass(type, f); - } - - std::shared_ptr<PBv3TB> createPBv3TB(const std::string& type) - { +} + +std::shared_ptr<PBv3TB> createPBv3TB(const std::string& type) { std::shared_ptr<PBv3TB> result = registry().makeClass(type); - if(result == nullptr) - throw "No PBv3 testbench (PBv3TB) of type " +type+ " found\n"; + if (result == nullptr) + throw "No PBv3 testbench (PBv3TB) of type " + type + " found\n"; return result; - } - - std::vector<std::string> listPBv3TB() - { - return registry().listClasses(); - } } +std::vector<std::string> listPBv3TB() { return registry().listClasses(); } +} // namespace PBv3TBRegistry diff --git a/pbv3/PBv3TBRegistry.h b/pbv3/PBv3TBRegistry.h index 775e064afd42363ceb6b3893ae1db44818836dfc..534114460e33a3db2b4430ebfb4048b9c5e607ab 100644 --- a/pbv3/PBv3TBRegistry.h +++ b/pbv3/PBv3TBRegistry.h @@ -1,35 +1,34 @@ +#include <ClassRegistry.h> + #include <functional> #include <memory> #include <string> #include <vector> -#include <ClassRegistry.h> - #include "PBv3TB.h" // Registry for specific PBv3 test bench implementations -namespace PBv3TBRegistry -{ - /** \brief Register new PBv3TB implementation - * - * \param type Type of the implementation - * \param f functional wrapping the constructor - */ - bool registerPBv3TB(const std::string& type, - std::function<std::shared_ptr<PBv3TB>()> f); +namespace PBv3TBRegistry { +/** \brief Register new PBv3TB implementation + * + * \param type Type of the implementation + * \param f functional wrapping the constructor + */ +bool registerPBv3TB(const std::string& type, + std::function<std::shared_ptr<PBv3TB>()> f); - /** \brief Get new instance of given PBv3TB implementation - * - * \param type Type of the implementation - */ - std::shared_ptr<PBv3TB> createPBv3TB(const std::string& type); +/** \brief Get new instance of given PBv3TB implementation + * + * \param type Type of the implementation + */ +std::shared_ptr<PBv3TB> createPBv3TB(const std::string& type); - /** \brief List registered implementations - */ - std::vector<std::string> listPBv3TB(); -} +/** \brief List registered implementations + */ +std::vector<std::string> listPBv3TB(); +} // namespace PBv3TBRegistry -#define REGISTER_PBV3TB(type) \ - static bool _registered_##type = \ - PBv3TBRegistry::registerPBv3TB(#type, \ - std::function<std::shared_ptr<PBv3TB>()>([]() { return std::make_shared<type>(); })); +#define REGISTER_PBV3TB(type) \ + static bool _registered_##type = PBv3TBRegistry::registerPBv3TB( \ + #type, std::function<std::shared_ptr<PBv3TB>()>( \ + []() { return std::make_shared<type>(); })); diff --git a/pbv3/PBv3TBSingle.cpp b/pbv3/PBv3TBSingle.cpp index 3cb70253cf91711cb1ef77d8cd91c8d798bfe04a..67e29d01a9308d889d274c1148a514957b1bc659 100644 --- a/pbv3/PBv3TBSingle.cpp +++ b/pbv3/PBv3TBSingle.cpp @@ -1,161 +1,128 @@ #include "PBv3TBSingle.h" -#include "Logger.h" +#include <NotSupportedException.h> +#include <OutOfRangeException.h> #include "EndeavourRawFTDI.h" +#include "Logger.h" -#include <OutOfRangeException.h> -#include <NotSupportedException.h> - -//Register test bench +// Register test bench #include "PBv3TBRegistry.h" REGISTER_PBV3TB(PBv3TBSingle) -PBv3TBSingle::PBv3TBSingle() -: PBv3TB() -{ } - -PBv3TBSingle::~PBv3TBSingle() -{ } - -void PBv3TBSingle::setConfiguration(const nlohmann::json& config) -{ - for (const auto &kv : config.items()) - { - if(kv.key()=="bkdev") - { - m_bkdev=kv.value(); - } - if(kv.key()=="ftdi_serial") - { - m_ftdi_serial=kv.value(); - } - if(kv.key()=="ftdi_description") - { - m_ftdi_description=kv.value(); - } +PBv3TBSingle::PBv3TBSingle() : PBv3TB() {} + +PBv3TBSingle::~PBv3TBSingle() {} + +void PBv3TBSingle::setConfiguration(const nlohmann::json& config) { + for (const auto& kv : config.items()) { + if (kv.key() == "bkdev") { + m_bkdev = kv.value(); + } + if (kv.key() == "ftdi_serial") { + m_ftdi_serial = kv.value(); + } + if (kv.key() == "ftdi_description") { + m_ftdi_description = kv.value(); + } } - PBv3TB::setConfiguration(config); + PBv3TB::setConfiguration(config); } -void PBv3TBSingle::init() -{ - if(!m_bkdev.empty()) initLoad(); - initPB(); +void PBv3TBSingle::init() { + if (!m_bkdev.empty()) initLoad(); + initPB(); } -void PBv3TBSingle::initLoad() -{ - // - // Configure variable load - logger(logINFO) << "Init BK DCDC Load"; - m_load=std::make_shared<Bk85xx>(m_bkdev); - - m_load->setRemote(); - m_load->setRemoteSense(false); - m_load->setModeCC(); - m_load->setCurrent(0); +void PBv3TBSingle::initLoad() { + // + // Configure variable load + logger(logINFO) << "Init BK DCDC Load"; + m_load = std::make_shared<Bk85xx>(m_bkdev); + + m_load->setRemote(); + m_load->setRemoteSense(false); + m_load->setModeCC(); + m_load->setCurrent(0); } -void PBv3TBSingle::initPB() -{ - // - // Configure the AMAC +void PBv3TBSingle::initPB() { + // + // Configure the AMAC #ifdef FTDI - static const uint16_t amacid=0x0; + static const uint16_t amacid = 0x0; - m_pb=std::make_shared<AMACv2>(amacid, std::shared_ptr<EndeavourRaw>(new EndeavourRawFTDI(m_ftdi_description, m_ftdi_serial))); + m_pb = std::make_shared<AMACv2>( + amacid, std::shared_ptr<EndeavourRaw>( + new EndeavourRawFTDI(m_ftdi_description, m_ftdi_serial))); - setCalDAC(dynamic_cast<EndeavourRawFTDI*>(m_pb->raw().get())->getDAC()); + setCalDAC(dynamic_cast<EndeavourRawFTDI*>(m_pb->raw().get())->getDAC()); #else - throw NotSupportedException("PB communication not supported without FTDI."); + throw NotSupportedException("PB communication not supported without FTDI."); #endif } - -std::shared_ptr<AMACv2> PBv3TBSingle::getPB(uint8_t pbNum) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); - return m_pb; +std::shared_ptr<AMACv2> PBv3TBSingle::getPB(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); + return m_pb; } -void PBv3TBSingle::setOFin(uint8_t pbNum, bool value) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +void PBv3TBSingle::setOFin(uint8_t pbNum, bool value) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); #ifdef FTDI - dynamic_cast<EndeavourRawFTDI*>(m_pb->raw().get())->setOF(value); + dynamic_cast<EndeavourRawFTDI*>(m_pb->raw().get())->setOF(value); #else - throw NotSupportedException("PB communication not supported without FTDI."); + throw NotSupportedException("PB communication not supported without FTDI."); #endif } -double PBv3TBSingle::getVin() -{ - return getLVPS()->measureVoltage(); -} +double PBv3TBSingle::getVin() { return getLVPS()->measureVoltage(); } -double PBv3TBSingle::getIload(uint8_t pbNum) -{ - return m_load->getValues().cur; -} +double PBv3TBSingle::getIload(uint8_t pbNum) { return m_load->getValues().cur; } -std::shared_ptr<Bk85xx> PBv3TBSingle::getLoadPtr() -{ return m_load; } +std::shared_ptr<Bk85xx> PBv3TBSingle::getLoadPtr() { return m_load; } -void PBv3TBSingle::loadOn(uint8_t pbNum) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +void PBv3TBSingle::loadOn(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); - m_load->turnOn(); + m_load->turnOn(); } -void PBv3TBSingle::loadOff(uint8_t pbNum) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +void PBv3TBSingle::loadOff(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); - m_load->turnOff(); + m_load->turnOff(); } -double PBv3TBSingle::setLoad(uint8_t pbNum, double load) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +double PBv3TBSingle::setLoad(uint8_t pbNum, double load) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); - return 0.; // TODO implement + return 0.; // TODO implement } -double PBv3TBSingle::getLoad(uint8_t pbNum) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +double PBv3TBSingle::getLoad(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); - return m_load->getValues().cur*1e3; + return m_load->getValues().cur * 1e3; } -double PBv3TBSingle::getVout(uint8_t pbNum) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +double PBv3TBSingle::getVout(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); - return m_load->getValues().vol*1e3; + return m_load->getValues().vol * 1e3; } -double PBv3TBSingle::getHVoutCurrent(uint8_t pbNum) -{ - if(pbNum!=0) - throw OutOfRangeException(pbNum,0,0); +double PBv3TBSingle::getHVoutCurrent(uint8_t pbNum) { + if (pbNum != 0) throw OutOfRangeException(pbNum, 0, 0); - return 0.; // TODO implement + return 0.; // TODO implement } -double PBv3TBSingle::readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value) -{ - logger(logWARNING) << "Powerboard output reading not setup for single testbench."; +double PBv3TBSingle::readCarrierOutput(uint32_t pbNum, + PBv3TB::CARRIER_OUTPUT value) { + logger(logWARNING) + << "Powerboard output reading not setup for single testbench."; - return 0.; + return 0.; } diff --git a/pbv3/PBv3TBSingle.h b/pbv3/PBv3TBSingle.h index f7871a98e99d636346646b15d46ab29740da47c7..6f358a33db61a3f715551504f5d285e20c97b574 100644 --- a/pbv3/PBv3TBSingle.h +++ b/pbv3/PBv3TBSingle.h @@ -3,10 +3,9 @@ #include <memory> -#include "PBv3TB.h" - #include "Bk85xx.h" #include "Keithley24XX.h" +#include "PBv3TB.h" /** \brief Testbench for controlling a Powerboard on a single-board carrier. * @@ -15,80 +14,78 @@ * - External load (Bk85xx) * - FTDI-based communication dongle */ -class PBv3TBSingle : public PBv3TB -{ -public: - /** - * Constructor - */ - PBv3TBSingle(); - - virtual ~PBv3TBSingle(); - - - /** \brief Configure on JSON object - * - * Valid keys: - * - `ftdi_description`: Serial number of the FT232H dongle (default: None) - * - `ftdi_serial`: Product description of the FT232H dongle (default: None) - * - `bkdev`: Linux device for serial communication with the BK load - * - * \param config JSON configuration - */ - virtual void setConfiguration(const nlohmann::json& config); - - /** \brief Initialize testbench - * - * Calls `initLoad and initPB` - */ - virtual void init(); - - - std::shared_ptr<AMACv2> getPB(uint8_t pbNum); - - void setOFin(uint8_t pbNum, bool value); - - double getVin(); - double getIload(uint8_t pbNum); - - //! \brief Return a pointer to the load - std::shared_ptr<Bk85xx> getLoadPtr(); - void loadOn(uint8_t pbNum); - void loadOff(uint8_t pbNum); - double setLoad(uint8_t pbNum, double load); - double getLoad(uint8_t pbNum); - double getVout(uint8_t pbNum); - - double getHVoutCurrent(uint8_t pbNum); - - double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value); - -private: - /* - * \brief Initialize external load - * - * - Create object and initialize communication - * - Disable remote sense - */ - void initLoad(); - - /* - * \brief Initialize the PB communication object - */ - void initPB(); - -private: - //! Serial number of the FT232H dongle to use - std::string m_ftdi_serial; - - //! Product description of the FT232H dongle to use - std::string m_ftdi_description; - - //! Linux device for serial communication with the BK load - std::string m_bkdev; - - std::shared_ptr<Bk85xx> m_load =nullptr; - std::shared_ptr<AMACv2> m_pb =nullptr; +class PBv3TBSingle : public PBv3TB { + public: + /** + * Constructor + */ + PBv3TBSingle(); + + virtual ~PBv3TBSingle(); + + /** \brief Configure on JSON object + * + * Valid keys: + * - `ftdi_description`: Serial number of the FT232H dongle (default: None) + * - `ftdi_serial`: Product description of the FT232H dongle (default: + * None) + * - `bkdev`: Linux device for serial communication with the BK load + * + * \param config JSON configuration + */ + virtual void setConfiguration(const nlohmann::json& config); + + /** \brief Initialize testbench + * + * Calls `initLoad and initPB` + */ + virtual void init(); + + std::shared_ptr<AMACv2> getPB(uint8_t pbNum); + + void setOFin(uint8_t pbNum, bool value); + + double getVin(); + double getIload(uint8_t pbNum); + + //! \brief Return a pointer to the load + std::shared_ptr<Bk85xx> getLoadPtr(); + void loadOn(uint8_t pbNum); + void loadOff(uint8_t pbNum); + double setLoad(uint8_t pbNum, double load); + double getLoad(uint8_t pbNum); + double getVout(uint8_t pbNum); + + double getHVoutCurrent(uint8_t pbNum); + + double readCarrierOutput(uint32_t pbNum, PBv3TB::CARRIER_OUTPUT value); + + private: + /* + * \brief Initialize external load + * + * - Create object and initialize communication + * - Disable remote sense + */ + void initLoad(); + + /* + * \brief Initialize the PB communication object + */ + void initPB(); + + private: + //! Serial number of the FT232H dongle to use + std::string m_ftdi_serial; + + //! Product description of the FT232H dongle to use + std::string m_ftdi_description; + + //! Linux device for serial communication with the BK load + std::string m_bkdev; + + std::shared_ptr<Bk85xx> m_load = nullptr; + std::shared_ptr<AMACv2> m_pb = nullptr; }; -#endif // PBV3TBSINGLE_H +#endif // PBV3TBSINGLE_H diff --git a/pbv3/PBv3TestTools.cpp b/pbv3/PBv3TestTools.cpp index b4178641e28c634cb6dc6967b85baf0a7c805374..e672461af91eb6e7285ea7a976f7a81bfb0baff3 100644 --- a/pbv3/PBv3TestTools.cpp +++ b/pbv3/PBv3TestTools.cpp @@ -1,31 +1,31 @@ #include "PBv3TestTools.h" -#include "PBv3Utils.h" - #include "EndeavourComException.h" +#include "PBv3Utils.h" #ifdef FTDI #include "EndeavourRawFTDI.h" #endif -#include "DT54xxPs.h" - -#include <memory> #include <chrono> +#include <memory> -namespace PBv3TestTools -{ - json testLvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) - { - logger(logINFO) << "## Test LV_ENABLE ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +#include "DT54xxPs.h" + +namespace PBv3TestTools { +json testLvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) { + logger(logINFO) << "## Test LV_ENABLE ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "LV_ENABLE"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = false; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); - uint32_t DCDCen_curr=amac->rdField(&AMACv2RegMap::DCDCen); + uint32_t DCDCen_curr = amac->rdField(&AMACv2RegMap::DCDCen); // // Initialize @@ -45,38 +45,38 @@ namespace PBv3TestTools // read interesting values double lv_off = tb->getVout(pbNum); - double Iin = tb->getVinCurrent(); - double Vin = tb->getVin(); + double Iin = tb->getVinCurrent(); + double Vin = tb->getVin(); double iout = tb->getLoad(pbNum); - uint32_t Vdcdc = amac->readAM(AMACv2::AM::VDCDC ); - uint32_t VddLr = amac->readAM(AMACv2::AM::VDDLR ); - uint32_t DCDCin = amac->readAM(AMACv2::AM::DCDCIN); - uint32_t NTC = amac->readAM(AMACv2::AM::NTCPB ); - uint32_t Cur10V = amac->readAM(AMACv2::AM::CUR10V); - uint32_t Cur1V = amac->readAM(AMACv2::AM::CUR1V ); - uint32_t PTAT = amac->readAM(AMACv2::AM::PTAT ); - - testSum["results"]["DCDCen" ][0] = 0; - testSum["results"]["VIN" ][0] = Vin; - testSum["results"]["IIN" ][0] = Iin; - testSum["results"]["VOUT" ][0] = lv_off; - testSum["results"]["IOUT" ][0] = iout; - testSum["results"]["AMACVDCDC" ][0] = Vdcdc; - testSum["results"]["AMACVDDLR" ][0] = VddLr; + uint32_t Vdcdc = amac->readAM(AMACv2::AM::VDCDC); + uint32_t VddLr = amac->readAM(AMACv2::AM::VDDLR); + uint32_t DCDCin = amac->readAM(AMACv2::AM::DCDCIN); + uint32_t NTC = amac->readAM(AMACv2::AM::NTCPB); + uint32_t Cur10V = amac->readAM(AMACv2::AM::CUR10V); + uint32_t Cur1V = amac->readAM(AMACv2::AM::CUR1V); + uint32_t PTAT = amac->readAM(AMACv2::AM::PTAT); + + testSum["results"]["DCDCen"][0] = 0; + testSum["results"]["VIN"][0] = Vin; + testSum["results"]["IIN"][0] = Iin; + testSum["results"]["VOUT"][0] = lv_off; + testSum["results"]["IOUT"][0] = iout; + testSum["results"]["AMACVDCDC"][0] = Vdcdc; + testSum["results"]["AMACVDDLR"][0] = VddLr; testSum["results"]["AMACDCDCIN"][0] = DCDCin; - testSum["results"]["AMACNTCPB" ][0] = NTC; + testSum["results"]["AMACNTCPB"][0] = NTC; testSum["results"]["AMACCUR10V"][0] = Cur10V; - testSum["results"]["AMACCUR1V" ][0] = Cur1V; - testSum["results"]["AMACPTAT" ][0] = PTAT; + testSum["results"]["AMACCUR1V"][0] = Cur1V; + testSum["results"]["AMACPTAT"][0] = PTAT; bool pass_lv_off = (lv_off < 0.1); logger(logINFO) << " ---> VIN: " << Vin << " V"; logger(logINFO) << " ---> IIN: " << Iin << " A"; - if(pass_lv_off) - logger(logINFO) << " ---> VOUT: " << lv_off << " V"; + if (pass_lv_off) + logger(logINFO) << " ---> VOUT: " << lv_off << " V"; else - logger(logERROR) << " ---> VOUT: " << lv_off << " V"; + logger(logERROR) << " ---> VOUT: " << lv_off << " V"; // // Run test with output @@ -89,171 +89,177 @@ namespace PBv3TestTools std::this_thread::sleep_for(std::chrono::milliseconds(500)); double lv_on = tb->getVout(pbNum); - Iin = tb->getVinCurrent(); - Vin = tb->getVin(); + Iin = tb->getVinCurrent(); + Vin = tb->getVin(); iout = tb->getLoad(pbNum); - Vdcdc = amac->readAM(AMACv2::AM::VDCDC ); - VddLr = amac->readAM(AMACv2::AM::VDDLR ); - DCDCin= amac->readAM(AMACv2::AM::DCDCIN); - NTC = amac->readAM(AMACv2::AM::NTCPB ); - Cur10V= amac->readAM(AMACv2::AM::CUR10V); - Cur1V = amac->readAM(AMACv2::AM::CUR1V ); - PTAT = amac->readAM(AMACv2::AM::PTAT ); - - testSum["results"]["DCDCen" ][1] = 1; - testSum["results"]["VIN" ][1] = Vin; - testSum["results"]["IIN" ][1] = Iin; - testSum["results"]["VOUT" ][1] = lv_on; - testSum["results"]["IOUT" ][1] = iout; - testSum["results"]["AMACVDCDC" ][1] = Vdcdc; - testSum["results"]["AMACVDDLR" ][1] = VddLr; + Vdcdc = amac->readAM(AMACv2::AM::VDCDC); + VddLr = amac->readAM(AMACv2::AM::VDDLR); + DCDCin = amac->readAM(AMACv2::AM::DCDCIN); + NTC = amac->readAM(AMACv2::AM::NTCPB); + Cur10V = amac->readAM(AMACv2::AM::CUR10V); + Cur1V = amac->readAM(AMACv2::AM::CUR1V); + PTAT = amac->readAM(AMACv2::AM::PTAT); + + testSum["results"]["DCDCen"][1] = 1; + testSum["results"]["VIN"][1] = Vin; + testSum["results"]["IIN"][1] = Iin; + testSum["results"]["VOUT"][1] = lv_on; + testSum["results"]["IOUT"][1] = iout; + testSum["results"]["AMACVDCDC"][1] = Vdcdc; + testSum["results"]["AMACVDDLR"][1] = VddLr; testSum["results"]["AMACDCDCIN"][1] = DCDCin; - testSum["results"]["AMACNTCPB" ][1] = NTC; + testSum["results"]["AMACNTCPB"][1] = NTC; testSum["results"]["AMACCUR10V"][1] = Cur10V; - testSum["results"]["AMACCUR1V" ][1] = Cur1V; - testSum["results"]["AMACPTAT" ][1] = PTAT; + testSum["results"]["AMACCUR1V"][1] = Cur1V; + testSum["results"]["AMACPTAT"][1] = PTAT; bool pass_lv_on = (1.45 < lv_on && lv_on < 1.65); logger(logINFO) << " ---> VIN: " << Vin << " V"; logger(logINFO) << " ---> IIN: " << Iin << " A"; - if(pass_lv_on) - logger(logINFO) << " ---> VOUT: " << lv_on << " V"; + if (pass_lv_on) + logger(logINFO) << " ---> VOUT: " << lv_on << " V"; else - logger(logERROR) << " ---> VOUT: " << lv_on << " V"; + logger(logERROR) << " ---> VOUT: " << lv_on << " V"; testSum["passed"] = true; - if (!pass_lv_on || !pass_lv_off) - { - logger(logERROR) << " -> LV enable not working! " << lv_on << " " << lv_off; - testSum["passed"] = false; - } - - if(testSum["passed"]) - logger(logINFO) << " LV_ENABLE passed! :)"; + if (!pass_lv_on || !pass_lv_off) { + logger(logERROR) << " -> LV enable not working! " << lv_on << " " + << lv_off; + testSum["passed"] = false; + } + + if (testSum["passed"]) + logger(logINFO) << " LV_ENABLE passed! :)"; else - logger(logERROR) << " LV_ENABLE failed! :("; + logger(logERROR) << " LV_ENABLE failed! :("; - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::DCDCen , DCDCen_curr); + amac->wrField(&AMACv2RegMap::DCDCen, DCDCen_curr); amac->wrField(&AMACv2RegMap::DCDCenC, DCDCen_curr); // Disable load tb->loadOff(pbNum); - logger(logINFO) << "## End test LV_ENABLE ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## End test LV_ENABLE ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); return testSum; - } +} - json testDCDCAdj(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) { - logger(logINFO) << "## Test DCDC_ADJUST ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +json testDCDCAdj(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) { + logger(logINFO) << "## Test DCDC_ADJUST ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "DCDC_ADJUST"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = false; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); - uint32_t DCDCen_curr=amac->rdField(&AMACv2RegMap::DCDCen); - uint32_t DCDCAdj_curr=amac->rdField(&AMACv2RegMap::DCDCAdj); - //set small load + uint32_t DCDCen_curr = amac->rdField(&AMACv2RegMap::DCDCen); + uint32_t DCDCAdj_curr = amac->rdField(&AMACv2RegMap::DCDCAdj); + // set small load tb->loadOn(pbNum); logger(logINFO) << " -> Set load to 0.2A"; tb->setLoad(pbNum, 0.2); - //enable DCDC w/ no offset + // enable DCDC w/ no offset logger(logINFO) << " --> Enabling DCDCen"; amac->wrField(&AMACv2::DCDCen, 1); amac->wrField(&AMACv2::DCDCenC, 1); - float shifts [4]; - std::cout << std::scientific << std::setprecision(3) << "DCDCAdj" << "\t" << "VOUT" << std::endl; - for (int i = 0; i < 4; i++) - { + float shifts[4]; + std::cout << std::scientific << std::setprecision(3) << "DCDCAdj" + << "\t" + << "VOUT" << std::endl; + for (int i = 0; i < 4; i++) { amac->wrField(&AMACv2::DCDCAdj, i); amac->wrField(&AMACv2::DCDCAdjC, i); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); shifts[i] = tb->getVout(pbNum); - testSum["results"]["VOUT" ][i] = shifts[i]; + testSum["results"]["VOUT"][i] = shifts[i]; testSum["results"]["DCDCAdj"][i] = i; - std::cout << std::scientific << std::setprecision(3) << i << "\t" << shifts[i] << std::endl; - } - float minusSix = (shifts[1] - shifts[0])/shifts[0]; - float minusThirteen = (shifts[2] - shifts[0])/shifts[0]; - float plusSix = (shifts[3] - shifts[0])/shifts[0]; + std::cout << std::scientific << std::setprecision(3) << i << "\t" + << shifts[i] << std::endl; + } + float minusSix = (shifts[1] - shifts[0]) / shifts[0]; + float minusThirteen = (shifts[2] - shifts[0]) / shifts[0]; + float plusSix = (shifts[3] - shifts[0]) / shifts[0]; bool minusSixPass = (-.0767 < minusSix && minusSix < -.0567); bool minusThirteenPass = (-.143 < minusThirteen && minusThirteen < -.123); bool plusSixPass = (.0567 < plusSix && plusSix < .0767); - bool pass_dcdcadj = minusSixPass && minusThirteenPass && plusSixPass; + bool pass_dcdcadj = minusSixPass && minusThirteenPass && plusSixPass; - if (minusThirteenPass) - { + if (minusThirteenPass) { logger(logINFO) << " ---> minusThirteen: " << minusThirteen; - } - else - { + } else { logger(logERROR) << " ---> minusThirteen: " << minusThirteen; - } - - if (minusSixPass) - { + } + + if (minusSixPass) { logger(logINFO) << " ---> minusSix: " << minusSix; - } - else - { + } else { logger(logERROR) << " ---> minusSix: " << minusSix; - } + } - if (plusSixPass) - { + if (plusSixPass) { logger(logINFO) << " ---> plusSix: " << plusSix; - } - else - { + } else { logger(logERROR) << " ---> plusSix: " << plusSix; - } - + } + testSum["passed"] = pass_dcdcadj; - - if(testSum["passed"]) - { logger(logINFO) << " DCDCAdj passed! :)"; } - else - { logger(logERROR) << " DCDCAdj failed! :("; } - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + if (testSum["passed"]) { + logger(logINFO) << " DCDCAdj passed! :)"; + } else { + logger(logERROR) << " DCDCAdj failed! :("; + } + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::DCDCen , DCDCen_curr); + amac->wrField(&AMACv2RegMap::DCDCen, DCDCen_curr); amac->wrField(&AMACv2RegMap::DCDCenC, DCDCen_curr); amac->wrField(&AMACv2RegMap::DCDCAdj, DCDCAdj_curr); - amac->wrField(&AMACv2RegMap::DCDCAdjC,DCDCAdj_curr); + amac->wrField(&AMACv2RegMap::DCDCAdjC, DCDCAdj_curr); // Disable load tb->loadOff(pbNum); - logger(logINFO) << "## End test DCDC_ADJUST ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + logger(logINFO) << "## End test DCDC_ADJUST ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); return testSum; - } +} - // Range is iout in A - json measureEfficiency(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, double step, double min, double max, double VinSet, uint32_t trails) - { - logger(logINFO) << "## Measuring DCDC efficiency ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +// Range is iout in A +json measureEfficiency(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, double step, + double min, double max, double VinSet, uint32_t trails) { + logger(logINFO) << "## Measuring DCDC efficiency ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "DCDCEFFICIENCY"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); // Store current state - uint32_t DCDCen_curr =amac->rdField(&AMACv2RegMap::DCDCen ); - uint32_t DCDCenC_curr=amac->rdField(&AMACv2RegMap::DCDCenC); - uint32_t Ch12Mux_curr=amac->rdField(&AMACv2RegMap::Ch12Mux); - uint32_t Ch13Mux_curr=amac->rdField(&AMACv2RegMap::Ch13Mux); + uint32_t DCDCen_curr = amac->rdField(&AMACv2RegMap::DCDCen); + uint32_t DCDCenC_curr = amac->rdField(&AMACv2RegMap::DCDCenC); + uint32_t Ch12Mux_curr = amac->rdField(&AMACv2RegMap::Ch12Mux); + uint32_t Ch13Mux_curr = amac->rdField(&AMACv2RegMap::Ch13Mux); // // Initialize @@ -269,7 +275,7 @@ namespace PBv3TestTools amac->wrField(&AMACv2RegMap::DCDCen, 0); amac->wrField(&AMACv2RegMap::DCDCenC, 0); std::this_thread::sleep_for(std::chrono::milliseconds(500)); - + double Iin_offset = tb->getVinCurrent(); logger(logINFO) << " --> Get baseline current: (" << Iin_offset << ")A"; testSum["results"]["IINOFFSET"] = Iin_offset; @@ -278,74 +284,96 @@ namespace PBv3TestTools amac->wrField(&AMACv2RegMap::DCDCen, 1); amac->wrField(&AMACv2RegMap::DCDCenC, 1); - //unsigned dwell_time = .1; //s - unsigned dwell_time_s = .005; //s - unsigned dwell_time = 5; //s - testSum["properties"]["DWELLTIMELONG" ] = dwell_time; + // unsigned dwell_time = .1; //s + unsigned dwell_time_s = .005; // s + unsigned dwell_time = 5; // s + testSum["properties"]["DWELLTIMELONG"] = dwell_time; testSum["properties"]["DWELLTIMESHORT"] = dwell_time_s; logger(logINFO) << " --> Starting measurement ..."; - std::cout << "VIN" << "\t" << "IIN" << "\t" << "VOUT" << "\t" << "IOUT" << "\t" << "IOUTSET" << "\t" << "AMACVDCDC" - << "\t" << "AMACVDDLR" << "\t" << "AMACDCDCIN" << "\t" << "AMACNTCPB" << "\t" - << "AMACCUR10V" << "\t" << "AMACCUR1V" << "\t" << "AMACPTAT" << "\t" << "EFFICIENCY" << std::endl; + std::cout << "VIN" + << "\t" + << "IIN" + << "\t" + << "VOUT" + << "\t" + << "IOUT" + << "\t" + << "IOUTSET" + << "\t" + << "AMACVDCDC" + << "\t" + << "AMACVDDLR" + << "\t" + << "AMACDCDCIN" + << "\t" + << "AMACNTCPB" + << "\t" + << "AMACCUR10V" + << "\t" + << "AMACCUR1V" + << "\t" + << "AMACPTAT" + << "\t" + << "EFFICIENCY" << std::endl; // Set sub-channel - amac->wrField(&AMACv2RegMap::Ch12Mux, 0); //a - amac->wrField(&AMACv2RegMap::Ch13Mux, 0); //a + amac->wrField(&AMACv2RegMap::Ch12Mux, 0); // a + amac->wrField(&AMACv2RegMap::Ch13Mux, 0); // a // Loop over currents int index = 0; - for (double iout=min;iout<=max;iout+=step) - { - //allowing system to reach thermal equilibrium - std::this_thread::sleep_for(std::chrono::seconds(dwell_time)); - logger(logDEBUG) << " --> Setting " << iout << "mA load!"; - // Set Current + for (double iout = min; iout <= max; iout += step) { + // allowing system to reach thermal equilibrium + std::this_thread::sleep_for(std::chrono::seconds(dwell_time)); + logger(logDEBUG) << " --> Setting " << iout << "mA load!"; + // Set Current tb->setLoad(pbNum, iout); - // Wait for temp and everything to settle - std::this_thread::sleep_for(std::chrono::seconds(dwell_time_s)); - - // Read AMAC values - uint32_t Vdcdc, VddLr, DCDCin, NTC, Cur10V, Cur1V, PTAT; - - for(uint32_t trail=0; trail<trails; trail++) - { - Vdcdc = amac->readAM(AMACv2::AM::VDCDC ); - VddLr = amac->readAM(AMACv2::AM::VDDLR ); - DCDCin= amac->readAM(AMACv2::AM::DCDCIN); - NTC = amac->readAM(AMACv2::AM::NTCPB ); - Cur10V= amac->readAM(AMACv2::AM::CUR10V); - Cur1V = amac->readAM(AMACv2::AM::CUR1V ); - PTAT = amac->readAM(AMACv2::AM::PTAT ); - - double Vin = tb->getVin(); - double Iin = tb->getVinCurrent(); - double Iout = tb->getIload(pbNum); - - double Vout = tb->getVout(pbNum); - - double efficiency = (Vout*Iout)/(Vin*(Iin-Iin_offset)); - std::cout << Vin << "\t" << Iin << "\t" << Vout << "\t" << Iout << "\t" << iout << "\t" << Vdcdc - << "\t" << VddLr << "\t" << DCDCin << "\t" << NTC << "\t" - << Cur10V << "\t" << Cur1V << "\t" << PTAT << "\t" << efficiency << std::endl; - testSum["results"]["VIN" ][index] = Vin; - testSum["results"]["IIN" ][index] = Iin; - testSum["results"]["VOUT" ][index] = Vout; - testSum["results"]["IOUT" ][index] = Iout; - testSum["results"]["IOUTSET" ][index] = iout; - testSum["results"]["AMACVDCDC" ][index] = Vdcdc; - testSum["results"]["AMACVDDLR" ][index] = VddLr; - testSum["results"]["AMACDCDCIN"][index] = DCDCin; - testSum["results"]["AMACNTCPB" ][index] = NTC; - testSum["results"]["AMACCUR10V"][index] = Cur10V; - testSum["results"]["AMACCUR1V" ][index] = Cur1V; - testSum["results"]["AMACPTAT" ][index] = PTAT; - testSum["results"]["EFFICIENCY"][index] = efficiency; - - index++; - } - } + // Wait for temp and everything to settle + std::this_thread::sleep_for(std::chrono::seconds(dwell_time_s)); + + // Read AMAC values + uint32_t Vdcdc, VddLr, DCDCin, NTC, Cur10V, Cur1V, PTAT; + + for (uint32_t trail = 0; trail < trails; trail++) { + Vdcdc = amac->readAM(AMACv2::AM::VDCDC); + VddLr = amac->readAM(AMACv2::AM::VDDLR); + DCDCin = amac->readAM(AMACv2::AM::DCDCIN); + NTC = amac->readAM(AMACv2::AM::NTCPB); + Cur10V = amac->readAM(AMACv2::AM::CUR10V); + Cur1V = amac->readAM(AMACv2::AM::CUR1V); + PTAT = amac->readAM(AMACv2::AM::PTAT); + + double Vin = tb->getVin(); + double Iin = tb->getVinCurrent(); + double Iout = tb->getIload(pbNum); + + double Vout = tb->getVout(pbNum); + + double efficiency = (Vout * Iout) / (Vin * (Iin - Iin_offset)); + std::cout << Vin << "\t" << Iin << "\t" << Vout << "\t" << Iout + << "\t" << iout << "\t" << Vdcdc << "\t" << VddLr << "\t" + << DCDCin << "\t" << NTC << "\t" << Cur10V << "\t" + << Cur1V << "\t" << PTAT << "\t" << efficiency + << std::endl; + testSum["results"]["VIN"][index] = Vin; + testSum["results"]["IIN"][index] = Iin; + testSum["results"]["VOUT"][index] = Vout; + testSum["results"]["IOUT"][index] = Iout; + testSum["results"]["IOUTSET"][index] = iout; + testSum["results"]["AMACVDCDC"][index] = Vdcdc; + testSum["results"]["AMACVDDLR"][index] = VddLr; + testSum["results"]["AMACDCDCIN"][index] = DCDCin; + testSum["results"]["AMACNTCPB"][index] = NTC; + testSum["results"]["AMACCUR10V"][index] = Cur10V; + testSum["results"]["AMACCUR1V"][index] = Cur1V; + testSum["results"]["AMACPTAT"][index] = PTAT; + testSum["results"]["EFFICIENCY"][index] = efficiency; + + index++; + } + } logger(logINFO) << " --> Done!! Turning off load!"; @@ -353,45 +381,50 @@ namespace PBv3TestTools tb->loadOff(pbNum); // Revert to old state - amac->wrField(&AMACv2RegMap::DCDCen , DCDCen_curr ); + amac->wrField(&AMACv2RegMap::DCDCen, DCDCen_curr); amac->wrField(&AMACv2RegMap::DCDCenC, DCDCenC_curr); amac->wrField(&AMACv2RegMap::Ch12Mux, Ch12Mux_curr); amac->wrField(&AMACv2RegMap::Ch13Mux, Ch13Mux_curr); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); return testSum; - } +} - json testHvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, unsigned frequency) - { - logger(logINFO) << "## Test HV_ENABLE ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json testHvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + unsigned frequency) { + logger(logINFO) << "## Test HV_ENABLE ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "HV_ENABLE"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = false; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - std::shared_ptr<PowerSupplyChannel> hv=tb->getHVPS(); + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + std::shared_ptr<PowerSupplyChannel> hv = tb->getHVPS(); - uint32_t CntSetHV0frq_curr =amac->rdField(&AMACv2RegMap::CntSetHV0frq ); - uint32_t CntSetCHV0frq_curr=amac->rdField(&AMACv2RegMap::CntSetCHV0frq); - uint32_t CntSetHV0en_curr =amac->rdField(&AMACv2RegMap::CntSetHV0en ); - uint32_t CntSetCHV0en_curr =amac->rdField(&AMACv2RegMap::CntSetCHV0en ); - uint32_t HVcurGain_curr =amac->rdField(&AMACv2RegMap::HVcurGain ); + uint32_t CntSetHV0frq_curr = amac->rdField(&AMACv2RegMap::CntSetHV0frq); + uint32_t CntSetCHV0frq_curr = amac->rdField(&AMACv2RegMap::CntSetCHV0frq); + uint32_t CntSetHV0en_curr = amac->rdField(&AMACv2RegMap::CntSetHV0en); + uint32_t CntSetCHV0en_curr = amac->rdField(&AMACv2RegMap::CntSetCHV0en); + uint32_t HVcurGain_curr = amac->rdField(&AMACv2RegMap::HVcurGain); logger(logINFO) << " ---> HVcurGain: " << 4; amac->wrField(&AMACv2RegMap::HVcurGain, 4); - logger(logINFO) << " ---> CntSetHV0frq: " << frequency << " # 0=high, 1=25kHz, 2=50kHz, 3=100kHz"; + logger(logINFO) << " ---> CntSetHV0frq: " << frequency + << " # 0=high, 1=25kHz, 2=50kHz, 3=100kHz"; amac->wrField(&AMACv2::CntSetHV0frq, frequency); amac->wrField(&AMACv2::CntSetCHV0frq, frequency); // Configure PS logger(logINFO) << " -> Turning everything off."; hv->turnOff(); - hv->setVoltageLevel (0); + hv->setVoltageLevel(0); hv->setCurrentProtect(1e-3); // See what we see @@ -404,7 +437,7 @@ namespace PBv3TestTools logger(logINFO) << " --> Disabling CntSetHV0en"; amac->wrField(&AMACv2::CntSetHV0en, 0); amac->wrField(&AMACv2::CntSetCHV0en, 0); - std::this_thread::sleep_for(std::chrono::seconds(2)); // wait to stabilize + std::this_thread::sleep_for(std::chrono::seconds(2)); // wait to stabilize // // Measure OFF state @@ -414,38 +447,38 @@ namespace PBv3TestTools uint32_t HVret_off = amac->rdField(&AMACv2RegMap::Ch14Value); testSum["results"]["CntSetHV0frq"][0] = frequency; - testSum["results"]["CntSetHV0en" ][0] = 0; - testSum["results"]["HVcurGain" ][0] = 4; - testSum["results"]["HVVIN" ][0] = hv_v_off; - testSum["results"]["HVIIN" ][0] = hv_i_off; - testSum["results"]["HVIOUT" ][0] = hvout_i_off; - testSum["results"]["AMACHVRET" ][0] = HVret_off; + testSum["results"]["CntSetHV0en"][0] = 0; + testSum["results"]["HVcurGain"][0] = 4; + testSum["results"]["HVVIN"][0] = hv_v_off; + testSum["results"]["HVIIN"][0] = hv_i_off; + testSum["results"]["HVIOUT"][0] = hvout_i_off; + testSum["results"]["AMACHVRET"][0] = HVret_off; // Check status - bool pass_hv_v_off = hv_v_off>450; - bool pass_HVret_off = HVret_off<200; - bool pass_hvout_i_off = hvout_i_off <2e-6; + bool pass_hv_v_off = hv_v_off > 450; + bool pass_HVret_off = HVret_off < 200; + bool pass_hvout_i_off = hvout_i_off < 2e-6; - if(pass_hv_v_off) - logger(logINFO) << " ---> HVVIN: " << hv_v_off << " V"; + if (pass_hv_v_off) + logger(logINFO) << " ---> HVVIN: " << hv_v_off << " V"; else - logger(logERROR) << " ---> HVVIN: " << hv_v_off << " V"; + logger(logERROR) << " ---> HVVIN: " << hv_v_off << " V"; logger(logINFO) << " ---> HVIIN: " << hv_i_off << " A"; - if(pass_hvout_i_off) - logger(logINFO) << " ---> HVIOUT: " << hvout_i_off << " A"; + if (pass_hvout_i_off) + logger(logINFO) << " ---> HVIOUT: " << hvout_i_off << " A"; else - logger(logERROR) << " ---> HVIOUT: " << hvout_i_off << " A"; - if(pass_HVret_off) - logger(logINFO) << " ---> AMACHVRET: " << HVret_off; + logger(logERROR) << " ---> HVIOUT: " << hvout_i_off << " A"; + if (pass_HVret_off) + logger(logINFO) << " ---> AMACHVRET: " << HVret_off; else - logger(logERROR) << " ---> AMACHVRET: " << HVret_off; + logger(logERROR) << " ---> AMACHVRET: " << HVret_off; // // Measure ON state logger(logINFO) << " --> Enabling CntSetHV0en"; - amac->wrField(&AMACv2::CntSetHV0en , 1); + amac->wrField(&AMACv2::CntSetHV0en, 1); amac->wrField(&AMACv2::CntSetCHV0en, 1); - std::this_thread::sleep_for(std::chrono::seconds(2)); // wait to stabilize + std::this_thread::sleep_for(std::chrono::seconds(2)); // wait to stabilize std::this_thread::sleep_for(std::chrono::milliseconds(5000)); double hv_v_on = fabs(hv->measureVoltage()); @@ -454,35 +487,35 @@ namespace PBv3TestTools uint32_t HVret_on = amac->rdField(&AMACv2RegMap::Ch14Value); testSum["results"]["CntSetHV0frq"][1] = frequency; - testSum["results"]["CntSetHV0en" ][1] = 1; - testSum["results"]["HVcurGain" ][1] = 4; - testSum["results"]["HVVIN" ][1] = hv_v_on; - testSum["results"]["HVIIN" ][1] = hv_i_on; - testSum["results"]["HVIOUT" ][1] = hvout_i_on; - testSum["results"]["AMACHVRET" ][1] = HVret_on; + testSum["results"]["CntSetHV0en"][1] = 1; + testSum["results"]["HVcurGain"][1] = 4; + testSum["results"]["HVVIN"][1] = hv_v_on; + testSum["results"]["HVIIN"][1] = hv_i_on; + testSum["results"]["HVIOUT"][1] = hvout_i_on; + testSum["results"]["AMACHVRET"][1] = HVret_on; // Check status - bool pass_hv_v_on = hv_v_on>450; - bool pass_HVret_on = HVret_on>300; + bool pass_hv_v_on = hv_v_on > 450; + bool pass_HVret_on = HVret_on > 300; bool pass_hv_i = (hv_i_on - hv_i_off) > 0.8e-3; bool pass_hvout_i_on = hvout_i_on > 0.8e-3; - if(pass_hv_v_on) - logger(logINFO) << " ---> HVVIN: " << hv_v_on << " V"; + if (pass_hv_v_on) + logger(logINFO) << " ---> HVVIN: " << hv_v_on << " V"; else - logger(logERROR) << " ---> HVVIN: " << hv_v_on << " V"; - if(pass_hv_i) - logger(logINFO) << " ---> HVIIN: " << hv_i_on << " A"; + logger(logERROR) << " ---> HVVIN: " << hv_v_on << " V"; + if (pass_hv_i) + logger(logINFO) << " ---> HVIIN: " << hv_i_on << " A"; else - logger(logERROR) << " ---> HVIIN: " << hv_i_on << " A"; - if(pass_hvout_i_on) - logger(logINFO) << " ---> HVIOUT: " << hvout_i_on << " A"; + logger(logERROR) << " ---> HVIIN: " << hv_i_on << " A"; + if (pass_hvout_i_on) + logger(logINFO) << " ---> HVIOUT: " << hvout_i_on << " A"; else - logger(logERROR) << " ---> HVIOUT: " << hvout_i_on << " A"; - if(pass_HVret_on) - logger(logINFO) << " ---> AMACHVRET: " << HVret_on; + logger(logERROR) << " ---> HVIOUT: " << hvout_i_on << " A"; + if (pass_HVret_on) + logger(logINFO) << " ---> AMACHVRET: " << HVret_on; else - logger(logERROR) << " ---> AMACHVRET: " << HVret_on; + logger(logERROR) << " ---> AMACHVRET: " << HVret_on; // Done... logger(logINFO) << " -> Turning off HVPS"; @@ -492,199 +525,213 @@ namespace PBv3TestTools // Error checking testSum["passed"] = true; - if (!pass_hv_v_on || !pass_hv_v_off) - { - logger(logERROR) << " -> HV power supply cannot reach nominal voltage..."; - testSum["passed"] = false; - } - - if (!pass_hv_i) - { - logger(logERROR) << " -> HV current does not change on toggle! (ΔI = " << hv_i_on - hv_i_off << " A)"; - testSum["passed"] = false; - } - - - if (!pass_hvout_i_on || !pass_hvout_i_off) - { - logger(logERROR) << " -> HV sensor current is wrong!"; - testSum["passed"] = false; - } - - if (!pass_HVret_on || !pass_HVret_off) - { - logger(logERROR) << " -> AMAC does not see a change in HV current!"; - testSum["passed"] = false; - } - - if(testSum["passed"]) - logger(logINFO) << " HV_ENABLE passed! :)"; + if (!pass_hv_v_on || !pass_hv_v_off) { + logger(logERROR) + << " -> HV power supply cannot reach nominal voltage..."; + testSum["passed"] = false; + } + + if (!pass_hv_i) { + logger(logERROR) << " -> HV current does not change on toggle! (ΔI = " + << hv_i_on - hv_i_off << " A)"; + testSum["passed"] = false; + } + + if (!pass_hvout_i_on || !pass_hvout_i_off) { + logger(logERROR) << " -> HV sensor current is wrong!"; + testSum["passed"] = false; + } + + if (!pass_HVret_on || !pass_HVret_off) { + logger(logERROR) << " -> AMAC does not see a change in HV current!"; + testSum["passed"] = false; + } + + if (testSum["passed"]) + logger(logINFO) << " HV_ENABLE passed! :)"; else - logger(logERROR) << " HV_ENABLE failed! :("; - logger(logINFO) << "## End test HV_ENABLE ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logERROR) << " HV_ENABLE failed! :("; + logger(logINFO) << "## End test HV_ENABLE ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::CntSetHV0frq , CntSetHV0frq_curr ); + amac->wrField(&AMACv2RegMap::CntSetHV0frq, CntSetHV0frq_curr); amac->wrField(&AMACv2RegMap::CntSetCHV0frq, CntSetCHV0frq_curr); - amac->wrField(&AMACv2RegMap::CntSetHV0en , CntSetHV0en_curr ); - amac->wrField(&AMACv2RegMap::CntSetCHV0en , CntSetCHV0en_curr ); - amac->wrField(&AMACv2RegMap::HVcurGain , HVcurGain_curr ); - + amac->wrField(&AMACv2RegMap::CntSetHV0en, CntSetHV0en_curr); + amac->wrField(&AMACv2RegMap::CntSetCHV0en, CntSetCHV0en_curr); + amac->wrField(&AMACv2RegMap::HVcurGain, HVcurGain_curr); + return testSum; - } +} - json readStatus(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupplyChannel> lv, std::shared_ptr<Bk85xx> load, std::shared_ptr<PowerSupplyChannel> hv, uint32_t tests) - { - logger(logINFO) << "## Reading current status ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json readStatus(std::shared_ptr<AMACv2> amac, + std::shared_ptr<PowerSupplyChannel> lv, + std::shared_ptr<Bk85xx> load, + std::shared_ptr<PowerSupplyChannel> hv, uint32_t tests) { + logger(logINFO) << "## Reading current status ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "STATUS"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - for(uint32_t index=0; index<tests; index++) - { - // ADCs - uint32_t Vdcdc = amac->readAM(AMACv2::AM::VDCDC ); - uint32_t VddLr = amac->readAM(AMACv2::AM::VDDLR ); - uint32_t DCDCin = amac->readAM(AMACv2::AM::DCDCIN ); - uint32_t VDDREG = amac->readAM(AMACv2::AM::VDDREG ); - uint32_t AM900BG = amac->readAM(AMACv2::AM::AM900BG); - uint32_t AM600BG = amac->readAM(AMACv2::AM::AM600BG); - uint32_t CALin = amac->readAM(AMACv2::AM::CAL ); - uint32_t CTAT = amac->readAM(AMACv2::AM::CTAT ); - uint32_t NTCx = amac->readAM(AMACv2::AM::NTCX ); - uint32_t NTCy = amac->readAM(AMACv2::AM::NTCY ); - uint32_t NTCpb = amac->readAM(AMACv2::AM::NTCPB ); - uint32_t Cur10V = amac->readAM(AMACv2::AM::CUR10V ); - uint32_t Cur1V = amac->readAM(AMACv2::AM::CUR1V ); - uint32_t HVret = amac->readAM(AMACv2::AM::HVRET ); - uint32_t PTAT = amac->readAM(AMACv2::AM::PTAT ); - - double Vin = (lv!=nullptr)? lv->measureVoltage() : 0.; - double Iin = (lv!=nullptr)? lv->measureCurrent() : 0.; - - double Vout = (load!=nullptr)? load->getValues().vol*1e-3 : 0.; - double Iout = (load!=nullptr)? load->getValues().cur*1e-3 : 0.; - - double HV_Vin = (hv!=nullptr)? hv->measureVoltage() : 0.; - double HV_Iin = (hv!=nullptr)? hv->measureCurrent() : 0.; - - double ADC0 = 0.; - double ADC1 = 0.; - double ADC2 = 0.; - double ADC3 = 0.; + for (uint32_t index = 0; index < tests; index++) { + // ADCs + uint32_t Vdcdc = amac->readAM(AMACv2::AM::VDCDC); + uint32_t VddLr = amac->readAM(AMACv2::AM::VDDLR); + uint32_t DCDCin = amac->readAM(AMACv2::AM::DCDCIN); + uint32_t VDDREG = amac->readAM(AMACv2::AM::VDDREG); + uint32_t AM900BG = amac->readAM(AMACv2::AM::AM900BG); + uint32_t AM600BG = amac->readAM(AMACv2::AM::AM600BG); + uint32_t CALin = amac->readAM(AMACv2::AM::CAL); + uint32_t CTAT = amac->readAM(AMACv2::AM::CTAT); + uint32_t NTCx = amac->readAM(AMACv2::AM::NTCX); + uint32_t NTCy = amac->readAM(AMACv2::AM::NTCY); + uint32_t NTCpb = amac->readAM(AMACv2::AM::NTCPB); + uint32_t Cur10V = amac->readAM(AMACv2::AM::CUR10V); + uint32_t Cur1V = amac->readAM(AMACv2::AM::CUR1V); + uint32_t HVret = amac->readAM(AMACv2::AM::HVRET); + uint32_t PTAT = amac->readAM(AMACv2::AM::PTAT); + + double Vin = (lv != nullptr) ? lv->measureVoltage() : 0.; + double Iin = (lv != nullptr) ? lv->measureCurrent() : 0.; + + double Vout = (load != nullptr) ? load->getValues().vol * 1e-3 : 0.; + double Iout = (load != nullptr) ? load->getValues().cur * 1e-3 : 0.; + + double HV_Vin = (hv != nullptr) ? hv->measureVoltage() : 0.; + double HV_Iin = (hv != nullptr) ? hv->measureCurrent() : 0.; + + double ADC0 = 0.; + double ADC1 = 0.; + double ADC2 = 0.; + double ADC3 = 0.; #ifdef FTDI - EndeavourRawFTDI* ftdiobj=dynamic_cast<EndeavourRawFTDI*>(amac->raw().get()); - if(ftdiobj!=nullptr) - { - ADC0 = ftdiobj->getADC()->read(0); - ADC1 = ftdiobj->getADC()->read(1); - ADC2 = ftdiobj->getADC()->read(2); - ADC3 = ftdiobj->getADC()->read(3); - } + EndeavourRawFTDI* ftdiobj = + dynamic_cast<EndeavourRawFTDI*>(amac->raw().get()); + if (ftdiobj != nullptr) { + ADC0 = ftdiobj->getADC()->read(0); + ADC1 = ftdiobj->getADC()->read(1); + ADC2 = ftdiobj->getADC()->read(2); + ADC3 = ftdiobj->getADC()->read(3); + } #endif - std::cout << "Vdcdc\tVddLr\tDCDCin\tVddReg\t" << - "Am900Bg\tAm600Bg\tCal" << - "\tCTAT\tNTCx\tNTCy\tNTCpb\tCur10V\t" << - "Cur1V\tHVret\tPTAT\tVin\tIin\tVout\tIout\t" << - "HV_Vin\tHV_Iin\tADC0\tADC1\tADC2\tADC3" << std::endl; - std::cout << Vdcdc << "\t" << VddLr << "\t" << DCDCin << "\t" << VDDREG << "\t" << AM900BG - << "\t" << AM600BG << "\t" << CALin - << "\t" << CTAT << "\t" << NTCx << "\t" << NTCy << "\t" << NTCpb << "\t" << Cur10V << "\t" << Cur1V - << "\t" << HVret << "\t" << PTAT << "\t" << Vin << "\t" << Iin << "\t" << Vout << "\t" - << Iout << "\t" << HV_Vin << "\t" << HV_Iin << "\t" << ADC0 << "\t" << ADC1 << "\t" << ADC2 << "\t" << ADC3 << std::endl; - - testSum["results"]["AMACVDCDC" ][index]=Vdcdc; - testSum["results"]["AMACVDDLR" ][index]=VddLr; - testSum["results"]["AMACDCDCIN" ][index]=DCDCin; - testSum["results"]["AMACVDDREG" ][index]=VDDREG; - testSum["results"]["AMACAM900BG"][index]=AM900BG; - testSum["results"]["AMACAM600BG"][index]=AM600BG; - testSum["results"]["AMACCAL" ][index]=CALin; - testSum["results"]["AMACCTAT" ][index]=CTAT; - testSum["results"]["AMACNTCX" ][index]=NTCx; - testSum["results"]["AMACNTCY" ][index]=NTCy; - testSum["results"]["AMACNTCPB" ][index]=NTCpb; - testSum["results"]["AMACCUR10V" ][index]=Cur10V; - testSum["results"]["AMACCUR1V" ][index]=Cur1V; - testSum["results"]["AMACHVRET" ][index]=HVret; - testSum["results"]["AMACPTAT" ][index]=PTAT; - testSum["results"]["VIN" ][index]=Vin; - testSum["results"]["IIN" ][index]=Iin; - testSum["results"]["VOUT" ][index]=Vout*1e-3; - testSum["results"]["IOUT" ][index]=Iout*1e-3; - testSum["results"]["HVVIN" ][index]=HV_Vin; - testSum["results"]["HVIIN" ][index]=HV_Iin; - testSum["results"]["ADC0" ][index]=ADC0; - testSum["results"]["ADC1" ][index]=ADC1; - testSum["results"]["ADC2" ][index]=ADC2; - testSum["results"]["ADC3" ][index]=ADC3; - } - - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + std::cout << "Vdcdc\tVddLr\tDCDCin\tVddReg\t" + << "Am900Bg\tAm600Bg\tCal" + << "\tCTAT\tNTCx\tNTCy\tNTCpb\tCur10V\t" + << "Cur1V\tHVret\tPTAT\tVin\tIin\tVout\tIout\t" + << "HV_Vin\tHV_Iin\tADC0\tADC1\tADC2\tADC3" << std::endl; + std::cout << Vdcdc << "\t" << VddLr << "\t" << DCDCin << "\t" << VDDREG + << "\t" << AM900BG << "\t" << AM600BG << "\t" << CALin << "\t" + << CTAT << "\t" << NTCx << "\t" << NTCy << "\t" << NTCpb + << "\t" << Cur10V << "\t" << Cur1V << "\t" << HVret << "\t" + << PTAT << "\t" << Vin << "\t" << Iin << "\t" << Vout << "\t" + << Iout << "\t" << HV_Vin << "\t" << HV_Iin << "\t" << ADC0 + << "\t" << ADC1 << "\t" << ADC2 << "\t" << ADC3 << std::endl; + + testSum["results"]["AMACVDCDC"][index] = Vdcdc; + testSum["results"]["AMACVDDLR"][index] = VddLr; + testSum["results"]["AMACDCDCIN"][index] = DCDCin; + testSum["results"]["AMACVDDREG"][index] = VDDREG; + testSum["results"]["AMACAM900BG"][index] = AM900BG; + testSum["results"]["AMACAM600BG"][index] = AM600BG; + testSum["results"]["AMACCAL"][index] = CALin; + testSum["results"]["AMACCTAT"][index] = CTAT; + testSum["results"]["AMACNTCX"][index] = NTCx; + testSum["results"]["AMACNTCY"][index] = NTCy; + testSum["results"]["AMACNTCPB"][index] = NTCpb; + testSum["results"]["AMACCUR10V"][index] = Cur10V; + testSum["results"]["AMACCUR1V"][index] = Cur1V; + testSum["results"]["AMACHVRET"][index] = HVret; + testSum["results"]["AMACPTAT"][index] = PTAT; + testSum["results"]["VIN"][index] = Vin; + testSum["results"]["IIN"][index] = Iin; + testSum["results"]["VOUT"][index] = Vout * 1e-3; + testSum["results"]["IOUT"][index] = Iout * 1e-3; + testSum["results"]["HVVIN"][index] = HV_Vin; + testSum["results"]["HVIIN"][index] = HV_Iin; + testSum["results"]["ADC0"][index] = ADC0; + testSum["results"]["ADC1"][index] = ADC1; + testSum["results"]["ADC2"][index] = ADC2; + testSum["results"]["ADC3"][index] = ADC3; + } + + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); return testSum; - } +} - json runBER(std::shared_ptr<AMACv2> amac, uint32_t trails) - { - logger(logINFO) << "## Test BER ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json runBER(std::shared_ptr<AMACv2> amac, uint32_t trails) { + logger(logINFO) << "## Test BER ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "BER"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = false; testSum["properties"]["TRAILS"] = trails; // Run the test - uint good=0; - for(uint i=0; i<trails; i++) - { - try - { - uint valin=rand()*0xFFFFFFFF; - amac->write_reg(166,valin); - uint valout=amac->read_reg(166); - - if(valin==valout) - good++; - else - logger(logERROR) << " -> Write: 0x" << std::hex << valin << ", Read: " << valout << std::dec; - } - catch(EndeavourComException &e) - { - logger(logDEBUG) << e.what(); - } - } - float reliability=((float)good)/trails; + uint good = 0; + for (uint i = 0; i < trails; i++) { + try { + uint valin = rand() * 0xFFFFFFFF; + amac->write_reg(166, valin); + uint valout = amac->read_reg(166); + + if (valin == valout) + good++; + else + logger(logERROR) << " -> Write: 0x" << std::hex << valin + << ", Read: " << valout << std::dec; + } catch (EndeavourComException& e) { + logger(logDEBUG) << e.what(); + } + } + float reliability = ((float)good) / trails; // Store the results testSum["results"]["RELIABILITY"] = reliability; - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - testSum["passed"] = reliability==1; + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["passed"] = reliability == 1; - if(testSum["passed"]) { logger(logINFO) << " --> RELIABILITY: " << reliability; } - else { logger(logERROR) << " --> RELIABILITY: " << reliability; } + if (testSum["passed"]) { + logger(logINFO) << " --> RELIABILITY: " << reliability; + } else { + logger(logERROR) << " --> RELIABILITY: " << reliability; + } - if(testSum["passed"]) - logger(logINFO) << " BER passed! :)"; + if (testSum["passed"]) + logger(logINFO) << " BER passed! :)"; else - logger(logERROR) << " BER failed! :("; + logger(logERROR) << " BER failed! :("; - logger(logINFO) << "## End test BER ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## End test BER ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); return testSum; - } +} - json calibrateAMACoffset(std::shared_ptr<AMACv2> amac, bool scanSettings) - { - logger(logINFO) << "## Calibrating AMAC offset ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json calibrateAMACoffset(std::shared_ptr<AMACv2> amac, bool scanSettings) { + logger(logINFO) << "## Calibrating AMAC offset ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "AMOFFSET"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; int counts; @@ -692,138 +739,145 @@ namespace PBv3TestTools amac->wrField(&AMACv2RegMap::AMzeroCalib, 1); amac->wrField(&AMACv2RegMap::AMzeroCalibC, 1); - uint32_t gain_curr=amac->rdField(&AMACv2RegMap::AMintCalib); + uint32_t gain_curr = amac->rdField(&AMACv2RegMap::AMintCalib); int index = 0; - for(uint32_t gain_set=((scanSettings)?0:gain_curr); - gain_set<((scanSettings)?16:(gain_curr+1)); - gain_set++) - { - amac->wrField(&AMACv2RegMap::AMintCalib, gain_set); - std::this_thread::sleep_for(std::chrono::milliseconds(5)); - - counts = amac->rdField(&AMACv2RegMap::Ch0Value ); - testSum["results"][ "CH0"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch1Value ); - testSum["results"][ "CH1"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch2Value ); - testSum["results"][ "CH2"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch3Value ); - testSum["results"][ "CH3"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch4Value ); - testSum["results"][ "CH4"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch5Value ); - testSum["results"][ "CH5"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch6Value ); - testSum["results"][ "CH6"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch7Value ); - testSum["results"][ "CH7"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch8Value ); - testSum["results"][ "CH8"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch9Value ); - testSum["results"][ "CH9"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch10Value); - testSum["results"]["CH10"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch11Value); - testSum["results"]["CH11"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch12Value); - testSum["results"]["CH12"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch13Value); - testSum["results"]["CH13"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch14Value); - testSum["results"]["CH14"][index] = counts; - counts = amac->rdField(&AMACv2RegMap::Ch15Value); - testSum["results"]["CH15"][index] = counts; - - testSum["results"]["AMintCalib"][index] = gain_set; - - index++; - } - - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - + for (uint32_t gain_set = ((scanSettings) ? 0 : gain_curr); + gain_set < ((scanSettings) ? 16 : (gain_curr + 1)); gain_set++) { + amac->wrField(&AMACv2RegMap::AMintCalib, gain_set); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + + counts = amac->rdField(&AMACv2RegMap::Ch0Value); + testSum["results"]["CH0"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch1Value); + testSum["results"]["CH1"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch2Value); + testSum["results"]["CH2"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch3Value); + testSum["results"]["CH3"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch4Value); + testSum["results"]["CH4"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch5Value); + testSum["results"]["CH5"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch6Value); + testSum["results"]["CH6"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch7Value); + testSum["results"]["CH7"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch8Value); + testSum["results"]["CH8"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch9Value); + testSum["results"]["CH9"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch10Value); + testSum["results"]["CH10"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch11Value); + testSum["results"]["CH11"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch12Value); + testSum["results"]["CH12"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch13Value); + testSum["results"]["CH13"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch14Value); + testSum["results"]["CH14"][index] = counts; + counts = amac->rdField(&AMACv2RegMap::Ch15Value); + testSum["results"]["CH15"][index] = counts; + + testSum["results"]["AMintCalib"][index] = gain_set; + + index++; + } + + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + amac->initRegisters(); - + return testSum; - } +} - json calibrateAMACslope(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, double step, bool scanSettings) - { +json calibrateAMACslope(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, double step, + bool scanSettings) { // Get useful tools from the TB - std::shared_ptr<AMACv2 > amac =tb->getPB(pbNum); - std::shared_ptr<DACDevice> CALdac=tb->getCalDAC(); + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + std::shared_ptr<DACDevice> CALdac = tb->getCalDAC(); // Start ramping - logger(logINFO) << "## Calibrating AMAC slope ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## Calibrating AMAC slope ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "AMSLOPE"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - std::cout << "CALIN" << "\t" << "AMbg" << "\t" << "AMintCalib" << "\t" << "AMACCAL" << std::endl; + std::cout << "CALIN" + << "\t" + << "AMbg" + << "\t" + << "AMintCalib" + << "\t" + << "AMACCAL" << std::endl; - uint32_t gain_curr =amac->rdField(&AMACv2RegMap::AMintCalib); - uint32_t bg_curr =amac->rdField(&AMACv2RegMap::AMbg ); - uint32_t Ch4Mux_curr=amac->rdField(&AMACv2RegMap::Ch4Mux ); + uint32_t gain_curr = amac->rdField(&AMACv2RegMap::AMintCalib); + uint32_t bg_curr = amac->rdField(&AMACv2RegMap::AMbg); + uint32_t Ch4Mux_curr = amac->rdField(&AMACv2RegMap::Ch4Mux); // Run the test - uint32_t index=0; - double CALact=0; - uint32_t CALamac=0; - amac->wrField(&AMACv2RegMap::Ch4Mux , 1); // Set Ch4 mux to CAL input - for(uint32_t bg_set = ((scanSettings)?0:bg_curr); - bg_set<((scanSettings)?16:(bg_curr+1)); - bg_set++) - { - amac->wrField(&AMACv2RegMap::AMbg , bg_set); - - for(uint32_t gain_set = (scanSettings)?0:gain_curr; - gain_set<((scanSettings)?16:(gain_curr+1)); - gain_set++) - { - amac->wrField(&AMACv2RegMap::AMintCalib, gain_set); - - // Longer wait for the first value due to RC constant - CALdac->set(0); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - for(double CALin=0; CALin<1.01; CALin+=step) - { - // set step - CALact=CALdac->set(CALin); - // wait - std::this_thread::sleep_for(std::chrono::milliseconds(5)); - // measure - CALamac = amac->rdField(&AMACv2RegMap::Ch4Value); - - testSum["results"]["CALIN" ][index] = CALact; - testSum["results"]["AMACCAL" ][index] = CALamac; - testSum["results"]["AMintCalib"][index] = gain_set; - testSum["results"]["AMbg" ][index] = bg_set; - index++; - std::cout << CALact << "\t" << bg_set << "\t" << gain_set << "\t" << CALamac << std::endl; - } //end cycling through voltages - } //end cycling through gain - } //end cycling through bandgap + uint32_t index = 0; + double CALact = 0; + uint32_t CALamac = 0; + amac->wrField(&AMACv2RegMap::Ch4Mux, 1); // Set Ch4 mux to CAL input + for (uint32_t bg_set = ((scanSettings) ? 0 : bg_curr); + bg_set < ((scanSettings) ? 16 : (bg_curr + 1)); bg_set++) { + amac->wrField(&AMACv2RegMap::AMbg, bg_set); + + for (uint32_t gain_set = (scanSettings) ? 0 : gain_curr; + gain_set < ((scanSettings) ? 16 : (gain_curr + 1)); gain_set++) { + amac->wrField(&AMACv2RegMap::AMintCalib, gain_set); + + // Longer wait for the first value due to RC constant + CALdac->set(0); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + for (double CALin = 0; CALin < 1.01; CALin += step) { + // set step + CALact = CALdac->set(CALin); + // wait + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + // measure + CALamac = amac->rdField(&AMACv2RegMap::Ch4Value); + + testSum["results"]["CALIN"][index] = CALact; + testSum["results"]["AMACCAL"][index] = CALamac; + testSum["results"]["AMintCalib"][index] = gain_set; + testSum["results"]["AMbg"][index] = bg_set; + index++; + std::cout << CALact << "\t" << bg_set << "\t" << gain_set + << "\t" << CALamac << std::endl; + } // end cycling through voltages + } // end cycling through gain + } // end cycling through bandgap CALdac->set(0); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::AMintCalib, gain_curr ); - amac->wrField(&AMACv2RegMap::AMbg , bg_curr ); - amac->wrField(&AMACv2RegMap::Ch4Mux , Ch4Mux_curr); + amac->wrField(&AMACv2RegMap::AMintCalib, gain_curr); + amac->wrField(&AMACv2RegMap::AMbg, bg_curr); + amac->wrField(&AMACv2RegMap::Ch4Mux, Ch4Mux_curr); return testSum; - } +} - json testOF(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) - { - std::shared_ptr<AMACv2 > amac =tb->getPB(pbNum); +json testOF(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) { + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); - logger(logINFO) << "## Test OF ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## Test OF ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "OF"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = false; logger(logINFO) << " --> Enabling OF"; @@ -832,21 +886,23 @@ namespace PBv3TestTools double Iin = tb->getVinCurrent(); double Vin = tb->getVin(); #ifdef FTDI - double ADC0 = dynamic_cast<EndeavourRawFTDI*>(amac->raw().get())->getADC()->read(0); + double ADC0 = + dynamic_cast<EndeavourRawFTDI*>(amac->raw().get())->getADC()->read(0); #else - double ADC0 = tb->readCarrierOutput(pbNum, PBv3TB::CARRIER_OUTPUT::LINPOL1V4); -#endif //FTDI - testSum["results"]["OF" ][1] = 1; - testSum["results"]["VIN" ][1] = Vin; - testSum["results"]["IIN" ][1] = Iin; + double ADC0 = + tb->readCarrierOutput(pbNum, PBv3TB::CARRIER_OUTPUT::LINPOL1V4); +#endif // FTDI + testSum["results"]["OF"][1] = 1; + testSum["results"]["VIN"][1] = Vin; + testSum["results"]["IIN"][1] = Iin; testSum["results"]["linPOLV"][1] = ADC0; - bool OFon_success =ADC0<0.25; + bool OFon_success = ADC0 < 0.25; logger(logINFO) << " ---> VIN: " << Vin << " V"; logger(logINFO) << " ---> IIN: " << Iin << " A"; - if(OFon_success) - logger(logINFO) << " ---> linPOLV: " << ADC0 << " V"; + if (OFon_success) + logger(logINFO) << " ---> linPOLV: " << ADC0 << " V"; else - logger(logERROR) << " ---> linPOLV: " << ADC0 << " V"; + logger(logERROR) << " ---> linPOLV: " << ADC0 << " V"; logger(logINFO) << " --> Disabling OF"; tb->setOFin(pbNum, false); @@ -855,194 +911,228 @@ namespace PBv3TestTools Iin = tb->getVinCurrent(); Vin = tb->getVin(); #ifdef FTDI - ADC0 = dynamic_cast<EndeavourRawFTDI*>(amac->raw().get())->getADC()->read(0); + ADC0 = + dynamic_cast<EndeavourRawFTDI*>(amac->raw().get())->getADC()->read(0); #else ADC0 = tb->readCarrierOutput(pbNum, PBv3TB::CARRIER_OUTPUT::LINPOL1V4); -#endif //FTDI - testSum["results"]["OF" ][0] = 0; - testSum["results"]["VIN" ][0] = Vin; - testSum["results"]["IIN" ][0] = Iin; +#endif // FTDI + testSum["results"]["OF"][0] = 0; + testSum["results"]["VIN"][0] = Vin; + testSum["results"]["IIN"][0] = Iin; testSum["results"]["linPOLV"][0] = ADC0; - bool OFoff_success=ADC0>1.3; + bool OFoff_success = ADC0 > 1.3; logger(logINFO) << " ---> VIN: " << Vin << " V"; logger(logINFO) << " ---> IIN: " << Iin << " A"; - if(OFoff_success) - logger(logINFO) << " ---> linPOLV: " << ADC0 << " V"; + if (OFoff_success) + logger(logINFO) << " ---> linPOLV: " << ADC0 << " V"; else - logger(logERROR) << " ---> linPOLV: " << ADC0 << " V"; + logger(logERROR) << " ---> linPOLV: " << ADC0 << " V"; // Final - testSum["passed"]= OFon_success && OFoff_success; + testSum["passed"] = OFon_success && OFoff_success; - if(testSum["passed"]) - logger(logINFO) << " OF passed! :)"; + if (testSum["passed"]) + logger(logINFO) << " OF passed! :)"; else - logger(logERROR) << " OF failed! :("; + logger(logERROR) << " OF failed! :("; - logger(logINFO) << "## End test OF ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## End test OF ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = OFon_success && OFoff_success; return testSum; - } +} - json measureHvSense(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t trails) - { - logger(logINFO) << "## Measure HV sense ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json measureHvSense(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t trails) { + logger(logINFO) << "## Measure HV sense ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "HVSENSE"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - std::shared_ptr<PowerSupplyChannel> hv=tb->getHVPS(); + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + std::shared_ptr<PowerSupplyChannel> hv = tb->getHVPS(); - uint32_t CntSetHV0en_curr =amac->rdField(&AMACv2RegMap::CntSetHV0en ); - uint32_t CntSetCHV0en_curr =amac->rdField(&AMACv2RegMap::CntSetCHV0en); - uint32_t HVcurGain_curr =amac->rdField(&AMACv2RegMap::HVcurGain ); + uint32_t CntSetHV0en_curr = amac->rdField(&AMACv2RegMap::CntSetHV0en); + uint32_t CntSetCHV0en_curr = amac->rdField(&AMACv2RegMap::CntSetCHV0en); + uint32_t HVcurGain_curr = amac->rdField(&AMACv2RegMap::HVcurGain); // Define the requested current measurement double ileak_min = 0; double ileak_max = 1.0e-3; - double ileak_step = 2e-7; // step in decade of ileak - double resist = 500e3; //500 kOhm resistor in HV circui + double ileak_step = 2e-7; // step in decade of ileak + double resist = 500e3; // 500 kOhm resistor in HV circui logger(logINFO) << " --> Turn on PS"; hv->turnOff(); - hv->setVoltageLevel (-ileak_min * resist); + hv->setVoltageLevel(-ileak_min * resist); hv->setCurrentProtect(1e-3); hv->turnOn(); logger(logINFO) << " --> Turn on HVmux"; - amac->wrField(&AMACv2RegMap::CntSetHV0en , 1); + amac->wrField(&AMACv2RegMap::CntSetHV0en, 1); amac->wrField(&AMACv2RegMap::CntSetCHV0en, 1); logger(logINFO) << " --> Starting measurement"; - std::cout << "HVVSET" << "\t" << "HVV" << "\t" << "HVI" << "\t" << "HVIOUT" << "\t" << "AMACGAIN0" << "\t" << "AMACGAIN1" << "\t" << "AMACGAIN2" << "\t" << "AMACGAIN4" << "\t" << "AMACGAIN8" << std::endl; + std::cout << "HVVSET" + << "\t" + << "HVV" + << "\t" + << "HVI" + << "\t" + << "HVIOUT" + << "\t" + << "AMACGAIN0" + << "\t" + << "AMACGAIN1" + << "\t" + << "AMACGAIN2" + << "\t" + << "AMACGAIN4" + << "\t" + << "AMACGAIN8" << std::endl; int counter = 0; int index = 0; - int32_t step_decade=std::floor(std::log10(ileak_step)); // decade of the current step - uint32_t steps_in_decade=std::floor(std::pow(10, step_decade+1)/ileak_step); - - for (double ileak=ileak_min; ileak<=ileak_max; ileak+=ileak_step) - { - double hvset=ileak*resist; - hv->setVoltageLevel(-hvset); - std::this_thread::sleep_for(std::chrono::seconds(2)); //wait to stabilize - - for(uint32_t i=0; i<trails; i++) - { - double hv_v = fabs(hv->measureVoltage()); - double hv_i = fabs(hv->measureCurrent()); - double hvout_i = tb->getHVoutCurrent(pbNum); - - unsigned val[5]; - for (unsigned g=0; g<5; g++) - { - if (g == 0) - amac->wrField(&AMACv2RegMap::HVcurGain, 0); - else - amac->wrField(&AMACv2RegMap::HVcurGain, pow(2,g-1)); - - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - val[g] = amac->rdField(&AMACv2::Ch14Value); - } - std::cout << std::scientific << std::setprecision(3) << hvset << "\t" << hv_v << "\t" << hv_i << "\t" << hvout_i << "\t" << std::dec << val[0] << "\t" << val[1] << "\t" << val[2] << "\t" << val[3] << "\t" << val[4] << std::endl; - testSum["results"]["HVVSET" ][index]=hvset; - testSum["results"]["HVV" ][index]=hv_v; - testSum["results"]["HVI" ][index]=hv_i; - testSum["results"]["HVIOUT" ][index]=hvout_i; - testSum["results"]["AMACGAIN0"][index]=val[0]; - testSum["results"]["AMACGAIN1"][index]=val[1]; - testSum["results"]["AMACGAIN2"][index]=val[2]; - testSum["results"]["AMACGAIN4"][index]=val[3]; - testSum["results"]["AMACGAIN8"][index]=val[4]; - index++; - } - - - // Increment counter - counter++; - if ((counter%steps_in_decade == 0) && counter!=0) - { - ileak_step = ileak_step*10; - ileak = 0; - } - } + int32_t step_decade = + std::floor(std::log10(ileak_step)); // decade of the current step + uint32_t steps_in_decade = + std::floor(std::pow(10, step_decade + 1) / ileak_step); + + for (double ileak = ileak_min; ileak <= ileak_max; ileak += ileak_step) { + double hvset = ileak * resist; + hv->setVoltageLevel(-hvset); + std::this_thread::sleep_for( + std::chrono::seconds(2)); // wait to stabilize + + for (uint32_t i = 0; i < trails; i++) { + double hv_v = fabs(hv->measureVoltage()); + double hv_i = fabs(hv->measureCurrent()); + double hvout_i = tb->getHVoutCurrent(pbNum); + + unsigned val[5]; + for (unsigned g = 0; g < 5; g++) { + if (g == 0) + amac->wrField(&AMACv2RegMap::HVcurGain, 0); + else + amac->wrField(&AMACv2RegMap::HVcurGain, pow(2, g - 1)); + + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + val[g] = amac->rdField(&AMACv2::Ch14Value); + } + std::cout << std::scientific << std::setprecision(3) << hvset + << "\t" << hv_v << "\t" << hv_i << "\t" << hvout_i << "\t" + << std::dec << val[0] << "\t" << val[1] << "\t" << val[2] + << "\t" << val[3] << "\t" << val[4] << std::endl; + testSum["results"]["HVVSET"][index] = hvset; + testSum["results"]["HVV"][index] = hv_v; + testSum["results"]["HVI"][index] = hv_i; + testSum["results"]["HVIOUT"][index] = hvout_i; + testSum["results"]["AMACGAIN0"][index] = val[0]; + testSum["results"]["AMACGAIN1"][index] = val[1]; + testSum["results"]["AMACGAIN2"][index] = val[2]; + testSum["results"]["AMACGAIN4"][index] = val[3]; + testSum["results"]["AMACGAIN8"][index] = val[4]; + index++; + } + + // Increment counter + counter++; + if ((counter % steps_in_decade == 0) && counter != 0) { + ileak_step = ileak_step * 10; + ileak = 0; + } + } hv->rampVoltageLevel(0, 20); hv->turnOff(); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::CntSetHV0en , CntSetHV0en_curr ); + amac->wrField(&AMACv2RegMap::CntSetHV0en, CntSetHV0en_curr); amac->wrField(&AMACv2RegMap::CntSetCHV0en, CntSetCHV0en_curr); - amac->wrField(&AMACv2RegMap::HVcurGain , HVcurGain_curr ); + amac->wrField(&AMACv2RegMap::HVcurGain, HVcurGain_curr); return testSum; - } +} - json measureHvCurrent(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t trails) - { - logger(logINFO) << "## Measure HV current ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json measureHvCurrent(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t trails) { + logger(logINFO) << "## Measure HV current ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "HVCURRENT"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - std::shared_ptr<PowerSupplyChannel> hv=tb->getHVPS(); + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + std::shared_ptr<PowerSupplyChannel> hv = tb->getHVPS(); logger(logINFO) << " --> Starting measurement"; - std::cout << "HV_v\t\tHV_i\t\tGain 0\tGain 1\tGain 2\tGain 4\tGain 8" << std::endl; - - for(uint32_t index=0; index<trails; index++) - { - double hv_v = hv->measureVoltage(); - double hv_i = hv->measureCurrent(); - - unsigned val[5]; - for (unsigned g=0; g<5; g++) - { - if (g == 0) - amac->wrField(&AMACv2RegMap::HVcurGain, 0); - else - amac->wrField(&AMACv2RegMap::HVcurGain, pow(2,g-1)); - - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - val[g] = amac->rdField(&AMACv2RegMap::Ch14Value); - } - std::cout << std::scientific << std::setprecision(3) << hv_v << "\t" << hv_i << "\t" << std::dec << val[0] << "\t" << val[1] << "\t" << val[2] << "\t" << val[3] << "\t" << val[4] << std::endl; - testSum["results"]["HVV" ][index]=hv_v; - testSum["results"]["HVI" ][index]=hv_i; - testSum["results"]["AMACGAIN0"][index]=val[0]; - testSum["results"]["AMACGAIN1"][index]=val[1]; - testSum["results"]["AMACGAIN2"][index]=val[2]; - testSum["results"]["AMACGAIN4"][index]=val[3]; - testSum["results"]["AMACGAIN8"][index]=val[4]; - } - - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + std::cout << "HV_v\t\tHV_i\t\tGain 0\tGain 1\tGain 2\tGain 4\tGain 8" + << std::endl; + + for (uint32_t index = 0; index < trails; index++) { + double hv_v = hv->measureVoltage(); + double hv_i = hv->measureCurrent(); + + unsigned val[5]; + for (unsigned g = 0; g < 5; g++) { + if (g == 0) + amac->wrField(&AMACv2RegMap::HVcurGain, 0); + else + amac->wrField(&AMACv2RegMap::HVcurGain, pow(2, g - 1)); + + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + val[g] = amac->rdField(&AMACv2RegMap::Ch14Value); + } + std::cout << std::scientific << std::setprecision(3) << hv_v << "\t" + << hv_i << "\t" << std::dec << val[0] << "\t" << val[1] + << "\t" << val[2] << "\t" << val[3] << "\t" << val[4] + << std::endl; + testSum["results"]["HVV"][index] = hv_v; + testSum["results"]["HVI"][index] = hv_i; + testSum["results"]["AMACGAIN0"][index] = val[0]; + testSum["results"]["AMACGAIN1"][index] = val[1]; + testSum["results"]["AMACGAIN2"][index] = val[2]; + testSum["results"]["AMACGAIN4"][index] = val[3]; + testSum["results"]["AMACGAIN8"][index] = val[4]; + } + + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); return testSum; - } +} - json measureLvIV(std::shared_ptr<PowerSupplyChannel> lv) - { - logger(logINFO) << "## Measure LV IV ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json measureLvIV(std::shared_ptr<PowerSupplyChannel> lv) { + logger(logINFO) << "## Measure LV IV ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "VINIIN"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; double v_start = 2.0; double v_end = 6.0; double v_step = 0.1; - logger(logINFO) << " --> Running from " << v_start << "V to " << v_end << "V in steps of " << v_step << "V"; + logger(logINFO) << " --> Running from " << v_start << "V to " << v_end + << "V in steps of " << v_step << "V"; lv->turnOff(); lv->setVoltageLevel(v_start); lv->setCurrentLevel(1.0); @@ -1050,305 +1140,362 @@ namespace PBv3TestTools std::cout << "Vset\tVread\tIread" << std::endl; int index = 0; - for (double vset = v_start; vset<=v_end; vset+=v_step) - { - lv->setVoltageLevel(vset); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - double v_read = lv->measureVoltage(); - double i_read = lv->measureCurrent(); - - std::cout << vset << "\t" << v_read << "\t" << i_read << std::endl; - testSum["results"]["VINSET"][index] = vset; - testSum["results"]["VIN" ][index] = v_read; - testSum["results"]["IIN" ][index] = i_read; - index++; - } + for (double vset = v_start; vset <= v_end; vset += v_step) { + lv->setVoltageLevel(vset); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + double v_read = lv->measureVoltage(); + double i_read = lv->measureCurrent(); + + std::cout << vset << "\t" << v_read << "\t" << i_read << std::endl; + testSum["results"]["VINSET"][index] = vset; + testSum["results"]["VIN"][index] = v_read; + testSum["results"]["IIN"][index] = i_read; + index++; + } logger(logINFO) << " --> Done!"; - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + return testSum; - } +} - json calibVinResponse(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupplyChannel> lv) - { - logger(logINFO) << "## Measure LV IV ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json calibVinResponse(std::shared_ptr<AMACv2> amac, + std::shared_ptr<PowerSupplyChannel> lv) { + logger(logINFO) << "## Measure LV IV ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "VIN"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; double v_start = 6.0; double v_end = 11.0; double v_step = 0.1; - logger(logINFO) << " --> Running from " << v_start << "V to " << v_end << "V in steps of " << v_step << "V"; + logger(logINFO) << " --> Running from " << v_start << "V to " << v_end + << "V in steps of " << v_step << "V"; std::cout << "VINSET\tVIN\tIIN\tAMACDCDCIN" << std::endl; int index = 0; - for (double vset = v_start; vset<=v_end; vset+=v_step) - { - lv->setVoltageLevel(vset); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - int DCDCin; - try - { - DCDCin = amac->rdField(&AMACv2RegMap::Ch2Value); - } - catch(EndeavourComException &e) - { - logger(logERROR) << e.what(); - testSum["error"] = e.what(); - return testSum; - } - double v_read = lv->measureVoltage(); - double i_read = lv->measureCurrent(); - - std::cout << vset << "\t" << v_read << "\t" << i_read << "\t" << DCDCin << std::endl; - testSum["results"]["VINSET" ][index] = vset; - testSum["results"]["VIN" ][index] = v_read; - testSum["results"]["IIN" ][index] = i_read; - testSum["results"]["AMACDCDCIN"][index] = DCDCin; - index++; - } + for (double vset = v_start; vset <= v_end; vset += v_step) { + lv->setVoltageLevel(vset); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + int DCDCin; + try { + DCDCin = amac->rdField(&AMACv2RegMap::Ch2Value); + } catch (EndeavourComException& e) { + logger(logERROR) << e.what(); + testSum["error"] = e.what(); + return testSum; + } + double v_read = lv->measureVoltage(); + double i_read = lv->measureCurrent(); + + std::cout << vset << "\t" << v_read << "\t" << i_read << "\t" << DCDCin + << std::endl; + testSum["results"]["VINSET"][index] = vset; + testSum["results"]["VIN"][index] = v_read; + testSum["results"]["IIN"][index] = i_read; + testSum["results"]["AMACDCDCIN"][index] = DCDCin; + index++; + } lv->setVoltageLevel(11.0); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + amac->initRegisters(); return testSum; - } +} - json calibrateAMACCur10V(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t tests) - { - logger(logINFO) << "## Calibrating input CM block ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +json calibrateAMACCur10V(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t tests) { + logger(logINFO) << "## Calibrating input CM block ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "CUR10V"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); // Store current state - uint32_t DCDCen_curr =amac->rdField(&AMACv2RegMap::DCDCen ); - uint32_t DCDCenC_curr =amac->rdField(&AMACv2RegMap::DCDCenC ); + uint32_t DCDCen_curr = amac->rdField(&AMACv2RegMap::DCDCen); + uint32_t DCDCenC_curr = amac->rdField(&AMACv2RegMap::DCDCenC); - uint32_t DCDCiZeroReading_curr=amac->rdField(&AMACv2RegMap::DCDCiZeroReading); - uint32_t DCDCiOffset_curr =amac->rdField(&AMACv2RegMap::DCDCiOffset ); - uint32_t DCDCiP_curr =amac->rdField(&AMACv2RegMap::DCDCiP ); - uint32_t DCDCiN_curr =amac->rdField(&AMACv2RegMap::DCDCiN ); + uint32_t DCDCiZeroReading_curr = + amac->rdField(&AMACv2RegMap::DCDCiZeroReading); + uint32_t DCDCiOffset_curr = amac->rdField(&AMACv2RegMap::DCDCiOffset); + uint32_t DCDCiP_curr = amac->rdField(&AMACv2RegMap::DCDCiP); + uint32_t DCDCiN_curr = amac->rdField(&AMACv2RegMap::DCDCiN); logger(logINFO) << " --> Turn off DCDC ..."; - amac->wrField(&AMACv2RegMap::DCDCen , 0); + amac->wrField(&AMACv2RegMap::DCDCen, 0); amac->wrField(&AMACv2RegMap::DCDCenC, 0); logger(logINFO) << " --> Starting measurement ..."; - uint32_t index=0; + uint32_t index = 0; uint32_t Cur10V, Cur10VTPL, Cur10VTPH; // Short the P/N - for(uint32_t DCDCiZeroReading=0;DCDCiZeroReading<2;DCDCiZeroReading++) - { - amac->wrField(&AMACv2RegMap::DCDCiZeroReading , DCDCiZeroReading); - logger(logDEBUG) << "Set DCDCiZeroReading = " << DCDCiZeroReading; - for(uint32_t DCDCiOffset=0;DCDCiOffset<pow(2,4);DCDCiOffset++) - { - amac->wrField(&AMACv2RegMap::DCDCiOffset, DCDCiOffset); - logger(logDEBUG) << "Set DCDCiOffset = " << DCDCiOffset; - for(uint32_t DCDCiP=0;DCDCiP<pow(2,3);DCDCiP++) - { - amac->wrField(&AMACv2RegMap::DCDCiP, DCDCiP); - logger(logDEBUG) << "Set DCDCiP = " << DCDCiP; - for(uint32_t DCDCiN=0;DCDCiN<pow(2,3);DCDCiN++) - { - amac->wrField(&AMACv2RegMap::DCDCiN, DCDCiN); - logger(logDEBUG) << "Set DCDCiN = " << DCDCiN; - - for (uint32_t i=0; i<tests; i++) - { - Cur10V = amac->readAM(AMACv2::AM::CUR10V ); - Cur10VTPL = amac->readAM(AMACv2::AM::CUR10VTPL); - Cur10VTPH = amac->readAM(AMACv2::AM::CUR10VTPH); - - testSum["results"]["DCDCiZeroReading"][index] = DCDCiZeroReading; - testSum["results"]["DCDCiOffset" ][index] = DCDCiOffset; - testSum["results"]["DCDCiP" ][index] = DCDCiP; - testSum["results"]["DCDCiN" ][index] = DCDCiN; - testSum["results"]["AMACCUR10V" ][index] = Cur10V; - testSum["results"]["AMACCUR10VTPL" ][index] = Cur10VTPL; - testSum["results"]["AMACCUR10VTPH" ][index] = Cur10VTPH; - index++; - } - } - } - } - } - - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - + for (uint32_t DCDCiZeroReading = 0; DCDCiZeroReading < 2; + DCDCiZeroReading++) { + amac->wrField(&AMACv2RegMap::DCDCiZeroReading, DCDCiZeroReading); + logger(logDEBUG) << "Set DCDCiZeroReading = " << DCDCiZeroReading; + for (uint32_t DCDCiOffset = 0; DCDCiOffset < pow(2, 4); DCDCiOffset++) { + amac->wrField(&AMACv2RegMap::DCDCiOffset, DCDCiOffset); + logger(logDEBUG) << "Set DCDCiOffset = " << DCDCiOffset; + for (uint32_t DCDCiP = 0; DCDCiP < pow(2, 3); DCDCiP++) { + amac->wrField(&AMACv2RegMap::DCDCiP, DCDCiP); + logger(logDEBUG) << "Set DCDCiP = " << DCDCiP; + for (uint32_t DCDCiN = 0; DCDCiN < pow(2, 3); DCDCiN++) { + amac->wrField(&AMACv2RegMap::DCDCiN, DCDCiN); + logger(logDEBUG) << "Set DCDCiN = " << DCDCiN; + + for (uint32_t i = 0; i < tests; i++) { + Cur10V = amac->readAM(AMACv2::AM::CUR10V); + Cur10VTPL = amac->readAM(AMACv2::AM::CUR10VTPL); + Cur10VTPH = amac->readAM(AMACv2::AM::CUR10VTPH); + + testSum["results"]["DCDCiZeroReading"][index] = + DCDCiZeroReading; + testSum["results"]["DCDCiOffset"][index] = DCDCiOffset; + testSum["results"]["DCDCiP"][index] = DCDCiP; + testSum["results"]["DCDCiN"][index] = DCDCiN; + testSum["results"]["AMACCUR10V"][index] = Cur10V; + testSum["results"]["AMACCUR10VTPL"][index] = Cur10VTPL; + testSum["results"]["AMACCUR10VTPH"][index] = Cur10VTPH; + index++; + } + } + } + } + } + + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + // Revert to old state - amac->wrField(&AMACv2RegMap::DCDCen ,DCDCen_curr ); - amac->wrField(&AMACv2RegMap::DCDCenC ,DCDCenC_curr ); - amac->wrField(&AMACv2RegMap::DCDCiZeroReading,DCDCiZeroReading_curr); - amac->wrField(&AMACv2RegMap::DCDCiOffset ,DCDCiOffset_curr ); - amac->wrField(&AMACv2RegMap::DCDCiP ,DCDCiP_curr ); - amac->wrField(&AMACv2RegMap::DCDCiN ,DCDCiN_curr ); + amac->wrField(&AMACv2RegMap::DCDCen, DCDCen_curr); + amac->wrField(&AMACv2RegMap::DCDCenC, DCDCenC_curr); + amac->wrField(&AMACv2RegMap::DCDCiZeroReading, DCDCiZeroReading_curr); + amac->wrField(&AMACv2RegMap::DCDCiOffset, DCDCiOffset_curr); + amac->wrField(&AMACv2RegMap::DCDCiP, DCDCiP_curr); + amac->wrField(&AMACv2RegMap::DCDCiN, DCDCiN_curr); return testSum; - } +} - json calibrateAMACCur1V(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t tests) - { - logger(logINFO) << "## Calibrating output CM block ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +json calibrateAMACCur1V(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t tests) { + logger(logINFO) << "## Calibrating output CM block ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "CUR1V"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; tb->setLoad(pbNum, 0.); std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); // Store current state - uint32_t DCDCen_curr =amac->rdField(&AMACv2RegMap::DCDCen ); - uint32_t DCDCenC_curr =amac->rdField(&AMACv2RegMap::DCDCenC ); + uint32_t DCDCen_curr = amac->rdField(&AMACv2RegMap::DCDCen); + uint32_t DCDCenC_curr = amac->rdField(&AMACv2RegMap::DCDCenC); - uint32_t DCDCoZeroReading_curr=amac->rdField(&AMACv2RegMap::DCDCoZeroReading); - uint32_t DCDCoOffset_curr =amac->rdField(&AMACv2RegMap::DCDCoOffset ); - uint32_t DCDCoP_curr =amac->rdField(&AMACv2RegMap::DCDCoP ); - uint32_t DCDCoN_curr =amac->rdField(&AMACv2RegMap::DCDCoN ); + uint32_t DCDCoZeroReading_curr = + amac->rdField(&AMACv2RegMap::DCDCoZeroReading); + uint32_t DCDCoOffset_curr = amac->rdField(&AMACv2RegMap::DCDCoOffset); + uint32_t DCDCoP_curr = amac->rdField(&AMACv2RegMap::DCDCoP); + uint32_t DCDCoN_curr = amac->rdField(&AMACv2RegMap::DCDCoN); logger(logINFO) << " --> Turn on DCDC ..."; - amac->wrField(&AMACv2RegMap::DCDCen , 1); + amac->wrField(&AMACv2RegMap::DCDCen, 1); amac->wrField(&AMACv2RegMap::DCDCenC, 1); logger(logINFO) << " --> Starting measurement ..."; // Set sub-channel - uint32_t index=0; + uint32_t index = 0; uint32_t Cur1V, Cur1VTPL, Cur1VTPH; - for(uint32_t DCDCoZeroReading=0;DCDCoZeroReading<2;DCDCoZeroReading++) - { - amac->wrField(&AMACv2RegMap::DCDCoZeroReading , DCDCoZeroReading); - logger(logDEBUG) << "Set DCDCoZeroReading = " << DCDCoZeroReading; - for(uint32_t DCDCoOffset=0;DCDCoOffset<pow(2,4);DCDCoOffset++) - { - amac->wrField(&AMACv2RegMap::DCDCoOffset, DCDCoOffset); - logger(logDEBUG) << "Set DCDCoOffset = " << DCDCoOffset; - for(uint32_t DCDCoP=0;DCDCoP<2;DCDCoP++) - { - amac->wrField(&AMACv2RegMap::DCDCoP, DCDCoP); - logger(logDEBUG) << "Set DCDCoP = " << DCDCoP; - for(uint32_t DCDCoN=0;DCDCoN<2;DCDCoN++) - { - amac->wrField(&AMACv2RegMap::DCDCoN, DCDCoN); - logger(logDEBUG) << "Set DCDCoN = " << DCDCoN; - - for (uint32_t i=0; i<tests; i++) - { - Cur1V = amac->readAM(AMACv2::AM::CUR1V ); - Cur1VTPL = amac->readAM(AMACv2::AM::CUR1VTPL); - Cur1VTPH = amac->readAM(AMACv2::AM::CUR1VTPH); - - testSum["results"]["DCDCoZeroReading"][index] = DCDCoZeroReading; - testSum["results"]["DCDCoOffset" ][index] = DCDCoOffset; - testSum["results"]["DCDCoP" ][index] = DCDCoP; - testSum["results"]["DCDCoN" ][index] = DCDCoN; - testSum["results"]["AMACCUR1V" ][index] = Cur1V; - testSum["results"]["AMACCUR1VTPL" ][index] = Cur1VTPL; - testSum["results"]["AMACCUR1VTPH" ][index] = Cur1VTPH; - index++; - } - } - } - } - } - - - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - + for (uint32_t DCDCoZeroReading = 0; DCDCoZeroReading < 2; + DCDCoZeroReading++) { + amac->wrField(&AMACv2RegMap::DCDCoZeroReading, DCDCoZeroReading); + logger(logDEBUG) << "Set DCDCoZeroReading = " << DCDCoZeroReading; + for (uint32_t DCDCoOffset = 0; DCDCoOffset < pow(2, 4); DCDCoOffset++) { + amac->wrField(&AMACv2RegMap::DCDCoOffset, DCDCoOffset); + logger(logDEBUG) << "Set DCDCoOffset = " << DCDCoOffset; + for (uint32_t DCDCoP = 0; DCDCoP < 2; DCDCoP++) { + amac->wrField(&AMACv2RegMap::DCDCoP, DCDCoP); + logger(logDEBUG) << "Set DCDCoP = " << DCDCoP; + for (uint32_t DCDCoN = 0; DCDCoN < 2; DCDCoN++) { + amac->wrField(&AMACv2RegMap::DCDCoN, DCDCoN); + logger(logDEBUG) << "Set DCDCoN = " << DCDCoN; + + for (uint32_t i = 0; i < tests; i++) { + Cur1V = amac->readAM(AMACv2::AM::CUR1V); + Cur1VTPL = amac->readAM(AMACv2::AM::CUR1VTPL); + Cur1VTPH = amac->readAM(AMACv2::AM::CUR1VTPH); + + testSum["results"]["DCDCoZeroReading"][index] = + DCDCoZeroReading; + testSum["results"]["DCDCoOffset"][index] = DCDCoOffset; + testSum["results"]["DCDCoP"][index] = DCDCoP; + testSum["results"]["DCDCoN"][index] = DCDCoN; + testSum["results"]["AMACCUR1V"][index] = Cur1V; + testSum["results"]["AMACCUR1VTPL"][index] = Cur1VTPL; + testSum["results"]["AMACCUR1VTPH"][index] = Cur1VTPH; + index++; + } + } + } + } + } + + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + // Revert to old state - amac->wrField(&AMACv2RegMap::DCDCen ,DCDCen_curr ); - amac->wrField(&AMACv2RegMap::DCDCenC ,DCDCenC_curr ); - amac->wrField(&AMACv2RegMap::DCDCoZeroReading,DCDCoZeroReading_curr); - amac->wrField(&AMACv2RegMap::DCDCoOffset ,DCDCoOffset_curr ); - amac->wrField(&AMACv2RegMap::DCDCoP ,DCDCoP_curr ); - amac->wrField(&AMACv2RegMap::DCDCoN ,DCDCoN_curr ); + amac->wrField(&AMACv2RegMap::DCDCen, DCDCen_curr); + amac->wrField(&AMACv2RegMap::DCDCenC, DCDCenC_curr); + amac->wrField(&AMACv2RegMap::DCDCoZeroReading, DCDCoZeroReading_curr); + amac->wrField(&AMACv2RegMap::DCDCoOffset, DCDCoOffset_curr); + amac->wrField(&AMACv2RegMap::DCDCoP, DCDCoP_curr); + amac->wrField(&AMACv2RegMap::DCDCoN, DCDCoN_curr); return testSum; - } +} - json toggleOutput(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) - { - logger(logINFO) << "## Test TOGGLEOUTPUT ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json toggleOutput(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) { + logger(logINFO) << "## Test TOGGLEOUTPUT ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "TOGGLEOUTPUT"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - std::cout << "\t\t\t" << "Off" << "\t\t" << "On" << std::endl; + std::cout << "\t\t\t" + << "Off" + << "\t\t" + << "On" << std::endl; std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::OFout , 1, 0, -0.01, 0.01, 1.0 , 1.5 , "OFout" , &AMACv2::RstCntOF, &AMACv2::RstCntCOF)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::SHUNTx, 0xFF, 0x00, 0.10, 0.30, 1.2 , 1.3 , "Shuntx", &AMACv2::DACShuntx)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::SHUNTy, 0xFF, 0x00, 0.10, 0.30, 1.2 , 1.3 , "Shunty", &AMACv2::DACShunty)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::CALx , 0xFF, 0x00, -0.10, 0.10, 0.8 , 1.0 , "CALx" , &AMACv2::DACCalx)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::CALy , 0xFF, 0x00, -0.10, 0.10, 0.8 , 1.0 , "CALy" , &AMACv2::DACCaly)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::LDx0EN, 0, 1, -0.01, 0.01, 1.0 , 1.5 , "LDx0EN", &AMACv2::CntSetHxLDO0en, &AMACv2::CntSetCHxLDO0en)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::LDx1EN, 0, 1, -0.01, 0.01, 1.0 , 1.5 , "LDx1EN", &AMACv2::CntSetHxLDO1en, &AMACv2::CntSetCHxLDO1en)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::LDx2EN, 0, 1, -0.01, 0.01, 1.0 , 1.5 , "LDx2EN", &AMACv2::CntSetHxLDO2en, &AMACv2::CntSetCHxLDO2en)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::LDy0EN, 0, 1, -0.01, 0.01, 1.0 , 1.5 , "LDy0EN", &AMACv2::CntSetHyLDO0en, &AMACv2::CntSetCHyLDO0en)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::LDy1EN, 0, 1, -0.01, 0.01, 1.0 , 1.5 , "LDy1EN", &AMACv2::CntSetHyLDO1en, &AMACv2::CntSetCHyLDO1en)); - PBv3Utils::mergeResult(testSum, PBv3TestTools::toggleOutputHelper(tb, pbNum, PBv3TB::LDy2EN, 0, 1, -0.01, 0.01, 1.0 , 1.5 , "LDy2EN", &AMACv2::CntSetHyLDO2en, &AMACv2::CntSetCHyLDO2en)); - - logger(logINFO) << "## End test TOGGLEOUTPUT ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + PBv3Utils::mergeResult( + testSum, PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::OFout, 1, 0, -0.01, 0.01, 1.0, 1.5, + "OFout", &AMACv2::RstCntOF, &AMACv2::RstCntCOF)); + PBv3Utils::mergeResult( + testSum, PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::SHUNTx, 0xFF, 0x00, 0.10, 0.30, 1.2, + 1.3, "Shuntx", &AMACv2::DACShuntx)); + PBv3Utils::mergeResult( + testSum, PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::SHUNTy, 0xFF, 0x00, 0.10, 0.30, 1.2, + 1.3, "Shunty", &AMACv2::DACShunty)); + PBv3Utils::mergeResult( + testSum, PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::CALx, 0xFF, 0x00, -0.10, 0.10, 0.8, 1.0, + "CALx", &AMACv2::DACCalx)); + PBv3Utils::mergeResult( + testSum, PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::CALy, 0xFF, 0x00, -0.10, 0.10, 0.8, 1.0, + "CALy", &AMACv2::DACCaly)); + PBv3Utils::mergeResult( + testSum, + PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::LDx0EN, 0, 1, -0.01, 0.01, 1.0, 1.5, "LDx0EN", + &AMACv2::CntSetHxLDO0en, &AMACv2::CntSetCHxLDO0en)); + PBv3Utils::mergeResult( + testSum, + PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::LDx1EN, 0, 1, -0.01, 0.01, 1.0, 1.5, "LDx1EN", + &AMACv2::CntSetHxLDO1en, &AMACv2::CntSetCHxLDO1en)); + PBv3Utils::mergeResult( + testSum, + PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::LDx2EN, 0, 1, -0.01, 0.01, 1.0, 1.5, "LDx2EN", + &AMACv2::CntSetHxLDO2en, &AMACv2::CntSetCHxLDO2en)); + PBv3Utils::mergeResult( + testSum, + PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::LDy0EN, 0, 1, -0.01, 0.01, 1.0, 1.5, "LDy0EN", + &AMACv2::CntSetHyLDO0en, &AMACv2::CntSetCHyLDO0en)); + PBv3Utils::mergeResult( + testSum, + PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::LDy1EN, 0, 1, -0.01, 0.01, 1.0, 1.5, "LDy1EN", + &AMACv2::CntSetHyLDO1en, &AMACv2::CntSetCHyLDO1en)); + PBv3Utils::mergeResult( + testSum, + PBv3TestTools::toggleOutputHelper( + tb, pbNum, PBv3TB::LDy2EN, 0, 1, -0.01, 0.01, 1.0, 1.5, "LDy2EN", + &AMACv2::CntSetHyLDO2en, &AMACv2::CntSetCHyLDO2en)); + + logger(logINFO) << "## End test TOGGLEOUTPUT ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); + + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); return testSum; - } +} - json toggleOutputHelper(std::shared_ptr<PBv3TB> tb, uint32_t pbNum, PBv3TB::CARRIER_OUTPUT muxCh, uint32_t on, uint32_t off, double offLowThresh, double offHighThresh, double onLowThresh, double onHighThresh, const std::string& outString, AMACv2Field AMACv2RegMap::* amacCh, AMACv2Field AMACv2RegMap::* amacChCopy) - { +json toggleOutputHelper(std::shared_ptr<PBv3TB> tb, uint32_t pbNum, + PBv3TB::CARRIER_OUTPUT muxCh, uint32_t on, uint32_t off, + double offLowThresh, double offHighThresh, + double onLowThresh, double onHighThresh, + const std::string& outString, + AMACv2Field AMACv2RegMap::*amacCh, + AMACv2Field AMACv2RegMap::*amacChCopy) { double offValue = 0; double onValue = 0; json testSum; std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); - //Determine original register state + // Determine original register state uint32_t orig_state = amac->rdField(amacCh); - uint32_t orig_state_copy = (amacChCopy)?(amac->rdField(amacChCopy)):0; + uint32_t orig_state_copy = (amacChCopy) ? (amac->rdField(amacChCopy)) : 0; - //Toggle off + // Toggle off amac->wrField(amacCh, off); - if(amacChCopy) amac->wrField(amacChCopy, off); - offValue = tb->readCarrierOutput(pbNum, muxCh); + if (amacChCopy) amac->wrField(amacChCopy, off); + offValue = tb->readCarrierOutput(pbNum, muxCh); - //Toggle on + // Toggle on amac->wrField(amacCh, on); - if(amacChCopy) amac->wrField(amacChCopy, on); - onValue = tb->readCarrierOutput(pbNum, muxCh); + if (amacChCopy) amac->wrField(amacChCopy, on); + onValue = tb->readCarrierOutput(pbNum, muxCh); - //Revert to original state + // Revert to original state amac->wrField(amacCh, orig_state); - if(amacChCopy) amac->wrField(amacChCopy, orig_state_copy); + if (amacChCopy) amac->wrField(amacChCopy, orig_state_copy); - if(offValue < offHighThresh && offValue > offLowThresh && onValue > onLowThresh && onValue < onHighThresh) - { - logger(logINFO) << outString << ": " << "\t" << offValue << "\t\t" << onValue; + if (offValue < offHighThresh && offValue > offLowThresh && + onValue > onLowThresh && onValue < onHighThresh) { + logger(logINFO) << outString << ": " + << "\t" << offValue << "\t\t" << onValue; testSum["passed"] = true; - } - else - { - logger(logERROR) << outString << ": " <<"\t" << offValue << "\t\t" << onValue; + } else { + logger(logERROR) << outString << ": " + << "\t" << offValue << "\t\t" << onValue; testSum["passed"] = false; - } + } testSum["results"][outString + "_reg_value"][0] = off; testSum["results"][outString + "_value"][0] = offValue; @@ -1356,266 +1503,284 @@ namespace PBv3TestTools testSum["results"][outString + "_value"][1] = onValue; return testSum; - } +} - json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) - { - logger(logINFO) << "## Test PADID ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; +json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb) { + logger(logINFO) << "## Test PADID ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "PADID"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - - //Power cycle AMAC if the ID is already set - if(amac->isCommIDSet()) - { - tb->setOFin(pbNum, true ); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - tb->setOFin(pbNum, false); - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - } - - for(uint32_t i=0; i<=16; i++) - { - try - { - amac->setid(EndeavourCom::REFMODE::IDPads, i); - testSum["results"]["PADID"]=i; - testSum["results"]["eFuse"]=amac->rdField(&AMACv2RegMap::SerNum); - if(i==0) - { logger(logINFO) << " --> PADID: " << i; } - else - { logger(logERROR) << " --> PADID: " << i; } - break; - } - catch(const EndeavourComException &e) - { - testSum["passed"] = false; - if(i==16) - { - logger(logERROR) << "Could not determine PADID"; - } - } - } - - //Power cycle AMAC to allow for resetting of the ID + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + + // Power cycle AMAC if the ID is already set + if (amac->isCommIDSet()) { + tb->setOFin(pbNum, true); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + tb->setOFin(pbNum, false); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + } + + for (uint32_t i = 0; i <= 16; i++) { + try { + amac->setid(EndeavourCom::REFMODE::IDPads, i); + testSum["results"]["PADID"] = i; + testSum["results"]["eFuse"] = amac->rdField(&AMACv2RegMap::SerNum); + if (i == 0) { + logger(logINFO) << " --> PADID: " << i; + } else { + logger(logERROR) << " --> PADID: " << i; + } + break; + } catch (const EndeavourComException& e) { + testSum["passed"] = false; + if (i == 16) { + logger(logERROR) << "Could not determine PADID"; + } + } + } + + // Power cycle AMAC to allow for resetting of the ID tb->setOFin(pbNum, true); std::this_thread::sleep_for(std::chrono::milliseconds(100)); tb->setOFin(pbNum, false); std::this_thread::sleep_for(std::chrono::milliseconds(100)); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - if(testSum["passed"]) - logger(logINFO) << " PADID passed! :)"; + if (testSum["passed"]) + logger(logINFO) << " PADID passed! :)"; else - logger(logERROR) << " PADID failed! :("; + logger(logERROR) << " PADID failed! :("; - logger(logINFO) << "## End test PADID ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## End test PADID ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); return testSum; - } +} - json temperature(std::shared_ptr<AMACv2> amac) - { - logger(logINFO) << "## Test TEMPERATURE ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ;; +json temperature(std::shared_ptr<AMACv2> amac) { + logger(logINFO) << "## Test TEMPERATURE ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); + ; json testSum; testSum["testType"] = "TEMPERATURE"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - uint32_t CTAToffset_curr =amac->rdField(&AMACv2RegMap::CTAToffset ); - uint32_t NTCx0SenseRange_curr=amac->rdField(&AMACv2RegMap::NTCx0SenseRange); - uint32_t NTCy0SenseRange_curr=amac->rdField(&AMACv2RegMap::NTCy0SenseRange); - uint32_t NTCpbSenseRange_curr=amac->rdField(&AMACv2RegMap::NTCpbSenseRange); + uint32_t CTAToffset_curr = amac->rdField(&AMACv2RegMap::CTAToffset); + uint32_t NTCx0SenseRange_curr = + amac->rdField(&AMACv2RegMap::NTCx0SenseRange); + uint32_t NTCy0SenseRange_curr = + amac->rdField(&AMACv2RegMap::NTCy0SenseRange); + uint32_t NTCpbSenseRange_curr = + amac->rdField(&AMACv2RegMap::NTCpbSenseRange); - amac->wrField(&AMACv2::CTAToffset , 4); + amac->wrField(&AMACv2::CTAToffset, 4); amac->wrField(&AMACv2::NTCx0SenseRange, 4); amac->wrField(&AMACv2::NTCy0SenseRange, 4); amac->wrField(&AMACv2::NTCpbSenseRange, 4); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - uint32_t CTAT = amac->readAM(AMACv2::AM::CTAT ); - uint32_t NTCx = amac->readAM(AMACv2::AM::NTCX ); - uint32_t NTCy = amac->readAM(AMACv2::AM::NTCY ); - uint32_t NTCpb = amac->readAM(AMACv2::AM::NTCPB ); - uint32_t PTAT = amac->readAM(AMACv2::AM::PTAT ); + uint32_t CTAT = amac->readAM(AMACv2::AM::CTAT); + uint32_t NTCx = amac->readAM(AMACv2::AM::NTCX); + uint32_t NTCy = amac->readAM(AMACv2::AM::NTCY); + uint32_t NTCpb = amac->readAM(AMACv2::AM::NTCPB); + uint32_t PTAT = amac->readAM(AMACv2::AM::PTAT); - testSum["results"]["CTAToffset" ]=7; - testSum["results"]["NTCx0SenseRange"]=4; - testSum["results"]["NTCy0SenseRange"]=4; - testSum["results"]["NTCpbSenseRange"]=4; + testSum["results"]["CTAToffset"] = 7; + testSum["results"]["NTCx0SenseRange"] = 4; + testSum["results"]["NTCy0SenseRange"] = 4; + testSum["results"]["NTCpbSenseRange"] = 4; - testSum["results"]["AMACCTAT" ]=CTAT; - testSum["results"]["AMACNTCX" ]=NTCx; - testSum["results"]["AMACNTCY" ]=NTCy; - testSum["results"]["AMACNTCPB" ]=NTCpb; - testSum["results"]["AMACPTAT" ]=PTAT; + testSum["results"]["AMACCTAT"] = CTAT; + testSum["results"]["AMACNTCX"] = NTCx; + testSum["results"]["AMACNTCY"] = NTCy; + testSum["results"]["AMACNTCPB"] = NTCpb; + testSum["results"]["AMACPTAT"] = PTAT; // Pass fail checks - if(200<CTAT && CTAT<500) - { - logger(logINFO) << " --> CTAT:\t" << CTAT; - } - else - { - logger(logERROR) << " --> CTAT:\t" << CTAT << " # not in [200,500]"; - testSum["passed"] = false; - } - - if(600<NTCx && NTCx<800) - { - logger(logINFO) << " --> NTCx:\t" << NTCx; - } - else - { - logger(logERROR) << " --> NTCx:\t" << NTCx << " # not in [650,750]"; - testSum["passed"] = false; - } - - if(600<NTCy && NTCy<800) - { - logger(logINFO) << " --> NTCy:\t" << NTCy; - } - else - { - logger(logERROR) << " --> NTCy:\t" << NTCy << " # not in [650,750]"; - testSum["passed"] = false; - } - - if(700<NTCpb && NTCpb<1000) - { - logger(logINFO) << " --> NTCpb:\t" << NTCpb; - } - else - { - logger(logERROR) << " --> NTCpb:\t" << NTCpb << " # not in [700,1000]"; - testSum["passed"] = false; - } - - if((200<PTAT && PTAT<500) || (600<PTAT && PTAT<750)) - { - logger(logINFO) << " --> PTAT:\t" << PTAT; - } - else - { - logger(logERROR) << " --> PTAT:\t" << PTAT << " # not in [200,500] or [600,700]"; - testSum["passed"] = false; - } + if (200 < CTAT && CTAT < 500) { + logger(logINFO) << " --> CTAT:\t" << CTAT; + } else { + logger(logERROR) << " --> CTAT:\t" << CTAT << " # not in [200,500]"; + testSum["passed"] = false; + } + + if (600 < NTCx && NTCx < 800) { + logger(logINFO) << " --> NTCx:\t" << NTCx; + } else { + logger(logERROR) << " --> NTCx:\t" << NTCx << " # not in [650,750]"; + testSum["passed"] = false; + } + + if (600 < NTCy && NTCy < 800) { + logger(logINFO) << " --> NTCy:\t" << NTCy; + } else { + logger(logERROR) << " --> NTCy:\t" << NTCy << " # not in [650,750]"; + testSum["passed"] = false; + } + + if (700 < NTCpb && NTCpb < 1000) { + logger(logINFO) << " --> NTCpb:\t" << NTCpb; + } else { + logger(logERROR) << " --> NTCpb:\t" << NTCpb << " # not in [700,1000]"; + testSum["passed"] = false; + } + + if ((200 < PTAT && PTAT < 500) || (600 < PTAT && PTAT < 750)) { + logger(logINFO) << " --> PTAT:\t" << PTAT; + } else { + logger(logERROR) << " --> PTAT:\t" << PTAT + << " # not in [200,500] or [600,700]"; + testSum["passed"] = false; + } - if(testSum["passed"]) - logger(logINFO) << " TEMPERATURE passed! :)"; + if (testSum["passed"]) + logger(logINFO) << " TEMPERATURE passed! :)"; else - logger(logERROR) << " TEMPERATURE failed! :("; + logger(logERROR) << " TEMPERATURE failed! :("; - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::CTAToffset , CTAToffset_curr ); - amac->wrField(&AMACv2RegMap::NTCx0SenseRange, NTCx0SenseRange_curr ); - amac->wrField(&AMACv2RegMap::NTCy0SenseRange, NTCy0SenseRange_curr ); - amac->wrField(&AMACv2RegMap::NTCpbSenseRange, NTCpbSenseRange_curr ); + amac->wrField(&AMACv2RegMap::CTAToffset, CTAToffset_curr); + amac->wrField(&AMACv2RegMap::NTCx0SenseRange, NTCx0SenseRange_curr); + amac->wrField(&AMACv2RegMap::NTCy0SenseRange, NTCy0SenseRange_curr); + amac->wrField(&AMACv2RegMap::NTCpbSenseRange, NTCpbSenseRange_curr); - logger(logINFO) << "## End test TEMPERATURE ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## End test TEMPERATURE ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); return testSum; - } +} - json temperatureNTC(std::shared_ptr<AMACv2> amac) - { - logger(logINFO) << "## Test TEMPERATURE_NTC ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ;; +json temperatureNTC(std::shared_ptr<AMACv2> amac) { + logger(logINFO) << "## Test TEMPERATURE_NTC ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); + ; json testSum; testSum["testType"] = "TEMPERATURE_NTC"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - uint32_t NTCx0SenseRange_curr=amac->rdField(&AMACv2RegMap::NTCx0SenseRange); - uint32_t NTCy0SenseRange_curr=amac->rdField(&AMACv2RegMap::NTCy0SenseRange); - uint32_t NTCpbSenseRange_curr=amac->rdField(&AMACv2RegMap::NTCpbSenseRange); - - std::cout << "NTCx0SenseRange" << "\t" << "NTCy0SenseRange" << "\t" << "NTCpbSenseRange" << "\t" << "AMACNTCX" << "\t" << "AMACNTCY" << "\t" << "AMACNTCPB" << std::endl; + uint32_t NTCx0SenseRange_curr = + amac->rdField(&AMACv2RegMap::NTCx0SenseRange); + uint32_t NTCy0SenseRange_curr = + amac->rdField(&AMACv2RegMap::NTCy0SenseRange); + uint32_t NTCpbSenseRange_curr = + amac->rdField(&AMACv2RegMap::NTCpbSenseRange); + + std::cout << "NTCx0SenseRange" + << "\t" + << "NTCy0SenseRange" + << "\t" + << "NTCpbSenseRange" + << "\t" + << "AMACNTCX" + << "\t" + << "AMACNTCY" + << "\t" + << "AMACNTCPB" << std::endl; uint32_t index = 0; - for(uint32_t NTCSenseRange=0; - NTCSenseRange<0x8; - NTCSenseRange++) - { - amac->wrField(&AMACv2::NTCx0SenseRange, NTCSenseRange); - amac->wrField(&AMACv2::NTCy0SenseRange, NTCSenseRange); - amac->wrField(&AMACv2::NTCpbSenseRange, NTCSenseRange); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + for (uint32_t NTCSenseRange = 0; NTCSenseRange < 0x8; NTCSenseRange++) { + amac->wrField(&AMACv2::NTCx0SenseRange, NTCSenseRange); + amac->wrField(&AMACv2::NTCy0SenseRange, NTCSenseRange); + amac->wrField(&AMACv2::NTCpbSenseRange, NTCSenseRange); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); - uint32_t AMACNTCX = amac->readAM(AMACv2::AM::NTCX ); - uint32_t AMACNTCY = amac->readAM(AMACv2::AM::NTCY ); - uint32_t AMACNTCPB = amac->readAM(AMACv2::AM::NTCPB ); + uint32_t AMACNTCX = amac->readAM(AMACv2::AM::NTCX); + uint32_t AMACNTCY = amac->readAM(AMACv2::AM::NTCY); + uint32_t AMACNTCPB = amac->readAM(AMACv2::AM::NTCPB); - std::cout << NTCSenseRange << "\t" << NTCSenseRange << "\t" << NTCSenseRange << "\t" << AMACNTCX << "\t" << AMACNTCY << "\t" << AMACNTCPB << std::endl; + std::cout << NTCSenseRange << "\t" << NTCSenseRange << "\t" + << NTCSenseRange << "\t" << AMACNTCX << "\t" << AMACNTCY + << "\t" << AMACNTCPB << std::endl; - testSum["results"]["NTCx0SenseRange"][index]=NTCSenseRange; - testSum["results"]["NTCy0SenseRange"][index]=NTCSenseRange; - testSum["results"]["NTCpbSenseRange"][index]=NTCSenseRange; + testSum["results"]["NTCx0SenseRange"][index] = NTCSenseRange; + testSum["results"]["NTCy0SenseRange"][index] = NTCSenseRange; + testSum["results"]["NTCpbSenseRange"][index] = NTCSenseRange; - testSum["results"]["AMACNTCX" ][index]=AMACNTCX; - testSum["results"]["AMACNTCY" ][index]=AMACNTCY; - testSum["results"]["AMACNTCPB" ][index]=AMACNTCPB; + testSum["results"]["AMACNTCX"][index] = AMACNTCX; + testSum["results"]["AMACNTCY"][index] = AMACNTCY; + testSum["results"]["AMACNTCPB"][index] = AMACNTCPB; - index++; - } + index++; + } - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::NTCx0SenseRange, NTCx0SenseRange_curr ); - amac->wrField(&AMACv2RegMap::NTCy0SenseRange, NTCy0SenseRange_curr ); - amac->wrField(&AMACv2RegMap::NTCpbSenseRange, NTCpbSenseRange_curr ); + amac->wrField(&AMACv2RegMap::NTCx0SenseRange, NTCx0SenseRange_curr); + amac->wrField(&AMACv2RegMap::NTCy0SenseRange, NTCy0SenseRange_curr); + amac->wrField(&AMACv2RegMap::NTCpbSenseRange, NTCpbSenseRange_curr); - logger(logINFO) << "## End test TEMPERATURE_NTC ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## End test TEMPERATURE_NTC ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); return testSum; - } +} - json temperatureCTAT(std::shared_ptr<AMACv2> amac) - { - logger(logINFO) << "## Test TEMPERATURE_CTAT ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ;; +json temperatureCTAT(std::shared_ptr<AMACv2> amac) { + logger(logINFO) << "## Test TEMPERATURE_CTAT ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); + ; json testSum; testSum["testType"] = "TEMPERATURE_CTAT"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; - uint32_t CTAToffset_curr =amac->rdField(&AMACv2RegMap::CTAToffset ); + uint32_t CTAToffset_curr = amac->rdField(&AMACv2RegMap::CTAToffset); - std::cout << "CTAToffset" << "\t" << "AMACCTAT" << std::endl; + std::cout << "CTAToffset" + << "\t" + << "AMACCTAT" << std::endl; uint32_t index = 0; - for(uint32_t CTAToffset=0; - CTAToffset<=0xF; - CTAToffset++) - { - amac->wrField(&AMACv2::CTAToffset, CTAToffset); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + for (uint32_t CTAToffset = 0; CTAToffset <= 0xF; CTAToffset++) { + amac->wrField(&AMACv2::CTAToffset, CTAToffset); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); - uint32_t AMACCTAT = amac->readAM(AMACv2::AM::CTAT ); + uint32_t AMACCTAT = amac->readAM(AMACv2::AM::CTAT); - std::cout << CTAToffset << "\t" << AMACCTAT << std::endl; + std::cout << CTAToffset << "\t" << AMACCTAT << std::endl; - testSum["results"]["CTAToffset"][index]=CTAToffset; + testSum["results"]["CTAToffset"][index] = CTAToffset; - testSum["results"]["AMACCTAT" ][index]=AMACCTAT; + testSum["results"]["AMACCTAT"][index] = AMACCTAT; - index++; - } + index++; + } - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); // Revert to old state - amac->wrField(&AMACv2RegMap::CTAToffset , CTAToffset_curr ); + amac->wrField(&AMACv2RegMap::CTAToffset, CTAToffset_curr); - logger(logINFO) << "## End test TEMPERATURE_CTAT ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) ; + logger(logINFO) << "## End test TEMPERATURE_CTAT ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); return testSum; - } - } + +} // namespace PBv3TestTools diff --git a/pbv3/PBv3TestTools.h b/pbv3/PBv3TestTools.h index 927f129902f603e65148c2fe839d40ae1de787a2..b96369f4f17c076ed8e98e2208fa1ace39dc807d 100644 --- a/pbv3/PBv3TestTools.h +++ b/pbv3/PBv3TestTools.h @@ -1,19 +1,16 @@ #ifndef PBV3TESTTOOLS_H #define PBV3TESTTOOLS_H -#include "AMACv2.h" - -#include "Bk85xx.h" - -#include "PBv3TB.h" - #include <chrono> -#include <thread> -#include <nlohmann/json.hpp> #include <iomanip> +#include <nlohmann/json.hpp> #include <string> +#include <thread> +#include "AMACv2.h" +#include "Bk85xx.h" #include "Logger.h" +#include "PBv3TB.h" using nlohmann::json; @@ -35,11 +32,12 @@ using nlohmann::json; * * The following placeholders are used in the examples below: * - `TESTTYPE`: Name of the, same as testType in the returned JSON. - * - `DATETIME`: Date+time in the following format: %Y_%m_%d-%H:%M:%SZ%z (see `PBv3Utils::getTimeAsString`) + * - `DATETIME`: Date+time in the following format: %Y_%m_%d-%H:%M:%SZ%z (see + * `PBv3Utils::getTimeAsString`) * * * The following are common rules for all formats: - * + * * All tests must begin with: * `[INFO] : ## Test TESTTYPE ## DATETIME` * @@ -62,11 +60,12 @@ using nlohmann::json; * whether it is in allowed range. For example, the BER. * * Placeholders: - * - `VALUE`: Value being measured, same as column in JSON file (can be multiple per test) + * - `VALUE`: Value being measured, same as column in JSON file (can be multiple + * per test) * - `XXX`: Measured value of `VALUE` * - `UNIT`: Units of `XXX` * - * Any value that falls outside of bounds should be + * Any value that falls outside of bounds should be * printed using `logger(logERROR)`. * * ``` @@ -85,11 +84,12 @@ using nlohmann::json; * - `ITEM`: Name of item being enabled, same as column in JSON file * - `CONST`: Columns constant for both OFF and ON states * - `CONSTVAL`: Column value for `CONST - * - `VALUE`: Value being measured, same as column in JSON file (can be multiple per test) + * - `VALUE`: Value being measured, same as column in JSON file (can be multiple + * per test) * - `XXX`: Measured value of `VALUE` * - `UNIT`: Units of `XXX` * - * Any value that falls outside of bounds should be + * Any value that falls outside of bounds should be * printed using `logger(logERROR)`. * * ``` @@ -105,500 +105,536 @@ using nlohmann::json; * ``` * */ -namespace PBv3TestTools -{ +namespace PBv3TestTools { - // - // LV tests +// +// LV tests - /** - * \brief LV_ENABLE Test the LV enable functionality - * - * Pass: Output voltage is between 1.4V and 1.6V when on and less than 0.1V when off. - * - * Modifies the following registers - * - DCDCen - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench object - * - * \return json object with test results - */ - json testLvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); +/** + * \brief LV_ENABLE Test the LV enable functionality + * + * Pass: Output voltage is between 1.4V and 1.6V when on and less than 0.1V when + * off. + * + * Modifies the following registers + * - DCDCen + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench object + * + * \return json object with test results + */ +json testLvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); - /** \brief Permutes through DCDC Adjust states and confirms the level of adjustment of the bpol DCDC output - * Looks at 0%, -13.3%, -6.67%, +6.67% shifts and confirms amount - * - * Pass: When all 3 DCDC Adjust states are within (hardcoded: +/- 1%) bounds - * - * Modifies the following registers - * - DCDCen - * - DCDCenC - * - DCDCAdj - * - DCDCAdjC - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench object - * - * \return json object with test results - */ - json testDCDCAdj(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); +/** \brief Permutes through DCDC Adjust states and confirms the level of + * adjustment of the bpol DCDC output Looks at 0%, -13.3%, -6.67%, +6.67% shifts + * and confirms amount + * + * Pass: When all 3 DCDC Adjust states are within (hardcoded: +/- 1%) bounds + * + * Modifies the following registers + * - DCDCen + * - DCDCenC + * - DCDCAdj + * - DCDCAdjC + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench object + * + * \return json object with test results + */ +json testDCDCAdj(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); - /** - * \brief DCDCEFFICIENCY Measures powerboard efficiency at different output currents by comparing output power to input power. - * - * Scans output current from min to max with given step size. - * - * At each set output current value, the following are recorded: - * - Input voltage (VIN) - * - Input current (IIN) - * - Output voltage (VOUT) - * - Measured output current (IOUT) - * - bPol output voltage, in counts (AMACVDCDC) - * - linPol output voltage, in counts (AMACVDDLR) - * - bPol input voltage, in counts (AMACDCDCIN) - * - Powerboard NTC reading, in counts (AMACNTCPB) - * - Output current, in counts (AMACCUR10V) - * - Input current, in counts (AMACCUR1V) - * - bPol PTAT temperature reading, in counts (AMACPTAT) - * - DCDC efficiency, calculated using the set ouput current (EFFICIENCY) - * - DCDC efficiency, calculated using the measured output current (EFFICIENCYSENSE) - * - * Efficiency is Power out/power in -> (Vout*Iout)/(Vin*(Iin-IinOffset)) - * - * Pass: Always - * - * Modifies the following registers - * - DCDCen - * - DCDCenC - * - Ch12Mux - * - Ch14Mux - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench object - * \param step Steps in load current - * \param min Minimum load current - * \param min Maximum load current - * \param VinSet Input voltage at power supply - * \param trails Number of measurements per set current - * - * \return json object with test results - */ - json measureEfficiency(uint32_t pbNum, std::shared_ptr<PBv3TB>, double step, double min, double max , double VinSet=11.0, uint32_t trails=1); +/** + * \brief DCDCEFFICIENCY Measures powerboard efficiency at different output + * currents by comparing output power to input power. + * + * Scans output current from min to max with given step size. + * + * At each set output current value, the following are recorded: + * - Input voltage (VIN) + * - Input current (IIN) + * - Output voltage (VOUT) + * - Measured output current (IOUT) + * - bPol output voltage, in counts (AMACVDCDC) + * - linPol output voltage, in counts (AMACVDDLR) + * - bPol input voltage, in counts (AMACDCDCIN) + * - Powerboard NTC reading, in counts (AMACNTCPB) + * - Output current, in counts (AMACCUR10V) + * - Input current, in counts (AMACCUR1V) + * - bPol PTAT temperature reading, in counts (AMACPTAT) + * - DCDC efficiency, calculated using the set ouput current (EFFICIENCY) + * - DCDC efficiency, calculated using the measured output current + * (EFFICIENCYSENSE) + * + * Efficiency is Power out/power in -> (Vout*Iout)/(Vin*(Iin-IinOffset)) + * + * Pass: Always + * + * Modifies the following registers + * - DCDCen + * - DCDCenC + * - Ch12Mux + * - Ch14Mux + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench object + * \param step Steps in load current + * \param min Minimum load current + * \param min Maximum load current + * \param VinSet Input voltage at power supply + * \param trails Number of measurements per set current + * + * \return json object with test results + */ +json measureEfficiency(uint32_t pbNum, std::shared_ptr<PBv3TB>, double step, + double min, double max, double VinSet = 11.0, + uint32_t trails = 1); - /** \brief Scans through different VIN values and measures AMAC response - * - * Scan of Vin from 6V to 11V (all valid for linPOL operation) is performed - * and the AMAC reading of this value is taken. - * - * Pass: Always - * - * \param amac AMAC communication object - * \param lv Low Voltage power supply - * - * \return json object with test result - */ - json calibVinResponse(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupplyChannel> lv); +/** \brief Scans through different VIN values and measures AMAC response + * + * Scan of Vin from 6V to 11V (all valid for linPOL operation) is performed + * and the AMAC reading of this value is taken. + * + * Pass: Always + * + * \param amac AMAC communication object + * \param lv Low Voltage power supply + * + * \return json object with test result + */ +json calibVinResponse(std::shared_ptr<AMACv2> amac, + std::shared_ptr<PowerSupplyChannel> lv); - /** \brief Scans through different VIN values and measures current - * - * Scan of Vin from 2V to 11V is performed and current usage monitored - * from the power supply. linPOL will not work below 6V, thus an AMAC - * reinitialization has to be preformed after this test. - * - * Pass: Always - * - * \param lv Low Voltage power supply - * - * \return json object with test result - */ - json measureLvIV(std::shared_ptr<PowerSupplyChannel> lv); +/** \brief Scans through different VIN values and measures current + * + * Scan of Vin from 2V to 11V is performed and current usage monitored + * from the power supply. linPOL will not work below 6V, thus an AMAC + * reinitialization has to be preformed after this test. + * + * Pass: Always + * + * \param lv Low Voltage power supply + * + * \return json object with test result + */ +json measureLvIV(std::shared_ptr<PowerSupplyChannel> lv); + +/** + * \brief toggleOutput calls toggleOutputHelper to toggle the outputs + * of various AMAC registers to determine what is working. + * + * Toggles the following: + * - Vout + * - OFout + * - Shuntx + * - Shunty + * - CALx + * - CALy + * - LDx0EN + * - LDx1EN + * - LDx2EN + * - LDy0EN + * - LDy1EN + * - LDy2EN + * + * Pass: if all calls to toggleOutputHelper pass. + * Acceptable ranges for the various registers are as follows: + * - Vout: + * - Off: (-0.1, 0.1) + * - On: (1.4, 1.6) + * - OFout: + * - Off: (-0.1, 0.1) + * - On: (1.0, 1.5) + * - Shuntx: + * - Off: (-0.1, 0.3) + * - On: (0.9, 1.3) + * - Shunty: + * - Off: (-0.1, 0.3) + * - On: (0.9, 1.3) + * - CALx: + * - Off: (-0.1, 0.1) + * - On: (0.9, 1.3) + * - CALy: + * - Off: (-0.1, 0.1) + * - On: (0.9, 1.3) + * - LDx0EN: + * - Off: (-0.01, 0.01) + * - On: (1.0, 1.5) + * - LDx1EN: + * - Off: (-0.01, 0.01) + * - On: (1.0, 1.5) + * - LDx2EN: + * - Off: (-0.01, 0.01) + * - On: (1.0, 1.5) + * - LDy0EN: + * - Off: (-0.01, 0.01) + * - On: (1.0, 1.5) + * - LDy1EN: + * - Off: (-0.01, 0.01) + * - On: (1.0, 1.5) + * - LDy2EN: + * - Off: (-0.01, 0.01) + * - On: (1.0, 1.5) + * + * \param pbNum powerboard number on testbench + * \param tb testbench + * + * \return json object with test result + */ +json toggleOutput(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); - /** - * \brief toggleOutput calls toggleOutputHelper to toggle the outputs - * of various AMAC registers to determine what is working. - * - * Toggles the following: - * - Vout - * - OFout - * - Shuntx - * - Shunty - * - CALx - * - CALy - * - LDx0EN - * - LDx1EN - * - LDx2EN - * - LDy0EN - * - LDy1EN - * - LDy2EN - * - * Pass: if all calls to toggleOutputHelper pass. - * Acceptable ranges for the various registers are as follows: - * - Vout: - * - Off: (-0.1, 0.1) - * - On: (1.4, 1.6) - * - OFout: - * - Off: (-0.1, 0.1) - * - On: (1.0, 1.5) - * - Shuntx: - * - Off: (-0.1, 0.3) - * - On: (0.9, 1.3) - * - Shunty: - * - Off: (-0.1, 0.3) - * - On: (0.9, 1.3) - * - CALx: - * - Off: (-0.1, 0.1) - * - On: (0.9, 1.3) - * - CALy: - * - Off: (-0.1, 0.1) - * - On: (0.9, 1.3) - * - LDx0EN: - * - Off: (-0.01, 0.01) - * - On: (1.0, 1.5) - * - LDx1EN: - * - Off: (-0.01, 0.01) - * - On: (1.0, 1.5) - * - LDx2EN: - * - Off: (-0.01, 0.01) - * - On: (1.0, 1.5) - * - LDy0EN: - * - Off: (-0.01, 0.01) - * - On: (1.0, 1.5) - * - LDy1EN: - * - Off: (-0.01, 0.01) - * - On: (1.0, 1.5) - * - LDy2EN: - * - Off: (-0.01, 0.01) - * - On: (1.0, 1.5) - * - * \param pbNum powerboard number on testbench - * \param tb testbench - * - * \return json object with test result - */ - json toggleOutput(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); +/** + * \brief toggleOutputHelper is a helper function for toggleOutput that toggles + * a single powerboard output + * + * Sets testSum["results"]["passed"]=false if test fails, otherwise passed is + * not set. + * + * \param tb Testbench object + * \param pbNum Powerboard number on the testboard + * \param muxCh multiplexer channel + * \param on AMAC register value to toggle on the output + * \param off AMAC register value to toggle off the output + * \param offLowThresh lower bound on acceptable range of off output value + * \param offHighThresh upper bound on acceptable range of off output value + * \param onLowThresh lower bound on acceptable range of on output value + * \param onHighThresh upper bound on acceptable range of on output value + * \param outString name output channel being toggled + * \param amacCh AMAC register to toggle + * \param amacChCopy second AMAC register to toggle (set to `nullptr` for non + * copy protected registers) + * + * Pass: If on value is between onLowThresh and onHighThresh and off value is + * between offLowThresh and offHighThresh. + * + * \return json object with test results + */ +json toggleOutputHelper(std::shared_ptr<PBv3TB> tb, uint32_t pbNum, + PBv3TB::CARRIER_OUTPUT muxCh, uint32_t on, uint32_t off, + double offLowThresh, double offHighThresh, + double onLowThresh, double onHighThresh, + const std::string& outString, + AMACv2Field AMACv2RegMap::*amacCh, + AMACv2Field AMACv2RegMap::*amacChCopy = nullptr); - /** - * \brief toggleOutputHelper is a helper function for toggleOutput that toggles a single powerboard output - * - * Sets testSum["results"]["passed"]=false if test fails, otherwise passed is not set. - * - * \param tb Testbench object - * \param pbNum Powerboard number on the testboard - * \param muxCh multiplexer channel - * \param on AMAC register value to toggle on the output - * \param off AMAC register value to toggle off the output - * \param offLowThresh lower bound on acceptable range of off output value - * \param offHighThresh upper bound on acceptable range of off output value - * \param onLowThresh lower bound on acceptable range of on output value - * \param onHighThresh upper bound on acceptable range of on output value - * \param outString name output channel being toggled - * \param amacCh AMAC register to toggle - * \param amacChCopy second AMAC register to toggle (set to `nullptr` for non copy protected registers) - * - * Pass: If on value is between onLowThresh and onHighThresh and off value is between offLowThresh and offHighThresh. - * - * \return json object with test results - */ - json toggleOutputHelper(std::shared_ptr<PBv3TB> tb, uint32_t pbNum, PBv3TB::CARRIER_OUTPUT muxCh, uint32_t on, uint32_t off, double offLowThresh, double offHighThresh, double onLowThresh, double onHighThresh, const std::string& outString, AMACv2Field AMACv2RegMap::* amacCh, AMACv2Field AMACv2RegMap::* amacChCopy=nullptr); +/** \name HV tests + * @{ */ - /** \name HV tests - * @{ */ +/** + * \brief HV_ENABLE test the HV enable functionality + * + * Output 500V from power supply with 1mA current limit. The + * current is then measured with HVmux in off and on states. + * + * Pass: + * - HVVIN ON and OFF states > 450 V + * - HVIIN ON state - OFF state > 0.4mA (HVmux toggled) + * - HVIOUT ON state > 0.8e-3 A + * - HVIOUT OFF state < 1e-7 A + * - AMACHVRET OFF state < 200 + * - AMACHVRET ON state > 300 + * + * Modifies the following registers + * - HVcurGain + * - CntSetHV0frq + * - CntSetCHV0frq + * - CntSetHV0en + * - CntSetCHV0en + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench object + * \param frequency Value of HV enable frequency register (see AMAC + * specification for possible values) + * + * \return JSON object with test results + */ +json testHvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + unsigned frequency = 0x3); - /** - * \brief HV_ENABLE test the HV enable functionality - * - * Output 500V from power supply with 1mA current limit. The - * current is then measured with HVmux in off and on states. - * - * Pass: - * - HVVIN ON and OFF states > 450 V - * - HVIIN ON state - OFF state > 0.4mA (HVmux toggled) - * - HVIOUT ON state > 0.8e-3 A - * - HVIOUT OFF state < 1e-7 A - * - AMACHVRET OFF state < 200 - * - AMACHVRET ON state > 300 - * - * Modifies the following registers - * - HVcurGain - * - CntSetHV0frq - * - CntSetCHV0frq - * - CntSetHV0en - * - CntSetCHV0en - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench object - * \param frequency Value of HV enable frequency register (see AMAC specification for possible values) - * - * \return JSON object with test results - */ - json testHvEnable(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, unsigned frequency=0x3); +/** + * \brief HVSENSE test AMAC response to changing HV current + * + * Step through several voltage values and read the AMAC + * measurement at different gain settings. This translates to + * a current scan if a fixed load is used. + * + * Pass: Always + * + * Modifies the following registers + * - CntSetHV0en + * - CntSetCHV0en + * - HVcurGain + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench object + * \param trails Number of trails at each current values + * + * \return JSON object with test results + */ +json measureHvSense(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t trails = 1); - /** - * \brief HVSENSE test AMAC response to changing HV current - * - * Step through several voltage values and read the AMAC - * measurement at different gain settings. This translates to - * a current scan if a fixed load is used. - * - * Pass: Always - * - * Modifies the following registers - * - CntSetHV0en - * - CntSetCHV0en - * - HVcurGain - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench object - * \param trails Number of trails at each current values - * - * \return JSON object with test results - */ - json measureHvSense(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t trails=1); +/** + * \brief HVCURRENT test AMAC measurement of HVret current + * + * Measures the sensor current using the AMAC for different gain + * settings. + * + * Pass: Always + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench object + * \param trails Number of trails at each current values + * + * \return JSON object with test results + */ +json measureHvCurrent(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t trails = 1); - /** - * \brief HVCURRENT test AMAC measurement of HVret current - * - * Measures the sensor current using the AMAC for different gain - * settings. - * - * Pass: Always - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench object - * \param trails Number of trails at each current values - * - * \return JSON object with test results - */ - json measureHvCurrent(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t trails=1); +/** @} */ - /** @} */ - - // - // AMAC tests +// +// AMAC tests - /** - * \brief BER Tests AMAC read/write reliability - * - * Writes random values to AMAC register 166 and reads them back to confirm that the value has not changed. - * - * Pass: If all values are returned unchanged. - * - * \param amac AMAC for communication - * \param trails Number if times to write to the register. Default: 1000. - * - * \return JSON object with test results - */ - json runBER(std::shared_ptr<AMACv2> amac, uint32_t trails=1000); +/** + * \brief BER Tests AMAC read/write reliability + * + * Writes random values to AMAC register 166 and reads them back to confirm that + * the value has not changed. + * + * Pass: If all values are returned unchanged. + * + * \param amac AMAC for communication + * \param trails Number if times to write to the register. Default: 1000. + * + * \return JSON object with test results + */ +json runBER(std::shared_ptr<AMACv2> amac, uint32_t trails = 1000); - /** - * \brief STATUS . - * - * Reads the current value of the AMAC for a number of registers and reads low voltage and high voltage currents and voltages from the connected power supplies and active board load. - * - * Reads the status of the following AMAC registers: - * - AMAC output voltage, in counts (AMACVDCDC) - * - AMAC VddLr, in counts (AMACVDDLR) - * - AMAC input voltage, in counts (AMACDCDCIN) - * - AMAC VddReg, in counts (AMACVDDREG) - * - AMAC AM bandgap, 900mV, in counts (AMACAM900BG) - * - AMAC AM bandgap, 600mV, in counts (AMACAM600BG) - * - AMAC CAL, in counts, (AMACCAL) - * - AMAC CTAT temperature reading, in counts, (AMACCTAT) - * - X Hybrid NTC temperature reading, in counts (AMACNTCX) - * - Y Hybrid NTC temperature reading, in counts (AMACNTCY) - * - Powerboard NTC temperature reading, in counts (AMACNTCPB) - * - AMAC output current, in counts (AMACCUR10V) - * - AMAC input current, in counts (AMACCUR1V) - * - AMAC high voltage return, in counts (AMACHVRET) - * - FEAST PTAT temperature reading, in counts (AMACPTAT) - * - AMAC ADC0, in counts (ADC0) - * - AMAC ADC1, in counts (ADC1) - * - AMAC ADC2, in counts (ADC2) - * - AMAC ADC3, in counts (ADC3) - * - * Reads the following values from either the power supplies or load: - * - Low voltage input voltage (VIN) - * - Low voltage input current (IIN) - * - Low voltage output voltage (VOUT) - * - Low voltage output current (IOUT) - * - High voltage input voltage (HVVIN) - * - High voltage input current (HVIIN) - * - * Pass: Always - * - * \param amac AMAC for communication - * \param lv low voltage power supply - * \param load external load - * \param hv high voltage power supply - * \param tests number of times to perform status read. Default: 1 - * - * \return JSON object with test results - */ - json readStatus(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupplyChannel> lv, std::shared_ptr<Bk85xx> load, std::shared_ptr<PowerSupplyChannel> hv, uint32_t tests=1); +/** + * \brief STATUS . + * + * Reads the current value of the AMAC for a number of registers and reads low + * voltage and high voltage currents and voltages from the connected power + * supplies and active board load. + * + * Reads the status of the following AMAC registers: + * - AMAC output voltage, in counts (AMACVDCDC) + * - AMAC VddLr, in counts (AMACVDDLR) + * - AMAC input voltage, in counts (AMACDCDCIN) + * - AMAC VddReg, in counts (AMACVDDREG) + * - AMAC AM bandgap, 900mV, in counts (AMACAM900BG) + * - AMAC AM bandgap, 600mV, in counts (AMACAM600BG) + * - AMAC CAL, in counts, (AMACCAL) + * - AMAC CTAT temperature reading, in counts, (AMACCTAT) + * - X Hybrid NTC temperature reading, in counts (AMACNTCX) + * - Y Hybrid NTC temperature reading, in counts (AMACNTCY) + * - Powerboard NTC temperature reading, in counts (AMACNTCPB) + * - AMAC output current, in counts (AMACCUR10V) + * - AMAC input current, in counts (AMACCUR1V) + * - AMAC high voltage return, in counts (AMACHVRET) + * - FEAST PTAT temperature reading, in counts (AMACPTAT) + * - AMAC ADC0, in counts (ADC0) + * - AMAC ADC1, in counts (ADC1) + * - AMAC ADC2, in counts (ADC2) + * - AMAC ADC3, in counts (ADC3) + * + * Reads the following values from either the power supplies or load: + * - Low voltage input voltage (VIN) + * - Low voltage input current (IIN) + * - Low voltage output voltage (VOUT) + * - Low voltage output current (IOUT) + * - High voltage input voltage (HVVIN) + * - High voltage input current (HVIIN) + * + * Pass: Always + * + * \param amac AMAC for communication + * \param lv low voltage power supply + * \param load external load + * \param hv high voltage power supply + * \param tests number of times to perform status read. Default: 1 + * + * \return JSON object with test results + */ +json readStatus(std::shared_ptr<AMACv2> amac, + std::shared_ptr<PowerSupplyChannel> lv, + std::shared_ptr<Bk85xx> load, + std::shared_ptr<PowerSupplyChannel> hv, uint32_t tests = 1); - /** - * \brief AMSLOPE step through CAL values to get the slope of the AM - * - * Modifies the following registers - * - AMintCalib - * - AMbg - * - Ch4Mux - * - * Pass: Always - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench with all control classes - * \param step Voltage steps for the CAL - * \param scanSettings Scan AMintCalib and AMbg if true, use current value if false - * - * \return JSON object with test results - */ - json calibrateAMACslope(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, double step, bool scanSettings=true); +/** + * \brief AMSLOPE step through CAL values to get the slope of the AM + * + * Modifies the following registers + * - AMintCalib + * - AMbg + * - Ch4Mux + * + * Pass: Always + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench with all control classes + * \param step Voltage steps for the CAL + * \param scanSettings Scan AMintCalib and AMbg if true, use current value if + * false + * + * \return JSON object with test results + */ +json calibrateAMACslope(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, double step, + bool scanSettings = true); - /** - * \brief AMOFFSET step through channels and gain settings to get the offset of the AM per channel. - * - * Modifies the following registers - * - AMintCalib - * - AMzeroCalib - * - AMzeroCalibC - * - * Pass: Always - * - * \param amac AMAC for communication - * \param scanSettings Scan AMintCalib if true, use current value if false - * - * \return JSON object with test results - */ - json calibrateAMACoffset(std::shared_ptr<AMACv2> amac, bool scanSettings=true); +/** + * \brief AMOFFSET step through channels and gain settings to get the offset of + * the AM per channel. + * + * Modifies the following registers + * - AMintCalib + * - AMzeroCalib + * - AMzeroCalibC + * + * Pass: Always + * + * \param amac AMAC for communication + * \param scanSettings Scan AMintCalib if true, use current value if false + * + * \return JSON object with test results + */ +json calibrateAMACoffset(std::shared_ptr<AMACv2> amac, + bool scanSettings = true); - /** - * \brief CUR10V calibrates the AMAC 10V current monitoring. - * - * Modifies the following registers - * - DCDCiZeroReading - * - DCDCiOffset - * - DCDCiP - * - DCDCiN - * - * Pass: Always - * - * \param amac AMAC for communication - * \param tests number of times read values. Default: 10. - * - * \return JSON object with test results - */ - json calibrateAMACCur10V(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t tests=10); +/** + * \brief CUR10V calibrates the AMAC 10V current monitoring. + * + * Modifies the following registers + * - DCDCiZeroReading + * - DCDCiOffset + * - DCDCiP + * - DCDCiN + * + * Pass: Always + * + * \param amac AMAC for communication + * \param tests number of times read values. Default: 10. + * + * \return JSON object with test results + */ +json calibrateAMACCur10V(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t tests = 10); - /** - * \brief CUR1V calibrates the AMAC 1V current monitoring. - * - * Modifies the following registers - * - DCDCen - * - DCDCenC - * - DCDCoZeroReading - * - DCDCoOffset - * - DCDCoP - * - DCDCoN - * - * Pass: Always - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench with all control classes - * - * \return JSON object with test results - */ - json calibrateAMACCur1V (uint32_t pbNum, std::shared_ptr<PBv3TB> tb, uint32_t tests=10); +/** + * \brief CUR1V calibrates the AMAC 1V current monitoring. + * + * Modifies the following registers + * - DCDCen + * - DCDCenC + * - DCDCoZeroReading + * - DCDCoOffset + * - DCDCoP + * - DCDCoN + * + * Pass: Always + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench with all control classes + * + * \return JSON object with test results + */ +json calibrateAMACCur1V(uint32_t pbNum, std::shared_ptr<PBv3TB> tb, + uint32_t tests = 10); - //! \brief Checks to see whether or not the linPOL on the powerboard is operational. - /** - * Toggles OF and checks that the linPOL output voltage is above 0.1V when OFF and 1.3V when ON. - * - * The test also reads the input voltage and current at both stages. The ON reading is done - * second with no AMAC configuration in between. Thus the current is the power-up current - * draw of the chip. - * - * Pass: - * - when OF is disabled (linPOL is on), the linPOL voltage is greater than 1.3V - * - when OF is enabled (linPOL is off), the linPOL voltage is less than 0.1V - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench with all control classes - * - * \return JSON object with test results - */ - json testOF(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); +//! \brief Checks to see whether or not the linPOL on the powerboard is +//! operational. +/** + * Toggles OF and checks that the linPOL output voltage is above 0.1V when OFF + * and 1.3V when ON. + * + * The test also reads the input voltage and current at both stages. The ON + * reading is done second with no AMAC configuration in between. Thus the + * current is the power-up current draw of the chip. + * + * Pass: + * - when OF is disabled (linPOL is on), the linPOL voltage is greater + * than 1.3V + * - when OF is enabled (linPOL is off), the linPOL voltage is less than 0.1V + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench with all control classes + * + * \return JSON object with test results + */ +json testOF(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); - /** - * \brief Determine the AMAC PADID and eFuse ID - * - * The implementation requires the AMAC ID to be set again even if it was previously. - * - * Pass: If AMAC PADID is 0. - * - * \param pbNum Powerboard number on the testboard - * \param tb Testbench with all control classes - * - * \return JSON object with test results - */ - json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); +/** + * \brief Determine the AMAC PADID and eFuse ID + * + * The implementation requires the AMAC ID to be set again even if it was + * previously. + * + * Pass: If AMAC PADID is 0. + * + * \param pbNum Powerboard number on the testboard + * \param tb Testbench with all control classes + * + * \return JSON object with test results + */ +json scanPADID(uint32_t pbNum, std::shared_ptr<PBv3TB> tb); - /** - * \brief Measure the temperature using all possible ways - * - * Pass: Temperature in range as defined by the following - * table. All values are in [counts]. - * - * | __Input__ | __Min__ | __Max__ | - * |-----------|---------|---------| - * | CTAT | 300 | 400 | - * | PTAT | 350 | 450 | - * | NTCpb | 700 | 1000 | - * | NTCx | 600 | 700 | - * | NTCy | 600 | 700 | - * - * Modifies the following registers - * - CTAToffset - * - NTCx0SenseRange - * - NTCy0SenseRange - * - NTCpbSenseRange - * - * \param amac AMAC communication object - * - * \return JSON object with test results - */ - json temperature(std::shared_ptr<AMACv2> amac); +/** + * \brief Measure the temperature using all possible ways + * + * Pass: Temperature in range as defined by the following + * table. All values are in [counts]. + * + * | __Input__ | __Min__ | __Max__ | + * |-----------|---------|---------| + * | CTAT | 300 | 400 | + * | PTAT | 350 | 450 | + * | NTCpb | 700 | 1000 | + * | NTCx | 600 | 700 | + * | NTCy | 600 | 700 | + * + * Modifies the following registers + * - CTAToffset + * - NTCx0SenseRange + * - NTCy0SenseRange + * - NTCpbSenseRange + * + * \param amac AMAC communication object + * + * \return JSON object with test results + */ +json temperature(std::shared_ptr<AMACv2> amac); - /** - * \brief Scan NTC gain settings - * - * Pass: Always - * - * Modifies the following registers - * - NTCx0SenseRange - * - NTCy0SenseRange - * - NTCpbSenseRange - * - * \param amac AMAC communication object - * - * \return JSON object with test results - */ - json temperatureNTC(std::shared_ptr<AMACv2> amac); +/** + * \brief Scan NTC gain settings + * + * Pass: Always + * + * Modifies the following registers + * - NTCx0SenseRange + * - NTCy0SenseRange + * - NTCpbSenseRange + * + * \param amac AMAC communication object + * + * \return JSON object with test results + */ +json temperatureNTC(std::shared_ptr<AMACv2> amac); - /** - * \brief Scan CTAT offset settings - * - * Pass: Always - * - * Modifies the following registers - * - CTAToffset - * - * \param amac AMAC communication object - * - * \return JSON object with test results - */ - json temperatureCTAT(std::shared_ptr<AMACv2> amac); -} +/** + * \brief Scan CTAT offset settings + * + * Pass: Always + * + * Modifies the following registers + * - CTAToffset + * + * \param amac AMAC communication object + * + * \return JSON object with test results + */ +json temperatureCTAT(std::shared_ptr<AMACv2> amac); +} // namespace PBv3TestTools #endif diff --git a/pbv3/PBv3Utils.cpp b/pbv3/PBv3Utils.cpp index 143d1e1b03a6d2bf47bc58f9039b7f0844b88a2a..1d4b11504ae408d2bf124749bbd489fc4eb41dec 100644 --- a/pbv3/PBv3Utils.cpp +++ b/pbv3/PBv3Utils.cpp @@ -4,94 +4,91 @@ using nlohmann::json; -#include <set> - #include <sys/stat.h> #include <sys/types.h> -std::string PBv3Utils::getTimeAsString(std::chrono::system_clock::time_point t) -{ - auto as_time_t = std::chrono::system_clock::to_time_t(t); - struct tm tm; - char some_buffer[128]; - if (::gmtime_r(&as_time_t, &tm)) - if (std::strftime(some_buffer, sizeof(some_buffer), "%Y_%m_%d-%H:%M:%SZ%z", &tm)) - return std::string(some_buffer); - throw std::runtime_error("Failed to get current date as string"); +#include <set> + +std::string PBv3Utils::getTimeAsString( + std::chrono::system_clock::time_point t) { + auto as_time_t = std::chrono::system_clock::to_time_t(t); + struct tm tm; + char some_buffer[128]; + if (::gmtime_r(&as_time_t, &tm)) + if (std::strftime(some_buffer, sizeof(some_buffer), + "%Y_%m_%d-%H:%M:%SZ%z", &tm)) + return std::string(some_buffer); + throw std::runtime_error("Failed to get current date as string"); } -void PBv3Utils::printResults(const json& results) -{ - // Ignore the following common results - std::set<std::string> ignorekeys={"TIMESTART","TIMEEND"}; +void PBv3Utils::printResults(const json& results) { + // Ignore the following common results + std::set<std::string> ignorekeys = {"TIMESTART", "TIMEEND"}; - // Determine widths of each column - std::unordered_map<std::string, uint32_t> colw; - for(const auto& kv : results.items()) - { - uint32_t mycolw=std::max<uint32_t>(kv.key().size()+2,10); // key size +2 pad with minimum of 8 - if(kv.value().is_string()) - mycolw=std::max<uint32_t>(mycolw,kv.value().get<std::string>().length()+2); + // Determine widths of each column + std::unordered_map<std::string, uint32_t> colw; + for (const auto& kv : results.items()) { + uint32_t mycolw = std::max<uint32_t>( + kv.key().size() + 2, 10); // key size +2 pad with minimum of 8 + if (kv.value().is_string()) + mycolw = std::max<uint32_t>( + mycolw, kv.value().get<std::string>().length() + 2); - colw[kv.key()]=mycolw; + colw[kv.key()] = mycolw; } - // Print header - uint32_t maxlen = 1; - for(const auto& kv : results.items()) - { - if(ignorekeys.count(kv.key())==1) continue; + // Print header + uint32_t maxlen = 1; + for (const auto& kv : results.items()) { + if (ignorekeys.count(kv.key()) == 1) continue; - std::cout << std::setw(colw[kv.key()]) << kv.key(); + std::cout << std::setw(colw[kv.key()]) << kv.key(); - if(kv.value().is_array()) - maxlen=kv.value().size(); + if (kv.value().is_array()) maxlen = kv.value().size(); } - std::cout << std::endl; - - // Print values - for(uint32_t i=0; i<maxlen; i++) - { - for(const auto& kv : results.items()) - { - if(ignorekeys.count(kv.key())==1) continue; - - uint32_t pad=colw[kv.key()]; - - const json& value=(kv.value().is_array())? kv.value()[i] : kv.value(); - - std::cout << std::setw(pad); - if(value.is_string()) - std::cout << value.get<std::string>(); - else if(value.is_number_float()) - std::cout << std::scientific << std::setprecision(2) << value.get<float>(); - else if(value.is_number_integer()) - std::cout << value.get<int32_t>(); - else - std::cout << value.get<uint32_t>(); - } - std::cout << std::endl; + std::cout << std::endl; + + // Print values + for (uint32_t i = 0; i < maxlen; i++) { + for (const auto& kv : results.items()) { + if (ignorekeys.count(kv.key()) == 1) continue; + + uint32_t pad = colw[kv.key()]; + + const json& value = + (kv.value().is_array()) ? kv.value()[i] : kv.value(); + + std::cout << std::setw(pad); + if (value.is_string()) + std::cout << value.get<std::string>(); + else if (value.is_number_float()) + std::cout << std::scientific << std::setprecision(2) + << value.get<float>(); + else if (value.is_number_integer()) + std::cout << value.get<int32_t>(); + else + std::cout << value.get<uint32_t>(); + } + std::cout << std::endl; } } -void PBv3Utils::createDirectory(const std::string& path) -{ - if(mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) - { - if(errno == EEXIST) - { /* Path already exists, ok */ } - - else - { - logger(logERROR) << "Cannot create folder " << path << ". Error: " << strerror(errno); - throw std::runtime_error(strerror(errno)); - } +void PBv3Utils::createDirectory(const std::string& path) { + if (mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) { + if (errno == EEXIST) { /* Path already exists, ok */ + } + + else { + logger(logERROR) << "Cannot create folder " << path + << ". Error: " << strerror(errno); + throw std::runtime_error(strerror(errno)); + } } } -void PBv3Utils::mergeResult(nlohmann::json& baseResult, const nlohmann::json& addResult) -{ - bool passed=baseResult["passed"] && addResult["passed"]; - baseResult.merge_patch(addResult); - baseResult["passed"]=passed; +void PBv3Utils::mergeResult(nlohmann::json& baseResult, + const nlohmann::json& addResult) { + bool passed = baseResult["passed"] && addResult["passed"]; + baseResult.merge_patch(addResult); + baseResult["passed"] = passed; } diff --git a/pbv3/PBv3Utils.h b/pbv3/PBv3Utils.h index 892a3c777f3068ca7c97a4c4727d75f3e4df6001..816b0b08c18c89674112b12debf0fbb6c79323bd 100644 --- a/pbv3/PBv3Utils.h +++ b/pbv3/PBv3Utils.h @@ -4,58 +4,57 @@ #include <chrono> #include <iomanip> #include <iostream> - #include <nlohmann/json.hpp> -namespace PBv3Utils -{ +namespace PBv3Utils { + +//! \brief Formats the time in a human-readable format. +/** + * The time is formatted as follows: YEAR_MONTH_DAY-HOUR:MINUTE:SECOND + * + * \param t time point + * + * \return string containing date/time + */ +std::string getTimeAsString(std::chrono::system_clock::time_point t); - //! \brief Formats the time in a human-readable format. - /** - * The time is formatted as follows: YEAR_MONTH_DAY-HOUR:MINUTE:SECOND - * - * \param t time point - * - * \return string containing date/time - */ - std::string getTimeAsString(std::chrono::system_clock::time_point t); +//! \brief Pretty print results stored in a JSON file +/** + * Prints the different columns in the results structure in + * a table. The text is formatted such that all columns + * align nicely. + * + * If an field is an array, then multiple rows are printed. + * In this case, scalar fields are repeated. There is an + * assumption that all arrays are of the same length. + * + * The following columns (keys of `results`) are ignored: + * - TIMESTART + * - TIMEEND + * + * \param results JSON dictionary containing results + */ +void printResults(const nlohmann::json& results); - //! \brief Pretty print results stored in a JSON file - /** - * Prints the different columns in the results structure in - * a table. The text is formatted such that all columns - * align nicely. - * - * If an field is an array, then multiple rows are printed. - * In this case, scalar fields are repeated. There is an - * assumption that all arrays are of the same length. - * - * The following columns (keys of `results`) are ignored: - * - TIMESTART - * - TIMEEND - * - * \param results JSON dictionary containing results - */ - void printResults(const nlohmann::json& results); +//! \brief Create directory at path, if it does not already exist +/** + * All parent directories must already exist. + * + * \param path Path for directory. + */ +void createDirectory(const std::string& path); - //! \brief Create directory at path, if it does not already exist - /** - * All parent directories must already exist. - * - * \param path Path for directory. - */ - void createDirectory(const std::string& path); - - //! Merge test results - /** - * Logic to merge is as follows: - * - `/passed` is the AND of the two inputs. This field must already be present in both. - * - Contents of base is updated using `merge_patch`. - * - * \param baseResult Base result that will be updated in-place - * \param addResult New data that will be merged into `baseResult` - */ - void mergeResult(nlohmann::json& baseResult, const nlohmann::json& addResult); -} +//! Merge test results +/** + * Logic to merge is as follows: + * - `/passed` is the AND of the two inputs. This field must already be present + * in both. + * - Contents of base is updated using `merge_patch`. + * + * \param baseResult Base result that will be updated in-place + * \param addResult New data that will be merged into `baseResult` + */ +void mergeResult(nlohmann::json& baseResult, const nlohmann::json& addResult); +} // namespace PBv3Utils -#endif // PBV3UTILS_H +#endif // PBV3UTILS_H diff --git a/pbv3/ftdihelp.cpp b/pbv3/ftdihelp.cpp index d82c45b4ddd01a5956f133d2fcc973fdcfc1e553..a9201fadd8c51c511b6c2f0542792abf0cda64ee 100644 --- a/pbv3/ftdihelp.cpp +++ b/pbv3/ftdihelp.cpp @@ -5,21 +5,18 @@ #include <chrono> #include <thread> -int32_t ftdi_read_alldata(struct ftdi_context *ftdi, std::vector<uint8_t>& data, uint32_t requested) -{ - data.resize(requested); - uint32_t cnt=0; - for(uint8_t tryIdx=0;tryIdx<10;tryIdx++) - { - int32_t ret=ftdi_read_data(ftdi, &data[cnt], data.size()-cnt); - if(ret<0) - return ret; - cnt+=ret; - if(cnt==requested) return cnt; +int32_t ftdi_read_alldata(struct ftdi_context* ftdi, std::vector<uint8_t>& data, + uint32_t requested) { + data.resize(requested); + uint32_t cnt = 0; + for (uint8_t tryIdx = 0; tryIdx < 10; tryIdx++) { + int32_t ret = ftdi_read_data(ftdi, &data[cnt], data.size() - cnt); + if (ret < 0) return ret; + cnt += ret; + if (cnt == requested) return cnt; - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } - return cnt; + return cnt; } - diff --git a/pbv3/ftdihelp.h b/pbv3/ftdihelp.h index 1399abc1c9d2f0109bb02bf9b7eb278e7e870185..e96b2c36c3428d6da2a1ef3c0ea0cb7f20431234 100644 --- a/pbv3/ftdihelp.h +++ b/pbv3/ftdihelp.h @@ -1,8 +1,8 @@ #ifndef FTDIHELP_H #define FTDIHELP_H -#include <vector> #include <cstdint> +#include <vector> //! read all requested data /** @@ -18,7 +18,7 @@ * * \return Number of bytes read. Equals to `requested` if no timeout occured. */ -int32_t ftdi_read_alldata(struct ftdi_context* ftdi, std::vector<uint8_t>& data, uint32_t requested); - -#endif // FTDIHELP_H +int32_t ftdi_read_alldata(struct ftdi_context* ftdi, std::vector<uint8_t>& data, + uint32_t requested); +#endif // FTDIHELP_H diff --git a/pbv3/tools/EndeavourBER.cpp b/pbv3/tools/EndeavourBER.cpp index 0d56e613aa59b10233fe5cfede763e2583bd99db..4a6d9ca191bdd2e5410c2a6544541782d03b7d30 100644 --- a/pbv3/tools/EndeavourBER.cpp +++ b/pbv3/tools/EndeavourBER.cpp @@ -1,103 +1,100 @@ #include "AMACv2.h" #ifdef FTDI #include "EndeavourRawFTDI.h" -#else +#else #include "EndeavourRawUIO.h" -#endif // FTDI -#include "ComIOException.h" -#include "EndeavourComException.h" -#include "UIOCom.h" - +#endif // FTDI #include <unistd.h> -#include <iostream> + #include <iomanip> -#include <vector> +#include <iostream> #include <memory> +#include <vector> + +#include "ComIOException.h" +#include "EndeavourComException.h" +#include "UIOCom.h" // Option parsing -uint32_t amacid=0; -uint32_t trails=1000; +uint32_t amacid = 0; +uint32_t trails = 1000; #ifndef FTDI -std::string uiodev="/dev/uio0"; -#endif // FTDI +std::string uiodev = "/dev/uio0"; +#endif // FTDI -void print_help() -{ - std::cout << "usage: EndeavourBER [driver options]" << std::endl; - std::cout << std::endl; - std::cout << "driver options" << std::endl; - std::cout << " -a amacid: amacid to use for communication (default: " << amacid << ")" << std::endl; - std::cout << " -n trails: number of tests to run (default: " << trails << ")" << std::endl; +void print_help() { + std::cout << "usage: EndeavourBER [driver options]" << std::endl; + std::cout << std::endl; + std::cout << "driver options" << std::endl; + std::cout << " -a amacid: amacid to use for communication (default: " + << amacid << ")" << std::endl; + std::cout << " -n trails: number of tests to run (default: " << trails + << ")" << std::endl; #ifndef FTDI - std::cout << " -d uio: UIO device to use (default: " << uiodev << ")" << std::endl; -#endif // FTID + std::cout << " -d uio: UIO device to use (default: " << uiodev << ")" + << std::endl; +#endif // FTID } -int main(int argc, char* argv[]) -{ - // Parse options - int opt; +int main(int argc, char* argv[]) { + // Parse options + int opt; #ifdef FTDI - while( (opt = getopt(argc, argv, "a:n:")) != -1 ) + while ((opt = getopt(argc, argv, "a:n:")) != -1) #else - while( (opt = getopt(argc, argv, "d:a:n:")) != -1 ) + while ((opt = getopt(argc, argv, "d:a:n:")) != -1) #endif { - switch( opt ) - { - case 'a': - amacid=std::stoul(optarg, nullptr, 0); - break; - case 'n': - trails=std::stoul(optarg, nullptr, 0); - break; + switch (opt) { + case 'a': + amacid = std::stoul(optarg, nullptr, 0); + break; + case 'n': + trails = std::stoul(optarg, nullptr, 0); + break; #ifndef FTDI - case 'd': - uiodev=optarg; - break; + case 'd': + uiodev = optarg; + break; #endif - default: - case '?': // unknown option... - print_help(); - return 1; - break; - } + default: + case '?': // unknown option... + print_help(); + return 1; + break; + } } - // - // Run test - + // + // Run test + #ifdef FTDI - AMACv2 amac(amacid,std::unique_ptr<EndeavourRaw>(new EndeavourRawFTDI())); + AMACv2 amac(amacid, std::unique_ptr<EndeavourRaw>(new EndeavourRawFTDI())); #else - std::shared_ptr<UIOCom> uio=std::make_shared<UIOCom>(uiodev,0x10000); - AMACv2 amac(amacid,std::unique_ptr<EndeavourRaw>(new EndeavourRawUIO(uio))); -#endif //FTDI + std::shared_ptr<UIOCom> uio = std::make_shared<UIOCom>(uiodev, 0x10000); + AMACv2 amac(amacid, + std::unique_ptr<EndeavourRaw>(new EndeavourRawUIO(uio))); +#endif // FTDI - uint good=0; - for(uint i=0; i<trails; i++) - { - try - { - uint valin=rand()*0xFFFFFFFF; - amac.write_reg(166,valin); - usleep(50); - uint valout=amac.read_reg(166); - usleep(50); - if(valin==valout) - good++; - else - std::cout << "Write: 0x" << std::hex << valin << ", Read: " << valout << std::dec << std::endl; - } - catch(EndeavourComException &e) - { - std::cout << e.what() << std::endl; + uint good = 0; + for (uint i = 0; i < trails; i++) { + try { + uint valin = rand() * 0xFFFFFFFF; + amac.write_reg(166, valin); + usleep(50); + uint valout = amac.read_reg(166); + usleep(50); + if (valin == valout) + good++; + else + std::cout << "Write: 0x" << std::hex << valin + << ", Read: " << valout << std::dec << std::endl; + } catch (EndeavourComException& e) { + std::cout << e.what() << std::endl; } } - std::cout << "Reliability: " << ((float)good)/trails << std::endl; - - + std::cout << "Reliability: " << ((float)good) / trails << std::endl; - return 0; + return 0; } diff --git a/pbv3/tools/endeavour.cpp b/pbv3/tools/endeavour.cpp index e8805100282beda051636b4b4c2691351de7cd64..2a9e69487541f507efe1b0fa2522c4fe31b40953 100644 --- a/pbv3/tools/endeavour.cpp +++ b/pbv3/tools/endeavour.cpp @@ -1,18 +1,17 @@ -#include <unistd.h> -#include <string.h> +#include <Logger.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <iomanip> #include <iostream> -#include <Logger.h> - #include "EndeavourComException.h" -#include "PBv3TBConf.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" //#include "EndeavourRawYARR.h" -#include "EndeavourRawElinks.h" #include "EndeavourComComline2.h" +#include "EndeavourRawElinks.h" //------ SETTINGS uint8_t pbNum = 0; @@ -26,505 +25,545 @@ bool do_not_wait_replies = false; unsigned short amacid = 1; unsigned short itsdaq_bus_channel = 0; -std::string itsdaq_path = "endeavourTest --ip 192.168.222.16"; -//bool amacid_comes_from_commandline = false; +std::string itsdaq_path = "endeavourTest --ip 192.168.222.16"; +// bool amacid_comes_from_commandline = false; //--------------- //------ fallback config file for a FelixYarrNetio setup -#define FALLBACK_NETIO_CONFIG_PATH "/opt/atlas/configs_yarr/controller/netio_amac.json" -std::string fallback_equipConfig("{" -" \"version\": \"1.0\"," -"" -" \"testbenches\": {" -" \"comment\": \"The default will be used by the tools.\"," -" \"default\": {" -" \"type\" : \"PBv3TBNetIO\"," -" \"config\" : \"" FALLBACK_NETIO_CONFIG_PATH "\"," -" \"amacid\" : 1" -" }" -" }" -"}"); +#define FALLBACK_NETIO_CONFIG_PATH \ + "/opt/atlas/configs_yarr/controller/netio_amac.json" +std::string fallback_equipConfig( + "{" + " \"version\": \"1.0\"," + "" + " \"testbenches\": {" + " \"comment\": \"The default will be used by the tools.\"," + " \"default\": {" + " \"type\" : \"PBv3TBNetIO\"," + " \"config\" : \"" FALLBACK_NETIO_CONFIG_PATH + "\"," + " \"amacid\" : 1" + " }" + " }" + "}"); //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] command [command parameters]" << std::endl; - std::cerr << std::endl; - std::cerr << "commands" << std::endl; - //std::cerr << " reset: reset the Endeavour master firmware" << std::endl; - std::cerr << " setid idpads/efuse internalid: set amacid for internalid efuse or idpads" << std::endl; - std::cerr << " write address data: write data to address " << std::endl; - std::cerr << " read address: read address " << std::endl; - std::cerr << " readnext: read next register " << std::endl; - std::cerr << " wrField name data: write data to a data field " << std::endl; - std::cerr << " rdField name: read a data field " << std::endl; - std::cerr << " readDataFieldName name: read a shortcut data field " << std::endl; - std::cerr << " getversion: detect the AMAC version " << std::endl; - std::cerr << " calibrate [calibration.json]: set the calibration data (from the file or defaults) " << std::endl << std::endl; - std::cerr << " readCalibratedData fieldName [calibration.json]: read calibrated data, calibrate with the dafault or [given] file" << std::endl << std::endl; - std::cerr << " readProperties: read AMAC fields, i.e. properties in the calibration file" << std::endl << std::endl; - - std::cerr << "List of options:" << std::endl; - //std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - //std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -c, --cfg config.json Connection configuration file (if not provided: default cfg, then default param-s)" << std::endl; - std::cerr << " -n, --icnetio Use ICNETIO as the connection backend, if it is built" << std::endl; - std::cerr << " -i, --amacid 21 The AMACID you want to talk to (default: " << amacid << ")" << std::endl; - std::cerr << " -x, --external Use external powertools commandline (OPC server testing)" << std::endl; - std::cerr << " -w, --nowait Do not wait for replies" << std::endl; - std::cerr << " -q, --itsdaq Use endeavourTest from ITSDAQ, requires path: endeavourTest --ip ..." << std::endl; - std::cerr << " -b, --bus Use endeavourTest from ITSDAQ, sets --channel <bus_channel>" << std::endl; - std::cerr << " -d, --debug Enable verbose printout" << std::endl; - std::cerr << " -h, --help Print usage info" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] + << " [options] command [command parameters]" << std::endl; + std::cerr << std::endl; + std::cerr << "commands" << std::endl; + // std::cerr << " reset: reset the Endeavour master firmware" << std::endl; + std::cerr << " setid idpads/efuse internalid: set amacid for internalid " + "efuse or idpads" + << std::endl; + std::cerr << " write address data: write data to address " << std::endl; + std::cerr << " read address: read address " << std::endl; + std::cerr << " readnext: read next register " << std::endl; + std::cerr << " wrField name data: write data to a data field " << std::endl; + std::cerr << " rdField name: read a data field " << std::endl; + std::cerr << " readDataFieldName name: read a shortcut data field " + << std::endl; + std::cerr << " getversion: detect the AMAC version " << std::endl; + std::cerr << " calibrate [calibration.json]: set the calibration data " + "(from the file or defaults) " + << std::endl + << std::endl; + std::cerr << " readCalibratedData fieldName [calibration.json]: read " + "calibrated data, calibrate with the dafault or [given] file" + << std::endl + << std::endl; + std::cerr << " readProperties: read AMAC fields, i.e. properties in the " + "calibration file" + << std::endl + << std::endl; + + std::cerr << "List of options:" << std::endl; + // std::cerr << " -b, --board Powerboard number (default: " << + // (uint32_t)pbNum << ")" << std::endl; std::cerr << " -e, --equip + // config.json Equipment configuration file (default: " << equipConfigFile << + // ")" << std::endl; + std::cerr << " -c, --cfg config.json Connection configuration file (if " + "not provided: default cfg, then default param-s)" + << std::endl; + std::cerr << " -n, --icnetio Use ICNETIO as the connection " + "backend, if it is built" + << std::endl; + std::cerr + << " -i, --amacid 21 The AMACID you want to talk to (default: " + << amacid << ")" << std::endl; + std::cerr << " -x, --external Use external powertools commandline " + "(OPC server testing)" + << std::endl; + std::cerr << " -w, --nowait Do not wait for replies" + << std::endl; + std::cerr << " -q, --itsdaq Use endeavourTest from ITSDAQ, " + "requires path: endeavourTest --ip ..." + << std::endl; + std::cerr << " -b, --bus Use endeavourTest from ITSDAQ, sets " + "--channel <bus_channel>" + << std::endl; + std::cerr << " -d, --debug Enable verbose printout" + << std::endl; + std::cerr << " -h, --help Print usage info" << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 1) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 1) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - //{"board" , required_argument, 0, 'b' }, - //{"equip" , required_argument, 0, 'e' }, - {"cfg" , required_argument, 0, 'c' }, - {"icnetio" , no_argument , 0, 'n' }, - {"amacid" , required_argument, 0, 'i' }, - {"itsdaq" , required_argument, 0, 'q' }, - {"bus" , required_argument, 0, 'b' }, - {"external" , no_argument , 0, 'x' }, - {"nowait" , no_argument , 0, 'w' }, - {"debug" , no_argument , 0, 'd' }, - {"help" , no_argument , 0, 'h' }, - {0 , 0 , 0, 0 } - }; - - //c = getopt_long(argc, argv, "b:e:i:dh", long_options, &option_index); - c = getopt_long(argc, argv, "c:i:xwdhq:b:", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'h': - usage(argv); - return 0; - - case 'b': - itsdaq_bus_channel = atoi(optarg); - break; - - case 'q': - use_itsdaq = true; - itsdaq_path = optarg; - break; - - case 'c': - equipConfigFile = optarg; - //equipConfigFile_is_provided = true; - break; - - case 'n': - use_icnetio = true; - break; - - case 'i': - amacid = atoi(optarg); - //amacid_comes_from_commandline = true; - break; - - case 'x': - use_external_powertools = true; - break; - - case 'w': - do_not_wait_replies = true; - break; - - case 'd': - logIt::incrDebug(); - break; - - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + //{"board" , required_argument, 0, 'b' }, + //{"equip" , required_argument, 0, 'e' }, + {"cfg", required_argument, 0, 'c'}, + {"icnetio", no_argument, 0, 'n'}, + {"amacid", required_argument, 0, 'i'}, + {"itsdaq", required_argument, 0, 'q'}, + {"bus", required_argument, 0, 'b'}, + {"external", no_argument, 0, 'x'}, + {"nowait", no_argument, 0, 'w'}, + {"debug", no_argument, 0, 'd'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0}}; + + // c = getopt_long(argc, argv, "b:e:i:dh", long_options, &option_index); + c = getopt_long(argc, argv, "c:i:xwdhq:b:", long_options, + &option_index); + if (c == -1) break; + + switch (c) { + case 'h': + usage(argv); + return 0; + + case 'b': + itsdaq_bus_channel = atoi(optarg); + break; + + case 'q': + use_itsdaq = true; + itsdaq_path = optarg; + break; + + case 'c': + equipConfigFile = optarg; + // equipConfigFile_is_provided = true; + break; + + case 'n': + use_icnetio = true; + break; + + case 'i': + amacid = atoi(optarg); + // amacid_comes_from_commandline = true; + break; + + case 'x': + use_external_powertools = true; + break; + + case 'w': + do_not_wait_replies = true; + break; + + case 'd': + logIt::incrDebug(); + break; + + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; + } } - // Determine the command - if(argc<=optind) - { - usage(argv); - return 1; + // Determine the command + if (argc <= optind) { + usage(argv); + return 1; } - std::string command=argv[optind++]; - std::vector<std::string> params; - while (optind < argc) - { - std::string p(argv[optind++]); - params.push_back(p); + std::string command = argv[optind++]; + std::vector<std::string> params; + while (optind < argc) { + std::string p(argv[optind++]); + params.push_back(p); } - // Create and initialize the AMAC - std::shared_ptr<AMACv2> amac; + // Create and initialize the AMAC + std::shared_ptr<AMACv2> amac; - // check if an external commandline powertools is required (OPC server testing) - // if not -- connect to netio - // check if a config file is provided for the connection - // if not, just make a default connection - try - { + // check if an external commandline powertools is required (OPC server + // testing) if not -- connect to netio check if a config file is provided + // for the connection if not, just make a default connection + try { + if (use_external_powertools) { + amac = std::make_shared<AMACv2>( + amacid, std::make_shared<EndeavourComComline2>("endeavour -w")); + } - if (use_external_powertools) - { - amac = std::make_shared<AMACv2>(amacid, std::make_shared<EndeavourComComline2>("endeavour -w")); - } + else if (use_itsdaq) { + logger(logDEBUG) << "Using ITSDAQ with path: " << itsdaq_path + << " and bus channel: " << itsdaq_bus_channel; + amac = std::make_shared<AMACv2>( + amacid, std::make_shared<EndeavourComComline>( + itsdaq_path, itsdaq_bus_channel)); + } + + // is it really needed? + // else if (equipConfigFile.size() > 0) + // { + // amac = std::make_shared<AMACv2>(amacid, + // std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks(use_icnetio, + // equipConfigFile))); + // } + + else { + // amac = std::make_shared<AMACv2>(amacid, + // std::unique_ptr<EndeavourRaw>(new + // EndeavourRawElinks(use_icnetio))); + amac = std::make_shared<AMACv2>( + amacid, + std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks( + use_icnetio, equipConfigFile, do_not_wait_replies))); + } - else if (use_itsdaq) + amac->connect(); + } + + catch (std::runtime_error e) { + std::cerr << e.what() << std::endl; + return 2; + } + + /* abandon this -- implement testbench scripts in pybind + if (amacid_comes_from_commandline && !equipConfigFile_is_provided) { - logger(logDEBUG) << "Using ITSDAQ with path: " << itsdaq_path << " and bus channel: " << itsdaq_bus_channel; - amac = std::make_shared<AMACv2>(amacid, std::make_shared<EndeavourComComline>(itsdaq_path, itsdaq_bus_channel)); + logger(logDEBUG) << "Direct AMAC: " << (uint32_t)amacid; + //amac = std::make_shared<AMACv2>(amacid, + std::unique_ptr<EndeavourRaw>(new EndeavourRawYARR("Netio", + FALLBACK_NETIO_CONFIG_PATH))); amac = std::make_shared<AMACv2>(amacid, + std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks())); + //amac = std::make_shared<AMACv2>(amacid, + std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks(0x1c, 0x14, + FALLBACK_EC_LINK_LOCK_FILE))); + //unsigned int rx_elink_n = 0x1c, + //unsigned int tx_elink_n = 0x14, + //std::string lock_filename = FALLBACK_EC_LINK_LOCK_FILE); } - // is it really needed? - //else if (equipConfigFile.size() > 0) - // { - // amac = std::make_shared<AMACv2>(amacid, std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks(use_icnetio, equipConfigFile))); - // } - else { - //amac = std::make_shared<AMACv2>(amacid, std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks(use_icnetio))); - amac = std::make_shared<AMACv2>(amacid, std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks(use_icnetio, equipConfigFile, do_not_wait_replies))); - } + // the standard powertools way through the TB object + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - amac->connect(); - } + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb; + if (equipConfigFile == "dummy_netio") + { + logger(logDEBUG) << " No equipment config is provided - set up a dummy + TB and use commandline arguments only"; json fallback_equipConfig_json = + json::parse(fallback_equipConfig); + factory_pbv3tb.setHardwareConfig(fallback_equipConfig_json); + } - catch(std::runtime_error e) - { - std::cerr << e.what() << std::endl; - return 2; - } + else + factory_pbv3tb.setHardwareConfig(equipConfigFile); - /* abandon this -- implement testbench scripts in pybind - if (amacid_comes_from_commandline && !equipConfigFile_is_provided) - { - logger(logDEBUG) << "Direct AMAC: " << (uint32_t)amacid; - //amac = std::make_shared<AMACv2>(amacid, std::unique_ptr<EndeavourRaw>(new EndeavourRawYARR("Netio", FALLBACK_NETIO_CONFIG_PATH))); - amac = std::make_shared<AMACv2>(amacid, std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks())); - //amac = std::make_shared<AMACv2>(amacid, std::unique_ptr<EndeavourRaw>(new EndeavourRawElinks(0x1c, 0x14, FALLBACK_EC_LINK_LOCK_FILE))); - //unsigned int rx_elink_n = 0x1c, - //unsigned int tx_elink_n = 0x14, - //std::string lock_filename = FALLBACK_EC_LINK_LOCK_FILE); - } + std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); + if(tb==nullptr) + return 1; - else - { - // the standard powertools way through the TB object - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + // get the AMAC powerboard from the TB + amac = tb->getPB(pbNum); - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb; - if (equipConfigFile == "dummy_netio") - { - logger(logDEBUG) << " No equipment config is provided - set up a dummy TB and use commandline arguments only"; - json fallback_equipConfig_json = json::parse(fallback_equipConfig); - factory_pbv3tb.setHardwareConfig(fallback_equipConfig_json); + // commandline -i amacid overwrites what's in the config file + if (amacid_comes_from_commandline) amac->_set_amacid(amacid); } + */ + + // Run the commands + try { + // if(command=="reset") + // { + // amac->reset(); + // } + + if (command == "setid") { + // Need two more + if (params.size() < 2) { + usage(argv); + return 1; + } - else - factory_pbv3tb.setHardwareConfig(equipConfigFile); + EndeavourCom::REFMODE refmode; + if (params[0] == "idpads") + refmode = EndeavourCom::REFMODE::IDPads; + else if (params[0] == "efuse") + refmode = EndeavourCom::REFMODE::EfuseId; + else { + std::cerr << "Could not recognize the reference mode for " + "SETID: idpads or efuse?" + << std::endl; + usage(argv); + return 1; + } + unsigned int refid = std::stoul(params[1], nullptr, 0); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + amac->setid(refmode, refid); + } - // get the AMAC powerboard from the TB - amac = tb->getPB(pbNum); + else if (command == "write") { + // Need two more + if (params.size() < 2) { + usage(argv); + return 1; + } - // commandline -i amacid overwrites what's in the config file - if (amacid_comes_from_commandline) amac->_set_amacid(amacid); - } - */ - - // Run the commands - try - { -// if(command=="reset") -// { -// amac->reset(); -// } - - if(command=="setid") - { - // Need two more - if(params.size()<2) - { - usage(argv); - return 1; - } - - EndeavourCom::REFMODE refmode; - if (params[0]=="idpads") refmode = EndeavourCom::REFMODE::IDPads; - else if (params[0]=="efuse") refmode = EndeavourCom::REFMODE::EfuseId; - else - { - std::cerr << "Could not recognize the reference mode for SETID: idpads or efuse?" << std::endl; - usage(argv); - return 1; - } - unsigned int refid=std::stoul(params[1], nullptr, 0); - - amac->setid(refmode,refid); - } - - else if(command=="write") - { - // Need two more - if(params.size()<2) - { - usage(argv); - return 1; - } - - unsigned int address=std::stoul(params[0], nullptr, 0); - unsigned int data=std::stoul(params[1], nullptr, 0); - - amac->write_reg(address,data); - } - - else if(command=="read") - { - // Need one more - if(params.size()<1) - { - usage(argv); - return 1; - } - - unsigned int address=std::stoul(params[0], nullptr, 0); - - unsigned int read=amac->read_reg(address); // to establish the connection to felixcore - //read=amac->read_reg(address); // to measure the timing - std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << read << std::endl; - } - - else if(command=="readnext") - { - // Need one more - if(params.size()>0) - { - usage(argv); - return 1; - } - - unsigned int read=amac->readnext_reg(); - std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << read << std::endl; - } - - else if(command=="wrField") - { - // Need two more - if(params.size()<2) - { - usage(argv); - return 1; - } - - // set register map - amac->detectAndSetVersion(); - - //unsigned int address=std::stoul(params[0], nullptr, 0); - std::string field_name(params[0]); - unsigned int data=std::stoul(params[1], nullptr, 0); - - amac->rdField(field_name); // to set the current value of the HW register in SW - amac->wrField(field_name, data); - std::cout << "wrote 0x" << std::hex << std::setw(8) << std::setfill('0') << data << " to " << field_name << std::endl; - } - - else if(command=="rdField") - { - // Need one more - if(params.size()<1) - { - usage(argv); - return 1; - } - - // set register map - amac->detectAndSetVersion(); - - //unsigned int address=std::stoul(params[0], nullptr, 0); - std::string field_name(params[0]); - //std::cout << "reading " << field_name << std::endl; - - unsigned int field_data=amac->rdField(field_name); - std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << field_data << std::endl; - } - - else if(command=="readDataFieldName") - { - // Need one more - if(params.size()<1) - { - usage(argv); - return 1; - } - - // set register map - amac->detectAndSetVersion(); - - //unsigned int address=std::stoul(params[0], nullptr, 0); - std::string field_name(params[0]); - //std::cout << "reading " << field_name << std::endl; - - unsigned int field_data=amac->readDataFieldName(field_name); - std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << field_data << std::endl; - } - - else if(command=="getversion") - { - // no more parameters - if(params.size()>0) - { - usage(argv); - return 1; - } - - unsigned int ver_id = amac->read_version(); - AMACv2::Version ver = amac->convertVersion(ver_id); - std::cout << "version: " << ver_id << " = " << (ver == AMACv2::Version::v2? "v2" : ver == AMACv2::Version::star ? "star" : "unknown") << std::endl; - } - - - else if(command=="calibrate") - { - // if there is one param - if(params.size()<1) - { - PBv3ConfigTools::configAMAC_default(amac, true, true); - } - - else if (params.size() == 1) - { - std::string calibrations_filename(params[0]); - PBv3ConfigTools::configAMAC_file(amac, calibrations_filename, true); - } - - else - { - usage(argv); - return 1; - } - - } - - else if(command=="readCalibratedData") - { - // Need one or two more - if(params.size()<1) - { - usage(argv); - return 1; - } - - // set register map - amac->detectAndSetVersion(); - amac->loadRegisters(); - - std::string data_field_name(params[0]); - double res = -1.1; - - // load calibration - if(params.size() == 1) - { - // use default - logger(logDEBUG) << "readCalibratedData with default calibrations file"; - PBv3ConfigTools::configAMAC_default(amac, true, true); - } - - else - { - // use the givel calibrations dir - std::string calibrations_dir(params[1]); - std::string std_calibration_filename = "calibrations_test_amac_pads_" + std::to_string(amacid) + ".json"; - std::string calibrations_file = calibrations_dir + "/" + std_calibration_filename; - logger(logDEBUG) << "readCalibratedData with calibrations file: " << calibrations_file; - - PBv3ConfigTools::configAMAC_file(amac, calibrations_file, true); + unsigned int address = std::stoul(params[0], nullptr, 0); + unsigned int data = std::stoul(params[1], nullptr, 0); + + amac->write_reg(address, data); + } + + else if (command == "read") { + // Need one more + if (params.size() < 1) { + usage(argv); + return 1; } - if (data_field_name == "temperatureX") res = amac -> temperatureX(true); // autorange = true - else if (data_field_name == "temperatureY") res = amac -> temperatureY(true); - else if (data_field_name == "temperaturePB") res = amac -> temperaturePB(true); - else if (data_field_name == "getNTCx") res = amac -> getNTCx(); - else if (data_field_name == "getNTCy") res = amac -> getNTCy(); - else if (data_field_name == "getNTCpb") res = amac -> getNTCpb(); - else if (data_field_name == "temperaturePTAT") res = amac -> temperaturePTAT(); - else if (data_field_name == "temperatureCTAT") res = amac -> temperatureCTAT(); - else if (data_field_name == "getCur10V") res = amac -> getCur10V(); - else if (data_field_name == "getCur1V") res = amac -> getCur1V(); - else if (data_field_name == "current10V") res = amac -> current10V(); - else if (data_field_name == "current1V") res = amac -> current1V(); - else if (data_field_name == "getHVret") res = amac -> getHVret(true); // autorange = true - else if (data_field_name == "getHVcur") res = amac -> getHVcur(true); - - else - { - std::cerr << "readCalibratedData unknown calibrated data field " << data_field_name << std::endl; - return -200; - } - - std::cout << res << std::endl; + unsigned int address = std::stoul(params[0], nullptr, 0); + + unsigned int read = amac->read_reg( + address); // to establish the connection to felixcore + // read=amac->read_reg(address); // to measure the timing + std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') + << read << std::endl; } - else if(command=="readProperties") - { - logger(logDEBUG) << "readProperties"; - - // set register map - amac->detectAndSetVersion(); - // load the HW state - amac->loadRegisters(); - - // - // Get register values - for(const AMACv2Field* field : amac->getFields()) - { - if(field->isReadWrite()) - std::cout << field->getName() << " " << field->read() << std::endl; - } + else if (command == "readnext") { + // Need one more + if (params.size() > 0) { + usage(argv); + return 1; + } + + unsigned int read = amac->readnext_reg(); + std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') + << read << std::endl; } - else - { - std::cerr << "the command is unknown: " << command << std::endl; - return -100; + else if (command == "wrField") { + // Need two more + if (params.size() < 2) { + usage(argv); + return 1; + } + + // set register map + amac->detectAndSetVersion(); + + // unsigned int address=std::stoul(params[0], nullptr, 0); + std::string field_name(params[0]); + unsigned int data = std::stoul(params[1], nullptr, 0); + + amac->rdField(field_name); // to set the current value of the HW + // register in SW + amac->wrField(field_name, data); + std::cout << "wrote 0x" << std::hex << std::setw(8) + << std::setfill('0') << data << " to " << field_name + << std::endl; + } + + else if (command == "rdField") { + // Need one more + if (params.size() < 1) { + usage(argv); + return 1; + } + + // set register map + amac->detectAndSetVersion(); + + // unsigned int address=std::stoul(params[0], nullptr, 0); + std::string field_name(params[0]); + // std::cout << "reading " << field_name << std::endl; + + unsigned int field_data = amac->rdField(field_name); + std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') + << field_data << std::endl; + } + + else if (command == "readDataFieldName") { + // Need one more + if (params.size() < 1) { + usage(argv); + return 1; + } + + // set register map + amac->detectAndSetVersion(); + + // unsigned int address=std::stoul(params[0], nullptr, 0); + std::string field_name(params[0]); + // std::cout << "reading " << field_name << std::endl; + + unsigned int field_data = amac->readDataFieldName(field_name); + std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') + << field_data << std::endl; + } + + else if (command == "getversion") { + // no more parameters + if (params.size() > 0) { + usage(argv); + return 1; + } + + unsigned int ver_id = amac->read_version(); + AMACv2::Version ver = amac->convertVersion(ver_id); + std::cout << "version: " << ver_id << " = " + << (ver == AMACv2::Version::v2 + ? "v2" + : ver == AMACv2::Version::star ? "star" + : "unknown") + << std::endl; } - amac->disconnect(); - } + else if (command == "calibrate") { + // if there is one param + if (params.size() < 1) { + PBv3ConfigTools::configAMAC_default(amac, true, true); + } + + else if (params.size() == 1) { + std::string calibrations_filename(params[0]); + PBv3ConfigTools::configAMAC_file(amac, calibrations_filename, + true); + } + + else { + usage(argv); + return 1; + } + + } + + else if (command == "readCalibratedData") { + // Need one or two more + if (params.size() < 1) { + usage(argv); + return 1; + } + + // set register map + amac->detectAndSetVersion(); + amac->loadRegisters(); + + std::string data_field_name(params[0]); + double res = -1.1; + + // load calibration + if (params.size() == 1) { + // use default + logger(logDEBUG) + << "readCalibratedData with default calibrations file"; + PBv3ConfigTools::configAMAC_default(amac, true, true); + } + + else { + // use the givel calibrations dir + std::string calibrations_dir(params[1]); + std::string std_calibration_filename = + "calibrations_test_amac_pads_" + std::to_string(amacid) + + ".json"; + std::string calibrations_file = + calibrations_dir + "/" + std_calibration_filename; + logger(logDEBUG) + << "readCalibratedData with calibrations file: " + << calibrations_file; + + PBv3ConfigTools::configAMAC_file(amac, calibrations_file, true); + } + + if (data_field_name == "temperatureX") + res = amac->temperatureX(true); // autorange = true + else if (data_field_name == "temperatureY") + res = amac->temperatureY(true); + else if (data_field_name == "temperaturePB") + res = amac->temperaturePB(true); + else if (data_field_name == "getNTCx") + res = amac->getNTCx(); + else if (data_field_name == "getNTCy") + res = amac->getNTCy(); + else if (data_field_name == "getNTCpb") + res = amac->getNTCpb(); + else if (data_field_name == "temperaturePTAT") + res = amac->temperaturePTAT(); + else if (data_field_name == "temperatureCTAT") + res = amac->temperatureCTAT(); + else if (data_field_name == "getCur10V") + res = amac->getCur10V(); + else if (data_field_name == "getCur1V") + res = amac->getCur1V(); + else if (data_field_name == "current10V") + res = amac->current10V(); + else if (data_field_name == "current1V") + res = amac->current1V(); + else if (data_field_name == "getHVret") + res = amac->getHVret(true); // autorange = true + else if (data_field_name == "getHVcur") + res = amac->getHVcur(true); + + else { + std::cerr << "readCalibratedData unknown calibrated data field " + << data_field_name << std::endl; + return -200; + } + + std::cout << res << std::endl; + } + + else if (command == "readProperties") { + logger(logDEBUG) << "readProperties"; + + // set register map + amac->detectAndSetVersion(); + // load the HW state + amac->loadRegisters(); + + // + // Get register values + for (const AMACv2Field* field : amac->getFields()) { + if (field->isReadWrite()) + std::cout << field->getName() << " " << field->read() + << std::endl; + } + } + + else { + std::cerr << "the command is unknown: " << command << std::endl; + return -100; + } + + amac->disconnect(); + } - catch(EndeavourComException e) - { - std::cerr << e.what() << std::endl; - return 1; + catch (EndeavourComException e) { + std::cerr << e.what() << std::endl; + return 1; } - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_active_calibrate.cpp b/pbv3/tools/pbv3_active_calibrate.cpp index dbe151800f63bf1b16ef935cc80537f5a5e1ce75..3635c30262afe2cceb727c1c311c0f047509f846 100644 --- a/pbv3/tools/pbv3_active_calibrate.cpp +++ b/pbv3/tools/pbv3_active_calibrate.cpp @@ -3,20 +3,18 @@ #include <chrono> #include <fstream> #include <memory> +#include <nlohmann/json.hpp> #include <string> #include <thread> -#include "Logger.h" +#include "DAC5574.h" #include "EquipConf.h" +#include "I2CDevCom.h" #include "IPowerSupply.h" +#include "Logger.h" +#include "MCP3428.h" #include "PBv3TBMassive.h" - -#include "I2CDevCom.h" #include "PCA9548ACom.h" -#include "MCP3428.h" -#include "DAC5574.h" - -#include <nlohmann/json.hpp> using nlohmann::json; //------ SETTINGS @@ -25,250 +23,277 @@ uint8_t pbNum = 0; std::string equipConfigFile = "config/equip_calib.json"; //--------------- -void usage(char *argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] filename" << std::endl; - std::cerr << "" << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number to test (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << "" << std::endl; - std::cerr << "" << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] filename" << std::endl; + std::cerr << "" << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number to test (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << "" << std::endl; + std::cerr << "" << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - loglevel = logDEBUG; - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + loglevel = logDEBUG; + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - if (argc-optind < 1) - { - std::cerr << "Not enough parameters!" << std::endl; - usage(argv); - return 1; + if (argc - optind < 1) { + std::cerr << "Not enough parameters!" << std::endl; + usage(argv); + return 1; } - std::string fileName = argv[optind++]; - - // - // Initialize the var load - std::shared_ptr<I2CCom> i2c_root=std::make_shared<I2CDevCom>(0x70, "/dev/i2c-0"); - - // Load measure - std::shared_ptr<MCP3428> adc_lvset0=std::make_shared<MCP3428>(std::make_shared<PCA9548ACom>(0x68, 5, i2c_root)); - std::shared_ptr<MCP3428> adc_lvset1=std::make_shared<MCP3428>(std::make_shared<PCA9548ACom>(0x6C, 5, i2c_root)); - std::shared_ptr<MCP3428> adc_lvset2=std::make_shared<MCP3428>(std::make_shared<PCA9548ACom>(0x6A, 5, i2c_root)); - - // Load set - std::shared_ptr<DAC5574> dac_0=std::make_shared<DAC5574>(3.25, std::make_shared<PCA9548ACom>(0x4C, 5, i2c_root)); - std::shared_ptr<DAC5574> dac_1=std::make_shared<DAC5574>(3.25, std::make_shared<PCA9548ACom>(0x4D, 5, i2c_root)); - std::shared_ptr<DAC5574> dac_2=std::make_shared<DAC5574>(3.25, std::make_shared<PCA9548ACom>(0x4E, 5, i2c_root)); - - // - // Initialize power supplies and other equipment - logger(logINFO) << "Init PS"; - EquipConf hw; - hw.setHardwareConfig(equipConfigFile); - - std::shared_ptr<PowerSupplyChannel> ps=hw.getPowerSupplyChannel("FakePB"); - if(ps==nullptr) - { - logger(logERROR) << "Unable to fetch FakePB power supply!"; - return 2; + std::string fileName = argv[optind++]; + + // + // Initialize the var load + std::shared_ptr<I2CCom> i2c_root = + std::make_shared<I2CDevCom>(0x70, "/dev/i2c-0"); + + // Load measure + std::shared_ptr<MCP3428> adc_lvset0 = std::make_shared<MCP3428>( + std::make_shared<PCA9548ACom>(0x68, 5, i2c_root)); + std::shared_ptr<MCP3428> adc_lvset1 = std::make_shared<MCP3428>( + std::make_shared<PCA9548ACom>(0x6C, 5, i2c_root)); + std::shared_ptr<MCP3428> adc_lvset2 = std::make_shared<MCP3428>( + std::make_shared<PCA9548ACom>(0x6A, 5, i2c_root)); + + // Load set + std::shared_ptr<DAC5574> dac_0 = std::make_shared<DAC5574>( + 3.25, std::make_shared<PCA9548ACom>(0x4C, 5, i2c_root)); + std::shared_ptr<DAC5574> dac_1 = std::make_shared<DAC5574>( + 3.25, std::make_shared<PCA9548ACom>(0x4D, 5, i2c_root)); + std::shared_ptr<DAC5574> dac_2 = std::make_shared<DAC5574>( + 3.25, std::make_shared<PCA9548ACom>(0x4E, 5, i2c_root)); + + // + // Initialize power supplies and other equipment + logger(logINFO) << "Init PS"; + EquipConf hw; + hw.setHardwareConfig(equipConfigFile); + + std::shared_ptr<PowerSupplyChannel> ps = hw.getPowerSupplyChannel("FakePB"); + if (ps == nullptr) { + logger(logERROR) << "Unable to fetch FakePB power supply!"; + return 2; } - // Set inital values - ps->setVoltageLevel (1.5); - ps->setCurrentProtect( 5); - - // - // Initialize the output - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; + // Set inital values + ps->setVoltageLevel(1.5); + ps->setCurrentProtect(5); + + // + // Initialize the output + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) << "Unable to create results file " << fileName; + return 2; } - // measurement - std::cout << "idx" << "\t" << "ISETcounts" << "\t" << "IPS" << "\t" << "ISENSE1" << "\t" << "ISENSE2" << "\t" << "ISENSE4" << "\t" << "ISENSE8" << "\t" << "ISET" << std::endl; - outfile << "idx" << "\t" << "ISETcounts" << "\t" << "IPS" << "\t" << "ISENSE1" << "\t" << "ISENSE2" << "\t" << "ISENSE4" << "\t" << "ISENSE8" << "\t" << "ISET" << std::endl; - - // - // Start testing - ps->turnOn(); - std::this_thread::sleep_for(std::chrono::seconds(1)); - logger(logINFO) << "Power supply turned on, voltage set to " << ps->measureVoltage() << "V" << ", current set to " << ps->measureCurrent() << "A"; - - double RLoad = 25.0e-3; - double R1 = 100e3; - double R2 = 5e3; - for(uint32_t DACcounts = 0; DACcounts<0xAC; DACcounts+=2) - { - // set load counts - switch ( pbNum ) - { - case 0 : - dac_0->setCount(DAC_CH_LOAD_PB0, DACcounts); - break; - - case 1 : - dac_0->setCount(DAC_CH_LOAD_PB1, DACcounts); - break; - - case 2 : - dac_0->setCount(DAC_CH_LOAD_PB2, DACcounts); - break; - - case 3 : - dac_0->setCount(DAC_CH_LOAD_PB3, DACcounts); - break; - - case 4 : - dac_1->setCount(DAC_CH_LOAD_PB4, DACcounts); - break; - - case 5 : - dac_1->setCount(DAC_CH_LOAD_PB5, DACcounts); - break; - - case 6 : - dac_1->setCount(DAC_CH_LOAD_PB6, DACcounts); - break; - - case 7 : - dac_1->setCount(DAC_CH_LOAD_PB7, DACcounts); - break; - - case 8 : - dac_2->setCount(DAC_CH_LOAD_PB8, DACcounts); - break; - - case 9 : - dac_2->setCount(DAC_CH_LOAD_PB9, DACcounts); - break; - - default: - // TODO throw exception - break; - } - - for(uint32_t j=0; j<100; j++) - { - std::this_thread::sleep_for(std::chrono::seconds(1)); - - double cur = ps->measureCurrent(); - - std::cout << j << "\t" << DACcounts << "\t" << cur << "\t"; - outfile << j << "\t" << DACcounts << "\t" << cur << "\t"; - - for(const MCP3428::Gain& gain : {MCP3428::Gain::x1, MCP3428::Gain::x2, MCP3428::Gain::x4, MCP3428::Gain::x8}) - { - adc_lvset0->setGain(gain); - adc_lvset1->setGain(gain); - adc_lvset2->setGain(gain); - int32_t Iload=0; - switch ( pbNum ) - { - case 0 : - Iload=adc_lvset0->readCount(ADC_ILOAD_PB0); - break; - - case 1 : - Iload=adc_lvset0->readCount(ADC_ILOAD_PB1); - break; - - case 2 : - Iload=adc_lvset0->readCount(ADC_ILOAD_PB2); - break; - - case 3 : - Iload=adc_lvset0->readCount(ADC_ILOAD_PB3); - break; - - case 4 : - Iload=adc_lvset1->readCount(ADC_ILOAD_PB4); - break; - - case 5 : - Iload=adc_lvset1->readCount(ADC_ILOAD_PB5); - break; - - case 6 : - Iload=adc_lvset1->readCount(ADC_ILOAD_PB6); - break; - - case 7 : - Iload=adc_lvset1->readCount(ADC_ILOAD_PB7); - break; - - case 8 : - Iload=adc_lvset2->readCount(ADC_ILOAD_PB8); - break; - - case 9 : - Iload=adc_lvset2->readCount(ADC_ILOAD_PB9); - break; - - default: - // TODO throw exception - Iload=0.; - break; - } - - std::cout << Iload << "\t"; - outfile << Iload << "\t"; - } - - double DACV = DACcounts*3.25/255.0; - - std::cout << DACV*R2/(R1+R2)/RLoad << std::endl; - outfile << DACV*R2/(R1+R2)/RLoad << std::endl; - } + // measurement + std::cout << "idx" + << "\t" + << "ISETcounts" + << "\t" + << "IPS" + << "\t" + << "ISENSE1" + << "\t" + << "ISENSE2" + << "\t" + << "ISENSE4" + << "\t" + << "ISENSE8" + << "\t" + << "ISET" << std::endl; + outfile << "idx" + << "\t" + << "ISETcounts" + << "\t" + << "IPS" + << "\t" + << "ISENSE1" + << "\t" + << "ISENSE2" + << "\t" + << "ISENSE4" + << "\t" + << "ISENSE8" + << "\t" + << "ISET" << std::endl; + + // + // Start testing + ps->turnOn(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + logger(logINFO) << "Power supply turned on, voltage set to " + << ps->measureVoltage() << "V" + << ", current set to " << ps->measureCurrent() << "A"; + + double RLoad = 25.0e-3; + double R1 = 100e3; + double R2 = 5e3; + for (uint32_t DACcounts = 0; DACcounts < 0xAC; DACcounts += 2) { + // set load counts + switch (pbNum) { + case 0: + dac_0->setCount(DAC_CH_LOAD_PB0, DACcounts); + break; + + case 1: + dac_0->setCount(DAC_CH_LOAD_PB1, DACcounts); + break; + + case 2: + dac_0->setCount(DAC_CH_LOAD_PB2, DACcounts); + break; + + case 3: + dac_0->setCount(DAC_CH_LOAD_PB3, DACcounts); + break; + + case 4: + dac_1->setCount(DAC_CH_LOAD_PB4, DACcounts); + break; + + case 5: + dac_1->setCount(DAC_CH_LOAD_PB5, DACcounts); + break; + + case 6: + dac_1->setCount(DAC_CH_LOAD_PB6, DACcounts); + break; + + case 7: + dac_1->setCount(DAC_CH_LOAD_PB7, DACcounts); + break; + + case 8: + dac_2->setCount(DAC_CH_LOAD_PB8, DACcounts); + break; + + case 9: + dac_2->setCount(DAC_CH_LOAD_PB9, DACcounts); + break; + + default: + // TODO throw exception + break; + } + + for (uint32_t j = 0; j < 100; j++) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + + double cur = ps->measureCurrent(); + + std::cout << j << "\t" << DACcounts << "\t" << cur << "\t"; + outfile << j << "\t" << DACcounts << "\t" << cur << "\t"; + + for (const MCP3428::Gain& gain : + {MCP3428::Gain::x1, MCP3428::Gain::x2, MCP3428::Gain::x4, + MCP3428::Gain::x8}) { + adc_lvset0->setGain(gain); + adc_lvset1->setGain(gain); + adc_lvset2->setGain(gain); + int32_t Iload = 0; + switch (pbNum) { + case 0: + Iload = adc_lvset0->readCount(ADC_ILOAD_PB0); + break; + + case 1: + Iload = adc_lvset0->readCount(ADC_ILOAD_PB1); + break; + + case 2: + Iload = adc_lvset0->readCount(ADC_ILOAD_PB2); + break; + + case 3: + Iload = adc_lvset0->readCount(ADC_ILOAD_PB3); + break; + + case 4: + Iload = adc_lvset1->readCount(ADC_ILOAD_PB4); + break; + + case 5: + Iload = adc_lvset1->readCount(ADC_ILOAD_PB5); + break; + + case 6: + Iload = adc_lvset1->readCount(ADC_ILOAD_PB6); + break; + + case 7: + Iload = adc_lvset1->readCount(ADC_ILOAD_PB7); + break; + + case 8: + Iload = adc_lvset2->readCount(ADC_ILOAD_PB8); + break; + + case 9: + Iload = adc_lvset2->readCount(ADC_ILOAD_PB9); + break; + + default: + // TODO throw exception + Iload = 0.; + break; + } + + std::cout << Iload << "\t"; + outfile << Iload << "\t"; + } + + double DACV = DACcounts * 3.25 / 255.0; + + std::cout << DACV * R2 / (R1 + R2) / RLoad << std::endl; + outfile << DACV * R2 / (R1 + R2) / RLoad << std::endl; + } } - - ps->turnOff(); - - outfile.close(); - return 0; + ps->turnOff(); + + outfile.close(); + + return 0; } diff --git a/pbv3/tools/pbv3_active_fancy_load.cpp b/pbv3/tools/pbv3_active_fancy_load.cpp index 5537feceac18d265808582d8a6161da884684d94..16d9c21f5439d9f344339400bf53f9e97c201e9b 100644 --- a/pbv3/tools/pbv3_active_fancy_load.cpp +++ b/pbv3/tools/pbv3_active_fancy_load.cpp @@ -1,25 +1,22 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> - -#include "Logger.h" +#include <thread> #include "AMACv2.h" #include "EndeavourComException.h" - +#include "Logger.h" +#include "PBv3ConfigTools.h" #include "PBv3TBConf.h" +#include "PBv3TBMassive.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" #include "PBv3Utils.h" -#include "PBv3TBMassive.h" //------ SETTINGS std::string configfile; @@ -28,37 +25,39 @@ std::string equipConfigFile = "config/equip_testbench.json"; //--------------- // Range is iout in A -json measureEfficiency(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupplyChannel> lv, std::shared_ptr<Bk85xx> load, double step, double min, double max, double VinSet=11.0) -{ - logger(logINFO) << "## Measuring DCDC efficiency ## " << PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); +json measureEfficiency(std::shared_ptr<AMACv2> amac, + std::shared_ptr<PowerSupplyChannel> lv, + std::shared_ptr<Bk85xx> load, double step, double min, + double max, double VinSet = 11.0) { + logger(logINFO) << "## Measuring DCDC efficiency ## " + << PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); json testSum; testSum["testType"] = "DCDCEFFICIENCY"; - testSum["results"]["TIMESTART"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMESTART"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); testSum["passed"] = true; // Store current state - uint32_t DCDCen_curr =amac->rdField(&AMACv2RegMap::DCDCen ); - uint32_t DCDCenC_curr=amac->rdField(&AMACv2RegMap::DCDCenC); - uint32_t Ch12Mux_curr=amac->rdField(&AMACv2RegMap::Ch12Mux); - uint32_t Ch13Mux_curr=amac->rdField(&AMACv2RegMap::Ch13Mux); + uint32_t DCDCen_curr = amac->rdField(&AMACv2RegMap::DCDCen); + uint32_t DCDCenC_curr = amac->rdField(&AMACv2RegMap::DCDCenC); + uint32_t Ch12Mux_curr = amac->rdField(&AMACv2RegMap::Ch12Mux); + uint32_t Ch13Mux_curr = amac->rdField(&AMACv2RegMap::Ch13Mux); // // Initialize // Set load to 0 - try - { - load->setCurrent(0); - load->turnOn(); - } - catch(const std::string &s) - { - logger(logERROR) << s; - testSum["error"] = s; - return testSum; - } - + try { + load->setCurrent(0); + load->turnOn(); + } catch (const std::string& s) { + logger(logERROR) << s; + testSum["error"] = s; + return testSum; + } + logger(logINFO) << " --> Vin = " << VinSet << "V"; lv->setVoltageLevel(VinSet); @@ -66,7 +65,7 @@ json measureEfficiency(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupply amac->wrField(&AMACv2::DCDCen, 0); amac->wrField(&AMACv2::DCDCenC, 0); std::this_thread::sleep_for(std::chrono::milliseconds(500)); - + double Iin_offset = lv->measureCurrent(); logger(logINFO) << " --> Get baseline current: (" << Iin_offset << ")A"; testSum["results"]["IINOFFSET"] = Iin_offset; @@ -75,73 +74,98 @@ json measureEfficiency(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupply amac->wrField(&AMACv2::DCDCen, 1); amac->wrField(&AMACv2::DCDCenC, 1); - //unsigned dwell_time = .1; //s - unsigned dwell_time_s = .005; //s - unsigned dwell_time = 5; //s - testSum["properties"]["DWELLTIMELONG" ] = dwell_time; + // unsigned dwell_time = .1; //s + unsigned dwell_time_s = .005; // s + unsigned dwell_time = 5; // s + testSum["properties"]["DWELLTIMELONG"] = dwell_time; testSum["properties"]["DWELLTIMESHORT"] = dwell_time_s; logger(logINFO) << " --> Starting measurement ..."; - std::cout << "Vin" << "\t" << "Iin" << "\t" << "Vout" << "\t" << "Iout" << "\t" << "IoutSense" << "\t" << "Vdcdc" - << "\t" << "VddLr" << "\t" << "DCDCin" << "\t" << "NTC" << "\t" - << "Cur10V" << "\t" << "Cur1V" << "\t" << "PTAT" << "\t" << "Efficiency" << "\t" << "EfficiencySense" << std::endl; + std::cout << "Vin" + << "\t" + << "Iin" + << "\t" + << "Vout" + << "\t" + << "Iout" + << "\t" + << "IoutSense" + << "\t" + << "Vdcdc" + << "\t" + << "VddLr" + << "\t" + << "DCDCin" + << "\t" + << "NTC" + << "\t" + << "Cur10V" + << "\t" + << "Cur1V" + << "\t" + << "PTAT" + << "\t" + << "Efficiency" + << "\t" + << "EfficiencySense" << std::endl; // Set sub-channel - amac->wrField(&AMACv2::Ch12Mux, 0); //a - amac->wrField(&AMACv2::Ch13Mux, 0); //a + amac->wrField(&AMACv2::Ch12Mux, 0); // a + amac->wrField(&AMACv2::Ch13Mux, 0); // a // Loop over currents int index = 0; - for (double iout=min;iout<=max;iout+=step) - { - //allowing system to reach thermal equilibrium - std::this_thread::sleep_for(std::chrono::seconds(dwell_time)); - logger(logDEBUG) << " --> Setting " << iout << "A load!"; - // Set Current - load->setCurrent(iout*1e3); - // Wait for temp and everything to settle - std::this_thread::sleep_for(std::chrono::seconds(dwell_time_s)); - // Read AMAC values - int Vdcdc, VddLr, DCDCin, NTC, Cur10V, Cur1V, PTAT; - - uint32_t trails=0; - for(uint32_t trail=0; trail<trails; trail++) - { - Vdcdc = amac->rdField(&AMACv2::Ch0Value); - VddLr = amac->rdField(&AMACv2::Ch1Value); - DCDCin = amac->rdField(&AMACv2::Ch2Value); - NTC = amac->rdField(&AMACv2::Ch9Value); - Cur10V = amac->rdField(&AMACv2::Ch12Value); - Cur1V = amac->rdField(&AMACv2::Ch13Value); - PTAT = amac->rdField(&AMACv2::Ch15Value); - - double Vin = lv->measureVoltage(); + for (double iout = min; iout <= max; iout += step) { + // allowing system to reach thermal equilibrium + std::this_thread::sleep_for(std::chrono::seconds(dwell_time)); + logger(logDEBUG) << " --> Setting " << iout << "A load!"; + // Set Current + load->setCurrent(iout * 1e3); + // Wait for temp and everything to settle + std::this_thread::sleep_for(std::chrono::seconds(dwell_time_s)); + // Read AMAC values + int Vdcdc, VddLr, DCDCin, NTC, Cur10V, Cur1V, PTAT; + + uint32_t trails = 0; + for (uint32_t trail = 0; trail < trails; trail++) { + Vdcdc = amac->rdField(&AMACv2::Ch0Value); + VddLr = amac->rdField(&AMACv2::Ch1Value); + DCDCin = amac->rdField(&AMACv2::Ch2Value); + NTC = amac->rdField(&AMACv2::Ch9Value); + Cur10V = amac->rdField(&AMACv2::Ch12Value); + Cur1V = amac->rdField(&AMACv2::Ch13Value); + PTAT = amac->rdField(&AMACv2::Ch15Value); + + double Vin = lv->measureVoltage(); double Iin = lv->measureCurrent(); - double IoutSense = load->getValues().cur*1e-3; - - double Vout = load->getValues().vol*1e-3; - - double efficiency = (Vout*iout)/(Vin*(Iin-Iin_offset)); - double efficiencySense = (Vout*IoutSense)/(Vin*(Iin-Iin_offset)); - std::cout << Vin << "\t" << Iin << "\t" << Vout << "\t" << iout << "\t" << IoutSense << "\t" << Vdcdc - << "\t" << VddLr << "\t" << DCDCin << "\t" << NTC << "\t" - << Cur10V << "\t" << Cur1V << "\t" << PTAT << "\t" << efficiency << "\t" << efficiencySense << std::endl; - testSum["results"]["VIN" ][index] = Vin; - testSum["results"]["IIN" ][index] = Iin; - testSum["results"]["VOUT" ][index] = Vout; - testSum["results"]["IOUT" ][index] = IoutSense; - testSum["results"]["AMACVDCDC" ][index] = Vdcdc; - testSum["results"]["AMACVDDLR" ][index] = VddLr; - testSum["results"]["AMACDCDCIN" ][index] = DCDCin; - testSum["results"]["AMACNTCPB" ][index] = NTC; - testSum["results"]["AMACCUR10V" ][index] = Cur10V; - testSum["results"]["AMACCUR1V" ][index] = Cur1V; - testSum["results"]["AMACPTAT" ][index] = PTAT; - testSum["results"]["EFFICIENCY" ][index] = efficiency; - testSum["results"]["EFFICIENCYSENSE"][index] = efficiencySense; - index++; - } - } + double IoutSense = load->getValues().cur * 1e-3; + + double Vout = load->getValues().vol * 1e-3; + + double efficiency = (Vout * iout) / (Vin * (Iin - Iin_offset)); + double efficiencySense = + (Vout * IoutSense) / (Vin * (Iin - Iin_offset)); + std::cout << Vin << "\t" << Iin << "\t" << Vout << "\t" << iout + << "\t" << IoutSense << "\t" << Vdcdc << "\t" << VddLr + << "\t" << DCDCin << "\t" << NTC << "\t" << Cur10V << "\t" + << Cur1V << "\t" << PTAT << "\t" << efficiency << "\t" + << efficiencySense << std::endl; + testSum["results"]["VIN"][index] = Vin; + testSum["results"]["IIN"][index] = Iin; + testSum["results"]["VOUT"][index] = Vout; + testSum["results"]["IOUT"][index] = IoutSense; + testSum["results"]["AMACVDCDC"][index] = Vdcdc; + testSum["results"]["AMACVDDLR"][index] = VddLr; + testSum["results"]["AMACDCDCIN"][index] = DCDCin; + testSum["results"]["AMACNTCPB"][index] = NTC; + testSum["results"]["AMACCUR10V"][index] = Cur10V; + testSum["results"]["AMACCUR1V"][index] = Cur1V; + testSum["results"]["AMACPTAT"][index] = PTAT; + testSum["results"]["EFFICIENCY"][index] = efficiency; + testSum["results"]["EFFICIENCYSENSE"][index] = efficiencySense; + index++; + } + } logger(logINFO) << " --> Done!! Turng off load!"; @@ -149,166 +173,163 @@ json measureEfficiency(std::shared_ptr<AMACv2> amac, std::shared_ptr<PowerSupply load->turnOff(); // Revert to old state - amac->wrField(&AMACv2RegMap::DCDCen , DCDCen_curr ); + amac->wrField(&AMACv2RegMap::DCDCen, DCDCen_curr); amac->wrField(&AMACv2RegMap::DCDCenC, DCDCenC_curr); amac->wrField(&AMACv2RegMap::Ch12Mux, Ch12Mux_curr); amac->wrField(&AMACv2RegMap::Ch13Mux, Ch13Mux_curr); - testSum["results"]["TIMEEND"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["results"]["TIMEEND"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); return testSum; - } - - -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] datadir BK85XX" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -c, --config Config for initializing the AMAC. (default: " << configfile << ")" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 3) - { - usage(argv); - return 1; - } +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] datadir BK85XX" + << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -c, --config Config for initializing the AMAC. " + "(default: " + << configfile << ")" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; +} - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"config" , required_argument, 0, 'c' }, - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "c:b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'c': - configfile = optarg; - break; - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } +int main(int argc, char* argv[]) { + if (argc < 3) { + usage(argv); + return 1; } - if (argc-optind < 2) - { - std::cerr << "Required paths missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"config", required_argument, 0, 'c'}, + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "c:b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'c': + configfile = optarg; + break; + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - std::string outDir = argv[optind++]; - std::string bkDev = argv[optind++]; - - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " outDir: " << outDir; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - logger(logDEBUG) << " bkDev: " << bkDev; - - // Output file - std::string fileName = outDir + "/" + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + "_pbv3-test.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; + if (argc - optind < 2) { + std::cerr << "Required paths missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - if(std::dynamic_pointer_cast<PBv3TBMassive>(tb)==nullptr) - { - logger(logERROR) << argv[0] << " only works with PBv3TBMassive!"; - return 1; + std::string outDir = argv[optind++]; + std::string bkDev = argv[optind++]; + + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " outDir: " << outDir; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << " bkDev: " << bkDev; + + // Output file + std::string fileName = + outDir + "/" + + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + + "_pbv3-test.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) << "Unable to create results file " << fileName; + return 2; } - // Turn on power - logger(logINFO) << "Turn on PS fully"; - tb->powerLVOn(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - // Init Load - logger(logINFO) << "Init BK DCDC Load"; - std::shared_ptr<Bk85xx> load=std::make_shared<Bk85xx>(bkDev); - load->setRemote(); - load->setRemoteSense(false); - load->setModeCC(); - load->setCurrent(0); - - // Init com - json config; - if(!configfile.empty()) - { - std::ifstream fh_in(configfile); - if(fh_in.is_open()) - fh_in >> config; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + if (std::dynamic_pointer_cast<PBv3TBMassive>(tb) == nullptr) { + logger(logERROR) << argv[0] << " only works with PBv3TBMassive!"; + return 1; } + // Turn on power + logger(logINFO) << "Turn on PS fully"; + tb->powerLVOn(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + // Init Load + logger(logINFO) << "Init BK DCDC Load"; + std::shared_ptr<Bk85xx> load = std::make_shared<Bk85xx>(bkDev); + load->setRemote(); + load->setRemoteSense(false); + load->setModeCC(); + load->setCurrent(0); + + // Init com + json config; + if (!configfile.empty()) { + std::ifstream fh_in(configfile); + if (fh_in.is_open()) fh_in >> config; + } - logger(logINFO) << "Init AMAC"; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - amac->init(); - PBv3ConfigTools::configAMAC(amac, config, false); - amac->initRegisters(); - PBv3ConfigTools::saveConfigAMAC(amac, config); + logger(logINFO) << "Init AMAC"; + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + amac->init(); + PBv3ConfigTools::configAMAC(amac, config, false); + amac->initRegisters(); + PBv3ConfigTools::saveConfigAMAC(amac, config); - // - // Start testing + // + // Start testing - std::shared_ptr<PowerSupplyChannel> lv=tb->getLVPS(); + std::shared_ptr<PowerSupplyChannel> lv = tb->getLVPS(); - json testSum; - testSum["program"] = argv[0]; - testSum["config"] = config; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + json testSum; + testSum["program"] = argv[0]; + testSum["config"] = config; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - uint32_t test=0; - testSum["tests"][test++] = measureEfficiency(amac, lv, load, 0.1, 0.0, 3.6); + uint32_t test = 0; + testSum["tests"][test++] = measureEfficiency(amac, lv, load, 0.1, 0.0, 3.6); - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; + outfile << std::setw(4) << testSum << std::endl; - outfile.close(); + outfile.close(); - logger(logINFO) << "Power off"; + logger(logINFO) << "Power off"; - tb->powerLVOff(); - load->turnOff(); + tb->powerLVOff(); + load->turnOff(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_active_init.cpp b/pbv3/tools/pbv3_active_init.cpp index 68cc8e3bb68f2bae4d9ec49a99da7de31f150a2d..ce8ae70804d90ce68a7c25a30c562c7404a24f31 100644 --- a/pbv3/tools/pbv3_active_init.cpp +++ b/pbv3/tools/pbv3_active_init.cpp @@ -1,84 +1,77 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> - -#include "Logger.h" +#include <thread> #include "AMACv2.h" - +#include "Logger.h" +#include "PBv3ConfigTools.h" #include "PBv3TBConf.h" #include "PBv3TBMassive.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" //------ SETTINGS std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; +int main(int argc, char* argv[]) { + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; - c = getopt_long(argc, argv, "e:d", long_options, &option_index); - if (c == -1) - break; + c = getopt_long(argc, argv, "e:d", long_options, &option_index); + if (c == -1) break; - switch (c) - { - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + switch (c) { + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - logger(logDEBUG) << "Settings"; + logger(logDEBUG) << "Settings"; - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TBMassive> tb=std::dynamic_pointer_cast<PBv3TBMassive>(factory_pbv3tb.getPBv3TB("default")); - if(tb==nullptr) - { - logger(logERROR) << "Error obtaining testbench object!"; - return 1; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TBMassive> tb = + std::dynamic_pointer_cast<PBv3TBMassive>( + factory_pbv3tb.getPBv3TB("default")); + if (tb == nullptr) { + logger(logERROR) << "Error obtaining testbench object!"; + return 1; } - for(uint32_t i=0;i<10;i++) - tb->setCarrierOutputEnable(i, false); + for (uint32_t i = 0; i < 10; i++) tb->setCarrierOutputEnable(i, false); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_basic_test.cpp b/pbv3/tools/pbv3_basic_test.cpp index 292d30efe7750cab46e992c21a8d211b4ebbb355..80ea06e843456c2fb7d3ff0cf6e3143696d10cea 100644 --- a/pbv3/tools/pbv3_basic_test.cpp +++ b/pbv3/tools/pbv3_basic_test.cpp @@ -1,24 +1,21 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> - -#include "Logger.h" +#include <thread> #include "AMACv2.h" #include "EndeavourComException.h" - +#include "Logger.h" +#include "PBv3ConfigTools.h" #include "PBv3TBConf.h" #include "PBv3TBSingle.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" #include "PBv3Utils.h" //------ SETTINGS @@ -28,171 +25,175 @@ std::string runNumber = "0-0"; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -c, --config Config for initializing the AMAC. (default: " << configfile << ")" << std::endl; - std::cerr << " -r, --runnumber Run number to associate with the test results. (default: " << runNumber << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr << " -c, --config Config for initializing the AMAC. " + "(default: " + << configfile << ")" << std::endl; + std::cerr << " -r, --runnumber Run number to associate with the " + "test results. (default: " + << runNumber << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"config" , required_argument, 0, 'c' }, - {"runnumber", required_argument, 0, 'r' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:c:r:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'c': - configfile = optarg; - break; - case 'r': - runNumber = optarg; - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"config", required_argument, 0, 'c'}, + {"runnumber", required_argument, 0, 'r'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:c:r:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'c': + configfile = optarg; + break; + case 'r': + runNumber = optarg; + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - if (argc-optind < 1) - { - std::cerr << "Required paths missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + if (argc - optind < 1) { + std::cerr << "Required paths missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - std::string outDir = argv[optind++]; - - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - logger(logDEBUG) << " outDir: " << outDir; + std::string outDir = argv[optind++]; - // - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << " outDir: " << outDir; + // + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - // Turn on power - logger(logINFO) << "Turn on PS fully"; - tb->powerLVOn(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + // Turn on power + logger(logINFO) << "Turn on PS fully"; + tb->powerLVOn(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); - // Init com - json config; - if(!configfile.empty()) - { - std::ifstream fh_in(configfile); - if(fh_in.is_open()) - fh_in >> config; + // Init com + json config; + if (!configfile.empty()) { + std::ifstream fh_in(configfile); + if (fh_in.is_open()) fh_in >> config; } + logger(logINFO) << "Init AMAC"; + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + try { + amac->init(); + PBv3ConfigTools::configAMAC(amac, config, false); + amac->initRegisters(); + PBv3ConfigTools::saveConfigAMAC(amac, config); + } catch (EndeavourComException& e) { + logger(logERROR) << "Unable to initialize AMACv2"; + logger(logERROR) << e.what(); + return 1; + } - logger(logINFO) << "Init AMAC"; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - try { - amac->init(); - PBv3ConfigTools::configAMAC(amac, config, false); - amac->initRegisters(); - PBv3ConfigTools::saveConfigAMAC(amac, config); - } catch(EndeavourComException &e) { - logger(logERROR) << "Unable to initialize AMACv2"; - logger(logERROR) << e.what(); - return 1; - } - - // - // Start testing - - std::shared_ptr<PowerSupplyChannel> lv =tb->getLVPS(); - std::shared_ptr<PowerSupplyChannel> hv =tb->getHVPS(); - - json testSum; - testSum["program"] = argv[0]; - testSum["runNumber"] = runNumber; - testSum["config"] = config; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - uint32_t test=0; - testSum["tests"][test++] = PBv3TestTools::runBER (amac); - if(std::dynamic_pointer_cast<PBv3TBSingle>(tb)) - testSum["tests"][test++] = PBv3TestTools::readStatus(amac, lv, std::dynamic_pointer_cast<PBv3TBSingle>(tb)->getLoadPtr(), hv); - else - testSum["tests"][test++] = PBv3TestTools::readStatus(amac, lv, nullptr, hv); - testSum["tests"][test++] = PBv3TestTools::testLvEnable (pbNum, tb); - testSum["tests"][test++] = PBv3TestTools::testDCDCAdj (pbNum, tb); - testSum["tests"][test++] = PBv3TestTools::testHvEnable (pbNum, tb); - testSum["tests"][test++] = PBv3TestTools::calibVinResponse (amac, lv); - testSum["tests"][test++] = PBv3TestTools::measureHvSense (pbNum, tb); - testSum["tests"][test++] = PBv3TestTools::measureEfficiency (pbNum, tb, 0.1, 0, 3.6); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACoffset(amac, false); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACslope (pbNum, tb, 0.01, false); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACCur10V(pbNum, tb, 10); - testSum["tests"][test++] = PBv3TestTools::calibrateAMACCur1V (pbNum, tb, 10); - testSum["tests"][test++] = PBv3TestTools::measureLvIV(lv); - - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - // Power off - logger(logINFO) << "Power off"; - - tb->powerHVOff(); - tb->powerLVOff(); - - // Output file - std::string fileName = outDir + "/" + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + "_pbv3-test.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; + // + // Start testing + + std::shared_ptr<PowerSupplyChannel> lv = tb->getLVPS(); + std::shared_ptr<PowerSupplyChannel> hv = tb->getHVPS(); + + json testSum; + testSum["program"] = argv[0]; + testSum["runNumber"] = runNumber; + testSum["config"] = config; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + uint32_t test = 0; + testSum["tests"][test++] = PBv3TestTools::runBER(amac); + if (std::dynamic_pointer_cast<PBv3TBSingle>(tb)) + testSum["tests"][test++] = PBv3TestTools::readStatus( + amac, lv, std::dynamic_pointer_cast<PBv3TBSingle>(tb)->getLoadPtr(), + hv); + else + testSum["tests"][test++] = + PBv3TestTools::readStatus(amac, lv, nullptr, hv); + testSum["tests"][test++] = PBv3TestTools::testLvEnable(pbNum, tb); + testSum["tests"][test++] = PBv3TestTools::testDCDCAdj(pbNum, tb); + testSum["tests"][test++] = PBv3TestTools::testHvEnable(pbNum, tb); + testSum["tests"][test++] = PBv3TestTools::calibVinResponse(amac, lv); + testSum["tests"][test++] = PBv3TestTools::measureHvSense(pbNum, tb); + testSum["tests"][test++] = + PBv3TestTools::measureEfficiency(pbNum, tb, 0.1, 0, 3.6); + testSum["tests"][test++] = PBv3TestTools::calibrateAMACoffset(amac, false); + testSum["tests"][test++] = + PBv3TestTools::calibrateAMACslope(pbNum, tb, 0.01, false); + testSum["tests"][test++] = + PBv3TestTools::calibrateAMACCur10V(pbNum, tb, 10); + testSum["tests"][test++] = PBv3TestTools::calibrateAMACCur1V(pbNum, tb, 10); + testSum["tests"][test++] = PBv3TestTools::measureLvIV(lv); + + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + // Power off + logger(logINFO) << "Power off"; + + tb->powerHVOff(); + tb->powerLVOff(); + + // Output file + std::string fileName = + outDir + "/" + + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + + "_pbv3-test.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) << "Unable to create results file " << fileName; + return 2; } - outfile << std::setw(4) << testSum << std::endl; + outfile << std::setw(4) << testSum << std::endl; - outfile.close(); + outfile.close(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_carrier_test.cpp b/pbv3/tools/pbv3_carrier_test.cpp index 856bceb43313af1e43287db5eb918fe109d0697f..ae382fd7cd9014608eb7ad5f92b86b5e266f7211 100644 --- a/pbv3/tools/pbv3_carrier_test.cpp +++ b/pbv3/tools/pbv3_carrier_test.cpp @@ -1,19 +1,17 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> +#include <thread> #include "Logger.h" - -#include "PBv3TBMassive.h" #include "PBv3CarrierTools.h" +#include "PBv3TBMassive.h" #include "PBv3Utils.h" using namespace nlohmann; @@ -22,102 +20,101 @@ using namespace nlohmann; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:c:r:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:c:r:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - if (argc-optind < 1) - { - std::cerr << "Required paths missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + if (argc - optind < 1) { + std::cerr << "Required paths missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - std::string outDir = argv[optind++]; - - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " outDir: " << outDir; - - // Output file - std::string fileName = outDir + "/" + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + "_pbv3-carrier.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; + std::string outDir = argv[optind++]; + + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " outDir: " << outDir; + + // Output file + std::string fileName = + outDir + "/" + + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + + "_pbv3-carrier.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) << "Unable to create results file " << fileName; + return 2; } - // - // Create and initialize the testbench - std::shared_ptr<PBv3TBMassive> tb=std::make_shared<PBv3TBMassive>(); - tb->init(); + // + // Create and initialize the testbench + std::shared_ptr<PBv3TBMassive> tb = std::make_shared<PBv3TBMassive>(); + tb->init(); - std::shared_ptr<EquipConf> equipConfig = std::make_shared<EquipConf>(equipConfigFile); - tb->setLVPS(equipConfig->getPowerSupplyChannel("Vin")); + std::shared_ptr<EquipConf> equipConfig = + std::make_shared<EquipConf>(equipConfigFile); + tb->setLVPS(equipConfig->getPowerSupplyChannel("Vin")); - // - // Start testing + // + // Start testing - json testSum; - testSum["program"] = argv[0]; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + json testSum; + testSum["program"] = argv[0]; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - uint32_t test=0; - testSum["tests"][test++] = PBv3CarrierTools::testLvEnable(tb); - testSum["tests"][test++] = PBv3CarrierTools::testMuxes(tb); + uint32_t test = 0; + testSum["tests"][test++] = PBv3CarrierTools::testLvEnable(tb); + testSum["tests"][test++] = PBv3CarrierTools::testMuxes(tb); - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; + outfile << std::setw(4) << testSum << std::endl; - outfile.close(); + outfile.close(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_config.cpp b/pbv3/tools/pbv3_config.cpp index cb927ed1c53474554cfcad1b594c08fef3e6c242..246dd9270cb7725dbf22669e9a9656e2b52af68c 100644 --- a/pbv3/tools/pbv3_config.cpp +++ b/pbv3/tools/pbv3_config.cpp @@ -1,21 +1,19 @@ -#include <unistd.h> -#include <string.h> +#include <Logger.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> #include <nlohmann/json.hpp> - -#include <Logger.h> +#include <thread> #include "AMACv2.h" #include "EndeavourComException.h" - -#include "PBv3TBConf.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" //------ SETTINGS uint8_t pbNum = 0; @@ -23,103 +21,96 @@ std::string configfile = "config.json"; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] config.json" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] config.json" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 1) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 1) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - if(optind==argc) - { - std::cerr << "Required config file argument missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + if (optind == argc) { + std::cerr << "Required config file argument missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - configfile=argv[optind++]; - - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - - // - // Open configuration - json config; - std::ifstream fh_in(configfile); - if(fh_in.is_open()) - fh_in >> config; - else - { - logger(logERROR) << "Unable to open config file: " << configfile; - return 1; + configfile = argv[optind++]; + + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + + // + // Open configuration + json config; + std::ifstream fh_in(configfile); + if (fh_in.is_open()) + fh_in >> config; + else { + logger(logERROR) << "Unable to open config file: " << configfile; + return 1; + } + PBv3ConfigTools::decorateConfig(config); + + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + amac->init(); + + // Write the configuration + try { + PBv3ConfigTools::configAMAC(amac, config, false); + amac->initRegisters(); + } catch (EndeavourComException& e) { + logger(logERROR) << "Unable to initialize AMACv2"; + logger(logERROR) << e.what(); + return 1; } - PBv3ConfigTools::decorateConfig(config); - - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - amac->init(); - - // Write the configuration - try { - PBv3ConfigTools::configAMAC(amac, config, false); - amac->initRegisters(); - } catch(EndeavourComException &e) { - logger(logERROR) << "Unable to initialize AMACv2"; - logger(logERROR) << e.what(); - return 1; - } - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_field.cpp b/pbv3/tools/pbv3_field.cpp index 11a23ea73996b3672ea1c3375d58d0279ffbc03b..59f783106ef99c98a636882a2b7bf4795f19c064 100644 --- a/pbv3/tools/pbv3_field.cpp +++ b/pbv3/tools/pbv3_field.cpp @@ -1,15 +1,13 @@ -#include <unistd.h> -#include <string.h> +#include <Logger.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <cmath> #include <iomanip> #include <iostream> -#include <Logger.h> - #include "AMACv2.h" - #include "PBv3TBConf.h" //------ SETTINGS @@ -17,143 +15,129 @@ uint8_t pbNum = 0; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] command [command parameters]" << std::endl; - std::cerr << std::endl; - std::cerr << "commands" << std::endl; - std::cerr << " list: list available fields" << std::endl; - std::cerr << " read field: read current value of field" << std::endl; - std::cerr << " write field value: write new value to field" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] + << " [options] command [command parameters]" << std::endl; + std::cerr << std::endl; + std::cerr << "commands" << std::endl; + std::cerr << " list: list available fields" << std::endl; + std::cerr << " read field: read current value of field" << std::endl; + std::cerr << " write field value: write new value to field" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - // Determine the command - if(argc<=optind) - { - usage(argv); - return 1; + // Determine the command + if (argc <= optind) { + usage(argv); + return 1; } - std::string command=argv[optind++]; - std::vector<std::string> params; - while (optind < argc) - { - std::string p(argv[optind++]); - params.push_back(p); + std::string command = argv[optind++]; + std::vector<std::string> params; + while (optind < argc) { + std::string p(argv[optind++]); + params.push_back(p); } - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - amac->init(); - - //Now interpret command - logger(logDEBUG) << "Sending commend to power-supply."; - if (command == "list") - { - for(const AMACv2Field* field : amac->getFields()) - std::cout << field->getName() << std::endl; - } - else if (command == "read") - { - if (params.size() != 1) - { - logger(logERROR) << "Invalid number of parameters to read command."; - logger(logERROR) << ""; - usage(argv); - return 1; - } - AMACv2Field *field=amac->findField(params[0]); - if(field==nullptr) - { - logger(logERROR) << "Invalid field name."; - return 1; - } - - uint32_t value=amac->rdField(params[0]); - - std::cout << "0x" << std::hex << std::setw(std::ceil(field->getWidth()/4.)) << std::setfill('0') << value << std::dec << std::endl; - } - else if (command == "write") - { - if (params.size() != 2) - { - logger(logERROR) << "Invalid number of parameters to write command."; - logger(logERROR) << ""; - usage(argv); - return 1; - } - AMACv2Field *field=amac->findField(params[0]); - if(field==nullptr) - { - logger(logERROR) << "Invalid field name."; - return 1; - } - - uint32_t value=std::stoul(params[1], nullptr, 0); - - amac->wrField(params[0],value); - } - else - { - usage(argv); + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + amac->init(); + + // Now interpret command + logger(logDEBUG) << "Sending commend to power-supply."; + if (command == "list") { + for (const AMACv2Field* field : amac->getFields()) + std::cout << field->getName() << std::endl; + } else if (command == "read") { + if (params.size() != 1) { + logger(logERROR) << "Invalid number of parameters to read command."; + logger(logERROR) << ""; + usage(argv); + return 1; + } + AMACv2Field* field = amac->findField(params[0]); + if (field == nullptr) { + logger(logERROR) << "Invalid field name."; + return 1; + } + + uint32_t value = amac->rdField(params[0]); + + std::cout << "0x" << std::hex + << std::setw(std::ceil(field->getWidth() / 4.)) + << std::setfill('0') << value << std::dec << std::endl; + } else if (command == "write") { + if (params.size() != 2) { + logger(logERROR) + << "Invalid number of parameters to write command."; + logger(logERROR) << ""; + usage(argv); + return 1; + } + AMACv2Field* field = amac->findField(params[0]); + if (field == nullptr) { + logger(logERROR) << "Invalid field name."; + return 1; + } + + uint32_t value = std::stoul(params[1], nullptr, 0); + + amac->wrField(params[0], value); + } else { + usage(argv); } - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_long_test.cpp b/pbv3/tools/pbv3_long_test.cpp index 37a1315d512b4be91315d9131db885696d8fd92c..b46feeb99fa2eae2ff29169d088e19530780efb2 100644 --- a/pbv3/tools/pbv3_long_test.cpp +++ b/pbv3/tools/pbv3_long_test.cpp @@ -1,24 +1,21 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> - -#include "Logger.h" +#include <thread> #include "AMACv2.h" #include "EndeavourComException.h" - +#include "Logger.h" +#include "PBv3ConfigTools.h" #include "PBv3TBConf.h" #include "PBv3TBSingle.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" #include "PBv3Utils.h" //------ SETTINGS @@ -29,286 +26,342 @@ std::string equipConfigFile = "config/equip_testbench.json"; #define PERIOD_LONG 600 #define PERIOD_MONITOR 1 -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -c, --config Config for initializing the AMAC. (default: " << configfile << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char *argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr << " -c, --config Config for initializing the AMAC. " + "(default: " + << configfile << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char *argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"config" , required_argument, 0, 'c' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:c:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'c': - configfile = optarg; - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"config", required_argument, 0, 'c'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:c:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'c': + configfile = optarg; + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - if (argc-optind < 1) - { - std::cout << argc << " " << optind << " " << 1 << std::endl; - std::cerr << "Required paths missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + if (argc - optind < 1) { + std::cout << argc << " " << optind << " " << 1 << std::endl; + std::cerr << "Required paths missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - std::string outDir = argv[optind++]; - - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - logger(logDEBUG) << " outDir: " << outDir; - - // Output file - std::string fileName = outDir + "/" + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + "_pbv3-test.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; + std::string outDir = argv[optind++]; + + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << " outDir: " << outDir; + + // Output file + std::string fileName = + outDir + "/" + + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + + "_pbv3-test.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) << "Unable to create results file " << fileName; + return 2; } - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - // Turn on power - logger(logINFO) << "Turn on PS fully"; - tb->powerLVOn(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - // Init com - json config; - if(!configfile.empty()) - { - std::ifstream fh_in(configfile); - if(fh_in.is_open()) - fh_in >> config; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + // Turn on power + logger(logINFO) << "Turn on PS fully"; + tb->powerLVOn(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + // Init com + json config; + if (!configfile.empty()) { + std::ifstream fh_in(configfile); + if (fh_in.is_open()) fh_in >> config; } - - logger(logINFO) << "Init AMAC"; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - amac->init(); - PBv3ConfigTools::configAMAC(amac, config, false); - amac->initRegisters(); - PBv3ConfigTools::saveConfigAMAC(amac, config); - - std::shared_ptr<PowerSupplyChannel> lv =tb->getLVPS(); - std::shared_ptr<PowerSupplyChannel> hv =tb->getHVPS(); - - // - // Start running tests in a loop forever! - // - //time in minutes when the monitor is written to json files - double time_write_mon =1.0; - - while(true) - { - // - // Run the long tests - - //Run all calibrations - json calib_all;// = PBv3ConfigTools::calibrateAll(amac); - // Prepare the output structure - json testSum; - testSum["program"] = argv[0]; - testSum["config"] = config; - testSum["calib_all"] = calib_all; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - // Start testing - //Run efficiency once to get baseline current (ie powercycle) - - uint32_t test=0; - - try { testSum["tests"][test++] = PBv3TestTools::runBER(amac); } - catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e; testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); break;} - - - try { testSum["tests"][test++] = PBv3TestTools::testLvEnable(0, tb); } - catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e; testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); break;} - - try { testSum["tests"][test++] = PBv3TestTools::testHvEnable(0, tb); } - catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e; testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); break;} - - try { testSum["tests"][test++] = PBv3TestTools::measureHvSense(0, tb); } - catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e;testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); break;} - - try { testSum["tests"][test++] = PBv3TestTools::measureEfficiency(0, tb, 100, 0, 3500); } - catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e; testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); break;} - - try { testSum["tests"][test++] = PBv3TestTools::calibrateAMACslope (0, tb, 0.01, false);} - catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e; testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); break;} - - try { testSum["tests"][test++] = PBv3TestTools::calibrateAMACoffset(amac, false); } - catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e;testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); break;} - // try{ testSum["tests"][test++] = PBv3TestTools::calibrateAMACcm (amac, 10000);} - // catch(const EndeavourComException &e) { logger(logERROR) << e.what(); } - // catch(std::string e) {logger(logERROR) << e; testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - // outfile << std::setw(4) << testSum << std::endl; - // outfile.close(); break;} - - - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); - - //Check if 30min has elapsed - auto t_out = std::chrono::system_clock::now(); - auto t_in = std::chrono::system_clock::now(); - auto t_in2 = std::chrono::system_clock::now(); - std::chrono::duration<double> elapse = t_in-t_out; - std::chrono::duration<double> elapse2 = t_in2-t_in; - - int iter = 0; - // - // Monitor things for a while (30 min explicitly here) - - // Enable load - tb->setLoad(pbNum,2); - tb->loadOn(pbNum); - - amac->wrField(&AMACv2::DCDCen, 1); - amac->wrField(&AMACv2::DCDCenC, 1); - - // Enable HV - tb->powerHVOn(); - - amac->wrField(&AMACv2::CntSetHV0en, 1); - amac->wrField(&AMACv2::CntSetCHV0en, 1); - - //for(uint32_t iMon=0;iMon<PERIOD_LONG/PERIOD_MONITOR;iMon++) - while(elapse.count()/60. < 30.) - { - std::string fileName = outDir + "/" + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + "_pbv3-monitor.json"; - std::fstream outfile(fileName, std::ios::out); - - // Prepare the output structure - json testSum; - testSum["calibrate"]; // = PBv3ConfigTools::calibrateAll(amac); - testSum["program"] = argv[0]; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - // Start testing ( 1 min, then the file is written) - while(elapse2.count()/60. < time_write_mon) - { - try - { - if(std::dynamic_pointer_cast<PBv3TBSingle>(tb)) - testSum["tests"][iter] = PBv3TestTools::readStatus(amac, lv, std::dynamic_pointer_cast<PBv3TBSingle>(tb)->getLoadPtr(), hv); - else - testSum["tests"][iter] = PBv3TestTools::readStatus(amac, lv, nullptr, hv); - } - catch(const EndeavourComException &e) - { logger(logERROR) << e.what(); } - catch(std::string e) {logger(logERROR) << e; - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); - break;} - - t_in2 = std::chrono::system_clock::now(); - elapse2 = t_in2-t_in; - - iter++; - } - std::cout<<elapse2.count()/60.<<std::endl; - - iter = 0; - - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); - //updating elapsed time - t_in = std::chrono::system_clock::now(); - t_in2 = std::chrono::system_clock::now(); - elapse = t_in-t_out; - elapse2 = t_in2-t_in; - } - - amac->wrField(&AMACv2::DCDCen, 0); - amac->wrField(&AMACv2::DCDCenC, 0); - tb->loadOff(pbNum); - - amac->wrField(&AMACv2::CntSetHV0en, 0); - amac->wrField(&AMACv2::CntSetCHV0en, 0); - tb->powerHVOff(); - + logger(logINFO) << "Init AMAC"; + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + amac->init(); + PBv3ConfigTools::configAMAC(amac, config, false); + amac->initRegisters(); + PBv3ConfigTools::saveConfigAMAC(amac, config); + + std::shared_ptr<PowerSupplyChannel> lv = tb->getLVPS(); + std::shared_ptr<PowerSupplyChannel> hv = tb->getHVPS(); + + // + // Start running tests in a loop forever! + // + // time in minutes when the monitor is written to json files + double time_write_mon = 1.0; + + while (true) { + // + // Run the long tests + + // Run all calibrations + json calib_all; // = PBv3ConfigTools::calibrateAll(amac); + // Prepare the output structure + json testSum; + testSum["program"] = argv[0]; + testSum["config"] = config; + testSum["calib_all"] = calib_all; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + // Start testing + // Run efficiency once to get baseline current (ie powercycle) + + uint32_t test = 0; + + try { + testSum["tests"][test++] = PBv3TestTools::runBER(amac); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + + try { + testSum["tests"][test++] = PBv3TestTools::testLvEnable(0, tb); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + + try { + testSum["tests"][test++] = PBv3TestTools::testHvEnable(0, tb); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + + try { + testSum["tests"][test++] = PBv3TestTools::measureHvSense(0, tb); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + + try { + testSum["tests"][test++] = + PBv3TestTools::measureEfficiency(0, tb, 100, 0, 3500); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + + try { + testSum["tests"][test++] = + PBv3TestTools::calibrateAMACslope(0, tb, 0.01, false); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + + try { + testSum["tests"][test++] = + PBv3TestTools::calibrateAMACoffset(amac, false); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + // try{ testSum["tests"][test++] = PBv3TestTools::calibrateAMACcm + // (amac, 10000);} catch(const EndeavourComException &e) { + // logger(logERROR) << e.what(); } catch(std::string e) + // {logger(logERROR) << e; testSum["time"]["end"] = + // PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + // outfile << std::setw(4) << testSum << std::endl; + // outfile.close(); break;} + + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + + // Check if 30min has elapsed + auto t_out = std::chrono::system_clock::now(); + auto t_in = std::chrono::system_clock::now(); + auto t_in2 = std::chrono::system_clock::now(); + std::chrono::duration<double> elapse = t_in - t_out; + std::chrono::duration<double> elapse2 = t_in2 - t_in; + + int iter = 0; + // + // Monitor things for a while (30 min explicitly here) + + // Enable load + tb->setLoad(pbNum, 2); + tb->loadOn(pbNum); + + amac->wrField(&AMACv2::DCDCen, 1); + amac->wrField(&AMACv2::DCDCenC, 1); + + // Enable HV + tb->powerHVOn(); + + amac->wrField(&AMACv2::CntSetHV0en, 1); + amac->wrField(&AMACv2::CntSetCHV0en, 1); + + // for(uint32_t iMon=0;iMon<PERIOD_LONG/PERIOD_MONITOR;iMon++) + while (elapse.count() / 60. < 30.) { + std::string fileName = + outDir + "/" + + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + + "_pbv3-monitor.json"; + std::fstream outfile(fileName, std::ios::out); + + // Prepare the output structure + json testSum; + testSum["calibrate"]; // = PBv3ConfigTools::calibrateAll(amac); + testSum["program"] = argv[0]; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + // Start testing ( 1 min, then the file is written) + while (elapse2.count() / 60. < time_write_mon) { + try { + if (std::dynamic_pointer_cast<PBv3TBSingle>(tb)) + testSum["tests"][iter] = PBv3TestTools::readStatus( + amac, lv, + std::dynamic_pointer_cast<PBv3TBSingle>(tb) + ->getLoadPtr(), + hv); + else + testSum["tests"][iter] = + PBv3TestTools::readStatus(amac, lv, nullptr, hv); + } catch (const EndeavourComException &e) { + logger(logERROR) << e.what(); + } catch (std::string e) { + logger(logERROR) << e; + testSum["time"]["end"] = PBv3Utils::getTimeAsString( + std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + break; + } + + t_in2 = std::chrono::system_clock::now(); + elapse2 = t_in2 - t_in; + + iter++; + } + std::cout << elapse2.count() / 60. << std::endl; + + iter = 0; + + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + // updating elapsed time + t_in = std::chrono::system_clock::now(); + t_in2 = std::chrono::system_clock::now(); + elapse = t_in - t_out; + elapse2 = t_in2 - t_in; + } + + amac->wrField(&AMACv2::DCDCen, 0); + amac->wrField(&AMACv2::DCDCenC, 0); + tb->loadOff(pbNum); + + amac->wrField(&AMACv2::CntSetHV0en, 0); + amac->wrField(&AMACv2::CntSetCHV0en, 0); + tb->powerHVOff(); } - // - // Power off - tb->powerLVOff(); - tb->powerHVOff(); + // + // Power off + tb->powerLVOff(); + tb->powerHVOff(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_mass_test.cpp b/pbv3/tools/pbv3_mass_test.cpp index 0584d4581e4e5d1caed6dacc861537792569ee2c..04de907cbc6bdddb8bba9b951cf90b2225793c88 100644 --- a/pbv3/tools/pbv3_mass_test.cpp +++ b/pbv3/tools/pbv3_mass_test.cpp @@ -1,26 +1,23 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> +#include <nlohmann/json.hpp> #include <sstream> #include <thread> -#include <nlohmann/json.hpp> - -#include "Logger.h" - #include "AMACv2.h" #include "EndeavourComException.h" - +#include "Logger.h" +#include "PBv3ConfigTools.h" +#include "PBv3QCFlow.h" #include "PBv3TBConf.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" #include "PBv3Utils.h" -#include "PBv3QCFlow.h" //------ SETTINGS std::string runNumber = "0-0"; @@ -30,320 +27,318 @@ std::string batch = "0"; std::vector<uint32_t> pbNum = {0}; std::vector<std::string> serial = {}; #else -std::vector<uint32_t> pbNum = {0,1,2,3,4,5,6,7,8,9}; +std::vector<uint32_t> pbNum = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; std::vector<std::string> serial = {}; -#endif //FTDI +#endif // FTDI std::string equipConfigFile = "config/equip_testbench.json"; bool skipHV = false; bool advanced = false; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] panelNum" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -r, --runnumber Run number to associate with the test results. (default: " << runNumber << ")" << std::endl; - std::cerr << " -b, --board Powerboard numbers to test, separated by commas. (default: 0 if single testbench, all 0,..,9 if mass testbench)" << std::endl; - std::cerr << " -v, --version Powerboard version (default: " << version << ")" << std::endl; - std::cerr << " -a, --batch Powerboard batch (default: " << batch << ")" << std::endl; - std::cerr << " -s, --serial Powerboard serial numbers, separated by commas. (default: same as -b)" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -f, --advanced Run all elecrical characterization tests" << std::endl; - std::cerr << " --skiphv Skip running HV tests" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] panelNum" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -r, --runnumber Run number to associate with the " + "test results. (default: " + << runNumber << ")" << std::endl; + std::cerr << " -b, --board Powerboard numbers to test, " + "separated by commas. (default: 0 if single testbench, all " + "0,..,9 if mass testbench)" + << std::endl; + std::cerr << " -v, --version Powerboard version (default: " + << version << ")" << std::endl; + std::cerr << " -a, --batch Powerboard batch (default: " << batch + << ")" << std::endl; + std::cerr << " -s, --serial Powerboard serial numbers, " + "separated by commas. (default: same as -b)" + << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr + << " -f, --advanced Run all elecrical characterization tests" + << std::endl; + std::cerr << " --skiphv Skip running HV tests" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - // - // Parse input options to configure test - // - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + // + // Parse input options to configure test + // + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"runnumber", required_argument, 0, 'r' }, - {"board" , required_argument, 0, 'b' }, - {"version" , required_argument, 0, 'v' }, - {"batch" , required_argument, 0, 'a' }, - {"serial" , required_argument, 0, 's' }, - {"equip" , required_argument, 0, 'e' }, - {"advanced" , no_argument , 0, 'f' }, - {"skiphv " , no_argument , 0, 1 }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "c:r:b:v:a:s:e:fmd", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 1: - skipHV = true; - break; - case 'r': - runNumber = optarg; - break; - case 'b': - { - pbNum.clear(); - std::stringstream pb_stream(optarg); - std::string pb_substr; - while(getline(pb_stream, pb_substr, ',')) - { pbNum.push_back(stoi(pb_substr)); } - } - break; - case 'v': - version = optarg; - break; - case 'a': - batch = optarg; - break; - case 's': - { - serial.clear(); - std::stringstream s_stream(optarg); - std::string s_substr; - while(getline(s_stream, s_substr, ',')) - { serial.push_back(s_substr); } - } - break; - case 'e': - equipConfigFile = optarg; - break; - case 'f': - advanced = true; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; - break; - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"runnumber", required_argument, 0, 'r'}, + {"board", required_argument, 0, 'b'}, + {"version", required_argument, 0, 'v'}, + {"batch", required_argument, 0, 'a'}, + {"serial", required_argument, 0, 's'}, + {"equip", required_argument, 0, 'e'}, + {"advanced", no_argument, 0, 'f'}, + {"skiphv ", no_argument, 0, 1}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "c:r:b:v:a:s:e:fmd", long_options, + &option_index); + if (c == -1) break; + + switch (c) { + case 1: + skipHV = true; + break; + case 'r': + runNumber = optarg; + break; + case 'b': { + pbNum.clear(); + std::stringstream pb_stream(optarg); + std::string pb_substr; + while (getline(pb_stream, pb_substr, ',')) { + pbNum.push_back(stoi(pb_substr)); + } + } break; + case 'v': + version = optarg; + break; + case 'a': + batch = optarg; + break; + case 's': { + serial.clear(); + std::stringstream s_stream(optarg); + std::string s_substr; + while (getline(s_stream, s_substr, ',')) { + serial.push_back(s_substr); + } + } break; + case 'e': + equipConfigFile = optarg; + break; + case 'f': + advanced = true; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; + break; + } } - if (argc-optind < 1) - { - std::cerr << "Required paths missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + if (argc - optind < 1) { + std::cerr << "Required paths missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - // - // Serial number formatting - bool serialGiven=!serial.empty(); - if(serialGiven) // transorm to full serial number + // + // Serial number formatting + bool serialGiven = !serial.empty(); + if (serialGiven) // transorm to full serial number { - std::transform(serial.begin(), serial.end(), serial.begin(), [](const std::string& num)->std::string - { - std::stringstream ss; - ss << "20USBP0" << version; - ss << std::setw(2) << std::setfill('0') << batch; - ss << std::setw(4) << std::setfill('0') << num; - return ss.str(); - }); - } - else // user powerboard numbers + std::transform(serial.begin(), serial.end(), serial.begin(), + [](const std::string& num) -> std::string { + std::stringstream ss; + ss << "20USBP0" << version; + ss << std::setw(2) << std::setfill('0') << batch; + ss << std::setw(4) << std::setfill('0') << num; + return ss.str(); + }); + } else // user powerboard numbers { - std::transform(pbNum.begin(), pbNum.end(), std::back_inserter(serial), [](uint32_t num)->std::string - { return std::to_string(num); }); + std::transform( + pbNum.begin(), pbNum.end(), std::back_inserter(serial), + [](uint32_t num) -> std::string { return std::to_string(num); }); } - if(pbNum.size()!=serial.size()) - { - std::cerr << "Number of serial numbers must match number of boards specified by optional argument -b." << std::endl; - usage(argv); - return 1; + if (pbNum.size() != serial.size()) { + std::cerr << "Number of serial numbers must match number of boards " + "specified by optional argument -b." + << std::endl; + usage(argv); + return 1; } + std::string panelDir = "panel" + std::string(argv[optind++]); + + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " Hardware configuration: " << equipConfigFile; + logger(logDEBUG) << " Panel directory: " << panelDir; + if (logIt::loglevel >= logDEBUG) { + logger(logDEBUG) << " (PB number, serial number): "; + for (int i = 0; i < pbNum.size(); i++) { + std::cout << "(" << pbNum[i] << ", " << serial[i] << ")" + << std::endl; + } + } - std::string panelDir = "panel" + std::string(argv[optind++]); + // + // Create output directories + // + + std::string startTime = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + // Create panel subfolder + PBv3Utils::createDirectory(panelDir); + + // Create date subfolder under panel subfolder + PBv3Utils::createDirectory(panelDir + "/" + startTime); + + // Create powerboard subfolders + for (uint8_t i = 0; i < serial.size(); i++) + PBv3Utils::createDirectory(panelDir + "/" + startTime + "/pb" + + serial[i]); + + // + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + bool doHV = (tb->getHVPS() != nullptr and !skipHV); + + // Make sure to start in off state + logger(logINFO) << "Turn off PS"; + if (doHV) tb->powerHVOff(); + tb->powerLVOff(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + // Turn on power + logger(logINFO) << "Turn on LV fully"; + tb->powerLVOn(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + float poweroncurrent = tb->getVinCurrent(); + logger(logINFO) << "LV current: " << poweroncurrent << "A"; + if (poweroncurrent > 0.7) { + tb->powerLVOff(); + logger(logERROR) << "Power-up current too high. Stopping test.."; + return 1; + } - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " Hardware configuration: " << equipConfigFile; - logger(logDEBUG) << " Panel directory: " << panelDir; - if(logIt::loglevel>=logDEBUG) - { - logger(logDEBUG) << " (PB number, serial number): "; - for(int i = 0; i<pbNum.size(); i++) - { - std::cout << "(" << pbNum[i] << ", " << serial[i] << ")" << std::endl; - } + // Create test tracking structure + std::vector<PBv3QCFlow> pbs; + for (uint32_t i = 0; i < pbNum.size(); i++) { + PBv3QCFlow pb(pbNum[i], doHV); + pb.setSerial(serial[i]); + pbs.push_back(pb); } - // - // Create output directories - // - - std::string startTime = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - //Create panel subfolder - PBv3Utils::createDirectory(panelDir); - - //Create date subfolder under panel subfolder - PBv3Utils::createDirectory(panelDir + "/" + startTime); - - // Create powerboard subfolders - for(uint8_t i = 0; i<serial.size(); i++) - PBv3Utils::createDirectory(panelDir + "/" + startTime + "/pb" + serial[i]); - - - // - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - bool doHV=(tb->getHVPS()!=nullptr and !skipHV); - - // Make sure to start in off state - logger(logINFO) << "Turn off PS"; - if(doHV) tb->powerHVOff(); - tb->powerLVOff(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - // Turn on power - logger(logINFO) << "Turn on LV fully"; - tb->powerLVOn(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - float poweroncurrent = tb->getVinCurrent(); - logger(logINFO) << "LV current: " << poweroncurrent << "A"; - if(poweroncurrent>0.7) + // + // Perform diagnostic tests on mass test panel and powerboards. + std::string pbDir; + + // + // Basic functionality tests + // + + // Is Alive version { - tb->powerLVOff(); - logger(logERROR) << "Power-up current too high. Stopping test.."; - return 1; + for (PBv3QCFlow& pb : pbs) { + // Output file + pbDir = panelDir + "/" + startTime + "/pb" + pb.serial(); + std::string fileName = pbDir + "/" + startTime + "_pbv3-alive.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) + << "Unable to create results file " << fileName; + return 2; + } + + json diagSum; + + diagSum["program"] = argv[0]; + diagSum["runNumber"] = runNumber; + + diagSum.merge_patch(pb.runAliveTests(tb)); + + outfile << std::setw(4) << diagSum << std::endl; + outfile.close(); + } } - // Create test tracking structure - std::vector<PBv3QCFlow> pbs; - for(uint32_t i = 0; i<pbNum.size(); i++) + // Functionality checks { - PBv3QCFlow pb(pbNum[i], doHV); - pb.setSerial(serial[i]); - pbs.push_back(pb); + for (PBv3QCFlow& pb : pbs) { + // Output file + pbDir = panelDir + "/" + startTime + "/pb" + pb.serial(); + std::string fileName = + pbDir + "/" + startTime + "_pbv3-functionality.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) + << "Unable to create results file " << fileName; + return 2; + } + + // Output structure + json diagSum; + + diagSum["program"] = argv[0]; + diagSum["runNumber"] = runNumber; + + diagSum.merge_patch(pb.runBasicTests(tb)); + + outfile << std::setw(4) << diagSum << std::endl; + outfile.close(); + } } - // - //Perform diagnostic tests on mass test panel and powerboards. - std::string pbDir; - - // - // Basic functionality tests - // - - // Is Alive version - { - for(PBv3QCFlow& pb : pbs) - { - // Output file - pbDir = panelDir + "/" + startTime + "/pb" + pb.serial(); - std::string fileName = pbDir + "/" + startTime + "_pbv3-alive.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; - } - - json diagSum; - - diagSum["program"] = argv[0]; - diagSum["runNumber"] = runNumber; - - diagSum.merge_patch(pb.runAliveTests(tb)); - - outfile << std::setw(4) << diagSum << std::endl; - outfile.close(); - } - } - - // Functionality checks - { - for(PBv3QCFlow& pb : pbs) - { - // Output file - pbDir = panelDir + "/" + startTime + "/pb" + pb.serial(); - std::string fileName = pbDir + "/" + startTime + "_pbv3-functionality.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; - } - - // Output structure - json diagSum; - - diagSum["program"] = argv[0]; - diagSum["runNumber"] = runNumber; - - diagSum.merge_patch(pb.runBasicTests(tb)); - - outfile << std::setw(4) << diagSum << std::endl; - outfile.close(); - } - } - - // - // Run advanced characterization tests - // - if(advanced) - { - for(PBv3QCFlow& pb : pbs) - { - // Output file - pbDir = panelDir + "/" + startTime + "/pb" + pb.serial(); - std::string fileName = pbDir + "/" + startTime + "_pbv3-advanced.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; - } - - // Output structure - json testSum; - testSum["program"] = argv[0]; - testSum["runNumber"] = runNumber; - - // testing - testSum.merge_patch(pb.runAdvancedTests(tb)); - - // save - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); - } + // + // Run advanced characterization tests + // + if (advanced) { + for (PBv3QCFlow& pb : pbs) { + // Output file + pbDir = panelDir + "/" + startTime + "/pb" + pb.serial(); + std::string fileName = + pbDir + "/" + startTime + "_pbv3-advanced.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) + << "Unable to create results file " << fileName; + return 2; + } + + // Output structure + json testSum; + testSum["program"] = argv[0]; + testSum["runNumber"] = runNumber; + + // testing + testSum.merge_patch(pb.runAdvancedTests(tb)); + + // save + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + } } - logger(logINFO) << "Power off"; + logger(logINFO) << "Power off"; - tb->powerLVOff(); - tb->loadOff (0); - if(doHV) - tb->powerHVOff(); + tb->powerLVOff(); + tb->loadOff(0); + if (doHV) tb->powerHVOff(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_module_test.cpp b/pbv3/tools/pbv3_module_test.cpp index bb2890fbac0b7e188c4b9a2a1dc0f9c9a184e239..94e67fdee61b2c429589245986c4bfd7a9a30553 100644 --- a/pbv3/tools/pbv3_module_test.cpp +++ b/pbv3/tools/pbv3_module_test.cpp @@ -1,26 +1,23 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> +#include <thread> -#include "Logger.h" - +#include "AMACv2.h" #include "EndeavourCom.h" #include "EndeavourComException.h" -#include "UIOCom.h" -#include "AMACv2.h" - +#include "Logger.h" +#include "PBv3ConfigTools.h" #include "PBv3TBConf.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" #include "PBv3Utils.h" +#include "UIOCom.h" //------ SETTINGS uint8_t pbNum = 0; @@ -29,132 +26,128 @@ std::string runNumber = "0-0"; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -c, --config Config for calibrating the AMAC. Register settings are ignored. (default: " << configfile << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr << " -c, --config Config for calibrating the AMAC. " + "Register settings are ignored. (default: " + << configfile << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"config" , required_argument, 0, 'c' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:c:r:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'c': - configfile = optarg; - break; - case 'r': - runNumber = optarg; - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"config", required_argument, 0, 'c'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:c:r:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'c': + configfile = optarg; + break; + case 'r': + runNumber = optarg; + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - if (argc-optind < 1) - { - std::cerr << "Required paths missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + if (argc - optind < 1) { + std::cerr << "Required paths missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - std::string outDir = argv[optind++]; - - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - logger(logDEBUG) << " outDir: " << outDir; - - // Output file - std::string fileName = outDir + "/" + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + "_pbv3-module.json"; - logger(logINFO) << "Results stored in " << fileName; - std::fstream outfile(fileName, std::ios::out); - if(!outfile.is_open()) - { - logger(logERROR) << "Unable to create results file " << fileName; - return 2; + std::string outDir = argv[optind++]; + + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << " outDir: " << outDir; + + // Output file + std::string fileName = + outDir + "/" + + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + + "_pbv3-module.json"; + logger(logINFO) << "Results stored in " << fileName; + std::fstream outfile(fileName, std::ios::out); + if (!outfile.is_open()) { + logger(logERROR) << "Unable to create results file " << fileName; + return 2; } - // - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - - - // Init com - json config; - if(!configfile.empty()) - { - std::ifstream fh_in(configfile); - if(fh_in.is_open()) - fh_in >> config; + // + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + // Init com + json config; + if (!configfile.empty()) { + std::ifstream fh_in(configfile); + if (fh_in.is_open()) fh_in >> config; } + logger(logINFO) << "Init AMAC"; + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + amac->init(); + PBv3ConfigTools::saveConfigAMAC(amac, config); - logger(logINFO) << "Init AMAC"; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - amac->init(); - PBv3ConfigTools::saveConfigAMAC(amac, config); - - // - // Start testing + // + // Start testing - json testSum; - testSum["program"] = argv[0]; - testSum["config"] = config; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + json testSum; + testSum["program"] = argv[0]; + testSum["config"] = config; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - uint32_t test=0; - testSum["tests"][test++] = PBv3TestTools::measureHvCurrent(pbNum, tb, 10000); + uint32_t test = 0; + testSum["tests"][test++] = + PBv3TestTools::measureHvCurrent(pbNum, tb, 10000); - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - outfile << std::setw(4) << testSum << std::endl; + outfile << std::setw(4) << testSum << std::endl; - outfile.close(); + outfile.close(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_monitor.cpp b/pbv3/tools/pbv3_monitor.cpp index 4ad9c874eb76119fa8b01f65a5b2ab4a6bdad0fc..d4d9fdd3af15b7e39ad7361f83c62322812701c3 100644 --- a/pbv3/tools/pbv3_monitor.cpp +++ b/pbv3/tools/pbv3_monitor.cpp @@ -1,24 +1,21 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> #include <signal.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> - -#include "Logger.h" +#include <thread> #include "AMACv2.h" - +#include "Logger.h" +#include "PBv3ConfigTools.h" #include "PBv3TBConf.h" #include "PBv3TBSingle.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" #include "PBv3Utils.h" //------ SETTINGS @@ -27,145 +24,148 @@ std::string configfile = "config.json"; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -bool quit=false; -void cleanup(int signum) -{ quit=true; } - -#define PERIOD_LONG 60 // number of seconds of monitoring between calibrations -#define PERIOD_MONITOR 1 // number of seconds to wait between readings -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -c, --config Config with AMAC calibrations. (default: " << configfile << ")" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +bool quit = false; +void cleanup(int signum) { quit = true; } + +#define PERIOD_LONG 60 // number of seconds of monitoring between calibrations +#define PERIOD_MONITOR 1 // number of seconds to wait between readings +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] datadir" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr + << " -c, --config Config with AMAC calibrations. (default: " + << configfile << ")" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"config" , required_argument, 0, 'c' }, - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "c:b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'c': - configfile = optarg; - break; - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } +int main(int argc, char* argv[]) { + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"config", required_argument, 0, 'c'}, + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "c:b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'c': + configfile = optarg; + break; + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - if (argc-optind < 1) - { - std::cerr << "Required output path missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + if (argc - optind < 1) { + std::cerr << "Required output path missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - std::string outDir = argv[optind++]; + std::string outDir = argv[optind++]; - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " outDir: " << outDir; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " outDir: " << outDir; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - // Register interrupt for cleanup - signal(SIGINT, cleanup); - signal(SIGTERM, cleanup); + // Register interrupt for cleanup + signal(SIGINT, cleanup); + signal(SIGTERM, cleanup); - // Get default config - json defconfig; - if(!configfile.empty()) - { - std::ifstream fh_in(configfile); - if(fh_in.is_open()) - fh_in >> defconfig; + // Get default config + json defconfig; + if (!configfile.empty()) { + std::ifstream fh_in(configfile); + if (fh_in.is_open()) fh_in >> defconfig; } - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - amac->init(); - - // - // Start running tests in a loop forever! - // - while(!quit) - { - // - // Rerun the calibration - - //Run all calibrations - json config=defconfig; - config.merge_patch(PBv3ConfigTools::tuneNTC (amac)); - config.merge_patch(PBv3ConfigTools::calibrateSlope (amac, tb->getCalDAC())); - config.merge_patch(PBv3ConfigTools::calibrateOffset (amac)); - config.merge_patch(PBv3ConfigTools::calibrateNTC (amac)); - PBv3ConfigTools::saveConfigAMAC(amac, config); - - // Prepare the output structure - json testSum; - testSum["program"] = argv[0]; - testSum["config"] = config; - testSum["time"]["start"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - uint32_t test=0; - - // Start monitoring in a loop - for(uint32_t monIdx=0; monIdx<PERIOD_LONG/PERIOD_MONITOR; monIdx++) - { - if(std::dynamic_pointer_cast<PBv3TBSingle>(tb)) - testSum["tests"][test++] = PBv3TestTools::readStatus(amac, tb->getLVPS(), std::dynamic_pointer_cast<PBv3TBSingle>(tb)->getLoadPtr(), tb->getHVPS()); - else - testSum["tests"][test++] = PBv3TestTools::readStatus(amac, tb->getLVPS(), nullptr, tb->getHVPS()); - std::this_thread::sleep_for(std::chrono::seconds(PERIOD_MONITOR)); - } - - // cleanup the file - testSum["time"]["end"] = PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); - - // Output file - std::string fileName = outDir + "/" + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + "_pbv3-monitor.json"; - std::fstream outfile(fileName, std::ios::out); - outfile << std::setw(4) << testSum << std::endl; - outfile.close(); - logger(logINFO) << "Results stored in " << fileName; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + amac->init(); + + // + // Start running tests in a loop forever! + // + while (!quit) { + // + // Rerun the calibration + + // Run all calibrations + json config = defconfig; + config.merge_patch(PBv3ConfigTools::tuneNTC(amac)); + config.merge_patch( + PBv3ConfigTools::calibrateSlope(amac, tb->getCalDAC())); + config.merge_patch(PBv3ConfigTools::calibrateOffset(amac)); + config.merge_patch(PBv3ConfigTools::calibrateNTC(amac)); + PBv3ConfigTools::saveConfigAMAC(amac, config); + + // Prepare the output structure + json testSum; + testSum["program"] = argv[0]; + testSum["config"] = config; + testSum["time"]["start"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + uint32_t test = 0; + + // Start monitoring in a loop + for (uint32_t monIdx = 0; monIdx < PERIOD_LONG / PERIOD_MONITOR; + monIdx++) { + if (std::dynamic_pointer_cast<PBv3TBSingle>(tb)) + testSum["tests"][test++] = PBv3TestTools::readStatus( + amac, tb->getLVPS(), + std::dynamic_pointer_cast<PBv3TBSingle>(tb)->getLoadPtr(), + tb->getHVPS()); + else + testSum["tests"][test++] = PBv3TestTools::readStatus( + amac, tb->getLVPS(), nullptr, tb->getHVPS()); + std::this_thread::sleep_for(std::chrono::seconds(PERIOD_MONITOR)); + } + + // cleanup the file + testSum["time"]["end"] = + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()); + + // Output file + std::string fileName = + outDir + "/" + + PBv3Utils::getTimeAsString(std::chrono::system_clock::now()) + + "_pbv3-monitor.json"; + std::fstream outfile(fileName, std::ios::out); + outfile << std::setw(4) << testSum << std::endl; + outfile.close(); + logger(logINFO) << "Results stored in " << fileName; } - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_powerOff.cpp b/pbv3/tools/pbv3_powerOff.cpp index da99bbec0f129f82217bc749521e68bad53d726a..f382dd93851134514d4c089519fae60f2da7db38 100644 --- a/pbv3/tools/pbv3_powerOff.cpp +++ b/pbv3/tools/pbv3_powerOff.cpp @@ -1,6 +1,5 @@ -#include <getopt.h> - #include <Logger.h> +#include <getopt.h> #include "PBv3TBConf.h" @@ -8,58 +7,53 @@ std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } +int main(int argc, char* argv[]) { + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - // Turn off power supplies - tb->powerHVOff(); - tb->powerLVOff(); + // Turn off power supplies + tb->powerHVOff(); + tb->powerLVOff(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_print_status.cpp b/pbv3/tools/pbv3_print_status.cpp index 56343f88661d639ddf509f9b44f8ab375cb66798..8df0f581d956e56d6d7f734e05dc6a03e7799fee 100644 --- a/pbv3/tools/pbv3_print_status.cpp +++ b/pbv3/tools/pbv3_print_status.cpp @@ -1,23 +1,20 @@ -#include <unistd.h> -#include <string.h> +#include <Logger.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> - -#include <Logger.h> +#include <thread> #include "AMACv2.h" - +#include "PBv3ConfigTools.h" #include "PBv3TBConf.h" #include "PBv3TBMassive.h" #include "PBv3TestTools.h" -#include "PBv3ConfigTools.h" //------ SETTINGS uint8_t pbNum = 0; @@ -25,271 +22,300 @@ std::string equipConfigFile = "config/equip_testbench.json"; //--------------- //------ Channel Map -std::map<std::string,AMACv2Field AMACv2RegMap::*> channelmap={ - {"VDCDC" ,&AMACv2::Ch0Value}, - {"VDDLR" ,&AMACv2::Ch1Value}, - {"DCDCin" ,&AMACv2::Ch2Value}, - {"VDDREG" ,&AMACv2::Ch3Value}, - {"sysBG" ,&AMACv2::Ch3Value}, - {"AM900BG" ,&AMACv2::Ch3Value}, - {"AM600BG" ,&AMACv2::Ch4Value}, - {"CAL" ,&AMACv2::Ch4Value}, - {"AMref" ,&AMACv2::Ch4Value}, - {"CALx" ,&AMACv2::Ch5Value}, - {"CALy" ,&AMACv2::Ch5Value}, - {"Shuntx" ,&AMACv2::Ch5Value}, - {"Shunty" ,&AMACv2::Ch5Value}, - {"HGND" ,&AMACv2::Ch5Value}, - {"DIETEMP" ,&AMACv2::Ch6Value}, - {"NTCx" ,&AMACv2::Ch7Value}, - {"NTCy" ,&AMACv2::Ch8Value}, - {"NTCpb" ,&AMACv2::Ch9Value}, - {"Hrefx" ,&AMACv2::Ch10Value}, - {"Hrefy" ,&AMACv2::Ch11Value}, - {"Cur10V" ,&AMACv2::Ch12Value}, - {"Cur10VTPlow" ,&AMACv2::Ch12Value}, - {"Cur10VTPhigh",&AMACv2::Ch12Value}, - {"Cur1V" ,&AMACv2::Ch13Value}, - {"Cur1VTPlow" ,&AMACv2::Ch13Value}, - {"Cur1VTPhigh" ,&AMACv2::Ch13Value}, - {"HVret" ,&AMACv2::Ch14Value}, - {"PTAT" ,&AMACv2::Ch15Value}, +std::map<std::string, AMACv2Field AMACv2RegMap::*> channelmap = { + {"VDCDC", &AMACv2::Ch0Value}, {"VDDLR", &AMACv2::Ch1Value}, + {"DCDCin", &AMACv2::Ch2Value}, {"VDDREG", &AMACv2::Ch3Value}, + {"sysBG", &AMACv2::Ch3Value}, {"AM900BG", &AMACv2::Ch3Value}, + {"AM600BG", &AMACv2::Ch4Value}, {"CAL", &AMACv2::Ch4Value}, + {"AMref", &AMACv2::Ch4Value}, {"CALx", &AMACv2::Ch5Value}, + {"CALy", &AMACv2::Ch5Value}, {"Shuntx", &AMACv2::Ch5Value}, + {"Shunty", &AMACv2::Ch5Value}, {"HGND", &AMACv2::Ch5Value}, + {"DIETEMP", &AMACv2::Ch6Value}, {"NTCx", &AMACv2::Ch7Value}, + {"NTCy", &AMACv2::Ch8Value}, {"NTCpb", &AMACv2::Ch9Value}, + {"Hrefx", &AMACv2::Ch10Value}, {"Hrefy", &AMACv2::Ch11Value}, + {"Cur10V", &AMACv2::Ch12Value}, {"Cur10VTPlow", &AMACv2::Ch12Value}, + {"Cur10VTPhigh", &AMACv2::Ch12Value}, {"Cur1V", &AMACv2::Ch13Value}, + {"Cur1VTPlow", &AMACv2::Ch13Value}, {"Cur1VTPhigh", &AMACv2::Ch13Value}, + {"HVret", &AMACv2::Ch14Value}, {"PTAT", &AMACv2::Ch15Value}, }; -std::map<std::string,std::pair<AMACv2Field AMACv2RegMap::*, uint32_t> > muxmap={ - {"VDDREG" ,{&AMACv2::Ch3Mux ,0}}, - {"sysBG" ,{&AMACv2::Ch3Mux ,1}}, - {"AM900BG" ,{&AMACv2::Ch3Mux ,2}}, - {"AM600BG" ,{&AMACv2::Ch4Mux ,0}}, - {"CAL" ,{&AMACv2::Ch4Mux ,1}}, - {"AMref" ,{&AMACv2::Ch4Mux ,2}}, - {"CALx" ,{&AMACv2::Ch5Mux ,0}}, - {"CALy" ,{&AMACv2::Ch5Mux ,1}}, - {"Shuntx" ,{&AMACv2::Ch5Mux ,2}}, - {"Shunty" ,{&AMACv2::Ch5Mux ,3}}, - {"HGND" ,{&AMACv2::Ch5Mux ,4}}, - {"Cur10V" ,{&AMACv2::Ch12Mux,0}}, - {"Cur10VTPlow" ,{&AMACv2::Ch12Mux,1}}, - {"Cur10VTPhigh",{&AMACv2::Ch12Mux,2}}, - {"Cur1V" ,{&AMACv2::Ch13Mux,0}}, - {"Cur1VTPlow" ,{&AMACv2::Ch13Mux,1}}, - {"Cur1VTPhigh" ,{&AMACv2::Ch13Mux,2}} -}; +std::map<std::string, std::pair<AMACv2Field AMACv2RegMap::*, uint32_t> > + muxmap = {{"VDDREG", {&AMACv2::Ch3Mux, 0}}, + {"sysBG", {&AMACv2::Ch3Mux, 1}}, + {"AM900BG", {&AMACv2::Ch3Mux, 2}}, + {"AM600BG", {&AMACv2::Ch4Mux, 0}}, + {"CAL", {&AMACv2::Ch4Mux, 1}}, + {"AMref", {&AMACv2::Ch4Mux, 2}}, + {"CALx", {&AMACv2::Ch5Mux, 0}}, + {"CALy", {&AMACv2::Ch5Mux, 1}}, + {"Shuntx", {&AMACv2::Ch5Mux, 2}}, + {"Shunty", {&AMACv2::Ch5Mux, 3}}, + {"HGND", {&AMACv2::Ch5Mux, 4}}, + {"Cur10V", {&AMACv2::Ch12Mux, 0}}, + {"Cur10VTPlow", {&AMACv2::Ch12Mux, 1}}, + {"Cur10VTPhigh", {&AMACv2::Ch12Mux, 2}}, + {"Cur1V", {&AMACv2::Ch13Mux, 0}}, + {"Cur1VTPlow", {&AMACv2::Ch13Mux, 1}}, + {"Cur1VTPhigh", {&AMACv2::Ch13Mux, 2}}}; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } void readAMAC(std::shared_ptr<AMACv2> amac); void readMux(std::shared_ptr<PBv3TB> tb, int pb); -int main(int argc, char* argv[]) -{ - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } - } +int main(int argc, char* argv[]) { + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - //Get amac - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - - if(std::dynamic_pointer_cast<PBv3TBMassive>(tb)) - { // Massive tester can check if AMAC is powered before trying to read it - double LP1V4; - LP1V4 = tb->readCarrierOutput(pbNum, PBv3TB::LINPOL1V4); - - if(LP1V4 > 1.3 && LP1V4 < 1.5) - { - readMux(tb, pbNum); - readAMAC(amac); - } - else - { - logger(logERROR) << "PB " << pbNum << ": linPOL 1V4 reading " << LP1V4 << "."; - readMux(tb, pbNum); - } + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - else - readAMAC(amac); - return 0; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + // Get amac + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + + if (std::dynamic_pointer_cast<PBv3TBMassive>( + tb)) { // Massive tester can check if AMAC is powered before trying + // to read it + double LP1V4; + LP1V4 = tb->readCarrierOutput(pbNum, PBv3TB::LINPOL1V4); + + if (LP1V4 > 1.3 && LP1V4 < 1.5) { + readMux(tb, pbNum); + readAMAC(amac); + } else { + logger(logERROR) + << "PB " << pbNum << ": linPOL 1V4 reading " << LP1V4 << "."; + readMux(tb, pbNum); + } + } else + readAMAC(amac); + + return 0; } -void readMux(std::shared_ptr<PBv3TB> tb, int pbNum) -{ - std::cout << "\nReading Multiplexer values:" << std::endl << std::endl; - - //Vout - std::cout << "Vout: " << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::VOUT ) << std::endl; - - //OFout - std::cout << "OFout: " << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::OFout ) << std::endl; - - //Shuntx - std::cout << "Shuntx: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::SHUNTx ) << std::endl; - - //Shunty - std::cout << "Shunty: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::SHUNTy ) << std::endl; - - //CALx - std::cout << "CALx: " << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::CALx ) << std::endl; - - //CALy - std::cout << "CALy: " << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::CALy ) << std::endl; - - //LDx0EN - std::cout << "LDx0EN: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDx0EN ) << std::endl; - - //LDx1EN - std::cout << "LDx1EN: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDx1EN ) << std::endl; - - //LDx2EN - std::cout << "LDx2EN: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDx2EN ) << std::endl; - - //LDy0EN - std::cout << "LDy0EN: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDy0EN ) << std::endl; - - //LDy1EN - std::cout << "LDy1EN: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDy1EN ) << std::endl; - - //LDy2EN - std::cout << "LDy2EN: " << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDy2EN ) << std::endl; +void readMux(std::shared_ptr<PBv3TB> tb, int pbNum) { + std::cout << "\nReading Multiplexer values:" << std::endl << std::endl; + + // Vout + std::cout << "Vout: " + << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::VOUT) + << std::endl; + + // OFout + std::cout << "OFout: " + << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::OFout) + << std::endl; + + // Shuntx + std::cout << "Shuntx: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::SHUNTx) + << std::endl; + + // Shunty + std::cout << "Shunty: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::SHUNTy) + << std::endl; + + // CALx + std::cout << "CALx: " + << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::CALx) + << std::endl; + + // CALy + std::cout << "CALy: " + << "\t\t" << tb->readCarrierOutput(pbNum, PBv3TB::CALy) + << std::endl; + + // LDx0EN + std::cout << "LDx0EN: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDx0EN) + << std::endl; + + // LDx1EN + std::cout << "LDx1EN: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDx1EN) + << std::endl; + + // LDx2EN + std::cout << "LDx2EN: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDx2EN) + << std::endl; + + // LDy0EN + std::cout << "LDy0EN: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDy0EN) + << std::endl; + + // LDy1EN + std::cout << "LDy1EN: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDy1EN) + << std::endl; + + // LDy2EN + std::cout << "LDy2EN: " + << "\t" << tb->readCarrierOutput(pbNum, PBv3TB::LDy2EN) + << std::endl; } -void readAMAC(std::shared_ptr<AMACv2> amac) -{ - std::cout << "\nReading AMAC values:" << std::endl << std::endl; - - std::cout << "VDCDC: " << "\t\t" << amac->rdField(&AMACv2::Ch0Value) << std::endl; - - std::cout << "VDDLR: " << "\t\t" << amac->rdField(&AMACv2::Ch1Value) << std::endl; - - std::cout << "DCDCin: " << "\t" << amac->rdField(&AMACv2::Ch2Value) << std::endl; - - amac->wrField(muxmap["VDDREG"].first,muxmap["VDDREG"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "VDDREG: " << "\t" << amac->rdField(&AMACv2::Ch3Value) << std::endl; - - amac->wrField(muxmap["sysBG"].first,muxmap["sysBG"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "sysBG: " << "\t\t" << amac->rdField(&AMACv2::Ch3Value) << std::endl; - - amac->wrField(muxmap["AM900BG"].first,muxmap["AM900BG"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "AM900BG: " << "\t" << amac->rdField(&AMACv2::Ch3Value) << std::endl; - - std::cout << "AM600BG: " << "\t" << amac->rdField(&AMACv2::Ch4Value) << std::endl; - - amac->wrField(muxmap["CAL"].first,muxmap["CAL"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "CAL: " << "\t\t" << amac->rdField(&AMACv2::Ch4Value) << std::endl; - - amac->wrField(muxmap["AMref"].first,muxmap["AMref"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "AMref: " << "\t\t" << amac->rdField(&AMACv2::Ch4Value) << std::endl; - - amac->wrField(muxmap["Shuntx"].first,muxmap["Shuntx"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Shuntx: " << "\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; - - amac->wrField(muxmap["Shunty"].first,muxmap["Shunty"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Shunty: " << "\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; - - amac->wrField(muxmap["CALx"].first,muxmap["CALx"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "CALx: " << "\t\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; - - amac->wrField(muxmap["CALy"].first,muxmap["CALy"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "CALy: " << "\t\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(200)); - - amac->wrField(muxmap["HGND"].first,muxmap["HGND"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "HGND: " << "\t\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; - - std::cout << "DIETEMP: " << "\t" << amac->rdField(&AMACv2::Ch6Value) << std::endl; - - std::cout << "NTCx: " << "\t\t" << amac->rdField(&AMACv2::Ch7Value) << std::endl; - - std::cout << "NTCy: " << "\t\t" << amac->rdField(&AMACv2::Ch8Value) << std::endl; - - std::cout << "NTCpb: " << "\t\t" << amac->rdField(&AMACv2::Ch9Value) << std::endl; - - std::cout << "Hrefx: " << "\t\t" << amac->rdField(&AMACv2::Ch10Value) << std::endl; - - std::cout << "Hrefy: " << "\t\t" << amac->rdField(&AMACv2::Ch11Value) << std::endl; - - amac->wrField(muxmap["Cur10V"].first,muxmap["Cur10V"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Cur10V: " << "\t" << amac->rdField(&AMACv2::Ch12Value) << std::endl; - - amac->wrField(muxmap["Cur10VTPlow"].first,muxmap["Cur10VTPlow"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Cur10VTPlow: " << "\t" << amac->rdField(&AMACv2::Ch12Value) << std::endl; - - amac->wrField(muxmap["Cur10VTPhigh"].first,muxmap["Cur10VTPhigh"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Cur10VTPhigh: " << "\t" << amac->rdField(&AMACv2::Ch12Value) << std::endl; - - amac->wrField(muxmap["Cur1V"].first,muxmap["Cur1V"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Cur1V: " << "\t\t" << amac->rdField(&AMACv2::Ch13Value) << std::endl; - - amac->wrField(muxmap["Cur1VTPlow"].first,muxmap["Cur1VTPlow"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Cur1VTPlow: " << "\t" << amac->rdField(&AMACv2::Ch13Value) << std::endl; - - amac->wrField(muxmap["Cur1VTPhigh"].first,muxmap["Cur1VTPhigh"].second); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - std::cout << "Cur1VTPhigh: " << "\t" << amac->rdField(&AMACv2::Ch13Value) << std::endl; - - std::cout << "HVret: " << "\t\t" << amac->rdField(&AMACv2::Ch14Value) << std::endl; - - std::cout << "PTAT: " << "\t\t" << amac->rdField(&AMACv2::Ch15Value) << std::endl; +void readAMAC(std::shared_ptr<AMACv2> amac) { + std::cout << "\nReading AMAC values:" << std::endl << std::endl; + + std::cout << "VDCDC: " + << "\t\t" << amac->rdField(&AMACv2::Ch0Value) << std::endl; + + std::cout << "VDDLR: " + << "\t\t" << amac->rdField(&AMACv2::Ch1Value) << std::endl; + + std::cout << "DCDCin: " + << "\t" << amac->rdField(&AMACv2::Ch2Value) << std::endl; + + amac->wrField(muxmap["VDDREG"].first, muxmap["VDDREG"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "VDDREG: " + << "\t" << amac->rdField(&AMACv2::Ch3Value) << std::endl; + + amac->wrField(muxmap["sysBG"].first, muxmap["sysBG"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "sysBG: " + << "\t\t" << amac->rdField(&AMACv2::Ch3Value) << std::endl; + + amac->wrField(muxmap["AM900BG"].first, muxmap["AM900BG"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "AM900BG: " + << "\t" << amac->rdField(&AMACv2::Ch3Value) << std::endl; + + std::cout << "AM600BG: " + << "\t" << amac->rdField(&AMACv2::Ch4Value) << std::endl; + + amac->wrField(muxmap["CAL"].first, muxmap["CAL"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "CAL: " + << "\t\t" << amac->rdField(&AMACv2::Ch4Value) << std::endl; + + amac->wrField(muxmap["AMref"].first, muxmap["AMref"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "AMref: " + << "\t\t" << amac->rdField(&AMACv2::Ch4Value) << std::endl; + + amac->wrField(muxmap["Shuntx"].first, muxmap["Shuntx"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Shuntx: " + << "\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; + + amac->wrField(muxmap["Shunty"].first, muxmap["Shunty"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Shunty: " + << "\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; + + amac->wrField(muxmap["CALx"].first, muxmap["CALx"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "CALx: " + << "\t\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; + + amac->wrField(muxmap["CALy"].first, muxmap["CALy"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "CALy: " + << "\t\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + + amac->wrField(muxmap["HGND"].first, muxmap["HGND"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "HGND: " + << "\t\t" << amac->rdField(&AMACv2::Ch5Value) << std::endl; + + std::cout << "DIETEMP: " + << "\t" << amac->rdField(&AMACv2::Ch6Value) << std::endl; + + std::cout << "NTCx: " + << "\t\t" << amac->rdField(&AMACv2::Ch7Value) << std::endl; + + std::cout << "NTCy: " + << "\t\t" << amac->rdField(&AMACv2::Ch8Value) << std::endl; + + std::cout << "NTCpb: " + << "\t\t" << amac->rdField(&AMACv2::Ch9Value) << std::endl; + + std::cout << "Hrefx: " + << "\t\t" << amac->rdField(&AMACv2::Ch10Value) << std::endl; + + std::cout << "Hrefy: " + << "\t\t" << amac->rdField(&AMACv2::Ch11Value) << std::endl; + + amac->wrField(muxmap["Cur10V"].first, muxmap["Cur10V"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Cur10V: " + << "\t" << amac->rdField(&AMACv2::Ch12Value) << std::endl; + + amac->wrField(muxmap["Cur10VTPlow"].first, muxmap["Cur10VTPlow"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Cur10VTPlow: " + << "\t" << amac->rdField(&AMACv2::Ch12Value) << std::endl; + + amac->wrField(muxmap["Cur10VTPhigh"].first, muxmap["Cur10VTPhigh"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Cur10VTPhigh: " + << "\t" << amac->rdField(&AMACv2::Ch12Value) << std::endl; + + amac->wrField(muxmap["Cur1V"].first, muxmap["Cur1V"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Cur1V: " + << "\t\t" << amac->rdField(&AMACv2::Ch13Value) << std::endl; + + amac->wrField(muxmap["Cur1VTPlow"].first, muxmap["Cur1VTPlow"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Cur1VTPlow: " + << "\t" << amac->rdField(&AMACv2::Ch13Value) << std::endl; + + amac->wrField(muxmap["Cur1VTPhigh"].first, muxmap["Cur1VTPhigh"].second); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::cout << "Cur1VTPhigh: " + << "\t" << amac->rdField(&AMACv2::Ch13Value) << std::endl; + + std::cout << "HVret: " + << "\t\t" << amac->rdField(&AMACv2::Ch14Value) << std::endl; + + std::cout << "PTAT: " + << "\t\t" << amac->rdField(&AMACv2::Ch15Value) << std::endl; } diff --git a/pbv3/tools/pbv3_readADC.cpp b/pbv3/tools/pbv3_readADC.cpp index 1eb19dd08d52f04499d0e4c592a119ea0951c19d..21042cb1106f1cbd35fa1918b65ebb38b12d5687 100644 --- a/pbv3/tools/pbv3_readADC.cpp +++ b/pbv3/tools/pbv3_readADC.cpp @@ -1,21 +1,18 @@ -#include <unistd.h> -#include <string.h> +#include <Logger.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <fstream> #include <iomanip> #include <iostream> -#include <thread> - #include <nlohmann/json.hpp> - -#include <Logger.h> +#include <thread> #include "AMACv2.h" - -#include "PBv3TBConf.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" //------ SETTINGS uint8_t pbNum = 0; @@ -23,220 +20,195 @@ std::string equipConfigFile = "config/equip_testbench.json"; //--------------- //------ Channel Map -std::map<std::string,AMACv2Field AMACv2RegMap::*> channelmap={ - {"VDCDC" ,&AMACv2::Ch0Value}, - {"VDDLR" ,&AMACv2::Ch1Value}, - {"DCDCin" ,&AMACv2::Ch2Value}, - {"VDDREG" ,&AMACv2::Ch3Value}, - {"sysBG" ,&AMACv2::Ch3Value}, - {"AM900BG" ,&AMACv2::Ch3Value}, - {"AM600BG" ,&AMACv2::Ch4Value}, - {"CAL" ,&AMACv2::Ch4Value}, - {"AMref" ,&AMACv2::Ch4Value}, - {"CALx" ,&AMACv2::Ch5Value}, - {"CALy" ,&AMACv2::Ch5Value}, - {"Shuntx" ,&AMACv2::Ch5Value}, - {"Shunty" ,&AMACv2::Ch5Value}, - {"HGND" ,&AMACv2::Ch5Value}, - {"DIETEMP" ,&AMACv2::Ch6Value}, - {"NTCx" ,&AMACv2::Ch7Value}, - {"NTCy" ,&AMACv2::Ch8Value}, - {"NTCpb" ,&AMACv2::Ch9Value}, - {"Hrefx" ,&AMACv2::Ch10Value}, - {"Hrefy" ,&AMACv2::Ch11Value}, - {"Cur10V" ,&AMACv2::Ch12Value}, - {"Cur10VTPlow" ,&AMACv2::Ch12Value}, - {"Cur10VTPhigh",&AMACv2::Ch12Value}, - {"Cur1V" ,&AMACv2::Ch13Value}, - {"Cur1VTPlow" ,&AMACv2::Ch13Value}, - {"Cur1VTPhigh" ,&AMACv2::Ch13Value}, - {"HVret" ,&AMACv2::Ch14Value}, - {"PTAT" ,&AMACv2::Ch15Value}, +std::map<std::string, AMACv2Field AMACv2RegMap::*> channelmap = { + {"VDCDC", &AMACv2::Ch0Value}, {"VDDLR", &AMACv2::Ch1Value}, + {"DCDCin", &AMACv2::Ch2Value}, {"VDDREG", &AMACv2::Ch3Value}, + {"sysBG", &AMACv2::Ch3Value}, {"AM900BG", &AMACv2::Ch3Value}, + {"AM600BG", &AMACv2::Ch4Value}, {"CAL", &AMACv2::Ch4Value}, + {"AMref", &AMACv2::Ch4Value}, {"CALx", &AMACv2::Ch5Value}, + {"CALy", &AMACv2::Ch5Value}, {"Shuntx", &AMACv2::Ch5Value}, + {"Shunty", &AMACv2::Ch5Value}, {"HGND", &AMACv2::Ch5Value}, + {"DIETEMP", &AMACv2::Ch6Value}, {"NTCx", &AMACv2::Ch7Value}, + {"NTCy", &AMACv2::Ch8Value}, {"NTCpb", &AMACv2::Ch9Value}, + {"Hrefx", &AMACv2::Ch10Value}, {"Hrefy", &AMACv2::Ch11Value}, + {"Cur10V", &AMACv2::Ch12Value}, {"Cur10VTPlow", &AMACv2::Ch12Value}, + {"Cur10VTPhigh", &AMACv2::Ch12Value}, {"Cur1V", &AMACv2::Ch13Value}, + {"Cur1VTPlow", &AMACv2::Ch13Value}, {"Cur1VTPhigh", &AMACv2::Ch13Value}, + {"HVret", &AMACv2::Ch14Value}, {"PTAT", &AMACv2::Ch15Value}, }; -std::map<std::string,std::pair<AMACv2Field AMACv2RegMap::*, uint32_t> > muxmap={ - {"VDDREG" ,{&AMACv2::Ch3Mux ,0}}, - {"sysBG" ,{&AMACv2::Ch3Mux ,1}}, - {"AM900BG" ,{&AMACv2::Ch3Mux ,2}}, - {"AM600BG" ,{&AMACv2::Ch4Mux ,0}}, - {"CAL" ,{&AMACv2::Ch4Mux ,1}}, - {"AMref" ,{&AMACv2::Ch4Mux ,2}}, - {"CALx" ,{&AMACv2::Ch5Mux ,0}}, - {"CALy" ,{&AMACv2::Ch5Mux ,1}}, - {"Shuntx" ,{&AMACv2::Ch5Mux ,2}}, - {"Shunty" ,{&AMACv2::Ch5Mux ,3}}, - {"HGND" ,{&AMACv2::Ch5Mux ,4}}, - {"Cur10V" ,{&AMACv2::Ch12Mux,0}}, - {"Cur10VTPlow" ,{&AMACv2::Ch12Mux,1}}, - {"Cur10VTPhigh",{&AMACv2::Ch12Mux,2}}, - {"Cur1V" ,{&AMACv2::Ch13Mux,0}}, - {"Cur1VTPlow" ,{&AMACv2::Ch13Mux,1}}, - {"Cur1VTPhigh" ,{&AMACv2::Ch13Mux,2}} -}; +std::map<std::string, std::pair<AMACv2Field AMACv2RegMap::*, uint32_t> > + muxmap = {{"VDDREG", {&AMACv2::Ch3Mux, 0}}, + {"sysBG", {&AMACv2::Ch3Mux, 1}}, + {"AM900BG", {&AMACv2::Ch3Mux, 2}}, + {"AM600BG", {&AMACv2::Ch4Mux, 0}}, + {"CAL", {&AMACv2::Ch4Mux, 1}}, + {"AMref", {&AMACv2::Ch4Mux, 2}}, + {"CALx", {&AMACv2::Ch5Mux, 0}}, + {"CALy", {&AMACv2::Ch5Mux, 1}}, + {"Shuntx", {&AMACv2::Ch5Mux, 2}}, + {"Shunty", {&AMACv2::Ch5Mux, 3}}, + {"HGND", {&AMACv2::Ch5Mux, 4}}, + {"Cur10V", {&AMACv2::Ch12Mux, 0}}, + {"Cur10VTPlow", {&AMACv2::Ch12Mux, 1}}, + {"Cur10VTPhigh", {&AMACv2::Ch12Mux, 2}}, + {"Cur1V", {&AMACv2::Ch13Mux, 0}}, + {"Cur1VTPlow", {&AMACv2::Ch13Mux, 1}}, + {"Cur1VTPhigh", {&AMACv2::Ch13Mux, 2}}}; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] channel" << std::endl; - std::cerr << "Channel can be either number or one of the following. a name.:" << std::endl; - for(const std::pair<std::string,AMACv2Field AMACv2RegMap::*>& kv : channelmap) - std::cerr << " " << kv.first << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] channel" << std::endl; + std::cerr + << "Channel can be either number or one of the following. a name.:" + << std::endl; + for (const std::pair<std::string, AMACv2Field AMACv2RegMap::*>& kv : + channelmap) + std::cerr << " " << kv.first << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - std::string chStr; - if (optind == argc-1) - { - chStr=argv[optind]; - } - else - { - std::cerr << "Required channel argument missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + std::string chStr; + if (optind == argc - 1) { + chStr = argv[optind]; + } else { + std::cerr << "Required channel argument missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - - - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - tb->getPB(pbNum)->init(); - - // - // Perform the read of the ADC - AMACv2Field AMACv2RegMap::* ch; - - // try channel number - try - { - int32_t chNum=std::stoi(chStr); - switch(chNum) - { - case 0: - ch=&AMACv2::Ch0Value; - break; - case 1: - ch=&AMACv2::Ch1Value; - break; - case 2: - ch=&AMACv2::Ch2Value; - break; - case 3: - ch=&AMACv2::Ch3Value; - break; - case 4: - ch=&AMACv2::Ch4Value; - break; - case 5: - ch=&AMACv2::Ch5Value; - break; - case 6: - ch=&AMACv2::Ch6Value; - break; - case 7: - ch=&AMACv2::Ch7Value; - break; - case 8: - ch=&AMACv2::Ch8Value; - break; - case 9: - ch=&AMACv2::Ch9Value; - break; - case 10: - ch=&AMACv2::Ch10Value; - break; - case 11: - ch=&AMACv2::Ch11Value; - break; - case 12: - ch=&AMACv2::Ch12Value; - break; - case 13: - ch=&AMACv2::Ch13Value; - break; - case 14: - ch=&AMACv2::Ch14Value; - break; - case 15: - ch=&AMACv2::Ch15Value; - break; - default: - std::cerr << "Channel must be in range 0-15." << std::endl; - usage(argv); - return 1; - } - } - catch(const std::invalid_argument& e) - { // Could be a channel name - if(channelmap.find(chStr)==channelmap.end()) - { - std::cerr << "Invalid channel name." << std::endl; - usage(argv); - return 1; - } - ch=channelmap[chStr]; - - // Set multiplexer - if(muxmap.find(chStr)!=muxmap.end()) - tb->getPB(pbNum)->wrField(muxmap[chStr].first,muxmap[chStr].second); + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + tb->getPB(pbNum)->init(); + + // + // Perform the read of the ADC + AMACv2Field AMACv2RegMap::*ch; + + // try channel number + try { + int32_t chNum = std::stoi(chStr); + switch (chNum) { + case 0: + ch = &AMACv2::Ch0Value; + break; + case 1: + ch = &AMACv2::Ch1Value; + break; + case 2: + ch = &AMACv2::Ch2Value; + break; + case 3: + ch = &AMACv2::Ch3Value; + break; + case 4: + ch = &AMACv2::Ch4Value; + break; + case 5: + ch = &AMACv2::Ch5Value; + break; + case 6: + ch = &AMACv2::Ch6Value; + break; + case 7: + ch = &AMACv2::Ch7Value; + break; + case 8: + ch = &AMACv2::Ch8Value; + break; + case 9: + ch = &AMACv2::Ch9Value; + break; + case 10: + ch = &AMACv2::Ch10Value; + break; + case 11: + ch = &AMACv2::Ch11Value; + break; + case 12: + ch = &AMACv2::Ch12Value; + break; + case 13: + ch = &AMACv2::Ch13Value; + break; + case 14: + ch = &AMACv2::Ch14Value; + break; + case 15: + ch = &AMACv2::Ch15Value; + break; + default: + std::cerr << "Channel must be in range 0-15." << std::endl; + usage(argv); + return 1; + } + } catch (const std::invalid_argument& e) { // Could be a channel name + if (channelmap.find(chStr) == channelmap.end()) { + std::cerr << "Invalid channel name." << std::endl; + usage(argv); + return 1; + } + ch = channelmap[chStr]; + + // Set multiplexer + if (muxmap.find(chStr) != muxmap.end()) + tb->getPB(pbNum)->wrField(muxmap[chStr].first, + muxmap[chStr].second); } - std::cout << tb->getPB(pbNum)->rdField(ch) << std::endl; + std::cout << tb->getPB(pbNum)->rdField(ch) << std::endl; - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_readMux.cpp b/pbv3/tools/pbv3_readMux.cpp index a6921489ff7dd77a555cb53f11941b1ab5f4c254..535eb96731d12de561012a49a99526dcc6a4210a 100644 --- a/pbv3/tools/pbv3_readMux.cpp +++ b/pbv3/tools/pbv3_readMux.cpp @@ -1,12 +1,11 @@ -#include <unistd.h> -#include <string.h> +#include <Logger.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <iomanip> #include <iostream> -#include <Logger.h> - #include "PBv3TBConf.h" //------ SETTINGS @@ -15,117 +14,107 @@ std::string equipConfigFile = "config/equip_testbench.json"; //--------------- //------ Output Map -std::map<std::string,PBv3TB::CARRIER_OUTPUT> outputmap={ - {"LINPOL1V4", PBv3TB::CARRIER_OUTPUT::LINPOL1V4}, - {"LINPOL3V3", PBv3TB::CARRIER_OUTPUT::LINPOL3V3}, - {"VOUT" , PBv3TB::CARRIER_OUTPUT::VOUT }, - {"OFout" , PBv3TB::CARRIER_OUTPUT::OFout }, - {"LDx0EN" , PBv3TB::CARRIER_OUTPUT::LDx0EN }, - {"LDx1EN" , PBv3TB::CARRIER_OUTPUT::LDx1EN }, - {"LDx2EN" , PBv3TB::CARRIER_OUTPUT::LDx2EN }, - {"HRSTBx" , PBv3TB::CARRIER_OUTPUT::HRSTBx }, - {"SHUNTx" , PBv3TB::CARRIER_OUTPUT::SHUNTx }, - {"CALx" , PBv3TB::CARRIER_OUTPUT::CALx }, - {"LDy0EN" , PBv3TB::CARRIER_OUTPUT::LDy0EN }, - {"LDy1EN" , PBv3TB::CARRIER_OUTPUT::LDy1EN }, - {"LDy2EN" , PBv3TB::CARRIER_OUTPUT::LDy2EN }, - {"HRSTBy" , PBv3TB::CARRIER_OUTPUT::HRSTBy }, - {"CALy" , PBv3TB::CARRIER_OUTPUT::CALy }, - {"SHUNTy" , PBv3TB::CARRIER_OUTPUT::SHUNTy } -}; +std::map<std::string, PBv3TB::CARRIER_OUTPUT> outputmap = { + {"LINPOL1V4", PBv3TB::CARRIER_OUTPUT::LINPOL1V4}, + {"LINPOL3V3", PBv3TB::CARRIER_OUTPUT::LINPOL3V3}, + {"VOUT", PBv3TB::CARRIER_OUTPUT::VOUT}, + {"OFout", PBv3TB::CARRIER_OUTPUT::OFout}, + {"LDx0EN", PBv3TB::CARRIER_OUTPUT::LDx0EN}, + {"LDx1EN", PBv3TB::CARRIER_OUTPUT::LDx1EN}, + {"LDx2EN", PBv3TB::CARRIER_OUTPUT::LDx2EN}, + {"HRSTBx", PBv3TB::CARRIER_OUTPUT::HRSTBx}, + {"SHUNTx", PBv3TB::CARRIER_OUTPUT::SHUNTx}, + {"CALx", PBv3TB::CARRIER_OUTPUT::CALx}, + {"LDy0EN", PBv3TB::CARRIER_OUTPUT::LDy0EN}, + {"LDy1EN", PBv3TB::CARRIER_OUTPUT::LDy1EN}, + {"LDy2EN", PBv3TB::CARRIER_OUTPUT::LDy2EN}, + {"HRSTBy", PBv3TB::CARRIER_OUTPUT::HRSTBy}, + {"CALy", PBv3TB::CARRIER_OUTPUT::CALy}, + {"SHUNTy", PBv3TB::CARRIER_OUTPUT::SHUNTy}}; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] output" << std::endl; - std::cerr << "Output can be either number or one of the following. a name.:" << std::endl; - for(const std::pair<std::string,PBv3TB::CARRIER_OUTPUT>& kv : outputmap) - std::cerr << " " << kv.first << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] output" << std::endl; + std::cerr << "Output can be either number or one of the following. a name.:" + << std::endl; + for (const std::pair<std::string, PBv3TB::CARRIER_OUTPUT>& kv : outputmap) + std::cerr << " " << kv.first << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 1) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 1) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - std::string outStr; - if (optind == argc-1) - { - outStr=argv[optind]; + std::string outStr; + if (optind == argc - 1) { + outStr = argv[optind]; + } else { + std::cerr << "Required output argument missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - else - { - std::cerr << "Required output argument missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; - } - - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - // Check the output name - if(outputmap.find(outStr)==outputmap.end()) - { - std::cerr << "Invalid output name." << std::endl; - usage(argv); - return 1; + // Check the output name + if (outputmap.find(outStr) == outputmap.end()) { + std::cerr << "Invalid output name." << std::endl; + usage(argv); + return 1; } - PBv3TB::CARRIER_OUTPUT out=outputmap[outStr]; + PBv3TB::CARRIER_OUTPUT out = outputmap[outStr]; - std::cout << tb->readCarrierOutput(pbNum, out) << " V" << std::endl; + std::cout << tb->readCarrierOutput(pbNum, out) << " V" << std::endl; - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_read_eFuse.cpp b/pbv3/tools/pbv3_read_eFuse.cpp index 0906f83a2fd89a7a73957e28f643bdb56d523a84..02eea56bc19e48da2e56087cf43ad41530c99f1f 100644 --- a/pbv3/tools/pbv3_read_eFuse.cpp +++ b/pbv3/tools/pbv3_read_eFuse.cpp @@ -1,88 +1,81 @@ -#include <unistd.h> #include <getopt.h> +#include <unistd.h> -#include <iostream> #include <iomanip> +#include <iostream> #include <thread> -#include "Logger.h" - -#include "PBv3TBConf.h" +#include "AMACv2.h" #include "EndeavourCom.h" #include "EndeavourComException.h" -#include "UIOCom.h" -#include "AMACv2.h" - +#include "Logger.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" +#include "UIOCom.h" //------ SETTINGS loglevel_e loglevel = logINFO; uint8_t pbNum; std::string equipConfigFile = "config/equip_testbench.json"; -void usage(char* argv[]) -{ - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number to tune (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << "" << std::endl; - std::cerr << "" << std::endl; - +void usage(char* argv[]) { + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number to tune (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr << " -e, --equip config.json Equipment configuration file " + "(default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" << std::endl; + std::cerr << "" << std::endl; + std::cerr << "" << std::endl; } -int main(int argc, char* argv[]) -{ - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board", required_argument, 0, 'b' }, - {"equip", required_argument, 0, 'e' }, - {"debug", no_argument , 0, 'd' }, - {0, 0, 0, 0 } - }; +int main(int argc, char* argv[]) { + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - loglevel = logDEBUG; - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + loglevel = logDEBUG; + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - logger(logDEBUG) << " Hardware configuration: " << equipConfigFile; + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << " Hardware configuration: " << equipConfigFile; - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - tb->getPB(pbNum)->init(); + tb->getPB(pbNum)->init(); - // - // Get eFuse ID - uint32_t eFuse = tb->getPB(pbNum)->rdField(&AMACv2RegMap::SerNum); - std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << eFuse << std::endl; + // + // Get eFuse ID + uint32_t eFuse = tb->getPB(pbNum)->rdField(&AMACv2RegMap::SerNum); + std::cout << "0x" << std::hex << std::setw(8) << std::setfill('0') << eFuse + << std::endl; - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_setcal.cpp b/pbv3/tools/pbv3_setcal.cpp index 8fc79dcecfe59ac7965b5b613c07b9cbd82d7d98..10a9cfd235138b3ccd71152e6ed52c8e2cbf1db6 100644 --- a/pbv3/tools/pbv3_setcal.cpp +++ b/pbv3/tools/pbv3_setcal.cpp @@ -1,6 +1,7 @@ -#include <unistd.h> -#include <string.h> +#include <Logger.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> #include <chrono> #include <iomanip> @@ -8,8 +9,6 @@ #include <memory> #include <thread> -#include <Logger.h> - #include "PBv3TBConf.h" //------ SETTINGS @@ -17,82 +16,74 @@ uint8_t pbNum = 0; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] value" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] value" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 2) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 2) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - double value; - if (optind == argc-1) - { - value=atof(argv[optind]); - } - else - { - std::cerr << "Required CAL value argument missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + double value; + if (optind == argc - 1) { + value = atof(argv[optind]); + } else { + std::cerr << "Required CAL value argument missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - std::shared_ptr<DACDevice> cal=tb->getCalDAC(); - double actual = cal->set(value); + std::shared_ptr<DACDevice> cal = tb->getCalDAC(); + double actual = cal->set(value); - std::cout << actual << std::endl; - return 0; + std::cout << actual << std::endl; + return 0; } diff --git a/pbv3/tools/pbv3_setload.cpp b/pbv3/tools/pbv3_setload.cpp index 7da6182569e8f7524d62becd9e8e36393f082c4c..9957277814ab1e58c38e63a00b8225029526840e 100644 --- a/pbv3/tools/pbv3_setload.cpp +++ b/pbv3/tools/pbv3_setload.cpp @@ -1,103 +1,93 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> -#include <iostream> -#include <iomanip> #include <chrono> -#include <thread> -#include <nlohmann/json.hpp> #include <fstream> - -#include "Logger.h" +#include <iomanip> +#include <iostream> +#include <nlohmann/json.hpp> +#include <thread> #include "AMACv2.h" - -#include "PBv3TBConf.h" +#include "Logger.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" //------ SETTINGS uint8_t pbNum; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] load" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] load" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 1) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 1) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - double load_value=0.; - if (optind < argc) - { - load_value=std::stod(argv[optind]); - } - else - { - std::cerr << "Required load argument missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + double load_value = 0.; + if (optind < argc) { + load_value = std::stod(argv[optind]); + } else { + std::cerr << "Required load argument missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - tb->setLoad(pbNum, load_value); + tb->setLoad(pbNum, load_value); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_setofin.cpp b/pbv3/tools/pbv3_setofin.cpp index 7a2b159e359c651bed6581273ab61e4969abe63d..3fd8109ff208a80559fe2980c76588653b4e54a8 100644 --- a/pbv3/tools/pbv3_setofin.cpp +++ b/pbv3/tools/pbv3_setofin.cpp @@ -1,104 +1,94 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> -#include <iostream> -#include <iomanip> #include <chrono> -#include <thread> -#include <nlohmann/json.hpp> #include <fstream> - -#include "Logger.h" +#include <iomanip> +#include <iostream> +#include <nlohmann/json.hpp> +#include <thread> #include "AMACv2.h" - -#include "PBv3TBConf.h" +#include "Logger.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" //------ SETTINGS uint8_t pbNum; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] 0-or-1" << std::endl; - std::cerr << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] 0-or-1" << std::endl; + std::cerr << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 1) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 1) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; - c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); - if (c == -1) - break; + c = getopt_long(argc, argv, "b:e:d", long_options, &option_index); + if (c == -1) break; - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - bool ofin=false; - if (optind < argc) - { - ofin=std::stoi(argv[optind++]); - std::cout << "OFin " << ofin << std::endl; - } - else - { - std::cerr << "Required OFin argument missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + bool ofin = false; + if (optind < argc) { + ofin = std::stoi(argv[optind++]); + std::cout << "OFin " << ofin << std::endl; + } else { + std::cerr << "Required OFin argument missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - tb->setOFin(pbNum, ofin); + tb->setOFin(pbNum, ofin); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_tune.cpp b/pbv3/tools/pbv3_tune.cpp index 52e5564961adcf0001a606af12278d70f7bac675..72e36121751c3a659318de0e7a203cec1c2d0944 100644 --- a/pbv3/tools/pbv3_tune.cpp +++ b/pbv3/tools/pbv3_tune.cpp @@ -1,191 +1,200 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> -#include <iostream> -#include <iomanip> #include <chrono> -#include <thread> -#include <nlohmann/json.hpp> #include <fstream> - -#include "Logger.h" +#include <iomanip> +#include <iostream> +#include <nlohmann/json.hpp> +#include <thread> #include "AMACv2.h" - -#include "PBv3TBConf.h" +#include "Logger.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" //------ SETTINGS uint8_t pbNum; std::string outfile = "config.json"; -bool outappend=false; +bool outappend = false; std::string serial = "DUMMY"; std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options] command [command...]" << std::endl; - std::cerr << "List of possible COMMAND:" << std::endl; - std::cerr << " vddbg Tune the VDD bandgap." << std::endl; - std::cerr << " ambg Tune the AM bandgap." << std::endl; - std::cerr << " rampgain Tune the ADC slope." << std::endl; - std::cerr << " slope Recalibrate the ADC slope." << std::endl; - std::cerr << " ntc Recalibrate the NTCs." << std::endl; - std::cerr << " cur1v Tune the Cur1V CM block." << std::endl; - std::cerr << " cur10v Tune the Cur10V CM block." << std::endl; - std::cerr << " temp Calibrate the temperature scale of PTAT/CTAT." << std::endl; - std::cerr << " all Tune everything." << std::endl; - std::cerr << "" << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -b, --board Powerboard number (default: " << (uint32_t)pbNum << ")" << std::endl; - std::cerr << " -o, --output File where to save the tuned configuration. (default: stdout)" << std::endl; - std::cerr << " -a, --append Modify existing output file instead of rewriting." << std::endl; - std::cerr << " -s, --serial Serial number of the powerboard. (default: " << serial << ")" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << "" << std::endl; - std::cerr << "" << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options] command [command...]" + << std::endl; + std::cerr << "List of possible COMMAND:" << std::endl; + std::cerr << " vddbg Tune the VDD bandgap." + << std::endl; + std::cerr << " ambg Tune the AM bandgap." + << std::endl; + std::cerr << " rampgain Tune the ADC slope." + << std::endl; + std::cerr << " slope Recalibrate the ADC slope." + << std::endl; + std::cerr << " ntc Recalibrate the NTCs." + << std::endl; + std::cerr << " cur1v Tune the Cur1V CM block." + << std::endl; + std::cerr << " cur10v Tune the Cur10V CM block." + << std::endl; + std::cerr << " temp Calibrate the temperature " + "scale of PTAT/CTAT." + << std::endl; + std::cerr << " all Tune everything." + << std::endl; + std::cerr << "" << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr << " -b, --board Powerboard number (default: " + << (uint32_t)pbNum << ")" << std::endl; + std::cerr << " -o, --output File where to save the tuned " + "configuration. (default: stdout)" + << std::endl; + std::cerr << " -a, --append Modify existing output file instead " + "of rewriting." + << std::endl; + std::cerr << " -s, --serial Serial number of the powerboard. " + "(default: " + << serial << ")" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << "" << std::endl; + std::cerr << "" << std::endl; } -int main(int argc, char* argv[]) -{ - if (argc < 1) - { - usage(argv); - return 1; +int main(int argc, char* argv[]) { + if (argc < 1) { + usage(argv); + return 1; } - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"board" , required_argument, 0, 'b' }, - {"output" , required_argument, 0, 'o' }, - {"append" , no_argument , 0, 'a' }, - {"serial" , required_argument, 0, 's' }, - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; - - c = getopt_long(argc, argv, "b:o:as:e:d", long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 'b': - pbNum = atoi(optarg); - break; - case 'o': - outfile = optarg; - break; - case 'a': - outappend = true; - break; - case 's': - serial = optarg; - break; - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"board", required_argument, 0, 'b'}, + {"output", required_argument, 0, 'o'}, + {"append", no_argument, 0, 'a'}, + {"serial", required_argument, 0, 's'}, + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; + + c = getopt_long(argc, argv, "b:o:as:e:d", long_options, &option_index); + if (c == -1) break; + + switch (c) { + case 'b': + pbNum = atoi(optarg); + break; + case 'o': + outfile = optarg; + break; + case 'a': + outappend = true; + break; + case 's': + serial = optarg; + break; + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - std::vector<std::string> commands; - if (optind < argc) - { - commands.push_back(argv[optind++]); - } - else - { - std::cerr << "Required command argument missing." << std::endl; - std::cerr << std::endl; - usage(argv); - return 1; + std::vector<std::string> commands; + if (optind < argc) { + commands.push_back(argv[optind++]); + } else { + std::cerr << "Required command argument missing." << std::endl; + std::cerr << std::endl; + usage(argv); + return 1; } - logger(logDEBUG) << "Settings"; - logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; - - // - // Open configuration - json config; - if(outappend) - { - std::ifstream fh_in(outfile); - if(fh_in.is_open()) - fh_in >> config; + logger(logDEBUG) << "Settings"; + logger(logDEBUG) << " PB number: " << (uint32_t)pbNum; + + // + // Open configuration + json config; + if (outappend) { + std::ifstream fh_in(outfile); + if (fh_in.is_open()) fh_in >> config; } - PBv3ConfigTools::decorateConfig(config); - config["component"]=serial; - - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; - - // Init com - logger(logINFO) << "Init AMAC"; - std::shared_ptr<AMACv2> amac=tb->getPB(pbNum); - amac->init(); - PBv3ConfigTools::configAMAC(amac, config, false); - amac->initRegisters(); - - // - // Run over all commands - for(const std::string& command : commands) - { - logger(logINFO) << "Running " << command; - if(command=="vddbg") - config.merge_patch(PBv3ConfigTools::tuneVDDBG (amac)); - if(command=="ambg") - config.merge_patch(PBv3ConfigTools::tuneAMBG (amac, tb->getCalDAC())); - if(command=="rampgain") - config.merge_patch(PBv3ConfigTools::tuneRampGain (amac, tb->getCalDAC())); - if(command=="slope") - config.merge_patch(PBv3ConfigTools::calibrateSlope (amac, tb->getCalDAC())); - if(command=="offset") - config.merge_patch(PBv3ConfigTools::calibrateOffset (amac)); - if(command=="ntc") - config.merge_patch(PBv3ConfigTools::calibrateNTC (amac)); - if(command=="cur10v") - config.merge_patch(PBv3ConfigTools::tuneCur10V (amac)); - if(command=="cur1v") - config.merge_patch(PBv3ConfigTools::tuneCur1V (amac)); - if(command=="temp") - config.merge_patch(PBv3ConfigTools::calibrateTemperature(amac)); - if(command=="all") - { - config.merge_patch(PBv3ConfigTools::calibrateSlope (amac, tb->getCalDAC())); - config.merge_patch(PBv3ConfigTools::calibrateOffset (amac)); - config.merge_patch(PBv3ConfigTools::tuneVDDBG (amac)); - config.merge_patch(PBv3ConfigTools::tuneAMBG (amac, tb->getCalDAC())); - config.merge_patch(PBv3ConfigTools::tuneRampGain (amac, tb->getCalDAC())); - config.merge_patch(PBv3ConfigTools::tuneCur10V (amac)); - config.merge_patch(PBv3ConfigTools::tuneCur1V (amac)); - config.merge_patch(PBv3ConfigTools::calibrateNTC (amac)); - config.merge_patch(PBv3ConfigTools::calibrateTemperature(amac)); - } + PBv3ConfigTools::decorateConfig(config); + config["component"] = serial; + + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; + + // Init com + logger(logINFO) << "Init AMAC"; + std::shared_ptr<AMACv2> amac = tb->getPB(pbNum); + amac->init(); + PBv3ConfigTools::configAMAC(amac, config, false); + amac->initRegisters(); + + // + // Run over all commands + for (const std::string& command : commands) { + logger(logINFO) << "Running " << command; + if (command == "vddbg") + config.merge_patch(PBv3ConfigTools::tuneVDDBG(amac)); + if (command == "ambg") + config.merge_patch( + PBv3ConfigTools::tuneAMBG(amac, tb->getCalDAC())); + if (command == "rampgain") + config.merge_patch( + PBv3ConfigTools::tuneRampGain(amac, tb->getCalDAC())); + if (command == "slope") + config.merge_patch( + PBv3ConfigTools::calibrateSlope(amac, tb->getCalDAC())); + if (command == "offset") + config.merge_patch(PBv3ConfigTools::calibrateOffset(amac)); + if (command == "ntc") + config.merge_patch(PBv3ConfigTools::calibrateNTC(amac)); + if (command == "cur10v") + config.merge_patch(PBv3ConfigTools::tuneCur10V(amac)); + if (command == "cur1v") + config.merge_patch(PBv3ConfigTools::tuneCur1V(amac)); + if (command == "temp") + config.merge_patch(PBv3ConfigTools::calibrateTemperature(amac)); + if (command == "all") { + config.merge_patch( + PBv3ConfigTools::calibrateSlope(amac, tb->getCalDAC())); + config.merge_patch(PBv3ConfigTools::calibrateOffset(amac)); + config.merge_patch(PBv3ConfigTools::tuneVDDBG(amac)); + config.merge_patch( + PBv3ConfigTools::tuneAMBG(amac, tb->getCalDAC())); + config.merge_patch( + PBv3ConfigTools::tuneRampGain(amac, tb->getCalDAC())); + config.merge_patch(PBv3ConfigTools::tuneCur10V(amac)); + config.merge_patch(PBv3ConfigTools::tuneCur1V(amac)); + config.merge_patch(PBv3ConfigTools::calibrateNTC(amac)); + config.merge_patch(PBv3ConfigTools::calibrateTemperature(amac)); + } } - // - // Save configuration - std::ofstream fh_out(outfile); - fh_out << std::setw(4) << config << std::endl; - fh_out.close(); + // + // Save configuration + std::ofstream fh_out(outfile); + fh_out << std::setw(4) << config << std::endl; + fh_out.close(); - return 0; + return 0; } diff --git a/pbv3/tools/pbv3_whatisalive.cpp b/pbv3/tools/pbv3_whatisalive.cpp index 08aa660ba9316905613c49d65d69f839e7961e6c..611a725f436a7c1f7f0fd652aea246beef5b4ef4 100644 --- a/pbv3/tools/pbv3_whatisalive.cpp +++ b/pbv3/tools/pbv3_whatisalive.cpp @@ -1,95 +1,87 @@ -#include <unistd.h> -#include <string.h> #include <getopt.h> +#include <string.h> +#include <unistd.h> -#include <iostream> -#include <iomanip> #include <chrono> -#include <thread> -#include <nlohmann/json.hpp> #include <fstream> - -#include "Logger.h" +#include <iomanip> +#include <iostream> +#include <nlohmann/json.hpp> +#include <thread> #include "AMACv2.h" - -#include "PBv3TBConf.h" +#include "Logger.h" #include "PBv3ConfigTools.h" +#include "PBv3TBConf.h" //------ SETTINGS std::string equipConfigFile = "config/equip_testbench.json"; //--------------- -void usage(char* argv[]) -{ - std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; - std::cerr << "" << std::endl; - std::cerr << "List of options:" << std::endl; - std::cerr << " -e, --equip config.json Equipment configuration file (default: " << equipConfigFile << ")" << std::endl; - std::cerr << " -d, --debug Enable more verbose printout" << std::endl; - std::cerr << std::endl; - std::cerr << std::endl; +void usage(char* argv[]) { + std::cerr << "Usage: " << argv[0] << " [options]" << std::endl; + std::cerr << "" << std::endl; + std::cerr << "List of options:" << std::endl; + std::cerr + << " -e, --equip config.json Equipment configuration file (default: " + << equipConfigFile << ")" << std::endl; + std::cerr << " -d, --debug Enable more verbose printout" + << std::endl; + std::cerr << std::endl; + std::cerr << std::endl; } -int main(int argc, char* argv[]) -{ - int c; - while (1) - { - int option_index = 0; - static struct option long_options[] = - { - {"equip" , required_argument, 0, 'e' }, - {"debug" , no_argument , 0, 'd' }, - {0 , 0 , 0, 0 } - }; +int main(int argc, char* argv[]) { + int c; + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"equip", required_argument, 0, 'e'}, + {"debug", no_argument, 0, 'd'}, + {0, 0, 0, 0}}; - c = getopt_long(argc, argv, "e:d", long_options, &option_index); - if (c == -1) - break; + c = getopt_long(argc, argv, "e:d", long_options, &option_index); + if (c == -1) break; - switch (c) - { - case 'e': - equipConfigFile = optarg; - break; - case 'd': - logIt::incrDebug(); - break; - default: - std::cerr << "Invalid option supplied. Aborting." << std::endl; - std::cerr << std::endl; - usage(argv); - } + switch (c) { + case 'e': + equipConfigFile = optarg; + break; + case 'd': + logIt::incrDebug(); + break; + default: + std::cerr << "Invalid option supplied. Aborting." << std::endl; + std::cerr << std::endl; + usage(argv); + } } - // Create and initialize the testbench - PBv3TBConf factory_pbv3tb(equipConfigFile); - std::shared_ptr<PBv3TB> tb=factory_pbv3tb.getPBv3TB("default"); - if(tb==nullptr) - return 1; + // Create and initialize the testbench + PBv3TBConf factory_pbv3tb(equipConfigFile); + std::shared_ptr<PBv3TB> tb = factory_pbv3tb.getPBv3TB("default"); + if (tb == nullptr) return 1; - std::cout << "-- linPOL output --" << std::endl; - for(uint32_t i=0; i<10; i++) - { - std::cout << i << " : "; - std::cout << tb->readCarrierOutput(i, PBv3TB::CARRIER_OUTPUT::LINPOL1V4); - std::cout << std::endl; + std::cout << "-- linPOL output --" << std::endl; + for (uint32_t i = 0; i < 10; i++) { + std::cout << i << " : "; + std::cout << tb->readCarrierOutput(i, + PBv3TB::CARRIER_OUTPUT::LINPOL1V4); + std::cout << std::endl; } - std::cout << "-- Run OFin --" << std::endl; - for(uint32_t i=0; i<10; i++) - { - tb->setOFin(i, true); + std::cout << "-- Run OFin --" << std::endl; + for (uint32_t i = 0; i < 10; i++) { + tb->setOFin(i, true); } - std::cout << "-- linPOL output --" << std::endl; - for(uint32_t i=0; i<10; i++) - { - std::cout << i << " : "; - std::cout << tb->readCarrierOutput(i, PBv3TB::CARRIER_OUTPUT::LINPOL1V4); - std::cout << std::endl; + std::cout << "-- linPOL output --" << std::endl; + for (uint32_t i = 0; i < 10; i++) { + std::cout << i << " : "; + std::cout << tb->readCarrierOutput(i, + PBv3TB::CARRIER_OUTPUT::LINPOL1V4); + std::cout << std::endl; } - return 0; + return 0; }