2019-04-23 01:53:11 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2013-2019 Software Radio Systems Limited
|
2017-05-30 06:38:04 -07:00
|
|
|
*
|
2019-04-23 01:53:11 -07:00
|
|
|
* This file is part of srsLTE.
|
2017-05-30 06:38:04 -07:00
|
|
|
*
|
2019-04-23 01:53:11 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2017-05-30 06:38:04 -07:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2019-04-23 01:53:11 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2017-05-30 06:38:04 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-03-31 10:04:04 -07:00
|
|
|
#ifndef SRSUE_PHCH_RECV_H
|
|
|
|
#define SRSUE_PHCH_RECV_H
|
2017-05-30 06:38:04 -07:00
|
|
|
|
2017-11-20 01:02:39 -08:00
|
|
|
#include <map>
|
2018-03-19 06:14:51 -07:00
|
|
|
#include <pthread.h>
|
2017-11-20 01:02:39 -08:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
#include "async_scell_recv.h"
|
|
|
|
#include "phy_common.h"
|
|
|
|
#include "prach.h"
|
|
|
|
#include "sf_worker.h"
|
2017-05-31 14:39:17 -07:00
|
|
|
#include "srslte/common/log.h"
|
|
|
|
#include "srslte/common/thread_pool.h"
|
2019-04-23 01:53:11 -07:00
|
|
|
#include "srslte/common/threads.h"
|
2017-11-20 01:02:39 -08:00
|
|
|
#include "srslte/common/tti_sync_cv.h"
|
2017-06-01 03:25:42 -07:00
|
|
|
#include "srslte/interfaces/ue_interfaces.h"
|
2019-04-23 01:53:11 -07:00
|
|
|
#include "srslte/radio/radio_multi.h"
|
|
|
|
#include "srslte/srslte.h"
|
2017-05-30 06:38:04 -07:00
|
|
|
|
|
|
|
namespace srsue {
|
|
|
|
|
2017-11-20 01:02:39 -08:00
|
|
|
typedef _Complex float cf_t;
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
class sync : public thread, public chest_feedback_itf
|
2017-05-30 06:38:04 -07:00
|
|
|
{
|
|
|
|
public:
|
2019-04-23 01:53:11 -07:00
|
|
|
sync();
|
|
|
|
~sync();
|
|
|
|
|
|
|
|
void init(srslte::radio* radio_handler,
|
|
|
|
mac_interface_phy* mac,
|
|
|
|
rrc_interface_phy* rrc,
|
|
|
|
prach* prach_buffer,
|
|
|
|
srslte::thread_pool* _workers_pool,
|
|
|
|
phy_common* _worker_com,
|
|
|
|
srslte::log* _log_h,
|
|
|
|
srslte::log* _log_phy_lib_h,
|
|
|
|
async_scell_recv* scell_sync_,
|
|
|
|
uint32_t prio,
|
|
|
|
int sync_cpu_affinity = -1);
|
2017-05-30 06:38:04 -07:00
|
|
|
void stop();
|
2018-03-19 06:14:51 -07:00
|
|
|
void radio_overflow();
|
2017-05-30 06:38:04 -07:00
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
// RRC interface for controling the SYNC state
|
2018-03-21 02:46:24 -07:00
|
|
|
phy_interface_rrc::cell_search_ret_t cell_search(phy_interface_rrc::phy_cell_t *cell);
|
2018-03-19 06:14:51 -07:00
|
|
|
bool cell_select(phy_interface_rrc::phy_cell_t *cell);
|
|
|
|
bool cell_is_camping();
|
2017-06-21 09:29:17 -07:00
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
// RRC interface for controlling the neighbour cell measurement
|
2017-11-20 01:02:39 -08:00
|
|
|
void meas_reset();
|
|
|
|
int meas_start(uint32_t earfcn, int pci);
|
|
|
|
int meas_stop(uint32_t earfcn, int pci);
|
|
|
|
|
2017-11-30 11:01:35 -08:00
|
|
|
// from chest_feedback_itf
|
2018-01-30 04:13:41 -08:00
|
|
|
void in_sync();
|
2017-12-01 10:50:42 -08:00
|
|
|
void out_of_sync();
|
2017-11-30 11:01:35 -08:00
|
|
|
void set_cfo(float cfo);
|
|
|
|
|
2017-05-30 06:38:04 -07:00
|
|
|
void set_time_adv_sec(float time_adv_sec);
|
2017-11-20 01:02:39 -08:00
|
|
|
void get_current_cell(srslte_cell_t *cell, uint32_t *earfcn = NULL);
|
2018-03-19 06:14:51 -07:00
|
|
|
uint32_t get_current_tti();
|
2017-10-13 08:59:12 -07:00
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
// From UE configuration
|
|
|
|
void set_agc_enable(bool enable);
|
|
|
|
void set_earfcn(std::vector<uint32_t> earfcn);
|
|
|
|
void force_freq(float dl_freq, float ul_freq);
|
2017-10-13 08:59:12 -07:00
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
// Other functions
|
2017-11-24 03:02:41 -08:00
|
|
|
double set_rx_gain(double gain);
|
2017-10-10 07:42:24 -07:00
|
|
|
int radio_recv_fnc(cf_t *data[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t *rx_time);
|
2017-05-30 06:38:04 -07:00
|
|
|
|
|
|
|
private:
|
2017-06-21 09:29:17 -07:00
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
// Class to run cell search
|
|
|
|
class search {
|
|
|
|
public:
|
|
|
|
typedef enum {CELL_NOT_FOUND, CELL_FOUND, ERROR, TIMEOUT} ret_code;
|
|
|
|
|
|
|
|
~search();
|
2019-04-23 01:53:11 -07:00
|
|
|
void init(cf_t* buffer[SRSLTE_MAX_PORTS], srslte::log* log_h, uint32_t nof_rx_antennas, sync* parent);
|
2017-10-10 07:42:24 -07:00
|
|
|
void reset();
|
|
|
|
float get_last_cfo();
|
2018-02-13 06:06:22 -08:00
|
|
|
void set_agc_enable(bool enable);
|
2017-10-10 07:42:24 -07:00
|
|
|
ret_code run(srslte_cell_t *cell);
|
|
|
|
|
|
|
|
private:
|
2019-04-23 01:53:11 -07:00
|
|
|
sync* p;
|
|
|
|
srslte::log* log_h;
|
2017-10-10 07:42:24 -07:00
|
|
|
cf_t *buffer[SRSLTE_MAX_PORTS];
|
|
|
|
srslte_ue_cellsearch_t cs;
|
|
|
|
srslte_ue_mib_sync_t ue_mib_sync;
|
|
|
|
int force_N_id_2;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class to synchronize system frame number
|
|
|
|
class sfn_sync {
|
|
|
|
public:
|
2018-03-19 06:14:51 -07:00
|
|
|
typedef enum {IDLE, SFN_FOUND, SFX0_FOUND, SFN_NOFOUND, ERROR} ret_code;
|
2017-10-10 07:42:24 -07:00
|
|
|
|
|
|
|
~sfn_sync();
|
2019-04-23 01:53:11 -07:00
|
|
|
void init(srslte_ue_sync_t* ue_sync,
|
|
|
|
cf_t* buffer[SRSLTE_MAX_PORTS],
|
|
|
|
srslte::log* log_h,
|
|
|
|
uint32_t nof_subframes = SFN_SYNC_NOF_SUBFRAMES);
|
2017-10-10 07:42:24 -07:00
|
|
|
void reset();
|
|
|
|
bool set_cell(srslte_cell_t cell);
|
2017-11-20 01:02:39 -08:00
|
|
|
ret_code run_subframe(srslte_cell_t *cell, uint32_t *tti_cnt, bool sfidx_only = false);
|
2019-04-23 01:53:11 -07:00
|
|
|
ret_code
|
|
|
|
decode_mib(srslte_cell_t* cell, uint32_t* tti_cnt, cf_t* ext_buffer[SRSLTE_MAX_PORTS], bool sfidx_only = false);
|
2017-10-10 07:42:24 -07:00
|
|
|
|
|
|
|
private:
|
2018-03-19 06:14:51 -07:00
|
|
|
const static int SFN_SYNC_NOF_SUBFRAMES = 100;
|
|
|
|
|
|
|
|
uint32_t cnt;
|
|
|
|
uint32_t timeout;
|
2017-10-10 07:42:24 -07:00
|
|
|
srslte::log *log_h;
|
|
|
|
srslte_ue_sync_t *ue_sync;
|
|
|
|
cf_t *buffer[SRSLTE_MAX_PORTS];
|
|
|
|
srslte_ue_mib_t ue_mib;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class to perform cell measurements
|
|
|
|
class measure {
|
2017-11-20 01:02:39 -08:00
|
|
|
|
|
|
|
// TODO: This class could early stop once the variance between the last N measurements is below 3GPP requirements
|
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
public:
|
|
|
|
typedef enum {IDLE, MEASURE_OK, ERROR} ret_code;
|
|
|
|
|
|
|
|
~measure();
|
2019-04-23 01:53:11 -07:00
|
|
|
void init(cf_t* buffer[SRSLTE_MAX_PORTS],
|
|
|
|
srslte::log* log_h,
|
|
|
|
uint32_t nof_rx_antennas,
|
|
|
|
phy_common* worker_com,
|
|
|
|
uint32_t nof_subframes = RSRP_MEASURE_NOF_FRAMES);
|
2017-10-10 07:42:24 -07:00
|
|
|
void reset();
|
|
|
|
void set_cell(srslte_cell_t cell);
|
|
|
|
ret_code run_subframe(uint32_t sf_idx);
|
2018-03-19 06:14:51 -07:00
|
|
|
ret_code run_multiple_subframes(cf_t *buffer, uint32_t offset, uint32_t sf_idx, uint32_t nof_sf);
|
2018-02-25 14:36:08 -08:00
|
|
|
float rssi();
|
2017-10-10 07:42:24 -07:00
|
|
|
float rsrp();
|
|
|
|
float rsrq();
|
|
|
|
float snr();
|
2017-12-02 03:02:01 -08:00
|
|
|
uint32_t frame_st_idx();
|
2017-11-23 10:46:34 -08:00
|
|
|
void set_rx_gain_offset(float rx_gain_offset);
|
2017-10-10 07:42:24 -07:00
|
|
|
private:
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte::log* log_h;
|
2017-10-10 07:42:24 -07:00
|
|
|
srslte_ue_dl_t ue_dl;
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_ue_dl_cfg_t ue_dl_cfg;
|
2017-10-10 07:42:24 -07:00
|
|
|
cf_t *buffer[SRSLTE_MAX_PORTS];
|
|
|
|
uint32_t cnt;
|
|
|
|
uint32_t nof_subframes;
|
2017-11-20 01:02:39 -08:00
|
|
|
uint32_t current_prb;
|
2017-11-23 10:46:34 -08:00
|
|
|
float rx_gain_offset;
|
2018-03-14 02:23:05 -07:00
|
|
|
float mean_rsrp, mean_rsrq, mean_snr, mean_rssi;
|
2017-12-02 03:02:01 -08:00
|
|
|
uint32_t final_offset;
|
2017-10-10 07:42:24 -07:00
|
|
|
const static int RSRP_MEASURE_NOF_FRAMES = 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class to receive secondary cell
|
2017-11-20 01:02:39 -08:00
|
|
|
class scell_recv {
|
2017-10-10 07:42:24 -07:00
|
|
|
public:
|
2017-11-20 01:02:39 -08:00
|
|
|
const static int MAX_CELLS = 8;
|
|
|
|
typedef struct {
|
|
|
|
uint32_t pci;
|
|
|
|
float rsrp;
|
|
|
|
float rsrq;
|
|
|
|
uint32_t offset;
|
|
|
|
} cell_info_t;
|
2019-04-23 01:53:11 -07:00
|
|
|
void init(srslte::log* log_h, bool sic_pss_enabled, uint32_t max_sf_window, phy_common* worker_com);
|
2018-03-20 07:09:32 -07:00
|
|
|
void deinit();
|
2017-10-13 08:59:12 -07:00
|
|
|
void reset();
|
2017-11-23 10:46:34 -08:00
|
|
|
int find_cells(cf_t *input_buffer, float rx_gain_offset, srslte_cell_t current_cell, uint32_t nof_sf, cell_info_t found_cells[MAX_CELLS]);
|
2017-10-10 07:42:24 -07:00
|
|
|
private:
|
|
|
|
|
|
|
|
cf_t *sf_buffer[SRSLTE_MAX_PORTS];
|
2017-11-20 01:02:39 -08:00
|
|
|
srslte::log *log_h;
|
|
|
|
srslte_sync_t sync_find;
|
2017-10-10 07:42:24 -07:00
|
|
|
|
2017-12-03 20:13:07 -08:00
|
|
|
bool sic_pss_enabled;
|
2017-11-27 04:57:05 -08:00
|
|
|
uint32_t current_fft_sz;
|
2017-10-10 07:42:24 -07:00
|
|
|
measure measure_p;
|
|
|
|
};
|
|
|
|
|
2017-11-20 01:02:39 -08:00
|
|
|
/* TODO: Intra-freq measurements can be improved by capturing 200 ms length signal and run cell search +
|
|
|
|
* measurements offline using sync object and finding multiple cells for each N_id_2
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Class to perform intra-frequency measurements
|
|
|
|
class intra_measure : public thread {
|
|
|
|
public:
|
2019-01-21 06:44:01 -08:00
|
|
|
intra_measure();
|
2018-03-20 07:09:32 -07:00
|
|
|
~intra_measure();
|
2019-04-23 01:53:11 -07:00
|
|
|
void init(phy_common* common, rrc_interface_phy* rrc, srslte::log* log_h);
|
2017-11-20 01:02:39 -08:00
|
|
|
void stop();
|
|
|
|
void add_cell(int pci);
|
|
|
|
void rem_cell(int pci);
|
|
|
|
void set_primay_cell(uint32_t earfcn, srslte_cell_t cell);
|
|
|
|
void clear_cells();
|
2017-11-23 10:46:34 -08:00
|
|
|
int get_offset(uint32_t pci);
|
2017-11-20 01:02:39 -08:00
|
|
|
void write(uint32_t tti, cf_t *data, uint32_t nsamples);
|
|
|
|
private:
|
|
|
|
void run_thread();
|
2018-02-02 10:31:22 -08:00
|
|
|
const static int INTRA_FREQ_MEAS_PRIO = DEFAULT_PRIORITY + 5;
|
|
|
|
|
2017-11-20 01:02:39 -08:00
|
|
|
scell_recv scell;
|
2019-04-23 01:53:11 -07:00
|
|
|
rrc_interface_phy* rrc;
|
2017-11-20 01:02:39 -08:00
|
|
|
srslte::log *log_h;
|
2019-04-23 01:53:11 -07:00
|
|
|
phy_common* common;
|
2017-11-20 01:02:39 -08:00
|
|
|
uint32_t current_earfcn;
|
|
|
|
uint32_t current_sflen;
|
|
|
|
srslte_cell_t primary_cell;
|
|
|
|
std::vector<int> active_pci;
|
|
|
|
|
|
|
|
srslte::tti_sync_cv tti_sync;
|
|
|
|
|
|
|
|
cf_t *search_buffer;
|
|
|
|
|
|
|
|
scell_recv::cell_info_t info[scell_recv::MAX_CELLS];
|
|
|
|
|
|
|
|
bool running;
|
|
|
|
bool receive_enabled;
|
|
|
|
bool receiving;
|
|
|
|
uint32_t measure_tti;
|
|
|
|
uint32_t receive_cnt;
|
|
|
|
srslte_ringbuffer_t ring_buffer;
|
|
|
|
};
|
2017-10-10 07:42:24 -07:00
|
|
|
|
2018-02-02 10:31:22 -08:00
|
|
|
// 36.133 9.1.2.1 for band 7
|
2018-02-15 08:46:44 -08:00
|
|
|
constexpr static float ABSOLUTE_RSRP_THRESHOLD_DBM = -125;
|
2017-10-10 07:42:24 -07:00
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
std::vector<uint32_t> earfcn;
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
void radio_error();
|
|
|
|
void set_ue_sync_opts(srslte_ue_sync_t *q, float cfo);
|
|
|
|
void run_thread();
|
2018-03-21 02:46:24 -07:00
|
|
|
float get_tx_cfo();
|
2018-03-19 06:14:51 -07:00
|
|
|
|
|
|
|
void set_sampling_rate();
|
|
|
|
bool set_frequency();
|
|
|
|
bool set_cell();
|
|
|
|
|
|
|
|
bool radio_is_overflow;
|
|
|
|
bool radio_overflow_return;
|
|
|
|
bool running;
|
2017-10-10 07:42:24 -07:00
|
|
|
|
|
|
|
// Objects for internal use
|
|
|
|
search search_p;
|
|
|
|
sfn_sync sfn_p;
|
2017-11-20 01:02:39 -08:00
|
|
|
intra_measure intra_freq_meas;
|
2017-09-18 09:34:33 -07:00
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
uint32_t current_sflen;
|
|
|
|
int next_offset;
|
|
|
|
|
|
|
|
// Pointers to other classes
|
2017-05-30 06:38:04 -07:00
|
|
|
mac_interface_phy *mac;
|
2017-06-23 10:15:30 -07:00
|
|
|
rrc_interface_phy *rrc;
|
2017-05-30 06:38:04 -07:00
|
|
|
srslte::log *log_h;
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte::log* log_phy_lib_h;
|
|
|
|
srslte::thread_pool* workers_pool;
|
|
|
|
srslte::radio* radio_h;
|
|
|
|
phy_common* worker_com;
|
2017-05-30 06:38:04 -07:00
|
|
|
prach *prach_buffer;
|
2019-04-23 01:53:11 -07:00
|
|
|
async_scell_recv* scell_sync;
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
// Object for synchronization of the primary cell
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_ue_sync_t ue_sync;
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
// Buffer for primary and secondary cell samples
|
|
|
|
cf_t* sf_buffer[SRSLTE_MAX_RADIOS][SRSLTE_MAX_PORTS];
|
2017-05-30 06:38:04 -07:00
|
|
|
|
|
|
|
// Sync metrics
|
2017-10-10 07:42:24 -07:00
|
|
|
sync_metrics_t metrics;
|
2017-05-30 06:38:04 -07:00
|
|
|
|
2018-02-01 09:17:40 -08:00
|
|
|
// in-sync / out-of-sync counters
|
|
|
|
uint32_t out_of_sync_cnt;
|
|
|
|
uint32_t in_sync_cnt;
|
|
|
|
|
|
|
|
const static uint32_t NOF_OUT_OF_SYNC_SF = 200;
|
|
|
|
const static uint32_t NOF_IN_SYNC_SF = 100;
|
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
// State machine for SYNC thread
|
|
|
|
class sync_state {
|
|
|
|
public:
|
|
|
|
typedef enum {
|
|
|
|
IDLE = 0,
|
|
|
|
CELL_SEARCH,
|
|
|
|
SFN_SYNC,
|
|
|
|
CAMPING,
|
|
|
|
} state_t;
|
|
|
|
|
|
|
|
/* Run_state is called by the main thread at the start of each loop. It updates the state
|
|
|
|
* and returns the current state
|
|
|
|
*/
|
|
|
|
state_t run_state() {
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
cur_state = next_state;
|
2018-08-14 10:50:03 -07:00
|
|
|
if (state_setting) {
|
2019-04-23 01:53:11 -07:00
|
|
|
state_setting = false;
|
|
|
|
state_running = true;
|
2018-08-14 10:50:03 -07:00
|
|
|
}
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_cond_broadcast(&cvar);
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
return cur_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by the main thread at the end of each state to indicate it has finished.
|
2018-03-21 02:46:24 -07:00
|
|
|
void state_exit(bool exit_ok = true) {
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_mutex_lock(&inside);
|
2018-03-21 02:46:24 -07:00
|
|
|
if (cur_state == SFN_SYNC && exit_ok == true) {
|
|
|
|
next_state = CAMPING;
|
|
|
|
} else {
|
|
|
|
next_state = IDLE;
|
|
|
|
}
|
2019-04-23 01:53:11 -07:00
|
|
|
state_running = false;
|
2018-08-14 10:50:03 -07:00
|
|
|
pthread_cond_broadcast(&cvar);
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
}
|
|
|
|
void force_sfn_sync() {
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
next_state = SFN_SYNC;
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Functions to be called from outside the STM thread to instruct the STM to switch state.
|
|
|
|
* The functions change the state and wait until it has changed it.
|
|
|
|
*
|
|
|
|
* These functions are mutexed and only 1 can be called at a time
|
|
|
|
*/
|
|
|
|
void go_idle() {
|
|
|
|
pthread_mutex_lock(&outside);
|
|
|
|
go_state(IDLE);
|
|
|
|
pthread_mutex_unlock(&outside);
|
|
|
|
}
|
|
|
|
void run_cell_search() {
|
|
|
|
pthread_mutex_lock(&outside);
|
|
|
|
go_state(CELL_SEARCH);
|
2019-04-23 01:53:11 -07:00
|
|
|
wait_state_run();
|
|
|
|
wait_state_next();
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_mutex_unlock(&outside);
|
|
|
|
}
|
|
|
|
void run_sfn_sync() {
|
|
|
|
pthread_mutex_lock(&outside);
|
|
|
|
go_state(SFN_SYNC);
|
2019-04-23 01:53:11 -07:00
|
|
|
wait_state_run();
|
|
|
|
wait_state_next();
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_mutex_unlock(&outside);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Helpers below this */
|
|
|
|
bool is_idle() {
|
|
|
|
return cur_state == IDLE;
|
|
|
|
}
|
|
|
|
bool is_camping() {
|
|
|
|
return cur_state == CAMPING;
|
|
|
|
}
|
|
|
|
|
2018-03-21 02:46:24 -07:00
|
|
|
const char *to_string() {
|
|
|
|
switch(cur_state) {
|
|
|
|
case IDLE:
|
|
|
|
return "IDLE";
|
|
|
|
case CELL_SEARCH:
|
|
|
|
return "SEARCH";
|
|
|
|
case SFN_SYNC:
|
|
|
|
return "SYNC";
|
|
|
|
case CAMPING:
|
|
|
|
return "CAMPING";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
sync_state() {
|
|
|
|
pthread_mutex_init(&inside, NULL);
|
|
|
|
pthread_mutex_init(&outside, NULL);
|
|
|
|
pthread_cond_init(&cvar, NULL);
|
|
|
|
cur_state = IDLE;
|
2019-04-23 01:53:11 -07:00
|
|
|
next_state = IDLE;
|
2018-08-14 10:50:03 -07:00
|
|
|
state_setting = false;
|
2019-04-23 01:53:11 -07:00
|
|
|
state_running = false;
|
2018-03-19 06:14:51 -07:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
void go_state(state_t s) {
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
next_state = s;
|
2018-08-14 10:50:03 -07:00
|
|
|
state_setting = true;
|
|
|
|
while(state_setting) {
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_cond_wait(&cvar, &inside);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Waits until there is a call to set_state() and then run_state(). Returns when run_state() returns */
|
2019-04-23 01:53:11 -07:00
|
|
|
void wait_state_run()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&inside);
|
|
|
|
while (state_running) {
|
|
|
|
pthread_cond_wait(&cvar, &inside);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
}
|
|
|
|
void wait_state_next()
|
|
|
|
{
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_mutex_lock(&inside);
|
2019-04-23 01:53:11 -07:00
|
|
|
while (cur_state != next_state) {
|
2018-03-19 06:14:51 -07:00
|
|
|
pthread_cond_wait(&cvar, &inside);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&inside);
|
|
|
|
}
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
bool state_running, state_setting;
|
2018-03-19 06:14:51 -07:00
|
|
|
state_t cur_state, next_state;
|
|
|
|
pthread_mutex_t inside, outside;
|
|
|
|
pthread_cond_t cvar;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
pthread_mutex_t rrc_mutex;
|
2018-03-05 04:07:24 -08:00
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
sync_state phy_state;
|
2017-06-23 10:15:30 -07:00
|
|
|
|
2018-03-19 06:14:51 -07:00
|
|
|
search::ret_code cell_search_ret;
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
// Sampling rate mode (find is 1.96 MHz, camp is the full cell BW)
|
2017-06-23 10:15:30 -07:00
|
|
|
enum {
|
|
|
|
SRATE_NONE=0, SRATE_FIND, SRATE_CAMP
|
|
|
|
} srate_mode;
|
2017-09-21 12:43:24 -07:00
|
|
|
float current_srate;
|
2017-05-30 06:38:04 -07:00
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
// This is the primary cell
|
2017-06-23 10:15:30 -07:00
|
|
|
srslte_cell_t cell;
|
2017-10-10 07:42:24 -07:00
|
|
|
bool started;
|
2018-04-24 04:50:59 -07:00
|
|
|
float time_adv_sec, next_time_adv_sec;
|
2017-09-01 04:29:11 -07:00
|
|
|
uint32_t tti;
|
2017-05-30 06:38:04 -07:00
|
|
|
bool do_agc;
|
2018-09-06 06:22:37 -07:00
|
|
|
|
|
|
|
uint32_t tx_worker_cnt;
|
|
|
|
uint32_t nof_workers;
|
2017-05-30 06:38:04 -07:00
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
float ul_dl_factor;
|
2018-03-19 06:14:51 -07:00
|
|
|
int current_earfcn;
|
|
|
|
uint32_t cellsearch_earfcn_index;
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2017-10-10 07:42:24 -07:00
|
|
|
float dl_freq;
|
|
|
|
float ul_freq;
|
2017-10-10 03:33:10 -07:00
|
|
|
|
2017-05-30 06:38:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace srsue
|
|
|
|
|
2018-03-31 10:04:04 -07:00
|
|
|
#endif // SRSUE_PHCH_RECV_H
|