GNSS-SDR  0.0.13
An Open Source GNSS Software Defined Receiver
fpga_multicorrelator.h
Go to the documentation of this file.
1 /*!
2  * \file fpga_multicorrelator.h
3  * \brief FPGA vector correlator class
4  * \authors <ul>
5  * <li> Marc Majoral, 2019. mmajoral(at)cttc.cat
6  * <li> Javier Arribas, 2019. jarribas(at)cttc.es
7  * </ul>
8  *
9  * Class that controls and executes a highly optimized vector correlator
10  * class in the FPGA
11  *
12  * -----------------------------------------------------------------------------
13  *
14  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
15  *
16  * GNSS-SDR is a software defined Global Navigation
17  * Satellite Systems receiver
18  *
19  * This file is part of GNSS-SDR.
20  *
21  * SPDX-License-Identifier: GPL-3.0-or-later
22  *
23  * -----------------------------------------------------------------------------
24  */
25 
26 #ifndef GNSS_SDR_FPGA_MULTICORRELATOR_H
27 #define GNSS_SDR_FPGA_MULTICORRELATOR_H
28 
29 #include <gnuradio/block.h>
30 #include <volk_gnsssdr/volk_gnsssdr_alloc.h>
31 #include <cstdint>
32 #include <string>
33 
34 
35 /*!
36  * \brief Class that implements carrier wipe-off and correlators.
37  */
39 {
40 public:
41  /*!
42  * \brief Constructor
43  */
44  Fpga_Multicorrelator_8sc(int32_t n_correlators,
45  const std::string &device_name,
46  uint32_t dev_file_num,
47  uint32_t num_prev_assigned_ch,
48  int32_t *ca_codes,
49  int32_t *data_codes,
50  uint32_t code_length_chips,
51  bool track_pilot,
52  uint32_t code_samples_per_chip);
53 
54  /*!
55  * \brief Destructor
56  */
58 
59  /*!
60  * \brief Configure pointers to the FPGA multicorrelator results
61  */
62  void set_output_vectors(gr_complex *corr_out, gr_complex *Prompt_Data);
63 
64  /*!
65  * \brief Configure the local code in the FPGA multicorrelator
66  */
68  float *shifts_chips, float *prompt_data_shift, int32_t PRN);
69 
70  /*!
71  * \brief Configure code phase and code rate parameters in the FPGA
72  */
73  void update_local_code();
74 
75  /*!
76  * \brief Perform a multicorrelation
77  */
79  float rem_carrier_phase_in_rad,
80  float phase_step_rad,
81  float carrier_phase_rate_step_rad,
82  float rem_code_phase_chips,
83  float code_phase_step_chips,
84  float code_phase_rate_step_chips,
85  int32_t signal_length_samples);
86 
87  /*!
88  * \brief Stop the correlation process in the FPGA and free code phase and code rate parameters
89  */
90  bool free();
91 
92  /*!
93  * \brief Set channel number and open the FPGA device driver
94  */
95  void set_channel(uint32_t channel);
96 
97  /*!
98  * \brief Set the initial sample number where the tracking process begins
99  */
100  void set_initial_sample(uint64_t samples_offset);
101 
102  /*!
103  * \brief Read the sample counter in the FPGA
104  */
105  uint64_t read_sample_counter();
106 
107  /*!
108  * \brief Start the tracking process in the FPGA
109  */
110  void lock_channel();
111 
112  /*!
113  * \brief finish the tracking process in the FPGA
114  */
115  void unlock_channel();
116 
117  /*!
118  * \brief Set the secondary code length in the FPGA. This is only used when extended coherent integration
119  * is enabled in the FPGA. If tracking the pilot is enabled then secondary_code_0_length is the length of the pilot
120  * secondary code and secondary_code_1_length is the length of the data secondary code. If tracking the pilot is disabled
121  * then secondary_code_0_length is the length of the data secondary code, and secondary_code_1_length must be set to zero.
122  */
123  void set_secondary_code_lengths(uint32_t secondary_code_0_length, uint32_t secondary_code_1_length);
124 
125  /*!
126  * \brief Initialize the secondary code in the FPGA. If tracking the pilot is enabled then the pilot secondary code is
127  * configured when secondary_code = 0 and the data secondary code is configured when secondary_code = 1. If tracking the
128  * pilot is disabled then the data secondary code is configured when secondary code = 0.
129  */
130  void initialize_secondary_code(uint32_t secondary_code, std::string *secondary_code_string);
131 
132  /*!
133  * \brief Set the PRN length in the FPGA in number of samples. This function is only used then extended coherent integration is enabled in the
134  * FPGA. The FPGA allows for the configuration of two PRN lengths. When the length of the extended coherent integration is bigger than the
135  * length of the PRN code, the FPGA uses the first_length_secondary_code as the length of the PRN code immediately following the beginning
136  * of the extended coherent integration, and the next_length_secondary_code as the length of the remaining PRN codes.
137  * The purpose of this is to have the option to allow the FPGA to compensate for a possible deviation between the nominal value of the PRN
138  * code length and the measured PRN code length in the PRN immediately following the start of the coherent integration only.
139  * If this option is not used then write the same value to first_length_secondary_code and next_length_secondary_code.
140  */
141  void update_prn_code_length(uint32_t first_prn_length, uint32_t next_prn_length);
142 
143  /*!
144  * \brief Enable the use of secondary codes in the FPGA
145  */
146  void enable_secondary_codes();
147 
148  /*!
149  * \brief Disable the use of secondary codes in the FPGA
150  */
152 
153 private:
154  // FPGA register addresses
155  // write addresses
156  static const uint32_t code_phase_step_chips_num_reg_addr = 0;
157  static const uint32_t initial_index_reg_base_addr = 1;
158  static const uint32_t initial_interp_counter_reg_base_addr = 7;
159  static const uint32_t nsamples_minus_1_reg_addr = 13;
160  static const uint32_t code_length_minus_1_reg_addr = 14;
161  static const uint32_t rem_carr_phase_rad_reg_addr = 15;
162  static const uint32_t phase_step_rad_reg_addr = 16;
163  static const uint32_t prog_mems_addr = 17;
164  static const uint32_t drop_samples_reg_addr = 18;
165  static const uint32_t initial_counter_value_reg_addr_lsw = 19;
166  static const uint32_t initial_counter_value_reg_addr_msw = 20;
167  static const uint32_t code_phase_step_chips_rate_reg_addr = 21;
168  static const uint32_t phase_step_rate_reg_addr = 22;
169  static const uint32_t stop_tracking_reg_addr = 23;
170  static const uint32_t secondary_code_lengths_reg_addr = 25;
171  static const uint32_t prog_secondary_code_0_data_reg_addr = 26;
172  static const uint32_t prog_secondary_code_1_data_reg_addr = 27;
173  static const uint32_t first_prn_length_minus_1_reg_addr = 28;
174  static const uint32_t next_prn_length_minus_1_reg_addr = 29;
175  static const uint32_t start_flag_addr = 30;
176  // read-write addresses
177  static const uint32_t test_reg_addr = 31;
178  // read addresses
179  static const uint32_t result_reg_real_base_addr = 1;
180  static const uint32_t result_reg_imag_base_addr = 7;
181  static const uint32_t sample_counter_reg_addr_lsw = 13;
182  static const uint32_t sample_counter_reg_addr_msw = 14;
183  // FPGA-related constants
184  static const uint32_t secondary_code_word_size = 20; // the secondary codes are written in to the FPGA in words of secondary_code_word_size bits
185  static const uint32_t secondary_code_wr_strobe = 0x800000; // write strobe position in the secondary code write register
186  static const uint32_t secondary_code_addr_bits = 0x100000; // memory address position in the secondary code write register
187  static const uint32_t drop_samples = 1; // bit 0 of drop_samples_reg_addr
188  static const uint32_t enable_secondary_code = 2; // bit 1 of drop_samples_reg_addr
189  static const uint32_t init_secondary_code_addresses = 4; // bit 2 of drop_samples_reg_addr
190  static const uint32_t page_size = 0x10000;
191  static const uint32_t max_length_deviceio_name = 50;
192  static const uint32_t max_code_resampler_counter = 1 << 31; // 2^(number of bits of precision of the code resampler)
193  static const uint32_t local_code_fpga_clear_address_counter = 0x10000000;
194  static const uint32_t test_register_track_writeval = 0x55AA;
195 
196  // private functions
197  uint32_t fpga_acquisition_test_register(uint32_t writeval);
198  void fpga_configure_tracking_gps_local_code(int32_t PRN);
199  void fpga_compute_code_shift_parameters();
200  void fpga_configure_code_parameters_in_fpga();
201  void fpga_compute_signal_parameters_in_fpga();
202  void fpga_configure_signal_parameters_in_fpga();
203  void fpga_launch_multicorrelator_fpga();
204  void read_tracking_gps_results();
205  void close_device(void);
206  void write_secondary_code(uint32_t secondary_code_length, std::string *secondary_code_string, uint32_t reg_addr);
207 
208  volk_gnsssdr::vector<uint32_t> d_initial_index;
209  volk_gnsssdr::vector<uint32_t> d_initial_interp_counter;
210 
211  uint64_t d_initial_sample_counter;
212 
213  gr_complex *d_corr_out;
214  gr_complex *d_Prompt_Data;
215 
216  float *d_shifts_chips;
217  float *d_prompt_data_shift;
218 
219  float d_rem_code_phase_chips;
220  float d_code_phase_step_chips;
221  float d_code_phase_rate_step_chips;
222  float d_rem_carrier_phase_in_rad;
223  float d_phase_step_rad;
224  float d_carrier_phase_rate_step_rad;
225 
226  uint32_t d_code_length_chips;
227  uint32_t d_code_length_samples;
228  uint32_t d_n_correlators; // number of correlators
229 
230  // data related to the hardware module and the driver
231  int32_t d_device_descriptor; // driver descriptor
232  volatile uint32_t *d_map_base; // driver memory map
233 
234  // configuration data received from the interface
235  uint32_t d_channel; // channel number
236  uint32_t d_correlator_length_samples;
237  uint32_t d_code_samples_per_chip;
238 
239  uint32_t d_code_phase_step_chips_num;
240  uint32_t d_code_phase_rate_step_chips_num;
241  int32_t d_rem_carr_phase_rad_int;
242  int32_t d_phase_step_rad_int;
243  int32_t d_carrier_phase_rate_step_rad_int;
244 
245  // driver
246  std::string d_device_name;
247  uint32_t d_dev_file_num;
248  uint32_t d_num_prev_assigned_ch;
249 
250  // PRN codes
251  int32_t *d_ca_codes;
252  int32_t *d_data_codes;
253 
254  // secondary code configuration
255  uint32_t d_secondary_code_0_length;
256  uint32_t d_secondary_code_1_length;
257 
258  bool d_track_pilot;
259  bool d_secondary_code_enabled;
260 };
261 
262 #endif // GNSS_SDR_FPGA_MULTICORRELATOR_H
bool free()
Stop the correlation process in the FPGA and free code phase and code rate parameters.
void set_local_code_and_taps(float *shifts_chips, float *prompt_data_shift, int32_t PRN)
Configure the local code in the FPGA multicorrelator.
void set_output_vectors(gr_complex *corr_out, gr_complex *Prompt_Data)
Configure pointers to the FPGA multicorrelator results.
void set_channel(uint32_t channel)
Set channel number and open the FPGA device driver.
void set_initial_sample(uint64_t samples_offset)
Set the initial sample number where the tracking process begins.
void update_local_code()
Configure code phase and code rate parameters in the FPGA.
void set_secondary_code_lengths(uint32_t secondary_code_0_length, uint32_t secondary_code_1_length)
Set the secondary code length in the FPGA. This is only used when extended coherent integration is en...
void disable_secondary_codes()
Disable the use of secondary codes in the FPGA.
void initialize_secondary_code(uint32_t secondary_code, std::string *secondary_code_string)
Initialize the secondary code in the FPGA. If tracking the pilot is enabled then the pilot secondary ...
uint64_t read_sample_counter()
Read the sample counter in the FPGA.
Fpga_Multicorrelator_8sc(int32_t n_correlators, const std::string &device_name, uint32_t dev_file_num, uint32_t num_prev_assigned_ch, int32_t *ca_codes, int32_t *data_codes, uint32_t code_length_chips, bool track_pilot, uint32_t code_samples_per_chip)
Constructor.
void unlock_channel()
finish the tracking process in the FPGA
Class that implements carrier wipe-off and correlators.
void Carrier_wipeoff_multicorrelator_resampler(float rem_carrier_phase_in_rad, float phase_step_rad, float carrier_phase_rate_step_rad, float rem_code_phase_chips, float code_phase_step_chips, float code_phase_rate_step_chips, int32_t signal_length_samples)
Perform a multicorrelation.
void enable_secondary_codes()
Enable the use of secondary codes in the FPGA.
~Fpga_Multicorrelator_8sc()
Destructor.
void update_prn_code_length(uint32_t first_prn_length, uint32_t next_prn_length)
Set the PRN length in the FPGA in number of samples. This function is only used then extended coheren...
void lock_channel()
Start the tracking process in the FPGA.