Commit a50cb354 authored by Sakthivel Velumani's avatar Sakthivel Velumani

Simplify map_current_symbol() function

parent e4c37fb3
...@@ -102,6 +102,7 @@ applicable. ...@@ -102,6 +102,7 @@ applicable.
/* /*
DMRS mapping in a RB for Type 1. DMRS mapping in a RB for Type 1.
Mapping as in TS 38.211 6.4.1.1.3 k = 4n + 2k^prime + delta
*/ */
static void map_dmrs_type1_cdm1_rb(const unsigned int delta, const c16_t *dmrs, c16_t *out) static void map_dmrs_type1_cdm1_rb(const unsigned int delta, const c16_t *dmrs, c16_t *out)
{ {
...@@ -132,8 +133,8 @@ static void map_data_dmrs_type1_cdm1_rb(const unsigned int num_cdm_no_data, cons ...@@ -132,8 +133,8 @@ static void map_data_dmrs_type1_cdm1_rb(const unsigned int num_cdm_no_data, cons
/* /*
Map DMRS for type 2 Map DMRS for type 2
Mapping as in TS 38.211 6.4.1.1.3 k = 6n + k^prime + delta
*/ */
static void map_dmrs_type2_rb(const unsigned int delta, const c16_t *dmrs, c16_t *out) static void map_dmrs_type2_rb(const unsigned int delta, const c16_t *dmrs, c16_t *out)
{ {
memcpy(out + delta, dmrs, sizeof(c16_t) * NR_DMRS_TYPE2_CDM_GRP_SIZE); memcpy(out + delta, dmrs, sizeof(c16_t) * NR_DMRS_TYPE2_CDM_GRP_SIZE);
...@@ -186,50 +187,50 @@ static void map_over_dc(const unsigned int right_dc, ...@@ -186,50 +187,50 @@ static void map_over_dc(const unsigned int right_dc,
const unsigned int data_per_rb, const unsigned int data_per_rb,
const unsigned int delta, const unsigned int delta,
const unsigned int ptrsIdx, const unsigned int ptrsIdx,
unsigned int *rb,
const c16_t **ptrs, const c16_t **ptrs,
const c16_t **dmrs, const c16_t **dmrs,
const c16_t **data, const c16_t **data,
c16_t **out) c16_t **out)
{ {
if (right_dc) { // if first RE is DC no need to map in this function
c16_t *out_tmp = *out; if (right_dc == 0)
c16_t tmp_out_buf[NR_NB_SC_PER_RB]; return;
const unsigned int left_dc = NR_NB_SC_PER_RB - right_dc;
/* copy out to temp buffer. incase we want to preserve the REs in the out buffer. */
memcpy(tmp_out_buf, out_tmp, sizeof(c16_t) * left_dc);
out_tmp -= (fft_size - left_dc);
memcpy(tmp_out_buf + left_dc, out_tmp, sizeof(c16_t) * right_dc);
/* map on to temp buffer */
if (dmrs && data) {
map_data_dmrs_ptr(num_cdm_no_data, *data, tmp_out_buf);
*data += data_per_rb;
} else if (dmrs) {
map_dmrs_ptr(delta, *dmrs, tmp_out_buf);
*dmrs += dmrs_per_rb;
} else if (ptrs) {
map_data_ptrs(ptrsIdx, *data, *ptrs, tmp_out_buf);
*data += (NR_NB_SC_PER_RB - 1);
*ptrs += 1;
} else if (data) {
map_data_rb(*data, tmp_out_buf);
*data += NR_NB_SC_PER_RB;
} else {
DevAssert(false);
}
/* copy back to out buffer */ c16_t *out_tmp = *out;
out_tmp = *out; c16_t tmp_out_buf[NR_NB_SC_PER_RB];
memcpy(out_tmp, tmp_out_buf, sizeof(c16_t) * left_dc); const unsigned int left_dc = NR_NB_SC_PER_RB - right_dc;
out_tmp -= (fft_size - left_dc); /* copy out to temp buffer. incase we want to preserve the REs in the out buffer
memcpy(out_tmp, tmp_out_buf + left_dc, sizeof(c16_t) * right_dc); as we call mapping of data in DMRS symbol after mapping DMRS REs
out_tmp += right_dc; */
*out = out_tmp; memcpy(tmp_out_buf, out_tmp, sizeof(c16_t) * left_dc);
*rb += 1; out_tmp -= (fft_size - left_dc);
memcpy(tmp_out_buf + left_dc, out_tmp, sizeof(c16_t) * right_dc);
/* map on to temp buffer */
if (dmrs && data) {
map_data_dmrs_ptr(num_cdm_no_data, *data, tmp_out_buf);
*data += data_per_rb;
} else if (dmrs) {
map_dmrs_ptr(delta, *dmrs, tmp_out_buf);
*dmrs += dmrs_per_rb;
} else if (ptrs) {
map_data_ptrs(ptrsIdx, *data, *ptrs, tmp_out_buf);
*data += (NR_NB_SC_PER_RB - 1);
*ptrs += 1;
} else if (data) {
map_data_rb(*data, tmp_out_buf);
*data += NR_NB_SC_PER_RB;
} else { } else {
*out = (*out) - fft_size; DevAssert(false);
} }
/* copy back to out buffer */
out_tmp = *out;
memcpy(out_tmp, tmp_out_buf, sizeof(c16_t) * left_dc);
out_tmp -= (fft_size - left_dc);
memcpy(out_tmp, tmp_out_buf + left_dc, sizeof(c16_t) * right_dc);
out_tmp += right_dc;
*out = out_tmp;
} }
/* /*
...@@ -266,12 +267,8 @@ typedef struct { ...@@ -266,12 +267,8 @@ typedef struct {
/* /*
Map all REs in one OFDM symbol Map all REs in one OFDM symbol
This function operation is as follows: This function operation is as follows:
> Computes the number of RB (stop_rb) below DC. (necessarily not below DC as the start_rb can be above DC) mapping is done on RB basis. if RB contains DC and if DC is in middle
> Maps REs in the RBs below DC. of the RB, then the mapping is done via map_over_dc().
> We call map_over_dc which
> maps the REs if a RB sits on both sides of DC & increments pointers else,
> it just increments the pointer
> If there are more RBs to map (nb_rb != stop_rb) i.e, RB above DC then those are mapped
*/ */
static void map_current_symbol(const nr_phy_pxsch_params_t p, static void map_current_symbol(const nr_phy_pxsch_params_t p,
const bool dmrs_symbol, const bool dmrs_symbol,
...@@ -283,9 +280,9 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p, ...@@ -283,9 +280,9 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p,
{ {
const unsigned int abs_start_rb = p.bwp_start + p.start_rb; const unsigned int abs_start_rb = p.bwp_start + p.start_rb;
const unsigned int start_sc = (p.first_sc_offset + abs_start_rb * NR_NB_SC_PER_RB) % p.fft_size; const unsigned int start_sc = (p.first_sc_offset + abs_start_rb * NR_NB_SC_PER_RB) % p.fft_size;
const bool cross_dc = start_sc + p.nb_rb * NR_NB_SC_PER_RB > p.fft_size; const unsigned int dc_rb = (p.fft_size - start_sc) / NR_NB_SC_PER_RB;
const unsigned int rb_over_dc = cross_dc ? (p.fft_size - start_sc) % NR_NB_SC_PER_RB : 0; const unsigned int rb_over_dc = (p.fft_size - start_sc) % NR_NB_SC_PER_RB;
const unsigned int stop_rb = cross_dc ? (p.fft_size - start_sc) / NR_NB_SC_PER_RB : p.nb_rb; const unsigned int n_cdm = p.num_cdm_no_data;
const c16_t *data_tmp = *data; const c16_t *data_tmp = *data;
/* If current symbol is DMRS symbol */ /* If current symbol is DMRS symbol */
if (dmrs_symbol) { if (dmrs_symbol) {
...@@ -294,37 +291,18 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p, ...@@ -294,37 +291,18 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p,
const c16_t *p_mod_dmrs = dmrs_seq + abs_start_rb * dmrs_per_rb; const c16_t *p_mod_dmrs = dmrs_seq + abs_start_rb * dmrs_per_rb;
c16_t *out_tmp = out + start_sc; c16_t *out_tmp = out + start_sc;
unsigned int rb = 0; for (unsigned int rb = 0; rb < p.nb_rb; rb++) {
/* map below/above DC */ if (rb == dc_rb) {
for (; rb < stop_rb; rb++) { // map RB at DC
map_dmrs_ptr(p.delta, p_mod_dmrs, out_tmp); if (rb_over_dc) {
p_mod_dmrs += dmrs_per_rb; // if DC is in middle of RB, the following function handles it.
out_tmp += NR_NB_SC_PER_RB; map_over_dc(rb_over_dc, n_cdm, p.fft_size, dmrs_per_rb, data_per_rb, p.delta, 0, NULL, &p_mod_dmrs, NULL, &out_tmp);
} continue;
/* if start_rb is above DC or if stop_rb == nb_rb, } else {
every RB is mapped at this point and the following code does nothing // else just move the pointer and following function will map the rb
*/ out_tmp -= p.fft_size;
}
/* map RB at DC */ }
/* if a RB is on both sides of DC, the following function handles it.
if not, then it just increaments the pointer incase there are more RBs above DC.
*/
map_over_dc(rb_over_dc,
p.num_cdm_no_data,
p.fft_size,
dmrs_per_rb,
data_per_rb,
p.delta,
0,
&rb,
NULL,
&p_mod_dmrs,
NULL,
&out_tmp);
/* map above DC */
/* if there are more RBs, they are mapped in the following part */
for (; rb < p.nb_rb; rb++) {
map_dmrs_ptr(p.delta, p_mod_dmrs, out_tmp); map_dmrs_ptr(p.delta, p_mod_dmrs, out_tmp);
p_mod_dmrs += dmrs_per_rb; p_mod_dmrs += dmrs_per_rb;
out_tmp += NR_NB_SC_PER_RB; out_tmp += NR_NB_SC_PER_RB;
...@@ -333,26 +311,16 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p, ...@@ -333,26 +311,16 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p,
/* if there is data in current DMRS symbol, we map it here. */ /* if there is data in current DMRS symbol, we map it here. */
if (map_data_dmrs_ptr) { if (map_data_dmrs_ptr) {
c16_t *out_tmp = out + start_sc; c16_t *out_tmp = out + start_sc;
unsigned int rb = 0; for (unsigned int rb = 0; rb < p.nb_rb; rb++) {
for (; rb < stop_rb; rb++) { if (rb == dc_rb) {
map_data_dmrs_ptr(p.num_cdm_no_data, data_tmp, out_tmp); if (rb_over_dc) {
data_tmp += data_per_rb; map_over_dc(rb_over_dc, n_cdm, p.fft_size, dmrs_per_rb, data_per_rb, p.delta, 0, NULL, &p_mod_dmrs, &data_tmp, &out_tmp);
out_tmp += NR_NB_SC_PER_RB; continue;
} } else {
map_over_dc(rb_over_dc, out_tmp -= p.fft_size;
p.num_cdm_no_data, }
p.fft_size, }
dmrs_per_rb, map_data_dmrs_ptr(n_cdm, data_tmp, out_tmp);
data_per_rb,
p.delta,
0,
&rb,
NULL,
&p_mod_dmrs,
&data_tmp,
&out_tmp);
for (; rb < p.nb_rb; rb++) {
map_data_dmrs_ptr(p.num_cdm_no_data, data_tmp, out_tmp);
data_tmp += data_per_rb; data_tmp += data_per_rb;
out_tmp += NR_NB_SC_PER_RB; out_tmp += NR_NB_SC_PER_RB;
} }
...@@ -361,58 +329,35 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p, ...@@ -361,58 +329,35 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p,
} else if (ptrs_symbol) { } else if (ptrs_symbol) {
const unsigned int first_ptrs_re = get_first_ptrs_re(p.rnti, p.K_ptrs, p.nb_rb, p.k_RE_ref) + start_sc; const unsigned int first_ptrs_re = get_first_ptrs_re(p.rnti, p.K_ptrs, p.nb_rb, p.k_RE_ref) + start_sc;
const unsigned int ptrs_idx_re = (start_sc - first_ptrs_re) % NR_NB_SC_PER_RB; // PTRS RE index within RB const unsigned int ptrs_idx_re = (start_sc - first_ptrs_re) % NR_NB_SC_PER_RB; // PTRS RE index within RB
unsigned int ptrs_idx_rb = (start_sc - first_ptrs_re) / NR_NB_SC_PER_RB; // number of RBs before the first PTRS RB unsigned int non_ptrs_rb = (start_sc - first_ptrs_re) / NR_NB_SC_PER_RB; // number of RBs before the first PTRS RB
unsigned int rb = 0; int ptrs_idx_rb = -non_ptrs_rb; // RB count to check for PTRS RB
c16_t *out_tmp = out + start_sc; c16_t *out_tmp = out + start_sc;
/* map data to RBs before the first PTRS RB */
for (; rb < ptrs_idx_rb; rb++) {
map_data_rb(data_tmp, out);
data_tmp += NR_NB_SC_PER_RB;
out_tmp += NR_NB_SC_PER_RB;
}
const c16_t *p_mod_ptrs = ptrs_seq; const c16_t *p_mod_ptrs = ptrs_seq;
ptrs_idx_rb = 0; // RB count to check for PTRS RB /* map data to RBs before the first PTRS RB or if current RB has no PTRS */
/* we start to map remaining RB here */ for (unsigned int rb = 0; rb < p.nb_rb; rb++) {
for (; rb < stop_rb; rb++) { if (rb < non_ptrs_rb || ptrs_idx_rb % p.K_ptrs) {
if (ptrs_idx_rb % p.K_ptrs) { // if current RB does not contain PTRS if (rb == dc_rb) {
map_data_rb(data_tmp, out_tmp); if (rb_over_dc) {
data_tmp += NR_NB_SC_PER_RB; map_over_dc(rb_over_dc, n_cdm, p.fft_size, 0, 0, p.delta, 0, NULL, NULL, &data_tmp, &out_tmp);
out_tmp += NR_NB_SC_PER_RB; continue;
} else { // if current RB contains PTRS } else {
map_data_ptrs(ptrs_idx_re, data_tmp, p_mod_ptrs, out_tmp); out_tmp -= p.fft_size;
p_mod_ptrs++; // increament once as only one PTRS RE per RB }
data_tmp += (NR_NB_SC_PER_RB - 1); }
out_tmp += NR_NB_SC_PER_RB;
}
ptrs_idx_rb++;
}
if (ptrs_idx_rb % p.K_ptrs) {
/* if not a PTRS RB set mod_ptrs to NULL in function arg */
map_over_dc(rb_over_dc, p.num_cdm_no_data, p.fft_size, 0, 0, p.delta, 0, &rb, NULL, NULL, &data_tmp, &out_tmp);
} else {
/* if a PTRS RB set valid mod_ptrs pointer */
map_over_dc(rb_over_dc,
p.num_cdm_no_data,
p.fft_size,
0,
0,
p.delta,
ptrs_idx_re,
&rb,
&p_mod_ptrs,
NULL,
&data_tmp,
&out_tmp);
}
/* map remaining RBs above DC */
for (; rb < p.nb_rb; rb++) {
if (ptrs_idx_rb % p.K_ptrs) {
map_data_rb(data_tmp, out_tmp); map_data_rb(data_tmp, out_tmp);
data_tmp += NR_NB_SC_PER_RB; data_tmp += NR_NB_SC_PER_RB;
out_tmp += NR_NB_SC_PER_RB; out_tmp += NR_NB_SC_PER_RB;
} else { } else {
if (rb == dc_rb) {
if (rb_over_dc) {
map_over_dc(rb_over_dc, n_cdm, p.fft_size, 0, 0, p.delta, ptrs_idx_re, &p_mod_ptrs, NULL, &data_tmp, &out_tmp);
continue;
} else {
out_tmp -= p.fft_size;
}
}
map_data_ptrs(ptrs_idx_re, data_tmp, p_mod_ptrs, out_tmp); map_data_ptrs(ptrs_idx_re, data_tmp, p_mod_ptrs, out_tmp);
p_mod_ptrs++; p_mod_ptrs++; // increament once as only one PTRS RE per RB
data_tmp += (NR_NB_SC_PER_RB - 1); data_tmp += (NR_NB_SC_PER_RB - 1);
out_tmp += NR_NB_SC_PER_RB; out_tmp += NR_NB_SC_PER_RB;
} }
...@@ -420,15 +365,16 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p, ...@@ -420,15 +365,16 @@ static void map_current_symbol(const nr_phy_pxsch_params_t p,
} }
} else { } else {
/* only data in this symbol */ /* only data in this symbol */
unsigned int rb = 0;
c16_t *out_tmp = out + start_sc; c16_t *out_tmp = out + start_sc;
for (; rb < stop_rb; rb++) { for (unsigned int rb = 0; rb < p.nb_rb; rb++) {
map_data_rb(data_tmp, out_tmp); if (rb == dc_rb) {
data_tmp += NR_NB_SC_PER_RB; if (rb_over_dc) {
out_tmp += NR_NB_SC_PER_RB; map_over_dc(rb_over_dc, n_cdm, p.fft_size, 0, 0, p.delta, 0, NULL, NULL, &data_tmp, &out_tmp);
} continue;
map_over_dc(rb_over_dc, p.num_cdm_no_data, p.fft_size, 0, 0, p.delta, 0, &rb, NULL, NULL, &data_tmp, &out_tmp); } else {
for (; rb < p.nb_rb; rb++) { out_tmp -= p.fft_size;
}
}
map_data_rb(data_tmp, out_tmp); map_data_rb(data_tmp, out_tmp);
data_tmp += NR_NB_SC_PER_RB; data_tmp += NR_NB_SC_PER_RB;
out_tmp += NR_NB_SC_PER_RB; out_tmp += NR_NB_SC_PER_RB;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment