diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-25 14:57:00 +0100 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-02-25 14:57:00 +0100 |
commit | 1889bd9353b309ea54f3543f5d609015fec5b73c (patch) | |
tree | f203dac446435aa395cadbd34ea4d347efdaacd6 /qtmips_machine | |
parent | ca242e325d823bc627ca4e6ff8eca24b888a6113 (diff) | |
download | qtmips-1889bd9353b309ea54f3543f5d609015fec5b73c.tar.gz qtmips-1889bd9353b309ea54f3543f5d609015fec5b73c.tar.bz2 qtmips-1889bd9353b309ea54f3543f5d609015fec5b73c.zip |
Simple serial port receive implementation.
Simple polled mode serial port input implemented for
serial port peripheral and for read and readv system
calls. When end of input character reserve is reached
for read/readv, newline is automatically appended.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_machine')
-rw-r--r-- | qtmips_machine/serialport.cpp | 22 | ||||
-rw-r--r-- | qtmips_machine/serialport.h | 5 |
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; }; |