mirror of https://github.com/g4klx/MMDVM.git
IO RXbuffer now uses template RingBuffer
This commit is contained in:
parent
6c3dd265ab
commit
26a703c68c
9
IO.cpp
9
IO.cpp
|
@ -272,15 +272,16 @@ void CIO::process()
|
|||
uint16_t rssi[RX_BLOCK_SIZE];
|
||||
|
||||
for (uint16_t i = 0U; i < RX_BLOCK_SIZE; i++) {
|
||||
uint16_t sample;
|
||||
m_rxBuffer.get(sample, control[i]);
|
||||
TSample sample;
|
||||
m_rxBuffer.get(sample);
|
||||
control[i] = sample.control;
|
||||
m_rssiBuffer.get(rssi[i]);
|
||||
|
||||
// Detect ADC overflow
|
||||
if (m_detect && (sample == 0U || sample == 4095U))
|
||||
if (m_detect && (sample.sample == 0U || sample.sample == 4095U))
|
||||
m_adcOverflow++;
|
||||
|
||||
q15_t res1 = q15_t(sample) - m_rxDCOffset;
|
||||
q15_t res1 = q15_t(sample.sample) - m_rxDCOffset;
|
||||
q31_t res2 = res1 * m_rxLevel;
|
||||
samples[i] = q15_t(__SSAT((res2 >> 15), 16));
|
||||
}
|
||||
|
|
15
IO.h
15
IO.h
|
@ -24,6 +24,19 @@
|
|||
#include "SampleRB.h"
|
||||
#include "RingBuffer.h"
|
||||
|
||||
struct TSample {
|
||||
volatile uint16_t sample;
|
||||
volatile uint8_t control;
|
||||
|
||||
TSample operator=(const volatile TSample& other) volatile {
|
||||
return {other.sample, other.control};
|
||||
}
|
||||
|
||||
volatile TSample operator=(const TSample& other) volatile {
|
||||
return {other.sample, other.control};
|
||||
}
|
||||
};
|
||||
|
||||
class CIO {
|
||||
public:
|
||||
CIO();
|
||||
|
@ -59,7 +72,7 @@ public:
|
|||
private:
|
||||
bool m_started;
|
||||
|
||||
CSampleRB m_rxBuffer;
|
||||
CRingBuffer<TSample> m_rxBuffer;
|
||||
CSampleRB m_txBuffer;
|
||||
CRingBuffer<uint16_t> m_rssiBuffer;
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ void CIO::interrupt()
|
|||
DACC->DACC_CDR = sample;
|
||||
|
||||
sample = ADC->ADC_CDR[ADC_CDR_Chan];
|
||||
m_rxBuffer.put(sample, control);
|
||||
m_rxBuffer.put({sample, control});
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
m_rssiBuffer.put(ADC->ADC_CDR[RSSI_CDR_Chan]);
|
||||
|
|
|
@ -1346,7 +1346,7 @@ void CIO::interrupt()
|
|||
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
|
||||
ADC_SoftwareStartConv(ADC1);
|
||||
|
||||
m_rxBuffer.put(sample, control);
|
||||
m_rxBuffer.put({sample, control});
|
||||
m_rssiBuffer.put(rawRSSI);
|
||||
|
||||
m_watchdog++;
|
||||
|
|
|
@ -420,7 +420,7 @@ void CIO::interrupt()
|
|||
|
||||
// Read value from ADC1 and ADC2
|
||||
sample = ADC1->DR; // read conversion result; EOC is cleared by this read
|
||||
m_rxBuffer.put(sample, control);
|
||||
m_rxBuffer.put({sample, control});
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
rawRSSI = ADC2->DR;
|
||||
m_rssiBuffer.put(rawRSSI);
|
||||
|
|
|
@ -169,7 +169,7 @@ void CIO::interrupt()
|
|||
|
||||
if ((ADC0_SC1A & ADC_SC1_COCO) == ADC_SC1_COCO) {
|
||||
sample = ADC0_RA;
|
||||
m_rxBuffer.put(sample, control);
|
||||
m_rxBuffer.put({sample, control});
|
||||
}
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
|
|
|
@ -53,9 +53,9 @@ public:
|
|||
|
||||
uint16_t getData() const;
|
||||
|
||||
bool put(const TDATATYPE item);
|
||||
bool put(const volatile TDATATYPE item) volatile;
|
||||
|
||||
bool get(TDATATYPE& item);
|
||||
bool get(volatile TDATATYPE& item) volatile;
|
||||
|
||||
TDATATYPE peek() const;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ template <typename TDATATYPE> uint16_t CRingBuffer<TDATATYPE>::getData() const
|
|||
return m_length - m_tail + m_head;
|
||||
}
|
||||
|
||||
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(const TDATATYPE sample)
|
||||
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(const TDATATYPE sample) volatile
|
||||
{
|
||||
if (m_full) {
|
||||
m_overflow = true;
|
||||
|
@ -80,7 +80,7 @@ template <typename TDATATYPE> TDATATYPE CRingBuffer<TDATATYPE>::peek() const
|
|||
return m_buffer[m_tail];
|
||||
}
|
||||
|
||||
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::get(TDATATYPE& item)
|
||||
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::get(volatile TDATATYPE& item) volatile
|
||||
{
|
||||
if (m_head == m_tail && !m_full)
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue