pflib v3.9.0-rc3-11-g2537d8f
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
6#include <vector>
7
8#include "pflib/Exception.h"
9#include "pflib/lpgbt/GPIO.h"
10
11namespace pflib {
12
17 public:
18 virtual ~lpGBT_ConfigTransport() {}
21 virtual uint8_t read_reg(uint16_t reg) = 0;
24 virtual void write_reg(uint16_t reg, uint8_t value) = 0;
30 virtual std::vector<uint8_t> read_regs(uint16_t reg, int n);
36 virtual void write_regs(uint16_t reg, const std::vector<uint8_t>& value);
37};
38
52class lpGBT {
53 public:
54 lpGBT(lpGBT_ConfigTransport& transport);
55
56 void write(uint16_t reg, uint8_t value) { tport_.write_reg(reg, value); }
57 uint8_t read(uint16_t reg) { return tport_.read_reg(reg); }
58 std::vector<uint8_t> read(uint16_t reg, int len) {
59 return tport_.read_regs(reg, len);
60 }
61
65 void write(const RegisterValueVector& regvalues);
66
68 RegisterValueVector read(const std::vector<uint16_t>& registers);
69
70 void bit_set(uint16_t reg, int ibit);
71 void bit_clr(uint16_t reg, int ibit);
72
73 /* -------------------------------------------------------
74 Medium-level interfaces
75 */
76
78 uint32_t serial_number();
79
81 int status();
82 std::string status_name(int pusm);
83
85 void gpio_set(int ibit, bool high);
87 bool gpio_get(int ibit);
89 void gpio_set(uint16_t values);
91 uint16_t gpio_get();
92
93 static const int GPIO_IS_OUTPUT = 0x01;
94 static const int GPIO_IS_PULLUP = 0x02;
95 static const int GPIO_IS_PULLDOWN = 0x04;
96 static const int GPIO_IS_STRONG = 0x08;
97
99 int gpio_cfg_get(int ibit);
101 void gpio_cfg_set(int ibit, int cfg, const std::string& name = "");
103 GPIO& gpio_interface() { return gpio_; }
104
109 uint16_t adc_read(int ipos, int ineg, int gain = 1);
110
115 uint16_t adc_resistance_read(int ipos, int current, int gain = 1);
116
123 void setup_eclk(int ieclk, int rate, bool polarity = true, int strength = 4);
124
137 void setup_erx(int ierx, int align, int alignphase = 0, int speed = 3,
138 bool invert = false, bool term = true, int equalization = 0,
139 bool acbias = false);
140
150 void check_prbs_errors_erx(int group, int channel, bool lpgbt_only = false,
151 int data_rate_code = 3,
152 uint8_t bert_time_code = 4);
153
161 void setup_etx(int ietx, bool enable, bool invert = false, int drive = 4,
162 int pe_mode = 0, int pe_strength = 0, int pe_width = 0);
163
174 void setup_ec(bool invert_tx = false, int drive = 4, bool fixed = false,
175 int alignphase = 0, bool invert_rx = false, bool term = true,
176 bool acbias = false, bool pullup = false);
177
178 uint32_t read_efuse(uint16_t addr);
179
189 void setup_i2c(int ibus, int speed_khz, bool scl_drive = false,
190 bool strong_scl = true, bool strong_sda = true,
191 bool pull_up_scl = false, bool pull_up_sda = false);
192
194 void start_i2c_read(int ibus, uint8_t i2c_addr, int len = 1);
195
197 void i2c_write(int ibus, uint8_t i2c_addr, uint8_t value);
198
200 void i2c_write(int ibus, uint8_t i2c_addr,
201 const std::vector<uint8_t>& values);
202
205 bool i2c_transaction_check(int ibus, bool wait = false);
206
209
211 void finalize_setup();
212
213 private:
214 lpGBT_ConfigTransport& tport_;
215 struct I2C {
216 uint8_t ctl_reg;
217 uint8_t read_len;
218 } i2c_[3];
220};
221
222} // namespace pflib
223
224#endif // PFLIB_lpGBT_H_INCLUDED
Representation of GPIO controller.
Definition GPIO.h:12
Definition lpGBT.h:16
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:52
uint32_t serial_number()
Get the serial number (somewhat complex)
Definition lpGBT.cxx:172
void setup_eclk(int ieclk, int rate, bool polarity=true, int strength=4)
Setup the given eclk.
Definition lpGBT.cxx:543
void i2c_write(int ibus, uint8_t i2c_addr, uint8_t value)
Start an I2C write of a single byte.
Definition lpGBT.cxx:623
int status()
Get the lpGBT status (power up state machine)
Definition lpGBT.cxx:694
std::vector< uint8_t > i2c_read_data(int ibus)
Get back the data from the read.
Definition lpGBT.cxx:677
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:491
uint16_t gpio_get()
Get the full GPIO array.
Definition lpGBT.cxx:232
int gpio_cfg_get(int ibit)
Get the GPIO pin configuration.
Definition lpGBT.cxx:239
bool i2c_transaction_check(int ibus, bool wait=false)
Check for transaction completion optionally waiting for completion, throws exception on failure.
Definition lpGBT.cxx:651
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:367
void gpio_cfg_set(int ibit, int cfg, const std::string &name="")
Set the GPIO pin configuration.
Definition lpGBT.cxx:261
void finalize_setup()
finalize the configuration
Definition lpGBT.cxx:692
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:310
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:291
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:353
void gpio_set(int ibit, bool high)
Set the given gpio bit.
Definition lpGBT.cxx:199
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:578
void start_i2c_read(int ibus, uint8_t i2c_addr, int len=1)
Start an I2C read.
Definition lpGBT.cxx:607
GPIO & gpio_interface()
Get the pflib GPIO object.
Definition lpGBT.h:103
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:529
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:215