Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 46 additions & 32 deletions plugins/DaphneV2ControllerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*/

#include "DaphneV2ControllerModule.hpp"
#include "appmodel/DaphneMapEntry.hpp"
#include "appmodel/DaphneV2BoardConf.hpp"
#include "appmodel/DaphneV2Channel.hpp"
#include "appmodel/DaphneV2AFE.hpp"
#include "appmodel/DaphneV2ADC.hpp"
#include "appmodel/DaphneV2LNA.hpp"
#include "appmodel/DaphneV2PGA.hpp"
#include "appmodel/DaphneConf.hpp"
#include "appmodel/DeferredConfig.hpp"
#include "appmodel/appmodelIssues.hpp"

#include "fddetdataformats/DAPHNEFrame.hpp"

Expand Down Expand Up @@ -57,6 +59,7 @@ DaphneV2ControllerModule::init(std::shared_ptr<appfwk::ConfigurationManager> cfg
throw ConfigurationFailed(ERS_HERE, get_name());
}
m_module_config = mdal;
m_config_manager = cfgMgr;
}


Expand Down Expand Up @@ -250,19 +253,36 @@ DaphneV2ControllerModule::do_conf(const CommandData_t&)
{
auto start_time = std::chrono::high_resolution_clock::now();

auto board_conf = m_module_config->get_board_conf();
auto slot = board_conf->get_slot_id();
auto daphne_conf = m_module_config->get_daphne_conf();
m_config_manager->load_deferred_db(daphne_conf->get_configuration_file());

auto m_daphne_board = m_config_manager->get_dal<appmodel::DaphneBoard>(daphne_conf->get_entry_uid());
if (m_daphne_board == nullptr) {
throw(appmodel::BadConf(ERS_HERE, "DaphneBoard not found"));
}
auto daphne_map = m_daphne_board->get_boards();
for (auto entry: daphne_map) {
if (entry->get_key() == m_module_config->get_daphne_id()) {
m_board_conf = entry->get_conf();
break;
}
}
if (m_board_conf == nullptr) {
throw(appmodel::BadConf(ERS_HERE, "DaphneBoard map does not contain an entry with our id"));
}

auto slot = m_board_conf->get_slot_id();
if ( slot >= 16 )
// // the slot used laster in the code is a 4 bit register, so we need to check we are not overflowing
throw InvalidSlot(ERS_HERE, slot, board_conf->get_address());
throw InvalidSlot(ERS_HERE, slot, m_board_conf->get_address());

// during configuration no other operations are allowed
const std::lock_guard<std::mutex> lock(m_mutex);

create_interface(board_conf->get_address(),
m_module_config->get_daphne_conf()->get_timeout());
create_interface(m_board_conf->get_address(),
m_board_conf->timeout());

validate_configuration( * m_module_config->get_board_conf() );
validate_configuration(*m_board_conf);

disable_links();

Expand Down Expand Up @@ -348,8 +368,7 @@ DaphneV2ControllerModule::create_interface(const std::string & ip, std::chrono::
throw InvalidIPAddress(ERS_HERE, ip);
}

auto board = m_module_config->get_board_conf();
TLOG() << get_name() << ": using daphne at " << ip << " with slot " << (int)board->get_slot_id(); // NOLINT(readability/casting)
TLOG() << get_name() << ": using daphne at " << ip << " with slot " << (int)m_board_conf->get_slot_id(); // NOLINT(readability/casting)

m_interface = std::make_unique<DaphneV2Interface>( ip.c_str(), 2001, timeout );

Expand Down Expand Up @@ -395,19 +414,18 @@ DaphneV2ControllerModule::configure_timing_endpoints() {
// bits 11..6 = detector_id(5..0), default is "000010"
// bits 5..0 = version_id(5..0), default is "000010"

auto board = m_module_config->get_board_conf();
std::bitset<26> config_value(board->get_slot_id());
std::bitset<26> config_value(m_board_conf->get_slot_id());
config_value <<= 10;
config_value |= board -> get_crate_id();
config_value |= m_board_conf -> get_crate_id();
config_value <<= 6;
config_value |= board -> get_detector_id();
config_value |= m_board_conf -> get_detector_id();
config_value <<= 6;
config_value |= std::bitset<6>(fddetdataformats::DAPHNEFrame::version).to_ulong();

TLOG() << get_name() << ": configuring timing endpoint with value " << config_value.to_string();
m_interface->write_register(0x4001, {0x1});
m_interface->write_register(0x3000, {config_value.to_ulong()});
if ( m_module_config->get_daphne_conf()->get_time_reset() ) {
if ( m_board_conf->get_time_reset() ) {
m_interface->write_register(0x4003, {1234});
}

Expand All @@ -423,7 +441,7 @@ DaphneV2ControllerModule::configure_timing_endpoints() {
} while (!check[0]);

if ( ! check[0] ) {
throw PLLNotLocked(ERS_HERE, board->get_slot_id(), "MMCM0");
throw PLLNotLocked(ERS_HERE, m_board_conf->get_slot_id(), "MMCM0");
}

m_interface->write_buffer(0x4002, {1234});
Expand All @@ -439,7 +457,7 @@ DaphneV2ControllerModule::configure_timing_endpoints() {
} while (!check[1]);

if ( ! check[1] ) {
throw PLLNotLocked(ERS_HERE, board->get_slot_id(), "MMCM1");
throw PLLNotLocked(ERS_HERE, m_board_conf->get_slot_id(), "MMCM1");
}

// at this point everything that is in register 0x4000 is the status of the timing endpoint
Expand All @@ -461,7 +479,7 @@ DaphneV2ControllerModule::configure_timing_endpoints() {
} while (!check[12]);

if ( ! check[12] ) {
throw TimingEndpointNotReady(ERS_HERE, board->get_slot_id(), check.to_string() );
throw TimingEndpointNotReady(ERS_HERE, m_board_conf->get_slot_id(), check.to_string() );
}

TLOG() << get_name() << ": done donfiguring timing endpoint";
Expand All @@ -477,8 +495,8 @@ void DaphneV2ControllerModule::configure_analog_chain(bool initial_config) {
TLOG() << get_name() << ": " << result.command << " -> " << result.result;
}

auto board_conf = initial_config ? m_module_config->get_board_conf() :
m_module_config->get_daphne_conf()->get_default_v2_settings();
auto board_conf = initial_config ? m_board_conf :
m_board->get_default_v2_settings();

auto result = m_interface->send_command(fmt::format("WR VBIASCTRL V {}", board_conf->get_bias_ctrl()));
TLOG() << get_name() << ": " << result.command << " -> " << result.result;
Expand Down Expand Up @@ -572,14 +590,13 @@ void DaphneV2ControllerModule::align_DDR() {
// this trigger the spy buffers

// read register ch 8 of each afe, by looping on all the afe we use
auto board_conf = m_module_config->get_board_conf();
for ( size_t afe = 0; afe < s_max_afes ; ++afe ) {
if ( board_conf -> is_afe_used(afe) ) {
if ( m_board_conf -> is_afe_used(afe) ) {
auto data = m_interface->read_register(0x40000000 + (afe * 0x100000) + (8 * 0x10000), 15); // ch = 8

// things are ok when the data is 0x3f80
if ( data[0] != DaphneV2ControllerModule::s_frame_alignment_good )
throw DDRNotAligned(ERS_HERE, board_conf->get_slot_id(), afe, data[0] );
throw DDRNotAligned(ERS_HERE, m_board_conf->get_slot_id(), afe, data[0] );
} //afe used
}

Expand All @@ -599,25 +616,22 @@ DaphneV2ControllerModule::configure_trigger_mode() {

TLOG() << get_name() << ": Setting trigger mode";

auto c = m_module_config->get_board_conf();

m_interface->write_register(0x6100, {c->get_self_trigger_xcorr()});
m_interface->write_register(0x6002, {c->get_tp_conf()});
m_interface->write_register(0x6003, {c->get_compensator()});
m_interface->write_register(0x6004, {c->get_inverter()});
m_interface->write_register(0x6100, {m_board_conf->get_self_trigger_xcorr()});
m_interface->write_register(0x6002, {m_board_conf->get_tp_conf()});
m_interface->write_register(0x6003, {m_board_conf->get_compensator()});
m_interface->write_register(0x6004, {m_board_conf->get_inverter()});

auto threshold = c->get_self_trigger_threshold();
auto threshold = m_board_conf->get_self_trigger_threshold();

if ( threshold > 0 ) {
// se are in self trigger mode
m_interface->write_register(0x3001, {0x3}); // only link0 is enabled
m_interface->write_register(0x6000, {threshold});

std::bitset<DaphneV2ControllerModule::s_max_channels> mask;
auto board_conf = m_module_config->get_board_conf();
// we unmask all the channels that are enabled
for ( ChannelId ch = 0; ch < s_max_channels; ++ch ) {
if ( board_conf->is_channel_used(ch) )
if ( m_board_conf->is_channel_used(ch) )
mask[ch] = true;
}
m_interface->write_register(0x6001, {(uint64_t)mask.to_ulong()}); // NOLINT
Expand All @@ -631,7 +645,7 @@ DaphneV2ControllerModule::configure_trigger_mode() {
m_interface->write_register(0x6000, {0}); // for safety we mask everything

size_t stream_id = 0;
auto full_stream_channels = c->get_full_stream_channels();
auto full_stream_channels = m_board_conf->get_full_stream_channels();
for ( const auto & ch : full_stream_channels ) {

// The channles are not identified with an id from 0-39, they have a different identifier to represent the
Expand Down
8 changes: 6 additions & 2 deletions plugins/DaphneV2ControllerModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

#include "daphnemodules/opmon/DaphneControllerModule.pb.h"

#include <appmodel/DaphneV2BoardConf.hpp>
#include <appmodel/DaphneV2ControllerModule.hpp>
#include "appmodel/DaphneBoard.hpp"
#include "appmodel/DaphneV2BoardConf.hpp"
#include "appmodel/DaphneV2ControllerModule.hpp"

#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.

Expand Down Expand Up @@ -165,6 +166,7 @@ class DaphneV2ControllerModule : public dunedaq::appfwk::DAQModule
static const ChannelId s_max_afes = 5;
using conf_t = appmodel::DaphneV2ControllerModule;
const conf_t* m_module_config = nullptr;
std::shared_ptr<appfwk::ConfigurationManager> m_config_manager;

static const uint16_t s_frame_alignment_good = 0x3f80;

Expand All @@ -183,6 +185,8 @@ class DaphneV2ControllerModule : public dunedaq::appfwk::DAQModule
std::atomic<counter_t> m_last_package_counter = 0;
std::atomic<counter_t> m_last_unsent_counter = 0;

const appmodel::DaphneBoard* m_board{nullptr};
const appmodel::DaphneV2BoardConf* m_board_conf{nullptr};
};

} // namespace dunedaq::daphnemodules
Expand Down
40 changes: 29 additions & 11 deletions plugins/DaphneV3ControllerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
#include "daphnemodules/daphne_control_high.pb.h"
#include "daphnemodules/daphne_control_low.pb.h"

#include "appmodel/DaphneConf.hpp"
#include "appmodel/DaphneBoard.hpp"
#include "appmodel/DaphneMapEntry.hpp"
#include "appmodel/DaphneV2BoardConf.hpp"
#include "appmodel/DaphneV2Channel.hpp"
#include "appmodel/DaphneV2AFE.hpp"
#include "appmodel/DaphneV2ADC.hpp"
#include "appmodel/DaphneV2PGA.hpp"
#include "appmodel/DaphneV2LNA.hpp"
#include "appmodel/DeferredConfig.hpp"
#include "appmodel/appmodelIssues.hpp"

#include "daphnemodules/opmon/DaphneControllerModule.pb.h"

Expand Down Expand Up @@ -48,6 +51,7 @@ namespace dunedaq::daphnemodules {
throw ConfigurationFailed(ERS_HERE, get_name());
}
m_module_config = mdal;
m_config_manager = cfg;
}


Expand All @@ -59,18 +63,33 @@ namespace dunedaq::daphnemodules {
TLOG() << get_name() << " starting configuring";
auto start_time = std::chrono::high_resolution_clock::now();

auto daphne_conf = m_module_config->get_daphne_conf();
m_config_manager->load_deferred_db(daphne_conf->get_configuration_file());

auto m_daphne_board = m_config_manager->get_dal<appmodel::DaphneBoard>(daphne_conf->get_entry_uid());
if (m_daphne_board == nullptr) {
throw(appmodel::BadConf(ERS_HERE, "DaphneBoard not found"));
}
auto daphne_map = m_daphne_board->get_boards();
for (auto entry: daphne_map) {
if (entry->get_key() == m_module_config->get_daphne_id()) {
m_board_conf = entry->get_conf();
break;
}
}
if (m_board_conf == nullptr) {
throw(appmodel::BadConf(ERS_HERE, "DaphneBoard map does not contain an entry with our id"));
}


using namespace daphne;

auto board_conf = m_module_config->get_board_conf();
auto general_conf = m_module_config->get_daphne_conf();

create_interface( board_conf->get_address(),
general_conf->get_timeout() );
create_interface( m_board_conf->get_address(),
m_board_conf->timeout() );

// validation to be taken from the previous version
// this should include the slot check
validate_configuration(*board_conf);
validate_configuration(*m_board_conf);

configure_analog_chain(true);

Expand Down Expand Up @@ -103,15 +122,14 @@ namespace dunedaq::daphnemodules {

void DaphneV3ControllerModule::configure_analog_chain(bool initial_config) {

auto general_conf = m_module_config->get_daphne_conf();
auto board_conf = initial_config ? m_module_config->get_board_conf() :
general_conf->get_default_v3_settings();
auto board_conf = initial_config ? m_board_conf :
m_board->get_default_v3_settings();

// Step 1: Build the ConfigureRequest
daphne::ConfigureRequest req;
req.set_daphne_address(board_conf->get_address());
req.set_slot(board_conf->get_slot_id());
req.set_timeout_ms(general_conf->get_timeout_ms());
req.set_timeout_ms(board_conf->get_timeout_ms());
req.set_biasctrl(board_conf->get_bias_ctrl());
req.set_self_trigger_threshold(board_conf->get_self_trigger_threshold());
req.set_self_trigger_xcorr(board_conf->get_self_trigger_xcorr());
Expand Down
6 changes: 6 additions & 0 deletions plugins/DaphneV3ControllerModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "daphnemodules/CommonIssues.hpp"
#include "daphnemodules/daphne_control_high.pb.h"
#include "appmodel/DaphneV3ControllerModule.hpp"
#include "appmodel/DaphneBoard.hpp"
#include "appmodel/DaphneV2BoardConf.hpp"

#include <string>
Expand Down Expand Up @@ -42,6 +43,11 @@ namespace dunedaq::daphnemodules{

using conf_t = appmodel::DaphneV3ControllerModule;
const conf_t* m_module_config = nullptr;
std::shared_ptr<appfwk::ConfigurationManager> m_config_manager;

const appmodel::DaphneBoard* m_board{nullptr};
const appmodel::DaphneV2BoardConf* m_board_conf{nullptr};

void validate_configuration(const appmodel::DaphneV2BoardConf &) const;

void configure_analog_chain(bool intial_config);
Expand Down
9 changes: 5 additions & 4 deletions python/daphnemodules/add_daphne_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def add_daphne_conf(oksfile:str, object_name:str, json_file:str, timeout_ms:int
bias_ctrl=0,
self_trigger_threshold=0,
default_channel=def_channel,
default_afe=def_afe )
default_afe=def_afe,
timeout_ms=timeout_ms )
db.update_dal(def_board)

maps=[]
Expand Down Expand Up @@ -154,7 +155,8 @@ def add_daphne_conf(oksfile:str, object_name:str, json_file:str, timeout_ms:int
crate_id=crate,
slot_id=slot,
default_channel=def_channel,
default_afe=def_afe )
default_afe=def_afe,
timeout_ms=timeout_ms )
db.update_dal(board)

link=dal.DaphneMapEntry(name,
Expand All @@ -168,8 +170,7 @@ def add_daphne_conf(oksfile:str, object_name:str, json_file:str, timeout_ms:int
## create default objects, they will override old configurations


new_conf = dal.DaphneConf(object_name,
timeout_ms=timeout_ms,
new_conf = dal.DaphneBoard(object_name,
boards=maps,
default_v2_settings=def_board,
default_v3_settings=def_board )
Expand Down
Loading