Skip to content

Commit

Permalink
WIP: Initial work on constraint file support. Not yet usable.
Browse files Browse the repository at this point in the history
azonenberg committed Feb 15, 2017
1 parent da9be6a commit 3c0011c
Showing 6 changed files with 58 additions and 10 deletions.
31 changes: 26 additions & 5 deletions doc/gp4-hdl.tex
Original file line number Diff line number Diff line change
@@ -261,18 +261,39 @@ \subsection{\namestyle{Yosys} Verilog Inference Limitations for GreenPAK}
\pagebreak
\section{\namestyle{gp4par} HDL Constraints}

There is only one supported constraint entry format at this time, Verilog attributes. There is currently no support for
adding constraints to netlist entities via external constraint files or command line arguments. The general format of a
constraint with name \tokenstyle{FOO} and value 42 applied to the register \wirestyle{foobar} is shown in Figure
\ref{constraint}.
Constraints may be entered by Verilog attributes or an external Physical Constraints File (.pcf) file. In the event of
a conflict, the PCF takes precedence over constraints in the Verilog. If two constraints in the same PCF file conflict,
the later constraint takes precedence.

\subsection{Verilog attributes}

The general format of a constraint with name \tokenstyle{FOO} and value 42 applied to the register \wirestyle{foobar}
is shown in Figure \ref{constraint-verilog}.

\begin{figure}[h]
\begin{lstlisting}
(* FOO=42 *)
reg[3:0] foobar = 0;
\end{lstlisting}
\caption{Example Verilog attribute constraint}
\label{constraint}
\label{constraint-verilog}
\end{figure}

\subsection{PCF constraints}

\namestyle{gp4par} PCF files used a syntax similar to that of the industry standard Synopsys Design Constraints (SDC).
Only constraints are supported; arbitrary TCL cannot be used.

The general format of a constraint with name \tokenstyle{FOO} and value 42 applied to the register \wirestyle{foobar}
is shown in Figure \ref{constraint-pcf}.

\begin{figure}[h]
\begin{lstlisting}
# set some random attribute
set_foo foobar 42
\end{lstlisting}
\caption{Example PCF constraint}
\label{constraint-pcf}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 changes: 3 additions & 1 deletion src/gp4par/main.cpp
Original file line number Diff line number Diff line change
@@ -328,7 +328,9 @@ int main(int argc, char* argv[])
void ShowUsage()
{
printf(// v 80th column
"Usage: gp4par -p part -o bitstream.txt netlist.json\n"
"Usage: gp4par [options] -p part -o bitstream.txt netlist.json\n"
" -c <file>\n"
" Reads placement constraints from <file>\n"
" --debug\n"
" Prints lots of internal debugging information.\n"
" --disable-charge-pump\n"
23 changes: 22 additions & 1 deletion src/greenpak4/Greenpak4Netlist.cpp
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ Greenpak4NetlistEntity::~Greenpak4NetlistEntity()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

Greenpak4Netlist::Greenpak4Netlist(std::string fname)
Greenpak4Netlist::Greenpak4Netlist(string fname, string constraint_file)
: m_topModule(NULL)
, m_parseOK(true)
{
@@ -94,6 +94,19 @@ Greenpak4Netlist::Greenpak4Netlist(std::string fname)
json_object_put(object);
json_tokener_free(tok);
delete[] json_string;

//Read the constraint file (if we have one)
if(constraint_file == "")
return;
fp = fopen(constraint_file.c_str(), "r");
if(fp == NULL)
{
LogError("Failed to open constraint file %s\n", fname.c_str());
m_parseOK = false;
return;
}
LoadConstraints(fp);
fclose(fp);
}

Greenpak4Netlist::~Greenpak4Netlist()
@@ -107,6 +120,14 @@ Greenpak4Netlist::~Greenpak4Netlist()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Parsing stuff

/**
@brief Parsing for a PCF file
*/
void Greenpak4Netlist::LoadConstraints(FILE* fp)
{

}

/**
@brief Top-level parsing routine
3 changes: 2 additions & 1 deletion src/greenpak4/Greenpak4Netlist.h
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
class Greenpak4Netlist
{
public:
Greenpak4Netlist(std::string fname);
Greenpak4Netlist(std::string fname, std::string constraint_file = "");
virtual ~Greenpak4Netlist();

Greenpak4NetlistModule* GetTopModule()
@@ -64,6 +64,7 @@ class Greenpak4Netlist
//Init helpers
void Load(json_object* object);
void LoadModules(json_object* object);
void LoadConstraints(FILE* fp);

std::string m_creator;

2 changes: 1 addition & 1 deletion tests/greenpak4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ function(add_greenpak4_bitstream name part)
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.txt"
COMMAND gp4par "--stdout-only"
--usercode 41
--quiet
# --quiet
--part ${part}
--output "${CMAKE_CURRENT_BINARY_DIR}/${name}.txt"
--logfile "${CMAKE_CURRENT_BINARY_DIR}/${name}-par.log"
5 changes: 4 additions & 1 deletion tests/greenpak4/slg46620v/Location.v
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

`default_nettype none

module Location(a, b, c, d, e);
module Location(a, b, c, d, e, f);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// I/O declarations
@@ -41,6 +41,9 @@ module Location(a, b, c, d, e);
(* LOC = "P16" *)
input wire e;

//LOC'd by constraint file
output wire f;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Clock/reset stuff

0 comments on commit 3c0011c

Please sign in to comment.