Add the analogue and interrupt processing.

This commit is contained in:
Jonathan Naylor 2024-10-08 14:54:38 +01:00
parent 07d54f74cc
commit fb5ce0101d
5 changed files with 45 additions and 7 deletions

View File

@ -25,12 +25,11 @@
#include "AX25Demodulator.h" #include "AX25Demodulator.h"
#include "AX25Defines.h" #include "AX25Defines.h"
const float32_t SAMPLE_RATE = 24000.0F; const uint32_t SYMBOL_RATE = 1200U;
const float32_t SYMBOL_RATE = 1200.0F;
const uint16_t DELAY_LEN = 11U; 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 float32_t PLL_LIMIT = SAMPLES_PER_SYMBOL / 2.0F;
const uint32_t LPF_FILTER_LEN = 48U; const uint32_t LPF_FILTER_LEN = 48U;

View File

@ -100,6 +100,8 @@ const uint16_t RX_BLOCK_SIZE = 2U;
const uint16_t TX_RINGBUFFER_SIZE = 500U; const uint16_t TX_RINGBUFFER_SIZE = 500U;
const uint16_t RX_RINGBUFFER_SIZE = 600U; const uint16_t RX_RINGBUFFER_SIZE = 600U;
const uint32_t SAMPLE_RATE = 24000U;
#if defined(__MK20DX256__) #if defined(__MK20DX256__)
const uint16_t TX_BUFFER_LEN = 2000U; const uint16_t TX_BUFFER_LEN = 2000U;
#else #else

View File

@ -80,6 +80,7 @@ const uint16_t BOXCAR5_FILTER_LEN = 6U;
const uint16_t DC_OFFSET = 2048U; const uint16_t DC_OFFSET = 2048U;
CIO::CIO() : CIO::CIO() :
m_timer(TIM2),
m_started(false), m_started(false),
m_rxBuffer(RX_RINGBUFFER_SIZE), m_rxBuffer(RX_RINGBUFFER_SIZE),
m_txBuffer(TX_RINGBUFFER_SIZE), m_txBuffer(TX_RINGBUFFER_SIZE),
@ -335,7 +336,6 @@ void CIO::start()
void CIO::process() void CIO::process()
{ {
m_ledCount++;
if (m_started) { if (m_started) {
// Two seconds timeout // Two seconds timeout
if (m_watchdog >= 48000U) { if (m_watchdog >= 48000U) {
@ -360,6 +360,7 @@ void CIO::process()
} }
#endif #endif
} else { } else {
m_ledCount++;
if (m_ledCount >= 240000U) { if (m_ledCount >= 240000U) {
m_ledCount = 0U; m_ledCount = 0U;
m_ledValue = !m_ledValue; m_ledValue = !m_ledValue;
@ -846,6 +847,32 @@ bool CIO::hasLockout() const
return m_lockout; 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() void CIO::initHardware()
{ {
#if defined(PIN_COS) #if defined(PIN_COS)
@ -888,11 +915,19 @@ void CIO::initHardware()
::pinMode(PIN_M17, OUTPUT); ::pinMode(PIN_M17, OUTPUT);
#endif #endif
#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() void CIO::startHardware()
{ {
m_timer.resume();
} }
bool CIO::getCOS() bool CIO::getCOS()

View File

@ -61,6 +61,8 @@ public:
void selfTest(); void selfTest();
private: private:
HardwareTimer m_timer;
bool m_started; bool m_started;
CRingBuffer<TSample> m_rxBuffer; CRingBuffer<TSample> m_rxBuffer;

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -19,7 +19,7 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
#define VERSION "20221121" #define VERSION "20241008"
#endif #endif