1#ifndef PFLIB_lpGBT_H_INCLUDED
2#define PFLIB_lpGBT_H_INCLUDED
5#include <yaml-cpp/yaml.h>
9#include "pflib/Exception.h"
10#include "pflib/logging/Logging.h"
11#include "pflib/lpgbt/GPIO.h"
26 virtual void write_reg(uint16_t reg, uint8_t value) = 0;
58 void write(uint16_t reg, uint8_t value) { tport_.
write_reg(reg, value); }
59 uint8_t read(uint16_t reg) {
return tport_.
read_reg(reg); }
72 void bit_set(uint16_t reg,
int ibit);
73 void bit_clr(uint16_t reg,
int ibit);
95 static const int GPIO_IS_OUTPUT = 0x01;
96 static const int GPIO_IS_PULLUP = 0x02;
97 static const int GPIO_IS_PULLDOWN = 0x04;
98 static const int GPIO_IS_STRONG = 0x08;
111 uint16_t
adc_read(
int ipos,
int ineg,
int gain = 1);
126 double temp_uncal_slope,
double temp_uncal_offset);
128 static constexpr double AVG_ADC_X2_OFFSET = -3.29456020e-02;
129 static constexpr double AVG_ADC_X2_OFFSET_TEMP = 1.33582562e-06;
130 static constexpr double AVG_ADC_X2_SLOPE = 1.04131896e-03;
131 static constexpr double AVG_ADC_X2_SLOPE_TEMP = -2.57597742e-09;
132 static constexpr double AVG_TEMPERATURE_OFFSET = -1.84069912e+02;
133 static constexpr double AVG_TEMPERATURE_SLOPE = 4.10623053e+02;
134 static constexpr double AVG_TEMPERATURE_UNCALVREF_OFFSET = -2.10640722e+02;
135 static constexpr double AVG_TEMPERATURE_UNCALVREF_SLOPE = 4.56134956e-01;
136 static constexpr double AVG_VREF_OFFSET = 1.34761703e+02;
137 static constexpr double AVG_VREF_SLOPE = -3.35998109e-01;
155 void setup_eclk(
int ieclk,
int rate,
bool polarity =
true,
int strength = 4);
170 bool short_pre_emphasis,
int pre_emphasis_amplitude);
187 void setup_erx(
int ierx,
int align,
int alignphase = 0,
int speed = 3,
188 bool invert =
false,
bool term =
true,
int equalization = 0,
189 bool acbias =
false);
205 bool lpgbt_only =
false,
int data_rate_code = 3,
206 uint8_t bert_time_code = 4);
215 void setup_etx(
int ietx,
bool enable,
bool invert =
false,
int drive = 4,
216 int pe_mode = 0,
int pe_strength = 0,
int pe_width = 0);
228 void setup_ec(
bool invert_tx =
false,
int drive = 4,
bool fixed =
false,
229 int alignphase = 0,
bool invert_rx =
false,
bool term =
true,
230 bool acbias =
false,
bool pullup =
false);
232 uint32_t read_efuse(uint16_t addr);
247 void setup_i2c(
int ibus,
int speed_khz,
bool scl_drive =
false,
248 bool strong_scl =
true,
bool strong_sda =
true,
249 bool pull_up_scl =
false,
bool pull_up_sda =
false);
269 void i2c_write(
int ibus, uint8_t i2c_addr, uint8_t value);
272 void i2c_write(
int ibus, uint8_t i2c_addr,
Representation of GPIO controller.
Definition GPIO.h:12
virtual void write_regs(uint16_t reg, const std::vector< uint8_t > &value)
Write the given values to a sequence of registers beginning with the listed one.
Definition lpGBT.cxx:18
virtual uint8_t read_reg(uint16_t reg)=0
Read the contents of the identified single register.
virtual void write_reg(uint16_t reg, uint8_t value)=0
Write the given value to the identified single register.
virtual std::vector< uint8_t > read_regs(uint16_t reg, int n)
Read the contents of several registers beginning with the listed one.
Definition lpGBT.cxx:13
Class which provides an interface with an lpGBT ASIC as mounted on an LDMX mezzanine.
Definition lpGBT.h:54
uint32_t serial_number()
Get the serial number (somewhat complex)
Definition lpGBT.cxx:176
void setup_eclk(int ieclk, int rate, bool polarity=true, int strength=4)
Setup the given eclk.
Definition lpGBT.cxx:732
void i2c_write(int ibus, uint8_t i2c_addr, uint8_t value)
Start an I2C write of a single byte.
Definition lpGBT.cxx:858
int status()
Get the lpGBT status (power up state machine)
Definition lpGBT.cxx:929
std::vector< uint8_t > i2c_read_data(int ibus)
Get back the data from the read.
Definition lpGBT.cxx:912
void setup_etx(int ietx, bool enable, bool invert=false, int drive=4, int pe_mode=0, int pe_strength=0, int pe_width=0)
Setup the given elink-tx.
Definition lpGBT.cxx:680
uint16_t gpio_get()
Get the full GPIO array.
Definition lpGBT.cxx:236
void read_internal_temp_avg()
Calculate the internal temperature of the lpGBT using averaged calibration constants.
Definition lpGBT.cxx:390
int gpio_cfg_get(int ibit)
Get the GPIO pin configuration.
Definition lpGBT.cxx:243
void check_prbs_errors_erx(int ierx, bool check_all_phases=false, bool lpgbt_only=false, int data_rate_code=3, uint8_t bert_time_code=4)
Check for PRBS errors on given eRx.
Definition lpGBT.cxx:464
void read_internal_temp_precise(YAML::Node cal_data)
Calculate the internal temperature of the lpGBT using precise calibration constants.
Definition lpGBT.cxx:410
bool i2c_transaction_check(int ibus, bool wait=false)
Check for transaction completion optionally waiting for completion, throws exception on failure.
Definition lpGBT.cxx:886
int find_vref_tune(double vref_slope, double vref_offset, double temp_uncal_slope, double temp_uncal_offset)
Find a good vref_tune for temperature measurement.
Definition lpGBT.cxx:376
void setup_i2c_speed(int ibus, int speed_khz)
Setup i2c bus speed.
Definition lpGBT.cxx:805
void gpio_cfg_set(int ibit, int cfg, const std::string &name="")
Set the GPIO pin configuration.
Definition lpGBT.cxx:265
void finalize_setup()
finalize the configuration
Definition lpGBT.cxx:927
uint16_t adc_read(int ipos, int ineg, int gain=1)
Carry out an ADC read for the given pair of channels Valid gain values are 1 or 2,...
Definition lpGBT.cxx:314
uint16_t adc_resistance_read(int ipos, int current, int gain=1)
Carry out an ADC read for the given channel, using the internal reference voltage for the other side ...
Definition lpGBT.cxx:295
void setup_i2c(int ibus, int speed_khz, bool scl_drive=false, bool strong_scl=true, bool strong_sda=true, bool pull_up_scl=false, bool pull_up_sda=false)
Setup an I2C bus.
Definition lpGBT.cxx:788
void setup_erx(int ierx, int align, int alignphase=0, int speed=3, bool invert=false, bool term=true, int equalization=0, bool acbias=false)
Setup the given elink-rx.
Definition lpGBT.cxx:447
void gpio_set(int ibit, bool high)
Set the given gpio bit.
Definition lpGBT.cxx:203
void start_i2c_read(int ibus, uint8_t i2c_addr, int len=1)
Start an I2C read.
Definition lpGBT.cxx:842
void setup_line_driver(int modulation_current, bool enable_pre_emphasis, bool short_pre_emphasis, int pre_emphasis_amplitude)
setup the line driver
Definition lpGBT.cxx:767
GPIO & gpio_interface()
Get the pflib GPIO object.
Definition lpGBT.h:105
void setup_ec(bool invert_tx=false, int drive=4, bool fixed=false, int alignphase=0, bool invert_rx=false, bool term=true, bool acbias=false, bool pullup=false)
Setup the EC port.
Definition lpGBT.cxx:718
int get_i2c_speed(int ibus)
Get the i2c bus speed.
Definition lpGBT.cxx:815
double adc_average()
Get an average ADC read using the adc_read function.
Definition lpGBT.cxx:357
boost::log::sources::severity_channel_logger_mt< level, std::string > logger
our logger type
Definition Logging.h:39
logger get(const std::string &name)
Gets a logger with the input name for its channel.
Definition Logging.cxx:24
This version of the fast control code interfaces with the CMS Fast control library which can be contr...
Definition Backend.cxx:3
void align(const std::string &cmd, Target *tgt)
TRIG.ALIGN commands.
Definition trig.cxx:144