aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gui/worker.cc1
-rw-r--r--ice40/bitstream.cc14
-rw-r--r--ice40/cells.cc3
-rw-r--r--ice40/chains.cc109
-rw-r--r--ice40/pack.cc18
5 files changed, 103 insertions, 42 deletions
diff --git a/gui/worker.cc b/gui/worker.cc
index b009ecd3..900883d4 100644
--- a/gui/worker.cc
+++ b/gui/worker.cc
@@ -126,6 +126,7 @@ TaskManager::TaskManager() : toTerminate(false), toPause(false)
TaskManager::~TaskManager()
{
+ log_write_function = nullptr;
if (workerThread.isRunning())
terminate_thread();
workerThread.quit();
diff --git a/ice40/bitstream.cc b/ice40/bitstream.cc
index 87d77b9d..d1f51676 100644
--- a/ice40/bitstream.cc
+++ b/ice40/bitstream.cc
@@ -156,7 +156,9 @@ void configure_extra_cell(chipconfig_t &config, const Context *ctx, CellInfo *ce
// Lattice's weird string style params, not sure if
// prefixes other than 0b should be supported, only 0b features in docs
std::string raw = get_param_str_or_def(cell, ctx->id(p.first), "0b0");
- assert(raw.substr(0, 2) == "0b");
+ if (raw.substr(0, 2) != "0b")
+ log_error("expected configuration string starting with '0b' for parameter '%s' on cell '%s'\n",
+ p.first.c_str(), cell->name.c_str(ctx));
raw = raw.substr(2);
value.resize(raw.length());
for (int i = 0; i < (int)raw.length(); i++) {
@@ -168,7 +170,13 @@ void configure_extra_cell(chipconfig_t &config, const Context *ctx, CellInfo *ce
}
}
} else {
- int ival = get_param_or_def(cell, ctx->id(p.first), 0);
+ int ival;
+ try {
+ ival = get_param_or_def(cell, ctx->id(p.first), 0);
+ } catch (std::invalid_argument &e) {
+ log_error("expected numeric value for parameter '%s' on cell '%s'\n", p.first.c_str(),
+ cell->name.c_str(ctx));
+ }
for (int i = 0; i < p.second; i++)
value.push_back((ival >> i) & 0x1);
@@ -592,7 +600,7 @@ void write_asc(const Context *ctx, std::ostream &out)
configure_extra_cell(config, ctx, cell.second.get(), rgba_params, true, std::string("IpConfig."));
set_ec_cbit(config, ctx, get_ec_config(ctx->chip_info, cell.second->bel), "RGBA_DRV_EN", true, "IpConfig.");
} else if (cell.second->type == ctx->id("SB_WARMBOOT") || cell.second->type == ctx->id("ICESTORM_LFOSC") ||
- cell.second->type == ctx->id("SB_LEDDA_IP") ) {
+ cell.second->type == ctx->id("SB_LEDDA_IP")) {
// No config needed
} else if (cell.second->type == ctx->id("ICESTORM_SPRAM")) {
const BelInfoPOD &beli = ci.bel_data[bel.index];
diff --git a/ice40/cells.cc b/ice40/cells.cc
index aad719b1..35a5346f 100644
--- a/ice40/cells.cc
+++ b/ice40/cells.cc
@@ -269,7 +269,8 @@ std::unique_ptr<CellInfo> create_ice_cell(Context *ctx, IdString type, std::stri
add_port(ctx, new_cell.get(), "LEDDADDR" + std::to_string(i), PORT_IN);
add_port(ctx, new_cell.get(), "LEDDDEN", PORT_IN);
add_port(ctx, new_cell.get(), "LEDDEXE", PORT_IN);
- add_port(ctx, new_cell.get(), "LEDDRST", PORT_IN); //doesn't actually exist, for icecube code compatibility only
+ add_port(ctx, new_cell.get(), "LEDDRST", PORT_IN); // doesn't actually exist, for icecube code compatibility
+ // only
add_port(ctx, new_cell.get(), "PWMOUT0", PORT_OUT);
add_port(ctx, new_cell.get(), "PWMOUT1", PORT_OUT);
add_port(ctx, new_cell.get(), "PWMOUT2", PORT_OUT);
diff --git a/ice40/chains.cc b/ice40/chains.cc
index fb361d2d..b3b54d6b 100644
--- a/ice40/chains.cc
+++ b/ice40/chains.cc
@@ -62,7 +62,7 @@ class ChainConstrainer
bool split_chain = (!ctx->logicCellsCompatible(tile.data(), tile.size())) ||
(int(chains.back().cells.size()) > max_length);
if (split_chain) {
- CellInfo *passout = make_carry_pass_out(cell->ports.at(ctx->id("COUT")));
+ CellInfo *passout = make_carry_pass_out((*(curr_cell - 1))->ports.at(ctx->id("COUT")));
tile.pop_back();
chains.back().cells.back() = passout;
start_of_chain = true;
@@ -74,10 +74,10 @@ class ChainConstrainer
(net_only_drives(ctx, carry_net, is_lc, ctx->id("I3"), false) !=
net_only_drives(ctx, carry_net, is_lc, ctx->id("CIN"), false)) ||
(at_end && !net_only_drives(ctx, carry_net, is_lc, ctx->id("I3"), true))) {
- CellInfo *passout = make_carry_pass_out(cell->ports.at(ctx->id("COUT")));
+ CellInfo *passout = make_carry_pass_out(cell->ports.at(ctx->id("COUT")),
+ at_end ? nullptr : *(curr_cell + 1));
chains.back().cells.push_back(passout);
tile.push_back(passout);
- start_of_chain = true;
}
}
++curr_cell;
@@ -87,30 +87,75 @@ class ChainConstrainer
}
// Insert a logic cell to legalise a COUT->fabric connection
- CellInfo *make_carry_pass_out(PortInfo &cout_port)
+ CellInfo *make_carry_pass_out(PortInfo &cout_port, CellInfo *cin_cell = nullptr)
{
NPNR_ASSERT(cout_port.net != nullptr);
std::unique_ptr<CellInfo> lc = create_ice_cell(ctx, ctx->id("ICESTORM_LC"));
lc->params[ctx->id("LUT_INIT")] = "65280"; // 0xff00: O = I3
lc->params[ctx->id("CARRY_ENABLE")] = "1";
- lc->ports.at(ctx->id("O")).net = cout_port.net;
+ lc->ports.at(id_O).net = cout_port.net;
std::unique_ptr<NetInfo> co_i3_net(new NetInfo());
co_i3_net->name = ctx->id(lc->name.str(ctx) + "$I3");
co_i3_net->driver = cout_port.net->driver;
PortRef i3_r;
- i3_r.port = ctx->id("I3");
+ i3_r.port = id_I3;
i3_r.cell = lc.get();
co_i3_net->users.push_back(i3_r);
PortRef o_r;
- o_r.port = ctx->id("O");
+ o_r.port = id_O;
o_r.cell = lc.get();
cout_port.net->driver = o_r;
- lc->ports.at(ctx->id("I3")).net = co_i3_net.get();
+ lc->ports.at(id_I3).net = co_i3_net.get();
cout_port.net = co_i3_net.get();
IdString co_i3_name = co_i3_net->name;
NPNR_ASSERT(ctx->nets.find(co_i3_name) == ctx->nets.end());
ctx->nets[co_i3_name] = std::move(co_i3_net);
+
+ // If COUT also connects to a CIN; preserve the carry chain
+ if (cin_cell) {
+ std::unique_ptr<NetInfo> co_cin_net(new NetInfo());
+ co_cin_net->name = ctx->id(lc->name.str(ctx) + "$COUT");
+
+ // Connect I1 to 1 to preserve carry chain
+ NetInfo *vcc = ctx->nets.at(ctx->id("$PACKER_VCC_NET")).get();
+ lc->ports.at(id_I1).net = vcc;
+ PortRef i1_r;
+ i1_r.port = id_I1;
+ i1_r.cell = lc.get();
+ vcc->users.push_back(i1_r);
+
+ // Connect co_cin_net to the COUT of the LC
+ PortRef co_r;
+ co_r.port = id_COUT;
+ co_r.cell = lc.get();
+ co_cin_net->driver = co_r;
+ lc->ports.at(id_COUT).net = co_cin_net.get();
+
+ // Find the user corresponding to the next CIN
+ int replaced_ports = 0;
+ if (ctx->debug)
+ log_info("cell: %s\n", cin_cell->name.c_str(ctx));
+ for (auto port : {id_CIN, id_I3}) {
+ auto &usr = lc->ports.at(id_O).net->users;
+ if (ctx->debug)
+ for (auto user : usr)
+ log_info("%s.%s\n", user.cell->name.c_str(ctx), user.port.c_str(ctx));
+ auto fnd_user = std::find_if(usr.begin(), usr.end(),
+ [&](const PortRef &pr) { return pr.cell == cin_cell && pr.port == port; });
+ if (fnd_user != usr.end()) {
+ co_cin_net->users.push_back(*fnd_user);
+ usr.erase(fnd_user);
+ cin_cell->ports.at(port).net = co_cin_net.get();
+ ++replaced_ports;
+ }
+ }
+ NPNR_ASSERT(replaced_ports > 0);
+ IdString co_cin_name = co_cin_net->name;
+ NPNR_ASSERT(ctx->nets.find(co_cin_name) == ctx->nets.end());
+ ctx->nets[co_cin_name] = std::move(co_cin_net);
+ }
+
IdString name = lc->name;
ctx->assignCellInfo(lc.get());
ctx->cells[lc->name] = std::move(lc);
@@ -163,29 +208,31 @@ class ChainConstrainer
void process_carries()
{
- std::vector<CellChain> carry_chains =
- find_chains(ctx, [](const Context *ctx, const CellInfo *cell) { return is_lc(ctx, cell); },
- [](const Context *ctx, const
-
- CellInfo *cell) {
- CellInfo *carry_prev =
- net_driven_by(ctx, cell->ports.at(ctx->id("CIN")).net, is_lc, ctx->id("COUT"));
- if (carry_prev != nullptr)
- return carry_prev;
- /*CellInfo *i3_prev = net_driven_by(ctx, cell->ports.at(ctx->id("I3")).net, is_lc,
- ctx->id("COUT")); if (i3_prev != nullptr) return i3_prev;*/
- return (CellInfo *)nullptr;
- },
- [](const Context *ctx, const CellInfo *cell) {
- CellInfo *carry_next = net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc,
- ctx->id("CIN"), false);
- if (carry_next != nullptr)
- return carry_next;
- /*CellInfo *i3_next =
- net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc, ctx->id("I3"),
- false); if (i3_next != nullptr) return i3_next;*/
- return (CellInfo *)nullptr;
- });
+ std::vector<CellChain> carry_chains = find_chains(
+ ctx, [](const Context *ctx, const CellInfo *cell) { return is_lc(ctx, cell); },
+ [](const Context *ctx, const
+
+ CellInfo *cell) {
+ CellInfo *carry_prev =
+ net_driven_by(ctx, cell->ports.at(ctx->id("CIN")).net, is_lc, ctx->id("COUT"));
+ if (carry_prev != nullptr)
+ return carry_prev;
+ CellInfo *i3_prev = net_driven_by(ctx, cell->ports.at(ctx->id("I3")).net, is_lc, ctx->id("COUT"));
+ if (i3_prev != nullptr)
+ return i3_prev;
+ return (CellInfo *)nullptr;
+ },
+ [](const Context *ctx, const CellInfo *cell) {
+ CellInfo *carry_next =
+ net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc, ctx->id("CIN"), false);
+ if (carry_next != nullptr)
+ return carry_next;
+ CellInfo *i3_next =
+ net_only_drives(ctx, cell->ports.at(ctx->id("COUT")).net, is_lc, ctx->id("I3"), false);
+ if (i3_next != nullptr)
+ return i3_next;
+ return (CellInfo *)nullptr;
+ });
std::unordered_set<IdString> chained;
for (auto &base_chain : carry_chains) {
for (auto c : base_chain.cells)
diff --git a/ice40/pack.cc b/ice40/pack.cc
index e71db46f..242f8ceb 100644
--- a/ice40/pack.cc
+++ b/ice40/pack.cc
@@ -1083,13 +1083,17 @@ static void pack_special(Context *ctx)
}
auto feedback_path = packed->params[ctx->id("FEEDBACK_PATH")];
- packed->params[ctx->id("FEEDBACK_PATH")] =
- feedback_path == "DELAY"
- ? "0"
- : feedback_path == "SIMPLE" ? "1"
- : feedback_path == "PHASE_AND_DELAY"
- ? "2"
- : feedback_path == "EXTERNAL" ? "6" : feedback_path;
+ std::string fbp_value = feedback_path == "DELAY"
+ ? "0"
+ : feedback_path == "SIMPLE"
+ ? "1"
+ : feedback_path == "PHASE_AND_DELAY"
+ ? "2"
+ : feedback_path == "EXTERNAL" ? "6" : feedback_path;
+ if (!std::all_of(fbp_value.begin(), fbp_value.end(), isdigit))
+ log_error("PLL '%s' has unsupported FEEDBACK_PATH value '%s'\n", ci->name.c_str(ctx),
+ feedback_path.c_str());
+ packed->params[ctx->id("FEEDBACK_PATH")] = fbp_value;
packed->params[ctx->id("PLLTYPE")] = std::to_string(sb_pll40_type(ctx, ci));
NetInfo *pad_packagepin_net = nullptr;