-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·400 lines (327 loc) · 11.4 KB
/
main.cpp
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#include "I2C.h"
#include "ExternalADC.h"
#include <iostream>
#include "Fpga.h"
#include "CurrentMonitor.h"
#include "Salt.h"
#include "fastComm.h"
#include "Dig_Clk_test.h"
#include "Ana_tests.h"
#include <time.h>
#include "hwlib.h"
#include "socal/socal.h"
#include "socal/hps.h"
#include "socal/alt_gpio.h"
#include <cstring>
#include <vector>
#include <fstream>
int main(int argc, char *argv[])
{
clock_t start_bp;
clock_t end_bp;
clock_t start;
clock_t finish;
start = clock();
ofstream outfile;
outfile.open("RunLog.txt");
uint16_t cur_counts_a = 0;
int bus_voltage_a = 0;
uint16_t cur_counts_d = 0;
int bus_voltage_d = 0;
float amp_a = 0;
float amp_d = 0;
CurrentMonitor *cur1 = new CurrentMonitor(2,0x41);
CurrentMonitor *cur2 = new CurrentMonitor(0,0x40);
// initial definitions
ExternalADC *adc1115 = new ExternalADC(0x49,2);
adc1115->access_device();
// uint16_t adc_counts = 0;
// double v = 0;
// adc1115->read_adc(&adc_counts);
// adc1115->inVolts(&adc_counts, &v);
Fpga *fpga = new Fpga();
Salt *st = new Salt(1,5);
FastComm *fastComm = new FastComm(fpga);
Dig_Clk_test *dig_com = new Dig_Clk_test(fpga,st,fastComm);
Ana_tests *ana_func = new Ana_tests(fpga,st,fastComm);
vector<string> arg;
// soft reset of SALT
//st->write_salt(0x601,(uint8_t) 1);
//st->write_salt(0x600,(uint8_t) 1);
if(argc == 1) {
cout << "ERROR::MUST PROVIDE AN ARGUMENT!!!" << endl;
cout << "Example: ./main i2c dll_pll fpga_daq_sync dsr_tfc_sync" << endl;
return 0;
}
for(int i=1; i < argc; i++)
arg.push_back(argv[i]);
for(int i=0; i < arg.size(); i++) {
if( (arg.at(i) == "power") || (arg.at(i) == "all") ) {
// uint16_t adc_counts = 0;
// double v = 0;
// adc1115->read_adc(&adc_counts);
// adc1115->inVolts(&adc_counts, &v);
/*uint16_t cur_counts_a = 0;
int bus_voltage_a = 0;
uint16_t cur_counts_d = 0;
int bus_voltage_d = 0;
float amp_a = 0;
float amp_d = 0;*/
// CurrentMonitor *cur1 = new CurrentMonitor(2,0x41);
cur1->access_device();
cur1->set_config_bits(0b00011111,0b00000100);
cur1->set_calib_bits(0b00000000,0b00100000);
cur1->define_setup();
cur1->read_current(&cur_counts_d);
cur1->read_BusVoltage_mV(&bus_voltage_d);
cur1->convert_to_amp(&cur_counts_d,&_d);
// printf("Digi: HEX 0x%02x\n or %f mA \n",cur_counts, amp);
cout << "Digital Power Consumption:" << endl;
cout << "Current[mA] = " << dec << amp_d << endl;
cout << "Voltage[mV] = " << dec << bus_voltage_d << endl;
//CurrentMonitor *cur2 = new CurrentMonitor(0,0x40);
cur2->access_device();
cur2->set_config_bits(0b00011111,0b00000100);
cur2->set_calib_bits(0b00000000,0b00100000);
cur2->define_setup();
cur2->read_current(&cur_counts_a);
cur2->convert_to_amp(&cur_counts_a,&_a);
cur2->read_BusVoltage_mV(&bus_voltage_a);
//printf("Monitor 2: HEX 0x%02x\n or %f mA \n",cur_counts, amp);
cout << "Analogue Power Consumption:" << endl;
cout << "Current[mA] = " << dec << amp_a << endl;
cout << "Voltage[mV] = " << dec << bus_voltage_a << endl;
cout << "Total Power Consumption:" << endl;
cout << "Current[mA] = " << dec << amp_a+amp_d << endl;
cout << "Voltage[mV] = " << dec << (bus_voltage_a+bus_voltage_d)/2 << endl;
outfile << "Digital Power Consumption:" << endl;
outfile << "Current[mA] = " << dec << amp_d << endl;
outfile << "Voltage[mV] = " << dec << bus_voltage_d << endl;
outfile << "Analogue Power Consumption:" << endl;
outfile << "Current[mA] = " << dec << amp_a << endl;
outfile << "Voltage[mV] = " << dec << bus_voltage_a << endl;
outfile << "Total Power Consumption:" << endl;
outfile << "Current[mA] = " << dec << amp_a+amp_d << endl;
outfile << "Voltage[mV] = " << dec << (bus_voltage_a+bus_voltage_d)/2 << endl;
if((amp_a+amp_d) < 500 ) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "POWER CONSUMPTION: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "POWER CONSUMPTION: FAIL" << endl;
}
}
if( (arg.at(i)== "i2c") || (arg.at(i) == "all")) {
cout << "I2C check:" << endl;
if(dig_com->I2C_check()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "I2C: OK" << endl;
}
else
{
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "I2C: FAIL" << endl;
exit(-1);
}
}
if( (arg.at(i)== "dll_pll") || (arg.at(i) == "all")) {
cout << "DLL and PLL configuration:" << endl;
if(dig_com->DLL_Check() && dig_com->PLL_Check()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "DLL/PLL CONFIG: OK" << endl;
}
else
{
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "DLL/PLL CONFIG: FAIL" << endl;
// exit(-1);
}
}
if( (arg.at(i) == "fpga_daq_sync") || (arg.at(i) == "all")) {
cout << "FPGA-DAQ sync:" << endl;
bool pass_bp = false;
start_bp = clock();
while( (clock() - start_bp)/CLOCKS_PER_SEC < 5) {
if(dig_com->DAQ_Sync()) {
pass_bp = true;
break;
}
}
if(pass_bp) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "FPGA/DAQ SYNC: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "FPGA/DAQ SYNC: FAIL" << endl;
}
}
if( (arg.at(i) == "dsr_tfc_sync") || (arg.at(i) == "all")) {
// reset TFC
dig_com->TFC_Reset();
// Synch between DSR and TFC
cout << "DSR and TFC synch:" << endl;
if(dig_com->TFC_DAQ_sync()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "DSR/TFC SYNC: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "DSR/TFC SYNC: FAIL" << endl;
}
}
if( (arg.at(i) == "tfc_cmd") || (arg.at(i) == "all")) {
cout << "TFC commands check:" << endl;
if(dig_com->TFC_Command_Check()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "TFC CMD CHECK: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "TFC CMD CHECK: FAIL" << endl;
}
}
// Do baseline corr
if( (arg.at(i) == "baseline_corr") || (arg.at(i) == "all")) {
cout << "Baseline corrections:" << endl;
if(ana_func->Baseline_corr()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
ana_func->baseline_output();
outfile << "BASELINE CORRECTIONS: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "BASELINE CORRECTIONS: FAIL" << endl;
}
}
if( (arg.at(i) == "zs") || (arg.at(i) == "all")) {
cout << "Zero supression:" << endl;
if(ana_func->Check_NZS()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "ZERO SUPPRESSION CHECK: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "ZERO SUPPRESSION CHECK: FAIL" << endl;
}
}
if( (arg.at(i) == "pedestal") || (arg.at(i) == "all")) {
cout << "Pedestal substraction:" << endl;
if(ana_func->Check_PedS()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "PEDESTAL SUBSTRACTION: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "PEDESTAL SUBTRACTION: FAIL" << endl;
}
}
if( (arg.at(i) == "mcms") || (arg.at(i) == "all")) {
cout << "Mean Common Mode Subtraction:" << endl;
if(ana_func->Check_MCMS()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "MCMS: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "MCMS: FAIL" << endl;
}
}
// Get noise
if( (arg.at(i) == "noise_run") || (arg.at(i) == "all")) {
cout << "Noise MCMS run:" << endl;
if(ana_func->Get_noise(100,"MCMS","NZS")) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "NOISE CHECK: OK" << endl;
ana_func->adc_output(-32,64);
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "NOISE CHECK: FAIL" << endl;
}
}
if((arg.at(i) == "calib_fifo") || (arg.at(i) == "all")) {
cout << "CALIB FIFO and ADC clk delay:" << endl;
if(ana_func->set_calib_fifo()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
outfile << "CALIB FIFO/ADC CLK DELAY: OK" << endl;
}
else {
outfile << "CALIB FIFO/ADC CLK DELAY: FAIL" << endl;
cout << "FAIL" << endl << "FAILED" << endl;
}
}
if( (arg.at(i) == "gain") || (arg.at(i) == "all")) {
cout << "Gain test:" << endl;
if(ana_func->Check_Gain()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
ana_func->gain_output();
outfile << "GAIN CHECK: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "GAIN CHECK: FAIL" << endl;
}
}
if ((arg.at(i) == "xtalk") || (arg.at(i) == "all") ) {
if(ana_func->xtalk_test()) {
cout << "SUCCESS!" << endl << "PASSED!" << endl;
ana_func->xtalk_output();
outfile << "CROSSTALK CHECK: OK" << endl;
}
else {
cout << "FAIL" << endl << "FAILED" << endl;
outfile << "CROSSTALK CHECK: FAIL" << endl;
}
}
if(arg.at(i) == "all") {
//CurrentMonitor *cur1 = new CurrentMonitor(2,0x41);
// cur1->access_device();
// cur1->set_config_bits(0b00011111,0b00000100);
// cur1->set_calib_bits(0b00000000,0b00100000);
//cur1->define_setup();
cur1->read_current(&cur_counts_d);
cur1->read_BusVoltage_mV(&bus_voltage_d);
cur1->convert_to_amp(&cur_counts_d,&_d);
// printf("Digi: HEX 0x%02x\n or %f mA \n",cur_counts, amp);
cout << "Digital Power Consumption (FINAL):" << endl;
cout << "Current[mA] = " << dec << amp_d << endl;
cout << "Voltage[mV] = " << dec << bus_voltage_d << endl;
//CurrentMonitor *cur2 = new CurrentMonitor(0,0x40);
//cur2->access_device();
//cur2->set_config_bits(0b00011111,0b00000100);
//cur2->set_calib_bits(0b00000000,0b00100000);
//cur2->define_setup();
cur2->read_current(&cur_counts_a);
cur2->convert_to_amp(&cur_counts_a,&_a);
cur2->read_BusVoltage_mV(&bus_voltage_a);
cout << "Analogue Power Consumption (FINAL):" << endl;
cout << "Current[mA] = " << dec << amp_a << endl;
cout << "Voltage[mV] = " << dec << bus_voltage_a << endl;
cout << "Total Power Consumption (FINAL):" << endl;
cout << "Current[mA] = " << dec << amp_a+amp_d << endl;
cout << "Voltage[mV] = " << dec << (bus_voltage_a+bus_voltage_d)/2 << endl;
outfile << "Digital Power Consumption (FINAL):" << endl;
outfile << "Current[mA] = " << dec << amp_d << endl;
outfile << "Voltage[mV] = " << dec << bus_voltage_d << endl;
outfile << "Analogue Power Consumption (FINAL):" << endl;
outfile << "Current[mA] = " << dec << amp_a << endl;
outfile << "Voltage[mV] = " << dec << bus_voltage_a << endl;
outfile << "Total Power Consumption (FINAL):" << endl;
outfile << "Current[mA] = " << dec << amp_a+amp_d << endl;
outfile << "Voltage[mV] = " << dec << (bus_voltage_a+bus_voltage_d)/2 << endl;
}
if(arg.at(i) == "reset_fpga") {
fpga->write_fpga(registers::RESET, (uint8_t) 0x01);
fpga->write_fpga(registers::RESET, (uint8_t) 0x00);
}
if(arg.at(i) == "reset" ) {
fpga->write_fpga(registers::RESET, (uint8_t) 0x03);
fpga->write_fpga(registers::I2C_ADD, (uint8_t) 0x05);
}
}
finish = clock();
cout << "Total time = " << (float) (finish-start)/CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}