mirror of https://github.com/pvnis/srsRAN_4G.git
Moved NR time/frequency allocation SLIV to new component
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
|
@ -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);
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue