2018-10-31 18:48:54 +08:00
|
|
|
/*
|
|
|
|
* nextpnr -- Next Generation Place and Route
|
|
|
|
*
|
2021-06-09 20:09:08 +08:00
|
|
|
* Copyright (C) 2018 gatecat <gatecat@ds0.me>
|
2018-10-31 18:48:54 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-02-28 06:54:32 +08:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2018-10-31 18:48:54 +08:00
|
|
|
#include <sstream>
|
2021-03-13 05:09:44 +08:00
|
|
|
|
|
|
|
#include "arch.h"
|
2018-10-31 18:48:54 +08:00
|
|
|
#include "log.h"
|
2021-03-13 05:09:44 +08:00
|
|
|
#include "nextpnr_namespaces.h"
|
2018-10-31 18:48:54 +08:00
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_BEGIN
|
|
|
|
|
2021-06-02 17:01:36 +08:00
|
|
|
static const pool<std::string> sysconfig_keys = {
|
2020-07-12 19:53:16 +08:00
|
|
|
"SLAVE_SPI_PORT", "MASTER_SPI_PORT", "SLAVE_PARALLEL_PORT",
|
|
|
|
"BACKGROUND_RECONFIG", "DONE_EX", "DONE_OD",
|
|
|
|
"DONE_PULL", "MCCLK_FREQ", "TRANSFR",
|
|
|
|
"CONFIG_IOVOLTAGE", "CONFIG_SECURE", "WAKE_UP",
|
|
|
|
"COMPRESS_CONFIG", "CONFIG_MODE", "INBUF",
|
|
|
|
};
|
|
|
|
|
2021-06-02 17:01:36 +08:00
|
|
|
static const pool<std::string> iobuf_keys = {
|
2020-07-14 00:30:24 +08:00
|
|
|
"IO_TYPE", "BANK", "BANK_VCC", "VREF", "PULLMODE", "DRIVE", "SLEWRATE",
|
|
|
|
"CLAMP", "OPENDRAIN", "DIFFRESISTOR", "DIFFDRIVE", "HYSTERESIS", "TERMINATION",
|
|
|
|
};
|
|
|
|
|
2021-02-03 18:33:06 +08:00
|
|
|
bool Arch::apply_lpf(std::string filename, std::istream &in)
|
2018-10-31 18:48:54 +08:00
|
|
|
{
|
2018-10-31 19:30:09 +08:00
|
|
|
auto isempty = [](const std::string &str) {
|
2019-02-28 06:54:32 +08:00
|
|
|
return std::all_of(str.begin(), str.end(), [](char c) { return isblank(c) || c == '\r' || c == '\n'; });
|
2018-10-31 19:30:09 +08:00
|
|
|
};
|
2018-10-31 18:48:54 +08:00
|
|
|
try {
|
|
|
|
if (!in)
|
|
|
|
log_error("failed to open LPF file\n");
|
|
|
|
std::string line;
|
|
|
|
std::string linebuf;
|
2019-02-25 22:40:38 +08:00
|
|
|
int lineno = 0;
|
2023-01-02 15:39:00 +08:00
|
|
|
auto strip_quotes = [&](const std::string &str) {
|
|
|
|
if (str.at(0) == '"') {
|
|
|
|
if (str.back() != '"') {
|
|
|
|
log_error("expected '\"' at end of string '%s' (on line %d)\n", str.c_str(), lineno);
|
|
|
|
}
|
|
|
|
return str.substr(1, str.size() - 2);
|
|
|
|
} else {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
};
|
2018-10-31 18:48:54 +08:00
|
|
|
while (std::getline(in, line)) {
|
2019-02-25 22:40:38 +08:00
|
|
|
++lineno;
|
2018-10-31 18:48:54 +08:00
|
|
|
size_t cstart = line.find('#');
|
2020-05-14 20:06:58 +08:00
|
|
|
if (cstart != std::string::npos)
|
|
|
|
line = line.substr(0, cstart);
|
|
|
|
cstart = line.find("//");
|
2018-10-31 18:48:54 +08:00
|
|
|
if (cstart != std::string::npos)
|
|
|
|
line = line.substr(0, cstart);
|
|
|
|
if (isempty(line))
|
|
|
|
continue;
|
|
|
|
linebuf += line;
|
|
|
|
// Look for a command up to a semicolon
|
|
|
|
size_t scpos = linebuf.find(';');
|
|
|
|
while (scpos != std::string::npos) {
|
|
|
|
std::string command = linebuf.substr(0, scpos);
|
|
|
|
// Split command into words
|
2018-10-31 19:30:09 +08:00
|
|
|
std::stringstream ss(command);
|
2018-10-31 18:48:54 +08:00
|
|
|
std::vector<std::string> words;
|
|
|
|
std::string tmp;
|
|
|
|
while (ss >> tmp)
|
|
|
|
words.push_back(tmp);
|
2021-02-25 19:21:39 +08:00
|
|
|
if (words.size() > 0) {
|
2018-10-31 18:48:54 +08:00
|
|
|
std::string verb = words.at(0);
|
2020-07-12 19:53:16 +08:00
|
|
|
if (verb == "BLOCK") {
|
2019-02-25 22:40:38 +08:00
|
|
|
if (words.size() != 2 || (words.at(1) != "ASYNCPATHS" && words.at(1) != "RESETPATHS"))
|
|
|
|
log_warning(" ignoring unsupported LPF command '%s' (on line %d)\n", command.c_str(),
|
|
|
|
lineno);
|
2020-07-12 19:53:16 +08:00
|
|
|
} else if (verb == "SYSCONFIG") {
|
|
|
|
for (size_t i = 1; i < words.size(); i++) {
|
|
|
|
std::string setting = words.at(i);
|
|
|
|
size_t eqpos = setting.find('=');
|
|
|
|
if (eqpos == std::string::npos)
|
|
|
|
log_error("expected syntax 'SYSCONFIG <attr>=<value>...' (on line %d)\n", lineno);
|
|
|
|
std::string key = setting.substr(0, eqpos), value = setting.substr(eqpos + 1);
|
|
|
|
if (!sysconfig_keys.count(key))
|
|
|
|
log_error("unexpected SYSCONFIG key '%s' (on line %d)\n", key.c_str(), lineno);
|
|
|
|
settings[id("arch.sysconfig." + key)] = value;
|
|
|
|
}
|
2019-02-22 19:46:43 +08:00
|
|
|
} else if (verb == "FREQUENCY") {
|
2019-02-25 22:40:38 +08:00
|
|
|
if (words.size() < 2)
|
|
|
|
log_error("expected object type after FREQUENCY (on line %d)\n", lineno);
|
2019-02-22 19:46:43 +08:00
|
|
|
std::string etype = words.at(1);
|
|
|
|
if (etype == "PORT" || etype == "NET") {
|
2019-02-25 22:40:38 +08:00
|
|
|
if (words.size() < 4)
|
|
|
|
log_error("expected frequency value and unit after 'FREQUENCY %s' (on line %d)\n",
|
|
|
|
etype.c_str(), lineno);
|
|
|
|
std::string target = strip_quotes(words.at(2));
|
2019-02-22 19:46:43 +08:00
|
|
|
float freq = std::stof(words.at(3));
|
|
|
|
std::string unit = words.at(4);
|
2019-02-28 06:54:32 +08:00
|
|
|
boost::algorithm::to_upper(unit);
|
|
|
|
if (unit == "MHZ")
|
2019-02-22 19:46:43 +08:00
|
|
|
;
|
2019-02-28 06:54:32 +08:00
|
|
|
else if (unit == "KHZ")
|
2019-02-22 19:46:43 +08:00
|
|
|
freq /= 1.0e3;
|
2019-02-28 06:54:32 +08:00
|
|
|
else if (unit == "HZ")
|
2019-02-22 19:46:43 +08:00
|
|
|
freq /= 1.0e6;
|
|
|
|
else
|
2019-02-25 22:40:38 +08:00
|
|
|
log_error("unsupported frequency unit '%s' (on line %d)\n", unit.c_str(), lineno);
|
2019-02-22 19:46:43 +08:00
|
|
|
addClock(id(target), freq);
|
|
|
|
} else {
|
2019-02-25 22:40:38 +08:00
|
|
|
log_warning(" ignoring unsupported LPF command '%s %s' (on line %d)\n", command.c_str(),
|
|
|
|
etype.c_str(), lineno);
|
2019-02-22 19:46:43 +08:00
|
|
|
}
|
2018-10-31 18:48:54 +08:00
|
|
|
} else if (verb == "LOCATE") {
|
2019-02-25 22:40:38 +08:00
|
|
|
if (words.size() < 5)
|
|
|
|
log_error("expected syntax 'LOCATE COMP <port name> SITE <pin>' (on line %d)\n", lineno);
|
|
|
|
if (words.at(1) != "COMP")
|
|
|
|
log_error("expected 'COMP' after 'LOCATE' (on line %d)\n", lineno);
|
2018-10-31 18:48:54 +08:00
|
|
|
std::string cell = strip_quotes(words.at(2));
|
2019-02-25 22:40:38 +08:00
|
|
|
if (words.at(3) != "SITE")
|
|
|
|
log_error("expected 'SITE' after 'LOCATE COMP %s' (on line %d)\n", cell.c_str(), lineno);
|
2018-10-31 18:48:54 +08:00
|
|
|
auto fnd_cell = cells.find(id(cell));
|
2020-04-06 11:35:21 +08:00
|
|
|
if (words.size() > 5)
|
|
|
|
log_error("unexpected input following LOCATE clause (on line %d)\n", lineno);
|
2019-02-25 22:40:38 +08:00
|
|
|
if (fnd_cell != cells.end()) {
|
2022-02-17 01:09:54 +08:00
|
|
|
fnd_cell->second->attrs[id_LOC] = strip_quotes(words.at(4));
|
2018-10-31 18:48:54 +08:00
|
|
|
}
|
|
|
|
} else if (verb == "IOBUF") {
|
2019-02-25 22:40:38 +08:00
|
|
|
if (words.size() < 3)
|
|
|
|
log_error("expected syntax 'IOBUF PORT <port name> <attr>=<value>...' (on line %d)\n",
|
|
|
|
lineno);
|
|
|
|
if (words.at(1) != "PORT")
|
|
|
|
log_error("expected 'PORT' after 'IOBUF' (on line %d)\n", lineno);
|
2018-10-31 18:48:54 +08:00
|
|
|
std::string cell = strip_quotes(words.at(2));
|
|
|
|
auto fnd_cell = cells.find(id(cell));
|
2019-02-25 22:40:38 +08:00
|
|
|
if (fnd_cell != cells.end()) {
|
2018-10-31 18:48:54 +08:00
|
|
|
for (size_t i = 3; i < words.size(); i++) {
|
|
|
|
std::string setting = words.at(i);
|
|
|
|
size_t eqpos = setting.find('=');
|
2019-02-25 22:40:38 +08:00
|
|
|
if (eqpos == std::string::npos)
|
|
|
|
log_error(
|
|
|
|
"expected syntax 'IOBUF PORT <port name> <attr>=<value>...' (on line %d)\n",
|
|
|
|
lineno);
|
2018-10-31 18:48:54 +08:00
|
|
|
std::string key = setting.substr(0, eqpos), value = setting.substr(eqpos + 1);
|
2020-07-14 00:30:24 +08:00
|
|
|
if (!iobuf_keys.count(key))
|
|
|
|
log_warning("IOBUF '%s' attribute '%s' is not recognised (on line %d)\n",
|
|
|
|
cell.c_str(), key.c_str(), lineno);
|
2018-10-31 18:48:54 +08:00
|
|
|
fnd_cell->second->attrs[id(key)] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 19:30:09 +08:00
|
|
|
linebuf = linebuf.substr(scpos + 1);
|
2018-10-31 18:48:54 +08:00
|
|
|
scpos = linebuf.find(';');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isempty(linebuf))
|
|
|
|
log_error("unexpected end of LPF file\n");
|
2019-06-13 00:34:34 +08:00
|
|
|
settings[id("input/lpf")] = filename;
|
2018-10-31 18:48:54 +08:00
|
|
|
return true;
|
|
|
|
} catch (log_execution_error_exception) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NEXTPNR_NAMESPACE_END
|