Simplify the calculations.

This commit is contained in:
Jonathan Naylor 2020-04-27 12:05:55 +01:00
parent 82dcc44a2d
commit e8ed77241c
4 changed files with 7 additions and 22 deletions

4
FM.cpp
View File

@ -156,7 +156,7 @@ uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFreque
m_timeoutTone.setParams(timeoutLevel); m_timeoutTone.setParams(timeoutLevel);
m_blanking.setParams(maxDev, timeoutLevel); m_blanking.setParams(maxDev, timeoutLevel);
uint8_t ret = m_ctcssRX.setParams(ctcssFrequency, ctcssThreshold, q15_t(rxLevel * 128)); uint8_t ret = m_ctcssRX.setParams(ctcssFrequency, ctcssThreshold, rxLevel);
if (ret != 0U) if (ret != 0U)
return ret; return ret;
@ -397,5 +397,3 @@ void CFM::beginRelaying()
m_timeoutTimer.start(); m_timeoutTimer.start();
m_ackMinTimer.start(); m_ackMinTimer.start();
} }

View File

@ -91,10 +91,9 @@ m_rxLevelInverse(1)
{ {
} }
uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, q15_t rxLevel) uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, uint8_t level)
{ {
// Calculate 1/rxLevel m_rxLevelInverse = 255 / q15_t(level);
m_rxLevelInverse = q31_t(q15Division(65535 /* This value should be 32767 (q15 1). But this does not work.*/, rxLevel));
m_coeffDivTwo = 0; m_coeffDivTwo = 0;
@ -115,7 +114,7 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, q15_t rxLeve
CTCSSState CFMCTCSSRX::process(q15_t sample) CTCSSState CFMCTCSSRX::process(q15_t sample)
{ {
q63_t sample31 = q31_t(sample) * m_rxLevelInverse; q31_t sample31 = q31_t(sample) * m_rxLevelInverse;
m_result = m_result & (~CTS_READY); m_result = m_result & (~CTS_READY);

View File

@ -53,7 +53,7 @@ class CFMCTCSSRX {
public: public:
CFMCTCSSRX(); CFMCTCSSRX();
uint8_t setParams(uint8_t frequency, uint8_t threshold, q15_t rxLevel); uint8_t setParams(uint8_t frequency, uint8_t threshold, uint8_t level);
CTCSSState process(q15_t sample); CTCSSState process(q15_t sample);
@ -62,25 +62,13 @@ public:
void reset(); void reset();
private: private:
static inline q15_t q15Division(q15_t a, q15_t divisor)
{
q31_t a31 = q31_t(a) << 16;
if (((a >> 31) & 1) == ((divisor >> 15) & 1))
a31 += divisor >> 1;
else
a31 -= divisor >> 1;
return a31 / divisor;
}
q63_t m_coeffDivTwo; q63_t m_coeffDivTwo;
q31_t m_threshold; q31_t m_threshold;
uint16_t m_count; uint16_t m_count;
q31_t m_q0; q31_t m_q0;
q31_t m_q1; q31_t m_q1;
CTCSSState m_result; CTCSSState m_result;
q31_t m_rxLevelInverse; q15_t m_rxLevelInverse;
}; };
#endif #endif

View File

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