1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-04-09 20:26:46 +00:00

acquisition gps unit test for the FPGA. The code is currently being cleaned

This commit is contained in:
mmajoral 2017-05-05 16:14:27 +02:00
parent 04369651f1
commit 9195740d8a
8 changed files with 2054 additions and 0 deletions

View File

@ -0,0 +1,282 @@
/*!
* \file gps_l1_ca_pcps_acquisition_fpga.cc
* \brief Adapts a PCPS acquisition block to an FPGA Acquisition Interface for
* GPS L1 C/A signals. This file is based on the file gps_l1_ca_pcps_acquisition.cc
* \authors <ul>
* <li> Marc Majoral, 2017. mmajoral(at)cttc.cat
* </ul>
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "gps_l1_ca_pcps_acquisition_fpga.h"
#include <boost/math/distributions/exponential.hpp>
#include <glog/logging.h>
#include "gps_sdr_signal_processing.h"
#include "GPS_L1_CA.h"
#include "configuration_interface.h"
using google::LogMessage;
GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga(
ConfigurationInterface* configuration, std::string role,
unsigned int in_streams, unsigned int out_streams) :
role_(role), in_streams_(in_streams), out_streams_(out_streams)
{
configuration_ = configuration;
std::string default_item_type = "cshort";
std::string default_dump_filename = "./data/acquisition.dat";
DLOG(INFO) << "role " << role;
item_type_ = configuration_->property(role + ".item_type", default_item_type);
fs_in_ = configuration_->property("GNSS-SDR.internal_fs_hz", 2048000);
if_ = configuration_->property(role + ".if", 0);
dump_ = configuration_->property(role + ".dump", false);
doppler_max_ = configuration_->property(role + ".doppler_max", 5000);
sampled_ms_ = configuration_->property(role + ".coherent_integration_time_ms", 1);
// note : the FPGA is implemented according to bit transition flag = 0. Setting bit transition flag to 1 has no effect.
bit_transition_flag_ = configuration_->property(role + ".bit_transition_flag", false);
// note : the FPGA is implemented according to use_CFAR_algorithm = 0. Setting use_CFAR_algorithm to 1 has no effect.
use_CFAR_algorithm_flag_=configuration_->property(role + ".use_CFAR_algorithm", false);
max_dwells_ = configuration_->property(role + ".max_dwells", 1);
dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename);
//--- Find number of samples per spreading code -------------------------
code_length_ = round(fs_in_ / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS));
// code length has the same value as d_fft_size
float nbits;
nbits = ceilf(log2f(code_length_));
nsamples_total_ = pow(2,nbits);
//vector_length_ = code_length_ * sampled_ms_;
vector_length_ = nsamples_total_ * sampled_ms_;
if( bit_transition_flag_ )
{
vector_length_ *= 2;
}
code_ = new gr_complex[vector_length_];
if (item_type_.compare("cshort") == 0 )
{
item_size_ = sizeof(lv_16sc_t);
gps_acquisition_fpga_sc_ = gps_pcps_make_acquisition_fpga_sc(sampled_ms_, max_dwells_,
doppler_max_, if_, fs_in_, code_length_, code_length_, vector_length_,
bit_transition_flag_, use_CFAR_algorithm_flag_, dump_, dump_filename_);
DLOG(INFO) << "acquisition(" << gps_acquisition_fpga_sc_->unique_id() << ")";
}
else{
LOG(FATAL) << item_type_ << " FPGA only accepts chsort";
}
channel_ = 0;
threshold_ = 0.0;
doppler_step_ = 0;
gnss_synchro_ = 0;
}
GpsL1CaPcpsAcquisitionFpga::~GpsL1CaPcpsAcquisitionFpga()
{
delete[] code_;
}
void GpsL1CaPcpsAcquisitionFpga::set_channel(unsigned int channel)
{
channel_ = channel;
gps_acquisition_fpga_sc_->set_channel(channel_);
}
void GpsL1CaPcpsAcquisitionFpga::set_threshold(float threshold)
{
float pfa = configuration_->property(role_ + ".pfa", 0.0);
if(pfa == 0.0)
{
threshold_ = threshold;
}
else
{
threshold_ = calculate_threshold(pfa);
}
DLOG(INFO) << "Channel " << channel_ << " Threshold = " << threshold_;
gps_acquisition_fpga_sc_->set_threshold(threshold_);
}
void GpsL1CaPcpsAcquisitionFpga::set_doppler_max(unsigned int doppler_max)
{
doppler_max_ = doppler_max;
gps_acquisition_fpga_sc_->set_doppler_max(doppler_max_);
}
void GpsL1CaPcpsAcquisitionFpga::set_doppler_step(unsigned int doppler_step)
{
doppler_step_ = doppler_step;
gps_acquisition_fpga_sc_->set_doppler_step(doppler_step_);
}
void GpsL1CaPcpsAcquisitionFpga::set_gnss_synchro(Gnss_Synchro* gnss_synchro)
{
gnss_synchro_ = gnss_synchro;
gps_acquisition_fpga_sc_->set_gnss_synchro(gnss_synchro_);
}
signed int GpsL1CaPcpsAcquisitionFpga::mag()
{
return gps_acquisition_fpga_sc_->mag();
}
void GpsL1CaPcpsAcquisitionFpga::init()
{
gps_acquisition_fpga_sc_->init();
set_local_code();
}
void GpsL1CaPcpsAcquisitionFpga::set_local_code()
{
std::complex<float>* code = new std::complex<float>[vector_length_];
//init to zeros for the zero padding of the fft
for (uint s=0;s<vector_length_;s++)
{
code[s] = std::complex<float>(0, 0);
}
unsigned long long interpolated_sampling_frequency; // warning: we need a long long to do this conversion to avoid running out of bits
gps_l1_ca_code_gen_complex_sampled(code, gnss_synchro_->PRN, fs_in_ , 0);
for (unsigned int i = 0; i < sampled_ms_; i++)
{
memcpy(&(code_[i*vector_length_]), code, sizeof(gr_complex)*vector_length_);
}
gps_acquisition_fpga_sc_->set_local_code(code_);
delete[] code;
}
void GpsL1CaPcpsAcquisitionFpga::reset()
{
gps_acquisition_fpga_sc_->set_active(true);
}
void GpsL1CaPcpsAcquisitionFpga::set_state(int state)
{
gps_acquisition_fpga_sc_->set_state(state);
}
float GpsL1CaPcpsAcquisitionFpga::calculate_threshold(float pfa)
{
//Calculate the threshold
unsigned int frequency_bins = 0;
for (int doppler = (int)(-doppler_max_); doppler <= (int)doppler_max_; doppler += doppler_step_)
{
frequency_bins++;
}
DLOG(INFO) << "Channel " << channel_ << " Pfa = " << pfa;
unsigned int ncells = vector_length_ * frequency_bins;
double exponent = 1 / static_cast<double>(ncells);
double val = pow(1.0 - pfa, exponent);
double lambda = double(vector_length_);
boost::math::exponential_distribution<double> mydist (lambda);
float threshold = (float)quantile(mydist,val);
return threshold;
}
void GpsL1CaPcpsAcquisitionFpga::connect(gr::top_block_sptr top_block)
{
//nothing to connect
}
void GpsL1CaPcpsAcquisitionFpga::disconnect(gr::top_block_sptr top_block)
{
//nothing to disconnect
}
gr::basic_block_sptr GpsL1CaPcpsAcquisitionFpga::get_left_block()
{
return gps_acquisition_fpga_sc_;
}
gr::basic_block_sptr GpsL1CaPcpsAcquisitionFpga::get_right_block()
{
return gps_acquisition_fpga_sc_;
}

View File

@ -0,0 +1,170 @@
/*!
* \file gps_l1_ca_pcps_acquisition_fpga.h
* \brief Adapts a PCPS acquisition block to an AcquisitionInterface for
* GPS L1 C/A signals. This file is based on the file gps_l1_ca_pcps_acquisition.h
* \authors <ul>
* <li> Marc Majoral, 2017. mmajoral(at)cttc.cat
* </ul>
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_GPS_L1_CA_PCPS_ACQUISITION_FPGA_H_
#define GNSS_SDR_GPS_L1_CA_PCPS_ACQUISITION_FPGA_H_
#include <string>
#include <gnuradio/blocks/stream_to_vector.h>
#include <gnuradio/blocks/float_to_complex.h>
#include "gnss_synchro.h"
#include "acquisition_interface.h"
#include "gps_pcps_acquisition_fpga_sc.h"
#include "complex_byte_to_float_x2.h"
#include <volk_gnsssdr/volk_gnsssdr.h>
class ConfigurationInterface;
/*!
* \brief This class adapts a PCPS acquisition block to an AcquisitionInterface
* for GPS L1 C/A signals
*/
class GpsL1CaPcpsAcquisitionFpga: public AcquisitionInterface
{
public:
GpsL1CaPcpsAcquisitionFpga(ConfigurationInterface* configuration,
std::string role, unsigned int in_streams,
unsigned int out_streams);
virtual ~GpsL1CaPcpsAcquisitionFpga();
std::string role()
{
return role_;
}
/*!
* \brief Returns "GPS_L1_CA_PCPS_Acquisition"
*/
std::string implementation()
{
return "GPS_L1_CA_PCPS_Acquisition";
}
size_t item_size()
{
return item_size_;
}
void connect(gr::top_block_sptr top_block);
void disconnect(gr::top_block_sptr top_block);
gr::basic_block_sptr get_left_block();
gr::basic_block_sptr get_right_block();
/*!
* \brief Set acquisition/tracking common Gnss_Synchro object pointer
* to efficiently exchange synchronization data between acquisition and
* tracking blocks
*/
void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro);
/*!
* \brief Set acquisition channel unique ID
*/
void set_channel(unsigned int channel);
/*!
* \brief Set statistics threshold of PCPS algorithm
*/
void set_threshold(float threshold);
/*!
* \brief Set maximum Doppler off grid search
*/
void set_doppler_max(unsigned int doppler_max);
/*!
* \brief Set Doppler steps for the grid search
*/
void set_doppler_step(unsigned int doppler_step);
/*!
* \brief Initializes acquisition algorithm.
*/
void init();
/*!
* \brief Sets local code for GPS L1/CA PCPS acquisition algorithm.
*/
void set_local_code();
/*!
* \brief Returns the maximum peak of grid search
*/
signed int mag();
/*!
* \brief Restart acquisition algorithm
*/
void reset();
/*!
* \brief If state = 1, it forces the block to start acquiring from the first sample
*/
void set_state(int state);
private:
ConfigurationInterface* configuration_;
gps_pcps_acquisition_fpga_sc_sptr gps_acquisition_fpga_sc_;
gr::blocks::stream_to_vector::sptr stream_to_vector_;
gr::blocks::float_to_complex::sptr float_to_complex_;
complex_byte_to_float_x2_sptr cbyte_to_float_x2_;
size_t item_size_;
std::string item_type_;
unsigned int vector_length_;
unsigned int code_length_;
bool bit_transition_flag_;
bool use_CFAR_algorithm_flag_;
unsigned int channel_;
float threshold_;
unsigned int doppler_max_;
unsigned int doppler_step_;
unsigned int sampled_ms_;
unsigned int max_dwells_;
long fs_in_;
long if_;
bool dump_;
std::string dump_filename_;
std::complex<float> * code_;
Gnss_Synchro * gnss_synchro_;
std::string role_;
unsigned int in_streams_;
unsigned int out_streams_;
unsigned int nsamples_total_;
float calculate_threshold(float pfa);
};
#endif /* GNSS_SDR_GPS_L1_CA_PCPS_ACQUISITION_H_ */

View File

@ -0,0 +1,440 @@
/*!
* \file gps_pcps_acquisition_fpga_sc.cc
* \brief This class implements a Parallel Code Phase Search Acquisition in the FPGA.
* This file is based on the file gps_pcps_acquisition_sc.cc
* \authors <ul>
* <li> Marc Majoral, 2017. mmajoral(at)cttc.cat
* </ul>
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "gps_pcps_acquisition_fpga_sc.h"
#include <sstream>
#include <boost/filesystem.hpp>
#include <gnuradio/io_signature.h>
#include <glog/logging.h>
#include <volk/volk.h>
#include <volk_gnsssdr/volk_gnsssdr.h>
#include "control_message_factory.h"
#include "GPS_L1_CA.h" //GPS_TWO_PI
using google::LogMessage;
void wait3(int seconds)
{
boost::this_thread::sleep_for(boost::chrono::seconds{seconds});
}
gps_pcps_acquisition_fpga_sc_sptr gps_pcps_make_acquisition_fpga_sc(
unsigned int sampled_ms, unsigned int max_dwells,
unsigned int doppler_max, long freq, long fs_in,
int samples_per_ms, int samples_per_code, int vector_length,
bool bit_transition_flag, bool use_CFAR_algorithm_flag,
bool dump,
std::string dump_filename)
{
return gps_pcps_acquisition_fpga_sc_sptr(
new gps_pcps_acquisition_fpga_sc(sampled_ms, max_dwells, doppler_max, freq, fs_in, samples_per_ms,
samples_per_code, vector_length, bit_transition_flag, use_CFAR_algorithm_flag, dump, dump_filename));
}
gps_pcps_acquisition_fpga_sc::gps_pcps_acquisition_fpga_sc(
unsigned int sampled_ms, unsigned int max_dwells,
unsigned int doppler_max, long freq, long fs_in,
int samples_per_ms, int samples_per_code, int vector_length,
bool bit_transition_flag, bool use_CFAR_algorithm_flag,
bool dump,
std::string dump_filename) :
gr::block("pcps_acquisition_fpga_sc",gr::io_signature::make(0, 0, sizeof(lv_16sc_t)),gr::io_signature::make(0, 0, 0))
{
this->message_port_register_out(pmt::mp("events"));
d_sample_counter = 0; // SAMPLE COUNTER
d_active = false;
d_state = 0;
d_freq = freq;
d_fs_in = fs_in;
d_samples_per_ms = samples_per_ms;
d_samples_per_code = samples_per_code;
d_sampled_ms = sampled_ms;
d_max_dwells = max_dwells;
d_well_count = 0;
d_doppler_max = doppler_max;
d_fft_size = d_sampled_ms * d_samples_per_ms;
d_mag = 0;
d_input_power = 0.0;
d_num_doppler_bins = 0;
d_bit_transition_flag = bit_transition_flag;
d_use_CFAR_algorithm_flag = use_CFAR_algorithm_flag;
d_threshold = 0.0;
d_doppler_step = 250;
d_code_phase = 0;
d_test_statistics = 0.0;
d_channel = 0;
d_doppler_freq = 0.0;
d_nsamples_total = vector_length;
// COD:
// Experimenting with the overlap/save technique for handling bit trannsitions
// The problem: Circular correlation is asynchronous with the received code.
// In effect the first code phase used in the correlation is the current
// estimate of the code phase at the start of the input buffer. If this is 1/2
// of the code period a bit transition would move all the signal energy into
// adjacent frequency bands at +/- 1/T where T is the integration time.
//
// We can avoid this by doing linear correlation, effectively doubling the
// size of the input buffer and padding the code with zeros.
if( d_bit_transition_flag )
{
d_fft_size *= 2;
d_max_dwells = 1;
}
d_fft_codes = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
d_magnitude = static_cast<float*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(float), volk_gnsssdr_get_alignment()));
//temporary storage for the input conversion from 16sc to float 32fc
d_in_32fc = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
d_fft_codes_padded = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
// Direct FFT
d_fft_if = new gr::fft::fft_complex(d_nsamples_total, true);
// Inverse FFT
d_ifft = new gr::fft::fft_complex(d_nsamples_total, false);
// For dumping samples into a file
d_dump = dump;
d_dump_filename = dump_filename;
d_gnss_synchro = 0;
d_grid_doppler_wipeoffs = 0;
}
gps_pcps_acquisition_fpga_sc::~gps_pcps_acquisition_fpga_sc()
{
if (d_num_doppler_bins > 0)
{
for (unsigned int i = 0; i < d_num_doppler_bins; i++)
{
volk_gnsssdr_free(d_grid_doppler_wipeoffs[i]);
}
delete[] d_grid_doppler_wipeoffs;
}
volk_gnsssdr_free(d_fft_codes);
volk_gnsssdr_free(d_magnitude);
volk_gnsssdr_free(d_in_32fc);
delete d_ifft;
delete d_fft_if;
if (d_dump)
{
d_dump_file.close();
}
acquisition_fpga_8sc.free();
}
void gps_pcps_acquisition_fpga_sc::set_local_code(std::complex<float> * code)
{
// COD
// Here we want to create a buffer that looks like this:
// [ 0 0 0 ... 0 c_0 c_1 ... c_L]
// where c_i is the local code and there are L zeros and L chips
int offset = 0;
if( d_bit_transition_flag )
{
std::fill_n( d_fft_if->get_inbuf(), d_nsamples_total, gr_complex( 0.0, 0.0 ) );
offset = d_nsamples_total;
}
memcpy(d_fft_if->get_inbuf() + offset, code, sizeof(gr_complex) * d_nsamples_total);
d_fft_if->execute(); // We need the FFT of local code
volk_32fc_conjugate_32fc(d_fft_codes_padded, d_fft_if->get_outbuf(), d_nsamples_total);
acquisition_fpga_8sc.set_local_code(d_fft_codes_padded);
}
void gps_pcps_acquisition_fpga_sc::update_local_carrier(gr_complex* carrier_vector, int correlator_length_samples, float freq)
{
static int debugint = 0;
float phase_step_rad = GPS_TWO_PI * freq / static_cast<float>(d_fs_in);
float _phase[1];
_phase[0] = 0;
volk_gnsssdr_s32f_sincos_32fc(carrier_vector, - phase_step_rad, _phase, correlator_length_samples);
}
void gps_pcps_acquisition_fpga_sc::init()
{
d_gnss_synchro->Flag_valid_acquisition = false;
d_gnss_synchro->Flag_valid_symbol_output = false;
d_gnss_synchro->Flag_valid_pseudorange = false;
d_gnss_synchro->Flag_valid_word = false;
d_gnss_synchro->Flag_preamble = false;
d_gnss_synchro->Acq_delay_samples = 0.0;
d_gnss_synchro->Acq_doppler_hz = 0.0;
d_gnss_synchro->Acq_samplestamp_samples = 0;
d_mag = 0.0;
d_input_power = 0.0;
d_num_doppler_bins = ceil( static_cast<double>(static_cast<int>(d_doppler_max) - static_cast<int>(-d_doppler_max)) / static_cast<double>(d_doppler_step));
// Create the carrier Doppler wipeoff signals
d_grid_doppler_wipeoffs = new gr_complex*[d_num_doppler_bins];
for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++)
{
d_grid_doppler_wipeoffs[doppler_index] = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
int doppler = -static_cast<int>(d_doppler_max) + d_doppler_step * doppler_index;
update_local_carrier(d_grid_doppler_wipeoffs[doppler_index], d_fft_size, d_freq + doppler);
}
// PENDING : SELECT_QUEUE MUST GO INTO CONFIGURATION
unsigned select_queue = 0;
acquisition_fpga_8sc.init(d_fft_size, d_nsamples_total, d_freq, d_doppler_max, d_doppler_step, d_num_doppler_bins, d_fs_in, select_queue);
}
void gps_pcps_acquisition_fpga_sc::set_state(int state)
{
d_state = state;
if (d_state == 1)
{
d_gnss_synchro->Acq_delay_samples = 0.0;
d_gnss_synchro->Acq_doppler_hz = 0.0;
d_gnss_synchro->Acq_samplestamp_samples = 0;
d_well_count = 0;
d_mag = 0.0;
d_input_power = 0.0;
d_test_statistics = 0.0;
}
else if (d_state == 0)
{}
else
{
LOG(ERROR) << "State can only be set to 0 or 1";
}
}
void gps_pcps_acquisition_fpga_sc::set_active(bool active)
{
float temp_peak_to_noise_level = 0.0;
float peak_to_noise_level = 0.0;
acquisition_fpga_8sc.block_samples(); // block the samples to run the acquisition this is only necessary for the tests
d_active = active;
while (d_well_count < d_max_dwells)
{
int acquisition_message = -1; //0=STOP_CHANNEL 1=ACQ_SUCCEES 2=ACQ_FAIL
d_state = 1;
// initialize acquisition algorithm
int doppler;
uint32_t indext = 0;
float magt = 0.0;
int effective_fft_size = ( d_bit_transition_flag ? d_fft_size/2 : d_fft_size );
float fft_normalization_factor = static_cast<float>(d_fft_size) * static_cast<float>(d_fft_size);
d_mag = 0.0;
unsigned int initial_sample;
d_well_count++;
DLOG(INFO) << "Channel: " << d_channel
<< " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN
//<< " ,sample stamp: " << d_sample_counter << ", threshold: "
<< ", threshold: "
<< d_threshold << ", doppler_max: " << d_doppler_max
<< ", doppler_step: " << d_doppler_step;
// Doppler frequency search loop
for (unsigned int doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++)
{
doppler = -static_cast<int>(d_doppler_max) + d_doppler_step * doppler_index;
acquisition_fpga_8sc.set_phase_step(doppler_index);
acquisition_fpga_8sc.run_acquisition(); // runs acquisition and waits until it is finished
acquisition_fpga_8sc.read_acquisition_results(&indext, &magt, &initial_sample, &d_input_power);
temp_peak_to_noise_level = (float) (magt / d_input_power);
if (peak_to_noise_level < temp_peak_to_noise_level)
{
peak_to_noise_level = temp_peak_to_noise_level;
d_mag = magt;
d_input_power = (d_input_power - d_mag) / (effective_fft_size - 1);
if (d_test_statistics < (d_mag / d_input_power) || !d_bit_transition_flag)
{
d_gnss_synchro->Acq_delay_samples = static_cast<double>(indext % d_samples_per_code);
d_gnss_synchro->Acq_doppler_hz = static_cast<double>(doppler);
d_gnss_synchro->Acq_samplestamp_samples = initial_sample;
d_test_statistics = d_mag / d_input_power;
}
}
// Record results to file if required
if (d_dump)
{
std::stringstream filename;
std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write
filename.str("");
boost::filesystem::path p = d_dump_filename;
filename << p.parent_path().string()
<< boost::filesystem::path::preferred_separator
<< p.stem().string()
<< "_" << d_gnss_synchro->System
<<"_" << d_gnss_synchro->Signal << "_sat_"
<< d_gnss_synchro->PRN << "_doppler_"
<< doppler
<< p.extension().string();
DLOG(INFO) << "Writing ACQ out to " << filename.str();
d_dump_file.open(filename.str().c_str(), std::ios::out | std::ios::binary);
d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin?
d_dump_file.close();
}
}
if (d_test_statistics > d_threshold)
{
d_state = 2; // Positive acquisition
// 6.1- Declare positive acquisition using a message port
DLOG(INFO) << "positive acquisition";
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN;
//DLOG(INFO) << "sample_stamp " << d_sample_counter;
DLOG(INFO) << "sample_stamp " << initial_sample;
DLOG(INFO) << "test statistics value " << d_test_statistics;
DLOG(INFO) << "test statistics threshold " << d_threshold;
DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples;
DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz;
DLOG(INFO) << "magnitude " << d_mag;
DLOG(INFO) << "input signal power " << d_input_power;
d_active = false;
d_state = 0;
acquisition_message = 1;
this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message));
break;
}
else //if (d_well_count == d_max_dwells)
{
d_state = 3; // Negative acquisition
// 6.2- Declare negative acquisition using a message port
DLOG(INFO) << "negative acquisition";
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN;
DLOG(INFO) << "sample_stamp " << d_sample_counter;
DLOG(INFO) << "sample_stamp " << initial_sample;
DLOG(INFO) << "test statistics value " << d_test_statistics;
DLOG(INFO) << "test statistics threshold " << d_threshold;
DLOG(INFO) << "code phase " << d_gnss_synchro->Acq_delay_samples;
DLOG(INFO) << "doppler " << d_gnss_synchro->Acq_doppler_hz;
DLOG(INFO) << "magnitude " << d_mag;
DLOG(INFO) << "input signal power " << d_input_power;
d_active = false;
d_state = 0;
acquisition_message = 2;
this->message_port_pub(pmt::mp("events"), pmt::from_long(acquisition_message));
break;
}
}
acquisition_fpga_8sc.unblock_samples();
DLOG(INFO) << "Done. Consumed 1 item.";
}
int gps_pcps_acquisition_fpga_sc::general_work(int noutput_items,
gr_vector_int &ninput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items __attribute__((unused)))
{
return noutput_items;
}

View File

@ -0,0 +1,235 @@
/*!
* \file gps_pcps_acquisition_fpga_sc.h
* \brief This class implements a Parallel Code Phase Search Acquisition in the FPGA.
* This file is based on the file gps_pcps_acquisition_sc.h
*
* Acquisition strategy (Kay Borre book + CFAR threshold).
* <ol>
* <li> Compute the input signal power estimation
* <li> Doppler serial search loop
* <li> Perform the FFT-based circular convolution (parallel time search)
* <li> Record the maximum peak and the associated synchronization parameters
* <li> Compute the test statistics and compare to the threshold
* <li> Declare positive or negative acquisition using a message port
* </ol>
*
* Kay Borre book: K.Borre, D.M.Akos, N.Bertelsen, P.Rinder, and S.H.Jensen,
* "A Software-Defined GPS and Galileo Receiver. A Single-Frequency
* Approach", Birkha user, 2007. pp 81-84
*
* \authors <ul>
* <li> Marc Majoral, 2017. mmajoral(at)cttc.cat
* </ul>
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_PCPS_ACQUISITION_FPGA_SC_H_
#define GNSS_SDR_PCPS_ACQUISITION_FPGA_SC_H_
#include <fstream>
#include <string>
#include <gnuradio/block.h>
#include <gnuradio/gr_complex.h>
#include <gnuradio/fft/fft.h>
#include "gnss_synchro.h"
#include "gps_fpga_acquisition_8sc.h"
class gps_pcps_acquisition_fpga_sc;
typedef boost::shared_ptr<gps_pcps_acquisition_fpga_sc> gps_pcps_acquisition_fpga_sc_sptr;
gps_pcps_acquisition_fpga_sc_sptr
gps_pcps_make_acquisition_fpga_sc(unsigned int sampled_ms, unsigned int max_dwells,
unsigned int doppler_max, long freq, long fs_in,
int samples_per_ms, int samples_per_code, int vector_length_,
bool bit_transition_flag, bool use_CFAR_algorithm_flag,
bool dump,
std::string dump_filename);
/*!
* \brief This class implements a Parallel Code Phase Search Acquisition.
*
* Check \ref Navitec2012 "An Open Source Galileo E1 Software Receiver",
* Algorithm 1, for a pseudocode description of this implementation.
*/
class gps_pcps_acquisition_fpga_sc: public gr::block
{
private:
friend gps_pcps_acquisition_fpga_sc_sptr
gps_pcps_make_acquisition_fpga_sc(unsigned int sampled_ms, unsigned int max_dwells,
unsigned int doppler_max, long freq, long fs_in,
int samples_per_ms, int samples_per_code, int vector_length,
bool bit_transition_flag, bool use_CFAR_algorithm_flag,
bool dump,
std::string dump_filename);
gps_pcps_acquisition_fpga_sc(unsigned int sampled_ms, unsigned int max_dwells,
unsigned int doppler_max, long freq, long fs_in,
int samples_per_ms, int samples_per_code, int vector_length,
bool bit_transition_flag, bool use_CFAR_algorithm_flag,
bool dump,
std::string dump_filename);
void update_local_carrier(gr_complex* carrier_vector,
int correlator_length_samples,
float freq);
long d_fs_in;
long d_freq;
int d_samples_per_ms;
int d_samples_per_code;
float d_threshold;
std::string d_satellite_str;
unsigned int d_doppler_max;
unsigned int d_doppler_step;
unsigned int d_sampled_ms;
unsigned int d_max_dwells;
unsigned int d_well_count;
unsigned int d_fft_size;
unsigned int d_nsamples_total; // the closest power of two approximation to d_fft_size
unsigned long int d_sample_counter;
gr_complex** d_grid_doppler_wipeoffs;
unsigned int d_num_doppler_bins;
gr_complex* d_fft_codes;
gr_complex* d_fft_codes_padded;
gr_complex* d_in_32fc;
gr::fft::fft_complex* d_fft_if;
gr::fft::fft_complex* d_ifft;
Gnss_Synchro *d_gnss_synchro;
unsigned int d_code_phase;
float d_doppler_freq;
float d_mag;
float* d_magnitude;
float d_input_power;
float d_test_statistics;
bool d_bit_transition_flag;
bool d_use_CFAR_algorithm_flag;
std::ofstream d_dump_file;
bool d_active;
int d_state;
bool d_dump;
unsigned int d_channel;
std::string d_dump_filename;
gps_fpga_acquisition_8sc acquisition_fpga_8sc;
public:
/*!
* \brief Default destructor.
*/
~gps_pcps_acquisition_fpga_sc();
/*!
* \brief Set acquisition/tracking common Gnss_Synchro object pointer
* to exchange synchronization data between acquisition and tracking blocks.
* \param p_gnss_synchro Satellite information shared by the processing blocks.
*/
void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
{
d_gnss_synchro = p_gnss_synchro;
}
/*!
* \brief Returns the maximum peak of grid search.
*/
unsigned int mag()
{
return d_mag;
}
/*!
* \brief Initializes acquisition algorithm.
*/
void init();
/*!
* \brief Sets local code for PCPS acquisition algorithm.
* \param code - Pointer to the PRN code.
*/
void set_local_code(std::complex<float> * code);
/*!
* \brief Starts acquisition algorithm, turning from standby mode to
* active mode
* \param active - bool that activates/deactivates the block.
*/
void set_active(bool active);
/*!
* \brief If set to 1, ensures that acquisition starts at the
* first available sample.
* \param state - int=1 forces start of acquisition
*/
void set_state(int state);
/*!
* \brief Set acquisition channel unique ID
* \param channel - receiver channel.
*/
void set_channel(unsigned int channel)
{
d_channel = channel;
}
/*!
* \brief Set statistics threshold of PCPS algorithm.
* \param threshold - Threshold for signal detection (check \ref Navitec2012,
* Algorithm 1, for a definition of this threshold).
*/
void set_threshold(float threshold)
{
d_threshold = threshold;
}
/*!
* \brief Set maximum Doppler grid search
* \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
*/
void set_doppler_max(unsigned int doppler_max)
{
d_doppler_max = doppler_max;
}
/*!
* \brief Set Doppler steps for the grid search
* \param doppler_step - Frequency bin of the search grid [Hz].
*/
void set_doppler_step(unsigned int doppler_step)
{
d_doppler_step = doppler_step;
}
/*!
* \brief Parallel Code Phase Search Acquisition signal processing.
*/
int general_work(int noutput_items, gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
#endif /* GNSS_SDR_PCPS_ACQUISITION_SC_H_*/

View File

@ -0,0 +1,91 @@
# Copyright (C) 2012-2015 (see AUTHORS file for a list of contributors)
#
# This file is part of GNSS-SDR.
#
# GNSS-SDR 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, either version 3 of the License, or
# (at your option) any later version.
#
# GNSS-SDR 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 for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
#
#if(ENABLE_CUDA)
# # Append current NVCC flags by something, eg comput capability
# # set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_30)
# list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30; -std=c++11;-O3; -use_fast_math -default-stream per-thread")
# set(CUDA_PROPAGATE_HOST_FLAGS OFF)
# CUDA_INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR})
# set(LIB_TYPE STATIC) #set the lib type
# CUDA_ADD_LIBRARY(CUDA_CORRELATOR_LIB ${LIB_TYPE} cuda_multicorrelator.h cuda_multicorrelator.cu)
# set(OPT_TRACKING_LIBRARIES ${OPT_TRACKING_LIBRARIES} CUDA_CORRELATOR_LIB)
# set(OPT_TRACKING_INCLUDES ${OPT_TRACKING_INCLUDES} ${CUDA_INCLUDE_DIRS} )
#endif(ENABLE_CUDA)
#set(TRACKING_LIB_SOURCES
set(ACQUISITION_LIB_SOURCES
gps_fpga_acquisition_8sc.cc
# cpu_multicorrelator.cc
# cpu_multicorrelator_16sc.cc
# lock_detectors.cc
# tcp_communication.cc
# tcp_packet_data.cc
# tracking_2nd_DLL_filter.cc
# tracking_2nd_PLL_filter.cc
# tracking_discriminators.cc
# tracking_FLL_PLL_filter.cc
# tracking_loop_filter.cc
)
#if(ENABLE_FPGA)
# SET(ACQUISITION_LIB_SOURCES ${ACQUISITION_LIB_SOURCES} fpga_acquisition_8sc.cc)
#endif(ENABLE_FPGA)
include_directories(
$(CMAKE_CURRENT_SOURCE_DIR)
${CMAKE_SOURCE_DIR}/src/core/system_parameters
${CMAKE_SOURCE_DIR}/src/core/interfaces
${CMAKE_SOURCE_DIR}/src/core/receiver
${VOLK_INCLUDE_DIRS}
${GLOG_INCLUDE_DIRS}
${GFlags_INCLUDE_DIRS}
${OPT_TRACKING_INCLUDES}
${VOLK_GNSSSDR_INCLUDE_DIRS}
)
if(ENABLE_GENERIC_ARCH)
add_definitions( -DGENERIC_ARCH=1 )
endif(ENABLE_GENERIC_ARCH)
if (SSE3_AVAILABLE)
add_definitions( -DHAVE_SSE3=1 )
endif(SSE3_AVAILABLE)
#file(GLOB TRACKING_LIB_HEADERS "*.h")
file(GLOB ACQUISITION_LIB_HEADERS "*.h")
#list(SORT TRACKING_LIB_HEADERS)
list(SORT ACQUISITION_LIB_HEADERS)
#add_library(tracking_lib ${TRACKING_LIB_SOURCES} ${TRACKING_LIB_HEADERS})
add_library(acquisition_lib ${ACQUISITION_LIB_SOURCES} ${ACQUISITION_LIB_HEADERS})
#source_group(Headers FILES ${TRACKING_LIB_HEADERS})
source_group(Headers FILES ${ACQUISITION_LIB_HEADERS})
#target_link_libraries(tracking_lib ${OPT_TRACKING_LIBRARIES} ${VOLK_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${GNURADIO_RUNTIME_LIBRARIES})
target_link_libraries(acquisition_lib ${OPT_ACQUISITION_LIBRARIES} ${VOLK_LIBRARIES} ${VOLK_GNSSSDR_LIBRARIES} ${GNURADIO_RUNTIME_LIBRARIES})
if(VOLK_GNSSSDR_FOUND)
# add_dependencies(tracking_lib glog-${glog_RELEASE})
add_dependencies(acquisition_lib glog-${glog_RELEASE})
else(VOLK_GNSSSDR_FOUND)
# add_dependencies(tracking_lib glog-${glog_RELEASE} volk_gnsssdr_module)
add_dependencies(acquisition_lib glog-${glog_RELEASE} volk_gnsssdr_module)
endif()

View File

@ -0,0 +1,336 @@
/*!
* \file gps_fpga_acquisition_8sc.cc
* \brief High optimized FPGA vector correlator class
* \authors <ul>
* <li> Marc Majoral, 2017. mmajoral(at)cttc.cat
* </ul>
*
* Class that controls and executes a high optimized vector correlator
* class in the FPGA
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "gps_fpga_acquisition_8sc.h"
#include <cmath>
// FPGA stuff
#include <new>
// libraries used by DMA test code and GIPO test code
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
// libraries used by DMA test code
#include <sys/stat.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
// libraries used by GPIO test code
#include <stdlib.h>
#include <signal.h>
#include <sys/mman.h>
// logging
#include <glog/logging.h>
#include "GPS_L1_CA.h"
#define PAGE_SIZE 0x10000
//#define MAX_LENGTH_DEVICEIO_NAME 50
#define CODE_RESAMPLER_NUM_BITS_PRECISION 20
#define CODE_PHASE_STEP_CHIPS_NUM_NBITS CODE_RESAMPLER_NUM_BITS_PRECISION
#define pwrtwo(x) (1 << (x))
#define MAX_CODE_RESAMPLER_COUNTER pwrtwo(CODE_PHASE_STEP_CHIPS_NUM_NBITS) // 2^CODE_PHASE_STEP_CHIPS_NUM_NBITS
#define PHASE_CARR_NBITS 32
#define PHASE_CARR_NBITS_INT 1
#define PHASE_CARR_NBITS_FRAC PHASE_CARR_NBITS - PHASE_CARR_NBITS_INT
#define MAX_PHASE_STEP_RAD 0.999999999534339 // 1 - pow(2,-31);
bool gps_fpga_acquisition_8sc::init(unsigned int fft_size, unsigned int nsamples_total, long freq, unsigned int doppler_max, unsigned int doppler_step, int num_doppler_bins, long fs_in, unsigned select_queue)
{
float phase_step_rad_fpga;
float phase_step_rad_fpga_real;
d_phase_step_rad_vector = new float[num_doppler_bins];
for (unsigned int doppler_index = 0; doppler_index < num_doppler_bins; doppler_index++)
{
int doppler = -static_cast<int>(doppler_max) + doppler_step * doppler_index;
float phase_step_rad = GPS_TWO_PI * (freq + doppler) / static_cast<float>(fs_in);
// The doppler step can never be outside the range -pi to +pi, otherwise there would be aliasing
// The FPGA expects phase_step_rad between -1 (-pi) to +1 (+pi)
// The FPGA also expects the phase to be negative since it produces cos(x) -j*sin(x)
// while the gnss-sdr software (volk_gnsssdr_s32f_sincos_32fc) generates cos(x) + j*sin(x)
phase_step_rad_fpga = phase_step_rad/(GPS_TWO_PI/2);
// avoid saturation of the fixed point representation in the fpga
// (only the positive value can saturate due to the 2's complement representation)
if (phase_step_rad_fpga == 1.0)
{
phase_step_rad_fpga = MAX_PHASE_STEP_RAD;
}
d_phase_step_rad_vector[doppler_index] = phase_step_rad_fpga;
}
// sanity check : check test register
unsigned writeval = 0x55AA;
unsigned readval;
readval = gps_fpga_acquisition_8sc::fpga_acquisition_test_register(writeval);
if (writeval != readval)
{
printf("test register fail\n");
LOG(WARNING) << "Acquisition test register sanity check failed";
}
else
{
printf("test register success\n");
LOG(INFO) << "Acquisition test register sanity check success !";
}
d_nsamples = fft_size;
d_nsamples_total = nsamples_total;
gps_fpga_acquisition_8sc::configure_acquisition();
return true;
}
bool gps_fpga_acquisition_8sc::set_local_code(gr_complex* fft_codes)
{
int i;
float val;
float max = 0;
d_fft_codes = new lv_16sc_t[d_nsamples_total];
for (i=0;i<d_nsamples_total;i++)
{
if(abs(fft_codes[i].real()) > max)
{
max = abs(fft_codes[i].real());
}
if(abs(fft_codes[i].imag()) > max)
{
max = abs(fft_codes[i].imag());
}
}
for (i=0;i<d_nsamples_total;i++)
{
d_fft_codes[i] = lv_16sc_t((int) (fft_codes[i].real()*(pow(2,7) - 1)/max), (int) (fft_codes[i].imag()*(pow(2,7) - 1)/max));
}
gps_fpga_acquisition_8sc::fpga_configure_acquisition_local_code(d_fft_codes);
return true;
}
gps_fpga_acquisition_8sc::gps_fpga_acquisition_8sc()
{
if ((d_fd = open(d_device_io_name, O_RDWR | O_SYNC )) == -1)
{
LOG(WARNING) << "Cannot open deviceio" << d_device_io_name;
}
d_map_base = (volatile unsigned *)mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, d_fd,0);
if (d_map_base == (void *) -1)
{
LOG(WARNING) << "Cannot map the FPGA acquisition module into user memory";
}
}
gps_fpga_acquisition_8sc::~gps_fpga_acquisition_8sc()
{
if (munmap((void*)d_map_base, PAGE_SIZE) == -1)
{
printf("Failed to unmap memory uio\n");
}
close(d_fd);
}
bool gps_fpga_acquisition_8sc::free()
{
if (d_fft_codes != nullptr)
{
delete [] d_fft_codes;
d_fft_codes = nullptr;
}
if (d_phase_step_rad_vector != nullptr)
{
delete [] d_phase_step_rad_vector;
d_phase_step_rad_vector = nullptr;
}
return true;
}
unsigned gps_fpga_acquisition_8sc::fpga_acquisition_test_register(unsigned writeval)
{
unsigned readval;
// write value to test register
d_map_base[15] = writeval;
// read value from test register
readval = d_map_base[15];
// return read value
return readval;
}
void gps_fpga_acquisition_8sc::fpga_configure_acquisition_local_code(lv_16sc_t fft_local_code[])
{
short int local_code;
unsigned int k, tmp, tmp2;
// clear memory address counter
d_map_base[4] = 0x10000000;
for (k = 0; k < d_nsamples_total; k++)
{
tmp = fft_local_code[k].real();
tmp2 = fft_local_code[k].imag();
local_code = (tmp & 0xFF) | ((tmp2*256) & 0xFF00); // put together the real part and the imaginary part
if (k < 20)
{
printf("tmp tmp2 local_code = %d %d %d\n", tmp, tmp2, local_code);
}
d_map_base[4] = 0x0C000000 | (local_code & 0xFFFF);
}
FILE *f;
f = fopen("captured_local_code_dec.txt", "w");
if (!f)
{
printf("Unable to open file!");
}
for(k=0;k< d_nsamples_total;k++)
{
fprintf(f,"%d\n",fft_local_code[k].real()); // real part
fprintf(f,"%d\n",fft_local_code[k].imag()); // real part
}
fclose(f);
}
void gps_fpga_acquisition_8sc::run_acquisition(void)
{
// enable interrupts
int reenable = 1;
write(d_fd, (void *)&reenable, sizeof(int));
d_map_base[5] = 0; // writing anything to reg 4 launches the acquisition process
int irq_count;
ssize_t nb;
// wait for interrupt
nb=read(d_fd, &irq_count, sizeof(irq_count));
if (nb != sizeof(irq_count))
{
printf("Tracking_module Read failed to retrive 4 bytes!\n");
printf("Tracking_module Interrupt number %d\n", irq_count);
}
}
void gps_fpga_acquisition_8sc::configure_acquisition()
{
d_map_base[0] = d_select_queue;
d_map_base[1] = d_nsamples_total;
d_map_base[2] = d_nsamples;
printf("nsamples = %d\n", d_nsamples);
printf("nsamples_total = %d\n", d_nsamples_total);
printf("d_select_queue = %d\n", d_select_queue);
}
void gps_fpga_acquisition_8sc::set_phase_step(unsigned int doppler_index)
{
float phase_step_rad_real;
float phase_step_rad_int_temp;
int32_t phase_step_rad_int;
phase_step_rad_real = d_phase_step_rad_vector[doppler_index];
phase_step_rad_int_temp = phase_step_rad_real*4; // * 2^2
phase_step_rad_int = (int32_t) (phase_step_rad_int_temp*(536870912)); // * 2^29 (in total it makes x2^31 in two steps to avoid the warnings
d_map_base[3] = phase_step_rad_int;
}
void gps_fpga_acquisition_8sc::read_acquisition_results(uint32_t* max_index, float* max_magnitude, unsigned *initial_sample, float *power_sum)
{
unsigned readval = 0;
readval = d_map_base[0];
printf("RESULT : result valid = %d\n", readval);
readval = d_map_base[1];
*initial_sample = readval;
printf("RESULT : initial sample = %d\n", *initial_sample);
readval = d_map_base[2];
*max_magnitude = (float) readval;
printf("RESULT : max_magnitude = %f\n", *max_magnitude);
readval = d_map_base[4];
*power_sum = (float) readval;
printf("RESULT : power sum = %f\n", *power_sum);
readval = d_map_base[3];
*max_index = readval;
printf("RESULT : max_index = %d\n", *max_index); // to avoid result_read line to stay high
}
void gps_fpga_acquisition_8sc::block_samples()
{
d_map_base[14] = 1; // block the samples
}
void gps_fpga_acquisition_8sc::unblock_samples()
{
d_map_base[14] = 0; // unblock the samples
}

View File

@ -0,0 +1,108 @@
/*!
* \file fpga_acquisition_8sc.h
* \brief High optimized FPGA vector correlator class for lv_16sc_t (short int complex)
* \authors <ul>
* <li> Marc Majoral, 2017. mmajoral(at)cttc.cat
* <li> Javier Arribas, 2016. jarribas(at)cttc.es
* </ul>
*
* Class that controls and executes a high optimized vector correlator
* class in the FPGA
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_FPGA_ACQUISITION_8SC_H_
#define GNSS_SDR_FPGA_ACQUISITION_8SC_H_
#include <volk_gnsssdr/volk_gnsssdr.h>
#include <gnuradio/block.h>
/*!
* \brief Class that implements carrier wipe-off and correlators.
*/
class gps_fpga_acquisition_8sc
{
public:
gps_fpga_acquisition_8sc();
~gps_fpga_acquisition_8sc();
//bool init(int max_signal_length_samples, int n_correlators);
bool init(unsigned int fft_size, unsigned int nsamples_total, long d_freq, unsigned int doppler_max, unsigned int doppler_step, int num_doppler_bins, long fs_in, unsigned select_queue);
bool set_local_code(gr_complex* fft_codes); //int code_length_chips, const lv_16sc_t* local_code_in, float *shifts_chips);
bool free();
void run_acquisition(void);
void set_phase_step(unsigned int doppler_index);
void read_acquisition_results(uint32_t* max_index, float* max_magnitude, unsigned *initial_sample, float *power_sum);
void block_samples();
void unblock_samples();
private:
const lv_16sc_t *d_local_code_in;
lv_16sc_t *d_corr_out;
float *d_shifts_chips;
int d_code_length_chips;
int d_n_correlators;
// data related to the hardware module and the driver
char d_device_io_name[11] = "/dev/uio13"; // driver io name
int d_fd; // driver descriptor
volatile unsigned *d_map_base; // driver memory map
// configuration data received from the interface
lv_16sc_t *d_fft_codes = nullptr;
float *d_phase_step_rad_vector = nullptr;
unsigned int d_nsamples_total; // total number of samples in the fft including padding
unsigned int d_nsamples; // number of samples not including padding
unsigned int d_select_queue =0; // queue selection
// unsigned int d_channel; // channel number
// unsigned d_ncorrelators; // number of correlators
// unsigned d_correlator_length_samples;
// float d_rem_code_phase_chips;
// float d_code_phase_step_chips;
// float d_rem_carrier_phase_in_rad;
// float d_phase_step_rad;
// configuration data computed in the format that the FPGA expects
// unsigned *d_initial_index;
// unsigned *d_initial_interp_counter;
// unsigned d_code_phase_step_chips_num;
// int d_rem_carr_phase_rad_int;
// int d_phase_step_rad_int;
// unsigned d_initial_sample_counter;
// FPGA private functions
unsigned fpga_acquisition_test_register(unsigned writeval);
void fpga_configure_acquisition_local_code(lv_16sc_t fft_local_code[]);
void configure_acquisition();
//void fpga_acquisition_8sc::run_acquisition(void);
};
#endif /* GNSS_SDR_FPGA_MULTICORRELATOR_H_ */

View File

@ -0,0 +1,392 @@
/*!
* \file gps_l1_ca_pcps_acquisition_test_fpga.cc
* \brief This class implements an acquisition test for
* GpsL1CaPcpsAcquisitionFpga class based on some input parameters.
* \author Marc Majoral, 2017. mmajoral(at)cttc.cat
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include <cstdlib>
#include <iostream>
#include <boost/make_shared.hpp>
#include <boost/thread.hpp>
#include <boost/chrono.hpp>
//#include <stdio.h>
#include <gnuradio/top_block.h>
#include <gnuradio/blocks/file_source.h>
#include <gnuradio/analog/sig_source_waveform.h>
#include <gnuradio/analog/sig_source_c.h>
#include <gnuradio/msg_queue.h>
#include <gnuradio/blocks/null_sink.h>
#include <gnuradio/blocks/throttle.h>
#include <gtest/gtest.h>
#include "gnss_block_factory.h"
#include "gnss_block_interface.h"
#include "in_memory_configuration.h"
#include "gnss_sdr_valve.h"
#include "gnss_synchro.h"
#include "gps_l1_ca_pcps_acquisition_fpga.h"
#include <unistd.h>
#define DMA_ACQ_TRANSFER_SIZE 4000
#define RX_SIGNAL_MAX_VALUE 127 // 2^7 - 1 for 8-bit signed values
#define NTIMES_CYCLE_THROUGH_RX_SAMPLES_FILE 50 // number of times we cycle through the file containing the received samples
#define ONE_SECOND 1000000 // one second in microseconds
#define FLOAT_SIZE (sizeof(float)) // size of the float variable in characters
// thread that reads the file containing the received samples, scales the samples to the dynamic range of the fixed point values, sends
// the samples to the DMA and finally it stops the top block
void thread_acquisition_send_rx_samples(gr::top_block_sptr top_block, const char * file_name)
{
FILE *ptr_myfile; // file descriptor
int fileLen; // length of the file containing the received samples
int tx_fd; // DMA descriptor
// sleep for 1 second to give some time to GNSS-SDR to activate the acquisition module.
// the acquisition module does not block the RX buffer before activation.
// If this process starts sending samples straight ahead without waiting it could occur that
// the first samples are lost. This is normal behaviour in a real receiver but this is not what
// we want for the test
usleep(ONE_SECOND);
char *buffer_temp; // temporary buffer to convert from binary char to float and from float to char
signed char *buffer_char; // temporary buffer to store the samples to be sent to the DMA
buffer_temp = (char *)malloc(FLOAT_SIZE); // allocate space for the temporary buffer
if (!buffer_temp)
{
fprintf(stderr, "Memory error!");
}
ptr_myfile = fopen(file_name,"rb"); // file containing the received signal
if (!ptr_myfile)
{
printf("Unable to open file!");
}
// determine the length of the file that contains the received signal
fseek(ptr_myfile, 0, SEEK_END);
fileLen = ftell(ptr_myfile);
fseek(ptr_myfile, 0, SEEK_SET);
// first step: check for the maximum value of the received signal
float max = 0;
float *pointer_float;
pointer_float = (float *) &buffer_temp[0];
for (int k=0;k<fileLen;k=k+FLOAT_SIZE)
{
fread(buffer_temp, FLOAT_SIZE, 1, ptr_myfile);
if (fabs(pointer_float[0]) > max)
{
max = (pointer_float[0]);
}
}
// go back to the beginning of the file containing the received samples
fseek(ptr_myfile, 0, SEEK_SET);
// allocate memory for the samples to be transferred to the DMA
buffer_char = (signed char *)malloc(DMA_ACQ_TRANSFER_SIZE);
if (!buffer_char)
{
fprintf(stderr, "Memory error!");
}
// open the DMA descriptor
tx_fd = open("/dev/loop_tx", O_WRONLY);
if ( tx_fd < 0 )
{
printf("can't open loop device\n");
exit(1);
}
// cycle through the file containing the received samples
for (int k=0;k<NTIMES_CYCLE_THROUGH_RX_SAMPLES_FILE;k++)
{
fseek(ptr_myfile, 0, SEEK_SET);
int transfer_size;
int num_transferred_samples = 0;
while (num_transferred_samples< fileLen/FLOAT_SIZE)
{
if (((fileLen/FLOAT_SIZE) - num_transferred_samples) > DMA_ACQ_TRANSFER_SIZE)
{
transfer_size = DMA_ACQ_TRANSFER_SIZE;
num_transferred_samples = num_transferred_samples + DMA_ACQ_TRANSFER_SIZE;
}
else
{
transfer_size = fileLen/FLOAT_SIZE - num_transferred_samples;
num_transferred_samples = fileLen/FLOAT_SIZE;
}
for (int t=0;t<transfer_size;t++)
{
fread(buffer_temp, FLOAT_SIZE, 1, ptr_myfile);
// specify (float) (int) for a quantization maximizing the dynamic range
buffer_char[t] = (signed char) ((pointer_float[0]*(RX_SIGNAL_MAX_VALUE - 1))/max);
}
//send_acquisition_gps_input_samples(buffer_char, transfer_size, tx_fd);
assert( transfer_size == write(tx_fd, &buffer_char[0], transfer_size) );
}
}
fclose(ptr_myfile);
free(buffer_temp);
free(buffer_char);
close(tx_fd);
// when all the samples are sent stop the top block
top_block->stop();
}
// ######## GNURADIO BLOCK MESSAGE RECEVER #########
class GpsL1CaPcpsAcquisitionTestFpga_msg_rx;
typedef boost::shared_ptr<GpsL1CaPcpsAcquisitionTestFpga_msg_rx> GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr;
GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make();
class GpsL1CaPcpsAcquisitionTestFpga_msg_rx : public gr::block
{
private:
friend GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make();
void msg_handler_events(pmt::pmt_t msg);
GpsL1CaPcpsAcquisitionTestFpga_msg_rx();
public:
int rx_message;
~GpsL1CaPcpsAcquisitionTestFpga_msg_rx(); //!< Default destructor
};
GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make()
{
return GpsL1CaPcpsAcquisitionTest_msg_fpga_rx_sptr(new GpsL1CaPcpsAcquisitionTestFpga_msg_rx());
}
void GpsL1CaPcpsAcquisitionTestFpga_msg_rx::msg_handler_events(pmt::pmt_t msg)
{
try
{
long int message = pmt::to_long(msg);
rx_message = message;
}
catch(boost::bad_any_cast& e)
{
LOG(WARNING) << "msg_handler_telemetry Bad any cast!";
rx_message = 0;
}
}
GpsL1CaPcpsAcquisitionTestFpga_msg_rx::GpsL1CaPcpsAcquisitionTestFpga_msg_rx() :
gr::block("GpsL1CaPcpsAcquisitionTestFpga_msg_rx", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0))
{
this->message_port_register_in(pmt::mp("events"));
this->set_msg_handler(pmt::mp("events"), boost::bind(&GpsL1CaPcpsAcquisitionTestFpga_msg_rx::msg_handler_events, this, _1));
rx_message = 0;
}
GpsL1CaPcpsAcquisitionTestFpga_msg_rx::~GpsL1CaPcpsAcquisitionTestFpga_msg_rx()
{}
// ###########################################################
class GpsL1CaPcpsAcquisitionTestFpga: public ::testing::Test
{
protected:
GpsL1CaPcpsAcquisitionTestFpga()
{
factory = std::make_shared<GNSSBlockFactory>();
config = std::make_shared<InMemoryConfiguration>();
item_size = sizeof(gr_complex);
gnss_synchro = Gnss_Synchro();
}
~GpsL1CaPcpsAcquisitionTestFpga()
{}
void init();
gr::top_block_sptr top_block;
std::shared_ptr<GNSSBlockFactory> factory;
std::shared_ptr<InMemoryConfiguration> config;
Gnss_Synchro gnss_synchro;
size_t item_size;
};
void GpsL1CaPcpsAcquisitionTestFpga::init()
{
gnss_synchro.Channel_ID = 0;
gnss_synchro.System = 'G';
std::string signal = "1C";
signal.copy(gnss_synchro.Signal, 2, 0);
gnss_synchro.PRN = 1;
config->set_property("GNSS-SDR.internal_fs_hz", "4000000");
//config->set_property("Acquisition.item_type", "gr_complex");
config->set_property("Acquisition.item_type", "cshort");
config->set_property("Acquisition.if", "0");
config->set_property("Acquisition.coherent_integration_time_ms", "1");
config->set_property("Acquisition.dump", "false");
config->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Acquisition");
config->set_property("Acquisition.threshold", "0.001");
config->set_property("Acquisition.doppler_max", "5000");
config->set_property("Acquisition.doppler_step", "500");
config->set_property("Acquisition.repeat_satellite", "false");
config->set_property("Acquisition.pfa", "0.0");
}
TEST_F(GpsL1CaPcpsAcquisitionTestFpga, Instantiate)
{
init();
boost::shared_ptr<GpsL1CaPcpsAcquisitionFpga> acquisition = boost::make_shared<GpsL1CaPcpsAcquisitionFpga>(config.get(), "Acquisition", 0, 1);
}
TEST_F(GpsL1CaPcpsAcquisitionTestFpga, ValidationOfResults)
{
struct timeval tv;
long long int begin = 0;
long long int end = 0;
top_block = gr::make_top_block("Acquisition test");
double expected_delay_samples = 524;
double expected_doppler_hz = 1680;
init();
std::shared_ptr<GpsL1CaPcpsAcquisitionFpga> acquisition = std::make_shared<GpsL1CaPcpsAcquisitionFpga>(config.get(), "Acquisition", 0, 1);
boost::shared_ptr<GpsL1CaPcpsAcquisitionTestFpga_msg_rx> msg_rx = GpsL1CaPcpsAcquisitionTestFpga_msg_rx_make();
ASSERT_NO_THROW( {
acquisition->set_channel(1);
}) << "Failure setting channel." << std::endl;
ASSERT_NO_THROW( {
acquisition->set_gnss_synchro(&gnss_synchro);
}) << "Failure setting gnss_synchro." << std::endl;
ASSERT_NO_THROW( {
acquisition->set_threshold(0.1);
}) << "Failure setting threshold." << std::endl;
ASSERT_NO_THROW( {
acquisition->set_doppler_max(10000);
}) << "Failure setting doppler_max." << std::endl;
ASSERT_NO_THROW( {
acquisition->set_doppler_step(250);
}) << "Failure setting doppler_step." << std::endl;
ASSERT_NO_THROW( {
acquisition->connect(top_block);
}) << "Failure connecting acquisition to the top_block." << std::endl;
std::string file = "./GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
const char * file_name = file.c_str();
ASSERT_NO_THROW( {
//std::string path = std::string(TEST_PATH);
//std::string file = path + "signal_samples/GSoC_CTTC_capture_2012_07_26_4Msps_4ms.dat";
//std::string file = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
// for the unit test use dummy blocks to make the flowgraph work and allow the acquisition message to be sent.
// in the actual system there is a flowchart running in parallel so this is not needed
gr::blocks::file_source::sptr file_source = gr::blocks::file_source::make(sizeof(gr_complex), file_name, false);
gr::blocks::null_sink::sptr null_sink = gr::blocks::null_sink::make(sizeof(gr_complex));
gr::blocks::throttle::sptr throttle_block = gr::blocks::throttle::make(sizeof(gr_complex),1000);
top_block->connect(file_source, 0, throttle_block, 0);
top_block->connect(throttle_block, 0, null_sink, 0);
top_block->msg_connect(acquisition->get_right_block(), pmt::mp("events"), msg_rx, pmt::mp("events"));
}) << "Failure connecting the blocks of acquisition test." << std::endl;
acquisition->set_state(1); // Ensure that acquisition starts at the first state
acquisition->init();
top_block->start(); // Start the top block
// start thread that sends the DMA samples to the FPGA
boost::thread t3{thread_acquisition_send_rx_samples, top_block, file_name};
EXPECT_NO_THROW( {
gettimeofday(&tv, NULL);
begin = tv.tv_sec * 1000000 + tv.tv_usec;
acquisition->reset(); // launch the tracking process
top_block->wait();
gettimeofday(&tv, NULL);
end = tv.tv_sec * 1000000 + tv.tv_usec;
}) << "Failure running the top_block." << std::endl;
t3.join();
unsigned long int nsamples = gnss_synchro.Acq_samplestamp_samples;
std::cout << "Acquired " << nsamples << " samples in " << (end - begin) << " microseconds" << std::endl;
ASSERT_EQ(1, msg_rx->rx_message) << "Acquisition failure. Expected message: 1=ACQ SUCCESS.";
double delay_error_samples = std::abs(expected_delay_samples - gnss_synchro.Acq_delay_samples);
float delay_error_chips = (float)(delay_error_samples * 1023 / 4000);
double doppler_error_hz = std::abs(expected_doppler_hz - gnss_synchro.Acq_doppler_hz);
EXPECT_LE(doppler_error_hz, 666) << "Doppler error exceeds the expected value: 666 Hz = 2/(3*integration period)";
EXPECT_LT(delay_error_chips, 0.5) << "Delay error exceeds the expected value: 0.5 chips";
}