diff --git a/lib/examples/cell_measurement.c b/lib/examples/cell_measurement.c index 71c0864c8..3185b74f1 100644 --- a/lib/examples/cell_measurement.c +++ b/lib/examples/cell_measurement.c @@ -239,7 +239,7 @@ int main(int argc, char **argv) { exit(-1); } - INFO("Stopping RF and flushing buffer...\n",0); + INFO("Stopping RF and flushing buffer...\n"); srslte_rf_stop_rx_stream(&rf); srslte_rf_flush_buffer(&rf); diff --git a/lib/examples/cell_search.c b/lib/examples/cell_search.c index 17e75369f..4ea89a0ca 100644 --- a/lib/examples/cell_search.c +++ b/lib/examples/cell_search.c @@ -220,7 +220,7 @@ int main(int argc, char **argv) { INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000); srslte_rf_set_rx_srate(&rf, SRSLTE_CS_SAMP_FREQ); - INFO("Starting receiver...\n", 0); + INFO("Starting receiver...\n"); srslte_rf_start_rx_stream(&rf, false); n = srslte_ue_cellsearch_scan(&cs, found_cells, NULL); diff --git a/lib/examples/pdsch_enodeb.c b/lib/examples/pdsch_enodeb.c index dafff03b9..c95fd50a9 100644 --- a/lib/examples/pdsch_enodeb.c +++ b/lib/examples/pdsch_enodeb.c @@ -528,9 +528,9 @@ int update_radl() { srslte_ra_pdsch_fprint(stdout, &ra_dl, cell.nof_prb); srslte_ra_dl_grant_t dummy_grant; - srslte_ra_nbits_t dummy_nbits; + srslte_ra_nbits_t dummy_nbits[SRSLTE_MAX_CODEWORDS]; srslte_ra_dl_dci_to_grant(&ra_dl, cell.nof_prb, UE_CRNTI, &dummy_grant); - srslte_ra_dl_grant_to_nbits(&dummy_grant, cfi, cell, 0, &dummy_nbits); + srslte_ra_dl_grant_to_nbits(&dummy_grant, cfi, cell, 0, dummy_nbits); srslte_ra_dl_grant_fprint(stdout, &dummy_grant); dummy_grant.sf_type = SRSLTE_SF_NORM; if (pdsch_cfg.mimo_type != SRSLTE_MIMO_TYPE_SINGLE_ANTENNA) { @@ -858,7 +858,7 @@ int main(int argc, char **argv) { if (net_port > 0) { send_data = net_packet_ready; if (net_packet_ready) { - INFO("Transmitting packet\n",0); + INFO("Transmitting packet\n"); } } else { INFO("SF: %d, Generating %d random bits\n", sf_idx, pdsch_cfg.grant.mcs[0].tbs + pdsch_cfg.grant.mcs[1].tbs); diff --git a/lib/examples/pdsch_ue.c b/lib/examples/pdsch_ue.c index 702049f73..8ef620b56 100644 --- a/lib/examples/pdsch_ue.c +++ b/lib/examples/pdsch_ue.c @@ -473,7 +473,7 @@ int main(int argc, char **argv) { exit(-1); } - INFO("Stopping RF and flushing buffer...\r",0); + INFO("Stopping RF and flushing buffer...\r"); } #endif @@ -606,7 +606,7 @@ int main(int argc, char **argv) { srslte_pbch_decode_reset(&ue_mib.pbch); - INFO("\nEntering main loop...\n\n", 0); + INFO("\nEntering main loop...\n\n"); /* Main loop */ while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) { bool acks [SRSLTE_MAX_CODEWORDS] = {false}; @@ -803,6 +803,7 @@ int main(int argc, char **argv) { PRINT_LINE(" nof layers: %d", ue_dl.pdsch_cfg.nof_layers); PRINT_LINE("nof codewords: %d", SRSLTE_RA_DL_GRANT_NOF_TB(&ue_dl.pdsch_cfg.grant)); PRINT_LINE(" CFO: %+7.2f Hz", srslte_ue_sync_get_cfo(&ue_sync)); + PRINT_LINE(" RSRP: %+5.1f dBm | %+5.1f dBm", 10 * log10(rsrp0), 10 * log10(rsrp1)); PRINT_LINE(" SNR: %+5.1f dB | %+5.1f dB", 10 * log10(rsrp0 / noise), 10 * log10(rsrp1 / noise)); PRINT_LINE(" Rb: %6.2f / %6.2f / %6.2f Mbps (net/maximum/processing)", uerate, enodebrate, procrate); PRINT_LINE(" PDCCH-Miss: %5.2f%%", 100 * (1 - (float) ue_dl.nof_detected / nof_trials)); diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index 567203c75..16d21dce8 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -79,7 +79,10 @@ public: printf("%s\n", strlen(used[i]->debug_name)?used[i]->debug_name:"Undefined"); } } - + + bool is_almost_empty() { + return available.size() < capacity/20; + } buffer_t* allocate(const char *debug_name = NULL) { @@ -92,8 +95,9 @@ public: used.push_back(b); available.pop(); - if (available.size() < capacity/20) { + if (is_almost_empty()) { printf("Warning buffer pool capacity is %f %%\n", (float) 100*available.size()/capacity); + print_all_buffers(); } #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED if (debug_name) { diff --git a/lib/include/srslte/common/common.h b/lib/include/srslte/common/common.h index 41a89fb36..ddd558016 100644 --- a/lib/include/srslte/common/common.h +++ b/lib/include/srslte/common/common.h @@ -63,7 +63,7 @@ #define SRSLTE_MAX_BUFFER_SIZE_BYTES 12756 #define SRSLTE_BUFFER_HEADER_OFFSET 1024 -//#define SRSLTE_BUFFER_POOL_LOG_ENABLED +#define SRSLTE_BUFFER_POOL_LOG_ENABLED #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED #define pool_allocate (pool->allocate(__FUNCTION__)) diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 5dc22f7c1..05ab4c5fa 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -10,6 +10,7 @@ #include #include "srslte/common/threads.h" +#include "srslte/srslte.h" namespace srslte { @@ -24,7 +25,8 @@ template class metrics_listener { public: - virtual void set_metrics(metrics_t &m) = 0; + virtual void set_metrics(metrics_t &m, const uint32_t period_usec) = 0; + virtual void stop() = 0; }; template @@ -33,15 +35,19 @@ class metrics_hub : public periodic_thread public: metrics_hub() :m(NULL) - ,report_period_secs(1) + ,sleep_period_start() {} bool init(metrics_interface *m_, float report_period_secs_=1.0) { m = m_; - report_period_secs = report_period_secs_; - start_periodic(report_period_secs*1e6); + // Start with user-default priority + start_periodic(report_period_secs_*1e6, -2); return true; } void stop() { + // stop all listeners + for (uint32_t i=0;istop(); + } thread_cancel(); wait_thread_finish(); } @@ -51,18 +57,24 @@ public: } private: - void run_period() { + void run_period(){ + // get current time and check how long we slept + gettimeofday(&sleep_period_start[2], NULL); + get_time_interval(sleep_period_start); + uint32_t period = sleep_period_start[0].tv_sec*1e6 + sleep_period_start[0].tv_usec; if (m) { metrics_t metric = {}; m->get_metrics(metric); for (uint32_t i=0;iset_metrics(metric); + listeners[i]->set_metrics(metric, period); } } + // store start of sleep period + gettimeofday(&sleep_period_start[1], NULL); } metrics_interface *m; std::vector*> listeners; - float report_period_secs; + struct timeval sleep_period_start[3]; }; } // namespace srslte diff --git a/lib/include/srslte/common/threads.h b/lib/include/srslte/common/threads.h index 077dda72b..e87407870 100644 --- a/lib/include/srslte/common/threads.h +++ b/lib/include/srslte/common/threads.h @@ -30,6 +30,9 @@ #include #include +// Default priority for all threads below UHD threads +#define DEFAULT_PRIORITY 60 + #ifdef __cplusplus extern "C" { #endif // __cplusplus diff --git a/lib/include/srslte/config.h b/lib/include/srslte/config.h index 8a988a971..1e9d27aac 100644 --- a/lib/include/srslte/config.h +++ b/lib/include/srslte/config.h @@ -59,6 +59,9 @@ // cf_t definition typedef _Complex float cf_t; + +#ifdef ENABLE_C16 typedef _Complex short int c16_t; +#endif /* ENABLE_C16 */ #endif // CONFIG_H diff --git a/lib/include/srslte/phy/common/phy_common.h b/lib/include/srslte/phy/common/phy_common.h index c55713cfc..2800e7db6 100644 --- a/lib/include/srslte/phy/common/phy_common.h +++ b/lib/include/srslte/phy/common/phy_common.h @@ -110,7 +110,7 @@ typedef enum {SRSLTE_SF_NORM, SRSLTE_SF_MBSFN} srslte_sf_t; #define SRSLTE_SF_LEN_MAX (SRSLTE_SF_LEN(SRSLTE_SYMBOL_SZ_MAX)) #define SRSLTE_SLOT_LEN_PRB(nof_prb) (SRSLTE_SLOT_LEN(srslte_symbol_sz(nof_prb))) -#define SRSLTE_SF_LEN_PRB(nof_prb) (SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb))) +#define SRSLTE_SF_LEN_PRB(nof_prb) (nof_prb > 0 ? SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb)) : 0) #define SRSLTE_SLOT_LEN_RE(nof_prb, cp) (nof_prb*SRSLTE_NRE*SRSLTE_CP_NSYMB(cp)) #define SRSLTE_SF_LEN_RE(nof_prb, cp) (2*SRSLTE_SLOT_LEN_RE(nof_prb, cp)) diff --git a/lib/include/srslte/phy/phch/cqi.h b/lib/include/srslte/phy/phch/cqi.h index f1f7eb03c..b8cc80ece 100644 --- a/lib/include/srslte/phy/phch/cqi.h +++ b/lib/include/srslte/phy/phch/cqi.h @@ -43,6 +43,7 @@ #define SRSLTE_CQI_MAX_BITS 64 #define SRSLTE_DIF_CQI_MAX_BITS 3 #define SRSLTE_PMI_MAX_BITS 4 +#define SRSLTE_CQI_STR_MAX_CHAR 32 typedef struct { bool configured; diff --git a/lib/include/srslte/phy/phch/ra.h b/lib/include/srslte/phy/phch/ra.h index f4274e416..80097f78e 100644 --- a/lib/include/srslte/phy/phch/ra.h +++ b/lib/include/srslte/phy/phch/ra.h @@ -139,7 +139,11 @@ typedef struct SRSLTE_API { uint8_t tpc_pucch; bool tb_en[2]; - + + bool is_ra_order; + uint32_t ra_preamble; + uint32_t ra_mask_idx; + bool dci_is_1a; bool dci_is_1c; } srslte_ra_dl_dci_t; diff --git a/lib/include/srslte/phy/utils/simd.h b/lib/include/srslte/phy/utils/simd.h index 7ea203290..e22a9ef09 100644 --- a/lib/include/srslte/phy/utils/simd.h +++ b/lib/include/srslte/phy/utils/simd.h @@ -150,7 +150,10 @@ #endif /* LV_HAVE_AVX2 */ #endif /* LV_HAVE_AVX512 */ - +#ifndef ENABLE_C16 +#undef SRSLTE_SIMD_C16_SIZE +#define SRSLTE_SIMD_C16_SIZE 0 +#endif /* ENABLE_C16 */ #if SRSLTE_SIMD_F_SIZE diff --git a/lib/include/srslte/phy/utils/vector_simd.h b/lib/include/srslte/phy/utils/vector_simd.h index 31725edb3..49268ca43 100644 --- a/lib/include/srslte/phy/utils/vector_simd.h +++ b/lib/include/srslte/phy/utils/vector_simd.h @@ -106,7 +106,9 @@ SRSLTE_API cf_t srslte_vec_dot_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, SRSLTE_API cf_t srslte_vec_dot_prod_ccc_simd(const cf_t *x, const cf_t *y, const int len); +#ifdef ENABLE_C16 SRSLTE_API c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t *x, const c16_t *y, const int len); +#endif /* ENABLE_C16 */ SRSLTE_API int srslte_vec_dot_prod_sss_simd(const int16_t *x, const int16_t *y, const int len); diff --git a/lib/include/srslte/upper/pdcp_entity.h b/lib/include/srslte/upper/pdcp_entity.h index 186da3767..0894b6578 100644 --- a/lib/include/srslte/upper/pdcp_entity.h +++ b/lib/include/srslte/upper/pdcp_entity.h @@ -61,7 +61,6 @@ static const char pdcp_d_c_text[PDCP_D_C_N_ITEMS][20] = {"Control PDU", * Common interface for all PDCP entities ***************************************************************************/ class pdcp_entity - :public thread { public: pdcp_entity(); @@ -71,7 +70,6 @@ public: srslte::log *log_, uint32_t lcid_, srslte_pdcp_config_t cfg_); - void stop(); void reset(); void reestablish(); @@ -97,10 +95,6 @@ private: srsue::rrc_interface_pdcp *rrc; srsue::gw_interface_pdcp *gw; - static const int PDCP_THREAD_PRIO = 7; - srslte::msg_queue rx_pdu_queue; - bool running; - bool active; uint32_t lcid; srslte_pdcp_config_t cfg; @@ -134,8 +128,6 @@ private: uint32_t ct_len, uint8_t *msg); - void run_thread(); - uint8_t get_bearer_id(uint8_t lcid); }; diff --git a/lib/src/asn1/liblte_s1ap.cc b/lib/src/asn1/liblte_s1ap.cc index 31c7391ab..530767c2f 100644 --- a/lib/src/asn1/liblte_s1ap.cc +++ b/lib/src/asn1/liblte_s1ap.cc @@ -2243,6 +2243,12 @@ LIBLTE_ERROR_ENUM liblte_s1ap_pack_imsi( if(ie != NULL && ptr != NULL) { + // max length of IE buffer is 32, so limit + if (ie->n_octets > 31) { + printf("Length in struct exceeds buffer (%d > 31).\n", ie->n_octets); + return LIBLTE_ERROR_ENCODE_FAIL; + } + // Dynamic octet string - IMSI // Length if(ie->n_octets < 128) { diff --git a/lib/src/common/threads.c b/lib/src/common/threads.c index 0533aa1b6..b6fa31778 100644 --- a/lib/src/common/threads.c +++ b/lib/src/common/threads.c @@ -67,6 +67,20 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void fprintf(stderr, "Error not enough privileges to set Scheduling priority\n"); } attr_enable = true; + } else if (prio_offset == -1) { + param.sched_priority = sched_get_priority_max(SCHED_FIFO) - DEFAULT_PRIORITY; + pthread_attr_init(&attr); + if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) { + perror("pthread_attr_setinheritsched"); + } + if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) { + perror("pthread_attr_setschedpolicy"); + } + if (pthread_attr_setschedparam(&attr, ¶m)) { + perror("pthread_attr_setschedparam"); + fprintf(stderr, "Error not enough privileges to set Scheduling priority\n"); + } + attr_enable = true; } else if (prio_offset == -2) { param.sched_priority = 0; pthread_attr_init(&attr); diff --git a/lib/src/phy/common/phy_common.c b/lib/src/phy/common/phy_common.c index b4f5e122b..489d6b3a5 100644 --- a/lib/src/phy/common/phy_common.c +++ b/lib/src/phy/common/phy_common.c @@ -66,7 +66,7 @@ bool srslte_cell_isvalid(srslte_cell_t *cell) { } void srslte_cell_fprint(FILE *stream, srslte_cell_t *cell, uint32_t sfn) { - fprintf(stream, " - Cell ID: %d\n", cell->id); + fprintf(stream, " - PCI: %d\n", cell->id); fprintf(stream, " - Nof ports: %d\n", cell->nof_ports); fprintf(stream, " - CP: %s\n", srslte_cp_string(cell->cp)); fprintf(stream, " - PRB: %d\n", cell->nof_prb); diff --git a/lib/src/phy/fec/turbodecoder_simd.c b/lib/src/phy/fec/turbodecoder_simd.c index a32d52962..d8a5c1716 100644 --- a/lib/src/phy/fec/turbodecoder_simd.c +++ b/lib/src/phy/fec/turbodecoder_simd.c @@ -133,7 +133,7 @@ void map_simd_dec(map_gen_t * h, int16_t * input[SRSLTE_TDEC_MAX_NPAR], int16_t { uint32_t nof_cb = 1; - int16_t *outptr[SRSLTE_TDEC_MAX_NPAR]; + int16_t *outptr[SRSLTE_TDEC_MAX_NPAR] = { NULL, NULL }; // Compute branch metrics switch(cb_mask) { diff --git a/lib/src/phy/fec/turbodecoder_sse_inter.c b/lib/src/phy/fec/turbodecoder_sse_inter.c index bb1168368..d75c8a649 100644 --- a/lib/src/phy/fec/turbodecoder_sse_inter.c +++ b/lib/src/phy/fec/turbodecoder_sse_inter.c @@ -85,6 +85,10 @@ void map_sse_inter_beta(srslte_tdec_simd_inter_t * s, int16_t *input, int16_t *p __m128i *outputPtr = (__m128i*) output; __m128i *alphaPtr = (__m128i*) s->alpha; + for (int i = 0; i < 8; i++) { + old[i] = _mm_set1_epi16(0); + } + for (int k = end - 1; k >= 0; k--) { x = _mm_load_si128(inputPtr++); y = _mm_load_si128(parityPtr++); diff --git a/lib/src/phy/io/filesource.c b/lib/src/phy/io/filesource.c index 048ecb584..1324bf2b0 100644 --- a/lib/src/phy/io/filesource.c +++ b/lib/src/phy/io/filesource.c @@ -50,7 +50,9 @@ void srslte_filesource_free(srslte_filesource_t *q) { } void srslte_filesource_seek(srslte_filesource_t *q, int pos) { - fseek(q->f, pos, SEEK_SET); + if (!fseek(q->f, pos, SEEK_SET)){ + perror("srslte_filesource_seek"); + } } int read_complex_f(FILE *f, _Complex float *y) { diff --git a/lib/src/phy/mimo/precoding.c b/lib/src/phy/mimo/precoding.c index a78c13056..6d50e3ed2 100644 --- a/lib/src/phy/mimo/precoding.c +++ b/lib/src/phy/mimo/precoding.c @@ -2205,7 +2205,9 @@ int srslte_precoding_pmi_select_2l_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT } /* Divide average by noise */ - sinr_list[i] /= count; + if (count) { + sinr_list[i] /= count; + } if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; @@ -2326,7 +2328,9 @@ int srslte_precoding_pmi_select_2l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT } /* Divide average by noise */ - sinr_list[i] /= count; + if (count) { + sinr_list[i] /= count; + } if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; @@ -2473,7 +2477,9 @@ int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT } /* Divide average by noise */ - sinr_list[i] /= count; + if (count) { + sinr_list[i] /= count; + } if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; @@ -2545,7 +2551,11 @@ float srslte_precoding_2x2_cn_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], u count++; } - return cn_avg/count; + if (count) { + cn_avg /= count; + } + + return cn_avg; } /* Computes the condition number for a given number of antennas, diff --git a/lib/src/phy/mimo/test/pmi_select_test.c b/lib/src/phy/mimo/test/pmi_select_test.c index c7e5b5c8e..a40723d34 100644 --- a/lib/src/phy/mimo/test/pmi_select_test.c +++ b/lib/src/phy/mimo/test/pmi_select_test.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) { /* Condition number */ if (srslte_precoding_cn(h, 2, 2, nof_symbols, &cn)) { - ERROR("Test case %d condition number returned error\n"); + ERROR("Test case %d condition number returned error\n", c + 1); goto clean; } diff --git a/lib/src/phy/mimo/test/precoder_test.c b/lib/src/phy/mimo/test/precoder_test.c index 589e3d51c..1054545c3 100644 --- a/lib/src/phy/mimo/test/precoder_test.c +++ b/lib/src/phy/mimo/test/precoder_test.c @@ -42,7 +42,7 @@ int nof_symbols = 1000; uint32_t codebook_idx = 0; int nof_layers = 1, nof_tx_ports = 1, nof_rx_ports = 1, nof_re = 1; char *mimo_type_name = NULL; -char decoder_type_name [16] = "zf"; +char decoder_type_name [17] = "zf"; float snr_db = 100.0f; float scaling = 0.1f; @@ -56,7 +56,7 @@ void usage(char *prog) { printf("\t-g Scaling [Default %.1f]*\n", scaling); printf("\t-d decoder type [zf|mmse] [Default %s]\n", decoder_type_name); printf("\n"); - printf("* Performance test example:\n\t for snr in {0..20..1}; do ./precoding_test -m single -s $snr; done; \n\n", decoder_type_name); + printf("* Performance test example:\n\t for snr in {0..20..1}; do ./precoding_test -m single -s $snr; done; \n\n"); } void parse_args(int argc, char **argv) { @@ -82,7 +82,8 @@ void parse_args(int argc, char **argv) { codebook_idx = (uint32_t) atoi(argv[optind]); break; case 'd': - strncpy(decoder_type_name, argv[optind], 16); + strncpy(decoder_type_name, argv[optind], 15); + decoder_type_name[15] = 0; break; case 's': snr_db = (float) atof(argv[optind]); diff --git a/lib/src/phy/phch/cqi.c b/lib/src/phy/phch/cqi.c index a115bcd28..522cdf10b 100644 --- a/lib/src/phy/phch/cqi.c +++ b/lib/src/phy/phch/cqi.c @@ -383,7 +383,7 @@ bool srslte_ri_send(uint32_t I_cqi_pmi, uint32_t I_ri, uint32_t tti) { return false; } - if (M_ri) { + if (M_ri && N_p) { if ((tti - N_offset_p + N_offset_ri) % (N_p * M_ri) == 0) { return true; } @@ -456,8 +456,16 @@ int srslte_cqi_hl_get_no_subbands(int nof_prb) void srslte_cqi_to_str(const uint8_t *cqi_value, int cqi_len, char *str, int str_len) { int i = 0; - for (i = 0; i < cqi_len && i < (str_len - 1); i++) { + + for (i = 0; i < cqi_len && i < (str_len - 5); i++) { str[i] = (cqi_value[i] == 0)?(char)'0':(char)'1'; } + + if (i == (str_len - 5)) { + str[i++] = '.'; + str[i++] = '.'; + str[i++] = '.'; + str[i++] = (cqi_value[cqi_len - 1] == 0)?(char)'0':(char)'1'; + } str[i] = '\0'; } diff --git a/lib/src/phy/phch/dci.c b/lib/src/phy/phch/dci.c index 7d4ccd1ea..6766ca5f0 100644 --- a/lib/src/phy/phch/dci.c +++ b/lib/src/phy/phch/dci.c @@ -71,12 +71,14 @@ int srslte_dci_msg_to_dl_grant(srslte_dci_msg_t *msg, uint16_t msg_rnti, //fprintf(stderr, "Can't unpack DCI message %s (%d)\n", srslte_dci_format_string(msg->format), msg->format); return ret; } - - srslte_ra_dl_dci_to_grant(dl_dci, nof_prb, msg_rnti, grant); - if (SRSLTE_VERBOSE_ISINFO()) { - srslte_ra_pdsch_fprint(stdout, dl_dci, nof_prb); - srslte_ra_dl_grant_fprint(stdout, grant); + if (!dl_dci->is_ra_order) { + srslte_ra_dl_dci_to_grant(dl_dci, nof_prb, msg_rnti, grant); + + if (SRSLTE_VERBOSE_ISINFO()) { + srslte_ra_pdsch_fprint(stdout, dl_dci, nof_prb); + srslte_ra_dl_grant_fprint(stdout, grant); + } } ret = SRSLTE_SUCCESS; @@ -391,7 +393,7 @@ uint32_t srslte_dci_dl_info(char *info_str, uint32_t len, srslte_ra_dl_dci_t *dc if (dci_msg->tb_en[0]) { n += snprintf(&info_str[n], len-n, "%d", dci_msg->mcs_idx); if (dci_msg->tb_en[1]) { - n += snprintf(&info_str[n], len-n, ","); + n += snprintf(&info_str[n], len-n, "/"); } else { n += snprintf(&info_str[n], len-n, "}, "); } @@ -403,7 +405,7 @@ uint32_t srslte_dci_dl_info(char *info_str, uint32_t len, srslte_ra_dl_dci_t *dc if (dci_msg->tb_en[0]) { n += snprintf(&info_str[n], len-n, "%d", dci_msg->rv_idx); if (dci_msg->tb_en[1]) { - n += snprintf(&info_str[n], len-n, ","); + n += snprintf(&info_str[n], len-n, "/"); } else { n += snprintf(&info_str[n], len-n, "}, "); } @@ -415,7 +417,7 @@ uint32_t srslte_dci_dl_info(char *info_str, uint32_t len, srslte_ra_dl_dci_t *dc if (dci_msg->tb_en[0]) { n += snprintf(&info_str[n], len-n, "%d", dci_msg->ndi); if (dci_msg->tb_en[1]) { - n += snprintf(&info_str[n], len-n, ","); + n += snprintf(&info_str[n], len-n, "/"); } else { n += snprintf(&info_str[n], len-n, "}, "); } @@ -575,7 +577,7 @@ int dci_format0_unpack(srslte_dci_msg_t *msg, srslte_ra_ul_dci_t *data, uint32_t return SRSLTE_ERROR; } if (*y++ != 0) { - INFO("DCI message is Format1A\n", 0); + INFO("DCI message is Format1A\n"); return SRSLTE_ERROR; } if (*y++ == 0) { @@ -834,7 +836,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 } if (*y++ != 1) { - INFO("DCI message is Format0\n", 0); + INFO("DCI message is Format0\n"); return SRSLTE_ERROR; } @@ -844,21 +846,31 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 if (*y == 0) { int nof_bits = riv_nbits(nof_prb); int i=0; - while(inof_bits-1 && y[i] == 0) { i++; } if (i == msg->nof_bits-1) { - //printf("Received a Format1A RA PDCCH order. Not implemented!\n"); - return SRSLTE_ERROR; + // This is a Random access order + y+=1+nof_bits; + + data->is_ra_order = true; + data->ra_preamble = srslte_bit_pack(&y, 6); + data->ra_mask_idx = srslte_bit_pack(&y, 4); + + return SRSLTE_SUCCESS; } } } + data->is_ra_order = false; + data->alloc_type = SRSLTE_RA_ALLOC_TYPE2; data->type2_alloc.mode = *y++; diff --git a/lib/src/phy/phch/pdcch.c b/lib/src/phy/phch/pdcch.c index ca8480bc6..969b53cf7 100644 --- a/lib/src/phy/phch/pdcch.c +++ b/lib/src/phy/phch/pdcch.c @@ -557,7 +557,7 @@ int srslte_pdcch_dci_encode(srslte_pdcch_t *q, uint8_t *data, uint8_t *e, uint32 srslte_pdcch_dci_encode_conv(q, data, nof_bits, tmp, rnti); - DEBUG("CConv output: ", 0); + DEBUG("CConv output: "); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, tmp, 3 * (nof_bits + 16)); } @@ -617,7 +617,7 @@ int srslte_pdcch_encode(srslte_pdcch_t *q, srslte_dci_msg_t *msg, srslte_dci_loc srslte_scrambling_b_offset(&q->seq[nsubframe], q->e, 72 * location.ncce, e_bits); - DEBUG("Scrambling output: ", 0); + DEBUG("Scrambling output: "); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->e, e_bits); } diff --git a/lib/src/phy/phch/pdsch.c b/lib/src/phy/phch/pdsch.c index fbf0860be..1cf4af4e2 100644 --- a/lib/src/phy/phch/pdsch.c +++ b/lib/src/phy/phch/pdsch.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "prb_dl.h" #include "srslte/phy/phch/pdsch.h" @@ -656,8 +658,8 @@ int srslte_pdsch_decode(srslte_pdsch_t *q, { uint32_t nof_tb = SRSLTE_RA_DL_GRANT_NOF_TB(&cfg->grant); - INFO("Decoding PDSCH SF: %d, RNTI: 0x%x, NofSymbols: %d, C_prb=%d, mimo_type=%d, nof_layers=%d, nof_tb=%d\n", - cfg->sf_idx, rnti, cfg->nbits[0].nof_re, cfg->grant.nof_prb, cfg->nof_layers, nof_tb); + INFO("Decoding PDSCH SF: %d, RNTI: 0x%x, NofSymbols: %d, C_prb=%d, mimo_type=%s, nof_layers=%d, nof_tb=%d\n", + cfg->sf_idx, rnti, cfg->nbits[0].nof_re, cfg->grant.nof_prb, srslte_mod_string(cfg->grant.mcs->mod), cfg->nof_layers, nof_tb); // Extract Symbols and Channel Estimates for (int j=0;jnof_rx_antennas;j++) { diff --git a/lib/src/phy/phch/phich.c b/lib/src/phy/phch/phich.c index 37b8e1b7a..6990d69e2 100644 --- a/lib/src/phy/phch/phich.c +++ b/lib/src/phy/phch/phich.c @@ -148,7 +148,7 @@ uint8_t srslte_phich_ack_decode(float bits[SRSLTE_PHICH_NBITS], float *distance) uint8_t index=0; if (SRSLTE_VERBOSE_ISINFO()) { - INFO("Received bits: ", 0); + INFO("Received bits: "); srslte_vec_fprint_f(stdout, bits, SRSLTE_PHICH_NBITS); } @@ -244,8 +244,8 @@ int srslte_phich_decode(srslte_phich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], srslte_predecoding_diversity_multi(q_sf_symbols, q_ce, x, q->nof_rx_antennas, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB, 1.0f); srslte_layerdemap_diversity(x, q->d0, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB / q->cell.nof_ports); } - DEBUG("Recv!!: \n", 0); - DEBUG("d0: ", 0); + DEBUG("Recv!!: \n"); + DEBUG("d0: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d0, SRSLTE_PHICH_MAX_NSYMB); @@ -265,7 +265,7 @@ int srslte_phich_decode(srslte_phich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], memcpy(q->d, q->d0, SRSLTE_PHICH_MAX_NSYMB * sizeof(cf_t)); } - DEBUG("d: ", 0); + DEBUG("d: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d, SRSLTE_PHICH_EXT_MSYMB); @@ -290,7 +290,7 @@ int srslte_phich_decode(srslte_phich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], } } - DEBUG("z: ", 0); + DEBUG("z: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->z, SRSLTE_PHICH_NBITS); @@ -353,7 +353,7 @@ int srslte_phich_encode(srslte_phich_t *q, uint8_t ack, uint32_t ngroup, uint32_ srslte_mod_modulate(&q->mod, q->data, q->z, SRSLTE_PHICH_NBITS); - DEBUG("data: ", 0); + DEBUG("data: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->z, SRSLTE_PHICH_NBITS); @@ -370,7 +370,7 @@ int srslte_phich_encode(srslte_phich_t *q, uint8_t ack, uint32_t ngroup, uint32_ } } - DEBUG("d: ", 0); + DEBUG("d: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d, SRSLTE_PHICH_EXT_MSYMB); @@ -397,7 +397,7 @@ int srslte_phich_encode(srslte_phich_t *q, uint8_t ack, uint32_t ngroup, uint32_ memcpy(q->d0, q->d, SRSLTE_PHICH_MAX_NSYMB * sizeof(cf_t)); } - DEBUG("d0: ", 0); + DEBUG("d0: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d0, SRSLTE_PHICH_MAX_NSYMB); diff --git a/lib/src/phy/phch/ra.c b/lib/src/phy/phch/ra.c index e1eaa5de2..7107ab2f6 100644 --- a/lib/src/phy/phch/ra.c +++ b/lib/src/phy/phch/ra.c @@ -555,7 +555,7 @@ static int dl_dci_to_grant_mcs(srslte_ra_dl_dci_t *dci, srslte_ra_dl_grant_t *gr } void srslte_ra_dl_grant_to_nbits(srslte_ra_dl_grant_t *grant, uint32_t cfi, srslte_cell_t cell, uint32_t sf_idx, - srslte_ra_nbits_t nbits [SRSLTE_MAX_CODEWORDS]) + srslte_ra_nbits_t nbits[SRSLTE_MAX_CODEWORDS]) { // Compute number of RE for (int i = 0; i < SRSLTE_MAX_TB; i++) { diff --git a/lib/src/phy/phch/sch.c b/lib/src/phy/phch/sch.c index a2da3195c..3a8285f73 100644 --- a/lib/src/phy/phch/sch.c +++ b/lib/src/phy/phch/sch.c @@ -494,7 +494,7 @@ static int decode_tb(srslte_sch_t *q, ((uint32_t) data[cb_segm->tbs/8+2]); if (par_rx == par_tx && par_rx) { - INFO("TB decoded OK\n",0); + INFO("TB decoded OK\n"); return SRSLTE_SUCCESS; } else { INFO("Error in TB parity: par_tx=0x%x, par_rx=0x%x\n", par_tx, par_rx); diff --git a/lib/src/phy/phch/test/pbch_file_test.c b/lib/src/phy/phch/test/pbch_file_test.c index 2ca12e4c9..6b79db422 100644 --- a/lib/src/phy/phch/test/pbch_file_test.c +++ b/lib/src/phy/phch/test/pbch_file_test.c @@ -154,7 +154,7 @@ int base_init() { return -1; } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } diff --git a/lib/src/phy/phch/test/pcfich_file_test.c b/lib/src/phy/phch/test/pcfich_file_test.c index e92d6c7ba..98ff829be 100644 --- a/lib/src/phy/phch/test/pcfich_file_test.c +++ b/lib/src/phy/phch/test/pcfich_file_test.c @@ -170,7 +170,7 @@ int base_init() { return -1; } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } @@ -232,7 +232,7 @@ int main(int argc, char **argv) { /* Get channel estimates for each port */ srslte_chest_dl_estimate(&chest, fft_buffer, ce, 0); - INFO("Decoding PCFICH\n", 0); + INFO("Decoding PCFICH\n"); n = srslte_pcfich_decode(&pcfich, fft_buffer, ce, srslte_chest_dl_get_noise_estimate(&chest), 0, &cfi, &cfi_corr); diff --git a/lib/src/phy/phch/test/pdcch_file_test.c b/lib/src/phy/phch/test/pdcch_file_test.c index 5482d9f98..2f0ae30cc 100644 --- a/lib/src/phy/phch/test/pdcch_file_test.c +++ b/lib/src/phy/phch/test/pdcch_file_test.c @@ -180,7 +180,7 @@ int base_init() { exit(-1); } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } @@ -244,7 +244,7 @@ int main(int argc, char **argv) { return -1; } if (rnti == SRSLTE_SIRNTI) { - INFO("Initializing common search space for SI-RNTI\n",0); + INFO("Initializing common search space for SI-RNTI\n"); nof_locations = srslte_pdcch_common_locations(&pdcch, locations, MAX_CANDIDATES, cfi); } else { INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti); diff --git a/lib/src/phy/phch/test/pdsch_pdcch_file_test.c b/lib/src/phy/phch/test/pdsch_pdcch_file_test.c index ba662bc49..76f48b959 100644 --- a/lib/src/phy/phch/test/pdsch_pdcch_file_test.c +++ b/lib/src/phy/phch/test/pdsch_pdcch_file_test.c @@ -148,7 +148,7 @@ int base_init() { srslte_ue_dl_set_rnti(&ue_dl, rnti); - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } diff --git a/lib/src/phy/phch/test/pdsch_test.c b/lib/src/phy/phch/test/pdsch_test.c index 0b18d8b10..4053176d9 100644 --- a/lib/src/phy/phch/test/pdsch_test.c +++ b/lib/src/phy/phch/test/pdsch_test.c @@ -51,7 +51,7 @@ srslte_cell_t cell = { SRSLTE_PHICH_R_1_6 // PHICH resources }; -char mimo_type_str [32] = "single"; +char mimo_type_str[32] = "single"; srslte_mimo_type_t mimo_type = SRSLTE_MIMO_TYPE_SINGLE_ANTENNA; uint32_t cfi = 1; uint32_t mcs[SRSLTE_MAX_CODEWORDS] = {0, 0}; @@ -111,7 +111,8 @@ void parse_args(int argc, char **argv) { cfi = atoi(argv[optind]); break; case 'x': - strncpy(mimo_type_str, argv[optind], 32); + strncpy(mimo_type_str, argv[optind], sizeof(mimo_type_str)-1); + mimo_type_str[sizeof(mimo_type_str)-1] = 0; break; case 'p': pmi = (uint32_t) atoi(argv[optind]); diff --git a/lib/src/phy/phch/test/phich_file_test.c b/lib/src/phy/phch/test/phich_file_test.c index 65f7ce9c0..45eec4921 100644 --- a/lib/src/phy/phch/test/phich_file_test.c +++ b/lib/src/phy/phch/test/phich_file_test.c @@ -194,7 +194,7 @@ int base_init() { return -1; } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } @@ -257,7 +257,7 @@ int main(int argc, char **argv) { /* Get channel estimates for each port */ srslte_chest_dl_estimate(&chest, fft_buffer, ce, 0); - INFO("Decoding PHICH\n", 0); + INFO("Decoding PHICH\n"); /* Receive all PHICH groups and sequence numbers */ for (ngroup=0;ngrouptmp_cqi, data, sizeof(uint8_t) * nof_bits); srslte_crc_attach(&q->crc, q->tmp_cqi, nof_bits); - DEBUG("cqi_crc_tx=", 0); + DEBUG("cqi_crc_tx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8); } srslte_convcoder_encode(&encoder, q->tmp_cqi, q->encoded_cqi, nof_bits + 8); - DEBUG("cconv_tx=", 0); + DEBUG("cconv_tx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->encoded_cqi, 3 * (nof_bits + 8)); } @@ -400,14 +400,14 @@ int decode_cqi_long(srslte_uci_cqi_pusch_t *q, int16_t *q_bits, uint32_t Q, srslte_rm_conv_rx_s(q_bits, Q, q->encoded_cqi_s, 3 * (nof_bits + 8)); - DEBUG("cconv_rx=", 0); + DEBUG("cconv_rx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_s(stdout, q->encoded_cqi_s, 3 * (nof_bits + 8)); } srslte_viterbi_decode_s(&q->viterbi, q->encoded_cqi_s, q->tmp_cqi, nof_bits + 8); - DEBUG("cqi_crc_rx=", 0); + DEBUG("cqi_crc_rx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8); } diff --git a/lib/src/phy/resampling/resample_arb.c b/lib/src/phy/resampling/resample_arb.c index 441e8c0dc..5cea28ed2 100644 --- a/lib/src/phy/resampling/resample_arb.c +++ b/lib/src/phy/resampling/resample_arb.c @@ -150,7 +150,7 @@ int srslte_resample_arb_compute(srslte_resample_arb_t *q, cf_t *input, cf_t *out res1 = srslte_resample_arb_dot_prod(filter_input, srslte_resample_arb_polyfilt[idx], SRSLTE_RESAMPLE_ARB_M); if(q->interpolate){ - res2 = srslte_resample_arb_dot_prod(filter_input, srslte_resample_arb_polyfilt[(idx%SRSLTE_RESAMPLE_ARB_N)+1], SRSLTE_RESAMPLE_ARB_M); + res2 = srslte_resample_arb_dot_prod(filter_input, srslte_resample_arb_polyfilt[(idx+1)%SRSLTE_RESAMPLE_ARB_N], SRSLTE_RESAMPLE_ARB_M); } if(idx == SRSLTE_RESAMPLE_ARB_N){ diff --git a/lib/src/phy/rf/rf_soapy_imp.c b/lib/src/phy/rf/rf_soapy_imp.c index 7421275b5..9a45ff8f1 100644 --- a/lib/src/phy/rf/rf_soapy_imp.c +++ b/lib/src/phy/rf/rf_soapy_imp.c @@ -97,7 +97,11 @@ char* rf_soapy_devname(void* h) bool rf_soapy_rx_wait_lo_locked(void *h) { - printf("TODO: implement rf_soapy_rx_wait_lo_locked()\n"); + rf_soapy_handler_t *handler = (rf_soapy_handler_t*)h; + char *ret = SoapySDRDevice_readChannelSensor(handler->device, SOAPY_SDR_RX, 0, "lo_locked"); + if (ret != NULL) { + return (strcmp(ret, "true") == 0 ? true : false); + } return true; } @@ -197,14 +201,13 @@ int rf_soapy_open_multi(char *args, void **h, uint32_t nof_rx_antennas) printf("No Soapy devices found.\n"); return SRSLTE_ERROR; } - char* devname; + char* devname = NULL; for (size_t i = 0; i < length; i++) { - printf("Soapy has Found device #%d: ", (int)i); + printf("Soapy has found device #%d: ", (int)i); for (size_t j = 0; j < soapy_args[i].size; j++) { printf("%s=%s, ", soapy_args[i].keys[j], soapy_args[i].vals[j]); if(!strcmp(soapy_args[i].keys[j],"name") && !strcmp(soapy_args[i].vals[j], "LimeSDR-USB")){ devname = DEVNAME_LIME; - } } printf("\n"); @@ -212,7 +215,7 @@ int rf_soapy_open_multi(char *args, void **h, uint32_t nof_rx_antennas) SoapySDRDevice *sdr = SoapySDRDevice_make(&(soapy_args[0])); if (sdr == NULL) { - printf("failed to create SOAPY object\n"); + printf("Failed to create Soapy object\n"); return SRSLTE_ERROR; } @@ -225,7 +228,7 @@ int rf_soapy_open_multi(char *args, void **h, uint32_t nof_rx_antennas) handler->rx_stream_active = false; handler->devname = devname; if(SoapySDRDevice_getNumChannels(handler->device,SOAPY_SDR_RX) > 0){ - printf("setting up RX stream\n"); + printf("Setting up RX stream\n"); if(SoapySDRDevice_setupStream(handler->device, &(handler->rxStream), SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { printf("Rx setupStream fail: %s\n", SoapySDRDevice_lastError()); return SRSLTE_ERROR; @@ -233,19 +236,27 @@ int rf_soapy_open_multi(char *args, void **h, uint32_t nof_rx_antennas) } if(SoapySDRDevice_getNumChannels(handler->device,SOAPY_SDR_TX) > 0){ - printf("setting up TX stream\n"); + printf("Setting up TX stream\n"); if (SoapySDRDevice_setupStream(handler->device, &(handler->txStream), SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { printf("Tx setupStream fail: %s\n", SoapySDRDevice_lastError()); return SRSLTE_ERROR; } } + + // list device sensors size_t sensor_length; char** sensors; sensors = SoapySDRDevice_listSensors(handler->device, &sensor_length); - for(int i = 0; i < sensor_length;i++) - { - printf("available sensors are : \n"); - puts(sensors[i]); + printf("Available device sensors: \n"); + for(int i = 0; i < sensor_length; i++) { + printf(" - %s\n", sensors[i]); + } + + // list channel sensors + sensors = SoapySDRDevice_listChannelSensors(handler->device, SOAPY_SDR_RX, 0, &sensor_length); + printf("Available sensors for RX channel 0: \n"); + for(int i = 0; i < sensor_length; i++) { + printf(" - %s\n", sensors[i]); } return SRSLTE_SUCCESS; @@ -399,7 +410,7 @@ void rf_soapy_get_time(void *h, time_t *secs, double *frac_secs) //TODO: add multi-channel support int rf_soapy_recv_with_time_multi(void *h, - void **data, + void *data[SRSLTE_MAX_PORTS], uint32_t nsamples, bool blocking, time_t *secs, @@ -408,6 +419,7 @@ int rf_soapy_recv_with_time_multi(void *h, rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; int flags; //flags set by receive operation int num_channels = 1; // temp + const long timeoutUs = 1000000; // arbitrarily chosen int trials = 0; int ret = 0; @@ -424,7 +436,7 @@ int rf_soapy_recv_with_time_multi(void *h, cf_t *data_c = (cf_t*) data[i]; buffs_ptr[i] = &data_c[n]; } - ret = SoapySDRDevice_readStream(handler->device, handler->rxStream, buffs_ptr, rx_samples, &flags, &timeNs, 1000000); + ret = SoapySDRDevice_readStream(handler->device, handler->rxStream, buffs_ptr, rx_samples, &flags, &timeNs, timeoutUs); if(ret < 0) { // continue when getting overflows if (ret == SOAPY_SDR_OVERFLOW) { @@ -446,8 +458,6 @@ int rf_soapy_recv_with_time_multi(void *h, n += ret; trials++; } while (n < nsamples && trials < 100); - - return n; } diff --git a/lib/src/phy/rf/rf_uhd_imp.c b/lib/src/phy/rf/rf_uhd_imp.c index c9c3c4866..0fc70c547 100644 --- a/lib/src/phy/rf/rf_uhd_imp.c +++ b/lib/src/phy/rf/rf_uhd_imp.c @@ -562,7 +562,10 @@ int rf_uhd_open_multi(char *args, void **h, uint32_t nof_channels) perror("pthread_create"); return -1; } - + + /* Restore priorities */ + uhd_set_thread_priority(0, false); + return 0; } else { return SRSLTE_ERROR_INVALID_INPUTS; @@ -708,13 +711,12 @@ int rf_uhd_recv_with_time(void *h, } int rf_uhd_recv_with_time_multi(void *h, - void **data, + void *data[SRSLTE_MAX_PORTS], uint32_t nsamples, bool blocking, time_t *secs, double *frac_secs) { - rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h; uhd_rx_metadata_handle *md = &handler->rx_md_first; size_t rxd_samples = 0; diff --git a/lib/src/phy/rf/rf_utils.c b/lib/src/phy/rf/rf_utils.c index ea016c721..4587ebdcb 100644 --- a/lib/src/phy/rf/rf_utils.c +++ b/lib/src/phy/rf/rf_utils.c @@ -117,7 +117,7 @@ int rf_mib_decoder(srslte_rf_t *rf, uint32_t nof_rx_antennas,cell_search_cfg_t * INFO("Setting sampling frequency %.2f MHz for PSS search\n", (float) srate/1000000); srslte_rf_set_rx_srate(rf, (float) srate); - INFO("Starting receiver...\n", 0); + INFO("Starting receiver...\n"); srslte_rf_start_rx_stream(rf, false); // Copy CFO estimate if provided and disable CP estimation during find @@ -174,7 +174,7 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000); srslte_rf_set_rx_srate(rf, SRSLTE_CS_SAMP_FREQ); - INFO("Starting receiver...\n", 0); + INFO("Starting receiver...\n"); srslte_rf_start_rx_stream(rf, false); /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */ diff --git a/lib/src/phy/sync/sync.c b/lib/src/phy/sync/sync.c index bf86eef4d..c948a53d4 100644 --- a/lib/src/phy/sync/sync.c +++ b/lib/src/phy/sync/sync.c @@ -178,7 +178,6 @@ int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offse int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && - frame_size <= 307200 && fft_size_isvalid(fft_size)) { if (frame_size > q->max_frame_size) { diff --git a/lib/src/phy/ue/ue_dl.c b/lib/src/phy/ue/ue_dl.c index 036f2b7cb..5c61b2c22 100644 --- a/lib/src/phy/ue/ue_dl.c +++ b/lib/src/phy/ue/ue_dl.c @@ -381,17 +381,6 @@ int srslte_ue_dl_decode_fft_estimate_mbsfn(srslte_ue_dl_t *q, uint32_t sf_idx, u }else{ srslte_ofdm_rx_sf(&q->fft[j]); } - - /* Correct SFO multiplying by complex exponential in the time domain */ - if (q->sample_offset) { - int nsym = (sf_type == SRSLTE_SF_MBSFN)?SRSLTE_CP_EXT_NSYMB:SRSLTE_CP_NSYMB(q->cell.cp); - for (int i=0;i<2*nsym;i++) { - srslte_cfo_correct(&q->sfo_correct, - &q->sf_symbols_m[j][i*q->cell.nof_prb*SRSLTE_NRE], - &q->sf_symbols_m[j][i*q->cell.nof_prb*SRSLTE_NRE], - q->sample_offset / q->fft[j].symbol_sz); - } - } } return srslte_ue_dl_decode_estimate_mbsfn(q, sf_idx, cfi, sf_type); } else { @@ -561,6 +550,7 @@ int srslte_ue_dl_decode_rnti(srslte_ue_dl_t *q, switch(dci_msg.format) { case SRSLTE_DCI_FORMAT1: case SRSLTE_DCI_FORMAT1A: + case SRSLTE_DCI_FORMAT1C: if (q->cell.nof_ports == 1) { mimo_type = SRSLTE_MIMO_TYPE_SINGLE_ANTENNA; } else { @@ -584,7 +574,6 @@ int srslte_ue_dl_decode_rnti(srslte_ue_dl_t *q, /* Not implemented formats */ case SRSLTE_DCI_FORMAT0: - case SRSLTE_DCI_FORMAT1C: case SRSLTE_DCI_FORMAT1B: case SRSLTE_DCI_FORMAT1D: case SRSLTE_DCI_FORMAT2B: diff --git a/lib/src/phy/ue/ue_sync.c b/lib/src/phy/ue/ue_sync.c index 480835e6b..7ee97c21b 100644 --- a/lib/src/phy/ue/ue_sync.c +++ b/lib/src/phy/ue/ue_sync.c @@ -751,7 +751,7 @@ int srslte_ue_sync_zerocopy_multi(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE break; case SRSLTE_SYNC_FOUND_NOSPACE: /* If a peak was found but there is not enough space for SSS/CP detection, discard a few samples */ - INFO("No space for SSS/CP detection. Realigning frame...\n",0); + INFO("No space for SSS/CP detection. Realigning frame...\n"); q->recv_callback(q->stream, dummy_offset_buffer, q->frame_len/2, NULL); srslte_sync_reset(&q->sfind); ret = SRSLTE_SUCCESS; diff --git a/lib/src/phy/ue/ue_ul.c b/lib/src/phy/ue/ue_ul.c index 5580a99d1..a0accb579 100644 --- a/lib/src/phy/ue/ue_ul.c +++ b/lib/src/phy/ue/ue_ul.c @@ -444,7 +444,6 @@ int srslte_ue_ul_pusch_encode_rnti_softbuffer(srslte_ue_ul_t *q, int ret = SRSLTE_ERROR_INVALID_INPUTS; if (q != NULL && - softbuffer != NULL && output_signal != NULL) { diff --git a/lib/src/phy/utils/test/vector_test.c b/lib/src/phy/utils/test/vector_test.c index cb7eff480..ebda516ea 100644 --- a/lib/src/phy/utils/test/vector_test.c +++ b/lib/src/phy/utils/test/vector_test.c @@ -49,8 +49,8 @@ bool verbose = false; #define RANDOM_F() ((float)rand())/((float)RAND_MAX) -#define RANDOM_S() ((int16_t)(rand() && 0x800F)) -#define RANDOM_B() ((int8_t)(rand() && 0x8008)) +#define RANDOM_S() ((int16_t)(rand() & 0x800F)) +#define RANDOM_B() ((int8_t)(rand() & 0x8008)) #define RANDOM_CF() (RANDOM_F() + _Complex_I*RANDOM_F()) #define TEST_CALL(TEST_CODE) gettimeofday(&start, NULL);\ @@ -137,7 +137,7 @@ TEST(srslte_vec_dot_prod_sss, MALLOC(int16_t, y); int16_t z; - cf_t gold = 0.0f; + int16_t gold = 0.0f; for (int i = 0; i < block_size; i++) { x[i] = RANDOM_S(); y[i] = RANDOM_S(); @@ -149,7 +149,7 @@ TEST(srslte_vec_dot_prod_sss, gold += x[i] * y[i]; } - mse += cabsf(gold - z) / cabsf(gold); + mse = (gold - z) / abs(gold); free(x); free(y); @@ -160,7 +160,7 @@ TEST(srslte_vec_sum_sss, MALLOC(int16_t, y); MALLOC(int16_t, z); - cf_t gold = 0.0f; + int16_t gold = 0; for (int i = 0; i < block_size; i++) { x[i] = RANDOM_S(); y[i] = RANDOM_S(); @@ -170,7 +170,7 @@ TEST(srslte_vec_sum_sss, for (int i = 0; i < block_size; i++) { gold = x[i] + y[i]; - mse += cabsf(gold - z[i]); + mse += abs(gold - z[i]); } free(x); @@ -183,7 +183,7 @@ TEST(srslte_vec_sub_sss, MALLOC(int16_t, y); MALLOC(int16_t, z); - cf_t gold = 0.0f; + int16_t gold = 0.0f; for (int i = 0; i < block_size; i++) { x[i] = RANDOM_S(); y[i] = RANDOM_S(); @@ -193,7 +193,7 @@ TEST(srslte_vec_sub_sss, for (int i = 0; i < block_size; i++) { gold = x[i] - y[i]; - mse += cabsf(gold - z[i]); + mse += abs(gold - z[i]); } free(x); @@ -206,7 +206,7 @@ TEST(srslte_vec_prod_sss, MALLOC(int16_t, y); MALLOC(int16_t, z); - cf_t gold = 0.0f; + int16_t gold = 0.0f; for (int i = 0; i < block_size; i++) { x[i] = RANDOM_S(); y[i] = RANDOM_S(); @@ -216,7 +216,7 @@ TEST(srslte_vec_prod_sss, for (int i = 0; i < block_size; i++) { gold = x[i] * y[i]; - mse += cabsf(gold - z[i]); + mse += abs(gold - z[i]); } free(x); @@ -802,16 +802,18 @@ int main(int argc, char **argv) { size_count++; } - char fname[68]; + char fname[69]; FILE *f = NULL; void * p = popen("(date +%g%m%d && hostname) | tr '\\r\\n' '__'", "r"); if (p) { fgets(fname, 64, p); - strncpy(fname + strnlen(fname, 64) - 1, ".tsv", 4); + strncpy(fname + strnlen(fname, 64) - 1, ".tsv", 5); f = fopen(fname, "w"); - if (f) printf("Saving benchmark results in '%s'\n", fname); + if (f) { + printf("Saving benchmark results in '%s'\n", fname); + } + pclose(p); } - pclose(p); printf("\n"); diff --git a/lib/src/phy/utils/vector_simd.c b/lib/src/phy/utils/vector_simd.c index 024b3849f..df8a1ea4e 100644 --- a/lib/src/phy/utils/vector_simd.c +++ b/lib/src/phy/utils/vector_simd.c @@ -433,6 +433,7 @@ cf_t srslte_vec_dot_prod_ccc_simd(const cf_t *x, const cf_t *y, const int len) { return result; } +#ifdef ENABLE_C16 c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t *x, const c16_t *y, const int len) { int i = 0; c16_t result = 0; @@ -460,6 +461,7 @@ c16_t srslte_vec_dot_prod_ccc_c16i_simd(const c16_t *x, const c16_t *y, const in return result; } +#endif /* ENABLE_C16 */ cf_t srslte_vec_dot_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, const int len) { @@ -620,6 +622,7 @@ void srslte_vec_prod_ccc_split_simd(const float *a_re, const float *a_im, const } } +#ifdef ENABLE_C16 void srslte_vec_prod_ccc_c16_simd(const int16_t *a_re, const int16_t *a_im, const int16_t *b_re, const int16_t *b_im, int16_t *r_re, int16_t *r_im, const int len) { int i = 0; @@ -652,6 +655,7 @@ void srslte_vec_prod_ccc_c16_simd(const int16_t *a_re, const int16_t *a_im, cons r_im[i] = a_re[i]*b_im[i] + a_im[i]*b_re[i]; } } +#endif /* ENABLE_C16 */ void srslte_vec_prod_conj_ccc_simd(const cf_t *x, const cf_t *y, cf_t *z, const int len) { int i = 0; diff --git a/lib/src/upper/pdcp.cc b/lib/src/upper/pdcp.cc index e7c02c179..320f02450 100644 --- a/lib/src/upper/pdcp.cc +++ b/lib/src/upper/pdcp.cc @@ -52,11 +52,6 @@ void pdcp::init(srsue::rlc_interface_pdcp *rlc_, srsue::rrc_interface_pdcp *rrc_ void pdcp::stop() { - for(uint32_t i=0;idebug("Init %s\n", rrc->get_rb_name(lcid).c_str()); } -void pdcp_entity::stop() -{ - if(running) { - running = false; - thread_cancel(); - wait_thread_finish(); - } -} - // Reestablishment procedure: 36.323 5.2 void pdcp_entity::reestablish() { // For SRBs @@ -165,7 +154,53 @@ void pdcp_entity::enable_encryption() // RLC interface void pdcp_entity::write_pdu(byte_buffer_t *pdu) { - rx_pdu_queue.write(pdu); + log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU, do_integrity = %s, do_encryption = %s", + rrc->get_rb_name(lcid).c_str(), (do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false"); + + // Handle DRB messages + if (cfg.is_data) { + uint32_t sn; + if (do_encryption) { + cipher_decrypt(&(pdu->msg[sn_len_bytes]), + rx_count, + pdu->N_bytes - sn_len_bytes, + &(pdu->msg[sn_len_bytes])); + log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str()); + } + if(12 == cfg.sn_len) + { + pdcp_unpack_data_pdu_long_sn(pdu, &sn); + } else { + pdcp_unpack_data_pdu_short_sn(pdu, &sn); + } + log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn); + gw->write_pdu(lcid, pdu); + } else { + // Handle SRB messages + if (cfg.is_control) { + uint32_t sn; + if (do_encryption) { + cipher_decrypt(&(pdu->msg[sn_len_bytes]), + rx_count, + pdu->N_bytes - sn_len_bytes, + &(pdu->msg[sn_len_bytes])); + log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str()); + } + + if (do_integrity) { + integrity_verify(pdu->msg, + rx_count, + pdu->N_bytes - 4, + &(pdu->msg[pdu->N_bytes - 4])); + } + + pdcp_unpack_control_pdu(pdu, &sn); + log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn); + } + // pass to RRC + rrc->write_pdu(lcid, pdu); + } + rx_count++; } void pdcp_entity::integrity_generate( uint8_t *msg, @@ -332,63 +367,6 @@ void pdcp_entity::cipher_decrypt(uint8_t *ct, } -void pdcp_entity::run_thread() -{ - byte_buffer_t *pdu; - running = true; - - while(running) { - rx_pdu_queue.read(&pdu); - log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU, do_integrity = %s, do_encryption = %s", - rrc->get_rb_name(lcid).c_str(), (do_integrity) ? "true" : "false", (do_encryption) ? "true" : "false"); - - // Handle DRB messages - if (cfg.is_data) { - uint32_t sn; - if (do_encryption) { - cipher_decrypt(&(pdu->msg[sn_len_bytes]), - rx_count, - pdu->N_bytes - sn_len_bytes, - &(pdu->msg[sn_len_bytes])); - log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str()); - } - if(12 == cfg.sn_len) - { - pdcp_unpack_data_pdu_long_sn(pdu, &sn); - } else { - pdcp_unpack_data_pdu_short_sn(pdu, &sn); - } - log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn); - gw->write_pdu(lcid, pdu); - } else { - // Handle SRB messages - if (cfg.is_control) { - uint32_t sn; - if (do_encryption) { - cipher_decrypt(&(pdu->msg[sn_len_bytes]), - rx_count, - pdu->N_bytes - sn_len_bytes, - &(pdu->msg[sn_len_bytes])); - log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU (decrypted)", rrc->get_rb_name(lcid).c_str()); - } - - if (do_integrity) { - integrity_verify(pdu->msg, - rx_count, - pdu->N_bytes - 4, - &(pdu->msg[pdu->N_bytes - 4])); - } - - pdcp_unpack_control_pdu(pdu, &sn); - log->info_hex(pdu->msg, pdu->N_bytes, "RX %s PDU SN: %d", rrc->get_rb_name(lcid).c_str(), sn); - } - // pass to RRC - rrc->write_pdu(lcid, pdu); - } - rx_count++; - } -} - uint8_t pdcp_entity::get_bearer_id(uint8_t lcid) { #define RB_ID_SRB2 2 diff --git a/lib/src/upper/rlc_am.cc b/lib/src/upper/rlc_am.cc index c6c69c12b..f4e7839c4 100644 --- a/lib/src/upper/rlc_am.cc +++ b/lib/src/upper/rlc_am.cc @@ -175,8 +175,8 @@ uint32_t rlc_am::get_bearer() void rlc_am::write_sdu(byte_buffer_t *sdu) { - log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", rrc->get_rb_name(lcid).c_str()); tx_sdu_queue.write(sdu); + log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, tx_sdu_len=%d", rrc->get_rb_name(lcid).c_str(), tx_sdu_queue.size()); } /**************************************************************************** @@ -682,7 +682,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) tx_sdu->msg += to_move; if(tx_sdu->N_bytes == 0) { - log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", + log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us()); pool->deallocate(tx_sdu); tx_sdu = NULL; @@ -717,7 +717,7 @@ int rlc_am::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) tx_sdu->msg += to_move; if(tx_sdu->N_bytes == 0) { - log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", + log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us()); pool->deallocate(tx_sdu); tx_sdu = NULL; diff --git a/lib/src/upper/rlc_tm.cc b/lib/src/upper/rlc_tm.cc index 627752494..843236ca8 100644 --- a/lib/src/upper/rlc_tm.cc +++ b/lib/src/upper/rlc_tm.cc @@ -111,7 +111,7 @@ int rlc_tm::read_pdu(uint8_t *payload, uint32_t nof_bytes) ul_queue.read(&buf); pdu_size = buf->N_bytes; memcpy(payload, buf->msg, buf->N_bytes); - log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", + log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", rrc->get_rb_name(lcid).c_str(), buf->get_latency_us()); pool->deallocate(buf); log->info_hex(payload, pdu_size, "TX %s, %s PDU", rrc->get_rb_name(lcid).c_str(), rlc_mode_text[RLC_MODE_TM]); diff --git a/lib/src/upper/rlc_um.cc b/lib/src/upper/rlc_um.cc index 4756e2f7c..85fc9f818 100644 --- a/lib/src/upper/rlc_um.cc +++ b/lib/src/upper/rlc_um.cc @@ -153,8 +153,8 @@ uint32_t rlc_um::get_bearer() void rlc_um::write_sdu(byte_buffer_t *sdu) { - log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU", rrc->get_rb_name(lcid).c_str()); tx_sdu_queue.write(sdu); + log->info_hex(sdu->msg, sdu->N_bytes, "%s Tx SDU, tx_sdu_len=%d", rrc->get_rb_name(lcid).c_str(), tx_sdu_queue.size()); } /**************************************************************************** @@ -178,7 +178,7 @@ uint32_t rlc_um::get_buffer_state() // Room needed for fixed header? if(n_bytes > 0) - n_bytes += 2; + n_bytes += 3; return n_bytes; } @@ -300,7 +300,7 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) tx_sdu->msg += to_move; if(tx_sdu->N_bytes == 0) { - log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", + log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us()); pool->deallocate(tx_sdu); tx_sdu = NULL; @@ -329,7 +329,7 @@ int rlc_um::build_data_pdu(uint8_t *payload, uint32_t nof_bytes) tx_sdu->msg += to_move; if(tx_sdu->N_bytes == 0) { - log->info("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", + log->debug("%s Complete SDU scheduled for tx. Stack latency: %ld us\n", rrc->get_rb_name(lcid).c_str(), tx_sdu->get_latency_us()); pool->deallocate(tx_sdu); tx_sdu = NULL; diff --git a/lib/test/upper/rlc_um_test.cc b/lib/test/upper/rlc_um_test.cc index 8abcfae3c..a58ea0a99 100644 --- a/lib/test/upper/rlc_um_test.cc +++ b/lib/test/upper/rlc_um_test.cc @@ -117,7 +117,7 @@ void basic_test() rlc1.write_sdu(&sdu_bufs[i]); } - assert(13 == rlc1.get_buffer_state()); + assert(14 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (1 byte each) byte_buffer_t pdu_bufs[NBUFS]; @@ -185,7 +185,7 @@ void loss_test() rlc1.write_sdu(&sdu_bufs[i]); } - assert(13 == rlc1.get_buffer_state()); + assert(14 == rlc1.get_buffer_state()); // Read 5 PDUs from RLC1 (1 byte each) byte_buffer_t pdu_bufs[NBUFS]; diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index f030ae12e..ff314977a 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -97,6 +97,7 @@ typedef struct { typedef struct { std::string phy_level; + std::string phy_lib_level; std::string mac_level; std::string rlc_level; std::string pdcp_level; diff --git a/srsenb/hdr/mac/mac.h b/srsenb/hdr/mac/mac.h index 4e37d439f..c99b733fb 100644 --- a/srsenb/hdr/mac/mac.h +++ b/srsenb/hdr/mac/mac.h @@ -121,7 +121,7 @@ private: static const uint32_t cfi = 3; srslte_dci_location_t locations[MAX_LOCATIONS]; - static const int MAC_PDU_THREAD_PRIO = 3; + static const int MAC_PDU_THREAD_PRIO = 60; diff --git a/srsenb/hdr/mac/scheduler_harq.h b/srsenb/hdr/mac/scheduler_harq.h index 211ec7d8d..ec2aa43c0 100644 --- a/srsenb/hdr/mac/scheduler_harq.h +++ b/srsenb/hdr/mac/scheduler_harq.h @@ -102,8 +102,8 @@ public: ul_alloc_t get_alloc(); void set_alloc(ul_alloc_t alloc); - void same_alloc(); - bool is_adaptive_retx(); + void re_alloc(ul_alloc_t alloc); + bool is_adaptive_retx(); void reset_pending_data(); bool has_pending_ack(); diff --git a/srsenb/hdr/upper/gtpu.h b/srsenb/hdr/upper/gtpu.h index 6ec371655..6958773b6 100644 --- a/srsenb/hdr/upper/gtpu.h +++ b/srsenb/hdr/upper/gtpu.h @@ -84,7 +84,7 @@ public: private: - static const int THREAD_PRIO = 7; + static const int THREAD_PRIO = 65; static const int GTPU_PORT = 2152; srslte::byte_buffer_pool *pool; bool running; diff --git a/srsenb/hdr/upper/rrc.h b/srsenb/hdr/upper/rrc.h index 97741a670..764320cc6 100644 --- a/srsenb/hdr/upper/rrc.h +++ b/srsenb/hdr/upper/rrc.h @@ -321,7 +321,7 @@ private: const static uint32_t LCID_REM_USER = 0xffff0001; bool running; - static const int RRC_THREAD_PRIO = 7; + static const int RRC_THREAD_PRIO = 65; srslte::block_queue rx_pdu_queue; typedef struct { diff --git a/srsenb/hdr/upper/s1ap.h b/srsenb/hdr/upper/s1ap.h index 02e5e207e..714035638 100644 --- a/srsenb/hdr/upper/s1ap.h +++ b/srsenb/hdr/upper/s1ap.h @@ -85,7 +85,7 @@ public: //void ue_capabilities(uint16_t rnti, LIBLTE_RRC_UE_EUTRA_CAPABILITY_STRUCT *caps); private: - static const int S1AP_THREAD_PRIO = 7; + static const int S1AP_THREAD_PRIO = 65; static const int MME_PORT = 36412; static const int ADDR_FAMILY = AF_INET; static const int SOCK_TYPE = SOCK_STREAM; diff --git a/srsenb/src/enb_cfg_parser.cc b/srsenb/src/enb_cfg_parser.cc index 26458e7a2..ab25d9dcc 100644 --- a/srsenb/src/enb_cfg_parser.cc +++ b/srsenb/src/enb_cfg_parser.cc @@ -715,7 +715,8 @@ int enb::parse_sib9(std::string filename, LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_9_STRUC if (!parser::parse_section(filename, &sib9)) { data->hnb_name_present = true; if (name_enabled) { - strncpy((char*) data->hnb_name, hnb_name.c_str(), 48); + strncpy((char*) data->hnb_name, hnb_name.c_str(), 47); + data->hnb_name[47] = 0; data->hnb_name_size = strnlen(hnb_name.c_str(), 48); } else if (hex_enabled) { data->hnb_name_size = HexToBytes(hex_value, data->hnb_name, 48); diff --git a/srsenb/src/mac/mac.cc b/srsenb/src/mac/mac.cc index f7a4d5b55..c710534ac 100644 --- a/srsenb/src/mac/mac.cc +++ b/srsenb/src/mac/mac.cc @@ -392,7 +392,7 @@ int mac::rach_detected(uint32_t tti, uint32_t preamble_idx, uint32_t time_adv) // Find empty slot for pending rars uint32_t ra_id=0; - while(pending_rars[ra_id].temp_crnti && ra_idsame_alloc(); - return h; + return h; } // If not, try to find another mask in the current tti if (new_allocation(alloc.L, &alloc)) { update_allocation(alloc); - h->set_alloc(alloc); - return h; + h->set_alloc(alloc); + return h; } } // If could not schedule the reTx, or there wasn't any pending retx, find an empty PID diff --git a/srsenb/src/mac/scheduler_ue.cc b/srsenb/src/mac/scheduler_ue.cc index eb8f2459f..0c89f9728 100644 --- a/srsenb/src/mac/scheduler_ue.cc +++ b/srsenb/src/mac/scheduler_ue.cc @@ -212,6 +212,7 @@ bool sched_ue::pucch_sr_collision(uint32_t current_tti, uint32_t n_cce) return false; } srslte_pucch_sched_t pucch_sched; + pucch_sched.sps_enabled = false; pucch_sched.n_pucch_sr = cfg.sr_N_pucch; pucch_sched.n_pucch_2 = cfg.n_pucch_cqi; pucch_sched.N_pucch_1 = cfg.pucch_cfg.n1_pucch_an; diff --git a/srsenb/src/mac/ue.cc b/srsenb/src/mac/ue.cc index 990b09386..166be24f1 100644 --- a/srsenb/src/mac/ue.cc +++ b/srsenb/src/mac/ue.cc @@ -256,7 +256,7 @@ void ue::push_pdu(uint32_t tti, uint32_t len) bool ue::process_ce(srslte::sch_subh *subh) { uint32_t buff_size[4] = {0, 0, 0, 0}; float phr = 0; - int idx = 0; + int32_t idx = 0; uint16_t old_rnti = 0; bool is_bsr = false; switch(subh->ce_type()) { @@ -279,6 +279,10 @@ bool ue::process_ce(srslte::sch_subh *subh) { case srslte::sch_subh::TRUNC_BSR: case srslte::sch_subh::SHORT_BSR: idx = subh->get_bsr(buff_size); + if(idx == -1){ + Error("Invalid Index Passed to lc groups\n"); + break; + } for (uint32_t i=0;iul_bsr(rnti, lc_groups[idx][i], buff_size[idx]); @@ -289,7 +293,7 @@ bool ue::process_ce(srslte::sch_subh *subh) { break; case srslte::sch_subh::LONG_BSR: subh->get_bsr(buff_size); - for (int idx=0;idx<4;idx++) { + for (idx=0;idx<4;idx++) { for (uint32_t i=0;iul_bsr(rnti, lc_groups[idx][i], buff_size[idx]); } @@ -320,7 +324,7 @@ void ue::allocate_sdu(srslte::sch_pdu *pdu, uint32_t lcid, uint32_t total_sdu_le if (sdu_space > 0) { int sdu_len = SRSLTE_MIN(total_sdu_len, (uint32_t) sdu_space); int n=1; - while(sdu_len > 0 && n > 0) { + while(sdu_len > 3 && n > 0) { if (pdu->new_subh()) { // there is space for a new subheader log_h->debug("SDU: set_sdu(), lcid=%d, sdu_len=%d, sdu_space=%d\n", lcid, sdu_len, sdu_space); n = pdu->get()->set_sdu(lcid, sdu_len, this); diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index 321eac52c..3aedda25a 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -104,6 +104,7 @@ void parse_args(all_args_t *args, int argc, char* argv[]) { ("log.phy_level", bpo::value(&args->log.phy_level), "PHY log level") ("log.phy_hex_limit", bpo::value(&args->log.phy_hex_limit), "PHY log hex dump limit") + ("log.phy_lib_level", bpo::value(&args->log.phy_lib_level)->default_value("none"), "PHY lib log level") ("log.mac_level", bpo::value(&args->log.mac_level), "MAC log level") ("log.mac_hex_limit", bpo::value(&args->log.mac_hex_limit), "MAC log hex dump limit") ("log.rlc_level", bpo::value(&args->log.rlc_level), "RLC log level") @@ -274,6 +275,9 @@ void parse_args(all_args_t *args, int argc, char* argv[]) { if(!vm.count("log.phy_level")) { args->log.phy_level = args->log.all_level; } + if (!vm.count("log.phy_lib_level")) { + args->log.phy_lib_level = args->log.all_level; + } if(!vm.count("log.mac_level")) { args->log.mac_level = args->log.all_level; } @@ -340,14 +344,19 @@ void *input_loop(void *m) char key; while(running) { cin >> key; - if('t' == key) { - do_metrics = !do_metrics; - if(do_metrics) { - cout << "Enter t to stop trace." << endl; - } else { - cout << "Enter t to restart trace." << endl; + if (cin.eof() || cin.bad()) { + cout << "Closing stdin thread." << endl; + break; + } else { + if('t' == key) { + do_metrics = !do_metrics; + if(do_metrics) { + cout << "Enter t to stop trace." << endl; + } else { + cout << "Enter t to restart trace." << endl; + } + metrics->toggle_print(do_metrics); } - metrics->toggle_print(do_metrics); } } return NULL; @@ -355,7 +364,8 @@ void *input_loop(void *m) int main(int argc, char *argv[]) { - signal(SIGINT, sig_int_handler); + signal(SIGINT, sig_int_handler); + signal(SIGTERM, sig_int_handler); all_args_t args; metrics_stdout metrics; enb *enb = enb::get_instance(); diff --git a/srsenb/src/phy/phch_worker.cc b/srsenb/src/phy/phch_worker.cc index cffc02d22..11c80ca8d 100644 --- a/srsenb/src/phy/phch_worker.cc +++ b/srsenb/src/phy/phch_worker.cc @@ -551,7 +551,7 @@ int phch_worker::decode_pusch(srslte_enb_ul_pusch_t *grants, uint32_t nof_pusch) ue_db[rnti].phich_info.n_prb_lowest = enb_ul.pusch_cfg.grant.n_prb_tilde[0]; ue_db[rnti].phich_info.n_dmrs = phy_grant.ncs_dmrs; - char cqi_str[64]; + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR]; if (cqi_enabled) { if (ue_db[rnti].cqi_en) { wideband_cqi_value = cqi_value.wideband.wideband_cqi; @@ -578,7 +578,7 @@ int phch_worker::decode_pusch(srslte_enb_ul_pusch_t *grants, uint32_t nof_pusch) cqi_value.subband_hl.wideband_cqi_cw0, cqi_value.subband_hl.N); } } - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 64); + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); //snprintf(cqi_str, 64, ", cqi=%s", wideband_cqi_value); } diff --git a/srsenb/src/upper/gtpu.cc b/srsenb/src/upper/gtpu.cc index 5d64cb4e5..53b7cffdb 100644 --- a/srsenb/src/upper/gtpu.cc +++ b/srsenb/src/upper/gtpu.cc @@ -125,7 +125,7 @@ void gtpu::stop() // gtpu_interface_pdcp void gtpu::write_pdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* pdu) { - gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d", rnti, lcid); + gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU, RNTI: 0x%x, LCID: %d, n_bytes=%d", rnti, lcid, pdu->N_bytes); gtpu_header_t header; header.flags = 0x30; header.message_type = 0xFF; @@ -234,7 +234,7 @@ void gtpu::run_thread() continue; } - gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d", rnti, lcid); + gtpu_log->info_hex(pdu->msg, pdu->N_bytes, "RX GTPU PDU rnti=0x%x, lcid=%d, n_bytes=%d", rnti, lcid, pdu->N_bytes); pdcp->write_sdu(rnti, lcid, pdu); do { diff --git a/srsenb/src/upper/rlc.cc b/srsenb/src/upper/rlc.cc index fff674112..0b7babbac 100644 --- a/srsenb/src/upper/rlc.cc +++ b/srsenb/src/upper/rlc.cc @@ -153,8 +153,8 @@ void rlc::write_sdu(uint16_t rnti, uint32_t lcid, srslte::byte_buffer_t* sdu) // communicate buffer state every time a new SDU is written uint32_t tx_queue = users[rnti].rlc->get_total_buffer_state(lcid); uint32_t retx_queue = 0; - log_h->info("Buffer state: rnti=0x%x, lcid=%d, tx_queue=%d\n", rnti, lcid, tx_queue); mac->rlc_buffer_state(rnti, lcid, tx_queue, retx_queue); + log_h->info("Buffer state: rnti=0x%x, lcid=%d, tx_queue=%d\n", rnti, lcid, tx_queue); } else { pool->deallocate(sdu); } diff --git a/srsenb/test/upper/ip_test.cc b/srsenb/test/upper/ip_test.cc index 2b789cf27..1d8423b9d 100644 --- a/srsenb/test/upper/ip_test.cc +++ b/srsenb/test/upper/ip_test.cc @@ -609,6 +609,7 @@ int setup_if_addr(char *ip_addr) if(0 > ioctl(tun_fd, TUNSETIFF, &ifr)) { perror("ioctl1"); + close(tun_fd); return -1; } @@ -617,15 +618,21 @@ int setup_if_addr(char *ip_addr) if(0 > ioctl(sock, SIOCGIFFLAGS, &ifr)) { perror("socket"); + close(sock); + close(tun_fd); return -1; } ifr.ifr_flags |= IFF_UP | IFF_RUNNING; if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr)) { perror("ioctl2"); + close(sock); + close(tun_fd); return -1; } + close(sock); + // Setup the IP address sock = socket(AF_INET, SOCK_DGRAM, 0); ifr.ifr_addr.sa_family = AF_INET; @@ -633,6 +640,8 @@ int setup_if_addr(char *ip_addr) if(0 > ioctl(sock, SIOCSIFADDR, &ifr)) { perror("ioctl"); + close(sock); + close(tun_fd); return -1; } ifr.ifr_netmask.sa_family = AF_INET; @@ -640,8 +649,12 @@ int setup_if_addr(char *ip_addr) if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr)) { perror("ioctl"); + close(sock); + close(tun_fd); return -1; } + + close(sock); return(tun_fd); } diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 8e9db9259..40f19b486 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -267,6 +267,8 @@ main (int argc,char * argv[] ) { cout << endl <<"--- Software Radio Systems EPC ---" << endl << endl; signal(SIGINT, sig_int_handler); + signal(SIGTERM, sig_int_handler); + signal(SIGKILL, sig_int_handler); all_args_t args; parse_args(&args, argc, argv); diff --git a/srsue/hdr/mac/mac.h b/srsue/hdr/mac/mac.h index b1b649de7..ee79456fc 100644 --- a/srsue/hdr/mac/mac.h +++ b/srsue/hdr/mac/mac.h @@ -112,8 +112,8 @@ public: private: void run_thread(); - static const int MAC_MAIN_THREAD_PRIO = 5; - static const int MAC_PDU_THREAD_PRIO = 6; + 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_NOF_HARQ_PROC = 2*HARQ_DELAY_MS; // Interaction with PHY diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 5b33be1ec..52307e162 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -219,7 +219,13 @@ private: // Receive and route HARQ feedbacks if (grant) { - if ((!(grant->rnti_type == SRSLTE_RNTI_TEMP) && grant->ndi[0] != get_ndi() && harq_feedback) || + if (grant->has_cqi_request && grant->phy_grant.ul.mcs.tbs == 0) { + /* Only CQI reporting (without SCH) */ + memcpy(&action->phy_grant.ul, &grant->phy_grant.ul, sizeof(srslte_ra_ul_grant_t)); + memcpy(&cur_grant, grant, sizeof(Tgrant)); + action->tx_enabled = true; + action->rnti = grant->rnti; + } else if ((!(grant->rnti_type == SRSLTE_RNTI_TEMP) && grant->ndi[0] != get_ndi() && harq_feedback) || (grant->rnti_type == SRSLTE_RNTI_USER && !has_grant()) || grant->is_from_rar) { diff --git a/srsue/hdr/metrics_csv.h b/srsue/hdr/metrics_csv.h index f0b3e48c4..72a9dc050 100644 --- a/srsue/hdr/metrics_csv.h +++ b/srsue/hdr/metrics_csv.h @@ -47,10 +47,11 @@ class metrics_csv : public srslte::metrics_listener { public: metrics_csv(std::string filename); + ~metrics_csv(); - void set_periodicity(float metrics_report_period_sec); - void set_metrics(ue_metrics_t &m); + void set_metrics(ue_metrics_t &m, const uint32_t period_usec); void set_ue_handle(ue_metrics_interface *ue_); + void stop(); private: std::string float_to_string(float f, int digits, bool add_semicolon = true); diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index 87a67cb2e..cd19e7f16 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -48,8 +48,9 @@ public: void set_periodicity(float metrics_report_period_sec); void toggle_print(bool b); - void set_metrics(ue_metrics_t &m); + void set_metrics(ue_metrics_t &m, const uint32_t period_usec); void set_ue_handle(ue_metrics_interface *ue_); + void stop() {}; private: std::string float_to_string(float f, int digits); diff --git a/srsue/hdr/phy/phch_common.h b/srsue/hdr/phy/phch_common.h index fd73d9421..31bf06122 100644 --- a/srsue/hdr/phy/phch_common.h +++ b/srsue/hdr/phy/phch_common.h @@ -46,6 +46,7 @@ namespace srsue { class chest_feedback_itf { public: + virtual void in_sync() = 0; virtual void out_of_sync() = 0; virtual void set_cfo(float cfo) = 0; }; @@ -69,6 +70,8 @@ public: float avg_rsrp; float avg_rsrp_dbm; float avg_rsrq_db; + float avg_rssi_dbm; + float last_radio_rssi; float rx_gain_offset; float avg_snr_db; float avg_noise; diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index ed4bd706a..0530459df 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -75,6 +75,7 @@ public: bool status_is_sync(); // from chest_feedback_itf + void in_sync(); void out_of_sync(); void set_cfo(float cfo); @@ -153,7 +154,7 @@ private: srslte_ue_mib_t ue_mib; uint32_t cnt; uint32_t timeout; - const static uint32_t SYNC_SFN_TIMEOUT = 200; + const static uint32_t SYNC_SFN_TIMEOUT = 500; }; // Class to perform cell measurements @@ -324,9 +325,6 @@ private: int cur_earfcn_index; bool cell_search_in_progress; - uint32_t out_of_sync_cnt; - uint32_t out_of_sync2_cnt; - float dl_freq; float ul_freq; diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index 5430a2d18..d73214514 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -158,6 +158,8 @@ private: float cfo; bool rar_cqi_request; + uint32_t rssi_read_cnt; + // Metrics dl_metrics_t dl_metrics; ul_metrics_t ul_metrics; diff --git a/srsue/hdr/phy/prach.h b/srsue/hdr/phy/prach.h index 8218ca644..09be0c9b2 100644 --- a/srsue/hdr/phy/prach.h +++ b/srsue/hdr/phy/prach.h @@ -56,6 +56,7 @@ namespace srsue { bool set_cell(srslte_cell_t cell); bool prepare_to_send(uint32_t preamble_idx, int allowed_subframe = -1, float target_power_dbm = -1); bool is_ready_to_send(uint32_t current_tti); + bool is_pending(); int tx_tti(); void send(srslte::radio* radio_handler, float cfo, float pathloss, srslte_timestamp_t rx_time); diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 0f668b927..98966510c 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -403,14 +403,19 @@ void *input_loop(void *m) { char key; while (running) { cin >> key; - if ('t' == key) { - do_metrics = !do_metrics; - if (do_metrics) { - cout << "Enter t to stop trace." << endl; - } else { - cout << "Enter t to restart trace." << endl; + if (cin.eof() || cin.bad()) { + cout << "Closing stdin thread." << endl; + break; + } else { + if ('t' == key) { + do_metrics = !do_metrics; + if (do_metrics) { + cout << "Enter t to stop trace." << endl; + } else { + cout << "Enter t to restart trace." << endl; + } + metrics_screen.toggle_print(do_metrics); } - metrics_screen.toggle_print(do_metrics); } } return NULL; @@ -420,6 +425,7 @@ int main(int argc, char *argv[]) { srslte::metrics_hub metricshub; signal(SIGINT, sig_int_handler); + signal(SIGTERM, sig_int_handler); all_args_t args; srslte_debug_handle_crash(argc, argv); @@ -441,13 +447,11 @@ int main(int argc, char *argv[]) metricshub.init(ue, args.expert.metrics_period_secs); metricshub.add_listener(&metrics_screen); metrics_screen.set_ue_handle(ue); - metrics_screen.set_periodicity(args.expert.metrics_period_secs); metrics_csv metrics_file(args.expert.metrics_csv_filename); if (args.expert.metrics_csv_enable) { metricshub.add_listener(&metrics_file); metrics_file.set_ue_handle(ue); - metrics_file.set_periodicity(args.expert.metrics_period_secs); } pthread_t input; diff --git a/srsue/src/metrics_csv.cc b/srsue/src/metrics_csv.cc index 7c84659b5..54702dc26 100644 --- a/srsue/src/metrics_csv.cc +++ b/srsue/src/metrics_csv.cc @@ -46,7 +46,12 @@ metrics_csv::metrics_csv(std::string filename) ,metrics_report_period(1.0) ,ue(NULL) { - file.open(filename.c_str()); + file.open(filename.c_str(), std::ios_base::out); +} + +metrics_csv::~metrics_csv() +{ + stop(); } void metrics_csv::set_ue_handle(ue_metrics_interface *ue_) @@ -54,15 +59,20 @@ void metrics_csv::set_ue_handle(ue_metrics_interface *ue_) ue = ue_; } -void metrics_csv::set_periodicity(float metrics_report_period_sec) { - this->metrics_report_period = metrics_report_period_sec; +void metrics_csv::stop() +{ + if (file.is_open()) { + file << "#eof\n"; + file.flush(); + file.close(); + } } -void metrics_csv::set_metrics(ue_metrics_t &metrics) +void metrics_csv::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec) { if (file.is_open() && ue != NULL) { if(n_reports == 0) { - file << "time;rsrp;pl;cfo;dl_mcs;dl_snr;dl_turbo;dl_brate;dl_bler;ul_mcs;ul_buff;ul_brate;ul_bler;rf_o;rf_u;rf_l;is_attached" << endl; + file << "time;rsrp;pl;cfo;dl_mcs;dl_snr;dl_turbo;dl_brate;dl_bler;ul_mcs;ul_buff;ul_brate;ul_bler;rf_o;rf_u;rf_l;is_attached\n"; } file << (metrics_report_period*n_reports) << ";"; file << float_to_string(metrics.phy.dl.rsrp, 2); @@ -71,7 +81,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics) file << float_to_string(metrics.phy.dl.mcs, 2); file << float_to_string(metrics.phy.dl.sinr, 2); file << float_to_string(metrics.phy.dl.turbo_iters, 2); - file << float_to_string((float) metrics.mac.rx_brate/metrics_report_period, 2); + file << float_to_string((float) metrics.mac.rx_brate/period_usec*1e6, 2); if (metrics.mac.rx_pkts > 0) { file << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1); } else { @@ -79,7 +89,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics) } file << float_to_string(metrics.phy.ul.mcs, 2); file << float_to_string((float) metrics.mac.ul_buffer, 2); - file << float_to_string((float) metrics.mac.tx_brate/metrics_report_period, 2); + file << float_to_string((float) metrics.mac.tx_brate/period_usec*1e6, 2); if (metrics.mac.tx_pkts > 0) { file << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1); } else { @@ -89,7 +99,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics) file << float_to_string(metrics.rf.rf_u, 2); file << float_to_string(metrics.rf.rf_l, 2); file << (ue->is_attached() ? "1.0" : "0.0"); - file << endl; + file << "\n"; n_reports++; } else { diff --git a/srsue/src/metrics_stdout.cc b/srsue/src/metrics_stdout.cc index 9f413b65f..c8f373284 100644 --- a/srsue/src/metrics_stdout.cc +++ b/srsue/src/metrics_stdout.cc @@ -50,7 +50,6 @@ char const * const prefixes[2][9] = metrics_stdout::metrics_stdout() :do_print(false) ,n_reports(10) - ,metrics_report_period(1.0) ,ue(NULL) { } @@ -65,11 +64,7 @@ void metrics_stdout::toggle_print(bool b) do_print = b; } -void metrics_stdout::set_periodicity(float metrics_report_period_sec) { - this->metrics_report_period = metrics_report_period_sec; -} - -void metrics_stdout::set_metrics(ue_metrics_t &metrics) +void metrics_stdout::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec) { if(!do_print || ue == NULL) return; @@ -92,7 +87,7 @@ void metrics_stdout::set_metrics(ue_metrics_t &metrics) cout << float_to_string(metrics.phy.dl.mcs, 2); cout << float_to_string(metrics.phy.dl.sinr, 2); cout << float_to_string(metrics.phy.dl.turbo_iters, 2); - cout << float_to_eng_string((float) metrics.mac.rx_brate/metrics_report_period, 2); + cout << float_to_eng_string((float) metrics.mac.rx_brate/period_usec*1e6, 2); if (metrics.mac.rx_pkts > 0) { cout << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1) << "%"; } else { @@ -100,7 +95,7 @@ void metrics_stdout::set_metrics(ue_metrics_t &metrics) } cout << float_to_string(metrics.phy.ul.mcs, 2); cout << float_to_eng_string((float) metrics.mac.ul_buffer, 2); - cout << float_to_eng_string((float) metrics.mac.tx_brate/metrics_report_period, 2); + cout << float_to_eng_string((float) metrics.mac.tx_brate/period_usec*1e6, 2); if (metrics.mac.tx_pkts > 0) { cout << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1) << "%"; } else { diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index bbefd7f3d..7d89892c9 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -97,7 +97,7 @@ void phch_recv::init(srslte::radio_multi *_radio_handler, mac_interface_phy *_ma intra_freq_meas.init(worker_com, rrc, log_h); reset(); - + running = true; // Start main thread if (sync_cpu_affinity < 0) { start(prio); @@ -125,7 +125,6 @@ void phch_recv::stop() void phch_recv::reset() { tx_mutex_cnt = 0; - running = true; phy_state = IDLE; time_adv_sec = 0; next_offset = 0; @@ -690,6 +689,12 @@ void phch_recv::run_thread() worker->set_tti(tti, tx_mutex_cnt); tx_mutex_cnt = (tx_mutex_cnt+1) % nof_tx_mutex; + // Reset Uplink TX buffer to avoid mixing packets in TX queue + if (prach_buffer->is_pending()) { + Info("SYNC: PRACH pending: Reset UL\n"); + worker_com->reset_ul(); + } + // Check if we need to TX a PRACH if (prach_buffer->is_ready_to_send(tti)) { srslte_timestamp_copy(&tx_time_prach, &rx_time); @@ -706,21 +711,11 @@ void phch_recv::run_thread() srslte_pss_sic(&ue_sync.strack.pss, &buffer[0][SRSLTE_SF_LEN_PRB(cell.nof_prb)/2-ue_sync.strack.fft_size]); } intra_freq_meas.write(tti, buffer[0], SRSLTE_SF_LEN_PRB(cell.nof_prb)); - out_of_sync_cnt = 0; break; case 0: - // Signal every 5 errors only (PSS is every 5) - if (out_of_sync_cnt == 0) { - // Notify RRC of out-of-sync frame - log_h->error("SYNC: Sync error. Sending out-of-sync to RRC\n"); - rrc->out_of_sync(); - } + out_of_sync(); worker->release(); worker_com->reset_ul(); - out_of_sync_cnt++; - if (out_of_sync_cnt >= 5) { - out_of_sync_cnt = 0; - } break; default: radio_error(); @@ -746,14 +741,12 @@ void phch_recv::run_thread() } } +void phch_recv::in_sync() { + rrc->in_sync(); +} + void phch_recv::out_of_sync() { - out_of_sync2_cnt++; - Info("SYNC: Received out_of_sync from channel estimator (%d)\n", out_of_sync2_cnt); - if (out_of_sync2_cnt >= 2) { - out_of_sync2_cnt = 0; - Info("SYNC: Trying to resync signal\n"); - resync_sfn(true, true); - } + rrc->out_of_sync(); } @@ -1085,7 +1078,7 @@ phch_recv::measure::ret_code phch_recv::measure::run_subframe_sync(srslte_ue_syn { int sync_res = srslte_ue_sync_zerocopy_multi(ue_sync, buffer); if (sync_res == 1) { - log_h->info("SYNC: CFO=%.1f KHz\n", srslte_ue_sync_get_cfo(ue_sync)); + log_h->info("SYNC: CFO=%.1f KHz\n", srslte_ue_sync_get_cfo(ue_sync)/1000); return run_subframe(sf_idx); } else { log_h->error("SYNC: Measuring RSRP: Sync error\n"); @@ -1284,10 +1277,11 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, srslte_sync_reset(&sync_find); srslte_sync_cfo_reset(&sync_find); - uint32_t sf5_cnt=0; + int sf5_cnt=-1; do { + sf5_cnt++; sync_res = srslte_sync_find(&sync_find, input_buffer, sf5_cnt*5*sf_len, &peak_idx); - } while(sync_res != SRSLTE_SYNC_FOUND && sf5_cnt < nof_sf/5); + } while(sync_res != SRSLTE_SYNC_FOUND && (uint32_t) sf5_cnt + 1 < nof_sf/5); switch(sync_res) { case SRSLTE_SYNC_ERROR: @@ -1315,20 +1309,20 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, -srslte_sync_get_cfo(&sync_find)/sync_find.fft_size); - switch(measure_p.run_multiple_subframes(input_cfo_corrected, peak_idx, sf_idx, nof_sf)) { + switch(measure_p.run_multiple_subframes(input_cfo_corrected, peak_idx+sf5_cnt*5*sf_len, sf_idx, nof_sf)) { case measure::MEASURE_OK: cells[nof_cells].pci = found_cell.id; cells[nof_cells].rsrp = measure_p.rsrp(); cells[nof_cells].rsrq = measure_p.rsrq(); cells[nof_cells].offset = measure_p.frame_st_idx(); - Info("INTRA: Found neighbour cell %d: PCI=%03d, RSRP=%5.1f dBm, peak_idx=%5d, peak_value=%3.2f n_id_2=%d, CFO=%6.1f Hz\n", - nof_cells, cell_id, measure_p.rsrp(), measure_p.frame_st_idx(), sync_find.peak_value, n_id_2, 15000*srslte_sync_get_cfo(&sync_find)); + Info("INTRA: Found neighbour cell %d: PCI=%03d, RSRP=%5.1f dBm, peak_idx=%5d, peak_value=%3.2f, sf5_cnt=%d, n_id_2=%d, CFO=%6.1f Hz\n", + nof_cells, cell_id, measure_p.rsrp(), measure_p.frame_st_idx(), sync_find.peak_value, sf5_cnt, n_id_2, 15000*srslte_sync_get_cfo(&sync_find)); nof_cells++; if (sic_pss_enabled) { - srslte_pss_sic(&sync_find.pss, &input_buffer[sf_len/2-fft_sz]); + srslte_pss_sic(&sync_find.pss, &input_buffer[sf5_cnt*5*sf_len+sf_len/2-fft_sz]); } break; @@ -1349,7 +1343,7 @@ int phch_recv::scell_recv::find_cells(cf_t *input_buffer, float rx_gain_offset, default: break; } - } while (sync_res == SRSLTE_SYNC_FOUND && sic_pss_enabled); + } while (sync_res == SRSLTE_SYNC_FOUND && sic_pss_enabled && nof_cells < MAX_CELLS); } } return nof_cells; @@ -1477,16 +1471,16 @@ void phch_recv::intra_measure::write(uint32_t tti, cf_t *data, uint32_t nsamples } if (receiving == true) { if (srslte_ringbuffer_write(&ring_buffer, data, nsamples*sizeof(cf_t)) < (int) (nsamples*sizeof(cf_t))) { - Warning("Error writing to ringbuffer\n"); + Warning("Error writting to ringbuffer\n"); receiving = false; } else { receive_cnt++; if (receive_cnt == CAPTURE_LEN_SF) { tti_sync.increase(); + receiving = false; } } } - } } diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 2910f07ff..1569b0860 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -100,6 +100,7 @@ void phch_worker::reset() rar_cqi_request = false; I_sr = 0; cfi = 0; + rssi_read_cnt = 0; } void phch_worker::set_common(phch_common* phy_) @@ -175,8 +176,6 @@ void phch_worker::set_tti(uint32_t tti_, uint32_t tx_tti_) tx_tti = tx_tti_; log_h->step(tti); log_phy_lib_h->step(tti); - - } void phch_worker::set_cfo(float cfo_) @@ -224,13 +223,20 @@ void phch_worker::work_imp() bool ul_grant_available = false; bool dl_ack[SRSLTE_MAX_CODEWORDS] = {false}; - mac_interface_phy::mac_grant_t dl_mac_grant; - mac_interface_phy::tb_action_dl_t dl_action; - bzero(&dl_action, sizeof(mac_interface_phy::tb_action_dl_t)); + mac_interface_phy::mac_grant_t dl_mac_grant = {}; + mac_interface_phy::tb_action_dl_t dl_action = {}; + + mac_interface_phy::mac_grant_t ul_mac_grant = {}; + mac_interface_phy::tb_action_ul_t ul_action = {}; + - mac_interface_phy::mac_grant_t ul_mac_grant; - mac_interface_phy::tb_action_ul_t ul_action; - bzero(&ul_action, sizeof(mac_interface_phy::tb_action_ul_t)); + /** Calculate RSSI on the input signal before generating the output */ + + // Average RSSI over all symbols + float rssi_dbm = 10*log10(srslte_vec_avg_power_cf(signal_buffer[0], SRSLTE_SF_LEN_PRB(cell.nof_prb))) + 30; + if (isnormal(rssi_dbm)) { + phy->avg_rssi_dbm = SRSLTE_VEC_EMA(rssi_dbm, phy->avg_rssi_dbm, phy->args->snr_ema_coeff); + } /* Do FFT and extract PDCCH LLR, or quit if no actions are required in this subframe */ bool chest_ok = extract_fft_and_pdcch_llr(); @@ -289,7 +295,8 @@ void phch_worker::work_imp() // Decode PHICH bool ul_ack = false; - bool ul_ack_available = decode_phich(&ul_ack); + bool ul_ack_available = decode_phich(&ul_ack); + /***** Uplink Processing + Transmission *******/ @@ -364,13 +371,12 @@ void phch_worker::work_imp() if (chest_ok) { if (snr_th_ok) { - phy->rrc->in_sync(); - log_h->debug("SYNC: Sending in-sync to RRC\n"); + log_h->debug("SNR=%.1f dB sync=in-sync from channel estimator\n", 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))); + chest_loop->in_sync(); } else if (snr_th_err) { - chest_loop->out_of_sync(); - phy->rrc->out_of_sync(); - log_h->info("SNR=%.1f dB under threshold. Sending out-of-sync to RRC\n", + log_h->info("SNR=%.1f dB sync=out-of-sync from channel estimator\n", 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))); + chest_loop->out_of_sync(); } } @@ -391,13 +397,14 @@ void phch_worker::compute_ri(uint8_t *ri, uint8_t *pmi, float *sinr) { Debug("TM3 RI select %d layers, κ=%fdB\n", (*ri) + 1, cn); } else { /* If only one receiving antenna, force RI for 1 layer */ - uci_data.uci_ri = 0; + if (ri) { + *ri = 0; + } } uci_data.uci_ri_len = 1; } else if (phy->config->dedicated.antenna_info_explicit_value.tx_mode == LIBLTE_RRC_TRANSMISSION_MODE_4) { srslte_ue_dl_ri_pmi_select(&ue_dl, ri, pmi, sinr); Debug("TM4 ri=%d; pmi=%d; SINR=%.1fdB\n", ue_dl.ri, ue_dl.pmi[ue_dl.ri], 10*log10f(ue_dl.sinr[ue_dl.ri][ue_dl.pmi[ue_dl.ri]])); - uci_data.uci_ri_len = 1; } } @@ -771,7 +778,7 @@ bool phch_worker::decode_pdcch_ul(mac_interface_phy::mac_grant_t* grant) // Handle Format0 adaptive retx if (ret) { // Use last TBS for this TB in case of mcs>28 - if (grant->phy_grant.ul.mcs.idx > 28) { + if (grant->phy_grant.ul.mcs.idx > 28 && grant->phy_grant.ul.mcs.mod == SRSLTE_MOD_LAST) { // Make sure we received a grant in the previous TTI for this PID grant->phy_grant.ul.mcs.tbs = phy->last_ul_tbs[UL_PIDOF(TTI_TX(tti))]; grant->phy_grant.ul.mcs.mod = phy->last_ul_mod[UL_PIDOF(TTI_TX(tti))]; @@ -898,11 +905,11 @@ void phch_worker::set_uci_aperiodic_cqi() { uint8_t ri = (uint8_t) ue_dl.ri; uint8_t pmi = (uint8_t) ue_dl.pmi[ri]; - float sinr = ue_dl.sinr[ri][pmi]; + float sinr_db = ue_dl.sinr[ri][pmi]; if (phy->config->dedicated.cqi_report_cnfg.report_mode_aperiodic_present) { /* Compute RI, PMI and SINR */ - compute_ri(&ri, &pmi, &sinr); + compute_ri(&ri, &pmi, &sinr_db); switch(phy->config->dedicated.cqi_report_cnfg.report_mode_aperiodic) { case LIBLTE_RRC_CQI_REPORT_MODE_APERIODIC_RM30: @@ -922,10 +929,24 @@ void phch_worker::set_uci_aperiodic_cqi() // TODO: implement subband CQI properly cqi_report.subband_hl.subband_diff_cqi_cw0 = 0; // Always report zero offset on all subbands - cqi_report.subband_hl.N = (cell.nof_prb > 7) ? srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0; + cqi_report.subband_hl.N = (cell.nof_prb > 7) ? (uint32_t) srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0; + + int cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + if (cqi_len < 0) { + Error("Error packing CQI value (Aperiodic reporting mode RM31)."); + return; + } + uci_data.uci_cqi_len = (uint32_t) cqi_len; + + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = {0}; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); - Info("PUSCH: Aperiodic CQI=%d, SNR=%.1f dB, for %d subbands\n", cqi_report.wideband.wideband_cqi, phy->avg_snr_db, cqi_report.subband_hl.N); - uci_data.uci_cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + /* Set RI = 1 */ + uci_data.uci_ri = ri; + uci_data.uci_ri_len = 1; + + Info("PUSCH: Aperiodic RM30 ri%s, CQI=%s, SNR=%.1f dB, for %d subbands\n", + (uci_data.uci_ri == 0)?"=1":"~1", cqi_str, phy->avg_snr_db, cqi_report.subband_hl.N); } break; case LIBLTE_RRC_CQI_REPORT_MODE_APERIODIC_RM31: @@ -941,11 +962,6 @@ void phch_worker::set_uci_aperiodic_cqi() other transmission modes they are reported conditioned on rank 1. */ if (rnti_is_set) { - /* Select RI, PMI and SINR */ - uint32_t ri = ue_dl.ri; // Select RI (0: 1 layer, 1: 2 layer, otherwise: not implemented) - uint32_t pmi = ue_dl.pmi[ri]; // Select PMI - float sinr_db = 10 * log10(ue_dl.sinr[ri][pmi]); - /* Fill CQI Report */ srslte_cqi_value_t cqi_report = {0}; cqi_report.type = SRSLTE_CQI_TYPE_SUBBAND_HL; @@ -966,16 +982,27 @@ void phch_worker::set_uci_aperiodic_cqi() // TODO: implement subband CQI properly cqi_report.subband_hl.N = (uint32_t) ((cell.nof_prb > 7) ? srslte_cqi_hl_get_no_subbands(cell.nof_prb) : 0); + int cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); + if (cqi_len < 0) { + Error("Error packing CQI value (Aperiodic reporting mode RM31)."); + return; + } + uci_data.uci_cqi_len = (uint32_t) cqi_len; + uci_data.uci_ri_len = 1; + uci_data.uci_ri = ri; + + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = {0}; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); + if (cqi_report.subband_hl.rank_is_not_one) { - Info("PUSCH: Aperiodic ri~1, CQI=%02d/%02d, SINR=%2.1f/%2.1fdB, pmi=%d for %d subbands\n", + Info("PUSCH: Aperiodic RM31 ri~1, CQI=%02d/%02d, SINR=%2.1f/%2.1fdB, pmi=%d for %d subbands\n", cqi_report.subband_hl.wideband_cqi_cw0, cqi_report.subband_hl.wideband_cqi_cw1, sinr_db, sinr_db, pmi, cqi_report.subband_hl.N); } else { - Info("PUSCH: Aperiodic ri=1, CQI=%02d, SINR=%2.1f, pmi=%d for %d subbands\n", + Info("PUSCH: Aperiodic RM31 ri=1, CQI=%02d, SINR=%2.1f, pmi=%d for %d subbands\n", cqi_report.subband_hl.wideband_cqi_cw0, sinr_db, pmi, cqi_report.subband_hl.N); } - uci_data.uci_cqi_len = srslte_cqi_value_pack(&cqi_report, uci_data.uci_cqi); } break; default: @@ -1040,15 +1067,15 @@ void phch_worker::encode_pusch(srslte_ra_ul_grant_t *grant, uint8_t *payload, ui snprintf(timestr, 64, ", tot_time=%4d us", (int) logtime_start[0].tv_usec); #endif - char cqi_str[32] = ""; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, 32); + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = ""; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); uint8_t dummy[2] = {0,0}; log_h->info("PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s%s\n", (tti + HARQ_DELAY_MS) % 10240, grant->n_prb[0], grant->n_prb[0] + grant->L_prb, grant->mcs.tbs / 8, grant->mcs.idx, rv, - uci_data.uci_ack_len > 0 ? (uci_data.uci_ack ? ", ack=1" : "0") : "", + uci_data.uci_ack_len > 0 ? (uci_data.uci_ack ? ", ack=1" : ", ack=0") : "", uci_data.uci_ack_len > 1 ? (uci_data.uci_ack_2 ? "1" : "0") : "", uci_data.uci_ri_len > 0 ? (uci_data.uci_ri ? ", ri=1" : ", ri=0") : "", cfo * 15, timestr, @@ -1094,8 +1121,8 @@ void phch_worker::encode_pucch() float tx_power = srslte_ue_ul_pucch_power(&ue_ul, phy->pathloss, ue_ul.last_pucch_format, uci_data.uci_cqi_len, uci_data.uci_ack_len); float gain = set_power(tx_power); - char str_cqi[32] = ""; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, str_cqi, 32); + char str_cqi[SRSLTE_CQI_STR_MAX_CHAR] = ""; + srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, str_cqi, SRSLTE_CQI_STR_MAX_CHAR); Info("PUCCH: tti_tx=%d, n_pucch=%d, n_prb=%d, ack=%s%s%s%s%s, sr=%s, cfo=%.1f KHz%s\n", (tti + 4) % 10240, @@ -1132,10 +1159,7 @@ void phch_worker::encode_srs() float tx_power = srslte_ue_ul_srs_power(&ue_ul, phy->pathloss); float gain = set_power(tx_power); - uint32_t fi = srslte_vec_max_fi((float*) signal_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb)); - float *f = (float*) signal_buffer; Info("SRS: power=%.2f dBm, tti_tx=%d%s\n", tx_power, TTI_TX(tti), timestr); - } void phch_worker::enable_pregen_signals(bool enabled) @@ -1316,42 +1340,50 @@ void phch_worker::update_measurements() { float snr_ema_coeff = phy->args->snr_ema_coeff; if (chest_done) { - /* Compute ADC/RX gain offset every ~10s */ - if (tti== 0 || phy->rx_gain_offset == 0) { - float rx_gain_offset = 0; - if (phy->get_radio()->has_rssi() && phy->args->rssi_sensor_enabled) { - float rssi_all_signal = 30+10*log10(srslte_vec_avg_power_cf(signal_buffer[0],SRSLTE_SF_LEN(srslte_symbol_sz(cell.nof_prb)))); - rx_gain_offset = 30+rssi_all_signal-phy->get_radio()->get_rssi(); - } else { - rx_gain_offset = phy->get_radio()->get_rx_gain(); + + /* Only worker 0 reads the RSSI sensor every ~1-nof_cores s */ + if (get_id() == 0) { + if (rssi_read_cnt) { + if (phy->get_radio()->has_rssi() && phy->args->rssi_sensor_enabled) { + phy->last_radio_rssi = phy->get_radio()->get_rssi(); + phy->rx_gain_offset = phy->avg_rssi_dbm - phy->last_radio_rssi + 30; + } else { + phy->rx_gain_offset = phy->get_radio()->get_rx_gain(); + } } - if (phy->rx_gain_offset) { - phy->rx_gain_offset = SRSLTE_VEC_EMA(rx_gain_offset, phy->rx_gain_offset, 0.5); - } else { - phy->rx_gain_offset = rx_gain_offset; + rssi_read_cnt++; + if (rssi_read_cnt == 1000) { + rssi_read_cnt = 0; } } // Average RSRQ float rsrq_db = 10*log10(srslte_chest_dl_get_rsrq(&ue_dl.chest)); if (isnormal(rsrq_db)) { - phy->avg_rsrq_db = SRSLTE_VEC_EMA(rsrq_db, phy->avg_rsrq_db, snr_ema_coeff); + if (!phy->avg_rsrq_db) { + phy->avg_rsrq_db = SRSLTE_VEC_EMA(rsrq_db, phy->avg_rsrq_db, snr_ema_coeff); + } else { + phy->avg_rsrq_db = rsrq_db; + } } // Average RSRP float rsrp_lin = srslte_chest_dl_get_rsrp(&ue_dl.chest); if (isnormal(rsrp_lin)) { - phy->avg_rsrp = SRSLTE_VEC_EMA(rsrp_lin, phy->avg_rsrp, snr_ema_coeff); + if (!phy->avg_rsrp) { + phy->avg_rsrp = SRSLTE_VEC_EMA(rsrp_lin, phy->avg_rsrp, snr_ema_coeff); + } else { + phy->avg_rsrp = rsrp_lin; + } } /* Correct absolute power measurements by RX gain offset */ float rsrp_dbm = 10*log10(rsrp_lin) + 30 - phy->rx_gain_offset; - float rssi_db = 10*log10(srslte_chest_dl_get_rssi(&ue_dl.chest)) + 30 - phy->rx_gain_offset; // Serving cell measurements are averaged over DEFAULT_MEAS_PERIOD_MS then sent to RRC if (isnormal(rsrp_dbm)) { if (!phy->avg_rsrp_dbm) { - phy->avg_rsrp_dbm= rsrp_dbm; + phy->avg_rsrp_dbm = rsrp_dbm; } else { phy->avg_rsrp_dbm = SRSLTE_VEC_EMA(rsrp_dbm, phy->avg_rsrp_dbm, snr_ema_coeff); } @@ -1381,7 +1413,7 @@ void phch_worker::update_measurements() dl_metrics.n = phy->avg_noise; dl_metrics.rsrp = phy->avg_rsrp_dbm; dl_metrics.rsrq = phy->avg_rsrq_db; - dl_metrics.rssi = rssi_db; + dl_metrics.rssi = phy->avg_rssi_dbm; dl_metrics.pathloss = phy->pathloss; dl_metrics.sinr = phy->avg_snr_db; dl_metrics.turbo_iters = srslte_pdsch_last_noi(&ue_dl.pdsch); diff --git a/srsue/src/phy/prach.cc b/srsue/src/phy/prach.cc index 498ea1c6a..fdf925642 100644 --- a/srsue/src/phy/prach.cc +++ b/srsue/src/phy/prach.cc @@ -152,8 +152,12 @@ bool prach::prepare_to_send(uint32_t preamble_idx_, int allowed_subframe_, float } } +bool prach::is_pending() { + return cell_initiated && preamble_idx >= 0 && preamble_idx < 64; +} + bool prach::is_ready_to_send(uint32_t current_tti_) { - if (cell_initiated && preamble_idx >= 0 && preamble_idx < 64) { + if (is_pending()) { // consider the number of subframes the transmission must be anticipated uint32_t current_tti = (current_tti_ + tx_advance_sf)%10240; if (srslte_prach_tti_opportunity(&prach_obj, current_tti, allowed_subframe)) { diff --git a/srsue/src/upper/gw.cc b/srsue/src/upper/gw.cc index d8b4a8fdc..65748f57b 100644 --- a/srsue/src/upper/gw.cc +++ b/srsue/src/upper/gw.cc @@ -201,7 +201,8 @@ srslte::error_t gw::init_if(char *err_str) } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ); + strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ-1); + ifr.ifr_ifrn.ifrn_name[IFNAMSIZ-1] = 0; if(0 > ioctl(tun_fd, TUNSETIFF, &ifr)) { err_str = strerror(errno); diff --git a/srsue/src/upper/nas.cc b/srsue/src/upper/nas.cc index 9a9015af7..67305aaa3 100644 --- a/srsue/src/upper/nas.cc +++ b/srsue/src/upper/nas.cc @@ -193,9 +193,9 @@ void nas::notify_connection_setup() { } void nas::write_pdu(uint32_t lcid, byte_buffer_t *pdu) { - uint8 pd; - uint8 msg_type; - uint8 sec_hdr_type; + uint8 pd = 0; + uint8 msg_type = 0; + uint8 sec_hdr_type = 0; bool mac_valid = false; nas_log->info_hex(pdu->msg, pdu->N_bytes, "DL %s PDU", rrc->get_rb_name(lcid).c_str()); @@ -216,7 +216,7 @@ void nas::write_pdu(uint32_t lcid, byte_buffer_t *pdu) { case LIBLTE_MME_SECURITY_HDR_TYPE_INTEGRITY_AND_CIPHERED_WITH_NEW_EPS_SECURITY_CONTEXT: break; default: - nas_log->error("Not handling NAS message with SEC_HDR_TYPE=%02X\n",msg_type); + nas_log->error("Not handling NAS message with SEC_HDR_TYPE=%02X\n", sec_hdr_type); pool->deallocate(pdu); break; } diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 654d64b40..84e4bbfd1 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -722,7 +722,6 @@ float rrc::get_squal(float Qqualmeas) { // Detection of physical layer problems (5.3.11.1) void rrc::out_of_sync() { - // attempt resync current_cell->in_sync = false; if (!mac_timers->timer_get(t311)->is_running() && !mac_timers->timer_get(t310)->is_running()) { n310_cnt++; @@ -730,7 +729,8 @@ void rrc::out_of_sync() { mac_timers->timer_get(t310)->reset(); mac_timers->timer_get(t310)->run(); n310_cnt = 0; - rrc_log->info("Detected %d out-of-sync from PHY. Starting T310 timer\n", N310); + phy->sync_reset(); + rrc_log->info("Detected %d out-of-sync from PHY. Trying to resync. Starting T310 timer\n", N310); } } } diff --git a/srsue/test/mac/mac_test.cc b/srsue/test/mac/mac_test.cc index 4cb47e9f8..324189427 100644 --- a/srsue/test/mac/mac_test.cc +++ b/srsue/test/mac/mac_test.cc @@ -132,7 +132,7 @@ void setup_mac_phy_sib2(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT *sib2, srsue::ma memcpy(&common.pusch_cnfg, &sib2->rr_config_common_sib.pusch_cnfg, sizeof(LIBLTE_RRC_PUSCH_CONFIG_COMMON_STRUCT)); memcpy(&common.pucch_cnfg, &sib2->rr_config_common_sib.pucch_cnfg, sizeof(LIBLTE_RRC_PUCCH_CONFIG_COMMON_STRUCT)); memcpy(&common.ul_pwr_ctrl, &sib2->rr_config_common_sib.ul_pwr_ctrl, sizeof(LIBLTE_RRC_UL_POWER_CONTROL_COMMON_STRUCT)); - memcpy(&common.prach_cnfg, &sib2->rr_config_common_sib.prach_cnfg, sizeof(LIBLTE_RRC_PRACH_CONFIG_STRUCT)); + memcpy(&common.prach_cnfg, &sib2->rr_config_common_sib.prach_cnfg, sizeof(LIBLTE_RRC_PRACH_CONFIG_SIB_STRUCT)); if (sib2->rr_config_common_sib.srs_ul_cnfg.present) { memcpy(&common.srs_ul_cnfg, &sib2->rr_config_common_sib.srs_ul_cnfg, sizeof(LIBLTE_RRC_SRS_UL_CONFIG_COMMON_STRUCT)); } else {