aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nexus/arch.cc44
-rw-r--r--nexus/arch.h18
-rw-r--r--nexus/constids.inc3
-rw-r--r--nexus/pack.cc135
4 files changed, 192 insertions, 8 deletions
diff --git a/nexus/arch.cc b/nexus/arch.cc
index 3799b167..dfcf9510 100644
--- a/nexus/arch.cc
+++ b/nexus/arch.cc
@@ -443,6 +443,50 @@ bool Arch::route()
// -----------------------------------------------------------------------
+CellPinMux Arch::get_cell_pinmux(CellInfo *cell, IdString pin) const
+{
+ IdString param = id(stringf("%sMUX", pin.c_str(this)));
+ auto fnd_param = cell->params.find(param);
+ if (fnd_param == cell->params.end())
+ return PINMUX_SIG;
+ const std::string &pm = fnd_param->second.as_string();
+ if (pm == "0")
+ return PINMUX_0;
+ else if (pm == "1")
+ return PINMUX_1;
+ else if (pm == "INV")
+ return PINMUX_INV;
+ else if (pm == pin.c_str(this))
+ return PINMUX_SIG;
+ else {
+ log_error("Invalid %s setting '%s' for cell '%s'\n", nameOf(param), pm.c_str(), nameOf(cell));
+ NPNR_ASSERT_FALSE("unreachable");
+ }
+}
+
+void Arch::set_cell_pinmux(CellInfo *cell, IdString pin, CellPinMux state)
+{
+ IdString param = id(stringf("%sMUX", pin.c_str(this)));
+ switch (state) {
+ case PINMUX_SIG:
+ cell->params.erase(param);
+ break;
+ case PINMUX_0:
+ cell->params[param] = std::string("0");
+ break;
+ case PINMUX_1:
+ cell->params[param] = std::string("1");
+ break;
+ case PINMUX_INV:
+ cell->params[param] = std::string("INV");
+ break;
+ default:
+ NPNR_ASSERT_FALSE("unreachable");
+ }
+}
+
+// -----------------------------------------------------------------------
+
#ifdef WITH_HEAP
const std::string Arch::defaultPlacer = "heap";
#else
diff --git a/nexus/arch.h b/nexus/arch.h
index 47276f42..6cb7323b 100644
--- a/nexus/arch.h
+++ b/nexus/arch.h
@@ -760,25 +760,32 @@ struct WireBelPinRange
enum CellPinStyle
{
PINOPT_NONE = 0x0, // no options, just signal as-is
- PINOPT_HI = 0x1, // can be tied low
- PINOPT_LO = 0x2, // can be tied high
+ PINOPT_LO = 0x1, // can be tied high
+ PINOPT_HI = 0x2, // can be tied low
PINOPT_INV = 0x4, // can be inverted
PINOPT_LOHI = 0x3, // can be tied low or high
PINOPT_LOHIINV = 0x7, // can be tied low or high; or inverted
+ PINOPT_MASK = 0x7,
+
PINDEF_NONE = 0x00, // leave disconnected
PINDEF_0 = 0x10, // connect to 0 if not used
PINDEF_1 = 0x20, // connect to 1 if not used
+ PINDEF_MASK = 0x30,
+
PINGLB_CLK = 0x100, // pin is a 'clock' for global purposes
- PINSTYLE_CIB = 0x011, // 'CIB' signal, floats high but explicitly zeroed if not used
+ PINGLB_MASK = 0x100,
+
+ PINSTYLE_NONE = 0x000, // default
+ PINSTYLE_CIB = 0x012, // 'CIB' signal, floats high but explicitly zeroed if not used
PINSTYLE_CLK = 0x107, // CLK type signal, invertible and defaults to disconnected
PINSTYLE_CE = 0x027, // CE type signal, invertible and defaults to enabled
PINSTYLE_LSR = 0x017, // LSR type signal, invertible and defaults to not reset
PINSTYLE_DEDI = 0x000, // dedicated signals, leave alone
- PINSTYLE_PU = 0x021, // signals that float high and default high
+ PINSTYLE_PU = 0x022, // signals that float high and default high
PINSTYLE_INV_PD = 0x017, // invertible, pull down by default
PINSTYLE_INV_PU = 0x027, // invertible, pull up by default
@@ -1416,6 +1423,9 @@ struct Arch : BaseCtx
bool nexus_logic_tile_valid(LogicTileStatus &lts) const;
+ CellPinMux get_cell_pinmux(CellInfo *cell, IdString pin) const;
+ void set_cell_pinmux(CellInfo *cell, IdString pin, CellPinMux state);
+
// -------------------------------------------------
void write_fasm(std::ostream &out) const;
};
diff --git a/nexus/constids.inc b/nexus/constids.inc
index 3ee93ea7..1aa36a88 100644
--- a/nexus/constids.inc
+++ b/nexus/constids.inc
@@ -106,6 +106,9 @@ X(CIB_LR)
X(IO_TYPE)
+
+X(OSCA)
+X(OSC)
X(OSC_CORE)
X(HFCLKOUT)
X(LFCLKOUT)
diff --git a/nexus/pack.cc b/nexus/pack.cc
index f367c3f8..602457f5 100644
--- a/nexus/pack.cc
+++ b/nexus/pack.cc
@@ -99,6 +99,8 @@ struct NexusPacker
{
Context *ctx;
+ std::unordered_map<IdString, Arch::CellPinsData> cell_db;
+
// Generic cell transformation
// Given cell name map and port map
// If port name is not found in port map; it will be copied as-is but stripping []
@@ -296,12 +298,68 @@ struct NexusPacker
}
}
- bool is_port_inverted(CellInfo *cell, IdString port)
+ NetInfo *get_const_net(IdString type)
+ {
+ // Gets a constant net, given the driver type (VHI or VLO)
+ // If one doesn't exist already; then create it
+ for (auto cell : sorted(ctx->cells)) {
+ CellInfo *ci = cell.second;
+ if (ci->type != type)
+ continue;
+ NetInfo *z = get_net_or_empty(ci, id_Z);
+ if (z == nullptr)
+ continue;
+ return z;
+ }
+
+ NetInfo *new_net = ctx->createNet(ctx->id(stringf("$CONST_%s_NET_", type.c_str(ctx))));
+ CellInfo *new_cell = ctx->createCell(ctx->id(stringf("$CONST_%s_DRV_", type.c_str(ctx))), type);
+ new_cell->addInput(id_Z);
+ connect_port(ctx, new_net, new_cell, id_Z);
+ return new_net;
+ }
+
+ CellPinStyle get_pin_style(CellInfo *cell, IdString port)
+ {
+ // Look up the pin style in the cell database
+ auto fnd_cell = cell_db.find(cell->type);
+ if (fnd_cell == cell_db.end())
+ return PINSTYLE_NONE;
+ auto fnd_port = fnd_cell->second.find(port);
+ if (fnd_port != fnd_cell->second.end())
+ return fnd_port->second;
+ // If there isn't an exact port match, then the empty IdString
+ // represents a wildcard default match
+ auto fnd_default = fnd_cell->second.find({});
+ if (fnd_default != fnd_cell->second.end())
+ return fnd_default->second;
+
+ return PINSTYLE_NONE;
+ }
+
+ CellPinMux get_pin_needed_muxval(CellInfo *cell, IdString port)
{
NetInfo *net = get_net_or_empty(cell, port);
- if (net == nullptr || net->driver.cell == nullptr)
- return false;
- return (net->driver.cell->type == id_INV);
+ if (net == nullptr || net->driver.cell == nullptr) {
+ // Pin is disconnected, return its default value
+ CellPinStyle pin_style = get_pin_style(cell, port);
+ if ((pin_style & PINDEF_MASK) == PINDEF_0)
+ return PINMUX_0;
+ else if ((pin_style & PINDEF_MASK) == PINDEF_1)
+ return PINMUX_1;
+ else
+ return PINMUX_SIG;
+ }
+ // Look to see if the driver is an inverter or constant
+ IdString drv_type = net->driver.cell->type;
+ if (drv_type == id_INV)
+ return PINMUX_INV;
+ else if (drv_type == id_VLO)
+ return PINMUX_0;
+ else if (drv_type == id_VHI)
+ return PINMUX_1;
+ else
+ return PINMUX_SIG;
}
void uninvert_port(CellInfo *cell, IdString port)
@@ -347,10 +405,79 @@ struct NexusPacker
ctx->cells.erase(rem_cell);
}
+ std::string remove_brackets(const std::string &name)
+ {
+ std::string new_name;
+ new_name.reserve(name.size());
+ for (char c : name)
+ if (c != '[' && c != ']')
+ new_name.push_back(c);
+ return new_name;
+ }
+
+ void prim_to_core(CellInfo *cell, IdString new_type = {})
+ {
+ // Convert a primitive to a '_CORE' variant
+ if (new_type == IdString())
+ new_type = ctx->id(cell->type.str(ctx) + "_CORE");
+ cell->type = new_type;
+ std::set<IdString> port_names;
+ for (auto port : cell->ports)
+ port_names.insert(port.first);
+ for (IdString port : port_names) {
+ IdString new_name = ctx->id(remove_brackets(port.str(ctx)));
+ if (new_name != port)
+ rename_port(ctx, cell, port, new_name);
+ }
+ }
+
+ NetInfo *gnd_net = nullptr, *vcc_net = nullptr;
+
+ void process_inv_constants(CellInfo *cell)
+ {
+ // Automatically create any extra inputs needed; so we can set them accordingly
+ autocreate_ports(cell);
+
+ for (auto &port : cell->ports) {
+ // Iterate over all inputs
+ if (port.second.type != PORT_IN)
+ continue;
+ IdString port_name = port.first;
+
+ CellPinMux req_mux = get_pin_needed_muxval(cell, port_name);
+ if (req_mux == PINMUX_SIG) {
+ // No special setting required, ignore
+ continue;
+ }
+
+ CellPinStyle pin_style = get_pin_style(cell, port_name);
+
+ if (req_mux == PINMUX_INV) {
+ // Pin is inverted. If there is a hard inverter; then use it
+ if ((pin_style & PINOPT_MASK) == PINOPT_INV) {
+ uninvert_port(cell, port_name);
+ ctx->set_cell_pinmux(cell, port_name, PINMUX_INV);
+ }
+ } else if (req_mux == PINMUX_0 || req_mux == PINMUX_1) {
+ // Pin is tied to a constant
+ // If there is a hard constant option; use it
+ if ((pin_style & int(req_mux)) == req_mux) {
+ disconnect_port(ctx, cell, port_name);
+ ctx->set_cell_pinmux(cell, port_name, req_mux);
+ } else if (port.second.net == nullptr) {
+ // If the port is disconnected; and there is no hard constant
+ // then we need to connect it to the relevant soft-constant net
+ connect_port(ctx, (req_mux == PINMUX_1) ? vcc_net : gnd_net, cell, port_name);
+ }
+ }
+ }
+ }
+
explicit NexusPacker(Context *ctx) : ctx(ctx) {}
void operator()()
{
+ ctx->get_cell_pin_data(cell_db);
pack_ffs();
pack_luts();
}