2020-12-30 22:59:55 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
2021-06-09 20:09:08 +08:00
|
|
|
* Copyright (C) 2019 gatecat <gatecat@ds0.me>
|
2020-12-30 22:59:55 +08:00
|
|
|
* Copyright (C) 2020 Pepijn de Vos <pepijn@symbioticeda.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cells.h"
|
2020-12-31 00:49:55 +08:00
|
|
|
#include <iostream>
|
2020-12-30 22:59:55 +08:00
|
|
|
#include "design_utils.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
std::unique_ptr<CellInfo> create_generic_cell(Context *ctx, IdString type, std::string name)
|
|
|
|
{
|
|
|
|
static int auto_idx = 0;
|
2022-02-16 21:53:47 +08:00
|
|
|
IdString name_id =
|
|
|
|
name.empty() ? ctx->id("$nextpnr_" + type.str(ctx) + "_" + std::to_string(auto_idx++)) : ctx->id(name);
|
|
|
|
auto new_cell = std::make_unique<CellInfo>(ctx, name_id, type);
|
2020-12-30 22:59:55 +08:00
|
|
|
if (type == id_SLICE) {
|
|
|
|
new_cell->params[id_INIT] = 0;
|
|
|
|
new_cell->params[id_FF_USED] = 0;
|
|
|
|
new_cell->params[id_FF_TYPE] = id_DFF.str(ctx);
|
|
|
|
|
|
|
|
IdString names[4] = {id_A, id_B, id_C, id_D};
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2022-02-17 00:45:45 +08:00
|
|
|
new_cell->addInput(names[i]);
|
2020-12-30 22:59:55 +08:00
|
|
|
}
|
|
|
|
|
2022-02-17 00:45:45 +08:00
|
|
|
new_cell->addInput(id_CLK);
|
2020-12-30 22:59:55 +08:00
|
|
|
|
2022-02-17 00:45:45 +08:00
|
|
|
new_cell->addOutput(id_F);
|
|
|
|
new_cell->addOutput(id_Q);
|
|
|
|
new_cell->addInput(id_CE);
|
|
|
|
new_cell->addInput(id_LSR);
|
2022-06-06 20:35:33 +08:00
|
|
|
} else if (type == id_RAMW) {
|
|
|
|
IdString names[8] = {id_A4, id_B4, id_C4, id_D4, id_A5, id_B5, id_C5, id_D5};
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
new_cell->addInput(names[i]);
|
|
|
|
}
|
|
|
|
new_cell->addInput(id_CLK);
|
2022-06-16 17:38:23 +08:00
|
|
|
new_cell->addInput(id_CE);
|
2022-06-06 20:35:33 +08:00
|
|
|
new_cell->addInput(id_LSR);
|
2022-08-11 01:58:22 +08:00
|
|
|
} else if (type.in(id_MUX2_LUT5, id_MUX2_LUT6, id_MUX2_LUT7, id_MUX2_LUT7, id_MUX2_LUT8)) {
|
2022-02-17 00:45:45 +08:00
|
|
|
new_cell->addInput(id_I0);
|
|
|
|
new_cell->addInput(id_I1);
|
|
|
|
new_cell->addInput(id_SEL);
|
|
|
|
new_cell->addOutput(id_OF);
|
2022-08-11 01:58:22 +08:00
|
|
|
} else if (type.in(id_IOB, id_IOBS)) {
|
2020-12-30 22:59:55 +08:00
|
|
|
new_cell->params[id_INPUT_USED] = 0;
|
|
|
|
new_cell->params[id_OUTPUT_USED] = 0;
|
|
|
|
new_cell->params[id_ENABLE_USED] = 0;
|
|
|
|
|
2022-02-17 00:45:45 +08:00
|
|
|
new_cell->addInout(id_PAD);
|
|
|
|
new_cell->addInput(id_I);
|
|
|
|
new_cell->addInput(id_OEN);
|
|
|
|
new_cell->addOutput(id_O);
|
2022-03-12 21:05:42 +08:00
|
|
|
} else if (type == id_GSR) {
|
|
|
|
new_cell->addInput(id_GSRI);
|
2022-03-20 02:44:08 +08:00
|
|
|
} else if (type == id_GND) {
|
|
|
|
new_cell->addOutput(id_G);
|
|
|
|
} else if (type == id_VCC) {
|
|
|
|
new_cell->addOutput(id_V);
|
2022-05-27 20:44:21 +08:00
|
|
|
} else if (type == id_BUFS) {
|
|
|
|
new_cell->addInput(id_I);
|
|
|
|
new_cell->addOutput(id_O);
|
2023-01-26 18:26:05 +08:00
|
|
|
} else if (type == id_rPLL) {
|
2022-11-10 17:14:41 +08:00
|
|
|
for (IdString iid :
|
2023-01-26 18:26:05 +08:00
|
|
|
{id_CLKIN, id_CLKFB, id_FBDSEL0, id_FBDSEL1, id_FBDSEL2, id_FBDSEL3, id_FBDSEL4, id_FBDSEL5, id_IDSEL0,
|
|
|
|
id_IDSEL1, id_IDSEL2, id_IDSEL3, id_IDSEL4, id_IDSEL5, id_ODSEL0, id_ODSEL1, id_ODSEL2, id_ODSEL3,
|
|
|
|
id_ODSEL4, id_ODSEL5, id_PSDA0, id_PSDA1, id_PSDA2, id_PSDA3, id_DUTYDA0, id_DUTYDA1, id_DUTYDA2,
|
|
|
|
id_DUTYDA3, id_FDLY0, id_FDLY1, id_FDLY2, id_FDLY3, id_RESET, id_RESET_P}) {
|
2022-11-10 17:14:41 +08:00
|
|
|
new_cell->addInput(iid);
|
|
|
|
}
|
|
|
|
new_cell->addOutput(id_CLKOUT);
|
|
|
|
new_cell->addOutput(id_CLKOUTP);
|
|
|
|
new_cell->addOutput(id_CLKOUTD);
|
|
|
|
new_cell->addOutput(id_CLKOUTD3);
|
|
|
|
new_cell->addOutput(id_LOCK);
|
2023-01-18 17:18:02 +08:00
|
|
|
} else if (type == id_PLLVR) {
|
|
|
|
for (IdString iid :
|
|
|
|
{id_CLKIN, id_CLKFB, id_FBDSEL0, id_FBDSEL1, id_FBDSEL2, id_FBDSEL3, id_FBDSEL4, id_FBDSEL5, id_IDSEL0,
|
|
|
|
id_IDSEL1, id_IDSEL2, id_IDSEL3, id_IDSEL4, id_IDSEL5, id_ODSEL0, id_ODSEL1, id_ODSEL2, id_ODSEL3,
|
|
|
|
id_ODSEL4, id_ODSEL5, id_PSDA0, id_PSDA1, id_PSDA2, id_PSDA3, id_DUTYDA0, id_DUTYDA1, id_DUTYDA2,
|
|
|
|
id_DUTYDA3, id_FDLY0, id_FDLY1, id_FDLY2, id_FDLY3, id_RESET, id_RESET_P, id_VREN}) {
|
|
|
|
new_cell->addInput(iid);
|
|
|
|
}
|
|
|
|
new_cell->addOutput(id_CLKOUT);
|
|
|
|
new_cell->addOutput(id_CLKOUTP);
|
|
|
|
new_cell->addOutput(id_CLKOUTD);
|
|
|
|
new_cell->addOutput(id_CLKOUTD3);
|
|
|
|
new_cell->addOutput(id_LOCK);
|
2023-03-22 15:15:17 +08:00
|
|
|
} else if (type == id_IOLOGIC) {
|
2023-04-12 11:42:16 +08:00
|
|
|
new_cell->addInput(id_FCLK);
|
2023-03-22 15:15:17 +08:00
|
|
|
new_cell->addInput(id_PCLK);
|
|
|
|
new_cell->addInput(id_RESET);
|
|
|
|
} else if (type == id_DUMMY_CELL) {
|
2020-12-30 22:59:55 +08:00
|
|
|
} else {
|
2021-10-07 16:38:33 +08:00
|
|
|
log_error("unable to create generic cell of type %s\n", type.c_str(ctx));
|
2020-12-30 22:59:55 +08:00
|
|
|
}
|
|
|
|
return new_cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lut_to_lc(const Context *ctx, CellInfo *lut, CellInfo *lc, bool no_dff)
|
|
|
|
{
|
|
|
|
lc->params[id_INIT] = lut->params[id_INIT];
|
2021-10-07 16:38:33 +08:00
|
|
|
lc->cluster = lut->cluster;
|
|
|
|
lc->constr_x = lut->constr_x;
|
|
|
|
lc->constr_y = lut->constr_y;
|
|
|
|
lc->constr_z = lut->constr_z;
|
|
|
|
|
|
|
|
// add itself to the cluster root children list
|
|
|
|
if (lc->cluster != ClusterId()) {
|
|
|
|
CellInfo *cluster_root = ctx->cells.at(lc->cluster).get();
|
|
|
|
lc->constr_x += cluster_root->constr_x;
|
|
|
|
lc->constr_y += cluster_root->constr_y;
|
|
|
|
lc->constr_z += cluster_root->constr_z;
|
|
|
|
if (cluster_root->cluster != cluster_root->name) {
|
|
|
|
lc->cluster = cluster_root->cluster;
|
|
|
|
cluster_root = ctx->cells.at(cluster_root->cluster).get();
|
|
|
|
}
|
|
|
|
cluster_root->constr_children.push_back(lc);
|
|
|
|
}
|
2020-12-30 22:59:55 +08:00
|
|
|
|
|
|
|
IdString sim_names[4] = {id_I0, id_I1, id_I2, id_I3};
|
|
|
|
IdString wire_names[4] = {id_A, id_B, id_C, id_D};
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2022-02-18 18:52:37 +08:00
|
|
|
lut->movePortTo(sim_names[i], lc, wire_names[i]);
|
2020-12-30 22:59:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (no_dff) {
|
|
|
|
lc->params[id_FF_USED] = 0;
|
2022-02-18 18:52:37 +08:00
|
|
|
lut->movePortTo(id_F, lc, id_F);
|
2020-12-30 22:59:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dff_to_lc(const Context *ctx, CellInfo *dff, CellInfo *lc, bool pass_thru_lut)
|
|
|
|
{
|
|
|
|
lc->params[id_FF_USED] = 1;
|
|
|
|
lc->params[id_FF_TYPE] = dff->type.str(ctx);
|
2022-02-18 18:52:37 +08:00
|
|
|
dff->movePortTo(id_CLK, lc, id_CLK);
|
|
|
|
dff->movePortTo(id_CE, lc, id_CE);
|
|
|
|
dff->movePortTo(id_SET, lc, id_LSR);
|
|
|
|
dff->movePortTo(id_RESET, lc, id_LSR);
|
|
|
|
dff->movePortTo(id_CLEAR, lc, id_LSR);
|
|
|
|
dff->movePortTo(id_PRESET, lc, id_LSR);
|
2020-12-30 22:59:55 +08:00
|
|
|
if (pass_thru_lut) {
|
|
|
|
// Fill LUT with alternating 10
|
|
|
|
const int init_size = 1 << 4;
|
|
|
|
std::string init;
|
|
|
|
init.reserve(init_size);
|
|
|
|
for (int i = 0; i < init_size; i += 2)
|
|
|
|
init.append("10");
|
|
|
|
lc->params[id_INIT] = Property::from_string(init);
|
|
|
|
|
2022-02-18 18:52:37 +08:00
|
|
|
dff->movePortTo(id_D, lc, id_A);
|
2020-12-30 22:59:55 +08:00
|
|
|
}
|
|
|
|
|
2022-02-18 18:52:37 +08:00
|
|
|
dff->movePortTo(id_Q, lc, id_Q);
|
2020-12-30 22:59:55 +08:00
|
|
|
}
|
|
|
|
|
2021-06-02 17:01:36 +08:00
|
|
|
void gwio_to_iob(Context *ctx, CellInfo *nxio, CellInfo *iob, pool<IdString> &todelete_cells)
|
2020-12-30 22:59:55 +08:00
|
|
|
{
|
|
|
|
if (nxio->type == id_IBUF) {
|
2021-12-20 13:48:38 +08:00
|
|
|
if (iob->type == id_IOBS) {
|
|
|
|
// VCC -> OEN
|
2022-02-18 18:52:37 +08:00
|
|
|
iob->connectPort(id_OEN, ctx->nets[ctx->id("$PACKER_VCC_NET")].get());
|
2021-12-20 13:48:38 +08:00
|
|
|
}
|
2020-12-30 22:59:55 +08:00
|
|
|
iob->params[id_INPUT_USED] = 1;
|
2022-02-18 18:52:37 +08:00
|
|
|
nxio->movePortTo(id_O, iob, id_O);
|
2020-12-30 22:59:55 +08:00
|
|
|
} else if (nxio->type == id_OBUF) {
|
2021-12-20 13:48:38 +08:00
|
|
|
if (iob->type == id_IOBS) {
|
|
|
|
// VSS -> OEN
|
2022-02-18 18:52:37 +08:00
|
|
|
iob->connectPort(id_OEN, ctx->nets[ctx->id("$PACKER_GND_NET")].get());
|
2021-12-20 13:48:38 +08:00
|
|
|
}
|
2020-12-30 22:59:55 +08:00
|
|
|
iob->params[id_OUTPUT_USED] = 1;
|
2022-02-18 18:52:37 +08:00
|
|
|
nxio->movePortTo(id_I, iob, id_I);
|
2020-12-30 22:59:55 +08:00
|
|
|
} else if (nxio->type == id_TBUF) {
|
|
|
|
iob->params[id_ENABLE_USED] = 1;
|
|
|
|
iob->params[id_OUTPUT_USED] = 1;
|
2022-02-18 18:52:37 +08:00
|
|
|
nxio->movePortTo(id_I, iob, id_I);
|
|
|
|
nxio->movePortTo(id_OEN, iob, id_OEN);
|
2020-12-30 22:59:55 +08:00
|
|
|
} else if (nxio->type == id_IOBUF) {
|
|
|
|
iob->params[id_ENABLE_USED] = 1;
|
|
|
|
iob->params[id_INPUT_USED] = 1;
|
|
|
|
iob->params[id_OUTPUT_USED] = 1;
|
2022-02-18 18:52:37 +08:00
|
|
|
nxio->movePortTo(id_I, iob, id_I);
|
|
|
|
nxio->movePortTo(id_O, iob, id_O);
|
|
|
|
nxio->movePortTo(id_OEN, iob, id_OEN);
|
2020-12-30 22:59:55 +08:00
|
|
|
} else {
|
|
|
|
NPNR_ASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-26 18:26:05 +08:00
|
|
|
void reconnect_pllvr(Context *ctx, CellInfo *pll, CellInfo *new_pll)
|
2022-11-10 17:14:41 +08:00
|
|
|
{
|
2023-01-26 18:26:05 +08:00
|
|
|
pll->movePortTo(id_CLKIN, new_pll, id_CLKIN);
|
|
|
|
pll->movePortTo(id_VREN, new_pll, id_VREN);
|
|
|
|
pll->movePortTo(id_CLKFB, new_pll, id_CLKFB);
|
|
|
|
pll->movePortTo(id_RESET, new_pll, id_RESET);
|
|
|
|
pll->movePortTo(id_RESET_P, new_pll, id_RESET_P);
|
2022-11-11 07:19:16 +08:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
2023-01-26 18:26:05 +08:00
|
|
|
pll->movePortTo(ctx->idf("FBDSEL[%d]", i), new_pll, ctx->idf("FBDSEL%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("IDSEL[%d]", i), new_pll, ctx->idf("IDSEL%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("ODSEL[%d]", i), new_pll, ctx->idf("ODSEL%d", i));
|
2022-11-11 07:19:16 +08:00
|
|
|
if (i < 4) {
|
2023-01-26 18:26:05 +08:00
|
|
|
pll->movePortTo(ctx->idf("PSDA[%d]", i), new_pll, ctx->idf("PSDA%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("DUTYDA[%d]", i), new_pll, ctx->idf("DUTYDA%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("FDLY[%d]", i), new_pll, ctx->idf("FDLY%d", i));
|
2022-11-11 07:19:16 +08:00
|
|
|
}
|
|
|
|
}
|
2023-01-26 18:26:05 +08:00
|
|
|
pll->movePortTo(id_CLKOUT, new_pll, id_CLKOUT);
|
|
|
|
pll->movePortTo(id_CLKOUTP, new_pll, id_CLKOUTP);
|
|
|
|
pll->movePortTo(id_CLKOUTD, new_pll, id_CLKOUTD);
|
|
|
|
pll->movePortTo(id_CLKOUTD3, new_pll, id_CLKOUTD3);
|
|
|
|
pll->movePortTo(id_LOCK, new_pll, id_LOCK);
|
2022-11-10 17:14:41 +08:00
|
|
|
}
|
|
|
|
|
2023-01-26 18:26:05 +08:00
|
|
|
void reconnect_rpll(Context *ctx, CellInfo *pll, CellInfo *new_pll)
|
2023-01-18 17:18:02 +08:00
|
|
|
{
|
|
|
|
pll->movePortTo(id_CLKIN, new_pll, id_CLKIN);
|
|
|
|
pll->movePortTo(id_CLKFB, new_pll, id_CLKFB);
|
|
|
|
pll->movePortTo(id_RESET, new_pll, id_RESET);
|
|
|
|
pll->movePortTo(id_RESET_P, new_pll, id_RESET_P);
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
pll->movePortTo(ctx->idf("FBDSEL[%d]", i), new_pll, ctx->idf("FBDSEL%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("IDSEL[%d]", i), new_pll, ctx->idf("IDSEL%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("ODSEL[%d]", i), new_pll, ctx->idf("ODSEL%d", i));
|
|
|
|
if (i < 4) {
|
|
|
|
pll->movePortTo(ctx->idf("PSDA[%d]", i), new_pll, ctx->idf("PSDA%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("DUTYDA[%d]", i), new_pll, ctx->idf("DUTYDA%d", i));
|
|
|
|
pll->movePortTo(ctx->idf("FDLY[%d]", i), new_pll, ctx->idf("FDLY%d", i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pll->movePortTo(id_CLKOUT, new_pll, id_CLKOUT);
|
|
|
|
pll->movePortTo(id_CLKOUTP, new_pll, id_CLKOUTP);
|
|
|
|
pll->movePortTo(id_CLKOUTD, new_pll, id_CLKOUTD);
|
|
|
|
pll->movePortTo(id_CLKOUTD3, new_pll, id_CLKOUTD3);
|
|
|
|
pll->movePortTo(id_LOCK, new_pll, id_LOCK);
|
|
|
|
}
|
|
|
|
|
2022-06-05 22:59:06 +08:00
|
|
|
void sram_to_ramw_split(Context *ctx, CellInfo *ram, CellInfo *ramw)
|
|
|
|
{
|
|
|
|
if (ramw->hierpath == IdString())
|
|
|
|
ramw->hierpath = ramw->hierpath;
|
|
|
|
ram->movePortTo(ctx->id("WAD[0]"), ramw, id_A4);
|
|
|
|
ram->movePortTo(ctx->id("WAD[1]"), ramw, id_B4);
|
|
|
|
ram->movePortTo(ctx->id("WAD[2]"), ramw, id_C4);
|
|
|
|
ram->movePortTo(ctx->id("WAD[3]"), ramw, id_D4);
|
|
|
|
|
|
|
|
ram->movePortTo(ctx->id("DI[0]"), ramw, id_A5);
|
|
|
|
ram->movePortTo(ctx->id("DI[1]"), ramw, id_B5);
|
|
|
|
ram->movePortTo(ctx->id("DI[2]"), ramw, id_C5);
|
|
|
|
ram->movePortTo(ctx->id("DI[3]"), ramw, id_D5);
|
2022-07-19 16:51:25 +08:00
|
|
|
|
2022-06-05 22:59:06 +08:00
|
|
|
ram->movePortTo(ctx->id("CLK"), ramw, id_CLK);
|
|
|
|
ram->movePortTo(ctx->id("WRE"), ramw, id_LSR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sram_to_slice(Context *ctx, CellInfo *ram, CellInfo *slice, int index)
|
|
|
|
{
|
|
|
|
if (slice->hierpath == IdString())
|
|
|
|
slice->hierpath = slice->hierpath;
|
|
|
|
|
2022-11-11 07:19:16 +08:00
|
|
|
slice->params[id_INIT] = ram->params[ctx->idf("INIT_%d", index)];
|
2022-06-06 20:35:33 +08:00
|
|
|
|
2022-11-11 07:19:16 +08:00
|
|
|
ram->movePortTo(ctx->idf("DO[%d]", index), slice, id_F);
|
2022-06-05 22:59:06 +08:00
|
|
|
|
|
|
|
ram->copyPortTo(ctx->id("RAD[0]"), slice, id_A);
|
|
|
|
ram->copyPortTo(ctx->id("RAD[1]"), slice, id_B);
|
|
|
|
ram->copyPortTo(ctx->id("RAD[2]"), slice, id_C);
|
|
|
|
ram->copyPortTo(ctx->id("RAD[3]"), slice, id_D);
|
|
|
|
}
|
|
|
|
|
2020-12-30 22:59:55 +08:00
|
|
|
NEXTPNR_NAMESPACE_END
|