diff --git a/lib/include/srslte/phy/common/sequence.h b/lib/include/srslte/phy/common/sequence.h index c3857ecb9..95538f062 100644 --- a/lib/include/srslte/phy/common/sequence.h +++ b/lib/include/srslte/phy/common/sequence.h @@ -25,7 +25,7 @@ #include "srslte/config.h" #include "srslte/phy/common/phy_common.h" -#define SRSLTE_SEQUENCE_MOD(X) ((X) & (uint32_t)INT32_MAX) +#define SRSLTE_SEQUENCE_MOD(X) ((uint32_t)((X) & (uint64_t)INT32_MAX)) typedef struct SRSLTE_API { uint32_t x1; diff --git a/lib/src/phy/ch_estimation/dmrs_pucch.c b/lib/src/phy/ch_estimation/dmrs_pucch.c index 92aab871a..f4666902e 100644 --- a/lib/src/phy/ch_estimation/dmrs_pucch.c +++ b/lib/src/phy/ch_estimation/dmrs_pucch.c @@ -292,7 +292,7 @@ static uint32_t dmrs_pucch_format2_cinit(const srslte_carrier_nr_t* car uint32_t n = SRSLTE_SLOT_NR_MOD(slot->idx, carrier->numerology); uint32_t n_id = (cfg->scrambling_id_present) ? cfg->scambling_id : carrier->id; - return SRSLTE_SEQUENCE_MOD((((SRSLTE_NSYMB_PER_SLOT_NR * n + l + 1U) * (2U * n_id + 1U)) << 17U) + 2U * n_id); + return SRSLTE_SEQUENCE_MOD((((SRSLTE_NSYMB_PER_SLOT_NR * n + l + 1UL) * (2UL * n_id + 1UL)) << 17UL) + 2UL * n_id); } int srslte_dmrs_pucch_format2_put(const srslte_pucch_nr_t* q, diff --git a/lib/src/phy/phch/pucch_nr.c b/lib/src/phy/phch/pucch_nr.c index da981920f..db9cbf7c4 100644 --- a/lib/src/phy/phch/pucch_nr.c +++ b/lib/src/phy/phch/pucch_nr.c @@ -520,10 +520,12 @@ int srslte_pucch_nr_format1_decode(srslte_pucch_nr_t* q, return SRSLTE_SUCCESS; } -static uint32_t pucch_nr_format2_cinit(const srslte_pucch_nr_common_cfg_t* pucch_cfg, +static uint32_t pucch_nr_format2_cinit(const srslte_carrier_nr_t* carrier, + const srslte_pucch_nr_common_cfg_t* pucch_cfg, const srslte_uci_cfg_nr_t* uci_cfg) { - uint32_t n_id = (pucch_cfg->scrambling_id_present) ? pucch_cfg->scrambling_id_present : uci_cfg->rnti; + uint32_t n_id = (pucch_cfg->scrambling_id_present) ? pucch_cfg->scrambling_id_present : carrier->id; + return ((uint32_t)uci_cfg->rnti << 15U) + n_id; } @@ -544,7 +546,7 @@ static int pucch_nr_format2_encode(srslte_pucch_nr_t* q, uint32_t E = srslte_uci_nr_pucch_format_2_3_4_E(resource); // 6.3.2.5.1 Scrambling - uint32_t cinit = pucch_nr_format2_cinit(cfg, uci_cfg); + uint32_t cinit = pucch_nr_format2_cinit(carrier, cfg, uci_cfg); srslte_sequence_apply_bit(q->b, q->b, E, cinit); // 6.3.2.5.2 Modulation @@ -555,7 +557,8 @@ static int pucch_nr_format2_encode(srslte_pucch_nr_t* q, uint32_t l_end = resource->start_symbol_idx + resource->nof_symbols; uint32_t k_start = SRSLTE_MIN(carrier->nof_prb - 1, resource->starting_prb) * SRSLTE_NRE; uint32_t k_end = SRSLTE_MIN(carrier->nof_prb, resource->starting_prb + resource->nof_prb) * SRSLTE_NRE; - for (uint32_t l = l_start, i = 0; l < l_end; l++) { + uint32_t i = 0; + for (uint32_t l = l_start; l < l_end; l++) { cf_t* symbol_ptr = &slot_symbols[l * carrier->nof_prb * SRSLTE_NRE]; for (uint32_t k = k_start; k < k_end; k += 3) { symbol_ptr[k] = q->d[i++]; @@ -563,6 +566,17 @@ static int pucch_nr_format2_encode(srslte_pucch_nr_t* q, } } + if (i * 2 != E) { + ERROR("Unmatched number of channel bits (%d!=%d); rb=(%d,%d); sym=(%d,%d)\n", + E, + 2 * i, + k_start, + k_end, + l_start, + l_end); + return SRSLTE_ERROR; + } + return SRSLTE_SUCCESS; } @@ -621,7 +635,7 @@ static int pucch_nr_format2_decode(srslte_pucch_nr_t* q, } // Undo Scrambling - uint32_t cinit = pucch_nr_format2_cinit(cfg, uci_cfg); + uint32_t cinit = pucch_nr_format2_cinit(carrier, cfg, uci_cfg); srslte_sequence_apply_c(llr, llr, E, cinit); return SRSLTE_SUCCESS;