From a0fb150e587034dc78ab491e083d7f14abb655b4 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Mon, 13 Apr 2020 17:22:50 +0200 Subject: [PATCH] Fix memory issues in PSCCH decoder --- lib/include/srslte/phy/common/phy_common_sl.h | 16 ++++--- lib/src/phy/ch_estimation/chest_sl.c | 40 +++-------------- lib/src/phy/phch/pscch.c | 8 ++-- lib/src/phy/phch/test/pscch_file_test.c | 44 +++++++++---------- 4 files changed, 42 insertions(+), 66 deletions(-) diff --git a/lib/include/srslte/phy/common/phy_common_sl.h b/lib/include/srslte/phy/common/phy_common_sl.h index 51fdd3e13..838b6beee 100644 --- a/lib/include/srslte/phy/common/phy_common_sl.h +++ b/lib/include/srslte/phy/common/phy_common_sl.h @@ -44,10 +44,10 @@ typedef enum SRSLTE_API { } srslte_sl_tm_t; typedef enum SRSLTE_API { - SRSLTE_SIDELINK_PSBCH = 0, - SRSLTE_SIDELINK_PSCCH, - SRSLTE_SIDELINK_PSSCH, - SRSLTE_SIDELINK_PSDCH + SRSLTE_SIDELINK_PSBCH = 0, // Physical Sidelink Broadcast Channel + SRSLTE_SIDELINK_PSCCH, // Physical Sidelink Control Channel + SRSLTE_SIDELINK_PSSCH, // Physical Sidelink Shared Channel + SRSLTE_SIDELINK_PSDCH // Physical Sidelink Discovery Channel } srslte_sl_channels_t; typedef struct SRSLTE_API { @@ -109,8 +109,6 @@ typedef enum SRSLTE_API { #define SRSLTE_PSCCH_MAX_NOF_PRB (SRSLTE_PSCCH_TM34_NOF_PRB) #define SRSLTE_PSCCH_SCRAMBLING_SEED (510) ///< Scrambling seed for PSCCH is 510 -#define SRSLTE_PSCCH_MAX_CODED_BITS (3 * (SRSLTE_SCI_MAX_LEN + SRSLTE_SCI_CRC_LEN)) - #define SRSLTE_PSCCH_TM12_NUM_DATA_SYMBOLS (12) #define SRSLTE_PSCCH_TM12_NUM_DMRS_SYMBOLS (2) #define SRSLTE_PSCCH_TM12_NUM_DATA_SYMBOLS_EXT (10) @@ -118,6 +116,12 @@ typedef enum SRSLTE_API { #define SRSLTE_PSCCH_TM34_NUM_DATA_SYMBOLS (10) #define SRSLTE_PSCCH_TM34_NUM_DMRS_SYMBOLS (4) +#define SRSLTE_PSCCH_TM12_NOF_CODED_BITS \ + (SRSLTE_NRE * SRSLTE_PSCCH_TM12_NUM_DATA_SYMBOLS * SRSLTE_PSCCH_TM12_NOF_PRB * SRSLTE_PSCCH_QM) +#define SRSLTE_PSCCH_TM34_NOF_CODED_BITS \ + (SRSLTE_NRE * SRSLTE_PSCCH_TM34_NUM_DATA_SYMBOLS * SRSLTE_PSCCH_TM34_NOF_PRB * SRSLTE_PSCCH_QM) +#define SRSLTE_PSCCH_MAX_CODED_BITS SRSLTE_MAX(SRSLTE_PSCCH_TM12_NOF_CODED_BITS, SRSLTE_PSCCH_TM34_NOF_CODED_BITS) + #define SRSLTE_PSSCH_CRC_LEN 24 #define SRSLTE_MAX_CODEWORD_LEN 168000 // 12 subcarriers * 100 PRB * 14 symbols * 10 bits, assuming 1024QAM #define SRSLTE_SL_SCH_MAX_TB_LEN 1000000 // Must be checked in 3GPP diff --git a/lib/src/phy/ch_estimation/chest_sl.c b/lib/src/phy/ch_estimation/chest_sl.c index eb7ae737d..816b5a045 100644 --- a/lib/src/phy/ch_estimation/chest_sl.c +++ b/lib/src/phy/ch_estimation/chest_sl.c @@ -296,14 +296,6 @@ static void chest_sl_psbch_ls_estimate(srslte_chest_sl_t* q, cf_t* sf_buffer) interpolate_pilots_sl_psbch(q); } -static void chest_sl_psbch_ls_equalize(srslte_chest_sl_t* q, cf_t* sf_buffer, cf_t* equalized_sf_buffer) -{ - srslte_chest_sl_estimate_noise(q); - - // Perform channel equalization - srslte_predecoding_single(sf_buffer, q->ce_average, equalized_sf_buffer, NULL, q->sf_n_re, 1, q->noise_estimated); -} - static int chest_sl_pscch_gen(srslte_chest_sl_t* q, uint32_t cyclic_shift) { // M_sc_rs - Reference Signal Length @@ -524,14 +516,6 @@ static void chest_sl_pscch_ls_estimate(srslte_chest_sl_t* q, cf_t* sf_buffer) interpolate_pilots_sl_pscch(q); } -static void chest_sl_pscch_ls_equalize(srslte_chest_sl_t* q, cf_t* sf_buffer, cf_t* equalized_sf_buffer) -{ - srslte_chest_sl_estimate_noise(q); - - // Perform channel equalization - srslte_predecoding_single(sf_buffer, q->ce_average, equalized_sf_buffer, NULL, q->sf_n_re, 1.0, q->noise_estimated); -} - static int chest_sl_pssch_gen(srslte_chest_sl_t* q) { // M_sc_rs - Reference Signal Length @@ -964,14 +948,6 @@ static void chest_sl_pssch_ls_estimate(srslte_chest_sl_t* q, cf_t* sf_buffer) interpolate_pilots_sl_pssch(q); } -static void chest_sl_pssch_ls_equalize(srslte_chest_sl_t* q, cf_t* sf_buffer, cf_t* equalized_sf_buffer) -{ - srslte_chest_sl_estimate_noise(q); - - // Perform channel equalization - srslte_predecoding_single(sf_buffer, q->ce_average, equalized_sf_buffer, NULL, q->sf_n_re, 1.0, q->noise_estimated); -} - static void get_subband_noise(srslte_chest_sl_t* q, uint32_t k_start, uint32_t k_end, uint32_t sf_nsymbols) { for (int k = k_start; k < k_end; k++) { @@ -1241,16 +1217,10 @@ void srslte_chest_sl_ls_estimate(srslte_chest_sl_t* q, cf_t* sf_buffer) void srslte_chest_sl_ls_equalize(srslte_chest_sl_t* q, cf_t* sf_buffer, cf_t* equalized_sf_buffer) { - switch (q->channel) { - case SRSLTE_SIDELINK_PSBCH: - return chest_sl_psbch_ls_equalize(q, sf_buffer, equalized_sf_buffer); - case SRSLTE_SIDELINK_PSCCH: - return chest_sl_pscch_ls_equalize(q, sf_buffer, equalized_sf_buffer); - case SRSLTE_SIDELINK_PSSCH: - return chest_sl_pssch_ls_equalize(q, sf_buffer, equalized_sf_buffer); - default: - return; - } + srslte_chest_sl_estimate_noise(q); + + // Perform channel equalization + srslte_predecoding_single(sf_buffer, q->ce_average, equalized_sf_buffer, NULL, q->sf_n_re, 1.0, q->noise_estimated); } void srslte_chest_sl_ls_estimate_equalize(srslte_chest_sl_t* q, cf_t* sf_buffer, cf_t* equalized_sf_buffer) @@ -1295,4 +1265,4 @@ void srslte_chest_sl_free(srslte_chest_sl_t* q) free(q->noise_tmp); } } -} \ No newline at end of file +} diff --git a/lib/src/phy/phch/pscch.c b/lib/src/phy/phch/pscch.c index c0b7605ee..7bbd19922 100644 --- a/lib/src/phy/phch/pscch.c +++ b/lib/src/phy/phch/pscch.c @@ -168,6 +168,7 @@ int srslte_pscch_set_cell(srslte_pscch_t* q, srslte_cell_sl_t cell) q->sci_len = srslte_sci_format0_sizeof(cell.nof_prb); q->nof_symbols = SRSLTE_PSCCH_TM12_NUM_DATA_SYMBOLS; q->pscch_nof_prb = SRSLTE_PSCCH_TM12_NOF_PRB; + q->E = SRSLTE_PSCCH_TM12_NOF_CODED_BITS; if (cell.cp == SRSLTE_CP_EXT) { q->nof_symbols = SRSLTE_PSCCH_TM12_NUM_DATA_SYMBOLS_EXT; @@ -176,15 +177,13 @@ int srslte_pscch_set_cell(srslte_pscch_t* q, srslte_cell_sl_t cell) q->sci_len = SRSLTE_SCI_TM34_LEN; q->nof_symbols = SRSLTE_PSCCH_TM34_NUM_DATA_SYMBOLS; q->pscch_nof_prb = SRSLTE_PSCCH_TM34_NOF_PRB; + q->E = SRSLTE_PSCCH_TM34_NOF_CODED_BITS; } else { return ret; } q->cell = cell; - ///< Calculate actual number of RE - q->E = SRSLTE_NRE * q->nof_symbols * q->pscch_nof_prb * SRSLTE_PSCCH_QM; - ///< Last OFDM symbol is processed but not transmitted q->nof_tx_re = (q->nof_symbols - 1) * SRSLTE_NRE * q->pscch_nof_prb; @@ -323,6 +322,9 @@ int srslte_pscch_get(srslte_pscch_t* q, cf_t* sf_buffer, uint32_t prb_start_idx) } } + // Force zeros in last symbol + srslte_vec_cf_zero(&q->scfdma_symbols[sample_pos], SRSLTE_NRE * q->pscch_nof_prb); + return sample_pos; } diff --git a/lib/src/phy/phch/test/pscch_file_test.c b/lib/src/phy/phch/test/pscch_file_test.c index 8071ab52a..4668aabb3 100644 --- a/lib/src/phy/phch/test/pscch_file_test.c +++ b/lib/src/phy/phch/test/pscch_file_test.c @@ -34,27 +34,27 @@ #include "srslte/phy/utils/debug.h" #include "srslte/phy/utils/vector.h" -char* input_file_name; -srslte_cell_sl_t cell = {.nof_prb = 6, .N_sl_id = 0, .tm = SRSLTE_SIDELINK_TM2, .cp = SRSLTE_CP_NORM}; -bool use_standard_lte_rates = false; -uint32_t file_offset = 0; +static char* input_file_name = NULL; +static srslte_cell_sl_t cell = {.nof_prb = 6, .N_sl_id = 0, .tm = SRSLTE_SIDELINK_TM2, .cp = SRSLTE_CP_NORM}; +static bool use_standard_lte_rates = false; +static uint32_t file_offset = 0; -uint32_t sf_n_samples; -uint32_t sf_n_re; -cf_t* sf_buffer; -cf_t* equalized_sf_buffer; -cf_t* input_buffer; -srslte_sci_t sci; -srslte_pscch_t pscch; -srslte_chest_sl_t pscch_chest; -srslte_ofdm_t fft; -srslte_sl_comm_resource_pool_t sl_comm_resource_pool; -uint32_t size_sub_channel = 10; -uint32_t num_sub_channel = 5; +static uint32_t sf_n_samples = 0; +static uint32_t sf_n_re = 0; +static cf_t* sf_buffer = NULL; +static cf_t* equalized_sf_buffer = NULL; +static cf_t* input_buffer = NULL; +static srslte_sci_t sci = {}; +static srslte_pscch_t pscch = {}; +static srslte_chest_sl_t pscch_chest = {}; +static srslte_ofdm_t fft = {}; +static srslte_sl_comm_resource_pool_t sl_comm_resource_pool = {}; +static uint32_t size_sub_channel = 10; +static uint32_t num_sub_channel = 5; -srslte_chest_sl_cfg_t pscch_chest_sl_cfg; +static srslte_chest_sl_cfg_t pscch_chest_sl_cfg = {}; -srslte_filesource_t fsrc; +static srslte_filesource_t fsrc = {}; void usage(char* prog) { @@ -88,13 +88,13 @@ void parse_args(int argc, char** argv) input_file_name = argv[optind]; break; case 's': - size_sub_channel = (int32_t)strtol(argv[optind], NULL, 10); + size_sub_channel = (uint32_t)strtol(argv[optind], NULL, 10); break; case 'n': - num_sub_channel = (int32_t)strtol(argv[optind], NULL, 10); + num_sub_channel = (uint32_t)strtol(argv[optind], NULL, 10); break; case 'p': - cell.nof_prb = (int32_t)strtol(argv[optind], NULL, 10); + cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10); break; case 't': switch ((int32_t)strtol(argv[optind], NULL, 10)) { @@ -134,7 +134,7 @@ void parse_args(int argc, char** argv) int base_init() { sf_n_samples = srslte_symbol_sz(cell.nof_prb) * 15; - sf_n_re = SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp); + sf_n_re = SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp); if (srslte_sl_comm_resource_pool_get_default_config(&sl_comm_resource_pool, cell) != SRSLTE_SUCCESS) { ERROR("Error initializing sl_comm_resource_pool\n");