Skip to content

Commit 9e24e43

Browse files
committedMay 31, 2017
More initial work on timing characterization stuff
1 parent 8eee84a commit 9e24e43

File tree

3 files changed

+138
-43
lines changed

3 files changed

+138
-43
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)
5+
gpdevboard greenpak4)
66

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

Diff for: ‎src/gp4tchar/main.cpp

+131-42
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
#include <unistd.h>
2323
#include <log.h>
2424
#include <gpdevboard.h>
25-
#ifndef _WIN32
26-
#include <termios.h>
27-
#else
28-
#include <conio.h>
29-
#endif
25+
#include <Greenpak4.h>
3026

3127
using namespace std;
3228

29+
hdevice InitializeHardware(unsigned int nboard, SilegoPart expectedPart);
30+
bool DoInitializeHardware(hdevice hdev, SilegoPart expectedPart);
31+
bool PostProgramSetup(hdevice hdev);
32+
bool IOReset(hdevice hdev);
33+
bool IOSetup(hdevice hdev);
34+
bool PowerSetup(hdevice hdev);
35+
3336
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3437
// Entry point
3538

@@ -69,35 +72,113 @@ int main(int argc, char* argv[])
6972
//Set up logging
7073
g_log_sinks.emplace(g_log_sinks.begin(), new STDLogSink(console_verbosity));
7174

72-
//Print status message
75+
//Hardware configuration
76+
Greenpak4Device::GREENPAK4_PART part = Greenpak4Device::GREENPAK4_SLG46620;
77+
SilegoPart spart = SilegoPart::SLG46620V;
78+
Greenpak4IOB::PullDirection unused_pull = Greenpak4IOB::PULL_DOWN;
79+
Greenpak4IOB::PullStrength unused_drive = Greenpak4IOB::PULL_1M;
80+
81+
//Print status message and set up the board
7382
LogNotice("GreenPAK timing characterization helper\n");
74-
LogNotice("Right now, just enables pins used by pmod-gpdevboard and sets up IO\n");
83+
hdevice hdev = InitializeHardware(nboard, spart);
84+
if(!hdev)
85+
return 1;
86+
87+
//Create the device object
88+
Greenpak4Device device(part, unused_pull, unused_drive);
89+
device.SetIOPrecharge(false);
90+
device.SetDisableChargePump(false);
91+
device.SetLDOBypass(false);
92+
device.SetNVMRetryCount(1);
93+
94+
//Configure pin 5 as an output and drive it high
95+
auto iob = device.GetIOB(5);
96+
auto vdd = device.GetPower();
97+
iob->SetInput("IN", vdd);
98+
iob->SetDriveType(Greenpak4IOB::DRIVE_PUSHPULL);
99+
iob->SetDriveStrength(Greenpak4IOB::DRIVE_1X);
100+
101+
//Generate a bitstream
102+
vector<uint8_t> bitstream;
103+
device.WriteToBuffer(bitstream, 0, false);
104+
device.WriteToFile("/tmp/test.txt", 0, false);
105+
106+
//Emulate the device
107+
LogVerbose("Loading new bitstream\n");
108+
if(!DownloadBitstream(hdev, bitstream, DownloadMode::EMULATION))
109+
return 1;
110+
if(!PostProgramSetup(hdev))
111+
return 1;
112+
113+
//Wait a bit
114+
usleep(5000 * 1000);
115+
116+
//Done
117+
LogNotice("Done, resetting board\n");
118+
SetStatusLED(hdev, 0);
119+
Reset(hdev);
120+
USBCleanup(hdev);
121+
122+
return 0;
123+
}
124+
125+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126+
// Board initialization
75127

128+
hdevice InitializeHardware(unsigned int nboard, SilegoPart expectedPart)
129+
{
76130
//Open the dev board
77131
hdevice hdev = OpenBoard(nboard);
78132
if(!hdev)
79-
return 1;
133+
return NULL;
80134

81-
//Light up the status LED
82-
if(!SetStatusLED(hdev, 1))
83-
return 1;
135+
//Light it up so we know it's busy
136+
SetStatusLED(hdev, 1);
84137

85-
//DO NOT do anything that might make the IO voltage change, or send Vpp!
138+
//Set it up
139+
if(!DoInitializeHardware(hdev, expectedPart))
140+
{
141+
SetStatusLED(hdev, 0);
142+
Reset(hdev);
143+
USBCleanup(hdev);
144+
return NULL;
145+
}
86146

87-
//Reset all signal generators we may have used during setup
88-
if(!ResetAllSiggens(hdev))
89-
return 1;
147+
return hdev;
148+
}
149+
150+
bool PostProgramSetup(hdevice hdev)
151+
{
152+
//Clear I/Os from programming mode
153+
if(!IOReset(hdev))
154+
return false;
155+
156+
//Load the new configuration
157+
if(!IOSetup(hdev))
158+
return false;
159+
if(!PowerSetup(hdev))
160+
return false;
161+
162+
return true;
163+
}
90164

91-
//Reset I/O config
165+
bool IOReset(hdevice hdev)
166+
{
92167
IOConfig ioConfig;
93168
for(size_t i = 2; i <= 20; i++)
94169
ioConfig.driverConfigs[i] = TP_RESET;
95170
if(!SetIOConfig(hdev, ioConfig))
96171
return false;
97172

173+
return true;
174+
}
175+
176+
bool IOSetup(hdevice hdev)
177+
{
178+
//Enable the I/O pins
98179
unsigned int pins[] =
99180
{
100-
2, 3, 4, 5, 12, 13, 14, 15
181+
3, 4, 5, 12, 13, 14, 15
101182
};
102183

103184
//Configure I/O voltage
@@ -109,36 +190,44 @@ int main(int argc, char* argv[])
109190
config.expansionEnabled[npin] = true;
110191
}
111192
if(!SetIOConfig(hdev, config))
112-
return 1;
193+
return false;
194+
195+
return true;
196+
}
113197

198+
bool PowerSetup(hdevice hdev)
199+
{
114200
//Do not change this voltage! This is what the FPGA uses
201+
//TODO: sweep from 3.15 to 3.45 to do voltage corner analysis
115202
float voltage = 3.3;
116-
if(!ConfigureSiggen(hdev, 1, voltage))
117-
return 1;
203+
return ConfigureSiggen(hdev, 1, voltage);
204+
}
118205

119-
//Hold the lock until something happens
120-
bool lock = true;
121-
if(lock)
206+
bool DoInitializeHardware(hdevice hdev, SilegoPart expectedPart)
207+
{
208+
//Figure out what's there
209+
SilegoPart detectedPart = SilegoPart::UNRECOGNIZED;
210+
vector<uint8_t> programmedBitstream;
211+
BitstreamKind bitstreamKind;
212+
if(!DetectPart(hdev, detectedPart, programmedBitstream, bitstreamKind))
213+
return false;
214+
215+
//Complain if we got something funny
216+
if(expectedPart != detectedPart)
122217
{
123-
LogNotice("Holding lock on board, press any key to exit...\n");
124-
SetStatusLED(hdev, 1);
125-
126-
#ifndef _WIN32
127-
struct termios oldt, newt;
128-
tcgetattr ( STDIN_FILENO, &oldt );
129-
newt = oldt;
130-
newt.c_lflag &= ~( ICANON | ECHO );
131-
tcsetattr ( STDIN_FILENO, TCSANOW, &newt );
132-
getchar();
133-
tcsetattr ( STDIN_FILENO, TCSANOW, &oldt );
134-
#else
135-
_getch();
136-
#endif
218+
LogError("Detected wrong part (not what we're trying to characterize)\n");
219+
return false;
137220
}
138221

139-
//Done
140-
LogNotice("Done, resetting board\n");
141-
SetStatusLED(hdev, 0);
142-
Reset(hdev);
143-
USBCleanup(hdev);
222+
//Get the board into a known state
223+
if(!ResetAllSiggens(hdev))
224+
return false;
225+
if(!IOReset(hdev))
226+
return false;
227+
if(!IOSetup(hdev))
228+
return false;
229+
if(!PowerSetup(hdev))
230+
return false;
231+
232+
return true;
144233
}

Diff for: ‎src/greenpak4/Greenpak4IOB.h

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ class Greenpak4IOB : public Greenpak4BitstreamEntity
125125
void SetAnalogConfigBase(unsigned int base)
126126
{ m_analogConfigBase = base; }
127127

128+
void SetDriveType(DriveType type)
129+
{ m_driveType = type; }
130+
131+
void SetDriveStrength(DriveStrength strength)
132+
{ m_driveStrength = strength; }
133+
128134
//Get our source (used for DRC)
129135
Greenpak4EntityOutput GetOutputSignal()
130136
{ return m_outputSignal; }

0 commit comments

Comments
 (0)
Please sign in to comment.