From 71176ac5384c696dde1d5601ea1beb5c46f281c6 Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 22 Jun 2018 12:34:42 +0200 Subject: Fixing 5k bitstream gen and place heuristics Signed-off-by: David Shah --- common/place_sa.cc | 5 ++--- ice40/bitstream.cc | 13 ++++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/common/place_sa.cc b/common/place_sa.cc index 69ba968f..cd4e7282 100644 --- a/common/place_sa.cc +++ b/common/place_sa.cc @@ -410,9 +410,8 @@ class SAPlacer delta = new_wirelength - curr_wirelength; n_move++; // SA acceptance criterea - if (delta < 0 || (temp > 1e-6 && - (ctx->rng() / float(0x3fffffff)) <= - std::exp(-(delta / 2) / temp))) { + if (delta < 0 || (temp > 1e-6 && (ctx->rng() / float(0x3fffffff)) <= + std::exp(-delta / temp))) { n_accept++; if (delta < 2) improved = true; diff --git a/ice40/bitstream.cc b/ice40/bitstream.cc index 8754fef7..e722cea4 100644 --- a/ice40/bitstream.cc +++ b/ice40/bitstream.cc @@ -229,6 +229,16 @@ void write_asc(const Context *ctx, std::ostream &out) set_config(ti, config.at(iey).at(iex), "IoCtrl.REN_" + std::to_string(iez), !pullup); } + + if (ctx->args.type == ArchArgs::UP5K) { + if (iez == 0) { + set_config(ti, config.at(iey).at(iex), "IoCtrl.cf_bit_39", + !pullup); + } else if (iez == 1) { + set_config(ti, config.at(iey).at(iex), "IoCtrl.cf_bit_35", + !pullup); + } + } } else if (cell.second->type == ctx->id("SB_GB")) { // no cell config bits } else if (cell.second->type == ctx->id("ICESTORM_RAM")) { @@ -312,7 +322,8 @@ void write_asc(const Context *ctx, std::ostream &out) ctx->args.type == ArchArgs::HX8K) { setColBufCtrl = (y == 8 || y == 9 || y == 24 || y == 25); } else if (ctx->args.type == ArchArgs::UP5K) { - if (tile == TILE_LOGIC) { + if (tile == TILE_LOGIC || tile == TILE_RAMB || + tile == TILE_RAMT) { setColBufCtrl = (y == 4 || y == 5 || y == 14 || y == 15 || y == 26 || y == 27); } else { -- cgit v1.2.3 From 3cd12e3671e5ee108f039cb4350bf885164a8cf5 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 12:11:22 +0200 Subject: Add ability to terminate running tasks --- gui/ice40/mainwindow.cc | 14 ++++++++++---- gui/ice40/worker.cc | 42 ++++++++++++++++++++++++++++++++++++------ gui/ice40/worker.h | 13 ++++++++++++- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 934798bb..e36464a0 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -17,18 +17,24 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent) std::string title = "nextpnr-ice40 - " + ctx->getChipName(); setWindowTitle(title.c_str()); - createMenu(); - task = new TaskManager(_ctx); connect(task, SIGNAL(log(std::string)), this, SLOT(writeInfo(std::string))); + + createMenu(); } -MainWindow::~MainWindow() {} +MainWindow::~MainWindow() { delete task; } void MainWindow::createMenu() { QMenu *menu_Custom = new QMenu("&ICE 40", menuBar); menuBar->addAction(menu_Custom->menuAction()); + + QAction *actionTerminate = new QAction("Terminate", this); + actionTerminate->setStatusTip("Terminate running task"); + connect(actionTerminate, SIGNAL(triggered()), task, + SLOT(terminate_thread())); + menu_Custom->addAction(actionTerminate); } void MainWindow::open() @@ -39,7 +45,7 @@ void MainWindow::open() tabWidget->setCurrentWidget(info); std::string fn = fileName.toStdString(); - task->parsejson(fn); + Q_EMIT task->parsejson(fn); } } bool MainWindow::save() { return false; } \ No newline at end of file diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 5702137b..a309f868 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -10,9 +10,19 @@ #include "route.h" #include "timing.h" -Worker::Worker(Context *_ctx) : ctx(_ctx) +struct WorkerInterruptionRequested { - log_write_function = [this](std::string text) { Q_EMIT log(text); }; +}; + +Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) +{ + log_write_function = [this, parent](std::string text) { + Q_EMIT log(text); + if (parent->shouldTerminate()) { + parent->clearTerminate(); + throw WorkerInterruptionRequested(); + } + }; } void Worker::parsejson(const std::string &filename) @@ -32,14 +42,16 @@ void Worker::parsejson(const std::string &filename) log_error("Placing design failed.\n"); if (!route_design(ctx)) log_error("Routing design failed.\n"); - Q_EMIT log("done"); + Q_EMIT log("DONE\n"); } catch (log_execution_error_exception) { + } catch (WorkerInterruptionRequested) { + Q_EMIT log("CANCELED\n"); } } -TaskManager::TaskManager(Context *ctx) +TaskManager::TaskManager(Context *ctx) : toTerminate(false) { - Worker *worker = new Worker(ctx); + Worker *worker = new Worker(ctx, this); worker->moveToThread(&workerThread); connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(this, &TaskManager::parsejson, worker, &Worker::parsejson); @@ -53,4 +65,22 @@ TaskManager::~TaskManager() workerThread.wait(); } -void TaskManager::info(const std::string &result) { Q_EMIT log(result); } \ No newline at end of file +void TaskManager::info(const std::string &result) { Q_EMIT log(result); } + +void TaskManager::terminate_thread() +{ + QMutexLocker locker(&mutex); + toTerminate = true; +} + +bool TaskManager::shouldTerminate() +{ + QMutexLocker locker(&mutex); + return toTerminate; +} + +void TaskManager::clearTerminate() +{ + QMutexLocker locker(&mutex); + toTerminate = false; +} \ No newline at end of file diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index 12d740dd..a2d220bd 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -1,17 +1,20 @@ #ifndef WORKER_H #define WORKER_H +#include #include #include "nextpnr.h" // FIXME USING_NEXTPNR_NAMESPACE +class TaskManager; + class Worker : public QObject { Q_OBJECT public: - Worker(Context *ctx); + Worker(Context *ctx, TaskManager *parent); public Q_SLOTS: void parsejson(const std::string &filename); Q_SIGNALS: @@ -29,11 +32,19 @@ class TaskManager : public QObject public: TaskManager(Context *ctx); ~TaskManager(); + bool shouldTerminate(); + void clearTerminate(); public Q_SLOTS: void info(const std::string &text); + void terminate_thread(); Q_SIGNALS: + void terminate(); void parsejson(const std::string &); void log(const std::string &text); + + private: + QMutex mutex; + bool toTerminate; }; #endif // WORKER_H -- cgit v1.2.3 From 5cb893aebdfdf711755b9bf610b36b8ff2d942ff Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 12:24:50 +0200 Subject: terminate on close --- gui/ice40/worker.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index a309f868..4b101e7e 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -61,6 +61,8 @@ TaskManager::TaskManager(Context *ctx) : toTerminate(false) TaskManager::~TaskManager() { + if (workerThread.isRunning()) + terminate_thread(); workerThread.quit(); workerThread.wait(); } -- cgit v1.2.3 From 11d99853ab4514b1f6b87c5beb87c91f50e702a6 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 12:49:20 +0200 Subject: more task control --- gui/CMakeLists.txt | 2 +- gui/base.qrc | 8 ++++++++ gui/basewindow.cc | 2 +- gui/dummy/nextpnr.qrc | 2 ++ gui/ice40/mainwindow.cc | 35 ++++++++++++++++++++++++++++++---- gui/ice40/nextpnr.qrc | 7 +++++++ gui/ice40/resources/control_pause.png | Bin 0 -> 598 bytes gui/ice40/resources/control_play.png | Bin 0 -> 592 bytes gui/ice40/resources/control_stop.png | Bin 0 -> 403 bytes gui/ice40/worker.cc | 22 ++++++++++++++++++++- gui/ice40/worker.h | 4 ++++ gui/nextpnr.qrc | 8 -------- 12 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 gui/base.qrc create mode 100644 gui/dummy/nextpnr.qrc create mode 100644 gui/ice40/nextpnr.qrc create mode 100644 gui/ice40/resources/control_pause.png create mode 100644 gui/ice40/resources/control_play.png create mode 100644 gui/ice40/resources/control_stop.png delete mode 100644 gui/nextpnr.qrc diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index b4dcde11..f19d2d20 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) aux_source_directory(. GUI_SOURCE_FILES) aux_source_directory(${family}/ GUI_SOURCE_FILES) -set(_RESOURCES nextpnr.qrc) +set(_RESOURCES base.qrc ${family}/nextpnr.qrc) qt5_add_resources(GUI_RESOURCE_FILES ${_RESOURCES}) diff --git a/gui/base.qrc b/gui/base.qrc new file mode 100644 index 00000000..b9e2f237 --- /dev/null +++ b/gui/base.qrc @@ -0,0 +1,8 @@ + + + resources/new.png + resources/open.png + resources/save.png + resources/exit.png + + diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 9020a719..b7258dd3 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -13,7 +13,7 @@ BaseMainWindow::BaseMainWindow(Context *_ctx, QWidget *parent) : QMainWindow(parent), ctx(_ctx) { - Q_INIT_RESOURCE(nextpnr); + Q_INIT_RESOURCE(base); qRegisterMetaType(); log_files.clear(); diff --git a/gui/dummy/nextpnr.qrc b/gui/dummy/nextpnr.qrc new file mode 100644 index 00000000..03585ec0 --- /dev/null +++ b/gui/dummy/nextpnr.qrc @@ -0,0 +1,2 @@ + + diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index e36464a0..9ce7f41e 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -14,6 +14,8 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, parent) { + Q_INIT_RESOURCE(nextpnr); + std::string title = "nextpnr-ice40 - " + ctx->getChipName(); setWindowTitle(title.c_str()); @@ -30,11 +32,36 @@ void MainWindow::createMenu() QMenu *menu_Custom = new QMenu("&ICE 40", menuBar); menuBar->addAction(menu_Custom->menuAction()); - QAction *actionTerminate = new QAction("Terminate", this); - actionTerminate->setStatusTip("Terminate running task"); - connect(actionTerminate, SIGNAL(triggered()), task, + QAction *actionPlay = new QAction("Play", this); + QIcon icon1; + icon1.addFile(QStringLiteral(":/icons/resources/control_play.png")); + actionPlay->setIcon(icon1); + actionPlay->setStatusTip("Continue running task"); + connect(actionPlay, SIGNAL(triggered()), task, + SLOT(continue_thread())); + + QAction *actionPause = new QAction("Pause", this); + QIcon icon2; + icon2.addFile(QStringLiteral(":/icons/resources/control_pause.png")); + actionPause->setIcon(icon2); + actionPause->setStatusTip("Pause running task"); + connect(actionPause, SIGNAL(triggered()), task, + SLOT(pause_thread())); + + QAction *actionStop = new QAction("Stop", this); + QIcon icon3; + icon3.addFile(QStringLiteral(":/icons/resources/control_stop.png")); + actionStop->setIcon(icon3); + actionStop->setStatusTip("Stop running task"); + connect(actionStop, SIGNAL(triggered()), task, SLOT(terminate_thread())); - menu_Custom->addAction(actionTerminate); + + QToolBar *taskToolBar = new QToolBar(); + addToolBar(Qt::TopToolBarArea, taskToolBar); + + taskToolBar->addAction(actionPlay); + taskToolBar->addAction(actionPause); + taskToolBar->addAction(actionStop); } void MainWindow::open() diff --git a/gui/ice40/nextpnr.qrc b/gui/ice40/nextpnr.qrc new file mode 100644 index 00000000..cbdb8b26 --- /dev/null +++ b/gui/ice40/nextpnr.qrc @@ -0,0 +1,7 @@ + + + resources/control_play.png + resources/control_pause.png + resources/control_stop.png + + diff --git a/gui/ice40/resources/control_pause.png b/gui/ice40/resources/control_pause.png new file mode 100644 index 00000000..2d9ce9c4 Binary files /dev/null and b/gui/ice40/resources/control_pause.png differ diff --git a/gui/ice40/resources/control_play.png b/gui/ice40/resources/control_play.png new file mode 100644 index 00000000..0846555d Binary files /dev/null and b/gui/ice40/resources/control_play.png differ diff --git a/gui/ice40/resources/control_stop.png b/gui/ice40/resources/control_stop.png new file mode 100644 index 00000000..893bb60e Binary files /dev/null and b/gui/ice40/resources/control_stop.png differ diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 4b101e7e..3854c67f 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -22,6 +22,9 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) parent->clearTerminate(); throw WorkerInterruptionRequested(); } + while (parent->isPaused()){ + QThread::sleep(1); + } }; } @@ -49,7 +52,7 @@ void Worker::parsejson(const std::string &filename) } } -TaskManager::TaskManager(Context *ctx) : toTerminate(false) +TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false) { Worker *worker = new Worker(ctx, this); worker->moveToThread(&workerThread); @@ -85,4 +88,21 @@ void TaskManager::clearTerminate() { QMutexLocker locker(&mutex); toTerminate = false; +} + +void TaskManager::pause_thread() +{ + QMutexLocker locker(&mutex); + toPause = true; +} + +void TaskManager::continue_thread() +{ + QMutexLocker locker(&mutex); + toPause = false; +} +bool TaskManager::isPaused() +{ + QMutexLocker locker(&mutex); + return toPause; } \ No newline at end of file diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index a2d220bd..49d1df4d 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -34,9 +34,12 @@ class TaskManager : public QObject ~TaskManager(); bool shouldTerminate(); void clearTerminate(); + bool isPaused(); public Q_SLOTS: void info(const std::string &text); void terminate_thread(); + void pause_thread(); + void continue_thread(); Q_SIGNALS: void terminate(); void parsejson(const std::string &); @@ -45,6 +48,7 @@ class TaskManager : public QObject private: QMutex mutex; bool toTerminate; + bool toPause; }; #endif // WORKER_H diff --git a/gui/nextpnr.qrc b/gui/nextpnr.qrc deleted file mode 100644 index b9e2f237..00000000 --- a/gui/nextpnr.qrc +++ /dev/null @@ -1,8 +0,0 @@ - - - resources/new.png - resources/open.png - resources/save.png - resources/exit.png - - -- cgit v1.2.3 From 63baa10032ecf301523e4cb1fca198d8a8b79e23 Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 22 Jun 2018 12:57:22 +0200 Subject: ice40: Make the packer deterministic Signed-off-by: David Shah --- common/util.h | 8 ++++++++ ice40/pack.cc | 17 +++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/common/util.h b/common/util.h index 34b2ed02..8151564f 100644 --- a/common/util.h +++ b/common/util.h @@ -21,6 +21,7 @@ #define UTIL_H #include +#include #include "nextpnr.h" NEXTPNR_NAMESPACE_BEGIN @@ -56,6 +57,13 @@ bool bool_or_default(const Container &ct, const KeyType &key, bool def = false) { return bool(int_or_default(ct, key, int(def))); }; + +// Wrap an unordered_map, and allow it to be iterated over sorted by key +template std::map sorted(const std::unordered_map &orig) { + return std::map(orig.begin(), orig.end()); +}; + + NEXTPNR_NAMESPACE_END #endif diff --git a/ice40/pack.cc b/ice40/pack.cc index 9258014e..35cef8b8 100644 --- a/ice40/pack.cc +++ b/ice40/pack.cc @@ -24,6 +24,7 @@ #include "cells.h" #include "design_utils.h" #include "log.h" +#include "util.h" NEXTPNR_NAMESPACE_BEGIN @@ -34,7 +35,7 @@ static void pack_lut_lutffs(Context *ctx) std::unordered_set packed_cells; std::vector new_cells; - for (auto cell : ctx->cells) { + for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (ctx->verbose) log_info("cell '%s' is of type '%s'\n", ci->name.c_str(ctx), @@ -96,7 +97,7 @@ static void pack_nonlut_ffs(Context *ctx) std::unordered_set packed_cells; std::vector new_cells; - for (auto cell : ctx->cells) { + for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (is_ff(ctx, ci)) { CellInfo *packed = create_ice_cell(ctx, "ICESTORM_LC", @@ -126,7 +127,7 @@ static void pack_carries(Context *ctx) std::unordered_set packed_cells; - for (auto cell : ctx->cells) { + for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (is_carry(ctx, ci)) { packed_cells.insert(cell.first); @@ -201,7 +202,7 @@ static void pack_ram(Context *ctx) std::unordered_set packed_cells; std::vector new_cells; - for (auto cell : ctx->cells) { + for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (is_ram(ctx, ci)) { CellInfo *packed = create_ice_cell(ctx, "ICESTORM_RAM", @@ -285,7 +286,7 @@ static void pack_constants(Context *ctx) bool gnd_used = false, vcc_used = false; - for (auto net : ctx->nets) { + for (auto net : sorted(ctx->nets)) { NetInfo *ni = net.second; if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("GND")) { @@ -329,7 +330,7 @@ static void pack_io(Context *ctx) log_info("Packing IOs..\n"); - for (auto cell : ctx->cells) { + for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (is_nextpnr_iob(ctx, ci)) { CellInfo *sb = nullptr; @@ -412,8 +413,8 @@ static void promote_globals(Context *ctx) { log_info("Promoting globals..\n"); - std::unordered_map clock_count, reset_count, cen_count; - for (auto net : ctx->nets) { + std::map clock_count, reset_count, cen_count; + for (auto net : sorted(ctx->nets)) { NetInfo *ni = net.second; if (ni->driver.cell != nullptr && !is_global_net(ctx, ni)) { clock_count[net.first] = 0; -- cgit v1.2.3 From 7f368282700172925428e45f23b8b61e0bf39f94 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 13:10:27 +0200 Subject: fixed namespace for gui section --- gui/basewindow.cc | 8 +++++++- gui/basewindow.h | 7 ++++--- gui/designwidget.cc | 4 ++++ gui/designwidget.h | 5 +++-- gui/dummy/mainwindow.cc | 10 +++++++++- gui/dummy/mainwindow.h | 5 +++-- gui/fpgaviewwidget.cc | 4 ++++ gui/fpgaviewwidget.h | 5 +++-- gui/ice40/mainwindow.cc | 22 +++++++++++++--------- gui/ice40/mainwindow.h | 5 +++-- gui/ice40/worker.cc | 10 +++++++--- gui/ice40/worker.h | 5 +++-- gui/infotab.cc | 4 ++++ gui/infotab.h | 5 +++-- gui/line_editor.cc | 7 +++++-- gui/line_editor.h | 5 +++++ gui/pythontab.cc | 6 +++++- gui/pythontab.h | 5 +++-- ice40/main.cc | 2 ++ 19 files changed, 90 insertions(+), 34 deletions(-) diff --git a/gui/basewindow.cc b/gui/basewindow.cc index b7258dd3..f16b205d 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -10,10 +10,14 @@ #include "mainwindow.h" #include "pythontab.h" +static void initBasenameResource() { Q_INIT_RESOURCE(base); } + +NEXTPNR_NAMESPACE_BEGIN + BaseMainWindow::BaseMainWindow(Context *_ctx, QWidget *parent) : QMainWindow(parent), ctx(_ctx) { - Q_INIT_RESOURCE(base); + initBasenameResource(); qRegisterMetaType(); log_files.clear(); @@ -114,3 +118,5 @@ void BaseMainWindow::createMenusAndBars() mainToolBar->addAction(actionOpen); mainToolBar->addAction(actionSave); } + +NEXTPNR_NAMESPACE_END diff --git a/gui/basewindow.h b/gui/basewindow.h index b20d4621..55e4affc 100644 --- a/gui/basewindow.h +++ b/gui/basewindow.h @@ -11,11 +11,10 @@ #include #include -// FIXME -USING_NEXTPNR_NAMESPACE - Q_DECLARE_METATYPE(std::string) +NEXTPNR_NAMESPACE_BEGIN + class BaseMainWindow : public QMainWindow { Q_OBJECT @@ -45,4 +44,6 @@ class BaseMainWindow : public QMainWindow QStatusBar *statusBar; }; +NEXTPNR_NAMESPACE_END + #endif // BASEMAINWINDOW_H diff --git a/gui/designwidget.cc b/gui/designwidget.cc index 9bb25992..7b1ce543 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -7,6 +7,8 @@ #include "fpgaviewwidget.h" #include "pybindings.h" +NEXTPNR_NAMESPACE_BEGIN + enum class ElementType { BEL, @@ -234,3 +236,5 @@ void DesignWidget::selectObject() { Q_EMIT info("selected " + itemContextMenu->text(0).toStdString() + "\n"); } + +NEXTPNR_NAMESPACE_END diff --git a/gui/designwidget.h b/gui/designwidget.h index 9682726c..5bd12d4d 100644 --- a/gui/designwidget.h +++ b/gui/designwidget.h @@ -7,8 +7,7 @@ #include "qttreepropertybrowser.h" #include "qtvariantproperty.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class DesignWidget : public QWidget { @@ -45,4 +44,6 @@ class DesignWidget : public QWidget QMap idToProperty; }; +NEXTPNR_NAMESPACE_END + #endif // DESIGNWIDGET_H diff --git a/gui/dummy/mainwindow.cc b/gui/dummy/mainwindow.cc index 7982c5f5..da162dd0 100644 --- a/gui/dummy/mainwindow.cc +++ b/gui/dummy/mainwindow.cc @@ -1,8 +1,14 @@ #include "mainwindow.h" +static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } + +NEXTPNR_NAMESPACE_BEGIN + MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, parent) { + initMainResource(); + std::string title = "nextpnr-dummy - " + ctx->getChipName(); setWindowTitle(title.c_str()); @@ -19,4 +25,6 @@ void MainWindow::createMenu() void MainWindow::open() {} -bool MainWindow::save() { return false; } \ No newline at end of file +bool MainWindow::save() { return false; } + +NEXTPNR_NAMESPACE_END diff --git a/gui/dummy/mainwindow.h b/gui/dummy/mainwindow.h index c9690f2c..c2786906 100644 --- a/gui/dummy/mainwindow.h +++ b/gui/dummy/mainwindow.h @@ -3,8 +3,7 @@ #include "../basewindow.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class MainWindow : public BaseMainWindow { @@ -22,4 +21,6 @@ class MainWindow : public BaseMainWindow virtual bool save(); }; +NEXTPNR_NAMESPACE_END + #endif // MAINWINDOW_H diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index 6b7e7787..8119eae3 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -6,6 +6,8 @@ #include #include "mainwindow.h" +NEXTPNR_NAMESPACE_BEGIN + FPGAViewWidget::FPGAViewWidget(QWidget *parent) : QOpenGLWidget(parent), m_xMove(0), m_yMove(0), m_zDistance(1.0) { @@ -173,3 +175,5 @@ void FPGAViewWidget::wheelEvent(QWheelEvent *event) setZoom(step.y() * -0.1f); } } + +NEXTPNR_NAMESPACE_END diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index 2407f757..fc3ca562 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -7,8 +7,7 @@ #include #include "nextpnr.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions { @@ -49,4 +48,6 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions Context *ctx; }; +NEXTPNR_NAMESPACE_END + #endif diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 9ce7f41e..4c7bc18f 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -11,11 +11,15 @@ #include "place_sa.h" #include "route.h" +static void initMainResource() { Q_INIT_RESOURCE(nextpnr); } + +NEXTPNR_NAMESPACE_BEGIN + MainWindow::MainWindow(Context *_ctx, QWidget *parent) : BaseMainWindow(_ctx, parent) { - Q_INIT_RESOURCE(nextpnr); - + initMainResource(); + std::string title = "nextpnr-ice40 - " + ctx->getChipName(); setWindowTitle(title.c_str()); @@ -37,24 +41,21 @@ void MainWindow::createMenu() icon1.addFile(QStringLiteral(":/icons/resources/control_play.png")); actionPlay->setIcon(icon1); actionPlay->setStatusTip("Continue running task"); - connect(actionPlay, SIGNAL(triggered()), task, - SLOT(continue_thread())); + connect(actionPlay, SIGNAL(triggered()), task, SLOT(continue_thread())); QAction *actionPause = new QAction("Pause", this); QIcon icon2; icon2.addFile(QStringLiteral(":/icons/resources/control_pause.png")); actionPause->setIcon(icon2); actionPause->setStatusTip("Pause running task"); - connect(actionPause, SIGNAL(triggered()), task, - SLOT(pause_thread())); + connect(actionPause, SIGNAL(triggered()), task, SLOT(pause_thread())); QAction *actionStop = new QAction("Stop", this); QIcon icon3; icon3.addFile(QStringLiteral(":/icons/resources/control_stop.png")); actionStop->setIcon(icon3); actionStop->setStatusTip("Stop running task"); - connect(actionStop, SIGNAL(triggered()), task, - SLOT(terminate_thread())); + connect(actionStop, SIGNAL(triggered()), task, SLOT(terminate_thread())); QToolBar *taskToolBar = new QToolBar(); addToolBar(Qt::TopToolBarArea, taskToolBar); @@ -75,4 +76,7 @@ void MainWindow::open() Q_EMIT task->parsejson(fn); } } -bool MainWindow::save() { return false; } \ No newline at end of file + +bool MainWindow::save() { return false; } + +NEXTPNR_NAMESPACE_END \ No newline at end of file diff --git a/gui/ice40/mainwindow.h b/gui/ice40/mainwindow.h index fd65f9ae..712f341a 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -4,8 +4,7 @@ #include "../basewindow.h" #include "worker.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class MainWindow : public BaseMainWindow { @@ -26,4 +25,6 @@ class MainWindow : public BaseMainWindow TaskManager *task; }; +NEXTPNR_NAMESPACE_END + #endif // MAINWINDOW_H diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 3854c67f..9549f659 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -10,6 +10,8 @@ #include "route.h" #include "timing.h" +NEXTPNR_NAMESPACE_BEGIN + struct WorkerInterruptionRequested { }; @@ -22,7 +24,7 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) parent->clearTerminate(); throw WorkerInterruptionRequested(); } - while (parent->isPaused()){ + while (parent->isPaused()) { QThread::sleep(1); } }; @@ -64,7 +66,7 @@ TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false) TaskManager::~TaskManager() { - if (workerThread.isRunning()) + if (workerThread.isRunning()) terminate_thread(); workerThread.quit(); workerThread.wait(); @@ -105,4 +107,6 @@ bool TaskManager::isPaused() { QMutexLocker locker(&mutex); return toPause; -} \ No newline at end of file +} + +NEXTPNR_NAMESPACE_END diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index 49d1df4d..181fafa3 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -5,8 +5,7 @@ #include #include "nextpnr.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class TaskManager; @@ -51,4 +50,6 @@ class TaskManager : public QObject bool toPause; }; +NEXTPNR_NAMESPACE_END + #endif // WORKER_H diff --git a/gui/infotab.cc b/gui/infotab.cc index 7690b83c..29d557d2 100644 --- a/gui/infotab.cc +++ b/gui/infotab.cc @@ -1,6 +1,8 @@ #include "infotab.h" #include +NEXTPNR_NAMESPACE_BEGIN + InfoTab::InfoTab(QWidget *parent) : QWidget(parent) { plainTextEdit = new QPlainTextEdit(); @@ -37,3 +39,5 @@ void InfoTab::showContextMenu(const QPoint &pt) } void InfoTab::clearBuffer() { plainTextEdit->clear(); } + +NEXTPNR_NAMESPACE_END diff --git a/gui/infotab.h b/gui/infotab.h index d7f1408c..3e0220c4 100644 --- a/gui/infotab.h +++ b/gui/infotab.h @@ -5,8 +5,7 @@ #include #include "nextpnr.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class InfoTab : public QWidget { @@ -24,4 +23,6 @@ class InfoTab : public QWidget QMenu *contextMenu; }; +NEXTPNR_NAMESPACE_END + #endif // INFOTAB_H diff --git a/gui/line_editor.cc b/gui/line_editor.cc index b5ed955f..6299c9cc 100644 --- a/gui/line_editor.cc +++ b/gui/line_editor.cc @@ -1,7 +1,8 @@ #include "line_editor.h" - #include +NEXTPNR_NAMESPACE_BEGIN + LineEditor::LineEditor(QWidget *parent) : QLineEdit(parent), index(0) { setContextMenuPolicy(Qt::CustomContextMenu); @@ -64,4 +65,6 @@ void LineEditor::clearHistory() lines.clear(); index = 0; clear(); -} \ No newline at end of file +} + +NEXTPNR_NAMESPACE_END \ No newline at end of file diff --git a/gui/line_editor.h b/gui/line_editor.h index 15b675f9..5f27e502 100644 --- a/gui/line_editor.h +++ b/gui/line_editor.h @@ -3,6 +3,9 @@ #include #include +#include "nextpnr.h" + +NEXTPNR_NAMESPACE_BEGIN class LineEditor : public QLineEdit { @@ -28,4 +31,6 @@ class LineEditor : public QLineEdit QMenu *contextMenu; }; +NEXTPNR_NAMESPACE_END + #endif // LINE_EDITOR_H diff --git a/gui/pythontab.cc b/gui/pythontab.cc index 96a6c4b9..19aa0162 100644 --- a/gui/pythontab.cc +++ b/gui/pythontab.cc @@ -3,6 +3,8 @@ #include "emb.h" #include "pybindings.h" +NEXTPNR_NAMESPACE_BEGIN + PythonTab::PythonTab(QWidget *parent) : QWidget(parent) { PyImport_ImportModule("emb"); @@ -114,4 +116,6 @@ void PythonTab::showContextMenu(const QPoint &pt) contextMenu->exec(mapToGlobal(pt)); } -void PythonTab::clearBuffer() { plainTextEdit->clear(); } \ No newline at end of file +void PythonTab::clearBuffer() { plainTextEdit->clear(); } + +NEXTPNR_NAMESPACE_END diff --git a/gui/pythontab.h b/gui/pythontab.h index 5aed8b0b..52a8ff8d 100644 --- a/gui/pythontab.h +++ b/gui/pythontab.h @@ -8,8 +8,7 @@ #include "line_editor.h" #include "nextpnr.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN class PythonTab : public QWidget { @@ -33,4 +32,6 @@ class PythonTab : public QWidget emb::stdout_write_type write; }; +NEXTPNR_NAMESPACE_END + #endif // PYTHONTAB_H diff --git a/ice40/main.cc b/ice40/main.cc index 067637e8..9e925148 100644 --- a/ice40/main.cc +++ b/ice40/main.cc @@ -38,6 +38,8 @@ #include "timing.h" #include "version.h" +USING_NEXTPNR_NAMESPACE + void svg_dump_el(const GraphicElement &el) { float scale = 10.0, offset = 10.0; -- cgit v1.2.3 From 6633441e32c99d09133e4a62c122a377a4af4ad1 Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 22 Jun 2018 13:22:14 +0200 Subject: Update README Signed-off-by: David Shah --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 50df309c..751a864b 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,6 @@ Prequisites - CMake 3.3 or later - Modern C++11 compiler (`clang-format` required for development) - - Note: clang may run out of memory building the chipdbs (peak memory - ~11GB) due to the system currently used. Use gcc, or the 1k-only - flag, if this causes a problem. - Qt5 or later (`qt5-default` for Ubuntu 16.04) - Python 3.5 or later, including development libraries (`python3-dev` for Ubuntu) - Boost libraries (`libboost-dev` or `libboost-all-dev` for Ubuntu) @@ -29,8 +26,8 @@ Building - For a release build, run `cmake .` - Add `-DCMAKE_INSTALL_PREFIX=/your/install/prefix` to use a different install prefix to the default `/usr/local` - Use Make to run the build itself - - For all targets, just run `make` - - For just the iCE40 CLI binary, run `make nextpnr-ice40` + - For all binary targets, just run `make` + - For just the iCE40 CLI&GUI binary, run `make nextpnr-ice40` - For just the iCE40 Python module, run `make nextpnrpy_ice40` - Using too many parallel jobs may lead to out-of-memory issues due to the significant memory needed to build the chipdbs - To install nextpnr, run `make install` -- cgit v1.2.3 From ce4ad44fd1837242324ca110a9058182eef99dcd Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 22 Jun 2018 14:58:27 +0200 Subject: Print quasi-TNS statistic during placement Signed-off-by: David Shah --- common/place_sa.cc | 24 ++++++++++++++++-------- common/util.h | 7 ++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/common/place_sa.cc b/common/place_sa.cc index cd4e7282..11f46ad9 100644 --- a/common/place_sa.cc +++ b/common/place_sa.cc @@ -146,8 +146,9 @@ class SAPlacer // Calculate wirelength after initial placement curr_wirelength = 0; + curr_tns = 0; for (auto net : ctx->nets) { - wirelen_t wl = get_wirelength(net.second); + wirelen_t wl = get_wirelength(net.second, curr_tns); wirelengths[net.first] = wl; curr_wirelength += wl; } @@ -162,8 +163,9 @@ class SAPlacer improved = false; if (iter % 5 == 0 || iter == 1) - log_info(" at iteration #%d: temp = %f, wire length = %f\n", - iter, temp, double(curr_wirelength)); + log_info(" at iteration #%d: temp = %.02f, wire length = " + "%.0f, est tns = %.02fns\n", + iter, temp, double(curr_wirelength), curr_tns); for (int m = 0; m < 15; ++m) { // Loop through all automatically placed cells @@ -220,8 +222,9 @@ class SAPlacer // Recalculate total wirelength entirely to avoid rounding errors // accumulating over time curr_wirelength = 0; + curr_tns = 0; for (auto net : ctx->nets) { - wirelen_t wl = get_wirelength(net.second); + wirelen_t wl = get_wirelength(net.second, curr_tns); wirelengths[net.first] = wl; curr_wirelength += wl; } @@ -308,7 +311,7 @@ class SAPlacer } // Get the total estimated wirelength for a net - wirelen_t get_wirelength(NetInfo *net) + wirelen_t get_wirelength(NetInfo *net, float &tns) { wirelen_t wirelength = 0; int driver_x, driver_y; @@ -337,6 +340,8 @@ class SAPlacer delay_t raw_wl = ctx->estimateDelay(drv_wire, user_wire); float slack = ctx->getDelayNS(load.budget) - ctx->getDelayNS(raw_wl); + if (slack < 0) + tns += slack; worst_slack = std::min(slack, worst_slack); int load_x, load_y; bool load_gb; @@ -348,8 +353,9 @@ class SAPlacer xmax = std::max(xmax, load_x); ymax = std::max(ymax, load_y); } - wirelength = wirelen_t((((ymax - ymin) + (xmax - xmin)) * - (1.0 + std::exp(-worst_slack / 5)))); + wirelength = + wirelen_t((((ymax - ymin) + (xmax - xmin)) * + std::min(3.0, (1.0 + std::exp(-worst_slack / 10))))); return wirelength; } @@ -403,7 +409,8 @@ class SAPlacer // Recalculate wirelengths for all nets touched by the peturbation for (auto net : update) { new_wirelength -= wirelengths.at(net->name); - wirelen_t net_new_wl = get_wirelength(net); + float temp_tns = 0; + wirelen_t net_new_wl = get_wirelength(net, temp_tns); new_wirelength += net_new_wl; new_lengths.push_back(std::make_pair(net->name, net_new_wl)); } @@ -465,6 +472,7 @@ class SAPlacer Context *ctx; std::unordered_map wirelengths; wirelen_t curr_wirelength = std::numeric_limits::max(); + float curr_tns = 0; float temp = 1000; bool improved = false; int n_move, n_accept; diff --git a/common/util.h b/common/util.h index 8151564f..4c60292b 100644 --- a/common/util.h +++ b/common/util.h @@ -20,8 +20,8 @@ #ifndef UTIL_H #define UTIL_H -#include #include +#include #include "nextpnr.h" NEXTPNR_NAMESPACE_BEGIN @@ -59,11 +59,12 @@ bool bool_or_default(const Container &ct, const KeyType &key, bool def = false) }; // Wrap an unordered_map, and allow it to be iterated over sorted by key -template std::map sorted(const std::unordered_map &orig) { +template +std::map sorted(const std::unordered_map &orig) +{ return std::map(orig.begin(), orig.end()); }; - NEXTPNR_NAMESPACE_END #endif -- cgit v1.2.3 From d7939f96e6da6eeaffe2d2851f233d32bfb5d6cd Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 22 Jun 2018 15:03:33 +0200 Subject: place_sa: Fix temp printing Signed-off-by: David Shah --- common/place_sa.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/place_sa.cc b/common/place_sa.cc index 11f46ad9..8b111c6c 100644 --- a/common/place_sa.cc +++ b/common/place_sa.cc @@ -163,7 +163,7 @@ class SAPlacer improved = false; if (iter % 5 == 0 || iter == 1) - log_info(" at iteration #%d: temp = %.02f, wire length = " + log_info(" at iteration #%d: temp = %f, wire length = " "%.0f, est tns = %.02fns\n", iter, temp, double(curr_wirelength), curr_tns); -- cgit v1.2.3 From f86a0d6c8c8792c36c87cf345665ce7c9fbcc60f Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 22 Jun 2018 15:17:00 +0200 Subject: place_sa: Tweak weighting given to timing Signed-off-by: David Shah --- common/place_sa.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/place_sa.cc b/common/place_sa.cc index 8b111c6c..058f0a84 100644 --- a/common/place_sa.cc +++ b/common/place_sa.cc @@ -355,7 +355,7 @@ class SAPlacer } wirelength = wirelen_t((((ymax - ymin) + (xmax - xmin)) * - std::min(3.0, (1.0 + std::exp(-worst_slack / 10))))); + std::min(5.0, (1.0 + std::exp(-worst_slack / 5))))); return wirelength; } -- cgit v1.2.3 From 56c09fc5e5f7fb5c299f7a0b52e839556146615d Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 Jun 2018 15:35:07 +0200 Subject: routing flow supported in gui --- gui/ice40/mainwindow.cc | 153 ++++++++++++++++++++++++++++++---- gui/ice40/mainwindow.h | 16 ++++ gui/ice40/nextpnr.qrc | 3 + gui/ice40/resources/control_pause.png | Bin 598 -> 721 bytes gui/ice40/resources/control_play.png | Bin 592 -> 717 bytes gui/ice40/resources/control_stop.png | Bin 403 -> 695 bytes gui/ice40/resources/pack.png | Bin 0 -> 853 bytes gui/ice40/resources/place.png | Bin 0 -> 825 bytes gui/ice40/resources/route.png | Bin 0 -> 683 bytes gui/ice40/worker.cc | 74 +++++++++++++--- gui/ice40/worker.h | 26 +++++- 11 files changed, 241 insertions(+), 31 deletions(-) create mode 100644 gui/ice40/resources/pack.png create mode 100644 gui/ice40/resources/place.png create mode 100644 gui/ice40/resources/route.png diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 4c7bc18f..0a248938 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -26,6 +26,15 @@ MainWindow::MainWindow(Context *_ctx, QWidget *parent) task = new TaskManager(_ctx); connect(task, SIGNAL(log(std::string)), this, SLOT(writeInfo(std::string))); + connect(task, SIGNAL(loadfile_finished(bool)), this, SLOT(loadfile_finished(bool))); + connect(task, SIGNAL(pack_finished(bool)), this, SLOT(pack_finished(bool))); + connect(task, SIGNAL(place_finished(bool)), this, SLOT(place_finished(bool))); + connect(task, SIGNAL(route_finished(bool)), this, SLOT(route_finished(bool))); + + connect(task, SIGNAL(taskCanceled()), this, SLOT(taskCanceled())); + connect(task, SIGNAL(taskStarted()), this, SLOT(taskStarted())); + connect(task, SIGNAL(taskPaused()), this, SLOT(taskPaused())); + createMenu(); } @@ -33,29 +42,67 @@ MainWindow::~MainWindow() { delete task; } void MainWindow::createMenu() { - QMenu *menu_Custom = new QMenu("&ICE 40", menuBar); - menuBar->addAction(menu_Custom->menuAction()); - - QAction *actionPlay = new QAction("Play", this); - QIcon icon1; - icon1.addFile(QStringLiteral(":/icons/resources/control_play.png")); - actionPlay->setIcon(icon1); + QMenu *menu_Design = new QMenu("&Design", menuBar); + menuBar->addAction(menu_Design->menuAction()); + + actionPack = new QAction("Pack", this); + QIcon iconPack; + iconPack.addFile(QStringLiteral(":/icons/resources/pack.png")); + actionPack->setIcon(iconPack); + actionPack->setStatusTip("Pack current design"); + connect(actionPack, SIGNAL(triggered()), task, SIGNAL(pack())); + actionPack->setEnabled(false); + + actionPlace = new QAction("Place", this); + QIcon iconPlace; + iconPlace.addFile(QStringLiteral(":/icons/resources/place.png")); + actionPlace->setIcon(iconPlace); + actionPlace->setStatusTip("Place current design"); + connect(actionPlace, SIGNAL(triggered()), task, SIGNAL(place())); + actionPlace->setEnabled(false); + + actionRoute = new QAction("Route", this); + QIcon iconRoute; + iconRoute.addFile(QStringLiteral(":/icons/resources/route.png")); + actionRoute->setIcon(iconRoute); + actionRoute->setStatusTip("Route current design"); + connect(actionRoute, SIGNAL(triggered()), task, SIGNAL(route())); + actionRoute->setEnabled(false); + + QToolBar *taskFPGABar = new QToolBar(); + addToolBar(Qt::TopToolBarArea, taskFPGABar); + + taskFPGABar->addAction(actionPack); + taskFPGABar->addAction(actionPlace); + taskFPGABar->addAction(actionRoute); + + menu_Design->addAction(actionPack); + menu_Design->addAction(actionPlace); + menu_Design->addAction(actionRoute); + + actionPlay = new QAction("Play", this); + QIcon iconPlay; + iconPlay.addFile(QStringLiteral(":/icons/resources/control_play.png")); + actionPlay->setIcon(iconPlay); actionPlay->setStatusTip("Continue running task"); connect(actionPlay, SIGNAL(triggered()), task, SLOT(continue_thread())); + actionPlay->setEnabled(false); - QAction *actionPause = new QAction("Pause", this); - QIcon icon2; - icon2.addFile(QStringLiteral(":/icons/resources/control_pause.png")); - actionPause->setIcon(icon2); + actionPause = new QAction("Pause", this); + QIcon iconPause; + iconPause.addFile(QStringLiteral(":/icons/resources/control_pause.png")); + actionPause->setIcon(iconPause); actionPause->setStatusTip("Pause running task"); connect(actionPause, SIGNAL(triggered()), task, SLOT(pause_thread())); + actionPause->setEnabled(false); - QAction *actionStop = new QAction("Stop", this); - QIcon icon3; - icon3.addFile(QStringLiteral(":/icons/resources/control_stop.png")); - actionStop->setIcon(icon3); + actionStop = new QAction("Stop", this); + QIcon iconStop; + iconStop.addFile(QStringLiteral(":/icons/resources/control_stop.png")); + actionStop->setIcon(iconStop); actionStop->setStatusTip("Stop running task"); connect(actionStop, SIGNAL(triggered()), task, SLOT(terminate_thread())); + actionStop->setEnabled(false); QToolBar *taskToolBar = new QToolBar(); addToolBar(Qt::TopToolBarArea, taskToolBar); @@ -73,10 +120,84 @@ void MainWindow::open() tabWidget->setCurrentWidget(info); std::string fn = fileName.toStdString(); - Q_EMIT task->parsejson(fn); + disableActions(); + Q_EMIT task->loadfile(fn); } } bool MainWindow::save() { return false; } +void MainWindow::disableActions() +{ + actionPack->setEnabled(false); + actionPlace->setEnabled(false); + actionRoute->setEnabled(false); + + actionPlay->setEnabled(false); + actionPause->setEnabled(false); + actionStop->setEnabled(false); +} + +void MainWindow::loadfile_finished(bool status) +{ + disableActions(); + if (status) { + log("Loading design successful.\n"); + actionPack->setEnabled(true); + } + else { + log("Loading design failed.\n"); + } +} +void MainWindow::pack_finished(bool status) +{ + disableActions(); + if (status) { + log("Packing design successful.\n"); + actionPlace->setEnabled(true); + } + else { + log("Packing design failed.\n"); + } +} +void MainWindow::place_finished(bool status) +{ + disableActions(); + if (status) { + log("Placing design successful.\n"); + actionRoute->setEnabled(true); + } + else { + log("Placing design failed.\n"); + } +} +void MainWindow::route_finished(bool status) +{ + disableActions(); + if (status) + log("Routing design successful.\n"); + else + log("Routing design failed.\n"); +} + +void MainWindow::taskCanceled() +{ + log("CANCELED\n"); + disableActions(); +} + +void MainWindow::taskStarted() +{ + disableActions(); + actionPause->setEnabled(true); + actionStop->setEnabled(true); +} + +void MainWindow::taskPaused() +{ + disableActions(); + actionPlay->setEnabled(true); + actionStop->setEnabled(true); +} + NEXTPNR_NAMESPACE_END \ No newline at end of file diff --git a/gui/ice40/mainwindow.h b/gui/ice40/mainwindow.h index 712f341a..9083ed8a 100644 --- a/gui/ice40/mainwindow.h +++ b/gui/ice40/mainwindow.h @@ -20,9 +20,25 @@ class MainWindow : public BaseMainWindow protected Q_SLOTS: virtual void open(); virtual bool save(); + void loadfile_finished(bool status); + void pack_finished(bool status); + void place_finished(bool status); + void route_finished(bool status); + + void taskCanceled(); + void taskStarted(); + void taskPaused(); private: + void disableActions(); + TaskManager *task; + QAction *actionPack; + QAction *actionPlace; + QAction *actionRoute; + QAction *actionPlay; + QAction *actionPause; + QAction *actionStop; }; NEXTPNR_NAMESPACE_END diff --git a/gui/ice40/nextpnr.qrc b/gui/ice40/nextpnr.qrc index cbdb8b26..3bc68978 100644 --- a/gui/ice40/nextpnr.qrc +++ b/gui/ice40/nextpnr.qrc @@ -3,5 +3,8 @@ resources/control_play.png resources/control_pause.png resources/control_stop.png + resources/pack.png + resources/place.png + resources/route.png diff --git a/gui/ice40/resources/control_pause.png b/gui/ice40/resources/control_pause.png index 2d9ce9c4..ec61099b 100644 Binary files a/gui/ice40/resources/control_pause.png and b/gui/ice40/resources/control_pause.png differ diff --git a/gui/ice40/resources/control_play.png b/gui/ice40/resources/control_play.png index 0846555d..f8c8ec68 100644 Binary files a/gui/ice40/resources/control_play.png and b/gui/ice40/resources/control_play.png differ diff --git a/gui/ice40/resources/control_stop.png b/gui/ice40/resources/control_stop.png index 893bb60e..e6f75d23 100644 Binary files a/gui/ice40/resources/control_stop.png and b/gui/ice40/resources/control_stop.png differ diff --git a/gui/ice40/resources/pack.png b/gui/ice40/resources/pack.png new file mode 100644 index 00000000..da3c2a2d Binary files /dev/null and b/gui/ice40/resources/pack.png differ diff --git a/gui/ice40/resources/place.png b/gui/ice40/resources/place.png new file mode 100644 index 00000000..0905f933 Binary files /dev/null and b/gui/ice40/resources/place.png differ diff --git a/gui/ice40/resources/route.png b/gui/ice40/resources/route.png new file mode 100644 index 00000000..258c16c6 Binary files /dev/null and b/gui/ice40/resources/route.png differ diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 9549f659..9df24f65 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -24,43 +24,88 @@ Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) parent->clearTerminate(); throw WorkerInterruptionRequested(); } + if (parent->isPaused()) + { + Q_EMIT taskPaused(); + } while (parent->isPaused()) { + if (parent->shouldTerminate()) { + parent->clearTerminate(); + throw WorkerInterruptionRequested(); + } QThread::sleep(1); } }; } -void Worker::parsejson(const std::string &filename) +void Worker::loadfile(const std::string &filename) { + Q_EMIT taskStarted(); std::string fn = filename; std::ifstream f(fn); try { - if (!parse_json_file(f, fn, ctx)) - log_error("Loading design failed.\n"); - if (!pack_design(ctx)) - log_error("Packing design failed.\n"); + Q_EMIT loadfile_finished(parse_json_file(f, fn, ctx)); + } catch (WorkerInterruptionRequested) { + Q_EMIT taskCanceled(); + } +} + +void Worker::pack() +{ + Q_EMIT taskStarted(); + try { + Q_EMIT pack_finished(pack_design(ctx)); + } catch (WorkerInterruptionRequested) { + Q_EMIT taskCanceled(); + } +} + +void Worker::place() +{ + Q_EMIT taskStarted(); + try { double freq = 50e6; assign_budget(ctx, freq); print_utilisation(ctx); + Q_EMIT place_finished(place_design_sa(ctx)); + } catch (WorkerInterruptionRequested) { + Q_EMIT taskCanceled(); + } +} - if (!place_design_sa(ctx)) - log_error("Placing design failed.\n"); - if (!route_design(ctx)) - log_error("Routing design failed.\n"); - Q_EMIT log("DONE\n"); - } catch (log_execution_error_exception) { +void Worker::route() +{ + Q_EMIT taskStarted(); + try { + Q_EMIT route_finished(route_design(ctx)); } catch (WorkerInterruptionRequested) { - Q_EMIT log("CANCELED\n"); + Q_EMIT taskCanceled(); } } + TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(false) { Worker *worker = new Worker(ctx, this); worker->moveToThread(&workerThread); + connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); - connect(this, &TaskManager::parsejson, worker, &Worker::parsejson); + + connect(this, &TaskManager::loadfile, worker, &Worker::loadfile); + connect(this, &TaskManager::pack, worker, &Worker::pack); + connect(this, &TaskManager::place, worker, &Worker::place); + connect(this, &TaskManager::route, worker, &Worker::route); + connect(worker, &Worker::log, this, &TaskManager::info); + connect(worker, &Worker::loadfile_finished, this, &TaskManager::loadfile_finished); + connect(worker, &Worker::pack_finished, this, &TaskManager::pack_finished); + connect(worker, &Worker::place_finished, this, &TaskManager::place_finished); + connect(worker, &Worker::route_finished, this, &TaskManager::route_finished); + + connect(worker, &Worker::taskCanceled, this, &TaskManager::taskCanceled); + connect(worker, &Worker::taskStarted, this, &TaskManager::taskStarted); + connect(worker, &Worker::taskPaused, this, &TaskManager::taskPaused); + workerThread.start(); } @@ -77,6 +122,7 @@ void TaskManager::info(const std::string &result) { Q_EMIT log(result); } void TaskManager::terminate_thread() { QMutexLocker locker(&mutex); + toPause = false; toTerminate = true; } @@ -102,7 +148,9 @@ void TaskManager::continue_thread() { QMutexLocker locker(&mutex); toPause = false; + Q_EMIT taskStarted(); } + bool TaskManager::isPaused() { QMutexLocker locker(&mutex); diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index 181fafa3..320dc94c 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -15,9 +15,19 @@ class Worker : public QObject public: Worker(Context *ctx, TaskManager *parent); public Q_SLOTS: - void parsejson(const std::string &filename); + void loadfile(const std::string &); + void pack(); + void place(); + void route(); Q_SIGNALS: void log(const std::string &text); + void loadfile_finished(bool status); + void pack_finished(bool status); + void place_finished(bool status); + void route_finished(bool status); + void taskCanceled(); + void taskStarted(); + void taskPaused(); private: Context *ctx; @@ -41,8 +51,20 @@ class TaskManager : public QObject void continue_thread(); Q_SIGNALS: void terminate(); - void parsejson(const std::string &); + void loadfile(const std::string &); + void pack(); + void place(); + void route(); + + // redirected signals void log(const std::string &text); + void loadfile_finished(bool status); + void pack_finished(bool status); + void place_finished(bool status); + void route_finished(bool status); + void taskCanceled(); + void taskStarted(); + void taskPaused(); private: QMutex mutex; -- cgit v1.2.3