aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam D. Jones <thor0505@comcast.net>2020-12-07 11:48:15 -0500
committergatecat <gatecat@ds0.me>2021-02-12 10:36:59 +0000
commitbbc683dd75fcf54b8f215704a932c5c2f1a39c93 (patch)
tree80e2bc5f4ad103a0e54e75b008b933e72d5cfe63
parent138519d820cd25cdd6700fabf13e855d67030e1a (diff)
downloadnextpnr-bbc683dd75fcf54b8f215704a932c5c2f1a39c93.tar.gz
nextpnr-bbc683dd75fcf54b8f215704a932c5c2f1a39c93.tar.bz2
nextpnr-bbc683dd75fcf54b8f215704a932c5c2f1a39c93.zip
machxo2: Implement all of Bel API except getBelPinWire.
-rw-r--r--machxo2/arch.cc79
-rw-r--r--machxo2/arch.h12
2 files changed, 79 insertions, 12 deletions
diff --git a/machxo2/arch.cc b/machxo2/arch.cc
index 6c7efbe5..a01f96e6 100644
--- a/machxo2/arch.cc
+++ b/machxo2/arch.cc
@@ -29,6 +29,18 @@
NEXTPNR_NAMESPACE_BEGIN
+static std::tuple<int, int, std::string> split_identifier_name(const std::string &name)
+{
+ size_t first_slash = name.find('/');
+ NPNR_ASSERT(first_slash != std::string::npos);
+ size_t second_slash = name.find('/', first_slash + 1);
+ NPNR_ASSERT(second_slash != std::string::npos);
+ return std::make_tuple(std::stoi(name.substr(1, first_slash)),
+ std::stoi(name.substr(first_slash + 2, second_slash - first_slash)),
+ name.substr(second_slash + 1));
+};
+
+
// -----------------------------------------------------------------------
void IdString::initialize_arch(const BaseCtx *ctx) {
@@ -134,7 +146,25 @@ IdString Arch::archArgsToId(ArchArgs args) const
BelId Arch::getBelByName(IdString name) const
{
- return BelId();
+ BelId ret;
+ auto it = bel_by_name.find(name);
+ if (it != bel_by_name.end())
+ return it->second;
+
+ Location loc;
+ std::string basename;
+ std::tie(loc.x, loc.y, basename) = split_identifier_name(name.str(this));
+ ret.location = loc;
+ const TileTypePOD *tilei = tileInfo(ret);
+ for (int i = 0; i < tilei->num_bels; i++) {
+ if (std::strcmp(tilei->bel_data[i].name.get(), basename.c_str()) == 0) {
+ ret.index = i;
+ break;
+ }
+ }
+ if (ret.index >= 0)
+ bel_by_name[name] = ret;
+ return ret;
}
BelId Arch::getBelByLocation(Loc loc) const
@@ -159,16 +189,25 @@ BelId Arch::getBelByLocation(Loc loc) const
return BelId();
}
-const std::vector<BelId> &Arch::getBelsByTile(int x, int y) const { return bel_id_dummy; }
-
-bool Arch::getBelGlobalBuf(BelId bel) const { return false; }
-
-uint32_t Arch::getBelChecksum(BelId bel) const
+BelRange Arch::getBelsByTile(int x, int y) const
{
- // FIXME
- return 0;
+ BelRange br;
+
+ br.b.cursor_tile = y * chip_info->width + x;
+ br.e.cursor_tile = y * chip_info->width + x;
+ br.b.cursor_index = 0;
+ br.e.cursor_index = chip_info->tiles[y * chip_info->width + x].num_bels - 1;
+ br.b.chip = chip_info;
+ br.e.chip = chip_info;
+ if (br.e.cursor_index == -1)
+ ++br.e.cursor_index;
+ else
+ ++br.e;
+ return br;
}
+bool Arch::getBelGlobalBuf(BelId bel) const { return false; }
+
const std::map<IdString, std::string> &Arch::getBelAttrs(BelId bel) const { return attrs_dummy; }
WireId Arch::getBelPinWire(BelId bel, IdString pin) const
@@ -176,11 +215,33 @@ WireId Arch::getBelPinWire(BelId bel, IdString pin) const
return WireId();
}
-PortType Arch::getBelPinType(BelId bel, IdString pin) const { return PortType(); }
+PortType Arch::getBelPinType(BelId bel, IdString pin) const
+{
+ NPNR_ASSERT(bel != BelId());
+
+ int num_bel_wires = tileInfo(bel)->bel_data[bel.index].num_bel_wires;
+ const BelWirePOD *bel_wires = &*tileInfo(bel)->bel_data[bel.index].bel_wires;
+
+ for(int i = 0; i < num_bel_wires; i++)
+ if(bel_wires[i].port == pin.index)
+ return PortType(bel_wires[i].dir);
+
+ return PORT_INOUT;
+}
std::vector<IdString> Arch::getBelPins(BelId bel) const
{
std::vector<IdString> ret;
+ NPNR_ASSERT(bel != BelId());
+
+ int num_bel_wires = tileInfo(bel)->bel_data[bel.index].num_bel_wires;
+ const BelWirePOD *bel_wires = &*tileInfo(bel)->bel_data[bel.index].bel_wires;
+
+ for(int i = 0; i < num_bel_wires; i++) {
+ IdString id(bel_wires[i].port);
+ ret.push_back(id);
+ }
+
return ret;
}
diff --git a/machxo2/arch.h b/machxo2/arch.h
index b5d6c522..b68a83ef 100644
--- a/machxo2/arch.h
+++ b/machxo2/arch.h
@@ -50,7 +50,7 @@ NPNR_PACKED_STRUCT(struct BelWirePOD {
LocationPOD rel_wire_loc;
int32_t wire_index;
int32_t port;
- int32_t dir;
+ int32_t dir; // FIXME: Corresponds to "type" in ECP5.
});
NPNR_PACKED_STRUCT(struct BelInfoPOD {
@@ -312,6 +312,7 @@ struct Arch : BaseCtx
const PackageInfoPOD *package_info;
std::vector<CellInfo *> bel_to_cell;
+ mutable std::unordered_map<IdString, BelId> bel_by_name;
// Placeholders to be removed.
std::unordered_map<Loc, BelId> bel_by_loc;
@@ -377,9 +378,14 @@ struct Arch : BaseCtx
}
BelId getBelByLocation(Loc loc) const;
- const std::vector<BelId> &getBelsByTile(int x, int y) const;
+ BelRange getBelsByTile(int x, int y) const;
bool getBelGlobalBuf(BelId bel) const;
- uint32_t getBelChecksum(BelId bel) const;
+
+ uint32_t getBelChecksum(BelId bel) const
+ {
+ // FIXME- Copied from ECP5. Should be return val from getBelFlatIndex?
+ return bel.index;
+ }
void bindBel(BelId bel, CellInfo *cell, PlaceStrength strength)
{