Moved NR time/frequency allocation SLIV to new component

master
Xavier Arteaga 3 years ago committed by Xavier Arteaga
parent 359cff2302
commit 5d149a4b78

@ -0,0 +1,23 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2021 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
#ifndef SRSRAN_SLIV_H
#define SRSRAN_SLIV_H
#include "srsran/config.h"
#include <inttypes.h>
SRSRAN_API void srsran_sliv_to_s_and_l(uint32_t N, uint32_t v, uint32_t* S, uint32_t* L);
SRSRAN_API uint32_t srsran_sliv_from_s_and_l(uint32_t N, uint32_t S, uint32_t L);
#endif // SRSRAN_SLIV_H

@ -6,7 +6,7 @@
# the distribution. # the distribution.
# #
set(SOURCES phy_common.c phy_common_sl.c phy_common_nr.c sequence.c timestamp.c zc_sequence.c) set(SOURCES phy_common.c phy_common_sl.c phy_common_nr.c sequence.c timestamp.c zc_sequence.c sliv.c)
add_library(srsran_phy_common OBJECT ${SOURCES}) add_library(srsran_phy_common OBJECT ${SOURCES})
add_subdirectory(test) add_subdirectory(test)

@ -0,0 +1,34 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2021 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
#include "srsran/phy/common/sliv.h"
void srsran_sliv_to_s_and_l(uint32_t N, uint32_t v, uint32_t* S, uint32_t* L)
{
uint32_t low = v % N;
uint32_t high = v / N;
if (high + 1 + low <= N) {
*S = low;
*L = high + 1;
} else {
*S = N - 1 - low;
*L = N - high + 1;
}
}
uint32_t srsran_sliv_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);
}

@ -14,3 +14,14 @@ add_executable(sequence_test sequence_test.c)
target_link_libraries(sequence_test srsran_phy) target_link_libraries(sequence_test srsran_phy)
add_test(sequence_test sequence_test) add_test(sequence_test sequence_test)
########################################################################
# SLIV TEST
########################################################################
add_executable(sliv_test sliv_test.c)
target_link_libraries(sliv_test srsran_phy)
add_test(sliv_test_14 sliv_test 14)
add_test(sliv_test_52 sliv_test 48)
add_test(sliv_test_52 sliv_test 52)

@ -0,0 +1,71 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2021 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
#include "srsran/common/test_common.h"
#include "srsran/phy/common/sliv.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
static uint32_t N = 48;
static int test()
{
for (uint32_t s = 0; s < N; s++) {
for (uint32_t l = 1; l < N - s; l++) {
uint32_t sliv = srsran_sliv_from_s_and_l(N, s, l);
uint32_t S = 0;
uint32_t L = 0;
srsran_sliv_to_s_and_l(N, sliv, &S, &L);
if (s != S || l != L) {
printf("s=%d; l=%d; SLIV=%d; Start: %d; Length: %d;\n", s, l, sliv, S, L);
return SRSRAN_ERROR;
}
}
}
return SRSRAN_SUCCESS;
}
int main(int argc, char** argv)
{
// Parse N
if (argc >= 2) {
N = (uint32_t)strtol(argv[1], NULL, 10);
}
// If two arguments, run brute force test
if (argc == 2) {
return test();
}
// if three arguments, calculate start and length from sliv
if (argc == 3) {
uint32_t sliv = (uint32_t)strtol(argv[2], NULL, 10);
uint32_t S = 0;
uint32_t L = 0;
srsran_sliv_to_s_and_l(N, sliv, &S, &L);
printf("SLIV=%d; Start: %d; Length: %d;\n", sliv, S, L);
return SRSRAN_SUCCESS;
}
// if four arguments, calculate sliv from start and length
if (argc == 4) {
uint32_t s = (uint32_t)strtol(argv[2], NULL, 10);
uint32_t l = (uint32_t)strtol(argv[3], NULL, 10);
uint32_t sliv = srsran_sliv_from_s_and_l(N, s, l);
printf("SLIV=%d; Start: %d; Length: %d;\n", sliv, s, l);
return SRSRAN_SUCCESS;
}
}

@ -115,7 +115,7 @@ int srsran_ra_dl_nr_time_default_A(uint32_t m, srsran_dmrs_sch_typeA_pos_t dmrs_
static void ra_dl_nr_time_hl(const srsran_sch_time_ra_t* hl_ra_cfg, srsran_sch_grant_nr_t* grant) static void ra_dl_nr_time_hl(const srsran_sch_time_ra_t* hl_ra_cfg, srsran_sch_grant_nr_t* grant)
{ {
// Compute S and L from SLIV from higher layers // Compute S and L from SLIV from higher layers
ra_helper_compute_s_and_l(SRSRAN_NSYMB_PER_SLOT_NR, hl_ra_cfg->sliv, &grant->S, &grant->L); srsran_sliv_to_s_and_l(SRSRAN_NSYMB_PER_SLOT_NR, hl_ra_cfg->sliv, &grant->S, &grant->L);
grant->k = hl_ra_cfg->k; grant->k = hl_ra_cfg->k;
grant->mapping = hl_ra_cfg->mapping_type; grant->mapping = hl_ra_cfg->mapping_type;
@ -322,5 +322,5 @@ int srsran_ra_dl_nr_freq(const srsran_carrier_nr_t* carrier,
uint32_t srsran_ra_nr_type1_riv(uint32_t N_prb, uint32_t start_rb, uint32_t length_rb) 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); return srsran_sliv_from_s_and_l(N_prb, start_rb, length_rb);
} }

@ -13,6 +13,7 @@
#ifndef SRSRAN_RA_HELPER_H #ifndef SRSRAN_RA_HELPER_H
#define SRSRAN_RA_HELPER_H #define SRSRAN_RA_HELPER_H
#include "srsran/phy/common/sliv.h"
#include "srsran/phy/utils/debug.h" #include "srsran/phy/utils/debug.h"
#include "srsran/phy/utils/vector.h" #include "srsran/phy/utils/vector.h"
#include <stdint.h> #include <stdint.h>
@ -60,32 +61,11 @@ static int ra_helper_freq_type0(const srsran_carrier_nr_t* carrier,
return 0; return 0;
} }
static inline void ra_helper_compute_s_and_l(uint32_t N, uint32_t v, uint32_t* S, uint32_t* L)
{
uint32_t low = v % N;
uint32_t high = v / N;
if (high + 1 + low <= N) {
*S = low;
*L = high + 1;
} else {
*S = N - 1 - low;
*L = N - high + 1;
}
}
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) static int ra_helper_freq_type1(uint32_t N_bwp_size, uint32_t riv, srsran_sch_grant_nr_t* grant)
{ {
uint32_t start = 0; uint32_t start = 0;
uint32_t len = 0; uint32_t len = 0;
ra_helper_compute_s_and_l(N_bwp_size, riv, &start, &len); srsran_sliv_to_s_and_l(N_bwp_size, riv, &start, &len);
if (start + len > N_bwp_size) { if (start + len > N_bwp_size) {
ERROR("RIV 0x%x for BWP size %d resulted in freq=%d:%d", riv, N_bwp_size, start, len); ERROR("RIV 0x%x for BWP size %d resulted in freq=%d:%d", riv, N_bwp_size, start, len);

@ -73,7 +73,7 @@ int srsran_ra_ul_nr_pusch_time_resource_default_A(uint32_t scs_cfg, uint32_t m,
static void ra_ul_nr_time_hl(const srsran_sch_time_ra_t* hl_ra_cfg, srsran_sch_grant_nr_t* grant) static void ra_ul_nr_time_hl(const srsran_sch_time_ra_t* hl_ra_cfg, srsran_sch_grant_nr_t* grant)
{ {
// Compute S and L from SLIV from higher layers // Compute S and L from SLIV from higher layers
ra_helper_compute_s_and_l(SRSRAN_NSYMB_PER_SLOT_NR, hl_ra_cfg->sliv, &grant->S, &grant->L); srsran_sliv_to_s_and_l(SRSRAN_NSYMB_PER_SLOT_NR, hl_ra_cfg->sliv, &grant->S, &grant->L);
grant->k = hl_ra_cfg->k; grant->k = hl_ra_cfg->k;
grant->mapping = hl_ra_cfg->mapping_type; grant->mapping = hl_ra_cfg->mapping_type;

Loading…
Cancel
Save