Rev 291 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 291 | Rev 299 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | static const int SiTCP_PORT = 24; |
3 | static const int SiTCP_PORT = 24; |
4 | SOCKET sock; |
4 | SOCKET sock; |
5 | 5 | ||
6 | unsigned int slowdata[sizeByte_SC]; |
6 | unsigned int slowdata[sizeByte_SC]; |
7 | unsigned int ReadSCdata[sizeByte_RSC]; |
7 | unsigned int ReadSCdata[sizeByte_RSC]; |
8 | unsigned int Probedata[sizeByte_PSC]; |
- | |
9 | unsigned int Pindata[sizeByte_PIN]; |
8 | unsigned int Pindata[sizeByte_PIN]; |
10 | 9 | ||
- | 10 | unsigned int iniData[sizeByte_PIN + 2*sizeByte_SC + 2*sizeByte_RSC]; |
|
- | 11 | ||
11 | unsigned int Probedata[sizeByte_PSC]; |
12 | unsigned int Probedata[sizeByte_PSC]; |
12 | 13 | ||
13 | int ForceStop = 0; |
14 | int ForceStop = 0; |
14 | int EndADC = 0; |
15 | int EndADC = 0; |
15 | 16 | ||
16 | #include <windows.h> |
17 | #include <windows.h> |
17 | 18 | ||
18 | void usleep(__int64 usec) |
19 | void usleep(__int64 usec) |
19 | { |
20 | { |
20 | HANDLE timer; |
21 | HANDLE timer; |
21 | LARGE_INTEGER ft; |
22 | LARGE_INTEGER ft; |
22 | 23 | ||
Line 52... | Line 53... | ||
52 | return -1; |
53 | return -1; |
53 | } |
54 | } |
54 | IP = SiTCP_MASTER_IP; |
55 | IP = SiTCP_MASTER_IP; |
55 | port = SiTCP_PORT; |
56 | port = SiTCP_PORT; |
56 | SiTCP_ADDR.sin_family = AF_INET; |
57 | SiTCP_ADDR.sin_family = AF_INET; |
57 | SiTCP_ADDR.sin_port = htons(port); |
58 | SiTCP_ADDR.sin_port = htons((unsigned short)port); |
58 | SiTCP_ADDR.sin_addr.s_addr = inet_addr(IP); |
59 | SiTCP_ADDR.sin_addr.s_addr = inet_addr(IP); |
59 | 60 | ||
60 | struct timeval tv; |
61 | struct timeval tv; |
61 | tv.tv_sec = 3; |
62 | tv.tv_sec = 3; |
62 | tv.tv_usec = 0; |
63 | tv.tv_usec = 0; |
Line 73... | Line 74... | ||
73 | closesocket(sock); |
74 | closesocket(sock); |
74 | return -1; |
75 | return -1; |
75 | } |
76 | } |
76 | 77 | ||
77 | printf("SiTCP Master :: Connection Done\n\n"); |
78 | printf("SiTCP Master :: Connection Done\n\n"); |
78 | 79 | ||
79 | // Auto Initialize ------------------------------------------------------- |
80 | // Auto Initialize ------------------------------------------------------- |
80 | PrepareFPGA(); |
81 | PrepareFPGA(); |
81 | DebugFPGA(sock); |
82 | DebugFPGA(sock); |
82 | printf("\nASIS Initialize : Done\n\n"); |
83 | printf("\nASIS Initialize : Done\n\n"); |
83 | //Sleep(1000); |
84 | //Sleep(1000); |
84 | 85 | ||
85 | WriteData(sock, 37888); |
86 | WriteData(sock, 37888); |
86 | PrepareSC(1); |
87 | PrepareSC(1); |
87 | TransmitSC(sock); |
88 | TransmitSC(sock); |
88 | printf("\nSlow Control chip1 : Done\n\n"); |
89 | printf("\nSlow Control chip1 : Done\n\n"); |
89 | PrepareReadSC(1); |
90 | PrepareReadSC(1); |
90 | TransmitReadSC(sock); |
91 | TransmitReadSC(sock); |
91 | printf("\nRead Slow Control chip1 : Done\n\n"); |
92 | printf("\nRead Slow Control chip1 : Done\n\n"); |
92 | 93 | ||
93 | WriteData(sock, 21504); |
94 | WriteData(sock, 21504); |
94 | PrepareSC(2); |
95 | PrepareSC(2); |
Line 114... | Line 115... | ||
114 | 115 | ||
115 | return 0; |
116 | return 0; |
116 | } |
117 | } |
117 | //------------------------------------------------------------------------------------------------------ |
118 | //------------------------------------------------------------------------------------------------------ |
118 | void easiroc_Close() |
119 | void easiroc_Close() |
119 | { |
120 | { |
120 | closesocket(sock); |
121 | closesocket(sock); |
121 | WSACleanup(); |
122 | WSACleanup(); |
122 | printf("easiroc_Close -> Done.\n"); |
123 | printf("easiroc_Close -> Done.\n"); |
123 | } |
124 | } |
124 | //------------------------------------------------------------------------------------------------------ |
125 | //------------------------------------------------------------------------------------------------------ |
Line 134... | Line 135... | ||
134 | Sleep(WRITEDATA_DELAY); |
135 | Sleep(WRITEDATA_DELAY); |
135 | 136 | ||
136 | unsigned int buf = 0; |
137 | unsigned int buf = 0; |
137 | unsigned int length = 4; |
138 | unsigned int length = 4; |
138 | int ret = recv(sock, (char*)&buf, length, 0); |
139 | int ret = recv(sock, (char*)&buf, length, 0); |
139 | 140 | ||
140 | if ( ret > 0 ) { |
141 | if ( ret > 0 ) { |
141 | if(esrcdbg) printf("Bytes received: %d\n", ret); |
142 | if(esrcdbg) printf("Bytes received: %d\n", ret); |
142 | else printf("."); |
143 | else printf("."); |
143 | } else if ( ret == 0 ) { |
144 | } else if ( ret == 0 ) { |
144 | printf("Connection closed\n"); |
145 | printf("Connection closed\n"); |
145 | return -1; |
146 | return -1; |
146 | } else { |
147 | } else { |
147 | printf("recv failed: %d\n", WSAGetLastError()); |
148 | printf("recv failed: %d\n", WSAGetLastError()); |
148 | return -1; |
149 | return -1; |
149 | } |
150 | } |
150 | 151 | ||
151 | return 0; |
152 | return 0; |
152 | } |
153 | } |
- | 154 | //------------------------------------------------------------------------------------------------------ |
|
- | 155 | int easiroc_LoadIni(const char *iniFile) |
|
- | 156 | { |
|
- | 157 | FILE *fp=fopen(iniFile, "rt"); |
|
- | 158 | if(!fp) { |
|
- | 159 | printf("easiroc::LoadIni() cannot open file %s !!!\n", iniFile); |
|
- | 160 | return 0; |
|
- | 161 | } |
|
- | 162 | ||
- | 163 | char lbuff[256]; |
|
- | 164 | int counter = 0; |
|
- | 165 | while(1) { |
|
- | 166 | int c = fgetc(fp); |
|
- | 167 | if(feof(fp)) break; |
|
- | 168 | if( '#' == (char)c ) { |
|
- | 169 | fgets(lbuff,256,fp); |
|
- | 170 | //printf("Found Comment line: %s", lbuff); |
|
- | 171 | } else { |
|
- | 172 | ungetc(c, fp); |
|
- | 173 | fscanf(fp, "%u\n", &iniData[counter] ); |
|
- | 174 | //printf("Found value [%d] %u\n", counter, iniData[counter]); |
|
- | 175 | counter++; |
|
- | 176 | } |
|
- | 177 | } |
|
- | 178 | fclose(fp); |
|
- | 179 | ||
- | 180 | return 1; |
|
- | 181 | } |
|
153 | //------------------------------------------------------------------------------------------------------ |
182 | //------------------------------------------------------------------------------------------------------ |
154 | void PrepareFPGA() |
183 | void PrepareFPGA() |
155 | { |
184 | { |
156 | Pindata[0] = |
185 | Pindata[0] = iniData[0]; |
157 | Pindata[1] = |
186 | Pindata[1] = iniData[1]; |
158 | } |
187 | } |
159 | //------------------------------------------------------------------------------------------------------ |
188 | //------------------------------------------------------------------------------------------------------ |
160 | void PrepareSC(int chipNo) |
189 | void PrepareSC(int chipNo) |
161 | { |
190 | { |
162 | if(chipNo == 1) { |
191 | if(chipNo == 1) { |
163 | slowdata[0] |
192 | slowdata[ 0] = iniData[sizeByte_PIN + 0]; |
164 | slowdata[1] |
193 | slowdata[ 1] = iniData[sizeByte_PIN + 1]; |
165 | slowdata[2] |
194 | slowdata[ 2] = iniData[sizeByte_PIN + 2]; |
166 | slowdata[3] |
195 | slowdata[ 3] = iniData[sizeByte_PIN + 3]; |
167 | slowdata[4] |
196 | slowdata[ 4] = iniData[sizeByte_PIN + 4]; |
168 | slowdata[5] |
197 | slowdata[ 5] = iniData[sizeByte_PIN + 5]; |
169 | slowdata[6] |
198 | slowdata[ 6] = iniData[sizeByte_PIN + 6]; |
170 | slowdata[7] |
199 | slowdata[ 7] = iniData[sizeByte_PIN + 7]; |
171 | slowdata[8] |
200 | slowdata[ 8] = iniData[sizeByte_PIN + 8]; |
172 | slowdata[9] |
201 | slowdata[ 9] = iniData[sizeByte_PIN + 9]; |
173 | slowdata[10] = |
202 | slowdata[10] = iniData[sizeByte_PIN + 0]; |
174 | slowdata[11] = |
203 | slowdata[11] = iniData[sizeByte_PIN + 11]; |
175 | slowdata[12] = |
204 | slowdata[12] = iniData[sizeByte_PIN + 12]; |
176 | slowdata[13] = |
205 | slowdata[13] = iniData[sizeByte_PIN + 13]; |
177 | slowdata[14] = |
206 | slowdata[14] = iniData[sizeByte_PIN + 14]; |
178 | } else { |
207 | } else { |
179 | slowdata[0] |
208 | slowdata[ 0] = iniData[sizeByte_PIN + 1*sizeByte_SC + 0]; |
180 | slowdata[1] |
209 | slowdata[ 1] = iniData[sizeByte_PIN + 1*sizeByte_SC + 1]; |
181 | slowdata[2] |
210 | slowdata[ 2] = iniData[sizeByte_PIN + 1*sizeByte_SC + 2]; |
182 | slowdata[3] |
211 | slowdata[ 3] = iniData[sizeByte_PIN + 1*sizeByte_SC + 3]; |
183 | slowdata[4] |
212 | slowdata[ 4] = iniData[sizeByte_PIN + 1*sizeByte_SC + 4]; |
184 | slowdata[5] |
213 | slowdata[ 5] = iniData[sizeByte_PIN + 1*sizeByte_SC + 5]; |
185 | slowdata[6] |
214 | slowdata[ 6] = iniData[sizeByte_PIN + 1*sizeByte_SC + 6]; |
186 | slowdata[7] |
215 | slowdata[ 7] = iniData[sizeByte_PIN + 1*sizeByte_SC + 7]; |
187 | slowdata[8] |
216 | slowdata[ 8] = iniData[sizeByte_PIN + 1*sizeByte_SC + 8]; |
188 | slowdata[9] |
217 | slowdata[ 9] = iniData[sizeByte_PIN + 1*sizeByte_SC + 9]; |
189 | slowdata[10] = |
218 | slowdata[10] = iniData[sizeByte_PIN + 1*sizeByte_SC + 10]; |
190 | slowdata[11] = |
219 | slowdata[11] = iniData[sizeByte_PIN + 1*sizeByte_SC + 11]; |
191 | slowdata[12] = |
220 | slowdata[12] = iniData[sizeByte_PIN + 1*sizeByte_SC + 12]; |
192 | slowdata[13] = |
221 | slowdata[13] = iniData[sizeByte_PIN + 1*sizeByte_SC + 13]; |
193 | slowdata[14] = |
222 | slowdata[14] = iniData[sizeByte_PIN + 1*sizeByte_SC + 14]; |
194 | } |
223 | } |
195 | } |
224 | } |
196 | //------------------------------------------------------------------------------------------------------ |
225 | //------------------------------------------------------------------------------------------------------ |
197 | void PrepareReadSC(int chipNo) |
226 | void PrepareReadSC(int chipNo) |
198 | { |
227 | { |
199 | if(chipNo == 1) { |
228 | if(chipNo == 1) { |
200 | ReadSCdata[0] = 0 |
229 | ReadSCdata[0] = iniData[sizeByte_PIN + 2*sizeByte_SC + 0]; |
201 | } else { |
230 | } else { |
- | 231 | ReadSCdata[0] = iniData[sizeByte_PIN + 2*sizeByte_SC + 1]; |
|
- | 232 | } |
|
- | 233 | } |
|
- | 234 | //------------------------------------------------------------------------------------------------------ |
|
- | 235 | void easiroc_PrintData() |
|
- | 236 | { |
|
- | 237 | printf(">>> Pindata\n"); |
|
- | 238 | for(int i=0; i<sizeByte_PIN; i++) printf("%u\n", Pindata[i]); |
|
- | 239 | ||
- | 240 | ||
- | 241 | printf(">>> slowdata (1)\n"); |
|
- | 242 | for(int i=0; i<sizeByte_SC; i++) printf("%u\n", slowdata[i]); |
|
- | 243 | ||
- | 244 | ||
- | 245 | printf(">>> slowdata (2)\n"); |
|
- | 246 | for(int i=0; i<sizeByte_SC; i++) printf("%u\n", slowdata[i]); |
|
- | 247 | ||
- | 248 | ||
- | 249 | printf(">>> ReadSCdata (1)\n"); |
|
- | 250 | for(int i=0; i<sizeByte_RSC; i++) printf("%u\n", ReadSCdata[i]); |
|
- | 251 | ||
- | 252 | ||
202 |
|
253 | printf(">>> ReadSCdata (2)\n"); |
- | 254 | for(int i=0; i<sizeByte_RSC; i++) printf("%u\n", ReadSCdata[i]); |
|
203 |
|
255 | |
204 | } |
256 | } |
205 | //------------------------------------------------------------------------------------------------------ |
257 | //------------------------------------------------------------------------------------------------------ |
206 | int DebugFPGA(SOCKET socket) |
258 | int DebugFPGA(SOCKET socket) |
207 | { |
259 | { |
- | 260 | printf(">>> DebugFPGA Pindata:\n"); |
|
- | 261 | for(int i=0; i<sizeByte_PIN; i++) printf("%u\n", Pindata[i]); |
|
- | 262 | ||
208 | unsigned int buffer = 0; |
263 | unsigned int buffer = 0; |
209 | buffer += 0 << 16; |
264 | buffer += 0 << 16; |
210 | buffer += (Pindata[0] & 255) << 8; |
265 | buffer += (Pindata[0] & 255) << 8; |
211 | if(-1 == WriteData(socket, buffer)){ |
266 | if(-1 == WriteData(socket, buffer)){ |
212 | return -1; |
267 | return -1; |
Line 230... | Line 285... | ||
230 | return 0; |
285 | return 0; |
231 | } |
286 | } |
232 | //------------------------------------------------------------------------------------------------------ |
287 | //------------------------------------------------------------------------------------------------------ |
233 | int TransmitSC(SOCKET socket) |
288 | int TransmitSC(SOCKET socket) |
234 | { |
289 | { |
- | 290 | printf(">>> TransmitSC slowdata:\n"); |
|
- | 291 | for(int i=0; i<sizeByte_SC; i++) printf("%u\n", slowdata[i]); |
|
- | 292 | ||
235 | unsigned int data = 0; |
293 | unsigned int data = 0; |
236 | //Set SC mode ----------------------------------------------------------- |
294 | //Set SC mode ----------------------------------------------------------- |
237 | data = 0; |
295 | data = 0; |
238 | data += 1 << 16; |
296 | data += 1 << 16; |
239 | data += 240 << 8; |
297 | data += 240 << 8; |
240 | if(-1 == WriteData(socket, data)){ |
298 | if(-1 == WriteData(socket, data)){ |
241 | return -1; |
299 | return -1; |
242 | } |
300 | } |
Line 265... | Line 323... | ||
265 | // Sleep(50000); |
323 | // Sleep(50000); |
266 | 324 | ||
267 | //StartCycle ----------------------------------------------------------- |
325 | //StartCycle ----------------------------------------------------------- |
268 | data = 0; |
326 | data = 0; |
269 | data += 1 << 16; |
327 | data += 1 << 16; |
270 | data += 242 << 8; |
328 | data += 242 << 8; |
271 | if(-1 == WriteData(socket, data)){ |
329 | if(-1 == WriteData(socket, data)){ |
272 | return -1; |
330 | return -1; |
273 | } |
331 | } |
274 | 332 | ||
275 | data = 0; |
333 | data = 0; |
276 | data += 1 << 16; |
334 | data += 1 << 16; |
277 | data += 240 << 8; |
335 | data += 240 << 8; |
278 | if(-1 == WriteData(socket, data)){ |
- | |
279 | return -1; |
- | |
280 | } |
- | |
281 | - | ||
282 | // Sleep(50000); |
- | |
283 | - | ||
284 | //Load SC -------------------------------------------------------------- |
- | |
285 | data = 0; |
- | |
286 | data += 1 << 16; |
- | |
287 | data += 241 << 8; |
- | |
288 | if(-1 == WriteData(socket, data)){ |
336 | if(-1 == WriteData(socket, data)){ |
289 | return -1; |
337 | return -1; |
290 | } |
338 | } |
291 | 339 | ||
- | 340 | // Sleep(50000); |
|
- | 341 | ||
- | 342 | //Load SC -------------------------------------------------------------- |
|
292 | data = 0; |
343 | data = 0; |
293 | data += 1 << 16; |
344 | data += 1 << 16; |
- | 345 | data += 241 << 8; |
|
- | 346 | if(-1 == WriteData(socket, data)){ |
|
- | 347 | return -1; |
|
- | 348 | } |
|
- | 349 | ||
- | 350 | data = 0; |
|
- | 351 | data += 1 << 16; |
|
294 | data += 240 << 8; |
352 | data += 240 << 8; |
295 | if(-1 == WriteData(socket, data)){ |
353 | if(-1 == WriteData(socket, data)){ |
296 | return -1; |
354 | return -1; |
297 | } |
355 | } |
298 | 356 | ||
299 | return 0; |
357 | return 0; |
300 | } |
358 | } |
301 | //------------------------------------------------------------------------------------------------------ |
359 | //------------------------------------------------------------------------------------------------------ |
302 | int TransmitReadSC(SOCKET socket) |
360 | int TransmitReadSC(SOCKET socket) |
303 | { |
361 | { |
- | 362 | ||
- | 363 | printf(">>> TransmitReadSC ReadSCdata:\n"); |
|
- | 364 | for(int i=0; i<sizeByte_RSC; i++) printf("%u\n", ReadSCdata[i]); |
|
- | 365 | ||
304 | //SCA read --------------------------------------------------------------- |
366 | //SCA read --------------------------------------------------------------- |
305 | unsigned int data = 0; |
367 | unsigned int data = 0; |
306 | 368 | ||
307 | for(int i = 0; i<4; ++i){ |
369 | for(int i = 0; i<4; ++i){ |
308 | data = 0; |
370 | data = 0; |
309 | data += 12 << 16; |
371 | data += 12 << 16; |
Line 345... | Line 407... | ||
345 | for(int i = 0; i<sizeByte_PSC; ++i){ |
407 | for(int i = 0; i<sizeByte_PSC; ++i){ |
346 | Probedata[i] = 0; |
408 | Probedata[i] = 0; |
347 | } |
409 | } |
348 | 410 | ||
349 | switch(CurrentProbeType){ |
411 | switch(CurrentProbeType){ |
350 | case |
412 | case 1: |
351 | CurrentProbe = pa_hg; |
413 | CurrentProbe = pa_hg; |
352 | break; |
414 | break; |
353 | 415 | ||
354 | case |
416 | case 2: |
355 | CurrentProbe = pa_lg; |
417 | CurrentProbe = pa_lg; |
356 | break; |
418 | break; |
357 | 419 | ||
358 | case |
420 | case 3: |
359 | CurrentProbe = ssh_hg; |
421 | CurrentProbe = ssh_hg; |
360 | break; |
422 | break; |
361 | 423 | ||
362 | case |
424 | case 4: |
363 | CurrentProbe = ssh_lg; |
425 | CurrentProbe = ssh_lg; |
364 | break; |
426 | break; |
365 | 427 | ||
366 | case |
428 | case 5: |
367 | CurrentProbe = fs; |
429 | CurrentProbe = fs; |
368 | break; |
430 | break; |
369 | 431 | ||
370 | case |
432 | case 6: |
371 | 433 | ||
372 | break; |
434 | break; |
373 | 435 | ||
374 | case |
436 | case 7: |
375 | 437 | ||
376 | break; |
438 | break; |
377 | 439 | ||
378 | case |
440 | case 8: |
379 | flag_rst = 1; |
441 | flag_rst = 1; |
380 | CurrentCh = 0; |
442 | CurrentCh = 0; |
381 | ProbeBuffer = 0; |
443 | ProbeBuffer = 0; |
382 | CurrentProbe = fs; |
444 | CurrentProbe = fs; |
383 | break; |
445 | break; |
384 | 446 | ||
385 | default: |
447 | default: |
386 | break; |
448 | break; |
387 | }; |
449 | }; |
- | 450 | ||
- | 451 | //printf("CurrentProbeType = %d | CurrentProbe = %d\n", CurrentProbeType, CurrentProbe); |
|
388 | 452 | ||
389 | if(flag_rst) { |
453 | if(flag_rst) { |
390 | return 0; |
454 | return 0; |
391 | } |
455 | } |
392 | 456 | ||
393 | if(flag_input) { |
457 | if(flag_input) { |
394 | ProbeBuffer = 1 << (31 - CurrentCh); |
458 | ProbeBuffer = 1 << (31 - CurrentCh); |
395 | } |
459 | } |
396 | 460 | ||
397 | unsigned int buffer_16 = ProbeBuffer*ProbeBuffer; |
461 | unsigned int buffer_16 = ProbeBuffer*ProbeBuffer; |
398 | unsigned int buffer_0 = (ProbeBuffer >> 16)*(ProbeBuffer >> 16); |
462 | unsigned int buffer_0 = (ProbeBuffer >> 16)*(ProbeBuffer >> 16); |
399 | if(CurrentProbe == ssh_hg || CurrentProbe == pa_hg) { |
463 | if(CurrentProbe == ssh_hg || CurrentProbe == pa_hg) { |
- | 464 | //printf("CurrentProbe == ssh_hg || CurrentProbe == pa_hg\n"); |
|
400 | buffer_16 = buffer_16 << 1; |
465 | buffer_16 = buffer_16 << 1; |
401 | buffer_0 = buffer_0 << 1; |
466 | buffer_0 = buffer_0 << 1; |
402 | } |
467 | } |
403 | if(CurrentProbe == fs) { |
468 | if(CurrentProbe == fs) { |
- | 469 | //printf("CurrentProbe == fs\n"); |
|
404 | Probedata[fs_all] = ProbeBuffer; |
470 | Probedata[fs_all] = ProbeBuffer; |
405 | } else if(CurrentProbe == ssh_hg || CurrentProbe == ssh_lg) { |
471 | } else if(CurrentProbe == ssh_hg || CurrentProbe == ssh_lg) { |
406 | if(CurrentCh > 15) { |
472 | if(CurrentCh > 15) { |
407 | Probedata[ssh_16] = buffer_16; |
473 | Probedata[ssh_16] = buffer_16; |
408 | } else { |
474 | } else { |
409 | Probedata[ssh_0] = buffer_0; |
475 | Probedata[ssh_0] = buffer_0; |
410 | } |
476 | } |
411 | } else if(CurrentProbe == pa_hg || CurrentProbe == pa_lg) { |
477 | } else if(CurrentProbe == pa_hg || CurrentProbe == pa_lg) { |
412 | if(CurrentCh > 15){ |
478 | if(CurrentCh > 15){ |
413 | Probedata[pa_16] = buffer_16; |
479 | Probedata[pa_16] = buffer_16; |
414 | }else{ |
480 | }else{ |
415 | Probedata[pa_0] = buffer_0; |
481 | Probedata[pa_0] = buffer_0; |
416 | } |
482 | } |
417 | } else { |
483 | } else { |
418 | printf("bug desu\n"); |
484 | printf("bug desu\n"); |
419 | } |
485 | } |
Line 446... | Line 512... | ||
446 | printf("."); |
512 | printf("."); |
447 | } |
513 | } |
448 | } |
514 | } |
449 | } |
515 | } |
450 | printf("\n"); |
516 | printf("\n"); |
451 | 517 | ||
452 | return 0; |
518 | return 0; |
453 | } |
519 | } |
454 | //------------------------------------------------------------------------------------------------------ |
520 | //------------------------------------------------------------------------------------------------------ |
455 | int TransmitProbe(SOCKET socket) |
521 | int TransmitProbe(SOCKET socket) |
456 | { |
522 | { |
457 | unsigned int data = 0; |
523 | unsigned int data = 0; |
458 | //Set Probe mode -------------------------------------------------------- |
524 | //Set Probe mode -------------------------------------------------------- |
459 | data += 1 << 16; |
525 | data += 1 << 16; |
460 | data += 208 << 8; |
526 | data += 208 << 8; |
461 | if(-1 == WriteData(socket, data)) { |
527 | if(-1 == WriteData(socket, data)) { |
462 | return -1; |
528 | return -1; |
463 | } |
529 | } |
464 | 530 | ||
465 | //Probe start ---------------------------------------------------------- |
531 | //Probe start ---------------------------------------------------------- |
466 | for(int i = 0; i<sizeByte_PSC; ++i) { |
532 | for(int i = 0; i<sizeByte_PSC; ++i) { |
467 | for(int shift = 0; shift<4; ++shift) { |
533 | for(int shift = 0; shift<4; ++shift) { |
468 | data = 0; |
534 | data = 0; |
469 | data += 10 << 16; |
535 | data += 10 << 16; |
Line 476... | Line 542... | ||
476 | 542 | ||
477 | //StartCycle ------------------------------------------------------------ |
543 | //StartCycle ------------------------------------------------------------ |
478 | data = 0; |
544 | data = 0; |
479 | data += 1 << 16; |
545 | data += 1 << 16; |
480 | data += 210 << 8; |
546 | data += 210 << 8; |
481 | if(-1 == WriteData(socket, data)) { |
547 | if(-1 == WriteData(socket, data)) { |
482 | return -1; |
548 | return -1; |
483 | } |
549 | } |
484 | 550 | ||
485 | data = 0; |
551 | data = 0; |
486 | data += 1 << 16; |
552 | data += 1 << 16; |
487 | data += 208 << 8; |
553 | data += 208 << 8; |
488 | if(-1 == WriteData(socket, data)) { |
554 | if(-1 == WriteData(socket, data)) { |
489 | return -1; |
555 | return -1; |
490 | } |
556 | } |
491 | 557 | ||
492 | return 0; |
558 | return 0; |
493 | } |
559 | } |
494 | //------------------------------------------------------------------------------------------------------ |
560 | //------------------------------------------------------------------------------------------------------ |
495 | int easiroc_fTransmitSC() |
561 | int easiroc_fTransmitSC() |
496 | { |
562 | { |
497 | if(WriteData(sock, 37888) != 0) return -1; |
563 | if(WriteData(sock, 37888) != 0) return -1; |
498 | PrepareSC(1); |
564 | PrepareSC(1); |
499 | if(TransmitSC(sock) != 0) return -1; |
565 | if(TransmitSC(sock) != 0) return -1; |
Line 529... | Line 595... | ||
529 | int easiroc_fAsicInitialize() |
595 | int easiroc_fAsicInitialize() |
530 | { |
596 | { |
531 | PrepareFPGA(); |
597 | PrepareFPGA(); |
532 | DebugFPGA(sock); |
598 | DebugFPGA(sock); |
533 | printf("\nASIS Initialize : Done\n\n"); |
599 | printf("\nASIS Initialize : Done\n\n"); |
534 | 600 | ||
535 | return 0; |
601 | return 0; |
536 | } |
602 | } |
537 | //------------------------------------------------------------------------------------------------------ |
603 | //------------------------------------------------------------------------------------------------------ |
538 | int easiroc_fTransmitProbe(int CurrentCh, int CurrentProbe) |
604 | int easiroc_fTransmitProbe(int CurrentCh, int CurrentProbe) |
539 | { |
605 | { |
Line 560... | Line 626... | ||
560 | //printf("\nTransmitProbe: Success!\n\n"); |
626 | //printf("\nTransmitProbe: Success!\n\n"); |
561 | 627 | ||
562 | return 0; |
628 | return 0; |
563 | } |
629 | } |
564 | //------------------------------------------------------------------------------------------------------ |
630 | //------------------------------------------------------------------------------------------------------ |
565 | int ADCOneCycle_wHeader_ver2(SOCKET socket, FILE* file) |
631 | int ADCOneCycle_wHeader_ver2(SOCKET socket, FILE* file, int stopping) |
566 | { |
632 | { |
567 | static const int NofHeader = 3; |
633 | static const int NofHeader = 3; |
568 | 634 | ||
569 | unsigned int DataBuffer[1000]; |
635 | unsigned int DataBuffer[1000]; |
570 | memset(DataBuffer, 0, sizeof(DataBuffer)); |
636 | memset(DataBuffer, 0, sizeof(DataBuffer)); |
Line 576... | Line 642... | ||
576 | 642 | ||
577 | unsigned int Header[] = {1, 1, 1}; |
643 | unsigned int Header[] = {1, 1, 1}; |
578 | int ret = 0; |
644 | int ret = 0; |
579 | 645 | ||
580 | ret = recv(sock, (char*)Header, sizeHeader, 0); |
646 | ret = recv(sock, (char*)Header, sizeHeader, 0); |
581 | if(ret <= 0 && EndADC == 1) { |
- | |
582 |
|
647 | //if(ret <= 0) printf("Fatal ADC ERROR : recv\n"); |
583 |
|
648 | if(ret <= 0 && EndADC == 1) return -1; |
584 | } |
- | |
585 | 649 | ||
586 | // sleep necessary! ERRORS happen if trigger rate lower than ~ sleep frequency! |
650 | // sleep necessary! ERRORS happen if trigger rate lower than ~ sleep frequency! |
587 | usleep(200); |
651 | usleep(200); |
588 | //Sleep(1); |
652 | //Sleep(1); |
589 | 653 | ||
Line 596... | Line 660... | ||
596 | unsigned int sizeData = (sizeof(int)*Header[1] & 0xffff); |
660 | unsigned int sizeData = (sizeof(int)*Header[1] & 0xffff); |
597 | unsigned int NofWord = (Header[1] & 0xffff); |
661 | unsigned int NofWord = (Header[1] & 0xffff); |
598 | unsigned int OneData[NofWord]; |
662 | unsigned int OneData[NofWord]; |
599 | 663 | ||
600 | recv(socket, (char*)OneData, sizeData, 0); |
664 | recv(socket, (char*)OneData, sizeData, 0); |
601 | - | ||
- | 665 | if(!stopping) { |
|
602 |
|
666 | for(int i = 0; i<NofWord; ++i) printf("[%d] 0x%x ", i, OneData[i]); |
- | 667 | printf("\n"); |
|
603 | 668 | } |
|
604 | memcpy(ptr_DataBuf, Header, sizeHeader); |
669 | memcpy(ptr_DataBuf, Header, sizeHeader); |
605 | ptr_DataBuf += NofHeader; |
670 | ptr_DataBuf += NofHeader; |
606 | 671 | ||
607 | memcpy(ptr_DataBuf, OneData, sizeData); |
672 | memcpy(ptr_DataBuf, OneData, sizeData); |
608 | ptr_DataBuf += sizeData/sizeof(int); |
673 | ptr_DataBuf += sizeData/sizeof(int); |
609 | 674 | ||
610 | TotalRecvByte += sizeHeader + sizeData; |
675 | TotalRecvByte += sizeHeader + sizeData; |
611 | ++TotalRecvEvent; |
676 | ++TotalRecvEvent; |
612 | } |
677 | } |
613 | 678 | ||
614 | if(EndADC != 1){ |
679 | if(EndADC != 1 && file!=NULL){ |
615 | for(unsigned int i = 0; i<TotalRecvByte/sizeof(int); ++i) { |
680 | for(unsigned int i = 0; i<TotalRecvByte/sizeof(int); ++i) { |
616 | unsigned int buffer = DataBuffer[i]; |
681 | unsigned int buffer = DataBuffer[i]; |
617 | fwrite((char*)&buffer, sizeof(int), 1, file); |
682 | fwrite((char*)&buffer, sizeof(int), 1, file); |
618 | } |
683 | } |
619 | } |
684 | } |
620 | 685 | ||
621 | return 0; |
686 | return 0; |
622 | } |
687 | } |
623 | //------------------------------------------------------------------------------------------------------ |
688 | //------------------------------------------------------------------------------------------------------ |
624 | void ADCStop(SOCKET socket) |
689 | void ADCStop(SOCKET socket) |
625 | { |
690 | { |
626 | unsigned int signal = 0; |
691 | unsigned int signal = 0; |
627 | printf("ADC exit process\n"); |
692 | printf("ADC exit process\n"); |
628 | signal += 16 << 24; |
693 | signal += 16 << 24; |
629 | signal += 100 << 16; |
694 | signal += 100 << 16; |
630 | send(socket, (char*)&signal, sizeof(int), 0); |
695 | send(socket, (char*)&signal, sizeof(int), 0); |
631 | Sleep(1); |
696 | Sleep(1); |
632 | 697 | ||
633 | signal = 0; |
698 | signal = 0; |
634 | signal += 100 << 16; |
699 | signal += 100 << 16; |
Line 653... | Line 718... | ||
653 | } |
718 | } |
654 | 719 | ||
655 | signal += 32 << 24; |
720 | signal += 32 << 24; |
656 | signal += 100 << 16; |
721 | signal += 100 << 16; |
657 | send(socket, (char*)&signal, sizeof(int), 0); |
722 | send(socket, (char*)&signal, sizeof(int), 0); |
658 | Sleep(100); |
723 | Sleep(100); |
659 | 724 | ||
660 | while(EventNum < MaxCycleNum){ |
725 | while(EventNum < MaxCycleNum){ |
661 | //Sleep(10); |
726 | //Sleep(10); |
662 | ADCOneCycle_wHeader_ver2(socket, file); |
727 | ADCOneCycle_wHeader_ver2(socket, file, 0); |
663 | ++EventNum; |
728 | ++EventNum; |
664 | if(0 == EventNum%1000){ |
729 | if(0 == EventNum%1000){ |
665 | printf("Event # %d\n", EventNum); |
730 | printf("Event # %d\n", EventNum); |
666 | } |
731 | } |
667 | 732 | ||
668 | if(0 || EventNum == MaxCycleNum|| ForceStop == 1) { |
733 | if(0 || EventNum == MaxCycleNum|| ForceStop == 1) { |
669 | ADCStop(socket); |
734 | ADCStop(socket); |
670 | 735 | ||
671 | EndADC = 1; |
736 | EndADC = 1; |
672 | int abort = 0; |
737 | int abort = 0; |
673 | while(0 == ADCOneCycle_wHeader_ver2(socket, file)) { |
738 | while(0 == ADCOneCycle_wHeader_ver2(socket, file, 1)) { |
674 | Sleep(1); |
739 | Sleep(1); |
675 | if(abort == 50) { |
740 | if(abort == 50) { |
676 | ADCStop(socket); |
741 | ADCStop(socket); |
677 | abort = 0; |
742 | abort = 0; |
678 | } |
743 | } |
Line 682... | Line 747... | ||
682 | } |
747 | } |
683 | 748 | ||
684 | EndADC = 0; |
749 | EndADC = 0; |
685 | ForceStop = 0; |
750 | ForceStop = 0; |
686 | break; |
751 | break; |
687 | } |
752 | } |
688 | } |
753 | } |
689 | 754 | ||
690 | printf("\nEnd ADC\n"); |
755 | printf("\nEnd ADC\n"); |
691 | fclose(file); |
756 | fclose(file); |
692 | 757 | ||
693 | return 0; |
758 | return 0; |
694 | } |
759 | } |
695 | //------------------------------------------------------------------------------------------------------ |
760 | //------------------------------------------------------------------------------------------------------ |
696 | int easiroc_fDAQ(char *file_name, int MaxCycleNum) |
761 | int easiroc_fDAQ(char *file_name, int MaxCycleNum) |
697 | { |
762 | { |
698 | printf("easiroc_fDAQ: Starting DAQ with file_name = %s | MaxCycleNum = %d\n", file_name, MaxCycleNum); |
763 | printf("easiroc_fDAQ: Starting DAQ with file_name = %s | MaxCycleNum = %d\n", file_name, MaxCycleNum); |
699 | if(ContinuousADC_ver2(sock, file_name, MaxCycleNum) != 0) return -1; |
764 | if(ContinuousADC_ver2(sock, file_name, MaxCycleNum) != 0) return -1; |
700 | 765 | ||
701 | return 0; |
766 | return 0; |
- | 767 | } |
|
- | 768 | //------------------------------------------------------------------------------------------------------ |
|
- | 769 | int easiroc_singleADCstart() { |
|
- | 770 | unsigned int signal = 0; |
|
- | 771 | ||
- | 772 | signal += 32 << 24; |
|
- | 773 | signal += 100 << 16; |
|
- | 774 | send(sock, (char*)&signal, sizeof(int), 0); |
|
- | 775 | Sleep(100); |
|
- | 776 | ||
- | 777 | printf("\nStart ADC\n"); |
|
- | 778 | ||
- | 779 | return 0; |
|
- | 780 | } |
|
- | 781 | //------------------------------------------------------------------------------------------------------ |
|
- | 782 | int easiroc_singleADCevent(unsigned int *retData) { |
|
- | 783 | static const int NofHeader = 3; |
|
- | 784 | ||
- | 785 | unsigned int DataBuffer[1000]; |
|
- | 786 | memset(DataBuffer, 0, sizeof(DataBuffer)); |
|
- | 787 | ||
- | 788 | unsigned int sizeHeader = NofHeader*sizeof(int); |
|
- | 789 | ||
- | 790 | unsigned int Header[] = {1, 1, 1}; |
|
- | 791 | int ret = 0; |
|
- | 792 | ||
- | 793 | ret = recv(sock, (char*)Header, sizeHeader, 0); |
|
- | 794 | //if(ret <= 0) printf("Fatal ADC ERROR : recv\n"); |
|
- | 795 | if(ret <= 0 && EndADC == 1) return -1; |
|
- | 796 | ||
- | 797 | //usleep(200); |
|
- | 798 | //Sleep(1); |
|
- | 799 | ||
- | 800 | //printf("Header1 (0xFFFFEA0C) : 0x%x | Header2 (0x00000100) : 0x%x\n", Header[0], Header[1]); |
|
- | 801 | if(Header[0] != 0xFFFFEA0C) { |
|
- | 802 | printf("Fatal ADC ERROR : HEADER\n"); |
|
- | 803 | printf("Header1 : 0x%x | Header2 : 0x%x | Header3 : 0x%x\n", Header[0], Header[1], Header[2]); |
|
- | 804 | return -2; |
|
- | 805 | } else { |
|
- | 806 | unsigned int sizeData = (sizeof(int)*Header[1] & 0xffff); |
|
- | 807 | unsigned int NofWord = (Header[1] & 0xffff); |
|
- | 808 | unsigned int OneData[NofWord]; |
|
- | 809 | ||
- | 810 | recv(sock, (char*)OneData, sizeData, 0); |
|
- | 811 | ||
- | 812 | //for(int i = 0; i<NofWord; ++i) printf("[%d] 0x%x ", i, OneData[i]); |
|
- | 813 | //printf("\n"); |
|
- | 814 | ||
- | 815 | if(NofWord < EASIROC_MAX_READ_N_WORDS) memcpy(retData, OneData, sizeData); |
|
- | 816 | ||
- | 817 | return NofWord; |
|
- | 818 | } |
|
- | 819 | } |
|
- | 820 | //------------------------------------------------------------------------------------------------------ |
|
- | 821 | int easiroc_singleADCstop() { |
|
- | 822 | ADCStop(sock); |
|
- | 823 | ||
- | 824 | EndADC = 1; |
|
- | 825 | int abort = 0; |
|
- | 826 | while(0 == ADCOneCycle_wHeader_ver2(sock, NULL, 1)) { |
|
- | 827 | Sleep(1); |
|
- | 828 | if(abort == 50) { |
|
- | 829 | ADCStop(sock); |
|
- | 830 | abort = 0; |
|
- | 831 | } |
|
- | 832 | //printf("dummy data\n"); |
|
- | 833 | printf("."); |
|
- | 834 | ++abort; |
|
- | 835 | } |
|
- | 836 | ||
- | 837 | EndADC = 0; |
|
- | 838 | ForceStop = 0; |
|
- | 839 | ||
- | 840 | printf("\nEnd ADC\n"); |
|
- | 841 | ||
- | 842 | return 0; |
|
702 | } |
843 | } |
- | 844 | //------------------------------------------------------------------------------------------------------ |
|
703 | 845 | ||
704 | 846 | ||
705 | 847 |