23
23
#include < log.h>
24
24
#include < gpdevboard.h>
25
25
#include < Greenpak4.h>
26
+ #include " ../xptools/Socket.h"
27
+
28
+ #ifndef _WIN32
29
+ #include < termios.h>
30
+ #else
31
+ #include < conio.h>
32
+ #endif
26
33
27
34
using namespace std ;
28
35
29
- hdevice InitializeHardware (unsigned int nboard, SilegoPart expectedPart);
30
- bool DoInitializeHardware (hdevice hdev, SilegoPart expectedPart);
36
+ bool InitializeHardware (hdevice hdev, SilegoPart expectedPart);
31
37
bool PostProgramSetup (hdevice hdev);
32
38
bool IOReset (hdevice hdev);
33
39
bool IOSetup (hdevice hdev);
34
40
bool PowerSetup (hdevice hdev);
41
+ bool CalibrateTraceDelays (Socket& sock, hdevice hdev);
42
+ bool MeasureDelay (Socket& sock, int src, int dst, float & delay);
43
+
44
+ void WaitForKeyPress ();
45
+
46
+ float g_pinDelays[21 ]; // 0 is unused so we can use 1-based pin numbering like the chip does
47
+ // For now, only pins 3-4-5 are used
35
48
36
49
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37
50
// Entry point
@@ -41,6 +54,9 @@ int main(int argc, char* argv[])
41
54
Severity console_verbosity = Severity::NOTICE;
42
55
unsigned int nboard = 0 ;
43
56
57
+ string server;
58
+ int port = 0 ;
59
+
44
60
// Parse command-line arguments
45
61
for (int i=1 ; i<argc; i++)
46
62
{
@@ -50,6 +66,11 @@ int main(int argc, char* argv[])
50
66
if (ParseLoggerArguments (i, argc, argv, console_verbosity))
51
67
continue ;
52
68
69
+ else if (s == " --port" )
70
+ port = atoi (argv[++i]);
71
+ else if (s == " --server" )
72
+ server = argv[++i];
73
+
53
74
else if (s == " --device" )
54
75
{
55
76
if (i+1 < argc)
@@ -72,6 +93,48 @@ int main(int argc, char* argv[])
72
93
// Set up logging
73
94
g_log_sinks.emplace (g_log_sinks.begin (), new STDLogSink (console_verbosity));
74
95
96
+ // Connect to the server
97
+ if ( (server == " " ) || (port == 0 ) )
98
+ {
99
+ LogError (" No server or port name specified\n " );
100
+ return 1 ;
101
+ }
102
+ Socket sock (AF_INET6, SOCK_STREAM, IPPROTO_TCP);
103
+ if (!sock.Connect (server, port))
104
+ {
105
+ LogError (" Failed to connect to GreenpakTimingTest server\n " );
106
+ return 1 ;
107
+ }
108
+
109
+ // Open the dev board
110
+ hdevice hdev = OpenBoard (nboard);
111
+ if (!hdev)
112
+ return 1 ;
113
+
114
+ // Light it up so we know it's busy
115
+ SetStatusLED (hdev, 1 );
116
+
117
+ // Do initial loopback characterization
118
+ // TODO: allow these to be specified by cmdline arg or file or something, so we don't have to redo it every time
119
+ if (!CalibrateTraceDelays (sock, hdev))
120
+ {
121
+ SetStatusLED (hdev, 0 );
122
+ Reset (hdev);
123
+ USBCleanup (hdev);
124
+ return 1 ;
125
+ }
126
+
127
+ /*
128
+ if(!InitializeHardware(hdev, expectedPart))
129
+ {
130
+ SetStatusLED(hdev, 0);
131
+ Reset(hdev);
132
+ USBCleanup(hdev);
133
+ return NULL;
134
+ }
135
+ */
136
+
137
+ /*
75
138
//Hardware configuration
76
139
Greenpak4Device::GREENPAK4_PART part = Greenpak4Device::GREENPAK4_SLG46620;
77
140
SilegoPart spart = SilegoPart::SLG46620V;
@@ -112,7 +175,7 @@ int main(int argc, char* argv[])
112
175
113
176
//Wait a bit
114
177
usleep(5000 * 1000);
115
-
178
+ */
116
179
// Done
117
180
LogNotice (" Done, resetting board\n " );
118
181
SetStatusLED (hdev, 0 );
@@ -125,28 +188,6 @@ int main(int argc, char* argv[])
125
188
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126
189
// Board initialization
127
190
128
- hdevice InitializeHardware (unsigned int nboard, SilegoPart expectedPart)
129
- {
130
- // Open the dev board
131
- hdevice hdev = OpenBoard (nboard);
132
- if (!hdev)
133
- return NULL ;
134
-
135
- // Light it up so we know it's busy
136
- SetStatusLED (hdev, 1 );
137
-
138
- // Set it up
139
- if (!DoInitializeHardware (hdev, expectedPart))
140
- {
141
- SetStatusLED (hdev, 0 );
142
- Reset (hdev);
143
- USBCleanup (hdev);
144
- return NULL ;
145
- }
146
-
147
- return hdev;
148
- }
149
-
150
191
bool PostProgramSetup (hdevice hdev)
151
192
{
152
193
// Clear I/Os from programming mode
@@ -203,7 +244,7 @@ bool PowerSetup(hdevice hdev)
203
244
return ConfigureSiggen (hdev, 1 , voltage);
204
245
}
205
246
206
- bool DoInitializeHardware (hdevice hdev, SilegoPart expectedPart)
247
+ bool InitializeHardware (hdevice hdev, SilegoPart expectedPart)
207
248
{
208
249
// Figure out what's there
209
250
SilegoPart detectedPart = SilegoPart::UNRECOGNIZED;
@@ -231,3 +272,106 @@ bool DoInitializeHardware(hdevice hdev, SilegoPart expectedPart)
231
272
232
273
return true ;
233
274
}
275
+
276
+ void WaitForKeyPress ()
277
+ {
278
+ LogNotice (" Press any key to continue . . .\n " );
279
+
280
+ #ifndef _WIN32
281
+ struct termios oldt, newt;
282
+ tcgetattr ( STDIN_FILENO, &oldt );
283
+ newt = oldt;
284
+ newt.c_lflag &= ~( ICANON | ECHO );
285
+ tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
286
+ getchar ();
287
+ tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
288
+ #else
289
+ _getch ();
290
+ #endif
291
+ }
292
+
293
+ // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
294
+ // Initial measurement calibration
295
+
296
+ bool CalibrateTraceDelays (Socket& sock, hdevice hdev)
297
+ {
298
+ LogNotice (" Calibrate FPGA-to-DUT trace delays\n " );
299
+ LogIndenter li;
300
+
301
+ if (!IOSetup (hdev))
302
+ return false ;
303
+
304
+ float delay_34;
305
+ float delay_35;
306
+ float delay_45;
307
+
308
+ // delay_34 = A + B
309
+ LogNotice (" Use a jumper to short pins 3 and 4 on the ZIF header\n " );
310
+ {
311
+ LogIndenter li;
312
+
313
+ WaitForKeyPress ();
314
+ if (!MeasureDelay (sock, 3 , 4 , delay_34))
315
+ return false ;
316
+ LogNotice (" Measured trace delay: %.3f ns\n " , delay_34);
317
+ }
318
+
319
+ // delay_35 = A + C
320
+ LogNotice (" Use a jumper to short pins 3 and 5 on the ZIF header\n " );
321
+ {
322
+ LogIndenter li;
323
+
324
+ WaitForKeyPress ();
325
+ if (!MeasureDelay (sock, 3 , 5 , delay_35))
326
+ return false ;
327
+ LogNotice (" Measured trace delay: %.3f ns\n " , delay_35);
328
+ }
329
+
330
+ // delay_45 = B + C
331
+ LogNotice (" Use a jumper to short pins 4 and 5 on the ZIF header\n " );
332
+ {
333
+ LogIndenter li;
334
+
335
+ WaitForKeyPress ();
336
+ if (!MeasureDelay (sock, 4 , 5 , delay_45))
337
+ return false ;
338
+ LogNotice (" Measured trace delay: %.3f ns\n " , delay_45);
339
+ }
340
+
341
+ // Pin 3 delay = A = ( (A+B) + (A+C) - (B+C) ) / 2 = (delay_34 + delay_35 - delay_45) / 2
342
+ g_pinDelays[3 ] = (delay_34 + delay_35 - delay_45) / 2 ;
343
+ g_pinDelays[4 ] = delay_34 - g_pinDelays[3 ];
344
+ g_pinDelays[5 ] = delay_35 - g_pinDelays[3 ];
345
+ LogNotice (" Calculated trace delays:\n " );
346
+ LogIndenter li2;
347
+ for (int i=3 ; i<=5 ; i++)
348
+ LogNotice (" Pin %d: %.3f\n " , i, g_pinDelays[i]);
349
+
350
+ return true ;
351
+ }
352
+
353
+ bool MeasureDelay (Socket& sock, int src, int dst, float & delay)
354
+ {
355
+ // Send test parameters
356
+ uint8_t drive = src;
357
+ uint8_t sample = dst;
358
+ if (!sock.SendLooped (&drive, 1 ))
359
+ return false ;
360
+ if (!sock.SendLooped (&sample, 1 ))
361
+ return false ;
362
+
363
+ // Read the results back
364
+ uint8_t ok;
365
+ if (!sock.RecvLooped (&ok, 1 ))
366
+ return false ;
367
+ if (!sock.RecvLooped ((uint8_t *)&delay, sizeof (delay)))
368
+ return false ;
369
+
370
+ if (!ok)
371
+ {
372
+ LogError (" Couldn't measure delay (open circuit?)\n " );
373
+ return false ;
374
+ }
375
+
376
+ return true ;
377
+ }
0 commit comments