GNSS-SDR  0.0.20
An Open Source GNSS Software Defined Receiver
fpga_acquisition.h
Go to the documentation of this file.
1 /*!
2  * \file fpga_acquisition.h
3  * \brief Highly optimized FPGA vector correlator class
4  * \authors <ul>
5  * <li> Marc Majoral, 2019. mmajoral(at)cttc.cat
6  * </ul>
7  *
8  * Class that controls and executes a highly optimized acquisition HW
9  * accelerator in the FPGA
10  *
11  * -----------------------------------------------------------------------------
12  *
13  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
14  * This file is part of GNSS-SDR.
15  *
16  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
17  * SPDX-License-Identifier: GPL-3.0-or-later
18  *
19  * -----------------------------------------------------------------------------
20  */
21 
22 #ifndef GNSS_SDR_FPGA_ACQUISITION_H
23 #define GNSS_SDR_FPGA_ACQUISITION_H
24 
25 #include <cstdint>
26 #include <string>
27 #include <utility> // for std::move, std::pair
28 #include <vector> // for std::vector
29 
30 /** \addtogroup Acquisition
31  * \{ */
32 /** \addtogroup acquisition_libs
33  * \{ */
34 
35 
36 /*!
37  * \brief Class that implements carrier wipe-off and correlators.
38  */
40 {
41 public:
42  /*!
43  * \brief Constructor
44  */
46  std::string device_name,
47  uint32_t select_queue,
48  std::vector<std::pair<uint32_t, uint32_t>> &downsampling_filter_specs,
49  uint32_t &max_FFT_size);
50 
51  /*!
52  * \brief Destructor
53  */
54  ~Fpga_Acquisition() = default;
55 
56  /*!
57  * \brief Initialize acquisition parameters
58  */
59  // void init(uint32_t samples_per_code, uint32_t code_length, int64_t resampled_fs, uint32_t *all_fft_codes);
60  void init(uint32_t nsamples, uint32_t doppler_max, uint32_t d_fft_size,
61  int64_t resampled_fs, uint32_t downsampling_filter_num, uint32_t excludelimit, uint32_t *all_fft_codes);
62 
63  /*!
64  * \brief Select the code with the chosen PRN
65  */
66  bool set_local_code(uint32_t PRN);
67 
68  /*!
69  * \brief Configure the doppler sweep parameters in the FPGA
70  */
71  void set_doppler_sweep(uint32_t num_sweeps, uint32_t doppler_step, int32_t doppler_min);
72 
73  /*!
74  * \brief Run the acquisition process in the FPGA
75  */
76  void run_acquisition();
77 
78  /*!
79  * \brief Read the results of the acquisition process
80  */
82  uint32_t *max_index,
83  float *firstpeak,
84  float *secondpeak,
85  uint64_t *initial_sample,
86  float *power_sum,
87  uint32_t *doppler_index,
88  uint32_t *total_blk_exp);
89 
90  /*!
91  * \brief Set maximum Doppler grid search
92  * \param doppler_max - Maximum Doppler shift considered in the grid search [Hz].
93  */
94  void set_doppler_max(uint32_t doppler_max)
95  {
96  d_doppler_max = doppler_max;
97  }
98 
99  /*!
100  * \brief Set Doppler steps for the grid search
101  * \param doppler_step - Frequency bin of the search grid [Hz].
102  */
103  void set_doppler_step(uint32_t doppler_step)
104  {
105  d_doppler_step = doppler_step;
106  }
107 
108  /*!
109  * \brief Reset the FPGA PL.
110  */
111  void reset_acquisition();
112 
113  /*!
114  * \brief stop the acquisition and the FPGA modules.
115  */
116  void stop_acquisition();
117 
118  /*!
119  * \brief Set the block exponent of the FFT in the FPGA.
120  */
121  void set_block_exp(uint32_t total_block_exp);
122 
123  /*!
124  * \brief Write the PRN code in the FPGA
125  */
126  void write_local_code(void);
127 
128  /*!
129  * \brief Write the acquisition parameters into the FPGA
130  */
131  void configure_acquisition(void);
132 
133  /*!
134  * \brief Open the device driver
135  */
136  void open_device();
137 
138  /*!
139  * \brief Close the device driver
140  */
141  void close_device();
142 
143 private:
144  // FPGA IP Core version
145  static const uint32_t FPGA_ACQ_IP_VERSION_1 = 0x0001; // FPGA IP core version
146 
147  // FPGA register addresses
148 
149  // write-only registers
150  static const uint32_t FREQ_BAND_DOWNSAMPLE_REG_ADDR = 0; // Select frequency band and downsampling filter
151  static const uint32_t FFT_LENGTH_REG_ADDR = 1; // Length of the FFT
152  static const uint32_t CORR_NSAMPLES_REG_ADDR = 2; // Correlation length
153  static const uint32_t DOPPLER_MIN_REG_ADDR = 3; // Doppler min
154  static const uint32_t DOPPLER_STEP_REG_ADDR = 4; // Doppler step
155  static const uint32_t NUM_DOPPLER_SEARCH_STEPS_REG_ADDR = 5; // Number of Doppler search steps
156  static const uint32_t PROG_MEM_ADDR = 6; // Access to the memory storing the PRN code of the target satellite.
157  static const uint32_t LOG2_FFT_LENGTH_REG_ADDR = 7; // Log2(FFT_LENGTH)
158  static const uint32_t ACQ_COMMAND_FLAGS_REG_ADDR = 8; // Flags that reset, start, and stop the acquisition process.
159  static const uint32_t CLEAR_MEM_REG_ADDR = 9; // Flag that resets the write address of the PRN code memory.
160  static const uint32_t MAX_FFT_SCALING_FACTOR_REG_ADDR = 11; // Reference FFT scaling factor
161  static const uint32_t EXCL_LIM_REG_ADDR = 12; // Exclude Limit value for the second FFT peak search process
162 
163  // read-write registers
164  static const uint32_t TEST_REG_ADDR = 15;
165 
166  // read-only registers
167  static const uint32_t RESULT_VALID_REG_ADDR = 0; // Flag that indicates a valid result
168  static const uint32_t SAMPLESTAMP_LSW_REG_ADDR = 1; // Sample stamp LSW
169  static const uint32_t SAMPLESTAMP_MSW_REG_ADDR = 2; // Sample stamp MSW
170  static const uint32_t MAG_SQ_FIRST_PEAK_REG_ADDR = 3; // magnitude squared of the first peak
171  static const uint32_t MAG_SQ_SECOND_PEAK_REG_ADDR = 4; // magnitude squared of the second peak
172  static const uint32_t ACQ_DELAY_SAMPLES_REG_ADDR = 5; // acquisition delay in samples
173  static const uint32_t DOPPLER_INDEX_REG_ADDR = 7; // Doppler index
174  static const uint32_t FFT_SCALING_FACTOR_REG_ADDR = 8; // Scaling factor applied by the FFT
175  static const uint32_t MAX_FFT_SIZE_REG_ADDR = 9; // Maximum FFT size supported by the FPGA
176  static const uint32_t DOWNSAMPLING_FILTER_DEC_FACTORS_REG_ADDR = 10; // Available decimation factors
177  static const uint32_t DOWNSAMPLING_FILTER_LATENCIES_REG_ADDR = 11; // Available downsampling filter latencies
178  static const uint32_t FPGA_IP_CORE_VERSION_REG_ADDR = 14; // FPGA acquisition IP core version
179 
180  // FPGA register parameters
181  static const uint32_t FPGA_PAGE_SIZE = 0x1000; // default page size for the multicorrelator memory map
182  static const uint32_t LAUNCH_ACQUISITION = 1; // command to launch the acquisition process
183  static const uint32_t RESET_ACQUISITION = 2; // command to reset the acquisition and the FPGA Modules
184  static const uint32_t STOP_ACQUISITION = 4; // command to stop the acquisition and the FPGA modules
185  static const uint32_t TEST_REG_SANITY_CHECK = 0x55AA; // value to check the presence of the test register (to detect the hw)
186  static const uint32_t LOCAL_CODE_CLEAR_MEM = 0x10000000; // command to clear the internal memory of the multicorrelator
187  static const uint32_t MEM_LOCAL_CODE_WR_ENABLE = 0x0C000000; // command to enable the ENA and WR pins of the internal memory of the multicorrelator
188  static const uint32_t POW_2_2 = 4; // 2^2 (used for the conversion of floating point numbers to integers)
189  static const uint32_t POW_2_31 = 2147483648; // 2^31 (used for the conversion of floating point numbers to integers)
190  static const uint32_t MAX_FILTERS_AVAILABLE = 2; // maximum number of downsampling filters available in the FPGA by default
191  static const uint32_t DEFAULT_MAX_FFT_SIZE = 32768; // default maximum FFT size supported by the FPGA
192  static const uint32_t ACQ_BUFF_0 = 0; // FPGA Acquisition IP buffer containing L1/E1 frequency band samples by default.
193  static const uint32_t ACQ_BUFF_1 = 0; // FPGA Acquisition IP buffer containing L2 or L5/E5a frequency band samples by default.
194 
195  // bit manipulation
196  static const uint32_t RSHIFT_4_BITS = 0x4;
197  static const uint32_t RSHIFT_8_BITS = 0x8;
198  static const uint32_t BIT_MASK_4 = 0xF;
199  static const uint32_t BIT_MASK_8 = 0xFF;
200 
201  // Downsampling default constants
202  const uint32_t DEFAULT_DOWNSAMPLING_FILTER_DELAY = 40; // default downsampling filter delay (for FPGA Acquisition IP core versions earlier than FPGA_ACQ_IP_VERSION_1)
203  const uint32_t DEFAULT_DOWNSAMPLING_FACTOR = 4; // default downsampling factor (for FPGA Acquisition IP core versions earlier than FPGA_ACQ_IP_VERSION_1)
204 
205  // private methods
206  void fpga_acquisition_test_register(void);
207  void read_ipcore_info(std::vector<std::pair<uint32_t, uint32_t>> &downsampling_filter_specs, uint32_t &max_FFT_size);
208 
209  std::vector<std::pair<uint32_t, uint32_t>> d_downsampling_filter_specs;
210  std::string d_device_name; // HW device name
211  int64_t d_resampled_fs; // sampling frequency
212  volatile uint32_t *d_map_base; // driver memory map
213  uint32_t *d_all_fft_codes; // memory that contains all the code ffts
214  int32_t d_fd; // driver descriptor
215  uint32_t d_fft_size; // number of samples including padding
216  uint32_t d_excludelimit;
217  uint32_t d_nsamples; // number of samples not including padding
218  uint32_t d_filter_num; // Selected downsampling filter
219  uint32_t d_downsampling_factor; // downsampling_factor
220  uint32_t d_downsampling_filter_delay; // Impulse response delay of the downsampling filter
221  uint32_t d_select_queue; // queue selection
222  uint32_t d_doppler_max; // max doppler
223  uint32_t d_doppler_step; // doppler step
224  uint32_t d_PRN; // PRN
225  uint32_t d_IP_core_version; // FPGA acquisition IP core version
226 };
227 
228 
229 /** \} */
230 /** \} */
231 #endif // GNSS_SDR_FPGA_ACQUISITION_H
void set_doppler_step(uint32_t doppler_step)
Set Doppler steps for the grid search.
void close_device()
Close the device driver.
Class that implements carrier wipe-off and correlators.
~Fpga_Acquisition()=default
Destructor.
void reset_acquisition()
Reset the FPGA PL.
void set_block_exp(uint32_t total_block_exp)
Set the block exponent of the FFT in the FPGA.
Fpga_Acquisition(std::string device_name, uint32_t select_queue, std::vector< std::pair< uint32_t, uint32_t >> &downsampling_filter_specs, uint32_t &max_FFT_size)
Constructor.
void stop_acquisition()
stop the acquisition and the FPGA modules.
void open_device()
Open the device driver.
void init(uint32_t nsamples, uint32_t doppler_max, uint32_t d_fft_size, int64_t resampled_fs, uint32_t downsampling_filter_num, uint32_t excludelimit, uint32_t *all_fft_codes)
Initialize acquisition parameters.
bool set_local_code(uint32_t PRN)
Select the code with the chosen PRN.
void run_acquisition()
Run the acquisition process in the FPGA.
void read_acquisition_results(uint32_t *max_index, float *firstpeak, float *secondpeak, uint64_t *initial_sample, float *power_sum, uint32_t *doppler_index, uint32_t *total_blk_exp)
Read the results of the acquisition process.
void configure_acquisition(void)
Write the acquisition parameters into the FPGA.
void set_doppler_sweep(uint32_t num_sweeps, uint32_t doppler_step, int32_t doppler_min)
Configure the doppler sweep parameters in the FPGA.
void set_doppler_max(uint32_t doppler_max)
Set maximum Doppler grid search.
void write_local_code(void)
Write the PRN code in the FPGA.