From 6e3a34df8fdaee85211f5b90b8cd5e8b996372e2 Mon Sep 17 00:00:00 2001 From: W3AXL <29879554+W3AXL@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:57:34 -0500 Subject: [PATCH] initial work to support DVM-V24 RTS/DTR boot modes --- src/host/Host.Config.cpp | 9 ++++-- src/host/modem/port/PseudoPTYPort.cpp | 2 +- src/host/modem/port/UARTPort.cpp | 40 +++++++++++++++++++++++++-- src/host/modem/port/UARTPort.h | 5 ++-- src/host/setup/HostSetup.cpp | 1 + 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/host/Host.Config.cpp b/src/host/Host.Config.cpp index eaab7480..9ad5d41b 100644 --- a/src/host/Host.Config.cpp +++ b/src/host/Host.Config.cpp @@ -552,12 +552,17 @@ bool Host::createModem() } if (portType == PTY_PORT) { - modemPort = new port::UARTPort(uartPort, serialSpeed, false); + modemPort = new port::UARTPort(uartPort, serialSpeed, false, false); LogInfo(" PTY Port: %s", uartPort.c_str()); LogInfo(" PTY Speed: %u", uartSpeed); } else { - modemPort = new port::UARTPort(uartPort, serialSpeed, true); + if (modemMode == MODEM_MODE_DFSI) { + modemPort = new port::UARTPort(uartPort, serialSpeed, false, true); + LogInfo(" RTS/DTR boot flags enabled"); + } else { + modemPort = new port::UARTPort(uartPort, serialSpeed, true, false); + } LogInfo(" UART Port: %s", uartPort.c_str()); LogInfo(" UART Speed: %u", uartSpeed); } diff --git a/src/host/modem/port/PseudoPTYPort.cpp b/src/host/modem/port/PseudoPTYPort.cpp index 3e7948dd..cf17279f 100644 --- a/src/host/modem/port/PseudoPTYPort.cpp +++ b/src/host/modem/port/PseudoPTYPort.cpp @@ -30,7 +30,7 @@ using namespace modem::port; /* Initializes a new instance of the PseudoPTYPort class. */ -PseudoPTYPort::PseudoPTYPort(const std::string& symlink, SERIAL_SPEED speed, bool assertRTS) : UARTPort(speed, assertRTS), +PseudoPTYPort::PseudoPTYPort(const std::string& symlink, SERIAL_SPEED speed, bool assertRTS) : UARTPort(speed, assertRTS, false), m_symlink(symlink) { /* stub */ diff --git a/src/host/modem/port/UARTPort.cpp b/src/host/modem/port/UARTPort.cpp index 1f12a2df..cbd4592e 100644 --- a/src/host/modem/port/UARTPort.cpp +++ b/src/host/modem/port/UARTPort.cpp @@ -37,11 +37,12 @@ using namespace modem::port; /* Initializes a new instance of the UARTPort class. */ -UARTPort::UARTPort(const std::string& device, SERIAL_SPEED speed, bool assertRTS) : +UARTPort::UARTPort(const std::string& device, SERIAL_SPEED speed, bool assertRTS, bool rtsBoot) : m_isOpen(false), m_device(device), m_speed(speed), m_assertRTS(assertRTS), + m_rtsBoot(rtsBoot), #if defined(_WIN32) m_fd(INVALID_HANDLE_VALUE) #else @@ -334,10 +335,11 @@ int UARTPort::setNonblock(bool nonblock) /* Initializes a new instance of the UARTPort class. */ -UARTPort::UARTPort(SERIAL_SPEED speed, bool assertRTS) : +UARTPort::UARTPort(SERIAL_SPEED speed, bool assertRTS, bool rtsBoot) : m_isOpen(false), m_speed(speed), m_assertRTS(assertRTS), + m_rtsBoot(rtsBoot), #if defined(_WIN32) m_fd(INVALID_HANDLE_VALUE) #else @@ -500,6 +502,40 @@ bool UARTPort::setTermios() } } + // Special setting of RTS/DTR for DVM-V24 boards with onboard DTR/RTS boot connections + if (m_rtsBoot) { + ::LogInfoEx(LOG_MODEM, "RTS/DTR boot flag enabled, forcing board reset"); + uint32_t y; + if (::ioctl(m_fd, TIOCMGET, &y) < 0) { + ::LogError(LOG_HOST, "Cannot get the control attributes for %s", m_device.c_str()); + ::close(m_fd); + return false; + } + + // Force RTS bit off + y &= ~TIOCM_RTS; + + if (::ioctl(m_fd, TIOCMSET, &y) < 0) { + ::LogError(LOG_HOST, "Cannot set the control attributes for %s", m_device.c_str()); + ::close(m_fd); + return false; + } + + // Toggle DTR to force second reset + y &= ~TIOCM_DTR; + if (::ioctl(m_fd, TIOCMSET, &y) < 0) { + ::LogError(LOG_HOST, "Cannot set the control attributes for %s", m_device.c_str()); + ::close(m_fd); + return false; + } + y |= TIOCM_DTR; + if (::ioctl(m_fd, TIOCMSET, &y) < 0) { + ::LogError(LOG_HOST, "Cannot set the control attributes for %s", m_device.c_str()); + ::close(m_fd); + return false; + } + } + #if defined(__APPLE__) setNonblock(false); #endif diff --git a/src/host/modem/port/UARTPort.h b/src/host/modem/port/UARTPort.h index 4aed835f..b5a4a1a7 100644 --- a/src/host/modem/port/UARTPort.h +++ b/src/host/modem/port/UARTPort.h @@ -76,7 +76,7 @@ namespace modem * @param speed Serial port speed. * @param assertRTS */ - UARTPort(const std::string& device, SERIAL_SPEED speed, bool assertRTS = false); + UARTPort(const std::string& device, SERIAL_SPEED speed, bool assertRTS = false, bool rtsBoot = false); /** * @brief Finalizes a instance of the UARTPort class. */ @@ -122,13 +122,14 @@ namespace modem * @param speed Serial port speed. * @param assertRTS */ - UARTPort(SERIAL_SPEED speed, bool assertRTS = false); + UARTPort(SERIAL_SPEED speed, bool assertRTS = false, bool rtsBoot = false); bool m_isOpen; std::string m_device; SERIAL_SPEED m_speed; bool m_assertRTS; + bool m_rtsBoot; #if defined(_WIN32) HANDLE m_fd; #else diff --git a/src/host/setup/HostSetup.cpp b/src/host/setup/HostSetup.cpp index 28112b1d..43db6ca8 100644 --- a/src/host/setup/HostSetup.cpp +++ b/src/host/setup/HostSetup.cpp @@ -811,6 +811,7 @@ bool HostSetup::createModem(bool consoleDisplay) modemPort = new port::UARTPort(uartPort, serialSpeed, true); LogInfo(" UART Port: %s", uartPort.c_str()); LogInfo(" UART Speed: %u", uartSpeed); + LogInfo(" Assert RTS enabled"); } LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no");