-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp~
285 lines (232 loc) · 7.58 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
#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>
int main(int argc, char *argv[])
{
// ExternalADC *adc1115 = new ExternalADC(0b01001000,0b11110011,0b11110011);
/*ExternalADC *adc1115 = new ExternalADC(0b01001000,1);
adc1115->access_device();
uint16_t adc_counts = 0;
double v = 0;
adc1115->read_adc(&adc_counts);
adc1115->inVolts(&adc_counts, &v);
*/
/*
uint32_t data = 0;
printf("DATA 0: 0x%08x\n",data);
Fpga *fpga = new Fpga();
fpga->read_fpga(0x00010040,&data);
uint32_t direction = 0x0f000000;
fpga->write_fpga((uint32_t)ALT_GPIO1_SWPORTA_DDR_ADDR,direction);
fpga->write_fpga((uint32_t)ALT_GPIO1_SWPORTA_DR_ADDR,direction);
printf("DATA 1: 0x%08x\n",data);
*/
/*
uint8_t dataW = strtoul( argv[ 1 ], NULL, 0 );
uint8_t register_add = strtoul( argv[ 2 ], NULL, 0 );
uint8_t r_w = 0;
r_w = strtoul( argv[ 3 ], NULL, 0 );
I2C *salt = new I2C(1,0x50);
salt->access_device();
uint8_t data = 0;
if(r_w==0){
salt->read_buffer(register_add, &data);
printf("DATA before write: 0x%02x in 0x%02x\n",data,register_add);
//uint16_t dataW = 0x05;
salt->write_buffer(register_add, dataW);
salt->read_buffer(register_add, &data);
printf("DATA after write: 0x%02x in 0x%02x\n",data,register_add);
}
if(r_w==1){
salt->read_buffer(register_add, &data);
printf("DATA: 0x%02x in 0x%02x\n",data,register_add);
}
if(r_w==2){
salt->write_buffer(register_add, dataW);
}
*/
//Example how to define different configuration
// but this config is default one as well
/*
uint16_t cur_counts = 0;
float amp = 0;
CurrentMonitor *cur1 = new CurrentMonitor(1,0b01000000);
cur1->access_device();
cur1->set_config_bits(0b00011111,0b00000100);
cur1->set_calib_bits(0b00000000,0b00100000);
cur1->define_setup();
cur1->read_current(&cur_counts);
cur1->convert_to_amp(&cur_counts,&);
printf("Monitor 1: HEX 0x%02x\n or %f mA \n",cur_counts, amp);
CurrentMonitor *cur2 = new CurrentMonitor(1,0b01000001);
cur2->access_device();
cur2->set_config_bits(0b00011111,0b00000100);
cur2->set_calib_bits(0b00000000,0b00100000);
cur2->define_setup();
cur2->read_current(&cur_counts);
cur1->convert_to_amp(&cur_counts,&);
printf("Monitor 2: HEX 0x%02x\n or %f mA \n",cur_counts, amp);
*/
clock_t start;
clock_t finish;
start = clock();
// initial definitions
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)== "i2c") || (arg.at(i) == "all")) {
cout << "I2C check:" << endl;
if(dig_com->I2C_check())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
{
cout << "FAIL" << endl << "FAILED" << 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;
else
{
cout << "FAIL" << endl << "FAILED" << endl;
exit(-1);
}
}
if( (arg.at(i) == "fpga_daq_sync") || (arg.at(i) == "all")) {
cout << "FPGA-DAQ sync:" << endl;
if(dig_com->DAQ_Sync())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << 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;
else
cout << "FAIL" << endl << "FAILED" << 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;
else
cout << "FAIL" << endl << "FAILED" << 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;
else
cout << "FAIL" << endl << "FAILED" << endl;
}
if( (arg.at(i) == "zs") || (arg.at(i) == "all")) {
cout << "Zero supression:" << endl;
if(ana_func->Check_NZS())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << endl;
}
if( (arg.at(i) == "pedestal") || (arg.at(i) == "all")) {
cout << "Pedestal substraction:" << endl;
if(ana_func->Check_PedS())
cout << "SUCCESS!" << endl << "PASSED!" << endl;
else
cout << "FAIL" << endl << "FAILED" << 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;
else
cout << "FAIL" << endl << "FAILED" << 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;
ana_func->adc_output(-32,64);
}
else
cout << "FAIL" << endl << "FAILED" << 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;
else
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;
else
cout << "FAIL" << endl << "FAILED" << endl;
}
if ((arg.at(i) == "test") )
{
unsigned Integer32 = 0x12345678;
uint8_t *Decomposed = (uint8_t *)&Integer32;
cout << hex << (int) Decomposed[0] << endl;
cout << hex << (int) Decomposed[1] << endl;
cout << hex << (int) Decomposed[2] << endl;
cout << hex << (int) Decomposed[3] << endl;
}
finish = clock();
cout << "Total time = " << (float) (finish-start)/CLOCKS_PER_SEC << "seconds" << endl;
//if((arg.at(i) == "calib_fifo") ) {
//
// cout << "CALIB FIFO" << endl;
// ana_func->set_calib_fifo();
// }
// uint8_t buffer=0;
// // st->read_salt(0x300,&buffer);
// // if(buffer != 0x80)
// // buffer = 0x80;
// // st->write_salt(0x300,buffer);
// ana_func->set_calib_fifo();
// cout << "others is " << hex << (unsigned) buffer << endl;
}
/*
Salt *st = new Salt();
uint8_t data = 0;
st->read_salt(0b101,0, &data);
printf(" 0x%02x \n",data);
*/
return 0;
}