aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2019-10-18 15:58:57 +0100
committerDavid Shah <dave@ds0.me>2019-10-18 15:58:57 +0100
commitcf5cbd1153c3ebaf6bcff98f2d936e1663407dff (patch)
treeed5d58e7f7be8b6340ca0f357816fa3bdc5cd80b
parent872e296f7b6b679be89ad3757a9ff9936dc71ba9 (diff)
downloadnextpnr-cf5cbd1153c3ebaf6bcff98f2d936e1663407dff.tar.gz
nextpnr-cf5cbd1153c3ebaf6bcff98f2d936e1663407dff.tar.bz2
nextpnr-cf5cbd1153c3ebaf6bcff98f2d936e1663407dff.zip
ecp5: Preserve top level IO properly
Signed-off-by: David Shah <dave@ds0.me>
-rw-r--r--common/design_utils.cc12
-rw-r--r--common/design_utils.h3
-rw-r--r--ecp5/cells.cc20
-rw-r--r--ecp5/pack.cc14
4 files changed, 36 insertions, 13 deletions
diff --git a/common/design_utils.cc b/common/design_utils.cc
index bdf5ca5c..10212a03 100644
--- a/common/design_utils.cc
+++ b/common/design_utils.cc
@@ -88,7 +88,7 @@ void connect_port(const Context *ctx, NetInfo *net, CellInfo *cell, IdString por
NPNR_ASSERT(net->driver.cell == nullptr);
net->driver.cell = cell;
net->driver.port = port_name;
- } else if (port.type == PORT_IN) {
+ } else if (port.type == PORT_IN || port.type == PORT_INOUT) {
PortRef user;
user.cell = cell;
user.port = port_name;
@@ -146,4 +146,14 @@ void rename_port(Context *ctx, CellInfo *cell, IdString old_name, IdString new_n
cell->ports[new_name] = pi;
}
+void rename_net(Context *ctx, NetInfo *net, IdString new_name)
+{
+ if (net == nullptr)
+ return;
+ NPNR_ASSERT(!ctx->nets.count(new_name));
+ std::swap(ctx->nets[net->name], ctx->nets[new_name]);
+ ctx->nets.erase(net->name);
+ net->name = new_name;
+}
+
NEXTPNR_NAMESPACE_END
diff --git a/common/design_utils.h b/common/design_utils.h
index 3eb9024f..1ae1d648 100644
--- a/common/design_utils.h
+++ b/common/design_utils.h
@@ -94,6 +94,9 @@ void connect_ports(Context *ctx, CellInfo *cell1, IdString port1_name, CellInfo
// Rename a port if it exists on a cell
void rename_port(Context *ctx, CellInfo *cell, IdString old_name, IdString new_name);
+// Rename a net without invalidating pointers to it
+void rename_net(Context *ctx, NetInfo *net, IdString new_name);
+
void print_utilisation(const Context *ctx);
NEXTPNR_NAMESPACE_END
diff --git a/ecp5/cells.cc b/ecp5/cells.cc
index 37b6ac8b..b70b412d 100644
--- a/ecp5/cells.cc
+++ b/ecp5/cells.cc
@@ -416,7 +416,25 @@ void nxio_to_tr(Context *ctx, CellInfo *nxio, CellInfo *trio, std::vector<std::u
} else {
NPNR_ASSERT(false);
}
- NetInfo *donet = trio->ports.at(ctx->id("I")).net;
+ NetInfo *donet = trio->ports.at(ctx->id("I")).net, *dinet = trio->ports.at(ctx->id("O")).net;
+
+ // Rename I/O nets to avoid conflicts
+ if (donet != nullptr)
+ rename_net(ctx, donet, ctx->id(donet->name.str(ctx) + "$TRELLIS_IO_OUT"));
+ if (dinet != nullptr)
+ rename_net(ctx, dinet, ctx->id(dinet->name.str(ctx) + "$TRELLIS_IO_IN"));
+
+ // Create a new top port net for accurate IO timing analysis and simulation netlists
+ if (ctx->ports.count(nxio->name)) {
+ IdString tn_netname = nxio->name;
+ NPNR_ASSERT(!ctx->nets.count(tn_netname));
+ std::unique_ptr<NetInfo> toplevel_net{new NetInfo};
+ toplevel_net->name = tn_netname;
+ connect_port(ctx, toplevel_net.get(), trio, ctx->id("B"));
+ ctx->ports[nxio->name].net = toplevel_net.get();
+ ctx->nets[tn_netname] = std::move(toplevel_net);
+ }
+
CellInfo *tbuf = net_driven_by(
ctx, donet, [](const Context *ctx, const CellInfo *cell) { return cell->type == ctx->id("$_TBUF_"); },
ctx->id("Y"));
diff --git a/ecp5/pack.cc b/ecp5/pack.cc
index 244a79d5..00ed891a 100644
--- a/ecp5/pack.cc
+++ b/ecp5/pack.cc
@@ -362,8 +362,7 @@ class Ecp5Packer
for (auto &port : ci->ports)
disconnect_port(ctx, ci, port.first);
} else if (trio != nullptr) {
- // Trivial case, TRELLIS_IO used. Just destroy the net and the
- // iobuf
+ // Trivial case, TRELLIS_IO used. Just remove the IOBUF
log_info("%s feeds TRELLIS_IO %s, removing %s %s.\n", ci->name.c_str(ctx), trio->name.c_str(ctx),
ci->type.c_str(ctx), ci->name.c_str(ctx));
@@ -384,14 +383,6 @@ class Ecp5Packer
std::swap(net->clkconstr, onet->clkconstr);
}
}
- ctx->nets.erase(net->name);
- trio->ports.at(ctx->id("B")).net = nullptr;
- }
- if (ci->type == ctx->id("$nextpnr_iobuf")) {
- NetInfo *net2 = ci->ports.at(ctx->id("I")).net;
- if (net2 != nullptr) {
- ctx->nets.erase(net2->name);
- }
}
} else if (drives_top_port(ionet, tp)) {
log_info("%s feeds %s %s.%s, removing %s %s.\n", ci->name.c_str(ctx), tp.cell->type.c_str(ctx),
@@ -414,7 +405,8 @@ class Ecp5Packer
new_cells.push_back(std::move(tr_cell));
trio = new_cells.back().get();
}
-
+ for (auto port : ci->ports)
+ disconnect_port(ctx, ci, port.first);
packed_cells.insert(ci->name);
if (trio != nullptr) {
for (const auto &attr : ci->attrs)