aboutsummaryrefslogtreecommitdiff
path: root/qtmips_cli/main.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2020-04-23 16:35:50 +0200
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2020-04-23 16:35:50 +0200
commit597c9271608c3d30ce193b96be3fe82966e4cc1d (patch)
treed5a0569bf937b39702d25bee27f2fa8f37bac766 /qtmips_cli/main.cpp
parent27b38375203880cbc991eaac1d97c927346fa7e0 (diff)
downloadqtmips-597c9271608c3d30ce193b96be3fe82966e4cc1d.tar.gz
qtmips-597c9271608c3d30ce193b96be3fe82966e4cc1d.tar.bz2
qtmips-597c9271608c3d30ce193b96be3fe82966e4cc1d.zip
qtmips_cli: add option to connect serial port input and output to file.
New options --serial-in, --serin <FNAME> File connected to the serial port input. --serial-out, --serout <FNAME> File connected to the serial port output. to provide support for B35APO subject task to write conversion of the random binary number to hexadecimal output to serial port. See the task with automatic check using qtmips_cli seminaries/qtmips/print-hex-to-uart in the repository https://gitlab.fel.cvut.cz/b35apo/stud-support/ Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_cli/main.cpp')
-rw-r--r--qtmips_cli/main.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/qtmips_cli/main.cpp b/qtmips_cli/main.cpp
index 2984d8c..6430695 100644
--- a/qtmips_cli/main.cpp
+++ b/qtmips_cli/main.cpp
@@ -44,6 +44,7 @@
#include "reporter.h"
#include "msgreport.h"
#include "simpleasm.h"
+#include "chariohandler.h"
using namespace machine;
using namespace std;
@@ -81,6 +82,8 @@ void create_parser(QCommandLineParser &p) {
p.addOption({"read-time", "Memory read access time (cycles).", "RTIME"});
p.addOption({"write-time", "Memory read access time (cycles).", "WTIME"});
p.addOption({"burst-time", "Memory read access time (cycles).", "BTIME"});
+ p.addOption({{"serial-in", "serin"}, "File connected to the serial port input.", "FNAME"});
+ p.addOption({{"serial-out", "serout"}, "File connected to the serial port output.", "FNAME"});
}
void configure_cache(MachineConfigCache &cacheconf, QStringList cachearg, QString which) {
@@ -284,6 +287,58 @@ void configure_reporter(QCommandLineParser &p, Reporter &r, const SymbolTable *s
// TODO
}
+void configure_serial_port(QCommandLineParser &p, SerialPort *ser_port) {
+ int siz;
+ CharIOHandler *ser_in = nullptr;
+ CharIOHandler *ser_out = nullptr;
+
+ if (!ser_port)
+ return;
+
+ siz = p.values("serial-in").size();
+ if (siz >= 1) {
+ QIODevice::OpenMode mode = QFile::ReadOnly;
+ QFile *qf = new QFile(p.values("serial-in").at(siz - 1));
+ ser_in = new CharIOHandler(qf, ser_port);
+ siz = p.values("serial-out").size();
+ if (siz) {
+ if (p.values("serial-in").at(siz - 1) == p.values("serial-out").at(siz - 1)) {
+ mode = QFile::ReadWrite;
+ ser_out = ser_in;
+ }
+ }
+ if (!ser_in->open(mode)) {
+ cout << "Serial port input file cannot be open for read." << endl;
+ exit(1);
+ }
+ }
+
+ if (!ser_out) {
+ siz = p.values("serial-out").size();
+ if (siz >= 1) {
+ QFile *qf = new QFile(p.values("serial-out").at(siz - 1));
+ ser_out = new CharIOHandler(qf, ser_port);
+ if (!ser_out->open(QFile::WriteOnly)) {
+ cout << "Serial port output file cannot be open for write." << endl;
+ exit(1);
+ }
+ }
+ }
+
+ if (ser_in) {
+ ser_port->connect(ser_in, SIGNAL(readyRead()), ser_port, SLOT(rx_queue_check()));
+ ser_port->connect(ser_port, SIGNAL(rx_byte_pool(int,unsigned int&, bool&)),
+ ser_in, SLOT(readBytePoll(int,unsigned int&, bool&)));
+ if (ser_in->bytesAvailable())
+ ser_port->rx_queue_check();
+ }
+
+ if (ser_out) {
+ ser_port->connect(ser_port, SIGNAL(tx_byte(unsigned int)),
+ ser_out, SLOT(writeByte(unsigned int)));
+ }
+}
+
void load_ranges(QtMipsMachine &machine, const QStringList &ranges) {
foreach (QString range_arg, ranges) {
std::uint32_t start;
@@ -371,6 +426,8 @@ int main(int argc, char *argv[]) {
Reporter r(&app, &machine);
configure_reporter(p, r, machine.symbol_table());
+ configure_serial_port(p, machine.serial_port());
+
if (asm_source) {
MsgReport msgrep(&app);
if (!assemble(machine, msgrep, p.positionalArguments()[0]))