You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
5.9 KiB
148 lines
5.9 KiB
/////////////////////////////////////////////////////////////////////////////////// |
|
// Copyright (C) 2020, 2022 Jon Beniston, M7RCE <jon@beniston.com> // |
|
// Copyright (C) 2020 Edouard Griffiths, F4EXB <f4exb06@gmail.com> // |
|
// // |
|
// This program is free software; you can redistribute it and/or modify // |
|
// it under the terms of the GNU General Public License as published by // |
|
// the Free Software Foundation as version 3 of the License, or // |
|
// (at your option) any later version. // |
|
// // |
|
// This program is distributed in the hope that it will be useful, // |
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
// GNU General Public License V3 for more details. // |
|
// // |
|
// You should have received a copy of the GNU General Public License // |
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. // |
|
/////////////////////////////////////////////////////////////////////////////////// |
|
|
|
#ifndef DEVICES_USRP_DEVICEUSRPPARAM_H_ |
|
#define DEVICES_USRP_DEVICEUSRPPARAM_H_ |
|
|
|
#include <QStringList> |
|
#include <QRecursiveMutex> |
|
#include <QMutex> |
|
#include <QWaitCondition> |
|
|
|
#include <uhd/usrp/multi_usrp.hpp> |
|
#include <uhd/exception.hpp> |
|
#include <uhd/types/tune_request.hpp> |
|
|
|
#include "export.h" |
|
|
|
/** |
|
* Fair (first come, first served) lock, used to serialise calls to rx_streamer::recv() for |
|
* different streams on the same device, on devices where that is required. |
|
* |
|
* On B2xx, all Rx streams share one transport, with packets being routed to each stream by UHD's |
|
* recv_packet_demuxer_3000. This reads from the transport without holding its mutex, so if |
|
* recv() is called concurrently for two streams, packets can be delivered out of order |
|
* (Seen as 'D' in the console, and reported as an overflow, although no samples are lost). |
|
* |
|
* The lock needs to be fair, so one thread can't starve the other, as packets for a starved |
|
* stream are queued by the demuxer, eventually exhausting the transport's receive frames. |
|
*/ |
|
class DeviceUSRPRecvLock |
|
{ |
|
public: |
|
DeviceUSRPRecvLock() : |
|
m_enabled(false), |
|
m_nextTicket(0), |
|
m_servingTicket(0) |
|
{ |
|
} |
|
|
|
void setEnabled(bool enabled) { m_enabled = enabled; } |
|
|
|
void lock() |
|
{ |
|
if (m_enabled) |
|
{ |
|
QMutexLocker locker(&m_mutex); |
|
quint64 ticket = m_nextTicket++; |
|
|
|
while (ticket != m_servingTicket) { |
|
m_waitCondition.wait(&m_mutex); |
|
} |
|
} |
|
} |
|
|
|
void unlock() |
|
{ |
|
if (m_enabled) |
|
{ |
|
QMutexLocker locker(&m_mutex); |
|
m_servingTicket++; |
|
m_waitCondition.wakeAll(); |
|
} |
|
} |
|
|
|
private: |
|
bool m_enabled; //!< Only set when device is opened, before any streams are created |
|
QMutex m_mutex; |
|
QWaitCondition m_waitCondition; |
|
quint64 m_nextTicket; |
|
quint64 m_servingTicket; |
|
}; |
|
|
|
/** |
|
* This structure refers to one physical device shared among parties (logical devices represented by |
|
* the DeviceAPI with single Rx or Tx stream type). |
|
* It allows storing information on the common resources in one place and is shared among participants. |
|
* There is only one copy that is constructed by the first participant and destroyed by the last. |
|
* A participant knows it is the first or last by checking the lists of buddies (Rx + Tx). |
|
*/ |
|
struct DEVICES_API DeviceUSRPParams |
|
{ |
|
uhd::usrp::multi_usrp::sptr m_dev; //!< device handle |
|
uint32_t m_nbRxChannels; //!< number of Rx channels |
|
uint32_t m_nbTxChannels; //!< number of Tx channels |
|
uhd::meta_range_t m_lpfRangeRx; //!< Low pass filter range information (Rx side) |
|
uhd::meta_range_t m_lpfRangeTx; //!< Low pass filter range information (Tx side) |
|
uhd::freq_range_t m_loRangeRx; //!< LO range for Rx |
|
uhd::freq_range_t m_loRangeTx; //!< LO range for Tx |
|
uhd::meta_range_t m_srRangeRx; //!< Sample rate range |
|
uhd::meta_range_t m_srRangeTx; //!< Sample rate range |
|
uhd::gain_range_t m_gainRangeRx; //!< Gain range for Rx |
|
uhd::gain_range_t m_gainRangeTx; //!< Gain range for Tx |
|
QStringList m_txAntennas; //!< List of Tx antenna names |
|
QStringList m_rxAntennas; //!< List of Rx antenna names |
|
QStringList m_rxGainNames; //!< List of Rx gain stages - Currently this seems limited to "PGA" |
|
QStringList m_clockSources; //!< List of clock sources E.g. "internal", "external", "gpsdo" |
|
QRecursiveMutex m_mutex; //!< Serialises configuration of the device from the device engine threads of different buddies |
|
DeviceUSRPRecvLock m_recvLock; //!< Serialises rx_streamer::recv() calls for streams of different buddies, where required |
|
|
|
DeviceUSRPParams() : |
|
m_dev(), |
|
m_nbRxChannels(0), |
|
m_nbTxChannels(0), |
|
m_lpfRangeRx(), |
|
m_lpfRangeTx(), |
|
m_loRangeRx(), |
|
m_loRangeTx(), |
|
m_srRangeRx(), |
|
m_srRangeTx(), |
|
m_gainRangeRx(), |
|
m_gainRangeTx(), |
|
m_txAntennas(), |
|
m_rxAntennas(), |
|
m_rxGainNames(), |
|
m_clockSources() |
|
{ |
|
} |
|
|
|
/** |
|
* Opens and initialize the device and obtain information (# channels, ranges, ...) |
|
*/ |
|
bool open(const QString &deviceStr, bool channelNumOnly); |
|
void close(); |
|
uhd::usrp::multi_usrp::sptr getDevice() { return m_dev; } |
|
|
|
~DeviceUSRPParams() |
|
{ |
|
close(); |
|
} |
|
|
|
}; |
|
|
|
#endif /* DEVICES_USRP_DEVICEUSRPPARAM_H_ */
|
|
|