pflib v3.9.4-12-gf8bd325
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/lpgbt/GPIO.h"
11
12namespace pflib {
13
18 public:
19 virtual ~lpGBT_ConfigTransport() {}
22 virtual uint8_t read_reg(uint16_t reg) = 0;
25 virtual void write_reg(uint16_t reg, uint8_t value) = 0;
31 virtual std::vector<uint8_t> read_regs(uint16_t reg, int n);
37 virtual void write_regs(uint16_t reg, const std::vector<uint8_t>& value);
38};
39
53class lpGBT {
54 public:
55 lpGBT(lpGBT_ConfigTransport& transport);
56
57 void write(uint16_t reg, uint8_t value) { tport_.write_reg(reg, value); }
58 uint8_t read(uint16_t reg) { return tport_.read_reg(reg); }
59 std::vector<uint8_t> read(uint16_t reg, int len) {
60 return tport_.read_regs(reg, len);
61 }
62
66 void write(const RegisterValueVector& regvalues);
67
69 RegisterValueVector read(const std::vector<uint16_t>& registers);
70
71 void bit_set(uint16_t reg, int ibit);
72 void bit_clr(uint16_t reg, int ibit);
73
74 /* -------------------------------------------------------
75 Medium-level interfaces
76 */
77
79 uint32_t serial_number();
80
82 int status();
83 std::string status_name(int pusm);
84
86 void gpio_set(int ibit, bool high);
88 bool gpio_get(int ibit);
90 void gpio_set(uint16_t values);
92 uint16_t gpio_get();
93
94 static const int GPIO_IS_OUTPUT = 0x01;
95 static const int GPIO_IS_PULLUP = 0x02;
96 static const int GPIO_IS_PULLDOWN = 0x04;
97 static const int GPIO_IS_STRONG = 0x08;
98
100 int gpio_cfg_get(int ibit);
102 void gpio_cfg_set(int ibit, int cfg, const std::string& name = "");
104 GPIO& gpio_interface() { return gpio_; }
105
110 uint16_t adc_read(int ipos, int ineg, int gain = 1);
111
116 uint16_t adc_resistance_read(int ipos, int current, int gain = 1);
117
120 double adc_average();
121
124 int find_vref_tune(double vref_slope, double vref_offset,
125 double temp_uncal_slope, double temp_uncal_offset);
126
127 static constexpr double AVG_ADC_X2_OFFSET = -3.29456020e-02;
128 static constexpr double AVG_ADC_X2_OFFSET_TEMP = 1.33582562e-06;
129 static constexpr double AVG_ADC_X2_SLOPE = 1.04131896e-03;
130 static constexpr double AVG_ADC_X2_SLOPE_TEMP = -2.57597742e-09;
131 static constexpr double AVG_TEMPERATURE_OFFSET = -1.84069912e+02;
132 static constexpr double AVG_TEMPERATURE_SLOPE = 4.10623053e+02;
133 static constexpr double AVG_TEMPERATURE_UNCALVREF_OFFSET = -2.10640722e+02;
134 static constexpr double AVG_TEMPERATURE_UNCALVREF_SLOPE = 4.56134956e-01;
135 static constexpr double AVG_VREF_OFFSET = 1.34761703e+02;
136 static constexpr double AVG_VREF_SLOPE = -3.35998109e-01;
137
142
146 void read_internal_temp_precise(YAML::Node cal_data);
147
154 void setup_eclk(int ieclk, int rate, bool polarity = true, int strength = 4);
155
168 void setup_erx(int ierx, int align, int alignphase = 0, int speed = 3,
169 bool invert = false, bool term = true, int equalization = 0,
170 bool acbias = false);
171
181 void check_prbs_errors_erx(int group, int channel, bool lpgbt_only = false,
182 int data_rate_code = 3,
183 uint8_t bert_time_code = 4);
184
192 void setup_etx(int ietx, bool enable, bool invert = false, int drive = 4,
193 int pe_mode = 0, int pe_strength = 0, int pe_width = 0);
194
205 void setup_ec(bool invert_tx = false, int drive = 4, bool fixed = false,
206 int alignphase = 0, bool invert_rx = false, bool term = true,
207 bool acbias = false, bool pullup = false);
208
209 uint32_t read_efuse(uint16_t addr);
210
220 void setup_i2c(int ibus, int speed_khz, bool scl_drive = false,
221 bool strong_scl = true, bool strong_sda = true,
222 bool pull_up_scl = false, bool pull_up_sda = false);
223
225 void start_i2c_read(int ibus, uint8_t i2c_addr, int len = 1);
226
228 void i2c_write(int ibus, uint8_t i2c_addr, uint8_t value);
229
231 void i2c_write(int ibus, uint8_t i2c_addr,
232 const std::vector<uint8_t>& values);
233
236 bool i2c_transaction_check(int ibus, bool wait = false);
237
240
242 void finalize_setup();
243
244 private:
245 lpGBT_ConfigTransport& tport_;
246 struct I2C {
247 uint8_t ctl_reg;
248 uint8_t read_len;
249 } i2c_[3];
251};
252
253} // namespace pflib
254
255#endif // PFLIB_lpGBT_H_INCLUDED
Representation of GPIO controller.
Definition GPIO.h:12
Definition lpGBT.h:17
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:15
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:10
Class which provides an interface with an lpGBT ASIC as mounted on an LDMX mezzanine.
Definition lpGBT.h:53
uint32_t serial_number()
Get the serial number (somewhat complex)
Definition lpGBT.cxx:173
void setup_eclk(int ieclk, int rate, bool polarity=true, int strength=4)
Setup the given eclk.
Definition lpGBT.cxx:634
void i2c_write(int ibus, uint8_t i2c_addr, uint8_t value)
Start an I2C write of a single byte.
Definition lpGBT.cxx:714
int status()
Get the lpGBT status (power up state machine)
Definition lpGBT.cxx:785
std::vector< uint8_t > i2c_read_data(int ibus)
Get back the data from the read.
Definition lpGBT.cxx:768
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:582
uint16_t gpio_get()
Get the full GPIO array.
Definition lpGBT.cxx:233
void read_internal_temp_avg()
Calculate the internal temperature of the lpGBT using averaged calibration constants.
Definition lpGBT.cxx:387
int gpio_cfg_get(int ibit)
Get the GPIO pin configuration.
Definition lpGBT.cxx:240
void read_internal_temp_precise(YAML::Node cal_data)
Calculate the internal temperature of the lpGBT using precise calibration constants.
Definition lpGBT.cxx:407
bool i2c_transaction_check(int ibus, bool wait=false)
Check for transaction completion optionally waiting for completion, throws exception on failure.
Definition lpGBT.cxx:742
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:373
void check_prbs_errors_erx(int group, int channel, bool lpgbt_only=false, int data_rate_code=3, uint8_t bert_time_code=4)
Check for PRBS errors on given eRx group and channel.
Definition lpGBT.cxx:458
void gpio_cfg_set(int ibit, int cfg, const std::string &name="")
Set the GPIO pin configuration.
Definition lpGBT.cxx:262
void finalize_setup()
finalize the configuration
Definition lpGBT.cxx:783
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:311
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:292
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:444
void gpio_set(int ibit, bool high)
Set the given gpio bit.
Definition lpGBT.cxx:200
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:669
void start_i2c_read(int ibus, uint8_t i2c_addr, int len=1)
Start an I2C read.
Definition lpGBT.cxx:698
GPIO & gpio_interface()
Get the pflib GPIO object.
Definition lpGBT.h:104
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:620
double adc_average()
Get an average ADC read using the adc_read function.
Definition lpGBT.cxx:354
Definition GPIO.h:14
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:246