8#ifndef SSPMODULES_SRC_SSPLEDCALIBWRAPPER_CPP_
9#define SSPMODULES_SRC_SSPLEDCALIBWRAPPER_CPP_
16#define TRACE_NAME "SSPLEDCalibWrapper"
59 ss <<
"Error: Incorrect timing address set (" <<
m_timing_address <<
")!" << std::endl;
61 throw ConfigurationError(
ERS_HERE, ss.str());
73 }
catch (
const std::exception& e) {
74 throw FailedLEDCalibrationInit(
ERS_HERE, e);
90 }
catch (
const std::exception& e) {
91 throw FailedLEDCalibrationConf(
ERS_HERE, e);
96 TLOG(
TLVL_FULL_DEBUG) <<
"SSPLEDCalibWrapper: I think that you want SSP LED Calib module to be in single pulse..."
100 TLOG(
TLVL_FULL_DEBUG) <<
"SSPLEDCalibWrapper: I think that you want SSP LED Calib module to be in BURST MODE..."
105 std::stringstream ss;
106 ss <<
"ERROR: SOMEHOW ENDED UP WITH SEVERAL PULSE MODES SET ON!!!!" << std::endl;
108 throw ConfigurationError(
ERS_HERE, ss.str());
115 TLOG(
TLVL_FULL_DEBUG) <<
"SSPLEDCalibWrapper: Configuring for single pulse mode..." << std::endl;
118 std::stringstream ss;
119 ss <<
"ERROR: SOMEHOW ENDED UP WITH NO PULSE MODES SET ON!!!!" << std::endl;
121 throw ConfigurationError(
ERS_HERE, ss.str());
139 <<
" is already pulsing...";
143 unsigned int base_bias_regAddress = 0x40000340;
144 unsigned int base_timing_regAddress = 0x800003C0;
147 base_bias_regAddress = 0x4000035C;
148 base_timing_regAddress = 0x800003DC;
153 std::stringstream ss;
154 ss <<
"ERROR: SOMEHOW ENDED UP WITHOUT NUMBER OF CHANNELS SET!!!!" << std::endl;
156 throw ConfigurationError(
ERS_HERE, ss.str());
163 unsigned int bias_regAddress = base_bias_regAddress + 0x4 * (counter);
164 unsigned int bias_regVal = 0x00040000;
165 unsigned int timing_regAddress = base_timing_regAddress + 0x4 * (counter);
166 unsigned int timing_regVal = 0x0;
169 timing_regVal = 0xF0000000;
171 timing_regVal = 0x90000000;
175 << (1 << counter) << std::endl;
176 if ((
m_channel_mask & ((
unsigned int)1 << counter)) == ((
unsigned int)1 << counter)) {
178 bias_regVal = bias_regVal + pulse_bias_setting_270nm;
180 bias_regVal = bias_regVal + pulse_bias_setting_367nm;
185 TLOG(
TLVL_FULL_DEBUG) <<
"Will turn on " << std::dec << counter <<
" channel at bias register 0x" << std::hex
186 << bias_regAddress <<
" with bias value 0x" << bias_regVal << std::endl;
187 TLOG(
TLVL_FULL_DEBUG) <<
" and set the width regsiter 0x" << std::hex << timing_regAddress <<
" to value of 0x"
188 << timing_regVal << std::dec << std::endl;
190 if ((counter == 7) && !((
m_channel_mask & ((
unsigned int)1 << counter)) == ((
unsigned int)1 << (counter - 1)))) {
200 TLOG(
TLVL_FULL_DEBUG) <<
"Will turn off channel " << std::dec << counter <<
" at timing register 0x" << std::hex
201 << timing_regAddress << std::dec << std::endl;
220 <<
" is already stopped, but stopping anyways...";
223 for (
unsigned int counter = 0; counter < 12; counter++) {
224 unsigned int bias_regAddress = 0x40000340 + 0x4 * (counter);
225 unsigned int timing_regAddress = 0x800003c0 + 0x4 * (counter);
298 TLOG(
TLVL_FULL_DEBUG) <<
"SSPLEDCalibWrapper: Processing the Hardware Configuration list..." << std::endl;
299 for (
auto regValuesIter : hw_conf) {
300 std::string m_name = regValuesIter->get_name();
301 unsigned int regAddr = regValuesIter->get_address();
302 unsigned int regVal = regValuesIter->get_value();
303 unsigned int regMask = regValuesIter->get_mask();
315 std::stringstream ss;
316 ss <<
"ERROR: Incorrect number_channels value " <<
m_number_channels <<
" is not equal to 5 or 12!!!" << std::endl;
318 throw ConfigurationError(
ERS_HERE, ss.str());
322 std::stringstream ss;
323 ss <<
"ERROR: Incorrect channel_maks value " <<
m_channel_mask <<
" is higher than the limit of 4095!!!"
326 throw ConfigurationError(
ERS_HERE, ss.str());
330 std::stringstream ss;
331 ss <<
"ERROR: Incorrect pulse_mode value. Neither single or burst." << std::endl;
333 throw ConfigurationError(
ERS_HERE, ss.str());
337 std::stringstream ss;
339 <<
", which is greater than the limit of 4095" << std::endl;
345 std::stringstream ss;
346 ss <<
"ERROR: Strange!! burst_count value is " <<
m_burst_count
347 <<
", which is more time than in a drift readout window" << std::endl;
353 std::stringstream ss;
355 <<
", which is greater than the limit of 255!!!" << std::endl;
357 throw ConfigurationError(
ERS_HERE, ss.str());
361 std::stringstream ss;
363 <<
", which is greater than the limit of 255!!!" << std::endl;
365 throw ConfigurationError(
ERS_HERE, ss.str());
369 std::stringstream ss;
371 <<
", which is greater than 100 percent!!!" << std::endl;
373 throw ConfigurationError(
ERS_HERE, ss.str());
377 std::stringstream ss;
379 <<
", which is greater than 100 percent!!!" << std::endl;
381 throw ConfigurationError(
ERS_HERE, ss.str());
uint32_t get_pulse2_width_ticks() const
Get "pulse2_width_ticks" attribute value. width of second pulse.
const std::string & get_pulse_mode() const
Get "pulse_mode" attribute value.
uint32_t get_pulse1_width_ticks() const
Get "pulse1_width_ticks" attribute value. Width of first pulse in time ticks.
uint32_t get_timing_address() const
Get "timing_address" attribute value. Timing address of the SSP board.
uint32_t get_channel_mask() const
Get "channel_mask" attribute value. Decimal number for the 12-bit channel mask where 1 is on,...
uint32_t get_number_channels() const
Get "number_channels" attribute value. Decimal number of the number of channels in the card,...
uint32_t get_partition_number() const
Get "partition_number" attribute value. FIXME: partition number for the SSP board.
uint32_t get_board_id() const
Get "board_id" attribute value. Board ID used for configuration and metric tracking.
uint32_t get_pulse_bias_percent_367nm() const
Get "pulse_bias_percent_367nm" attribute value. the fraction of bias applied to 367 nm LEDs.
uint32_t get_module_id() const
Get "module_id" attribute value. Module ID used for configuration and metric tracking.
uint32_t get_pulse_bias_percent_270nm() const
Get "pulse_bias_percent_270nm" attribute value. the fraction of bias applied to 270 nm LED.
uint32_t get_burst_count() const
Get "burst_count" attribute value. Number of LED calib pulses to send in a burst.
const std::vector< const dunedaq::appmodel::SSPRegister * > & get_hardware_configuration() const
Get "hardware_configuration" relationship value.
uint32_t get_double_pulse_delay_ticks() const
Get "double_pulse_delay_ticks" attribute value. number of ticks between first and second pulse in dou...
void SetRegisterByName(std::string name, unsigned int value)
void SetRegister(unsigned int address, unsigned int value, unsigned int mask=0xFFFFFFFF)
void SetTimingAddress(unsigned int val)
void SetPartitionNumber(unsigned int val)
void ConfigureLEDCalib(const appmodel::SSPLEDCalibModule *conf)
unsigned int m_burst_count
unsigned int m_partition_number
SSPLEDCalibWrapper()
SSPLEDCalibWrapper Constructor.
unsigned int m_timing_address
void configure_burst_mode()
unsigned int m_number_channels
void manual_configure_device(const std::vector< const appmodel::SSPRegister * > &hw_conf)
std::string m_instance_name_for_metrics
void stop(const data_t &args)
dunedaq::sspmodules::DeviceInterface * m_device_interface
unsigned int m_pulse1_width_ticks
void start(const data_t &args)
void init(const appmodel::SSPLEDCalibModule *mcfg)
std::atomic< bool > m_run_marker
void validate_config(const data_t &args)
void conf(const appmodel::SSPLEDCalibModule *mcfg)
unsigned long m_module_id
unsigned int m_pulse_bias_percent_270nm
unsigned int m_channel_mask
unsigned int m_pulse_bias_percent_367nm
void configure_single_pulse()
unsigned int m_pulse2_width_ticks
unsigned int m_double_pulse_delay_ticks
#define TLVL_ENTER_EXIT_METHODS
#define TLOG_DEBUG(lvl,...)