Clock the timers seperately.

This commit is contained in:
Jonathan Naylor 2020-05-03 13:08:33 +01:00
parent f8e119c26b
commit 4feca3c5b7
2 changed files with 20 additions and 13 deletions

29
FM.cpp
View File

@ -53,6 +53,8 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
if (!m_useCOS) if (!m_useCOS)
cos = true; cos = true;
clock(length);
uint8_t i = 0U; uint8_t i = 0U;
for (; i < length; i++) { for (; i < length; i++) {
q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access
@ -65,20 +67,20 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
} else if (CTCSS_READY(ctcssState) && m_modemState != STATE_FM) { } else if (CTCSS_READY(ctcssState) && m_modemState != STATE_FM) {
//we had enough samples for CTCSS and we are in some other mode than FM //we had enough samples for CTCSS and we are in some other mode than FM
bool validCTCSS = CTCSS_VALID(ctcssState); bool validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS && cos, i + 1U); stateMachine(validCTCSS && cos);
if (m_modemState != STATE_FM) if (m_modemState != STATE_FM)
continue; continue;
} else if (CTCSS_READY(ctcssState) && m_modemState == STATE_FM) { } else if (CTCSS_READY(ctcssState) && m_modemState == STATE_FM) {
//We had enough samples for CTCSS and we are in FM mode, trigger the state machine //We had enough samples for CTCSS and we are in FM mode, trigger the state machine
bool validCTCSS = CTCSS_VALID(ctcssState); bool validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS && cos, i + 1U); stateMachine(validCTCSS && cos);
if (m_modemState != STATE_FM) if (m_modemState != STATE_FM)
break; break;
} else if (CTCSS_NOT_READY(ctcssState) && m_modemState == STATE_FM && i == length - 1) { } else if (CTCSS_NOT_READY(ctcssState) && m_modemState == STATE_FM && i == length - 1) {
//Not enough samples for CTCSS but we already are in FM, trigger the state machine //Not enough samples for CTCSS but we already are in FM, trigger the state machine
//but do not trigger the state machine on every single sample, save CPU! //but do not trigger the state machine on every single sample, save CPU!
bool validCTCSS = CTCSS_VALID(ctcssState); bool validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS && cos, i + 1U); stateMachine(validCTCSS && cos);
} }
// Only let audio through when relaying audio // Only let audio through when relaying audio
@ -182,16 +184,8 @@ uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFreque
return m_ctcssTX.setParams(ctcssFrequency, ctcssLevel); return m_ctcssTX.setParams(ctcssFrequency, ctcssLevel);
} }
void CFM::stateMachine(bool validSignal, uint8_t length) void CFM::stateMachine(bool validSignal)
{ {
m_callsignTimer.clock(length);
m_timeoutTimer.clock(length);
m_holdoffTimer.clock(length);
m_kerchunkTimer.clock(length);
m_ackMinTimer.clock(length);
m_ackDelayTimer.clock(length);
m_hangTimer.clock(length);
switch (m_state) { switch (m_state) {
case FS_LISTENING: case FS_LISTENING:
listeningState(validSignal); listeningState(validSignal);
@ -232,6 +226,17 @@ void CFM::stateMachine(bool validSignal, uint8_t length)
} }
} }
void CFM::clock(uint8_t length)
{
m_callsignTimer.clock(length);
m_timeoutTimer.clock(length);
m_holdoffTimer.clock(length);
m_kerchunkTimer.clock(length);
m_ackMinTimer.clock(length);
m_ackDelayTimer.clock(length);
m_hangTimer.clock(length);
}
void CFM::listeningState(bool validSignal) void CFM::listeningState(bool validSignal)
{ {
if (validSignal) { if (validSignal) {

4
FM.h
View File

@ -83,7 +83,7 @@ private:
q15_t m_rfAudioBoost; q15_t m_rfAudioBoost;
CFMDownsampler m_downsampler; CFMDownsampler m_downsampler;
void stateMachine(bool validSignal, uint8_t length); void stateMachine(bool validSignal);
void listeningState(bool validSignal); void listeningState(bool validSignal);
void kerchunkState(bool validSignal); void kerchunkState(bool validSignal);
void relayingState(bool validSignal); void relayingState(bool validSignal);
@ -92,6 +92,8 @@ private:
void timeoutWaitState(bool validSignal); void timeoutWaitState(bool validSignal);
void hangState(bool validSignal); void hangState(bool validSignal);
void clock(uint8_t length);
void sendCallsign(); void sendCallsign();
void beginRelaying(); void beginRelaying();
}; };