5G-MAG Reference Tools - MBMS Modem
Phy.h
Go to the documentation of this file.
1 // 5G-MAG Reference Tools
2 // MBMS Modem Process
3 //
4 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Affero General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Affero General Public License for more details.
15 //
16 // You should have received a copy of the GNU Affero General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #pragma once
21 
22 #include <functional>
23 #include <cstdint>
24 #include <string>
25 #include <map>
26 #include <vector>
27 #include <thread>
28 #include <libconfig.h++>
29 
30 #include "srsran/srsran.h"
31 #include "srsran/interfaces/rrc_interface_types.h"
32 #include "srsran/common/gen_mch_tables.h"
33 #include "srsran/phy/common/phy_common.h"
34 
35 constexpr unsigned int MAX_PRB = 100;
36 
42 class Phy {
43  public:
47  typedef std::function<int(cf_t* data[SRSRAN_MAX_CHANNELS], uint32_t nsamples, srsran_timestamp_t* rx_time)> get_samples_t;
48 
57  Phy(const libconfig::Config& cfg, get_samples_t cb, uint8_t cs_nof_prb, int8_t override_nof_prb, uint8_t rx_channels);
58 
62  virtual ~Phy();
63 
67  bool init();
68 
74  bool cell_search();
75 
81  bool synchronize_subframe();
82 
86  bool get_next_frame(cf_t** buffer, uint32_t size);
87 
91  srsran_cell_t cell() {
92  return _cell;
93  }
94 
98  unsigned nr_prb() { return _cell.nof_prb; }
99 
103  uint32_t tti() { return _tti; }
104 
108  float cfo() { return srsran_ue_sync_get_cfo(&_ue_sync);}
109 
113  void set_cfo_from_channel_estimation(float cfo) { srsran_ue_sync_set_cfo_ref(&_ue_sync, cfo); }
114 
118  void set_mch_scheduling_info(const srsran::sib13_t& sib13);
119 
123  void set_mbsfn_config(const srsran::mcch_msg_t& mcch);
124 
128  void reset() { _mcch_configured = _mch_configured = false; }
129 
134 
138  uint8_t mbsfn_area_id() { return _sib13.mbsfn_area_info_list[0].mbsfn_area_id; }
139 
143  srsran_mbsfn_cfg_t mbsfn_config_for_tti(uint32_t tti, unsigned& area);
144 
148  void set_decode_mcch(bool d) { _decode_mcch = d; }
149 
153  uint8_t nof_mbsfn_prb() { return _cell.mbsfn_prb; }
154 
158  void set_nof_mbsfn_prb(uint8_t prb) { _cell.mbsfn_prb = prb; }
159 
160  void set_cell();
161 
162  bool is_cas_subframe(unsigned tti);
163  bool is_mbsfn_subframe(unsigned tti);
164 
165 
166 
167  /**************** Getters and setters for phy params of _ue_sync **************/
168 
172  void inline set_ue_sync_cfo_loop_bw_pss(float bw) { _ue_sync.cfo_loop_bw_pss = bw; };
173  float inline get_ue_sync_cfo_loop_bw_pss() { return _ue_sync.cfo_loop_bw_pss; };
174 
178  void inline set_ue_sync_find_cfo_pss_enable(bool enable) { srsran_sync_set_cfo_pss_enable(&_ue_sync.sfind, enable); };
179  bool inline get_ue_sync_find_cfo_pss_enable() { return _ue_sync.sfind.cfo_pss_enable; };
180 
184  void inline set_ue_sync_track_cfo_pss_enable(bool enable) { srsran_sync_set_cfo_pss_enable(&_ue_sync.strack, enable); };
185  bool inline get_ue_sync_track_cfo_pss_enable() { return _ue_sync.strack.cfo_pss_enable; };
186 
190  void inline set_ue_sync_find_cfo_correct_enable(bool enable) {
191  _ue_sync.cfo_correct_enable_find = enable;
192  }
193  bool inline get_ue_sync_find_cfo_correct_enable() { return _ue_sync.cfo_correct_enable_find; }
194 
198  void inline set_ue_sync_track_cfo_correct_enable(bool enable) { _ue_sync.cfo_correct_enable_track = enable; }
199  bool inline get_ue_sync_track_cfo_correct_enable() { return _ue_sync.cfo_correct_enable_track; }
200 
204  void inline set_ue_sync_track_cfo_ema(float ema) { srsran_ue_sync_set_cfo_ema(&_ue_sync, ema); };
205  float inline get_ue_sync_track_cfo_ema() { return _ue_sync.strack.cfo_ema_alpha; };
206 
210  void inline set_ue_sync_find_cfo_ema(float ema) { srsran_sync_set_cfo_ema_alpha(&_ue_sync.sfind, ema); };
211  float inline get_ue_sync_find_cfo_ema() { return _ue_sync.sfind.cfo_ema_alpha; };
212 
216  void inline set_ue_sync_track_sfo_ema(float ema) { srsran_ue_sync_set_sfo_ema(&_ue_sync, ema); };
217  float inline get_ue_sync_track_sfo_ema() { return _ue_sync.sfo_ema; };
218 
222  void inline set_ue_sync_pss_cfo_ema_find(float ema) { srsran_sync_set_em_alpha(&_ue_sync.sfind, ema); };
223  float inline get_ue_sync_pss_cfo_ema_find() { return _ue_sync.sfind.pss.ema_alpha; };
224 
228  void inline set_ue_sync_pss_cfo_ema_track(float ema) { srsran_sync_set_em_alpha(&_ue_sync.strack, ema); };
229  float inline get_ue_sync_pss_cfo_ema_track() { return _ue_sync.strack.pss.ema_alpha; };
230 
234  void inline set_ue_sync_threshold_track(float threshold) { srsran_sync_set_threshold(&_ue_sync.strack, threshold); };
235  float inline get_ue_sync_threshold_track() { return _ue_sync.strack.threshold; };
236 
240  void inline set_ue_sync_threshold_find(float threshold) { srsran_sync_set_threshold(&_ue_sync.sfind, threshold); };
241  float inline get_ue_sync_threshold_find() { return _ue_sync.sfind.threshold; };
242 
243  typedef struct {
244  std::string tmgi;
245  std::string dest;
246  int lcid;
247  } mtch_info_t;
248  typedef struct {
249  int mcs;
250  std::vector< mtch_info_t > mtchs;
251  } mch_info_t;
252 
253  const std::vector< mch_info_t>& mch_info() { return _mch_info; }
254 
255  void set_dest_for_lcid(uint32_t mch_idx, int lcid, std::string dest) { _dests[mch_idx][lcid] = dest; }
256 
257  enum class SubcarrierSpacing {
258  df_15kHz,
259  df_7kHz5,
260  df_1kHz25
261  };
262 
264  if (_cell.mbms_dedicated) {
265  switch (_sib13.mbsfn_area_info_list[0].subcarrier_spacing) {
266  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_1dot25: return SubcarrierSpacing::df_1kHz25;
267  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_7dot5: return SubcarrierSpacing::df_7kHz5;
268  default: return SubcarrierSpacing::df_15kHz;
269  }
270  } else {
272  }
273  }
274 
276  if (_cell.mbms_dedicated) {
277  switch (_sib13.mbsfn_area_info_list[0].subcarrier_spacing) {
278  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_1dot25: return 1.25;
279  case srsran::mbsfn_area_info_t::subcarrier_spacing_t::khz_7dot5: return 7.5;
280  default: return 15;
281  }
282  } else {
283  return 15;
284  }
285  }
286 
287  srsran::mcch_msg_t& mcch() { return _mcch; }
288 
289  int _mcs = 0;
291 
292  private:
293  const libconfig::Config& _cfg;
294  srsran_ue_sync_t _ue_sync = {};
295  srsran_ue_cellsearch_t _cell_search = {};
296  srsran_ue_mib_sync_t _mib_sync = {};
297  srsran_ue_mib_t _mib = {};
298  srsran_cell_t _cell = {};
299 
300  bool _decode_mcch = false;
301 
302  cf_t* _mib_buffer[SRSRAN_MAX_CHANNELS] = {};
303  uint32_t _buffer_max_samples = 0;
304  uint32_t _tti = 0;
305 
306  uint8_t _mcch_table[10] = {};
307  bool _mcch_configured = false;
308  srsran::sib13_t _sib13 = {};
309  srsran::mcch_msg_t _mcch = {};
310 
311  bool _mch_configured = false;
312 
313  uint8_t _cs_nof_prb;
314 
315  std::vector< mch_info_t > _mch_info;
316 
317  std::map< uint32_t, std::map< int, std::string >> _dests;
318 
320  uint8_t _rx_channels;
321  bool _search_extended_cp = true;
322 };
constexpr unsigned int MAX_PRB
Definition: Phy.h:35
The PHY component.
Definition: Phy.h:42
float get_ue_sync_threshold_track()
Definition: Phy.h:235
srsran_mbsfn_cfg_t mbsfn_config_for_tti(uint32_t tti, unsigned &area)
Returns the MBSFN configuration (MCS, etc) for the subframe with the passed TTI.
Definition: Phy.cpp:329
void set_cfo_from_channel_estimation(float cfo)
Set the CFO value from channel estimation.
Definition: Phy.h:113
int _mcs
Definition: Phy.h:289
std::function< int(cf_t *data[SRSRAN_MAX_CHANNELS], uint32_t nsamples, srsran_timestamp_t *rx_time)> get_samples_t
Definition of the callback function used to fetch samples from the SDR.
Definition: Phy.h:47
std::map< uint32_t, std::map< int, std::string > > _dests
Definition: Phy.h:317
bool mcch_configured()
Return true if MCCH has been configured.
Definition: Phy.h:133
bool get_ue_sync_track_cfo_pss_enable()
Definition: Phy.h:185
SubcarrierSpacing mbsfn_subcarrier_spacing()
Definition: Phy.h:263
void set_ue_sync_track_cfo_ema(float ema)
Sets the ema alpha value used for the tracking of the CFO in the trackin sync object,...
Definition: Phy.h:204
unsigned nr_prb()
Get the current number of PRB.
Definition: Phy.h:98
uint8_t mbsfn_area_id()
Returns the current MBSFN area ID.
Definition: Phy.h:138
void set_decode_mcch(bool d)
Enable MCCH decoding.
Definition: Phy.h:148
const std::vector< mch_info_t > & mch_info()
Definition: Phy.h:253
void set_ue_sync_threshold_track(float threshold)
Sets the threshold of the peak found while tracking for synchronization.
Definition: Phy.h:234
bool get_ue_sync_find_cfo_pss_enable()
Definition: Phy.h:179
void set_mch_scheduling_info(const srsran::sib13_t &sib13)
Set the values received in SIB13.
Definition: Phy.cpp:229
float get_ue_sync_pss_cfo_ema_find()
Definition: Phy.h:223
uint8_t _cs_nof_prb
Definition: Phy.h:313
float get_ue_sync_track_cfo_ema()
Definition: Phy.h:205
std::vector< mch_info_t > _mch_info
Definition: Phy.h:315
SubcarrierSpacing
Definition: Phy.h:257
void set_ue_sync_find_cfo_ema(float ema)
Sets the ema alpha value used for the tracking of the CFO in the trackin sync object,...
Definition: Phy.h:210
cf_t * _mib_buffer[SRSRAN_MAX_CHANNELS]
Definition: Phy.h:302
bool get_next_frame(cf_t **buffer, uint32_t size)
Get the sample data for the next subframe.
Definition: Phy.cpp:225
srsran_cell_t cell()
Get the current cell (with params adjusted for MBSFN)
Definition: Phy.h:91
void set_ue_sync_track_cfo_pss_enable(bool enable)
Enables or disables the CFO estimation from the PSS in the tracking stage.
Definition: Phy.h:184
bool synchronize_subframe()
Synchronizes PSS/SSS and tries to deocode the MIB.
Definition: Phy.cpp:64
bool _mcch_configured
Definition: Phy.h:307
uint8_t _mcch_table[10]
Definition: Phy.h:306
bool _search_extended_cp
Definition: Phy.h:321
const libconfig::Config & _cfg
Definition: Phy.h:293
uint8_t nof_mbsfn_prb()
Get number of PRB in MBSFN/PMCH.
Definition: Phy.h:153
void set_ue_sync_pss_cfo_ema_find(float ema)
Sets the weight factor alpha for the exponential moving average of the PSS correlation output
Definition: Phy.h:222
void set_cell()
Definition: Phy.cpp:188
float get_ue_sync_find_cfo_ema()
Definition: Phy.h:211
srsran_ue_cellsearch_t _cell_search
Definition: Phy.h:295
void reset()
Clear configuration values.
Definition: Phy.h:128
bool is_cas_subframe(unsigned tti)
Definition: Phy.cpp:308
srsran::mcch_msg_t _mcch
Definition: Phy.h:309
uint32_t tti()
Get the current subframe TTI.
Definition: Phy.h:103
void set_ue_sync_track_sfo_ema(float ema)
Sets the ema alpha value used for the tracking of the SFO in ue_sync in the function track_peak_ok.
Definition: Phy.h:216
srsran_ue_sync_t _ue_sync
Definition: Phy.h:294
srsran_cell_t _cell
Definition: Phy.h:298
void set_ue_sync_pss_cfo_ema_track(float ema)
Sets the weight factor alpha for the exponential moving average of the PSS correlation output
Definition: Phy.h:228
uint8_t _rx_channels
Definition: Phy.h:320
bool _mch_configured
Definition: Phy.h:311
void set_ue_sync_track_cfo_correct_enable(bool enable)
Enables the CFO correction while tracking the synchronization from previous estimations.
Definition: Phy.h:198
bool init()
Initialize the underlying components.
Definition: Phy.cpp:197
float get_ue_sync_cfo_loop_bw_pss()
Definition: Phy.h:173
float mbsfn_subcarrier_spacing_khz()
Definition: Phy.h:275
bool cell_search()
Search for a cell.
Definition: Phy.cpp:96
bool get_ue_sync_find_cfo_correct_enable()
Definition: Phy.h:193
virtual ~Phy()
Default destructor.
Definition: Phy.cpp:59
bool _decode_mcch
Definition: Phy.h:300
uint32_t _buffer_max_samples
Definition: Phy.h:303
void set_nof_mbsfn_prb(uint8_t prb)
Override number of PRB in MBSFN/PMCH.
Definition: Phy.h:158
void set_ue_sync_find_cfo_pss_enable(bool enable)
Enables or disables the CFO estimation from the PSS in the finding stage.
Definition: Phy.h:178
srsran_ue_mib_t _mib
Definition: Phy.h:297
void set_dest_for_lcid(uint32_t mch_idx, int lcid, std::string dest)
Definition: Phy.h:255
get_samples_t _sample_cb
Definition: Phy.h:290
void set_ue_sync_find_cfo_correct_enable(bool enable)
Enables the CFO correction while finding the synchronization from previous estimations.
Definition: Phy.h:190
srsran::sib13_t _sib13
Definition: Phy.h:308
float get_ue_sync_pss_cfo_ema_track()
Definition: Phy.h:229
srsran::mcch_msg_t & mcch()
Definition: Phy.h:287
bool is_mbsfn_subframe(unsigned tti)
Definition: Phy.cpp:319
void set_mbsfn_config(const srsran::mcch_msg_t &mcch)
Set MBSFN configuration values.
Definition: Phy.cpp:265
int8_t _override_nof_prb
Definition: Phy.h:319
bool get_ue_sync_track_cfo_correct_enable()
Definition: Phy.h:199
uint32_t _tti
Definition: Phy.h:304
void set_ue_sync_cfo_loop_bw_pss(float bw)
Set the factor for the PSS loopback.
Definition: Phy.h:172
float cfo()
Get the current CFO value.
Definition: Phy.h:108
float get_ue_sync_track_sfo_ema()
Definition: Phy.h:217
void set_ue_sync_threshold_find(float threshold)
Sets the threshold of the peak found while searching for synchronization.
Definition: Phy.h:240
srsran_ue_mib_sync_t _mib_sync
Definition: Phy.h:296
float get_ue_sync_threshold_find()
Definition: Phy.h:241
Phy(const libconfig::Config &cfg, get_samples_t cb, uint8_t cs_nof_prb, int8_t override_nof_prb, uint8_t rx_channels)
Default constructor.
Definition: Phy.cpp:47
static Config cfg
Global configuration object.
Definition: main.cpp:172
std::vector< mtch_info_t > mtchs
Definition: Phy.h:250
std::string dest
Definition: Phy.h:245
std::string tmgi
Definition: Phy.h:244