forked from psi46/psi46test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_dtb.h
374 lines (277 loc) · 12.5 KB
/
pixel_dtb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*---------------------------------------------------------------------
*
* filename: pixel_dtb.h
*
* description: PSI46 testboard API for DTB
* author: Beat Meier
* date: 15.7.2013
* rev:
*
*---------------------------------------------------------------------
*/
#pragma once
#include "profiler.h"
#include "rpc.h"
#include "config.h"
#ifdef _WIN32
#include "pipe.h"
#endif
#include "usb.h"
// size of ROC pixel array
#define ROC_NUMROWS 80 // # rows
#define ROC_NUMCOLS 52 // # columns
#define ROC_NUMDCOLS 26 // # double columns (= columns/2)
#define PIXMASK 0x80
// PUC register addresses for roc_SetDAC
#define Vdig 0x01
#define Vana 0x02
#define Vsh 0x03
#define Vcomp 0x04
#define Vleak_comp 0x05
#define VrgPr 0x06
#define VwllPr 0x07
#define VrgSh 0x08
#define VwllSh 0x09
#define VhldDel 0x0A
#define Vtrim 0x0B
#define VthrComp 0x0C
#define VIBias_Bus 0x0D
#define Vbias_sf 0x0E
#define VoffsetOp 0x0F
#define VIbiasOp 0x10
#define VoffsetRO 0x11
#define VIon 0x12
#define VIbias_PH 0x13
#define Ibias_DAC 0x14
#define VIbias_roc 0x15
#define VIColOr 0x16
#define Vnpix 0x17
#define VsumCol 0x18
#define Vcal 0x19
#define CalDel 0x1A
#define RangeTemp 0x1B
#define WBC 0xFE
#define CtrlReg 0xFD
class CTestboard
{
RPC_DEFS
RPC_THREAD
#ifdef _WIN32
CPipeClient pipe;
#endif
CUSB usb;
public:
CRpcIo& GetIo() { return *rpc_io; }
CTestboard() { RPC_INIT rpc_io = &usb; }
~CTestboard() { RPC_EXIT }
// === RPC ==============================================================
// Don't change the following two entries
RPC_EXPORT uint16_t GetRpcVersion();
RPC_EXPORT int32_t GetRpcCallId(string &callName);
RPC_EXPORT void GetRpcTimestamp(stringR &ts);
RPC_EXPORT int32_t GetRpcCallCount();
RPC_EXPORT bool GetRpcCallName(int32_t id, stringR &callName);
// === DTB connection ====================================================
bool EnumFirst(unsigned int &nDevices) { return usb.EnumFirst(nDevices); };
bool EnumNext(string &name);
bool Enum(unsigned int pos, string &name);
bool FindDTB(string &usbId);
bool Open(string &name, bool init=true); // opens a connection
void Close(); // closes the connection to the testboard
#ifdef _WIN32
bool OpenPipe(const char *name) { return pipe.Open(name); }
void ClosePipe() { pipe.Close(); }
#endif
bool IsConnected() { return usb.Connected(); }
const char * ConnectionError()
{ return usb.GetErrorMsg(usb.GetLastError()); }
void Flush() { rpc_io->Flush(); }
void Clear() { rpc_io->Clear(); }
// === DTB identification ================================================
RPC_EXPORT void GetInfo(stringR &info);
RPC_EXPORT uint16_t GetBoardId();
RPC_EXPORT void GetHWVersion(stringR &version);
RPC_EXPORT uint16_t GetFWVersion();
RPC_EXPORT uint16_t GetSWVersion();
// === DTB service ======================================================
// --- upgrade
RPC_EXPORT uint16_t UpgradeGetVersion();
RPC_EXPORT uint8_t UpgradeStart(uint16_t version);
RPC_EXPORT uint8_t UpgradeData(string &record);
RPC_EXPORT uint8_t UpgradeError();
RPC_EXPORT void UpgradeErrorMsg(stringR &msg);
RPC_EXPORT void UpgradeExec(uint16_t recordCount);
// === DTB functions ====================================================
RPC_EXPORT void Init();
RPC_EXPORT void Welcome();
RPC_EXPORT void SetLed(uint8_t x);
// --- Clock, Timing ----------------------------------------------------
RPC_EXPORT void cDelay(uint16_t clocks);
RPC_EXPORT void uDelay(uint16_t us);
void mDelay(uint16_t ms);
// --- Signal Delay -----------------------------------------------------
#define SIG_CLK 0
#define SIG_CTR 1
#define SIG_SDA 2
#define SIG_TIN 3
#define SIG_MODE_NORMAL 0
#define SIG_MODE_LO 1
#define SIG_MODE_HI 2
RPC_EXPORT void Sig_SetMode(uint8_t signal, uint8_t mode);
RPC_EXPORT void Sig_SetPRBS(uint8_t signal, uint8_t speed);
RPC_EXPORT void Sig_SetDelay(uint8_t signal, uint16_t delay, int8_t duty = 0);
RPC_EXPORT void Sig_SetLevel(uint8_t signal, uint8_t level);
RPC_EXPORT void Sig_SetOffset(uint8_t offset);
RPC_EXPORT void Sig_SetLVDS();
RPC_EXPORT void Sig_SetLCDS();
// --- digital signal probe ---------------------------------------------
#define PROBE_OFF 0
#define PROBE_CLK 1
#define PROBE_SDA 2
#define PROBE_PGTOK 3
#define PROBE_PGTRG 4
#define PROBE_PGCAL 5
#define PROBE_PGRESR 6
#define PROBE_PGREST 7
#define PROBE_PGSYNC 8
#define PROBE_CTR 9
#define PROBE_CLKP 10
#define PROBE_CLKG 11
#define PROBE_CRC 12
RPC_EXPORT void SignalProbeD1(uint8_t signal);
RPC_EXPORT void SignalProbeD2(uint8_t signal);
// --- analog signal probe ----------------------------------------------
#define PROBEA_TIN 0
#define PROBEA_SDATA1 1
#define PROBEA_SDATA2 2
#define PROBEA_CTR 3
#define PROBEA_CLK 4
#define PROBEA_SDA 5
#define PROBEA_TOUT 6
#define PROBEA_OFF 7
#define GAIN_1 0
#define GAIN_2 1
#define GAIN_3 2
#define GAIN_4 3
RPC_EXPORT void SignalProbeA1(uint8_t signal);
RPC_EXPORT void SignalProbeA2(uint8_t signal);
RPC_EXPORT void SignalProbeADC(uint8_t signal, uint8_t gain = 0);
// --- ROC/Module power VD/VA -------------------------------------------
RPC_EXPORT void Pon(); // switch ROC power on
RPC_EXPORT void Poff(); // switch ROC power off
RPC_EXPORT void _SetVD(uint16_t mV);
RPC_EXPORT void _SetVA(uint16_t mV);
RPC_EXPORT void _SetID(uint16_t uA100);
RPC_EXPORT void _SetIA(uint16_t uA100);
RPC_EXPORT uint16_t _GetVD();
RPC_EXPORT uint16_t _GetVA();
RPC_EXPORT uint16_t _GetID();
RPC_EXPORT uint16_t _GetIA();
void SetVA(double V) { _SetVA(uint16_t(V*1000)); } // set VA voltage
void SetVD(double V) { _SetVD(uint16_t(V*1000)); } // set VD voltage
void SetIA(double A) { _SetIA(uint16_t(A*10000)); } // set VA current limit
void SetID(double A) { _SetID(uint16_t(A*10000)); } // set VD current limit
double GetVA() { return _GetVA()/1000.0; } // get VA voltage in V
double GetVD() { return _GetVD()/1000.0; } // get VD voltage in V
double GetIA() { return _GetIA()/10000.0; } // get VA current in A
double GetID() { return _GetID()/10000.0; } // get VD current in A
RPC_EXPORT void HVon();
RPC_EXPORT void HVoff();
RPC_EXPORT void ResetOn();
RPC_EXPORT void ResetOff();
RPC_EXPORT uint8_t GetStatus();
RPC_EXPORT void SetRocAddress(uint8_t addr);
// --- pulse pattern generator ------------------------------------------
#define PG_TOK 0x0100
#define PG_TRG 0x0200
#define PG_CAL 0x0400
#define PG_RESR 0x0800
#define PG_REST 0x1000
#define PG_SYNC 0x2000
RPC_EXPORT void Pg_SetCmd(uint16_t addr, uint16_t cmd);
// RPC_EXPORT void Pg_SetCmdAll(vector<uint16_t> &cmd);
RPC_EXPORT void Pg_Stop();
RPC_EXPORT void Pg_Single();
RPC_EXPORT void Pg_Trigger();
RPC_EXPORT void Pg_Loop(uint16_t period);
// RPC_EXPORT uint16_t GetUser1Version();
// --- data aquisition --------------------------------------------------
RPC_EXPORT uint32_t Daq_Open(uint32_t buffersize, uint8_t dma ); // max # of samples
RPC_EXPORT void Daq_Close();
RPC_EXPORT void Daq_Start();
RPC_EXPORT void Daq_Stop();
RPC_EXPORT uint32_t Daq_GetSize(uint8_t channel = 0);
RPC_EXPORT uint8_t Daq_Read(vectorR<uint16_t> &data,
uint8_t channel, uint16_t blocksize = 16384);
RPC_EXPORT uint8_t Daq_Read(vectorR<uint16_t> &data,
uint8_t channel, uint16_t blocksize, uint32_t &availsize);
RPC_EXPORT uint8_t Daq_Read(vectorR<uint16_t> &data,
uint16_t blocksize, uint32_t &availsize);
RPC_EXPORT uint8_t Daq_Read(vectorR<uint16_t> &data,
uint16_t blocksize = 16384);
RPC_EXPORT void Daq_Select_ADC(uint16_t blocksize, uint8_t source,
uint8_t start, uint8_t stop = 0);
RPC_EXPORT void Daq_Select_Deser160(uint8_t shift);
// --- ROC/module Communication -----------------------------------------
// -- set the i2c address for the following commands
RPC_EXPORT void roc_I2cAddr(uint8_t id);
// -- sends "ClrCal" command to ROC
RPC_EXPORT void roc_ClrCal();
// -- sets a single (DAC) register
RPC_EXPORT void roc_SetDAC(uint8_t reg, uint8_t value);
// -- set pixel bits (count <= 60)
// M - - - 8 4 2 1
RPC_EXPORT void roc_Pix(uint8_t col, uint8_t row, uint8_t value);
// -- trimm a single pixel (count < =60)
RPC_EXPORT void roc_Pix_Trim(uint8_t col, uint8_t row, uint8_t value);
// -- mask a single pixel (count <= 60)
RPC_EXPORT void roc_Pix_Mask(uint8_t col, uint8_t row);
// -- set calibrate at specific column and row
RPC_EXPORT void roc_Pix_Cal(uint8_t col, uint8_t row, bool sensor_cal = false);
// -- enable/disable a double column
RPC_EXPORT void roc_Col_Enable(uint8_t col, bool on);
// -- mask all pixels of a column and the coresponding double column
RPC_EXPORT void roc_Col_Mask(uint8_t col);
// -- mask all pixels and columns of the chip
RPC_EXPORT void roc_Chip_Mask();
// --- TBM --------------------------------------------------------------
// -- Enables the use of a TBM
RPC_EXPORT void tbm_Enable(bool on);
// -- Selects hub and port to be used, disables module abstraction layer
RPC_EXPORT void tbm_Addr(uint8_t hub, uint8_t port);
// -- Selects hub. Port is selected according to barrel module layout convention
RPC_EXPORT void mod_Addr(uint8_t hub);
// -- Sends I2C commands to the selected address
RPC_EXPORT void tbm_Set(uint8_t reg, uint8_t value);
// -- Reads back the register via I2C
RPC_EXPORT bool tbm_Get(uint8_t reg, uint8_t &value);
// -- Reads back uninterpreted data, gives raw bit pattern. For debugging purposes if tbm_Get failes with error
RPC_EXPORT bool tbm_GetRaw(uint8_t reg, uint32_t &value);
// -- Other TBM functions
RPC_EXPORT void tbm1_Write(uint32_t hubAddr, uint32_t addr, int32_t value);
RPC_EXPORT void tbm2_Write(uint32_t hubAddr, uint32_t addr, int32_t value);
RPC_EXPORT void tbm_Write(uint32_t hubAddr, uint32_t addr, int32_t value);
int16_t DecodePixel(vector<uint16_t> &data, int16_t &pos, int16_t &n, int16_t &ph, int16_t &col, int16_t &row);
RPC_EXPORT bool GetPixelAddressInverted();
RPC_EXPORT void SetPixelAddressInverted(bool status);
RPC_EXPORT int32_t CountReadouts(int32_t nTriggers);
RPC_EXPORT int32_t CountReadouts(int32_t nTriggers, int32_t chipId);
RPC_EXPORT int32_t CountReadouts(int32_t nTriggers, int32_t dacReg, int32_t dacValue);
//RPC_EXPORT uint8_t DacDac_dtb(vectorR<uint16_t> &res, int32_t dac1, int32_t dacRange1, int32_t dac2, int32_t dacRange2, int32_t nTrig);
RPC_EXPORT int32_t PH(int32_t col, int32_t row, int32_t trim, int16_t nTriggers);
//int32_t ThresholdBinary(int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t dacMin, int32_t dacMax, bool reverseMode);
int32_t Threshold(int32_t start, int32_t step, int32_t thrLevel, int32_t nTrig, int32_t dacReg);
//bool FindReadout(int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t &dacMin, int32_t &dacMax, bool reverseMode);
// RPC_EXPORT int32_t PixelThreshold(int32_t col, int32_t row, int32_t start, int32_t step, int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t xtalk, int32_t cals, int32_t trim);
RPC_EXPORT bool test_pixel_address(int32_t col, int32_t row);
//RPC_EXPORT int32_t ChipEfficiency(int16_t nTriggers, vectorR<uint8_t> &res);
// --- Wafer test functions
RPC_EXPORT bool testColPixel(uint8_t col, uint8_t trimbit, vectorR<uint8_t> &res);
// Ethernet test functions
RPC_EXPORT void Ethernet_Send(string &message);
RPC_EXPORT uint32_t Ethernet_RecvPackets();
RPC_EXPORT int32_t PixelThreshold(int32_t col, int32_t row, int32_t start, int32_t step, int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t xtalk, int32_t cals, int32_t trim);
// int32_t ChipThreshold(int32_t start, int32_t step, int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t xtalk, int32_t cals, int32_t trim, int32_t res);
int32_t ChipThreshold(int32_t start, int32_t step, int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t xtalk, int32_t cals, int32_t trim[], int32_t res[]);
RPC_EXPORT int32_t ChipThresholdConvert(int32_t start, int32_t step, int32_t thrLevel, int32_t nTrig, int32_t dacReg, int32_t xtalk, int32_t cals, vectorR<int32_t> &trim, vectorR<int32_t> &res);
};