pflib v3.12.0-1-g716e801
Pretty Fine HGCROC Interaction Library
Loading...
Searching...
No Matches
lpGBT.h
1#ifndef PFLIB_lpGBT_H_INCLUDED
2#define PFLIB_lpGBT_H_INCLUDED
3
4#include <stdint.h>
5#include <yaml-cpp/yaml.h>
6
7#include <vector>
8
9#include "pflib/Exception.h"
10#include "pflib/logging/Logging.h"
11#include "pflib/lpgbt/GPIO.h"
12
13namespace pflib {
14
19 public:
20 virtual ~lpGBT_ConfigTransport() {}
23 virtual uint8_t read_reg(uint16_t reg) = 0;
26 virtual void write_reg(uint16_t reg, uint8_t value) = 0;
32 virtual std::vector<uint8_t> read_regs(uint16_t reg, int n);
38 virtual void write_regs(uint16_t reg, const std::vector<uint8_t>& value);
39};
40
54class lpGBT {
55 public:
56 lpGBT(lpGBT_ConfigTransport& transport);
57
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); }
60 std::vector<uint8_t> read(uint16_t reg, int len) {
61 return tport_.read_regs(reg, len);
62 }
63
67 void write(const RegisterValueVector& regvalues);
68
70 RegisterValueVector read(const std::vector<uint16_t>& registers);
71
72 void bit_set(uint16_t reg, int ibit);
73 void bit_clr(uint16_t reg, int ibit);
74
75 /* -------------------------------------------------------
76 Medium-level interfaces
77 */
78
80 uint32_t serial_number();
81
83 int status();
84 std::string status_name(int pusm);
85
87 void gpio_set(int ibit, bool high);
89 bool gpio_get(int ibit);
91 void gpio_set(uint16_t values);
93 uint16_t gpio_get();
94
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;
99
101 int gpio_cfg_get(int ibit);
103 void gpio_cfg_set(int ibit, int cfg, const std::string& name = "");
105 GPIO& gpio_interface() { return gpio_; }
106
111 uint16_t adc_read(int ipos, int ineg, int gain = 1);
112
117 uint16_t adc_resistance_read(int ipos, int current, int gain = 1);
118
121 double adc_average();
122
125 int find_vref_tune(double vref_slope, double vref_offset,
126 double temp_uncal_slope, double temp_uncal_offset);
127
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;
138
143
147 void read_internal_temp_precise(YAML::Node cal_data);
148
155 void setup_eclk(int ieclk, int rate, bool polarity = true, int strength = 4);
156
169 void setup_line_driver(int modulation_current, bool enable_pre_emphasis,
170 bool short_pre_emphasis, int pre_emphasis_amplitude);
171
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);
190
204 void check_prbs_errors_erx(int ierx, bool check_all_phases = false,
205 bool lpgbt_only = false, int data_rate_code = 3,
206 uint8_t bert_time_code = 4);
207
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);
217
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);
231
232 uint32_t read_efuse(uint16_t addr);
233
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);
250
256 void setup_i2c_speed(int ibus, int speed_khz);
257
263 int get_i2c_speed(int ibus);
264
266 void start_i2c_read(int ibus, uint8_t i2c_addr, int len = 1);
267
269 void i2c_write(int ibus, uint8_t i2c_addr, uint8_t value);
270
272 void i2c_write(int ibus, uint8_t i2c_addr,
273 const std::vector<uint8_t>& values);
274
277 bool i2c_transaction_check(int ibus, bool wait = false);
278
281
283 void finalize_setup();
284
285 private:
286 lpGBT_ConfigTransport& tport_;
287 struct I2C {
288 uint8_t ctl_reg;
289 uint8_t read_len;
290 } i2c_[3];
292 mutable logging::logger the_log_{logging::get("lpGBT")};
293};
294
295} // namespace pflib
296
297#endif // PFLIB_lpGBT_H_INCLUDED
Representation of GPIO controller.
Definition GPIO.h:12
Definition lpGBT.h:18
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
Definition GPIO.h:14
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
Definition lpGBT.h:287
void align(const std::string &cmd, Target *tgt)
TRIG.ALIGN commands.
Definition trig.cxx:144