diff --git a/plugins/samplesink/limesdroutput/limesdroutput.cpp b/plugins/samplesink/limesdroutput/limesdroutput.cpp index e01ae924f..00b80abb1 100644 --- a/plugins/samplesink/limesdroutput/limesdroutput.cpp +++ b/plugins/samplesink/limesdroutput/limesdroutput.cpp @@ -693,8 +693,18 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo bool suspendTxThread = false; bool suspendAllThread = false; bool doCalibration = false; + double clockGenFreq = 0.0; // QMutexLocker mutexLocker(&m_mutex); + if (LMS_GetClockFreq(m_deviceShared.m_deviceParams->getDevice(), LMS_CLOCK_CGEN, &clockGenFreq) != 0) + { + qCritical("LimeSDROutput::applySettings: could not get clock gen frequency"); + } + else + { + qDebug() << "LimeSDROutput::applySettings: clock gen frequency: " << clockGenFreq; + } + // determine if buddies threads or own thread need to be suspended if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || @@ -766,7 +776,7 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo } else { - //doCalibration = true; + doCalibration = true; qDebug() << "LimeSDROutput::applySettings: Gain set to " << settings.m_gain; } } @@ -792,7 +802,7 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo { m_deviceShared.m_deviceParams->m_log2OvSRTx = settings.m_log2HardInterp; m_deviceShared.m_deviceParams->m_sampleRate = settings.m_devSampleRate; - doCalibration = true; + //doCalibration = true; forceNCOFrequency = true; qDebug("LimeSDROutput::applySettings: set sample rate set to %d with oversampling of %d", settings.m_devSampleRate, @@ -824,7 +834,7 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo } else { - doCalibration = true; + //doCalibration = true; qDebug("LimeSDROutput::applySettings: LPF set to %f Hz", settings.m_lpfBW); } } @@ -847,7 +857,7 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo } else { - doCalibration = true; + //doCalibration = true; qDebug("LimeSDROutput::applySettings: %sd and set LPF FIR to %f Hz", settings.m_lpfFIREnable ? "enable" : "disable", settings.m_lpfFIRBW); @@ -937,9 +947,29 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo } m_settings = settings; + double clockGenFreqAfter; + + if (LMS_GetClockFreq(m_deviceShared.m_deviceParams->getDevice(), LMS_CLOCK_CGEN, &clockGenFreqAfter) != 0) + { + qCritical("LimeSDROutput::applySettings: could not get clock gen frequency"); + } + else + { + qDebug() << "LimeSDROutput::applySettings: clock gen frequency after: " << clockGenFreqAfter; + doCalibration = doCalibration || (clockGenFreqAfter != clockGenFreq); + } if (doCalibration && m_channelAcquired) { + if (m_limeSDROutputThread && m_limeSDROutputThread->isRunning()) + { + m_limeSDROutputThread->stopWork(); + ownThreadWasRunning = true; + } + + suspendRxBuddies(); + suspendTxBuddies(); + if (LMS_Calibrate(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_TX, m_deviceShared.m_channel, @@ -952,6 +982,13 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo { qDebug("LimeSDROutput::applySettings: calibration successful on Tx channel %d", m_deviceShared.m_channel); } + + resumeTxBuddies(); + resumeRxBuddies(); + + if (ownThreadWasRunning) { + m_limeSDROutputThread->startWork(); + } } // resume buddies threads or own thread diff --git a/plugins/samplesource/limesdrinput/limesdrinput.cpp b/plugins/samplesource/limesdrinput/limesdrinput.cpp index 7c6a4be50..728058993 100644 --- a/plugins/samplesource/limesdrinput/limesdrinput.cpp +++ b/plugins/samplesource/limesdrinput/limesdrinput.cpp @@ -715,8 +715,18 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc bool suspendAllThread = false; bool doCalibration = false; bool setAntennaAuto = false; + double clockGenFreq = 0.0; // QMutexLocker mutexLocker(&m_mutex); + if (LMS_GetClockFreq(m_deviceShared.m_deviceParams->getDevice(), LMS_CLOCK_CGEN, &clockGenFreq) != 0) + { + qCritical("LimeSDRInput::applySettings: could not get clock gen frequency"); + } + else + { + qDebug() << "LimeSDRInput::applySettings: clock gen frequency: " << clockGenFreq; + } + // determine if buddies threads or own thread need to be suspended if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || @@ -783,53 +793,44 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) { - m_settings.m_dcBlock = settings.m_dcBlock; - m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection); + m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection); } if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) { - m_settings.m_iqCorrection = settings.m_iqCorrection; - m_deviceAPI->configureCorrections(m_settings.m_dcBlock, m_settings.m_iqCorrection); + m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection); } if ((m_settings.m_gainMode != settings.m_gainMode) || force) { - m_settings.m_gainMode = settings.m_gainMode; - - if (m_settings.m_gainMode == LimeSDRInputSettings::GAIN_AUTO) + if (settings.m_gainMode == LimeSDRInputSettings::GAIN_AUTO) { - m_settings.m_gain = settings.m_gain; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (LMS_SetGaindB(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, - m_settings.m_gain) < 0) + settings.m_gain) < 0) { qDebug("LimeSDRInput::applySettings: LMS_SetGaindB() failed"); } else { - //doCalibration = true; - qDebug() << "LimeSDRInput::applySettings: Gain set to " << m_settings.m_gain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: Gain set to " << settings.m_gain; } } } else { - m_settings.m_lnaGain = settings.m_lnaGain; - m_settings.m_tiaGain = settings.m_tiaGain; - m_settings.m_pgaGain = settings.m_pgaGain; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (DeviceLimeSDR::SetRFELNA_dB(m_deviceShared.m_deviceParams->getDevice(), m_deviceShared.m_channel, - m_settings.m_lnaGain)) + settings.m_lnaGain)) { - qDebug() << "LimeSDRInput::applySettings: LNA gain set to " << m_settings.m_lnaGain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: LNA gain set to " << settings.m_lnaGain; } else { @@ -838,9 +839,10 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if (DeviceLimeSDR::SetRFETIA_dB(m_deviceShared.m_deviceParams->getDevice(), m_deviceShared.m_channel, - m_settings.m_tiaGain)) + settings.m_tiaGain)) { - qDebug() << "LimeSDRInput::applySettings: TIA gain set to " << m_settings.m_tiaGain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: TIA gain set to " << settings.m_tiaGain; } else { @@ -849,9 +851,10 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if (DeviceLimeSDR::SetRBBPGA_dB(m_deviceShared.m_deviceParams->getDevice(), m_deviceShared.m_channel, - m_settings.m_pgaGain)) + settings.m_pgaGain)) { - qDebug() << "LimeSDRInput::applySettings: PGA gain set to " << m_settings.m_pgaGain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: PGA gain set to " << settings.m_pgaGain; } else { @@ -863,36 +866,33 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if ((m_settings.m_gainMode == LimeSDRInputSettings::GAIN_AUTO) && (m_settings.m_gain != settings.m_gain)) { - m_settings.m_gain = settings.m_gain; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (LMS_SetGaindB(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, - m_settings.m_gain) < 0) + settings.m_gain) < 0) { qDebug("LimeSDRInput::applySettings: LMS_SetGaindB() failed"); } else { - //doCalibration = true; - qDebug() << "LimeSDRInput::applySettings: Gain set to " << m_settings.m_gain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: Gain set to " << settings.m_gain; } } } if ((m_settings.m_gainMode == LimeSDRInputSettings::GAIN_MANUAL) && (m_settings.m_lnaGain != settings.m_lnaGain)) { - m_settings.m_lnaGain = settings.m_lnaGain; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (DeviceLimeSDR::SetRFELNA_dB(m_deviceShared.m_deviceParams->getDevice(), m_deviceShared.m_channel, - m_settings.m_lnaGain)) + settings.m_lnaGain)) { - qDebug() << "LimeSDRInput::applySettings: LNA gain set to " << m_settings.m_lnaGain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: LNA gain set to " << settings.m_lnaGain; } else { @@ -903,15 +903,14 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if ((m_settings.m_gainMode == LimeSDRInputSettings::GAIN_MANUAL) && (m_settings.m_tiaGain != settings.m_tiaGain)) { - m_settings.m_tiaGain = settings.m_tiaGain; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (DeviceLimeSDR::SetRFETIA_dB(m_deviceShared.m_deviceParams->getDevice(), m_deviceShared.m_channel, - m_settings.m_tiaGain)) + settings.m_tiaGain)) { - qDebug() << "LimeSDRInput::applySettings: TIA gain set to " << m_settings.m_tiaGain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: TIA gain set to " << settings.m_tiaGain; } else { @@ -922,15 +921,14 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if ((m_settings.m_gainMode == LimeSDRInputSettings::GAIN_MANUAL) && (m_settings.m_pgaGain != settings.m_pgaGain)) { - m_settings.m_pgaGain = settings.m_pgaGain; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (DeviceLimeSDR::SetRBBPGA_dB(m_deviceShared.m_deviceParams->getDevice(), m_deviceShared.m_channel, - m_settings.m_pgaGain)) + settings.m_pgaGain)) { - qDebug() << "LimeSDRInput::applySettings: PGA gain set to " << m_settings.m_pgaGain; + doCalibration = true; + qDebug() << "LimeSDRInput::applySettings: PGA gain set to " << settings.m_pgaGain; } else { @@ -944,50 +942,45 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc { forwardChangeAllDSP = true; //m_settings.m_devSampleRate != settings.m_devSampleRate; - m_settings.m_devSampleRate = settings.m_devSampleRate; - m_settings.m_log2HardDecim = settings.m_log2HardDecim; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (LMS_SetSampleRateDir(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, - m_settings.m_devSampleRate, - 1<m_log2OvSRRx = m_settings.m_log2HardDecim; - m_deviceShared.m_deviceParams->m_sampleRate = m_settings.m_devSampleRate; - doCalibration = true; + m_deviceShared.m_deviceParams->m_log2OvSRRx = settings.m_log2HardDecim; + m_deviceShared.m_deviceParams->m_sampleRate = settings.m_devSampleRate; + //doCalibration = true; forceNCOFrequency = true; qDebug("LimeSDRInput::applySettings: set sample rate set to %d with oversampling of %d", - m_settings.m_devSampleRate, - 1<getDevice() != 0 && m_channelAcquired) { if (LMS_SetLPFBW(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, - m_settings.m_lpfBW) < 0) + settings.m_lpfBW) < 0) { - qCritical("LimeSDRInput::applySettings: could not set LPF to %f Hz", m_settings.m_lpfBW); + qCritical("LimeSDRInput::applySettings: could not set LPF to %f Hz", settings.m_lpfBW); } else { doCalibration = true; - qDebug("LimeSDRInput::applySettings: LPF set to %f Hz", m_settings.m_lpfBW); + qDebug("LimeSDRInput::applySettings: LPF set to %f Hz", settings.m_lpfBW); } } } @@ -995,27 +988,24 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if ((m_settings.m_lpfFIRBW != settings.m_lpfFIRBW) || (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force) { - m_settings.m_lpfFIRBW = settings.m_lpfFIRBW; - m_settings.m_lpfFIREnable = settings.m_lpfFIREnable; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (LMS_SetGFIRLPF(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, - m_settings.m_lpfFIREnable, - m_settings.m_lpfFIRBW) < 0) + settings.m_lpfFIREnable, + settings.m_lpfFIRBW) < 0) { qCritical("LimeSDRInput::applySettings: could %s and set LPF FIR to %f Hz", - m_settings.m_lpfFIREnable ? "enable" : "disable", - m_settings.m_lpfFIRBW); + settings.m_lpfFIREnable ? "enable" : "disable", + settings.m_lpfFIRBW); } else { - doCalibration = true; + //doCalibration = true; qDebug("LimeSDRInput::applySettings: %sd and set LPF FIR to %f Hz", - m_settings.m_lpfFIREnable ? "enable" : "disable", - m_settings.m_lpfFIRBW); + settings.m_lpfFIREnable ? "enable" : "disable", + settings.m_lpfFIRBW); } } } @@ -1023,72 +1013,65 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if ((m_settings.m_ncoFrequency != settings.m_ncoFrequency) || (m_settings.m_ncoEnable != settings.m_ncoEnable) || force || forceNCOFrequency) { - m_settings.m_ncoFrequency = settings.m_ncoFrequency; - m_settings.m_ncoEnable = settings.m_ncoEnable; - if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) { if (DeviceLimeSDR::setNCOFrequency(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, - m_settings.m_ncoEnable, - m_settings.m_ncoFrequency)) + settings.m_ncoEnable, + settings.m_ncoFrequency)) { //doCalibration = true; forwardChangeOwnDSP = true; - m_deviceShared.m_ncoFrequency = m_settings.m_ncoEnable ? m_settings.m_ncoFrequency : 0; // for buddies + m_deviceShared.m_ncoFrequency = settings.m_ncoEnable ? settings.m_ncoFrequency : 0; // for buddies qDebug("LimeSDRInput::applySettings: %sd and set NCO to %d Hz", - m_settings.m_ncoEnable ? "enable" : "disable", - m_settings.m_ncoFrequency); + settings.m_ncoEnable ? "enable" : "disable", + settings.m_ncoFrequency); } else { qCritical("LimeSDRInput::applySettings: could not %s and set NCO to %d Hz", - m_settings.m_ncoEnable ? "enable" : "disable", - m_settings.m_ncoFrequency); + settings.m_ncoEnable ? "enable" : "disable", + settings.m_ncoFrequency); } } } if ((m_settings.m_log2SoftDecim != settings.m_log2SoftDecim) || force) { - m_settings.m_log2SoftDecim = settings.m_log2SoftDecim; forwardChangeOwnDSP = true; - m_deviceShared.m_log2Soft = m_settings.m_log2SoftDecim; // for buddies + m_deviceShared.m_log2Soft = settings.m_log2SoftDecim; // for buddies if (m_limeSDRInputThread != 0) { - m_limeSDRInputThread->setLog2Decimation(m_settings.m_log2SoftDecim); - qDebug() << "LimeSDRInput::applySettings: set soft decimation to " << (1<setLog2Decimation(settings.m_log2SoftDecim); + qDebug() << "LimeSDRInput::applySettings: set soft decimation to " << (1<getDevice() != 0 && m_channelAcquired) { if (DeviceLimeSDR::setRxAntennaPath(m_deviceShared.m_deviceParams->getDevice(), m_deviceShared.m_channel, - m_settings.m_antennaPath)) + settings.m_antennaPath)) { doCalibration = true; - setAntennaAuto = (m_settings.m_antennaPath == 0); + setAntennaAuto = (settings.m_antennaPath == 0); qDebug("LimeSDRInput::applySettings: set antenna path to %d", - (int) m_settings.m_antennaPath); + (int) settings.m_antennaPath); } else { qCritical("LimeSDRInput::applySettings: could not set antenna path to %d", - (int) m_settings.m_antennaPath); + (int) settings.m_antennaPath); } } } if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || setAntennaAuto || force) { - m_settings.m_centerFrequency = settings.m_centerFrequency; forwardChangeRxDSP = true; if (m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired) @@ -1096,22 +1079,43 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc if (LMS_SetLOFrequency(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, // same for both channels anyway but switches antenna port automatically - m_settings.m_centerFrequency) < 0) + settings.m_centerFrequency) < 0) { - qCritical("LimeSDRInput::applySettings: could not set frequency to %lu", m_settings.m_centerFrequency); + qCritical("LimeSDRInput::applySettings: could not set frequency to %lu", settings.m_centerFrequency); } else { doCalibration = true; - m_deviceShared.m_centerFrequency = m_settings.m_centerFrequency; // for buddies - qDebug("LimeSDRInput::applySettings: frequency set to %lu", m_settings.m_centerFrequency); + m_deviceShared.m_centerFrequency = settings.m_centerFrequency; // for buddies + qDebug("LimeSDRInput::applySettings: frequency set to %lu", settings.m_centerFrequency); } } } + m_settings = settings; + double clockGenFreqAfter; + + if (LMS_GetClockFreq(m_deviceShared.m_deviceParams->getDevice(), LMS_CLOCK_CGEN, &clockGenFreqAfter) != 0) + { + qCritical("LimeSDRInput::applySettings: could not get clock gen frequency"); + } + else + { + qDebug() << "LimeSDRInput::applySettings: clock gen frequency after: " << clockGenFreqAfter; + doCalibration = doCalibration || (clockGenFreqAfter != clockGenFreq); + } if (doCalibration) { + if (m_limeSDRInputThread && m_limeSDRInputThread->isRunning()) + { + m_limeSDRInputThread->stopWork(); + ownThreadWasRunning = true; + } + + suspendRxBuddies(); + suspendTxBuddies(); + if (LMS_Calibrate(m_deviceShared.m_deviceParams->getDevice(), LMS_CH_RX, m_deviceShared.m_channel, @@ -1124,6 +1128,13 @@ bool LimeSDRInput::applySettings(const LimeSDRInputSettings& settings, bool forc { qDebug("LimeSDRInput::applySettings: calibration successful on Rx channel %d", m_deviceShared.m_channel); } + + resumeTxBuddies(); + resumeRxBuddies(); + + if (ownThreadWasRunning) { + m_limeSDRInputThread->startWork(); + } } // resume buddies threads or own thread