From fb5ce0101dfd443c7f0f35ee5d0cac6969df1ce1 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 8 Oct 2024 14:54:38 +0100 Subject: [PATCH] Add the analogue and interrupt processing. --- src/AX25/AX25Demodulator.cpp | 5 ++--- src/Globals.h | 2 ++ src/IO.cpp | 39 ++++++++++++++++++++++++++++++++++-- src/IO.h | 2 ++ src/Version.h | 4 ++-- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/AX25/AX25Demodulator.cpp b/src/AX25/AX25Demodulator.cpp index eb0022d..13dadc3 100644 --- a/src/AX25/AX25Demodulator.cpp +++ b/src/AX25/AX25Demodulator.cpp @@ -25,12 +25,11 @@ #include "AX25Demodulator.h" #include "AX25Defines.h" -const float32_t SAMPLE_RATE = 24000.0F; -const float32_t SYMBOL_RATE = 1200.0F; +const uint32_t SYMBOL_RATE = 1200U; const uint16_t DELAY_LEN = 11U; -const float32_t SAMPLES_PER_SYMBOL = SAMPLE_RATE / SYMBOL_RATE; +const float32_t SAMPLES_PER_SYMBOL = float32_t(SAMPLE_RATE / SYMBOL_RATE); const float32_t PLL_LIMIT = SAMPLES_PER_SYMBOL / 2.0F; const uint32_t LPF_FILTER_LEN = 48U; diff --git a/src/Globals.h b/src/Globals.h index 371b01e..f21b8f1 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -100,6 +100,8 @@ const uint16_t RX_BLOCK_SIZE = 2U; const uint16_t TX_RINGBUFFER_SIZE = 500U; const uint16_t RX_RINGBUFFER_SIZE = 600U; +const uint32_t SAMPLE_RATE = 24000U; + #if defined(__MK20DX256__) const uint16_t TX_BUFFER_LEN = 2000U; #else diff --git a/src/IO.cpp b/src/IO.cpp index b282691..41d0e62 100644 --- a/src/IO.cpp +++ b/src/IO.cpp @@ -80,6 +80,7 @@ const uint16_t BOXCAR5_FILTER_LEN = 6U; const uint16_t DC_OFFSET = 2048U; CIO::CIO() : +m_timer(TIM2), m_started(false), m_rxBuffer(RX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE), @@ -335,7 +336,6 @@ void CIO::start() void CIO::process() { - m_ledCount++; if (m_started) { // Two seconds timeout if (m_watchdog >= 48000U) { @@ -360,6 +360,7 @@ void CIO::process() } #endif } else { + m_ledCount++; if (m_ledCount >= 240000U) { m_ledCount = 0U; m_ledValue = !m_ledValue; @@ -846,6 +847,32 @@ bool CIO::hasLockout() const return m_lockout; } +void IRQHandler() +{ + io.interrupt(); +} + +void CIO::interrupt() +{ + TSample sample = {DC_OFFSET, MARK_NONE}; + uint16_t rawRSSI = 0U; + + m_txBuffer.get(sample); + ::analogWrite(PIN_TX, sample.sample); + + sample.sample = ::analogRead(PIN_RX); + +#if defined(SEND_RSSI_DATA) + rawRSSI = ::analogRead(PIN_RSSI); +#endif + + m_rxBuffer.put(sample); + m_rssiBuffer.put(rawRSSI); + + m_ledCount++; + m_watchdog++; +} + void CIO::initHardware() { #if defined(PIN_COS) @@ -888,11 +915,19 @@ void CIO::initHardware() ::pinMode(PIN_M17, OUTPUT); #endif #endif + + ::analogReadResolution(12); + ::analogWriteResolution(12); + + m_timer.setPrescaleFactor((SystemCoreClock / (6 * SAMPLE_RATE)) - 1); + m_timer.setOverflow(2); + m_timer.attachInterrupt(IRQHandler); + m_timer.refresh(); // Make register changes take effect } void CIO::startHardware() { - + m_timer.resume(); } bool CIO::getCOS() diff --git a/src/IO.h b/src/IO.h index ae65998..de7d1ba 100644 --- a/src/IO.h +++ b/src/IO.h @@ -61,6 +61,8 @@ public: void selfTest(); private: + HardwareTimer m_timer; + bool m_started; CRingBuffer m_rxBuffer; diff --git a/src/Version.h b/src/Version.h index c86e21f..d28e3b0 100644 --- a/src/Version.h +++ b/src/Version.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021,2022 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2022,2024 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,7 @@ #if !defined(VERSION_H) #define VERSION_H -#define VERSION "20221121" +#define VERSION "20241008" #endif