mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-10-24 12:07:40 +00:00
Optimize the use of the FPGA dynamic bit selection blocks. Reorder AD9361 FPGA signal source private members by size. use ssize_t write() return value.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* \file fpga_dynamic_bit_selection.cc
|
||||
* \brief Dynamic Bit Selection in the received signal.
|
||||
* \authors <ul>
|
||||
* <li> Marc Majoral, 2020. mmajoral(at)cttc.es
|
||||
* <li> Marc Majoral, 2023. mmajoral(at)cttc.es
|
||||
* </ul>
|
||||
*
|
||||
* Class that controls the Dynamic Bit Selection in the FPGA.
|
||||
@@ -13,58 +13,52 @@
|
||||
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
||||
* Copyright (C) 2010-2023 (see AUTHORS file for a list of contributors)
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "fpga_dynamic_bit_selection.h"
|
||||
#include "uio_fpga.h"
|
||||
#include <glog/logging.h>
|
||||
#include <fcntl.h> // for open, O_RDWR, O_SYNC
|
||||
#include <iostream> // for cout
|
||||
#include <sys/mman.h> // for mmap
|
||||
|
||||
Fpga_dynamic_bit_selection::Fpga_dynamic_bit_selection(const std::string &device_name1, const std::string &device_name2)
|
||||
Fpga_dynamic_bit_selection::Fpga_dynamic_bit_selection(uint32_t num_freq_bands)
|
||||
: d_num_freq_bands(num_freq_bands)
|
||||
{
|
||||
// dynamic bits selection corresponding to frequency band 1
|
||||
if ((d_device_descriptor1 = open(device_name1.c_str(), O_RDWR | O_SYNC)) == -1)
|
||||
d_map_base = std::vector<volatile unsigned *>(d_num_freq_bands);
|
||||
d_device_descriptors = std::vector<int>(d_num_freq_bands);
|
||||
d_shift_out_bits = std::vector<uint32_t>(d_num_freq_bands);
|
||||
for (uint32_t k = 0; k < d_num_freq_bands; k++)
|
||||
{
|
||||
LOG(WARNING) << "Cannot open deviceio" << device_name1;
|
||||
// find the uio device file corresponding to the dynamic bit selector 0 module.
|
||||
std::string device_name;
|
||||
if (find_uio_dev_file_name(device_name, dyn_bit_sel_device_name, 0) < 0)
|
||||
{
|
||||
std::cerr << "Cannot find the FPGA uio device file corresponding to device name " << dyn_bit_sel_device_name << '\n';
|
||||
return;
|
||||
}
|
||||
// dynamic bits selection corresponding to frequency band 1
|
||||
if ((d_device_descriptors[k] = open(device_name.c_str(), O_RDWR | O_SYNC)) == -1)
|
||||
{
|
||||
LOG(WARNING) << "Cannot open deviceio" << device_name;
|
||||
}
|
||||
d_map_base[k] = reinterpret_cast<volatile unsigned *>(mmap(nullptr, FPGA_PAGE_SIZE,
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, d_device_descriptors[k], 0));
|
||||
|
||||
if (d_map_base[k] == reinterpret_cast<void *>(-1))
|
||||
{
|
||||
LOG(WARNING) << "Cannot map the FPGA dynamic bit selection module in frequency band 1 into tracking memory";
|
||||
std::cout << "Could not map dynamic bit selection memory corresponding to frequency band 1.\n";
|
||||
}
|
||||
|
||||
// init bit selection corresopnding to frequency band 1
|
||||
d_shift_out_bits[k] = shift_out_bits_default;
|
||||
d_map_base[k][0] = d_shift_out_bits[k];
|
||||
}
|
||||
d_map_base1 = reinterpret_cast<volatile unsigned *>(mmap(nullptr, FPGA_PAGE_SIZE,
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, d_device_descriptor1, 0));
|
||||
|
||||
if (d_map_base1 == reinterpret_cast<void *>(-1))
|
||||
{
|
||||
LOG(WARNING) << "Cannot map the FPGA dynamic bit selection module in frequency band 1 into tracking memory";
|
||||
std::cout << "Could not map dynamic bit selection memory corresponding to frequency band 1.\n";
|
||||
}
|
||||
|
||||
// dynamic bits selection corresponding to frequency band 2
|
||||
if ((d_device_descriptor2 = open(device_name2.c_str(), O_RDWR | O_SYNC)) == -1)
|
||||
{
|
||||
LOG(WARNING) << "Cannot open deviceio" << device_name2;
|
||||
}
|
||||
d_map_base2 = reinterpret_cast<volatile unsigned *>(mmap(nullptr, FPGA_PAGE_SIZE,
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, d_device_descriptor2, 0));
|
||||
|
||||
if (d_map_base2 == reinterpret_cast<void *>(-1))
|
||||
{
|
||||
LOG(WARNING) << "Cannot map the FPGA dynamic bit selection module in frequency band 2 into tracking memory";
|
||||
std::cout << "Could not map dynamic bit selection memory corresponding to frequency band 2.\n";
|
||||
}
|
||||
|
||||
// initialize default bit selection
|
||||
shift_out_bits_band1 = shift_out_bits_default;
|
||||
shift_out_bits_band2 = shift_out_bits_default;
|
||||
|
||||
// init bit selection corresopnding to frequency band 1
|
||||
d_map_base1[0] = shift_out_bits_band1;
|
||||
|
||||
// init bit selection corresponding to frequency band 2
|
||||
d_map_base2[0] = shift_out_bits_band2;
|
||||
|
||||
DLOG(INFO) << "Dynamic bit selection FPGA class created";
|
||||
}
|
||||
|
||||
@@ -77,65 +71,42 @@ Fpga_dynamic_bit_selection::~Fpga_dynamic_bit_selection()
|
||||
|
||||
void Fpga_dynamic_bit_selection::bit_selection()
|
||||
{
|
||||
// estimated signal power corresponding to frequency band 1
|
||||
uint32_t rx_signal_power1 = d_map_base1[1];
|
||||
// estimated signal power corresponding to frequency band 2
|
||||
uint32_t rx_signal_power2 = d_map_base2[1];
|
||||
|
||||
// dynamic bit selection corresponding to frequency band 1
|
||||
if (rx_signal_power1 > Power_Threshold_High)
|
||||
for (uint32_t k = 0; k < d_num_freq_bands; k++)
|
||||
{
|
||||
if (shift_out_bits_band1 < shift_out_bit_max)
|
||||
{
|
||||
shift_out_bits_band1 = shift_out_bits_band1 + 1;
|
||||
}
|
||||
}
|
||||
else if (rx_signal_power1 < Power_Threshold_Low)
|
||||
{
|
||||
if (shift_out_bits_band1 > shift_out_bits_min)
|
||||
{
|
||||
shift_out_bits_band1 = shift_out_bits_band1 - 1;
|
||||
}
|
||||
}
|
||||
// estimated signal power
|
||||
uint32_t rx_signal_power = d_map_base[k][1];
|
||||
|
||||
// dynamic bit selection corresponding to frequency band 2
|
||||
if (rx_signal_power2 > Power_Threshold_High)
|
||||
{
|
||||
if (shift_out_bits_band2 < shift_out_bit_max)
|
||||
// dynamic bit selection
|
||||
if (rx_signal_power > Power_Threshold_High)
|
||||
{
|
||||
shift_out_bits_band2 = shift_out_bits_band2 + 1;
|
||||
if (d_shift_out_bits[k] < shift_out_bit_max)
|
||||
{
|
||||
d_shift_out_bits[k] = d_shift_out_bits[k] + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (rx_signal_power2 < Power_Threshold_Low)
|
||||
{
|
||||
if (shift_out_bits_band2 > shift_out_bits_min)
|
||||
else if (rx_signal_power < Power_Threshold_Low)
|
||||
{
|
||||
shift_out_bits_band2 = shift_out_bits_band2 - 1;
|
||||
if (d_shift_out_bits[k] > shift_out_bits_min)
|
||||
{
|
||||
d_shift_out_bits[k] = d_shift_out_bits[k] - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// update bit selection corresopnding to frequency band 1
|
||||
d_map_base[k][0] = d_shift_out_bits[k];
|
||||
}
|
||||
|
||||
// update bit selection corresopnding to frequency band 1
|
||||
d_map_base1[0] = shift_out_bits_band1;
|
||||
|
||||
// udpate bit selection corresponding to frequency band 2
|
||||
d_map_base2[0] = shift_out_bits_band2;
|
||||
}
|
||||
|
||||
|
||||
void Fpga_dynamic_bit_selection::close_devices()
|
||||
{
|
||||
auto *aux = const_cast<unsigned *>(d_map_base1);
|
||||
if (munmap(static_cast<void *>(aux), FPGA_PAGE_SIZE) == -1)
|
||||
for (uint32_t k = 0; k < d_num_freq_bands; k++)
|
||||
{
|
||||
std::cout << "Failed to unmap memory uio\n";
|
||||
auto *aux = const_cast<unsigned *>(d_map_base[k]);
|
||||
if (munmap(static_cast<void *>(aux), FPGA_PAGE_SIZE) == -1)
|
||||
{
|
||||
std::cout << "Failed to unmap memory uio\n";
|
||||
}
|
||||
close(d_device_descriptors[k]);
|
||||
}
|
||||
|
||||
aux = const_cast<unsigned *>(d_map_base2);
|
||||
if (munmap(static_cast<void *>(aux), FPGA_PAGE_SIZE) == -1)
|
||||
{
|
||||
std::cout << "Failed to unmap memory uio\n";
|
||||
}
|
||||
|
||||
close(d_device_descriptor1);
|
||||
close(d_device_descriptor2);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** \addtogroup Signal_Source
|
||||
* \{ */
|
||||
@@ -42,7 +43,7 @@ public:
|
||||
/*!
|
||||
* \brief Constructor
|
||||
*/
|
||||
explicit Fpga_dynamic_bit_selection(const std::string& device_name1, const std::string& device_name2);
|
||||
explicit Fpga_dynamic_bit_selection(uint32_t num_freq_bands);
|
||||
|
||||
/*!
|
||||
* \brief Destructor
|
||||
@@ -52,12 +53,12 @@ public:
|
||||
/*!
|
||||
* \brief This function configures the switch in th eFPGA
|
||||
*/
|
||||
// void set_switch_position(int32_t switch_position);
|
||||
void bit_selection(void);
|
||||
|
||||
private:
|
||||
const std::string switch_device_name = std::string("AXIS_Switch_v1_0_0"); // Switch UIO device name
|
||||
const std::string dyn_bit_sel_device_name = std::string("dynamic_bits_selector"); // Switch dhnamic bit selector device name
|
||||
static const size_t FPGA_PAGE_SIZE = 0x1000;
|
||||
|
||||
static const uint32_t Num_bits_ADC = 12; // Number of bits in the ADC
|
||||
static const uint32_t Num_bits_FPGA = 4; // Number of bits after the bit selection
|
||||
static const uint32_t shift_out_bits_default = Num_bits_ADC - Num_bits_FPGA; // take the most significant bits by default
|
||||
@@ -70,14 +71,11 @@ private:
|
||||
|
||||
void close_devices(void);
|
||||
|
||||
uint32_t shift_out_bits_band1; // number of bits to shift for frequency band 1
|
||||
uint32_t shift_out_bits_band2; // number of bits to shift for frequency band 2
|
||||
std::vector<volatile unsigned*> d_map_base;
|
||||
std::vector<int> d_device_descriptors;
|
||||
std::vector<uint32_t> d_shift_out_bits;
|
||||
|
||||
volatile unsigned* d_map_base1; // driver memory map corresponding to frequency band 1
|
||||
int d_device_descriptor1; // driver descriptor corresponding to frequency band 1
|
||||
|
||||
volatile unsigned* d_map_base2; // driver memory map corresponding to frequency band 2
|
||||
int d_device_descriptor2; // driver descriptor corresponding to frequency band 2
|
||||
uint32_t d_num_freq_bands; // number of frequency bands
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user