diff options
Diffstat (limited to 'gui/ice40')
-rw-r--r-- | gui/ice40/mainwindow.cc | 172 | ||||
-rw-r--r-- | gui/ice40/mainwindow.h | 21 | ||||
-rw-r--r-- | gui/ice40/nextpnr.qrc | 10 | ||||
-rw-r--r-- | gui/ice40/resources/control_pause.png | bin | 0 -> 721 bytes | |||
-rw-r--r-- | gui/ice40/resources/control_play.png | bin | 0 -> 717 bytes | |||
-rw-r--r-- | gui/ice40/resources/control_stop.png | bin | 0 -> 695 bytes | |||
-rw-r--r-- | gui/ice40/resources/pack.png | bin | 0 -> 853 bytes | |||
-rw-r--r-- | gui/ice40/resources/place.png | bin | 0 -> 825 bytes | |||
-rw-r--r-- | gui/ice40/resources/route.png | bin | 0 -> 683 bytes | |||
-rw-r--r-- | gui/ice40/worker.cc | 138 | ||||
-rw-r--r-- | gui/ice40/worker.h | 48 |
11 files changed, 358 insertions, 31 deletions
diff --git a/gui/ice40/mainwindow.cc b/gui/ice40/mainwindow.cc index 934798bb..0a248938 100644 --- a/gui/ice40/mainwindow.cc +++ b/gui/ice40/mainwindow.cc @@ -11,24 +11,105 @@ #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)
{
+ initMainResource();
+
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)));
+
+ 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();
}
-MainWindow::~MainWindow() {}
+MainWindow::~MainWindow() { delete task; }
void MainWindow::createMenu()
{
- QMenu *menu_Custom = new QMenu("&ICE 40", menuBar);
- menuBar->addAction(menu_Custom->menuAction());
+ 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);
+
+ 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);
+
+ 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);
+
+ taskToolBar->addAction(actionPlay);
+ taskToolBar->addAction(actionPause);
+ taskToolBar->addAction(actionStop);
}
void MainWindow::open()
@@ -39,7 +120,84 @@ void MainWindow::open() tabWidget->setCurrentWidget(info);
std::string fn = fileName.toStdString();
- 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");
}
}
-bool MainWindow::save() { return false; }
\ No newline at end of file +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 fd65f9ae..9083ed8a 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
{
@@ -21,9 +20,27 @@ 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
+
#endif // MAINWINDOW_H
diff --git a/gui/ice40/nextpnr.qrc b/gui/ice40/nextpnr.qrc new file mode 100644 index 00000000..3bc68978 --- /dev/null +++ b/gui/ice40/nextpnr.qrc @@ -0,0 +1,10 @@ +<RCC> + <qresource prefix="/icons"> + <file>resources/control_play.png</file> + <file>resources/control_pause.png</file> + <file>resources/control_stop.png</file> + <file>resources/pack.png</file> + <file>resources/place.png</file> + <file>resources/route.png</file> + </qresource> +</RCC> diff --git a/gui/ice40/resources/control_pause.png b/gui/ice40/resources/control_pause.png Binary files differnew file mode 100644 index 00000000..ec61099b --- /dev/null +++ b/gui/ice40/resources/control_pause.png diff --git a/gui/ice40/resources/control_play.png b/gui/ice40/resources/control_play.png Binary files differnew file mode 100644 index 00000000..f8c8ec68 --- /dev/null +++ b/gui/ice40/resources/control_play.png diff --git a/gui/ice40/resources/control_stop.png b/gui/ice40/resources/control_stop.png Binary files differnew file mode 100644 index 00000000..e6f75d23 --- /dev/null +++ b/gui/ice40/resources/control_stop.png diff --git a/gui/ice40/resources/pack.png b/gui/ice40/resources/pack.png Binary files differnew file mode 100644 index 00000000..da3c2a2d --- /dev/null +++ b/gui/ice40/resources/pack.png diff --git a/gui/ice40/resources/place.png b/gui/ice40/resources/place.png Binary files differnew file mode 100644 index 00000000..0905f933 --- /dev/null +++ b/gui/ice40/resources/place.png diff --git a/gui/ice40/resources/route.png b/gui/ice40/resources/route.png Binary files differnew file mode 100644 index 00000000..258c16c6 --- /dev/null +++ b/gui/ice40/resources/route.png diff --git a/gui/ice40/worker.cc b/gui/ice40/worker.cc index 5702137b..9df24f65 100644 --- a/gui/ice40/worker.cc +++ b/gui/ice40/worker.cc @@ -10,47 +10,151 @@ #include "route.h" #include "timing.h" -Worker::Worker(Context *_ctx) : ctx(_ctx) +NEXTPNR_NAMESPACE_BEGIN + +struct WorkerInterruptionRequested +{ +}; + +Worker::Worker(Context *_ctx, TaskManager *parent) : ctx(_ctx) { - log_write_function = [this](std::string text) { Q_EMIT log(text); }; + log_write_function = [this, parent](std::string text) { + Q_EMIT log(text); + if (parent->shouldTerminate()) { + 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"); - } catch (log_execution_error_exception) { +void Worker::route() +{ + Q_EMIT taskStarted(); + try { + Q_EMIT route_finished(route_design(ctx)); + } catch (WorkerInterruptionRequested) { + Q_EMIT taskCanceled(); } } -TaskManager::TaskManager(Context *ctx) + +TaskManager::TaskManager(Context *ctx) : toTerminate(false), toPause(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); + + 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(); } TaskManager::~TaskManager() { + if (workerThread.isRunning()) + terminate_thread(); workerThread.quit(); 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); + toPause = false; + toTerminate = true; +} + +bool TaskManager::shouldTerminate() +{ + QMutexLocker locker(&mutex); + return toTerminate; +} + +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; + Q_EMIT taskStarted(); +} + +bool TaskManager::isPaused() +{ + QMutexLocker locker(&mutex); + return toPause; +} + +NEXTPNR_NAMESPACE_END diff --git a/gui/ice40/worker.h b/gui/ice40/worker.h index 12d740dd..320dc94c 100644 --- a/gui/ice40/worker.h +++ b/gui/ice40/worker.h @@ -1,21 +1,33 @@ #ifndef WORKER_H #define WORKER_H +#include <QMutex> #include <QThread> #include "nextpnr.h" -// FIXME -USING_NEXTPNR_NAMESPACE +NEXTPNR_NAMESPACE_BEGIN + +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); + 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; @@ -29,11 +41,37 @@ class TaskManager : public QObject public: TaskManager(Context *ctx); ~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 parsejson(const std::string &); + void terminate(); + 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; + bool toTerminate; + bool toPause; }; +NEXTPNR_NAMESPACE_END + #endif // WORKER_H |