Skip to content

Commit

Permalink
gowin: Use speed from chip base.
Browse files Browse the repository at this point in the history
Another simplification of the input regular expression, now
the speed is taken from the base.

Signed-off-by: YRabbit <rabbit@yrabbit.cyou>
  • Loading branch information
yrabbit committed Nov 5, 2021
1 parent 0e8a299 commit 74b4f69
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
39 changes: 25 additions & 14 deletions gowin/arch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ void Arch::addMuxBels(const DatabasePOD *db, int row, int col)
Arch::Arch(ArchArgs args) : args(args)
{
family = args.family;
device = args.device;

// Load database
std::string chipdb = stringf("gowin/chipdb-%s.bin", family.c_str());
Expand All @@ -685,32 +684,39 @@ Arch::Arch(ArchArgs args) : args(args)
for (size_t i = 0; i < db->num_ids; i++) {
IdString::initialize_add(this, db->id_strs[i].get(), uint32_t(i) + db->num_constids);
}
// setup timing info
speed = nullptr;
for (unsigned int i = 0; i < db->num_speeds; i++) {
const TimingClassPOD *tc = &db->speeds[i];
// std::cout << IdString(tc->name_id).str(this) << std::endl;
if (IdString(tc->name_id) == id(args.speed)) {
speed = tc->groups.get();
break;
}
}
if (speed == nullptr) {
log_error("Unsuported speed grade '%s'.\n", args.speed.c_str());
}

// setup package
IdString package_name;
IdString device_id;
IdString speed_id;
for (unsigned int i = 0; i < db->num_partnumbers; i++) {
auto partnumber = &db->partnumber_packages[i];
// std::cout << IdString(partnumber->name_id).str(this) << IdString(partnumber->package_id).str(this) <<
// std::endl;
if (IdString(partnumber->name_id) == id(args.partnumber)) {
package_name = IdString(partnumber->package_id);
device_id = IdString(partnumber->device_id);
speed_id = IdString(partnumber->speed_id);
break;
}
}
if (package_name == IdString()) {
log_error("Unsuported partnumber '%s'.\n", args.partnumber.c_str());
}

// setup timing info
speed = nullptr;
for (unsigned int i = 0; i < db->num_speeds; i++) {
const TimingClassPOD *tc = &db->speeds[i];
// std::cout << IdString(tc->name_id).str(this) << std::endl;
if (IdString(tc->name_id) == speed_id) {
speed = tc->groups.get();
break;
}
}
if (speed == nullptr) {
log_error("Unsuported speed grade '%s'.\n", speed_id.c_str(this));
}

const VariantPOD *variant = nullptr;
for (unsigned int i = 0; i < db->num_variants; i++) {
Expand Down Expand Up @@ -742,6 +748,11 @@ Arch::Arch(ArchArgs args) : args(args)
if (package == nullptr) {
log_error("Unsuported package '%s'.\n", package_name.c_str(this));
}

//
log_info("Series:%s Device:%s Package:%s Speed:%s\n", family.c_str(), device_id.c_str(this),
package_name.c_str(this), speed_id.c_str(this));

// setup db
char buf[32];
// The reverse order of the enumeration simplifies the creation
Expand Down
3 changes: 1 addition & 2 deletions gowin/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ NPNR_PACKED_STRUCT(struct PartnumberPOD {
uint32_t name_id;
uint32_t package_id;
uint32_t device_id;
uint32_t speed_id;
});

NPNR_PACKED_STRUCT(struct PackagePOD {
Expand Down Expand Up @@ -170,9 +171,7 @@ NPNR_PACKED_STRUCT(struct DatabasePOD {

struct ArchArgs
{
std::string device;
std::string family;
std::string speed;
std::string partnumber;
// y = mx + c relationship between distance and delay for interconnect
// delay estimates
Expand Down
5 changes: 1 addition & 4 deletions gowin/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ po::options_description GowinCommandHandler::getArchOptions()

std::unique_ptr<Context> GowinCommandHandler::createContext(dict<std::string, Property> &values)
{
std::regex devicere = std::regex("GW1N([A-Z]*)-(LV|UV|UX)([0-9])(C?)([A-Z]{2}[0-9]+)(C[0-9]/I[0-9])");
std::regex devicere = std::regex("GW1N([A-Z]*)-(LV|UV|UX)([0-9])(C?).*");
std::smatch match;
std::string device = vm["device"].as<std::string>();
if (!std::regex_match(device, match, devicere)) {
log_error("Invalid device %s\n", device.c_str());
}
ArchArgs chipArgs;
char buf[36];
snprintf(buf, 36, "GW1N%s-%s%s", match[1].str().c_str(), match[3].str().c_str(), match[4].str().c_str());
chipArgs.device = buf;
// GW1N and GW1NR variants share the same database.
// Most Gowin devices are a System in Package with some SDRAM wirebonded to a GPIO bank.
// However, it appears that the S series with embedded ARM core are unique silicon.
Expand All @@ -74,7 +72,6 @@ std::unique_ptr<Context> GowinCommandHandler::createContext(dict<std::string, Pr
}
chipArgs.family = buf;
chipArgs.partnumber = match[0];
chipArgs.speed = match[6];
return std::unique_ptr<Context>(new Context(chipArgs));
}

Expand Down

0 comments on commit 74b4f69

Please sign in to comment.