mirror of https://github.com/PentHertz/srsLTE.git
Radio: added locks to protect sample rate change concurrent access
This commit is contained in:
parent
029f36b449
commit
7bad21c30a
|
@ -105,6 +105,8 @@ private:
|
||||||
phy_interface_radio* phy = nullptr;
|
phy_interface_radio* phy = nullptr;
|
||||||
cf_t* zeros = nullptr;
|
cf_t* zeros = nullptr;
|
||||||
std::array<cf_t*, SRSLTE_MAX_CHANNELS> dummy_buffers;
|
std::array<cf_t*, SRSLTE_MAX_CHANNELS> dummy_buffers;
|
||||||
|
std::mutex tx_mutex;
|
||||||
|
std::mutex rx_mutex;
|
||||||
std::array<std::vector<cf_t>, SRSLTE_MAX_CHANNELS> tx_buffer;
|
std::array<std::vector<cf_t>, SRSLTE_MAX_CHANNELS> tx_buffer;
|
||||||
std::array<std::vector<cf_t>, SRSLTE_MAX_CHANNELS> rx_buffer;
|
std::array<std::vector<cf_t>, SRSLTE_MAX_CHANNELS> rx_buffer;
|
||||||
std::array<srslte_resampler_fft_t, SRSLTE_MAX_CHANNELS> interpolators = {};
|
std::array<srslte_resampler_fft_t, SRSLTE_MAX_CHANNELS> interpolators = {};
|
||||||
|
|
|
@ -192,6 +192,16 @@ int radio::init(const rf_args_t& args, phy_interface_radio* phy_)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set resampler buffers to 5 ms
|
||||||
|
if (std::isnormal(fix_srate_hz)) {
|
||||||
|
for (auto& buf : rx_buffer) {
|
||||||
|
buf.resize(size_t(fix_srate_hz / 200));
|
||||||
|
}
|
||||||
|
for (auto& buf : tx_buffer) {
|
||||||
|
buf.resize(size_t(fix_srate_hz / 200));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Frequency offset
|
// Frequency offset
|
||||||
freq_offset = args.freq_offset;
|
freq_offset = args.freq_offset;
|
||||||
|
|
||||||
|
@ -260,6 +270,7 @@ bool radio::start_agc(bool tx_gain_same_rx)
|
||||||
|
|
||||||
bool radio::rx_now(rf_buffer_interface& buffer, rf_timestamp_interface& rxd_time)
|
bool radio::rx_now(rf_buffer_interface& buffer, rf_timestamp_interface& rxd_time)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(rx_mutex);
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
rf_buffer_t buffer_rx;
|
rf_buffer_t buffer_rx;
|
||||||
uint32_t ratio = SRSLTE_MAX(1, decimators[0].ratio);
|
uint32_t ratio = SRSLTE_MAX(1, decimators[0].ratio);
|
||||||
|
@ -294,9 +305,11 @@ bool radio::rx_now(rf_buffer_interface& buffer, rf_timestamp_interface& rxd_time
|
||||||
// Perform decimation
|
// Perform decimation
|
||||||
if (ratio > 1) {
|
if (ratio > 1) {
|
||||||
for (uint32_t ch = 0; ch < nof_channels; ch++) {
|
for (uint32_t ch = 0; ch < nof_channels; ch++) {
|
||||||
|
if (buffer.get(ch) and buffer_rx.get(ch)) {
|
||||||
srslte_resampler_fft_run(&decimators[ch], buffer_rx.get(ch), buffer.get(ch), buffer_rx.get_nof_samples());
|
srslte_resampler_fft_run(&decimators[ch], buffer_rx.get(ch), buffer.get(ch), buffer_rx.get_nof_samples());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -361,6 +374,7 @@ bool radio::rx_dev(const uint32_t& device_idx, const rf_buffer_interface& buffer
|
||||||
bool radio::tx(rf_buffer_interface& buffer, const rf_timestamp_interface& tx_time)
|
bool radio::tx(rf_buffer_interface& buffer, const rf_timestamp_interface& tx_time)
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
std::unique_lock<std::mutex> lock(tx_mutex);
|
||||||
|
|
||||||
// If the interpolator have been set, interpolate
|
// If the interpolator have been set, interpolate
|
||||||
if (interpolators[0].ratio > 1) {
|
if (interpolators[0].ratio > 1) {
|
||||||
|
@ -604,6 +618,8 @@ void radio::set_rx_gain_th(const float& gain)
|
||||||
|
|
||||||
void radio::set_rx_srate(const double& srate)
|
void radio::set_rx_srate(const double& srate)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(rx_mutex);
|
||||||
|
|
||||||
if (!is_initialized) {
|
if (!is_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -620,10 +636,6 @@ void radio::set_rx_srate(const double& srate)
|
||||||
uint32_t ratio = (uint32_t)ceil(cur_rx_srate / srate);
|
uint32_t ratio = (uint32_t)ceil(cur_rx_srate / srate);
|
||||||
for (uint32_t ch = 0; ch < nof_channels; ch++) {
|
for (uint32_t ch = 0; ch < nof_channels; ch++) {
|
||||||
srslte_resampler_fft_init(&decimators[ch], SRSLTE_RESAMPLER_MODE_DECIMATE, ratio);
|
srslte_resampler_fft_init(&decimators[ch], SRSLTE_RESAMPLER_MODE_DECIMATE, ratio);
|
||||||
|
|
||||||
if (rx_buffer[ch].empty()) {
|
|
||||||
rx_buffer[ch].resize(SRSLTE_SF_LEN_MAX * 5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -845,6 +857,7 @@ double radio::get_dev_cal_tx_adv_sec(const std::string& device_name)
|
||||||
|
|
||||||
void radio::set_tx_srate(const double& srate)
|
void radio::set_tx_srate(const double& srate)
|
||||||
{
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(tx_mutex);
|
||||||
if (!is_initialized) {
|
if (!is_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -862,10 +875,6 @@ void radio::set_tx_srate(const double& srate)
|
||||||
uint32_t ratio = (uint32_t)ceil(cur_tx_srate / srate);
|
uint32_t ratio = (uint32_t)ceil(cur_tx_srate / srate);
|
||||||
for (uint32_t ch = 0; ch < nof_channels; ch++) {
|
for (uint32_t ch = 0; ch < nof_channels; ch++) {
|
||||||
srslte_resampler_fft_init(&interpolators[ch], SRSLTE_RESAMPLER_MODE_INTERPOLATE, ratio);
|
srslte_resampler_fft_init(&interpolators[ch], SRSLTE_RESAMPLER_MODE_INTERPOLATE, ratio);
|
||||||
|
|
||||||
if (tx_buffer[ch].empty()) {
|
|
||||||
tx_buffer[ch].resize(5 * SRSLTE_SF_LEN_MAX);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (srslte_rf_t& rf_device : rf_devices) {
|
for (srslte_rf_t& rf_device : rf_devices) {
|
||||||
|
|
Loading…
Reference in New Issue