aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/serialport.cpp22
-rw-r--r--qtmips_machine/serialport.h5
2 files changed, 25 insertions, 2 deletions
diff --git a/qtmips_machine/serialport.cpp b/qtmips_machine/serialport.cpp
index 9e4177b..c636d38 100644
--- a/qtmips_machine/serialport.cpp
+++ b/qtmips_machine/serialport.cpp
@@ -51,6 +51,7 @@ using namespace machine;
SerialPort::SerialPort() {
rx_st_reg = 0;
+ rx_data_reg = 0;
tx_st_reg = 0;
}
@@ -58,6 +59,18 @@ SerialPort::~SerialPort() {
}
+void SerialPort::pool_rx_byte() const {
+ unsigned int byte = 0;
+ bool available = false;
+ if (!(rx_st_reg & SERP_RX_ST_REG_READY_m)) {
+ emit rx_byte_pool(0, byte, available);
+ if (available) {
+ rx_data_reg = byte;
+ rx_st_reg |= SERP_RX_ST_REG_READY_m;
+ }
+ }
+}
+
bool SerialPort::wword(std::uint32_t address, std::uint32_t value) {
#if 0
printf("SerialPort::wword address 0x%08lx data 0x%08lx\n",
@@ -90,10 +103,17 @@ std::uint32_t SerialPort::rword(std::uint32_t address, bool debug_access) const
#endif
switch (address) {
case SERP_RX_ST_REG_o:
+ pool_rx_byte();
value = rx_st_reg;
break;
case SERP_RX_DATA_REG_o:
- value = 0;
+ pool_rx_byte();
+ if (rx_st_reg & SERP_RX_ST_REG_READY_m) {
+ value = rx_data_reg;
+ rx_st_reg &= ~SERP_RX_ST_REG_READY_m;
+ } else {
+ value = 0;
+ }
break;
case SERP_TX_ST_REG_o:
value = tx_st_reg | SERP_TX_ST_REG_READY_m;
diff --git a/qtmips_machine/serialport.h b/qtmips_machine/serialport.h
index add1fe6..5262720 100644
--- a/qtmips_machine/serialport.h
+++ b/qtmips_machine/serialport.h
@@ -52,6 +52,7 @@ public:
signals:
void tx_byte(unsigned int data);
+ void rx_byte_pool(int fd, unsigned int &data, bool &available) const;
void write_notification(std::uint32_t address, std::uint32_t value);
void read_notification(std::uint32_t address, std::uint32_t *value) const;
@@ -59,7 +60,9 @@ public:
bool wword(std::uint32_t address, std::uint32_t value);
std::uint32_t rword(std::uint32_t address, bool debug_access = false) const;
private:
- std::uint32_t rx_st_reg;
+ void pool_rx_byte() const;
+ mutable std::uint32_t rx_st_reg;
+ mutable std::uint32_t rx_data_reg;
std::uint32_t tx_st_reg;
};