Set to Continuous RX and TX

master
Ismael Gomez 7 years ago
parent 5fe066df69
commit fd0c8168f0

@ -72,6 +72,8 @@ namespace srslte {
trace_enabled = false; trace_enabled = false;
tti = 0; tti = 0;
agc_enabled = false; agc_enabled = false;
radio_is_streaming = false;
is_initialized = false;
}; };
bool init(char *args = NULL, char *devname = NULL, uint32_t nof_channels = 1); bool init(char *args = NULL, char *devname = NULL, uint32_t nof_channels = 1);
@ -119,13 +121,13 @@ namespace srslte {
void start_trace(); void start_trace();
void write_trace(std::string filename); void write_trace(std::string filename);
void start_rx(bool now = false);
void stop_rx();
void set_tti(uint32_t tti); void set_tti(uint32_t tti);
bool is_first_of_burst(); bool is_first_of_burst();
bool is_init();
void register_error_handler(srslte_rf_error_handler_t h); void register_error_handler(srslte_rf_error_handler_t h);
protected: protected:
@ -168,6 +170,9 @@ namespace srslte {
uint32_t tti; uint32_t tti;
bool agc_enabled; bool agc_enabled;
bool is_initialized = true;;
bool radio_is_streaming;
uint32_t saved_nof_channels; uint32_t saved_nof_channels;
char saved_args[128]; char saved_args[128];
char saved_devname[128]; char saved_devname[128];

@ -557,11 +557,12 @@ int rf_uhd_open_multi(char *args, void **h, uint32_t nof_channels)
uhd_meta_range_free(&gain_range); uhd_meta_range_free(&gain_range);
// Start low priority thread to receive async commands // Start low priority thread to receive async commands
handler->async_thread_running = true; /*
handler->async_thread_running = true;
if (pthread_create(&handler->async_thread, NULL, async_thread, handler)) { if (pthread_create(&handler->async_thread, NULL, async_thread, handler)) {
perror("pthread_create"); perror("pthread_create");
return -1; return -1;
} }*/
/* Restore priorities */ /* Restore priorities */
uhd_set_thread_priority(0, false); uhd_set_thread_priority(0, false);

@ -71,7 +71,12 @@ bool radio::init(char *args, char *devname, uint32_t nof_channels)
} }
saved_nof_channels = nof_channels; saved_nof_channels = nof_channels;
return true; is_initialized = true;
return true;
}
bool radio::is_init() {
return is_initialized;
} }
void radio::stop() void radio::stop()
@ -141,6 +146,10 @@ bool radio::rx_at(void* buffer, uint32_t nof_samples, srslte_timestamp_t rx_time
bool radio::rx_now(void* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_timestamp_t* rxd_time) bool radio::rx_now(void* buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, srslte_timestamp_t* rxd_time)
{ {
if (!radio_is_streaming) {
srslte_rf_start_rx_stream(&rf_device, true);
radio_is_streaming = true;
}
if (srslte_rf_recv_with_time_multi(&rf_device, buffer, nof_samples, true, if (srslte_rf_recv_with_time_multi(&rf_device, buffer, nof_samples, true,
rxd_time?&rxd_time->full_secs:NULL, rxd_time?&rxd_time->frac_secs:NULL) > 0) { rxd_time?&rxd_time->full_secs:NULL, rxd_time?&rxd_time->frac_secs:NULL) > 0) {
return true; return true;
@ -446,16 +455,6 @@ void radio::set_tx_srate(double srate)
tx_adv_sec = nsamples/cur_tx_srate; tx_adv_sec = nsamples/cur_tx_srate;
} }
void radio::start_rx(bool now)
{
srslte_rf_start_rx_stream(&rf_device, now);
}
void radio::stop_rx()
{
srslte_rf_stop_rx_stream(&rf_device);
}
void radio::register_error_handler(srslte_rf_error_handler_t h) void radio::register_error_handler(srslte_rf_error_handler_t h)
{ {
srslte_rf_register_error_handler(&rf_device, h); srslte_rf_register_error_handler(&rf_device, h);

@ -37,6 +37,7 @@ bool radio_multi::init_multi(uint32_t nof_rx_antennas, char* args, char* devname
strncpy(saved_devname, devname, 127); strncpy(saved_devname, devname, 127);
} }
is_initialized = true;
return true; return true;
} }
@ -46,7 +47,11 @@ bool radio_multi::rx_now(cf_t *buffer[SRSLTE_MAX_PORTS], uint32_t nof_samples, s
for (int i=0;i<SRSLTE_MAX_PORTS;i++) { for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
ptr[i] = buffer[i]; ptr[i] = buffer[i];
} }
if (srslte_rf_recv_with_time_multi(&rf_device, ptr, nof_samples, true, if (!radio_is_streaming) {
srslte_rf_start_rx_stream(&rf_device, true);
radio_is_streaming = true;
}
if (srslte_rf_recv_with_time_multi(&rf_device, ptr, nof_samples, true,
rxd_time?&rxd_time->full_secs:NULL, rxd_time?&rxd_time->frac_secs:NULL) > 0) { rxd_time?&rxd_time->full_secs:NULL, rxd_time?&rxd_time->frac_secs:NULL) > 0) {
return true; return true;
} else { } else {

@ -104,9 +104,7 @@ void txrx::run_thread()
log_h->info("Starting RX/TX thread nof_prb=%d, sf_len=%d\n",worker_com->cell.nof_prb, sf_len); log_h->info("Starting RX/TX thread nof_prb=%d, sf_len=%d\n",worker_com->cell.nof_prb, sf_len);
// Start streaming RX samples
radio_h->start_rx();
// Set TTI so that first TX is at tti=0 // Set TTI so that first TX is at tti=0
tti = 10235; tti = 10235;

@ -27,7 +27,7 @@
#ifndef UEPHYWORKERCOMMON_H #ifndef UEPHYWORKERCOMMON_H
#define UEPHYWORKERCOMMON_H #define UEPHYWORKERCOMMON_H
#define TX_MODE_CONTINUOUS 0 #define TX_MODE_CONTINUOUS 1
#include <pthread.h> #include <pthread.h>

@ -95,7 +95,6 @@ private:
void reset(); void reset();
void radio_error(); void radio_error();
bool wait_radio_reset();
void set_ue_sync_opts(srslte_ue_sync_t *q, float cfo); void set_ue_sync_opts(srslte_ue_sync_t *q, float cfo);
void run_thread(); void run_thread();
@ -104,14 +103,7 @@ private:
bool set_cell(); bool set_cell();
void cell_search_inc(); void cell_search_inc();
void resync_sfn(bool restart_radio, bool restart_now = false);
bool stop_sync();
void stop_rx();
void start_rx(bool now = false);
bool radio_is_rx;
bool radio_is_resetting;
bool running; bool running;
// Class to run cell search // Class to run cell search
@ -309,10 +301,9 @@ private:
CELL_SELECT, CELL_SELECT,
CELL_MEASURE, CELL_MEASURE,
CELL_CAMP, CELL_CAMP,
IDLE_RX
} phy_state; } phy_state;
bool is_in_idle, is_in_idle_rx; bool is_in_idle;
// Sampling rate mode (find is 1.96 MHz, camp is the full cell BW) // Sampling rate mode (find is 1.96 MHz, camp is the full cell BW)
enum { enum {

@ -325,7 +325,7 @@ private:
static const uint32_t RRC_PLMN_SELECT_TIMEOUT = 10000; static const uint32_t RRC_PLMN_SELECT_TIMEOUT = 10000;
uint32_t select_cell_timeout; uint32_t select_cell_timeout;
static const uint32_t RRC_SELECT_CELL_TIMEOUT = 2000; static const uint32_t RRC_SELECT_CELL_TIMEOUT = 1000;
uint8_t k_rrc_enc[32]; uint8_t k_rrc_enc[32];
uint8_t k_rrc_int[32]; uint8_t k_rrc_int[32];

@ -134,7 +134,6 @@ void phch_recv::reset()
srate_mode = SRATE_NONE; srate_mode = SRATE_NONE;
cell_search_in_progress = false; cell_search_in_progress = false;
current_earfcn = 0; current_earfcn = 0;
radio_is_resetting = false;
sfn_p.reset(); sfn_p.reset();
measure_p.reset(); measure_p.reset();
search_p.reset(); search_p.reset();
@ -145,7 +144,6 @@ void phch_recv::radio_error()
{ {
log_h->error("SYNC: Receiving from radio.\n"); log_h->error("SYNC: Receiving from radio.\n");
phy_state = IDLE; phy_state = IDLE;
radio_is_resetting=true;
// Need to find a method to effectively reset radio, reloading the driver does not work // Need to find a method to effectively reset radio, reloading the driver does not work
//radio_h->reset(); //radio_h->reset();
@ -155,22 +153,12 @@ void phch_recv::radio_error()
exit(-1); exit(-1);
reset(); reset();
radio_is_resetting=false;
} }
void phch_recv::set_cfo(float cfo) { void phch_recv::set_cfo(float cfo) {
srslte_ue_sync_set_cfo_ref(&ue_sync, cfo); srslte_ue_sync_set_cfo_ref(&ue_sync, cfo);
} }
bool phch_recv::wait_radio_reset() {
int cnt=0;
while(cnt < 20 && radio_is_resetting) {
sleep(1);
cnt++;
}
return radio_is_resetting;
}
void phch_recv::set_agc_enable(bool enable) void phch_recv::set_agc_enable(bool enable)
{ {
do_agc = enable; do_agc = enable;
@ -265,24 +253,6 @@ bool phch_recv::set_cell() {
return cell_is_set; return cell_is_set;
} }
void phch_recv::resync_sfn(bool restart_radio, bool restart_now) {
if (restart_radio) {
wait_radio_reset();
stop_rx();
usleep(100000);
}
sfn_p.reset();
search_p.reset();
srslte_ue_sync_reset(&ue_sync);
if (restart_radio) {
start_rx(restart_now);
}
phy_state = CELL_SELECT;
}
void phch_recv::set_earfcn(std::vector<uint32_t> earfcn) { void phch_recv::set_earfcn(std::vector<uint32_t> earfcn) {
this->earfcn = earfcn; this->earfcn = earfcn;
} }
@ -292,35 +262,14 @@ void phch_recv::force_freq(float dl_freq, float ul_freq) {
this->ul_freq = ul_freq; this->ul_freq = ul_freq;
} }
bool phch_recv::stop_sync() {
wait_radio_reset();
if (phy_state == IDLE && is_in_idle) {
return true;
} else {
Info("SYNC: Going to IDLE (state=%d)\n", phy_state);
phy_state = IDLE;
int cnt = 0;
while (!is_in_idle && cnt < 100) {
usleep(10000);
cnt++;
}
if (!is_in_idle) {
Warning("SYNC: Could not go to IDLE (state=%d)\n", phy_state);
}
return is_in_idle;
}
}
void phch_recv::reset_sync() { void phch_recv::reset_sync() {
if (phy_state != CELL_SELECT) { sfn_p.reset();
Warning("SYNC: Resetting sync, cell_search_in_progress=%s\n", cell_search_in_progress?"yes":"no"); search_p.reset();
resync_sfn(false); measure_p.reset();
} else { srslte_ue_sync_reset(&ue_sync);
Warning("SYNC: Trying to reset sync while in cell reselection\n");
} phy_state = CELL_SELECT;
} }
void phch_recv::cell_search_inc() void phch_recv::cell_search_inc()
@ -345,9 +294,6 @@ void phch_recv::cell_search_inc()
void phch_recv::cell_search_next(bool reset) { void phch_recv::cell_search_next(bool reset) {
if (cell_search_in_progress || reset) { if (cell_search_in_progress || reset) {
cell_search_in_progress = false; cell_search_in_progress = false;
if (!stop_sync()) {
log_h->warning("SYNC: Couldn't stop PHY (state=%d)\n", phy_state);
}
if (reset) { if (reset) {
cur_earfcn_index = -1; cur_earfcn_index = -1;
} }
@ -373,9 +319,6 @@ void phch_recv::cell_search_start() {
void phch_recv::cell_search_stop() { void phch_recv::cell_search_stop() {
Info("SYNC: Stopping Cell Search procedure...\n"); Info("SYNC: Stopping Cell Search procedure...\n");
if (!stop_sync()) {
Error("SYNC: Stopping cell search\n");
}
cell_search_in_progress = false; cell_search_in_progress = false;
} }
@ -391,9 +334,9 @@ bool phch_recv::cell_handover(srslte_cell_t cell)
bool ret = false; bool ret = false;
this->cell = cell; this->cell = cell;
Info("Cell HO: Stopping sync with current cell\n"); Info("Cell HO: Stopping sync with current cell\n");
phy_state = IDLE_RX; phy_state = IDLE;
cnt = 0; cnt = 0;
while(!is_in_idle_rx && cnt<20) { while(!is_in_idle && cnt<20) {
usleep(1000); usleep(1000);
cnt++; cnt++;
} }
@ -401,12 +344,11 @@ bool phch_recv::cell_handover(srslte_cell_t cell)
((phch_worker*) workers_pool->get_worker(i))->reset(); ((phch_worker*) workers_pool->get_worker(i))->reset();
} }
worker_com->reset(); worker_com->reset();
//radio_h->tx_end(); if (is_in_idle) {
if (is_in_idle_rx) {
Info("Cell HO: Reconfiguring cell\n"); Info("Cell HO: Reconfiguring cell\n");
if (set_cell()) { if (set_cell()) {
resync_sfn(false);
Info("Cell HO: Synchronizing with new cell\n"); Info("Cell HO: Synchronizing with new cell\n");
phy_state = CELL_SELECT;
ret = true; ret = true;
} else { } else {
log_h->error("Cell HO: Configuring cell PCI=%d\n", cell.id); log_h->error("Cell HO: Configuring cell PCI=%d\n", cell.id);
@ -428,18 +370,12 @@ bool phch_recv::cell_select(uint32_t earfcn, srslte_cell_t cell) {
if (srate_mode != SRATE_CAMP) { if (srate_mode != SRATE_CAMP) {
set_sampling_rate(); set_sampling_rate();
} }
if (phy_state < CELL_SELECT) { phy_state = CELL_SELECT;
resync_sfn(true, false);
}
return true; return true;
} else { } else {
cell_search_in_progress = false; cell_search_in_progress = false;
if (!stop_sync()) {
log_h->warning("Still not in idle\n");
}
if (earfcn != current_earfcn) { if (earfcn != current_earfcn) {
if (set_frequency()) { if (set_frequency()) {
log_h->error("Cell Select: Configuring cell in EARFCN=%d, PCI=%d\n", earfcn, cell.id); log_h->error("Cell Select: Configuring cell in EARFCN=%d, PCI=%d\n", earfcn, cell.id);
@ -453,8 +389,7 @@ bool phch_recv::cell_select(uint32_t earfcn, srslte_cell_t cell) {
if (set_cell()) { if (set_cell()) {
log_h->info("Cell Select: Synchronizing on cell...\n"); log_h->info("Cell Select: Synchronizing on cell...\n");
phy_state = CELL_SELECT;
resync_sfn(true, false);
return true; return true;
} }
return false; return false;
@ -522,22 +457,6 @@ void phch_recv::set_sampling_rate()
} }
} }
void phch_recv::stop_rx() {
if (radio_is_rx) {
Info("SYNC: Stopping RX streaming\n");
radio_h->stop_rx();
}
radio_is_rx = false;
}
void phch_recv::start_rx(bool now) {
if (!radio_is_rx) {
Info("SYNC: Starting RX streaming\n");
radio_h->start_rx(now);
}
radio_is_rx = true;
}
uint32_t phch_recv::get_current_tti() { uint32_t phch_recv::get_current_tti() {
return tti; return tti;
} }
@ -592,18 +511,19 @@ void phch_recv::run_thread()
uint32_t sf_idx = 0; uint32_t sf_idx = 0;
phy_state = IDLE; phy_state = IDLE;
is_in_idle = true; is_in_idle = true;
is_in_idle_rx = false;
cf_t *dummy_buffer[SRSLTE_MAX_PORTS];
for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
dummy_buffer[i] = (cf_t*) malloc(sizeof(cf_t)*SRSLTE_SF_LEN_PRB(100));
}
while (running) while (running)
{ {
if (phy_state != IDLE) { if (phy_state != IDLE) {
is_in_idle = false; is_in_idle = false;
Debug("SYNC: state=%d\n", phy_state);
}
if (phy_state != IDLE_RX) {
is_in_idle_rx = false;
} }
Debug("SYNC: state=%d\n", phy_state);
log_h->step(tti); log_h->step(tti);
log_phy_lib_h->step(tti); log_phy_lib_h->step(tti);
@ -624,7 +544,7 @@ void phch_recv::run_thread()
} }
if (set_cell()) { if (set_cell()) {
set_sampling_rate(); set_sampling_rate();
resync_sfn(true, false); phy_state = CELL_SELECT;
} }
break; break;
case search::CELL_NOT_FOUND: case search::CELL_NOT_FOUND:
@ -659,7 +579,7 @@ void phch_recv::run_thread()
phy_state = CELL_SEARCH; phy_state = CELL_SEARCH;
} else { } else {
log_h->warning("SYNC: Timeout while synchronizing SFN. Reselecting cell\n"); log_h->warning("SYNC: Timeout while synchronizing SFN. Reselecting cell\n");
resync_sfn(false); phy_state = CELL_SELECT;
} }
break; break;
case sfn_sync::IDLE: case sfn_sync::IDLE:
@ -775,28 +695,18 @@ void phch_recv::run_thread()
} }
break; break;
case IDLE: case IDLE:
if (!is_in_idle) { if (radio_h->is_init()) {
stop_rx(); uint32_t nsamples = 1920;
} if (current_srate > 0) {
is_in_idle = true; nsamples = current_srate/1000;
usleep(1000);
break;
case IDLE_RX:
if (!worker) {
worker = (phch_worker *) workers_pool->wait_worker(tti);
}
is_in_idle_rx = true;
if (worker) {
for (uint32_t i = 0; i < SRSLTE_MAX_PORTS; i++) {
buffer[i] = worker->get_buffer(i);
} }
if (!radio_h->rx_now(buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb), NULL)) { if (!radio_h->rx_now(dummy_buffer, nsamples, NULL)) {
Error("SYNC: Receiving from radio while in IDLE_RX\n"); printf("SYNC: Receiving from radio while in IDLE_RX\n");
} }
} else { } else {
// wait_worker() only returns NULL if it's being closed. Quit now to avoid unnecessary loops here usleep(1000);
running = false;
} }
is_in_idle = true;
break; break;
} }
@ -917,7 +827,6 @@ phch_recv::search::ret_code phch_recv::search::run(srslte_cell_t *cell)
p->srate_mode = SRATE_FIND; p->srate_mode = SRATE_FIND;
p->radio_h->set_rx_srate(1.92e6); p->radio_h->set_rx_srate(1.92e6);
} }
p->start_rx();
/* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */ /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */
uint32_t max_peak_cell = 0; uint32_t max_peak_cell = 0;
@ -935,10 +844,8 @@ phch_recv::search::ret_code phch_recv::search::run(srslte_cell_t *cell)
if (ret < 0) { if (ret < 0) {
Error("SYNC: Error decoding MIB: Error searching PSS\n"); Error("SYNC: Error decoding MIB: Error searching PSS\n");
p->stop_rx();
return ERROR; return ERROR;
} else if (ret == 0) { } else if (ret == 0) {
p->stop_rx();
Info("SYNC: Could not find any cell in this frequency\n"); Info("SYNC: Could not find any cell in this frequency\n");
return CELL_NOT_FOUND; return CELL_NOT_FOUND;
} }
@ -966,8 +873,6 @@ phch_recv::search::ret_code phch_recv::search::run(srslte_cell_t *cell)
ret = srslte_ue_mib_sync_decode(&ue_mib_sync, ret = srslte_ue_mib_sync_decode(&ue_mib_sync,
40, 40,
bch_payload, &cell->nof_ports, &sfn_offset); bch_payload, &cell->nof_ports, &sfn_offset);
p->stop_rx();
if (ret == 1) { if (ret == 1) {
srslte_pbch_mib_unpack(bch_payload, cell, NULL); srslte_pbch_mib_unpack(bch_payload, cell, NULL);

@ -1380,7 +1380,7 @@ void phch_worker::update_measurements()
/* Only worker 0 reads the RSSI sensor every ~1-nof_cores s */ /* Only worker 0 reads the RSSI sensor every ~1-nof_cores s */
if (get_id() == 0) { if (get_id() == 0) {
if (rssi_read_cnt) { if (!rssi_read_cnt) {
if (phy->get_radio()->has_rssi() && phy->args->rssi_sensor_enabled) { if (phy->get_radio()->has_rssi() && phy->args->rssi_sensor_enabled) {
phy->last_radio_rssi = phy->get_radio()->get_rssi(); phy->last_radio_rssi = phy->get_radio()->get_rssi();
phy->rx_gain_offset = phy->avg_rssi_dbm - phy->last_radio_rssi + 30; phy->rx_gain_offset = phy->avg_rssi_dbm - phy->last_radio_rssi + 30;

@ -366,7 +366,6 @@ void phy::reset()
workers[i].reset(); workers[i].reset();
} }
workers_common.reset(); workers_common.reset();
workers_common.reset_ul();
} }
uint32_t phy::get_current_tti() uint32_t phy::get_current_tti()

@ -173,7 +173,6 @@ void nas::plmn_search_end() {
} else { } else {
nas_log->info("Finished searching PLMN in current EARFCN set but no networks were found.\n"); nas_log->info("Finished searching PLMN in current EARFCN set but no networks were found.\n");
if (state == EMM_STATE_REGISTERED_INITIATED && plmn_selection == PLMN_NOT_SELECTED) { if (state == EMM_STATE_REGISTERED_INITIATED && plmn_selection == PLMN_NOT_SELECTED) {
sleep(1);
rrc->plmn_search(); rrc->plmn_search();
} }
} }

Loading…
Cancel
Save