From 68a1868c33e467bca55f505b47aba49695d26f50 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 28 Apr 2020 10:40:34 +0200 Subject: [PATCH] npdsch_{ue,enodeb}: few more LGTM fixes --- lib/examples/npdsch_enodeb.c | 58 +++++++++++----------- lib/examples/npdsch_ue.c | 36 +++++++------- lib/include/srslte/phy/common/phy_common.h | 2 + 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/lib/examples/npdsch_enodeb.c b/lib/examples/npdsch_enodeb.c index 364eec96e..594b7df40 100644 --- a/lib/examples/npdsch_enodeb.c +++ b/lib/examples/npdsch_enodeb.c @@ -45,8 +45,9 @@ #define HAVE_NPDSCH 1 #define NPDCCH_SF_IDX 1 -const uint8_t dummy_sib1_payload[] = {0x43, 0x4d, 0xd0, 0x92, 0x22, 0x06, 0x04, 0x30, 0x28, 0x6e, 0x87, 0xd0, 0x4b, - 0x13, 0x90, 0xb4, 0x12, 0xa1, 0x02, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +static const uint8_t dummy_sib1_payload[] = {0x43, 0x4d, 0xd0, 0x92, 0x22, 0x06, 0x04, 0x30, 0x28, + 0x6e, 0x87, 0xd0, 0x4b, 0x13, 0x90, 0xb4, 0x12, 0xa1, + 0x02, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; #ifndef DISABLE_RF #include "srslte/phy/rf/rf.h" @@ -55,7 +56,7 @@ static srslte_rf_t radio; #pragma message "Compiling npdsch_ue with no RF support" #endif -char* output_file_name = NULL; +static char* output_file_name = NULL; srslte_nbiot_cell_t cell = { .base = {.nof_ports = 1, .nof_prb = SRSLTE_NBIOT_DEFAULT_NUM_PRB_BASECELL, .cp = SRSLTE_CP_NORM, .id = 0}, @@ -73,27 +74,28 @@ static char* rf_args = ""; static float rf_amp = 0.8, rf_gain = 70.0, rf_freq = 0; static float file_snr = -100.0; -bool null_file_sink = false; -srslte_random_t* random_gen; -srslte_filesink_t fsink; -srslte_ofdm_t ifft; -srslte_npss_synch_t npss_sync; -srslte_nsss_synch_t nsss_sync; -srslte_npbch_t npbch; -srslte_npdcch_t npdcch; -srslte_npdsch_t npdsch; -srslte_npdsch_cfg_t sib1_npdsch_cfg; -srslte_npdsch_cfg_t npdsch_cfg; -srslte_nbiot_ue_dl_t ue_dl; -srslte_softbuffer_tx_t softbuffer; -srslte_ra_nbiot_dl_dci_t ra_dl; -srslte_ra_nbiot_dl_dci_t ra_dl_sib1; -srslte_chest_dl_nbiot_t est; -srslte_mib_nb_t mib_nb; -uint32_t sched_info_tag = 0; // according to Table 16.4.1.3-3 in 36.213, 0 means 4 NPDSCH repetitions with TBS 208 - -cf_t *sf_buffer = NULL, *output_buffer = NULL; -int sf_n_re = 0, sf_n_samples = 0; +static bool null_file_sink = false; +static srslte_random_t* random_gen; +static srslte_filesink_t fsink; +static srslte_ofdm_t ifft; +static srslte_npss_synch_t npss_sync; +static srslte_nsss_synch_t nsss_sync; +static srslte_npbch_t npbch; +static srslte_npdcch_t npdcch; +static srslte_npdsch_t npdsch; +static srslte_npdsch_cfg_t sib1_npdsch_cfg; +static srslte_npdsch_cfg_t npdsch_cfg; +static srslte_nbiot_ue_dl_t ue_dl; +static srslte_softbuffer_tx_t softbuffer; +static srslte_ra_nbiot_dl_dci_t ra_dl; +static srslte_ra_nbiot_dl_dci_t ra_dl_sib1; +static srslte_chest_dl_nbiot_t ch_est; +static srslte_mib_nb_t mib_nb; +static uint32_t sched_info_tag = + 0; // according to Table 16.4.1.3-3 in 36.213, 0 means 4 NPDSCH repetitions with TBS 208 + +static cf_t *sf_buffer = NULL, *output_buffer = NULL; +static int sf_n_re = 0, sf_n_samples = 0; void usage(char* prog) { @@ -284,7 +286,7 @@ void base_free() srslte_npdsch_free(&npdsch); srslte_npdcch_free(&npdcch); srslte_npbch_free(&npbch); - srslte_chest_dl_nbiot_free(&est); + srslte_chest_dl_nbiot_free(&ch_est); srslte_npss_synch_free(&npss_sync); srslte_nsss_synch_free(&nsss_sync); srslte_ofdm_tx_free(&ifft); @@ -474,11 +476,11 @@ int main(int argc, char** argv) #endif /* Generate CRS+NRS signals */ - if (srslte_chest_dl_nbiot_init(&est, SRSLTE_NBIOT_MAX_PRB)) { + if (srslte_chest_dl_nbiot_init(&ch_est, SRSLTE_NBIOT_MAX_PRB)) { fprintf(stderr, "Error initializing equalizer\n"); exit(-1); } - if (srslte_chest_dl_nbiot_set_cell(&est, cell) != SRSLTE_SUCCESS) { + if (srslte_chest_dl_nbiot_set_cell(&ch_est, cell) != SRSLTE_SUCCESS) { fprintf(stderr, "Error setting channel estimator's cell configuration\n"); return -1; } @@ -557,7 +559,7 @@ int main(int argc, char** argv) } else { // NRS in all other subframes (using CSR signal intentionally) // DEBUG("%d.%d: Putting %d NRS pilots\n", sfn, sf_idx, SRSLTE_REFSIGNAL_NUM_SF(1, cell.nof_ports)); - srslte_refsignal_nrs_put_sf(cell, 0, est.nrs_signal.pilots[0][sf_idx], sf_buffer); + srslte_refsignal_nrs_put_sf(cell, 0, ch_est.nrs_signal.pilots[0][sf_idx], sf_buffer); } #if HAVE_NPDSCH diff --git a/lib/examples/npdsch_ue.c b/lib/examples/npdsch_ue.c index 1c4c13f8a..d3e030e00 100644 --- a/lib/examples/npdsch_ue.c +++ b/lib/examples/npdsch_ue.c @@ -235,7 +235,7 @@ void parse_args(prog_args_t* args, int argc, char** argv) } /**********************************************************************/ -static uint8_t data[20000]; // Byte buffer for rx'ed transport blocks +static uint8_t rx_tb[SRSLTE_MAX_DL_BITS_CAT_NB1]; // Byte buffer for rx'ed transport blocks bool go_exit = false; void sig_int_handler(int signo) @@ -264,8 +264,8 @@ void pcap_pack_and_write(FILE* pcap_file, .ueid = 1, .isRetx = reTX, .crcStatusOK = crc_ok, - .sysFrameNumber = (uint16_t)(tti / 10), - .subFrameNumber = (uint16_t)(tti % 10), + .sysFrameNumber = (uint16_t)(tti / SRSLTE_NOF_SF_X_FRAME), + .subFrameNumber = (uint16_t)(tti % SRSLTE_NOF_SF_X_FRAME), .nbiotMode = 1}; if (pdu) { LTE_PCAP_MAC_WritePDU(pcap_file, &context, pdu, pdu_len_bytes); @@ -574,10 +574,10 @@ int main(int argc, char** argv) srslte_nbiot_ue_dl_set_rnti(&ue_dl, prog_args.rnti); // Pretty-print MIB - srslte_bit_pack_vector(bch_payload, data, SRSLTE_MIB_NB_CRC_LEN); + srslte_bit_pack_vector(bch_payload, rx_tb, SRSLTE_MIB_NB_CRC_LEN); #ifdef ENABLE_GUI if (bcch_bch_to_pretty_string( - data, SRSLTE_MIB_NB_CRC_LEN, mib_buffer_decode, sizeof(mib_buffer_decode))) { + rx_tb, SRSLTE_MIB_NB_CRC_LEN, mib_buffer_decode, sizeof(mib_buffer_decode))) { fprintf(stderr, "Error decoding MIB\n"); } #endif @@ -585,11 +585,11 @@ int main(int argc, char** argv) #if HAVE_PCAP // write to PCAP pcap_pack_and_write(pcap_file, - data, + rx_tb, SRSLTE_MIB_NB_CRC_LEN, 0, true, - system_frame_number * 10, + system_frame_number * SRSLTE_NOF_SF_X_FRAME, 0, DIRECTION_DOWNLINK, NO_RNTI); @@ -605,34 +605,34 @@ int main(int argc, char** argv) if (!have_sib1) { int dec_ret = srslte_nbiot_ue_dl_decode_npdsch(&ue_dl, &buff_ptrs[0][prog_args.time_offset], - data, + rx_tb, system_frame_number, srslte_ue_sync_nbiot_get_sfidx(&ue_sync), SRSLTE_SIRNTI); if (dec_ret == SRSLTE_SUCCESS) { printf("SIB1 received\n"); srslte_sys_info_block_type_1_nb_t sib = {}; - srslte_npdsch_sib1_unpack(data, &sib); + srslte_npdsch_sib1_unpack(rx_tb, &sib); hyper_frame_number = sib.hyper_sfn; have_sib1 = true; #ifdef ENABLE_GUI if (bcch_dl_sch_to_pretty_string( - data, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, sib1_buffer_decode, sizeof(sib1_buffer_decode))) { + rx_tb, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, sib1_buffer_decode, sizeof(sib1_buffer_decode))) { fprintf(stderr, "Error decoding SIB1\n"); } #endif // Decode SIB1 and extract SIB2 scheduling params - get_sib2_params(data, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, &sib2_params); + get_sib2_params(rx_tb, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, &sib2_params); // Activate SIB2 decoding srslte_nbiot_ue_dl_decode_sib( &ue_dl, hyper_frame_number, system_frame_number, SRSLTE_NBIOT_SI_TYPE_SIB2, sib2_params); #if HAVE_PCAP pcap_pack_and_write(pcap_file, - data, + rx_tb, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, 0, true, @@ -654,7 +654,7 @@ int main(int argc, char** argv) // SIB2 is transmitted over multiple subframes, so this needs to be called more than once .. int dec_ret = srslte_nbiot_ue_dl_decode_npdsch(&ue_dl, &buff_ptrs[0][prog_args.time_offset], - data, + rx_tb, system_frame_number, srslte_ue_sync_nbiot_get_sfidx(&ue_sync), SRSLTE_SIRNTI); @@ -664,14 +664,14 @@ int main(int argc, char** argv) #ifdef ENABLE_GUI if (bcch_dl_sch_to_pretty_string( - data, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, sib2_buffer_decode, sizeof(sib2_buffer_decode))) { + rx_tb, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, sib2_buffer_decode, sizeof(sib2_buffer_decode))) { fprintf(stderr, "Error decoding SIB2\n"); } #endif #if HAVE_PCAP pcap_pack_and_write(pcap_file, - data, + rx_tb, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, 0, true, @@ -701,7 +701,7 @@ int main(int argc, char** argv) // attempt to decode NPDSCH n = srslte_nbiot_ue_dl_decode_npdsch(&ue_dl, &buff_ptrs[0][prog_args.time_offset], - data, + rx_tb, system_frame_number, srslte_ue_sync_nbiot_get_sfidx(&ue_sync), prog_args.rnti); @@ -741,7 +741,7 @@ int main(int argc, char** argv) // decode SIB1 over and over again n = srslte_nbiot_ue_dl_decode_npdsch(&ue_dl, &buff_ptrs[0][prog_args.time_offset], - data, + rx_tb, system_frame_number, srslte_ue_sync_nbiot_get_sfidx(&ue_sync), prog_args.rnti); @@ -749,7 +749,7 @@ int main(int argc, char** argv) #ifdef ENABLE_GUI if (n == SRSLTE_SUCCESS) { if (bcch_dl_sch_to_pretty_string( - data, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, sib1_buffer_decode, sizeof(sib1_buffer_decode))) { + rx_tb, ue_dl.npdsch_cfg.grant.mcs[0].tbs / 8, sib1_buffer_decode, sizeof(sib1_buffer_decode))) { fprintf(stderr, "Error decoding SIB1\n"); } } diff --git a/lib/include/srslte/phy/common/phy_common.h b/lib/include/srslte/phy/common/phy_common.h index 258cac26d..4acd87a74 100644 --- a/lib/include/srslte/phy/common/phy_common.h +++ b/lib/include/srslte/phy/common/phy_common.h @@ -340,6 +340,8 @@ typedef struct SRSLTE_API { #define SRSLTE_NBIOT_NPBCH_NOF_BITS_SF \ (SRSLTE_NBIOT_NPBCH_NOF_TOTAL_BITS / 8) ///< The NPBCH is transmitted in 8 blocks (See 36.211 Sec 10.2.4.4) +#define SRSLTE_MAX_DL_BITS_CAT_NB1 (680) ///< TS 36.306 v15.4.0 Table 4.1C-1 + ///< PHY common function declarations SRSLTE_API bool srslte_cell_isvalid(srslte_cell_t* cell);