Skip to content

Commit 47eba72

Browse files
committedMay 31, 2017
Continued work on GreenPAK timing characterization
1 parent 57abc63 commit 47eba72

File tree

2 files changed

+171
-27
lines changed

2 files changed

+171
-27
lines changed
 

Diff for: ‎src/gp4tchar/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ add_executable(gp4tchar
22
main.cpp)
33

44
target_link_libraries(gp4tchar
5-
gpdevboard greenpak4)
5+
gpdevboard greenpak4 xptools)
66

77
#Don't install, this is a development tool only
88
#install(TARGETS gp4tchar

Diff for: ‎src/gp4tchar/main.cpp

+170-26
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,28 @@
2323
#include <log.h>
2424
#include <gpdevboard.h>
2525
#include <Greenpak4.h>
26+
#include "../xptools/Socket.h"
27+
28+
#ifndef _WIN32
29+
#include <termios.h>
30+
#else
31+
#include <conio.h>
32+
#endif
2633

2734
using namespace std;
2835

29-
hdevice InitializeHardware(unsigned int nboard, SilegoPart expectedPart);
30-
bool DoInitializeHardware(hdevice hdev, SilegoPart expectedPart);
36+
bool InitializeHardware(hdevice hdev, SilegoPart expectedPart);
3137
bool PostProgramSetup(hdevice hdev);
3238
bool IOReset(hdevice hdev);
3339
bool IOSetup(hdevice hdev);
3440
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
3548

3649
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3750
// Entry point
@@ -41,6 +54,9 @@ int main(int argc, char* argv[])
4154
Severity console_verbosity = Severity::NOTICE;
4255
unsigned int nboard = 0;
4356

57+
string server;
58+
int port = 0;
59+
4460
//Parse command-line arguments
4561
for(int i=1; i<argc; i++)
4662
{
@@ -50,6 +66,11 @@ int main(int argc, char* argv[])
5066
if(ParseLoggerArguments(i, argc, argv, console_verbosity))
5167
continue;
5268

69+
else if(s == "--port")
70+
port = atoi(argv[++i]);
71+
else if(s == "--server")
72+
server = argv[++i];
73+
5374
else if(s == "--device")
5475
{
5576
if(i+1 < argc)
@@ -72,6 +93,48 @@ int main(int argc, char* argv[])
7293
//Set up logging
7394
g_log_sinks.emplace(g_log_sinks.begin(), new STDLogSink(console_verbosity));
7495

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+
/*
75138
//Hardware configuration
76139
Greenpak4Device::GREENPAK4_PART part = Greenpak4Device::GREENPAK4_SLG46620;
77140
SilegoPart spart = SilegoPart::SLG46620V;
@@ -112,7 +175,7 @@ int main(int argc, char* argv[])
112175
113176
//Wait a bit
114177
usleep(5000 * 1000);
115-
178+
*/
116179
//Done
117180
LogNotice("Done, resetting board\n");
118181
SetStatusLED(hdev, 0);
@@ -125,28 +188,6 @@ int main(int argc, char* argv[])
125188
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126189
// Board initialization
127190

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-
150191
bool PostProgramSetup(hdevice hdev)
151192
{
152193
//Clear I/Os from programming mode
@@ -203,7 +244,7 @@ bool PowerSetup(hdevice hdev)
203244
return ConfigureSiggen(hdev, 1, voltage);
204245
}
205246

206-
bool DoInitializeHardware(hdevice hdev, SilegoPart expectedPart)
247+
bool InitializeHardware(hdevice hdev, SilegoPart expectedPart)
207248
{
208249
//Figure out what's there
209250
SilegoPart detectedPart = SilegoPart::UNRECOGNIZED;
@@ -231,3 +272,106 @@ bool DoInitializeHardware(hdevice hdev, SilegoPart expectedPart)
231272

232273
return true;
233274
}
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

Comments
 (0)