diff options
author | michael-west <michael.west@ettus.com> | 2016-08-15 11:21:57 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2016-09-02 11:10:46 -0700 |
commit | 7ea624b179cfb2cd6204be4dc128ba7ef07f4546 (patch) | |
tree | 4b2e34bea964b9e2ff2d1429301d70171f49c90c | |
parent | b229a1972c421c90420363ce1f93be91cc9bd2aa (diff) | |
download | uhd-7ea624b179cfb2cd6204be4dc128ba7ef07f4546.tar.gz uhd-7ea624b179cfb2cd6204be4dc128ba7ef07f4546.tar.bz2 uhd-7ea624b179cfb2cd6204be4dc128ba7ef07f4546.zip |
X300: GPSDO fixes
- Optimize writes so full 32-bit words are written at a time
- Simplify UART so it does not strip or add characters
-rw-r--r-- | firmware/usrp3/x300/x300_main.c | 2 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_fw_uart.cpp | 36 |
2 files changed, 18 insertions, 20 deletions
diff --git a/firmware/usrp3/x300/x300_main.c b/firmware/usrp3/x300/x300_main.c index 3b812a2c4..125459583 100644 --- a/firmware/usrp3/x300/x300_main.c +++ b/firmware/usrp3/x300/x300_main.c @@ -345,12 +345,12 @@ static void handle_uarts(void) static uint32_t rxoffset = 0; for (int rxch = wb_uart_getc(UART0_BASE); rxch != -1; rxch = wb_uart_getc(UART0_BASE)) { - rxoffset++; const int shift = ((rxoffset%4) * 8); static uint32_t rxword32 = 0; if (shift == 0) rxword32 = 0; rxword32 |= ((uint32_t) rxch & 0xFF) << shift; rxpool[(rxoffset/4) % NUM_POOL_WORDS32] = rxword32; + rxoffset++; shmem[X300_FW_SHMEM_UART_RX_INDEX] = rxoffset; } diff --git a/host/lib/usrp/x300/x300_fw_uart.cpp b/host/lib/usrp/x300/x300_fw_uart.cpp index 86141ca9a..7f60e26fc 100644 --- a/host/lib/usrp/x300/x300_fw_uart.cpp +++ b/host/lib/usrp/x300/x300_fw_uart.cpp @@ -30,28 +30,36 @@ using namespace uhd; struct x300_uart_iface : uart_iface { x300_uart_iface(wb_iface::sptr iface): - rxoffset(0), txoffset(0), txword32(0), rxpool(0), txpool(0), poolsize(0) + _iface(iface), + rxoffset(0), + txword32(0), + _last_device_rxoffset(0) { - _iface = iface; - rxoffset = _iface->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_UART_RX_INDEX)); txoffset = _iface->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_UART_TX_INDEX)); rxpool = _iface->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_UART_RX_ADDR)); txpool = _iface->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_UART_TX_ADDR)); poolsize = _iface->peek32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_UART_WORDS32)); _rxcache.resize(poolsize); - _last_device_rxoffset = rxoffset; //this->write_uart("HELLO UART\n"); //this->read_uart(0.1); } void putchar(const char ch) { - txoffset = (txoffset + 1) % (poolsize*4); const int shift = ((txoffset%4) * 8); if (shift == 0) txword32 = 0; txword32 |= boost::uint32_t(ch) << shift; - _iface->poke32(SR_ADDR(txpool, txoffset/4), txword32); - _iface->poke32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_UART_TX_INDEX), txoffset); + // Write out full 32 bit words or whatever we have if end of string + if (txoffset % 4 == 3 or ch == '\n') + { + _iface->poke32(SR_ADDR(txpool, txoffset/4), txword32); + } + txoffset = (txoffset + 1) % (poolsize*4); + if (ch == '\n') + { + // Tell the X300 to write the string + _iface->poke32(SR_ADDR(X300_FW_SHMEM_BASE, X300_FW_SHMEM_UART_TX_INDEX), txoffset); + } } void write_uart(const std::string &buff) @@ -59,7 +67,6 @@ struct x300_uart_iface : uart_iface boost::mutex::scoped_lock(_write_mutex); BOOST_FOREACH(const char ch, buff) { - if (ch == '\n') this->putchar('\r'); this->putchar(ch); } } @@ -128,22 +135,13 @@ struct x300_uart_iface : uart_iface // Get available characters for (int ch = this->getchar(); ch != -1; ch = this->getchar()) { - // skip carriage returns - if (ch == '\r') - continue; - - // avoid returning empty strings - if (ch == '\n' and _rxbuff.empty()) - continue; - // store character to buffer - _rxbuff += std::string(1, (char)ch); + _rxbuff.append(1, ch); // newline found - return string if (ch == '\n') { - buff = _rxbuff; - _rxbuff.clear(); + buff.swap(_rxbuff); return buff; } } |