diff --git a/lib/include/srsran/phy/phch/ra_nr.h b/lib/include/srsran/phy/phch/ra_nr.h index a2ddd5042..eb008ed1d 100644 --- a/lib/include/srsran/phy/phch/ra_nr.h +++ b/lib/include/srsran/phy/phch/ra_nr.h @@ -139,4 +139,13 @@ SRSRAN_API int srsran_ra_ul_set_grant_uci_nr(const srsran_carrier_nr_t* carri const srsran_uci_cfg_nr_t* uci_cfg, srsran_sch_cfg_nr_t* pusch_cfg); +/** + * @brief Calculates frequency allocation type 1 RIV field + * @param N_rb Number of resource blocks + * @param start_rb Start resource block index + * @param length_rb Number of resource blocks + * @return The RIV field with the encoded value + */ +SRSRAN_API uint32_t srsran_ra_nr_type1_riv(uint32_t N_rb, uint32_t start_rb, uint32_t length_rb); + #endif // SRSRAN_RA_NR_H diff --git a/lib/src/phy/phch/ra_dl_nr.c b/lib/src/phy/phch/ra_dl_nr.c index d3bf524e3..78eb6856f 100644 --- a/lib/src/phy/phch/ra_dl_nr.c +++ b/lib/src/phy/phch/ra_dl_nr.c @@ -319,3 +319,8 @@ int srsran_ra_dl_nr_freq(const srsran_carrier_nr_t* carrier, ERROR("Unhandled case"); return SRSRAN_ERROR; } + +uint32_t srsran_ra_nr_type1_riv(uint32_t N_prb, uint32_t start_rb, uint32_t length_rb) +{ + return ra_helper_from_s_and_l(N_prb, start_rb, length_rb); +} \ No newline at end of file diff --git a/lib/src/phy/phch/ra_helper.h b/lib/src/phy/phch/ra_helper.h index 029bb6ad6..004bf6075 100644 --- a/lib/src/phy/phch/ra_helper.h +++ b/lib/src/phy/phch/ra_helper.h @@ -73,6 +73,14 @@ static inline void ra_helper_compute_s_and_l(uint32_t N, uint32_t v, uint32_t* S } } +static inline uint32_t ra_helper_from_s_and_l(uint32_t N, uint32_t S, uint32_t L) +{ + if ((L - 1) <= N / 2) { + return N * (L - 1) + S; + } + return N * (N - L + 1) + (N - 1 - S); +} + static int ra_helper_freq_type1(uint32_t N_bwp_size, uint32_t riv, srsran_sch_grant_nr_t* grant) { uint32_t start = 0;