Merge branch 'FM' into dstar_correlator_fm

This commit is contained in:
Jonathan Naylor 2020-05-02 16:52:27 +01:00
commit 278622dd88
5 changed files with 35 additions and 50 deletions

View File

@ -38,13 +38,13 @@ const struct TONE_TABLE {
const uint8_t TONE_TABLE_DATA_LEN = 6U;
CCalFM::CCalFM() :
m_tone(NULL),
m_frequency(0),
m_length(0),
m_tone(NULL),
m_level(128*32),
m_transmit(false),
m_lastState(STATE_IDLE),
m_audioSeq(0)
m_audioSeq(0),
m_lastState(STATE_IDLE)
{
}

14
FM.cpp
View File

@ -57,7 +57,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
for (; i < length; i++) {
q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access
CTCSSState ctcssState = m_ctcssRX.process(currentSample);
uint8_t ctcssState = m_ctcssRX.process(currentSample);
if (CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) {
//Not enough samples to determine if you have CTCSS, just carry on
@ -123,7 +123,19 @@ void CFM::process()
void CFM::reset()
{
m_state = FS_LISTENING;
m_callsignTimer.stop();
m_timeoutTimer.stop();
m_kerchunkTimer.stop();
m_ackMinTimer.stop();
m_ackDelayTimer.stop();
m_hangTimer.stop();
m_ctcssRX.reset();
m_rfAck.stop();
m_callsign.stop();
m_timeoutTone.stop();
}
uint8_t CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd)

View File

@ -112,11 +112,11 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, uint8_t leve
return 0U;
}
CTCSSState CFMCTCSSRX::process(q15_t sample)
uint8_t CFMCTCSSRX::process(q15_t sample)
{
q31_t sample31 = q31_t(sample) * m_rxLevelInverse;
m_result = m_result & (~CTS_READY);
m_result &= ~CTS_READY;
q31_t q2 = m_q1;
m_q1 = m_q0;
@ -150,13 +150,13 @@ CTCSSState CFMCTCSSRX::process(q15_t sample)
q31_t value = t2 + t4 - t9;
bool previousCTCSSValid = CTCSS_VALID(m_result);
m_result = m_result | CTS_READY;
m_result |= CTS_READY;
if (value >= m_threshold)
m_result = m_result | CTS_VALID;
m_result |= CTS_VALID;
else
m_result = m_result & ~CTS_VALID;
m_result &= ~CTS_VALID;
if(previousCTCSSValid != CTCSS_VALID(m_result))
if (previousCTCSSValid != CTCSS_VALID(m_result))
DEBUG4("CTCSS Value / Threshold / Valid", value, m_threshold, CTCSS_VALID(m_result));
m_count = 0U;
@ -167,11 +167,6 @@ CTCSSState CFMCTCSSRX::process(q15_t sample)
return m_result;
}
CTCSSState CFMCTCSSRX::getState()
{
return m_result;
}
void CFMCTCSSRX::reset()
{
m_q0 = 0;
@ -192,4 +187,3 @@ q15_t CFMCTCSSRX::q15Division(q15_t a, q15_t divisor)
return a31 / divisor;
}

View File

@ -21,28 +21,9 @@
#include "Config.h"
enum CTCSSState
{
CTS_NONE = 0,
CTS_READY = 1,
CTS_VALID = 2,
CTS_READY_VALID = CTS_READY | CTS_VALID
};
inline CTCSSState operator|(CTCSSState a, CTCSSState b)
{
return static_cast<CTCSSState>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
}
inline CTCSSState operator&(CTCSSState a, CTCSSState b)
{
return static_cast<CTCSSState>(static_cast<uint8_t>(a) & static_cast<uint8_t>(b));
}
inline CTCSSState operator~(CTCSSState a)
{
return static_cast<CTCSSState>(~(static_cast<uint8_t>(a)));
}
const uint8_t CTS_NONE = 0U;
const uint8_t CTS_READY = 1U;
const uint8_t CTS_VALID = 2U;
#define CTCSS_READY(a) ((a & CTS_READY) != 0)
#define CTCSS_NOT_READY(a) ((a & CTS_READY) == 0)
@ -55,22 +36,20 @@ public:
uint8_t setParams(uint8_t frequency, uint8_t threshold, uint8_t level);
CTCSSState process(q15_t sample);
CTCSSState getState();
uint8_t process(q15_t sample);
void reset();
private:
q15_t q15Division(q15_t a, q15_t divisor);
q63_t m_coeffDivTwo;
q31_t m_threshold;
uint16_t m_count;
q31_t m_q0;
q31_t m_q1;
uint8_t m_result;
q15_t m_rxLevelInverse;
q63_t m_coeffDivTwo;
q31_t m_threshold;
uint16_t m_count;
q31_t m_q0;
q31_t m_q1;
CTCSSState m_result;
q15_t m_rxLevelInverse;
q15_t q15Division(q15_t a, q15_t divisor);
};
#endif

View File

@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U;
#define HW_TYPE "MMDVM"
#endif
#define DESCRIPTION "20200501 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)"
#define DESCRIPTION "20200502 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)"
#if defined(GITVERSION)
#define concat(h, a, b, c) h " " a " " b " GitID #" c ""