From e04551979d6556ee7b065b15f1243cd08a613293 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Fri, 10 Feb 2017 16:14:02 -0300 Subject: [PATCH] Adding original MMDVM watchdog and LED functions --- ADF7021.cpp | 2 -- IO.cpp | 39 ++++++++++++++++++++++++++++++++++++++- IO.h | 7 +++++++ SerialPort.cpp | 6 ++---- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/ADF7021.cpp b/ADF7021.cpp index 585d78f..a53e567 100644 --- a/ADF7021.cpp +++ b/ADF7021.cpp @@ -331,7 +331,6 @@ void CIO::setTX() // PTT pin on PTT_pin(HIGH); - LED_pin(LOW); } //====================================================================================================================== @@ -350,7 +349,6 @@ void CIO::setRX() // PTT pin off PTT_pin(LOW); - LED_pin(HIGH); } #endif diff --git a/IO.cpp b/IO.cpp index 8f2cffc..d5b938f 100644 --- a/IO.cpp +++ b/IO.cpp @@ -32,7 +32,10 @@ uint8_t m_power; CIO::CIO(): m_started(false), m_rxBuffer(RX_RINGBUFFER_SIZE), -m_txBuffer(TX_RINGBUFFER_SIZE) +m_txBuffer(TX_RINGBUFFER_SIZE), +m_ledCount(0U), +m_ledValue(true), +m_watchdog(0U) { Init(); @@ -57,6 +60,33 @@ m_txBuffer(TX_RINGBUFFER_SIZE) void CIO::process() { uint8_t bit; + + m_ledCount++; + + if (m_started) { + // Two seconds timeout + if (m_watchdog >= 19200U) { + if (m_modemState == STATE_DSTAR || m_modemState == STATE_DMR || m_modemState == STATE_YSF || m_modemState == STATE_P25) { + m_modemState = STATE_IDLE; + setMode(); + } + + m_watchdog = 0U; + } + + if (m_ledCount >= 24000U) { + m_ledCount = 0U; + m_ledValue = !m_ledValue; + LED_pin(m_ledValue); + } + } else { + if (m_ledCount >= 240000U) { + m_ledCount = 0U; + m_ledValue = !m_ledValue; + LED_pin(m_ledValue); + } + return; + } // Switch off the transmitter if needed if (m_txBuffer.getData() == 0U && m_tx) { @@ -108,6 +138,8 @@ void CIO::interrupt() m_rxBuffer.put(bit); } + + m_watchdog++; } void CIO::start() @@ -185,3 +217,8 @@ void CIO::setDecode(bool dcd) m_dcd = dcd; } + +void CIO::resetWatchdog() +{ + m_watchdog = 0U; +} diff --git a/IO.h b/IO.h index 90fbd23..788c2c4 100644 --- a/IO.h +++ b/IO.h @@ -47,9 +47,11 @@ public: bool SREAD_pin(void); void SLE_pin(bool on); bool RXD_pin(void); + #if defined(BIDIR_DATA_PIN) void RXD_pin_write(bool on); #endif + void TXD_pin(bool on); void PTT_pin(bool on); void LED_pin(bool on); @@ -60,6 +62,7 @@ public: void P25_pin(bool on); void COS_pin(bool on); void interrupt(void); + void resetWatchdog(void); #if defined(BIDIR_DATA_PIN) void Data_dir_out(bool dir); @@ -94,6 +97,10 @@ private: bool m_started; CBitRB m_rxBuffer; CBitRB m_txBuffer; + + uint32_t m_ledCount; + bool m_ledValue; + volatile uint32_t m_watchdog; }; diff --git a/SerialPort.cpp b/SerialPort.cpp index e240250..b015f16 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -68,7 +68,7 @@ const uint8_t MMDVM_DEBUG3 = 0xF3U; const uint8_t MMDVM_DEBUG4 = 0xF4U; const uint8_t MMDVM_DEBUG5 = 0xF5U; -const uint8_t HARDWARE[] = "MMDVM 20161213-HS (D-Star/DMR/YSF/P25)"; +const uint8_t HARDWARE[] = "MMDVM-HS 20170210 (D-Star/DMR/YSF/P25)"; const uint8_t PROTOCOL_VERSION = 1U; @@ -107,7 +107,7 @@ void CSerialPort::sendNAK(uint8_t err) void CSerialPort::getStatus() { - //io.resetWatchdog(); + io.resetWatchdog(); uint8_t reply[15U]; @@ -212,8 +212,6 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) if (colorCode > 15U) return 4U; -// uint8_t dmrDelay = data[7U]; - m_modemState = modemState; m_dstarEnable = dstarEnable;