Skip to content

Commit

Permalink
Improved neighbour cell accuracy. Changed RRC to avoid segfault when …
Browse files Browse the repository at this point in the history
…neighbour cell addition
  • Loading branch information
ismagom committed Feb 2, 2018
1 parent be62b8a commit a279ab4
Show file tree
Hide file tree
Showing 13 changed files with 510 additions and 323 deletions.
2 changes: 1 addition & 1 deletion lib/include/srslte/interfaces/ue_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class rrc_interface_phy
virtual void out_of_sync() = 0;
virtual void earfcn_end() = 0;
virtual void cell_found(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp) = 0;
virtual void new_phy_meas(float rsrp, float rsrq, uint32_t tti, uint32_t earfcn = 0, uint32_t pci = 0) = 0;
virtual void new_phy_meas(float rsrp, float rsrq, uint32_t tti, int earfcn = -1, int pci = -1) = 0;
};

// RRC interface for NAS
Expand Down
5 changes: 4 additions & 1 deletion lib/include/srslte/phy/utils/ringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include "srslte/config.h"
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>

typedef struct {
uint8_t *buffer;
uint8_t *buffer;
bool active;
int capacity;
int count;
int wpm;
Expand All @@ -34,6 +36,7 @@ SRSLTE_API int srslte_ringbuffer_read(srslte_ringbuffer_t *q,
void *ptr,
int nof_bytes);

SRSLTE_API void srslte_ringbuffer_stop(srslte_ringbuffer_t *q);

#endif

Expand Down
7 changes: 4 additions & 3 deletions lib/src/phy/phch/pdcch.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ uint32_t srslte_pdcch_common_locations_ncce(uint32_t nof_cce, srslte_dci_locatio
for (l = 3; l > 1; l--) {
L = (1 << l);
for (i = 0; i < SRSLTE_MIN(nof_cce, 16) / (L); i++) {
if (k < max_candidates) {
c[k].L = l;
c[k].ncce = (L) * (i % (nof_cce / (L)));
uint32_t ncce = (L) * (i % (nof_cce / (L)));
if (k < max_candidates && ncce + L <= nof_cce) {
c[k].L = l;
c[k].ncce = ncce;
DEBUG("Common SS Candidate %d: nCCE: %d, L: %d\n",
k, c[k].ncce, c[k].L);
k++;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/phy/sync/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_o
q->N_id_1 = 1000;

q->cfo_ema_alpha = CFO_EMA_ALPHA;
q->sss_alg = SSS_FULL;
q->sss_alg = SSS_PARTIAL_3;

q->detect_cp = true;
q->sss_en = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/phy/ue/ue_dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ static int find_dl_dci_type_crnti(srslte_ue_dl_t *q, uint32_t tm, uint32_t cfi,

current_ss->format = format;
if ((ret = dci_blind_search(q, current_ss, rnti, cfi, dci_msg))) {
return ret;
return ret;
}
}

Expand Down
17 changes: 14 additions & 3 deletions lib/src/phy/utils/ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int srslte_ringbuffer_init(srslte_ringbuffer_t *q, int capacity)
if (!q->buffer) {
return -1;
}

q->active = true;
q->capacity = capacity;
srslte_ringbuffer_reset(q);

Expand All @@ -24,6 +24,7 @@ int srslte_ringbuffer_init(srslte_ringbuffer_t *q, int capacity)
void srslte_ringbuffer_free(srslte_ringbuffer_t *q)
{
if (q) {
srslte_ringbuffer_stop(q);
if (q->buffer) {
free(q->buffer);
q->buffer = NULL;
Expand Down Expand Up @@ -52,6 +53,9 @@ int srslte_ringbuffer_write(srslte_ringbuffer_t *q, void *p, int nof_bytes)
uint8_t *ptr = (uint8_t*) p;
int w_bytes = nof_bytes;
pthread_mutex_lock(&q->mutex);
if (!q->active) {
return 0;
}
if (q->count + w_bytes > q->capacity) {
w_bytes = q->capacity - q->count;
fprintf(stderr, "Buffer overrun: lost %d bytes\n", nof_bytes - w_bytes);
Expand All @@ -77,9 +81,12 @@ int srslte_ringbuffer_read(srslte_ringbuffer_t *q, void *p, int nof_bytes)
{
uint8_t *ptr = (uint8_t*) p;
pthread_mutex_lock(&q->mutex);
while(q->count < nof_bytes) {
while(q->count < nof_bytes && q->active) {
pthread_cond_wait(&q->cvar, &q->mutex);
}
if (!q->active) {
return 0;
}
if (nof_bytes + q->rpm > q->capacity) {
int x = q->capacity - q->rpm;
memcpy(ptr, &q->buffer[q->rpm], x);
Expand All @@ -96,5 +103,9 @@ int srslte_ringbuffer_read(srslte_ringbuffer_t *q, void *p, int nof_bytes)
return nof_bytes;
}


void srslte_ringbuffer_stop(srslte_ringbuffer_t *q) {
pthread_mutex_lock(&q->mutex);
pthread_cond_broadcast(&q->cvar);
pthread_mutex_unlock(&q->mutex);
}

2 changes: 1 addition & 1 deletion srsue/hdr/mac/mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class mac
void run_thread();

static const int MAC_MAIN_THREAD_PRIO = -1; // Use default high-priority below UHD
static const int MAC_PDU_THREAD_PRIO = -1;
static const int MAC_PDU_THREAD_PRIO = DEFAULT_PRIORITY-5;
static const int MAC_NOF_HARQ_PROC = 2*HARQ_DELAY_MS;

// Interaction with PHY
Expand Down
15 changes: 9 additions & 6 deletions srsue/hdr/phy/phch_recv.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class phch_recv : public thread, public chest_feedback_itf
typedef enum {IDLE, MEASURE_OK, ERROR} ret_code;

~measure();
void init(cf_t *buffer[SRSLTE_MAX_PORTS], srslte::log *log_h,
void init(cf_t *buffer[SRSLTE_MAX_PORTS], srslte::log *log_h, srslte::radio *radio_h,
uint32_t nof_rx_antennas, uint32_t nof_subframes = RSRP_MEASURE_NOF_FRAMES);
void reset();
void set_cell(srslte_cell_t cell);
Expand All @@ -182,11 +182,12 @@ class phch_recv : public thread, public chest_feedback_itf
srslte::log *log_h;
srslte_ue_dl_t ue_dl;
cf_t *buffer[SRSLTE_MAX_PORTS];
srslte::radio *radio_h;
uint32_t cnt;
uint32_t nof_subframes;
uint32_t current_prb;
float rx_gain_offset;
float mean_rsrp, mean_rsrq, mean_snr;
float mean_rsrp, mean_rsrq, mean_snr, mean_rssi;
uint32_t final_offset;
const static int RSRP_MEASURE_NOF_FRAMES = 5;
};
Expand All @@ -201,13 +202,11 @@ class phch_recv : public thread, public chest_feedback_itf
float rsrq;
uint32_t offset;
} cell_info_t;
void init(srslte::log *log_h, bool sic_pss_enabled);
void init(srslte::log *log_h, bool sic_pss_enabled, uint32_t max_sf_window);
void reset();
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]);
private:

const static int DEFAULT_MEASUREMENT_LEN = 10;

cf_t *input_cfo_corrected;
cf_t *sf_buffer[SRSLTE_MAX_PORTS];
srslte::log *log_h;
Expand Down Expand Up @@ -235,8 +234,10 @@ class phch_recv : public thread, public chest_feedback_itf
void write(uint32_t tti, cf_t *data, uint32_t nsamples);
private:
void run_thread();
const static int CAPTURE_LEN_SF = 15;
const static int INTRA_FREQ_MEAS_LEN_MS = 20;
const static int INTRA_FREQ_MEAS_PERIOD_MS = 200;
const static int INTRA_FREQ_MEAS_PRIO = DEFAULT_PRIORITY + 5;

scell_recv scell;
rrc_interface_phy *rrc;
srslte::log *log_h;
Expand All @@ -260,6 +261,8 @@ class phch_recv : public thread, public chest_feedback_itf
srslte_ringbuffer_t ring_buffer;
};

// 36.133 9.1.2.1 for band 7
const static float ABSOLUTE_RSRP_THRESHOLD_DBM = -125;


// Objects for internal use
Expand Down
93 changes: 67 additions & 26 deletions srsue/hdr/upper/rrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,58 @@ using srslte::byte_buffer_t;

namespace srsue {


class cell_t
{
public:
bool is_valid() {
return earfcn != 0 && srslte_cell_isvalid(&phy_cell);
}
bool equals(cell_t *x) {
return equals(x->earfcn, x->phy_cell.id);
}
bool equals(uint32_t earfcn, uint32_t pci) {
return earfcn == this->earfcn && pci == phy_cell.id;
}
bool greater(cell_t *x) {
return x->rsrp > rsrp;
}
bool plmn_equals(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id) {
for (uint32_t i = 0; i < sib1.N_plmn_ids; i++) {
if (plmn_id.mcc == sib1.plmn_id[i].id.mcc && plmn_id.mnc == sib1.plmn_id[i].id.mnc) {
return true;
}
}
return false;
}
cell_t() {
this->has_valid_sib1 = false;
this->has_valid_sib2 = false;
this->has_valid_sib3 = false;
}
cell_t(srslte_cell_t phy_cell, uint32_t earfcn, float rsrp) {
this->has_valid_sib1 = false;
this->has_valid_sib2 = false;
this->has_valid_sib3 = false;
this->phy_cell = phy_cell;
this->rsrp = rsrp;
this->earfcn = earfcn;
}

uint32_t earfcn;
srslte_cell_t phy_cell;
float rsrp;
bool has_valid_sib1;
bool has_valid_sib2;
bool has_valid_sib3;
bool has_valid_sib13;
bool in_sync;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT sib1;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT sib2;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_3_STRUCT sib3;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_13_STRUCT sib13;
};

class rrc
:public rrc_interface_nas
,public rrc_interface_phy
Expand Down Expand Up @@ -100,7 +152,7 @@ class rrc
void out_of_sync();
void earfcn_end();
void cell_found(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp);
void new_phy_meas(float rsrp, float rsrq, uint32_t tti, uint32_t earfcn, uint32_t pci);
void new_phy_meas(float rsrp, float rsrq, uint32_t tti, int earfcn, int pci);

// MAC interface
void ho_ra_completed(bool ra_successful);
Expand Down Expand Up @@ -154,7 +206,7 @@ class rrc
bool first_stimsi_attempt;

uint16_t ho_src_rnti;
int ho_src_cell_idx;
cell_t ho_src_cell;
phy_interface_rrc::phy_cfg_t ho_src_phy_cfg;
mac_interface_rrc::mac_cfg_t ho_src_mac_cfg;
bool pending_mob_reconf;
Expand Down Expand Up @@ -215,28 +267,18 @@ class rrc
}
}

typedef struct {
uint32_t earfcn;
srslte_cell_t phy_cell;
float rsrp;
bool has_valid_sib1;
bool has_valid_sib2;
bool has_valid_sib3;
bool has_valid_sib13;
bool in_sync;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT sib1;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT sib2;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_3_STRUCT sib3;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_13_STRUCT sib13;
} cell_t;

const static int MAX_KNOWN_CELLS = 64;
cell_t known_cells[MAX_KNOWN_CELLS];
cell_t *current_cell;

int find_cell_idx(uint32_t earfcn, uint32_t pci);
cell_t* add_new_cell(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp);
uint32_t find_best_cell(uint32_t earfcn, srslte_cell_t *cell);
// List of strongest neighbour cell
const static int NOF_NEIGHBOUR_CELLS = 8;
std::vector<cell_t*> neighbour_cells;
cell_t *serving_cell;
void set_serving_cell(uint32_t cell_idx);
void set_serving_cell(uint32_t earfcn, uint32_t pci);

int find_neighbour_cell(uint32_t earfcn, uint32_t pci);
bool add_neighbour_cell(uint32_t earfcn, uint32_t pci, float rsrp);
bool add_neighbour_cell(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp);
bool add_neighbour_cell(cell_t *cell);
void sort_neighbour_cells();

typedef enum {
SI_ACQUIRE_IDLE = 0,
Expand All @@ -253,7 +295,6 @@ class rrc

void select_next_cell_in_plmn();
LIBLTE_RRC_PLMN_IDENTITY_STRUCT selected_plmn_id;
int last_selected_cell;

bool thread_running;
void run_thread();
Expand Down Expand Up @@ -395,10 +436,10 @@ class rrc
// Helpers
void ho_failed();
bool ho_prepare();
void add_neighbour_cell(uint32_t earfcn, uint32_t pci, float rsrp);
void rrc_connection_release();
void con_restablish_cell_reselected();
void radio_link_failure();
void leave_connected();

static void* start_sib_thread(void *rrc_);
void sib_search();
Expand Down
2 changes: 1 addition & 1 deletion srsue/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void parse_args(all_args_t *args, int argc, char *argv[]) {
"After the PSS estimation is below cfo_loop_pss_tol for cfo_loop_pss_timeout times consecutively, RS adjustments are allowed.")

("expert.sic_pss_enabled",
bpo::value<bool>(&args->expert.phy.sic_pss_enabled)->default_value(true),
bpo::value<bool>(&args->expert.phy.sic_pss_enabled)->default_value(false),
"Applies Successive Interference Cancellation to PSS signals when searching for neighbour cells. Must be disabled if cells have identical channel and timing.")

("expert.average_subframe_enabled",
Expand Down
Loading

0 comments on commit a279ab4

Please sign in to comment.