mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
557 lines
18 KiB
C
557 lines
18 KiB
C
10 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
10 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
10 years ago
|
*
|
||
10 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
10 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
10 years ago
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
10 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
10 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
10 years ago
|
* GNU Affero General Public License for more details.
|
||
10 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
10 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdint.h>
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <strings.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <assert.h>
|
||
|
#include <math.h>
|
||
|
|
||
10 years ago
|
#include "srslte/ch_estimation/refsignal_ul.h"
|
||
10 years ago
|
#include "srslte/phch/pusch.h"
|
||
10 years ago
|
#include "srslte/phch/pusch_cfg.h"
|
||
10 years ago
|
#include "srslte/phch/uci.h"
|
||
|
#include "srslte/common/phy_common.h"
|
||
|
#include "srslte/utils/bit.h"
|
||
|
#include "srslte/utils/debug.h"
|
||
|
#include "srslte/utils/vector.h"
|
||
10 years ago
|
#include "srslte/dft/dft_precoding.h"
|
||
10 years ago
|
|
||
10 years ago
|
#define MAX_PUSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12)
|
||
10 years ago
|
|
||
|
|
||
|
|
||
10 years ago
|
const static srslte_mod_t modulations[4] =
|
||
10 years ago
|
{ SRSLTE_MOD_BPSK, SRSLTE_MOD_QPSK, SRSLTE_MOD_16QAM, SRSLTE_MOD_64QAM };
|
||
10 years ago
|
|
||
10 years ago
|
static int f_hop_sum(srslte_pusch_t *q, uint32_t i) {
|
||
10 years ago
|
uint32_t sum = 0;
|
||
|
for (uint32_t k=i*10+1;k<i*10+9;i++) {
|
||
|
sum += (q->seq_type2_fo.c[k]<<(k-(i*10+1)));
|
||
|
}
|
||
|
return sum;
|
||
|
}
|
||
|
|
||
10 years ago
|
static int f_hop(srslte_pusch_t *q, srslte_pusch_hopping_cfg_t *hopping, int i) {
|
||
10 years ago
|
if (i == -1) {
|
||
|
return 0;
|
||
|
} else {
|
||
|
if (hopping->n_sb == 1) {
|
||
|
return 0;
|
||
|
} else if (hopping->n_sb == 2) {
|
||
|
return (f_hop(q, hopping, i-1) + f_hop_sum(q, i))%2;
|
||
|
} else {
|
||
|
return (f_hop(q, hopping, i-1) + f_hop_sum(q, i)%(hopping->n_sb-1)+1)%hopping->n_sb;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
static int f_m(srslte_pusch_t *q, srslte_pusch_hopping_cfg_t *hopping, uint32_t i, uint32_t current_tx_nb) {
|
||
10 years ago
|
if (hopping->n_sb == 1) {
|
||
10 years ago
|
if (hopping->hop_mode == SRSLTE_PUSCH_HOP_MODE_INTER_SF) {
|
||
10 years ago
|
return current_tx_nb%2;
|
||
10 years ago
|
} else {
|
||
|
return i%2;
|
||
|
}
|
||
|
} else {
|
||
|
return q->seq_type2_fo.c[i*10];
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
/* Computes PUSCH frequency hopping as defined in Section 8.4 of 36.213 */
|
||
10 years ago
|
void compute_freq_hopping(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant,
|
||
|
srslte_pusch_hopping_cfg_t *hopping,
|
||
10 years ago
|
uint32_t sf_idx, uint32_t current_tx_nb)
|
||
10 years ago
|
{
|
||
10 years ago
|
|
||
10 years ago
|
for (uint32_t slot=0;slot<2;slot++) {
|
||
|
|
||
|
INFO("PUSCH Freq hopping: %d\n", grant->freq_hopping);
|
||
10 years ago
|
uint32_t n_prb_tilde = grant->n_prb[slot];
|
||
10 years ago
|
|
||
10 years ago
|
if (grant->freq_hopping == 1) {
|
||
10 years ago
|
if (hopping->hop_mode == SRSLTE_PUSCH_HOP_MODE_INTER_SF) {
|
||
10 years ago
|
n_prb_tilde = grant->n_prb[current_tx_nb%2];
|
||
10 years ago
|
} else {
|
||
10 years ago
|
n_prb_tilde = grant->n_prb[slot];
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
if (grant->freq_hopping == 2) {
|
||
10 years ago
|
/* Freq hopping type 2 as defined in 5.3.4 of 36.211 */
|
||
10 years ago
|
uint32_t n_vrb_tilde = grant->n_prb[0];
|
||
10 years ago
|
if (hopping->n_sb > 1) {
|
||
|
n_vrb_tilde -= (hopping->hopping_offset-1)/2+1;
|
||
|
}
|
||
|
int i=0;
|
||
10 years ago
|
if (hopping->hop_mode == SRSLTE_PUSCH_HOP_MODE_INTER_SF) {
|
||
10 years ago
|
i = sf_idx;
|
||
10 years ago
|
} else {
|
||
10 years ago
|
i = 2*sf_idx+slot;
|
||
10 years ago
|
}
|
||
10 years ago
|
uint32_t n_rb_sb = q->cell.nof_prb;
|
||
10 years ago
|
if (hopping->n_sb > 1) {
|
||
|
n_rb_sb = (n_rb_sb-hopping->hopping_offset-hopping->hopping_offset%2)/hopping->n_sb;
|
||
|
}
|
||
|
n_prb_tilde = (n_vrb_tilde+f_hop(q, hopping, i)*n_rb_sb+
|
||
10 years ago
|
(n_rb_sb-1)-2*(n_vrb_tilde%n_rb_sb)*f_m(q, hopping, i, current_tx_nb))%(n_rb_sb*hopping->n_sb);
|
||
10 years ago
|
|
||
10 years ago
|
INFO("n_prb_tilde: %d, n_vrb_tilde: %d, n_rb_sb: %d, n_sb: %d\n",
|
||
|
n_prb_tilde, n_vrb_tilde, n_rb_sb, hopping->n_sb);
|
||
10 years ago
|
if (hopping->n_sb > 1) {
|
||
|
n_prb_tilde += (hopping->hopping_offset-1)/2+1;
|
||
|
}
|
||
|
|
||
|
}
|
||
10 years ago
|
grant->n_prb_tilde[slot] = n_prb_tilde;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/* Allocate/deallocate PUSCH RBs to the resource grid
|
||
|
*/
|
||
|
int pusch_cp(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant, cf_t *input, cf_t *output, bool advance_input)
|
||
|
{
|
||
|
cf_t *in_ptr = input;
|
||
|
cf_t *out_ptr = output;
|
||
|
|
||
|
uint32_t L_ref = 3;
|
||
|
if (SRSLTE_CP_ISEXT(q->cell.cp)) {
|
||
|
L_ref = 2;
|
||
|
}
|
||
|
for (uint32_t slot=0;slot<2;slot++) {
|
||
10 years ago
|
uint32_t N_srs = 0;
|
||
|
if (q->shortened && slot == 1) {
|
||
|
N_srs = 1;
|
||
|
}
|
||
10 years ago
|
INFO("Allocating PUSCH %d PRB to index %d at slot %d\n",grant->L_prb, grant->n_prb_tilde[slot], slot);
|
||
10 years ago
|
for (uint32_t l=0;l<SRSLTE_CP_NSYMB(q->cell.cp)-N_srs;l++) {
|
||
10 years ago
|
if (l != L_ref) {
|
||
10 years ago
|
uint32_t idx = SRSLTE_RE_IDX(q->cell.nof_prb, l+slot*SRSLTE_CP_NSYMB(q->cell.cp),
|
||
10 years ago
|
grant->n_prb_tilde[slot]*SRSLTE_NRE);
|
||
10 years ago
|
if (advance_input) {
|
||
|
out_ptr = &output[idx];
|
||
|
} else {
|
||
|
in_ptr = &input[idx];
|
||
|
}
|
||
10 years ago
|
memcpy(out_ptr, in_ptr, grant->L_prb * SRSLTE_NRE * sizeof(cf_t));
|
||
10 years ago
|
if (advance_input) {
|
||
10 years ago
|
in_ptr += grant->L_prb*SRSLTE_NRE;
|
||
10 years ago
|
} else {
|
||
10 years ago
|
out_ptr += grant->L_prb*SRSLTE_NRE;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
10 years ago
|
return SRSLTE_NRE*grant->L_prb;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
int pusch_put(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant, cf_t *input, cf_t *output) {
|
||
|
return pusch_cp(q, grant, input, output, true);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
int pusch_get(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant, cf_t *input, cf_t *output) {
|
||
|
return pusch_cp(q, grant, input, output, false);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
|
||
10 years ago
|
/** Initializes the PDCCH transmitter and receiver */
|
||
10 years ago
|
int srslte_pusch_init(srslte_pusch_t *q, srslte_cell_t cell) {
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
int i;
|
||
|
|
||
|
if (q != NULL &&
|
||
10 years ago
|
srslte_cell_isvalid(&cell))
|
||
10 years ago
|
{
|
||
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_pusch_t));
|
||
10 years ago
|
ret = SRSLTE_ERROR;
|
||
10 years ago
|
|
||
|
q->cell = cell;
|
||
10 years ago
|
q->max_re = q->cell.nof_prb * MAX_PUSCH_RE(q->cell.cp);
|
||
10 years ago
|
|
||
|
INFO("Init PUSCH: %d ports %d PRBs, max_symbols: %d\n", q->cell.nof_ports,
|
||
10 years ago
|
q->cell.nof_prb, q->max_re);
|
||
10 years ago
|
|
||
|
for (i = 0; i < 4; i++) {
|
||
9 years ago
|
if (srslte_modem_table_lte(&q->mod[i], modulations[i])) {
|
||
10 years ago
|
goto clean;
|
||
|
}
|
||
9 years ago
|
srslte_modem_table_bytes(&q->mod[i]);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
/* Precompute sequence for type2 frequency hopping */
|
||
10 years ago
|
if (srslte_sequence_LTE_pr(&q->seq_type2_fo, 210, q->cell.id)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating type2 frequency hopping sequence\n");
|
||
|
goto clean;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
srslte_sch_init(&q->dl_sch);
|
||
10 years ago
|
|
||
10 years ago
|
if (srslte_dft_precoding_init(&q->dft_precoding, cell.nof_prb)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating DFT transform precoding\n");
|
||
|
goto clean;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
q->rnti_is_set = false;
|
||
|
|
||
10 years ago
|
// Allocate floats for reception (LLRs). Buffer casted to uint8_t for transmission
|
||
10 years ago
|
q->q = srslte_vec_malloc(sizeof(float) * q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM));
|
||
|
if (!q->q) {
|
||
10 years ago
|
goto clean;
|
||
|
}
|
||
|
|
||
|
// Allocate floats for reception (LLRs). Buffer casted to uint8_t for transmission
|
||
10 years ago
|
q->g = srslte_vec_malloc(sizeof(float) * q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM));
|
||
|
if (!q->g) {
|
||
10 years ago
|
goto clean;
|
||
|
}
|
||
10 years ago
|
q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
||
|
if (!q->d) {
|
||
9 years ago
|
goto clean;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
q->ce = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
||
10 years ago
|
if (!q->ce) {
|
||
|
goto clean;
|
||
|
}
|
||
10 years ago
|
q->z = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
||
|
if (!q->z) {
|
||
10 years ago
|
goto clean;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
|
clean:
|
||
10 years ago
|
if (ret == SRSLTE_ERROR) {
|
||
10 years ago
|
srslte_pusch_free(q);
|
||
10 years ago
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
10 years ago
|
void srslte_pusch_free(srslte_pusch_t *q) {
|
||
10 years ago
|
int i;
|
||
|
|
||
10 years ago
|
if (q->q) {
|
||
|
free(q->q);
|
||
10 years ago
|
}
|
||
10 years ago
|
if (q->d) {
|
||
|
free(q->d);
|
||
10 years ago
|
}
|
||
10 years ago
|
if (q->g) {
|
||
|
free(q->g);
|
||
10 years ago
|
}
|
||
10 years ago
|
if (q->ce) {
|
||
|
free(q->ce);
|
||
10 years ago
|
}
|
||
10 years ago
|
if (q->z) {
|
||
|
free(q->z);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
srslte_dft_precoding_free(&q->dft_precoding);
|
||
10 years ago
|
|
||
10 years ago
|
for (i = 0; i < SRSLTE_NSUBFRAMES_X_FRAME; i++) {
|
||
10 years ago
|
srslte_sequence_free(&q->seq[i]);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
srslte_sequence_free(&q->seq_type2_fo);
|
||
|
|
||
10 years ago
|
for (i = 0; i < 4; i++) {
|
||
10 years ago
|
srslte_modem_table_free(&q->mod[i]);
|
||
10 years ago
|
}
|
||
10 years ago
|
srslte_sch_free(&q->dl_sch);
|
||
10 years ago
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_pusch_t));
|
||
10 years ago
|
|
||
|
}
|
||
|
|
||
10 years ago
|
/* Configures the structure srslte_pusch_cfg_t from the UL DCI allocation dci_msg.
|
||
|
* If dci_msg is NULL, the grant is assumed to be already stored in cfg->grant
|
||
|
*/
|
||
10 years ago
|
int srslte_pusch_cfg(srslte_pusch_t *q,
|
||
|
srslte_pusch_cfg_t *cfg,
|
||
|
srslte_ra_ul_grant_t *grant,
|
||
|
srslte_uci_cfg_t *uci_cfg,
|
||
|
srslte_pusch_hopping_cfg_t *hopping_cfg,
|
||
|
srslte_refsignal_srs_cfg_t *srs_cfg,
|
||
|
uint32_t tti,
|
||
|
uint32_t rv_idx,
|
||
|
uint32_t current_tx_nb)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (q && cfg && grant) {
|
||
|
memcpy(&cfg->grant, grant, sizeof(srslte_ra_ul_grant_t));
|
||
|
|
||
|
if (srslte_cbsegm(&cfg->cb_segm, cfg->grant.mcs.tbs)) {
|
||
|
fprintf(stderr, "Error computing Codeblock segmentation for TBS=%d\n", cfg->grant.mcs.tbs);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
|
}
|
||
10 years ago
|
|
||
|
/* Compute PUSCH frequency hopping */
|
||
|
if (hopping_cfg) {
|
||
|
compute_freq_hopping(q, &cfg->grant, hopping_cfg, tti%10, current_tx_nb);
|
||
|
} else {
|
||
|
cfg->grant.n_prb_tilde[0] = cfg->grant.n_prb[0];
|
||
|
cfg->grant.n_prb_tilde[1] = cfg->grant.n_prb[1];
|
||
|
}
|
||
|
if (srs_cfg) {
|
||
|
q->shortened = false;
|
||
|
if (srs_cfg->configured) {
|
||
|
// If UE-specific SRS is configured, PUSCH is shortened every time UE transmits SRS even if overlaping in the same RB or not
|
||
|
if (srslte_refsignal_srs_send_cs(srs_cfg->subframe_config, tti%10) == 1 &&
|
||
|
srslte_refsignal_srs_send_ue(srs_cfg->I_srs, tti) == 1)
|
||
|
{
|
||
|
q->shortened = true;
|
||
|
/* If RBs are contiguous, PUSCH is not shortened */
|
||
10 years ago
|
uint32_t k0_srs = srslte_refsignal_srs_rb_start_cs(srs_cfg->bw_cfg, q->cell.nof_prb);
|
||
|
uint32_t nrb_srs = srslte_refsignal_srs_rb_L_cs(srs_cfg->bw_cfg, q->cell.nof_prb);
|
||
10 years ago
|
for (uint32_t ns=0;ns<2 && q->shortened;ns++) {
|
||
9 years ago
|
if (cfg->grant.n_prb_tilde[ns] == k0_srs + nrb_srs || // If PUSCH is contiguous on the right-hand side of SRS
|
||
|
cfg->grant.n_prb_tilde[ns] + cfg->grant.L_prb == k0_srs) // If SRS is contiguous on the left-hand side of PUSCH
|
||
10 years ago
|
{
|
||
|
q->shortened = false;
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
// If not coincides with UE transmission. PUSCH shall be shortened if cell-specific SRS transmission RB
|
||
|
//coincides with PUSCH allocated RB
|
||
|
if (!q->shortened) {
|
||
|
if (srslte_refsignal_srs_send_cs(srs_cfg->subframe_config, tti%10) == 1) {
|
||
|
uint32_t k0_srs = srslte_refsignal_srs_rb_start_cs(srs_cfg->bw_cfg, q->cell.nof_prb);
|
||
|
uint32_t nrb_srs = srslte_refsignal_srs_rb_L_cs(srs_cfg->bw_cfg, q->cell.nof_prb);
|
||
|
for (uint32_t ns=0;ns<2 && !q->shortened;ns++) {
|
||
|
if ((cfg->grant.n_prb_tilde[ns] >= k0_srs && cfg->grant.n_prb_tilde[ns] < k0_srs + nrb_srs) ||
|
||
|
(cfg->grant.n_prb_tilde[ns] + cfg->grant.L_prb >= k0_srs &&
|
||
|
cfg->grant.n_prb_tilde[ns] + cfg->grant.L_prb < k0_srs + nrb_srs) ||
|
||
|
(cfg->grant.n_prb_tilde[ns] <= k0_srs && cfg->grant.n_prb_tilde[ns] + cfg->grant.L_prb >= k0_srs + nrb_srs))
|
||
|
{
|
||
|
q->shortened = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|
||
10 years ago
|
|
||
|
/* Compute final number of bits and RE */
|
||
|
srslte_ra_ul_grant_to_nbits(&cfg->grant, q->cell.cp, q->shortened?1:0, &cfg->nbits);
|
||
10 years ago
|
|
||
10 years ago
|
cfg->sf_idx = tti%10;
|
||
|
cfg->tti = tti;
|
||
|
cfg->rv = rv_idx;
|
||
|
cfg->cp = q->cell.cp;
|
||
|
|
||
|
// Save UCI configuration
|
||
10 years ago
|
if (uci_cfg) {
|
||
|
memcpy(&cfg->uci_cfg, uci_cfg, sizeof(srslte_uci_cfg_t));
|
||
|
}
|
||
10 years ago
|
|
||
|
return SRSLTE_SUCCESS;
|
||
|
} else {
|
||
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
/* Precalculate the PUSCH scramble sequences for a given RNTI. This function takes a while
|
||
|
* to execute, so shall be called once the final C-RNTI has been allocated for the session.
|
||
10 years ago
|
* For the connection procedure, use srslte_pusch_encode_rnti() or srslte_pusch_decode_rnti() functions */
|
||
|
int srslte_pusch_set_rnti(srslte_pusch_t *q, uint16_t rnti) {
|
||
10 years ago
|
uint32_t i;
|
||
|
|
||
10 years ago
|
for (i = 0; i < SRSLTE_NSUBFRAMES_X_FRAME; i++) {
|
||
10 years ago
|
if (srslte_sequence_pusch(&q->seq[i], rnti, 2 * i, q->cell.id,
|
||
|
q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM))) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
q->rnti_is_set = true;
|
||
|
q->rnti = rnti;
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
|
|
||
|
/** Decodes the PUSCH from the received symbols
|
||
|
*/
|
||
10 years ago
|
int srslte_pusch_decode(srslte_pusch_t *q,
|
||
|
srslte_pusch_cfg_t *cfg, srslte_softbuffer_rx_t *softbuffer,
|
||
|
cf_t *sf_symbols,
|
||
|
cf_t *ce, float noise_estimate,
|
||
|
uint8_t *data)
|
||
10 years ago
|
{
|
||
|
|
||
10 years ago
|
uint32_t n;
|
||
10 years ago
|
|
||
10 years ago
|
if (q != NULL &&
|
||
|
sf_symbols != NULL &&
|
||
|
data != NULL &&
|
||
|
cfg != NULL)
|
||
10 years ago
|
{
|
||
|
|
||
|
if (q->rnti_is_set) {
|
||
10 years ago
|
INFO("Decoding PUSCH SF: %d, Mod %s, NofBits: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
|
||
10 years ago
|
cfg->sf_idx, srslte_mod_string(cfg->grant.mcs.mod), cfg->grant.mcs.tbs,
|
||
10 years ago
|
cfg->nbits.nof_re, cfg->nbits.nof_symb, cfg->nbits.nof_bits, cfg->rv);
|
||
10 years ago
|
|
||
|
/* extract symbols */
|
||
10 years ago
|
n = pusch_get(q, &cfg->grant, sf_symbols, q->d);
|
||
10 years ago
|
if (n != cfg->nbits.nof_re) {
|
||
|
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
|
||
|
/* extract channel estimates */
|
||
10 years ago
|
n = pusch_get(q, &cfg->grant, ce, q->ce);
|
||
10 years ago
|
if (n != cfg->nbits.nof_re) {
|
||
|
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
srslte_predecoding_single(q->d, q->ce, q->z, cfg->nbits.nof_re, noise_estimate);
|
||
10 years ago
|
|
||
10 years ago
|
srslte_dft_predecoding(&q->dft_precoding, q->z, q->d, cfg->grant.L_prb, cfg->nbits.nof_symb);
|
||
10 years ago
|
|
||
10 years ago
|
/* demodulate symbols
|
||
|
* The MAX-log-MAP algorithm used in turbo decoding is unsensitive to SNR estimation,
|
||
|
* thus we don't need tot set it in the LLRs normalization
|
||
|
*/
|
||
9 years ago
|
srslte_demod_soft_demodulate(cfg->grant.mcs.mod, q->d, q->q, cfg->nbits.nof_re);
|
||
10 years ago
|
|
||
|
/* descramble */
|
||
10 years ago
|
srslte_scrambling_f_offset(&q->seq[cfg->sf_idx], q->q, 0, cfg->nbits.nof_bits);
|
||
10 years ago
|
|
||
10 years ago
|
return srslte_ulsch_decode(&q->dl_sch, cfg, softbuffer, q->q, data);
|
||
10 years ago
|
} else {
|
||
10 years ago
|
fprintf(stderr, "Must call srslte_pusch_set_rnti() before calling srslte_pusch_decode()\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
} else {
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
int srslte_pusch_encode_rnti(srslte_pusch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
|
||
|
uint8_t *data, uint16_t rnti,
|
||
|
cf_t *sf_symbols)
|
||
10 years ago
|
{
|
||
10 years ago
|
srslte_uci_data_t uci_data;
|
||
|
bzero(&uci_data, sizeof(srslte_uci_data_t));
|
||
10 years ago
|
return srslte_pusch_uci_encode_rnti(q, cfg, softbuffer, data, uci_data, rnti, sf_symbols);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_pusch_encode(srslte_pusch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
|
||
|
uint8_t *data, cf_t *sf_symbols)
|
||
10 years ago
|
{
|
||
|
if (q->rnti_is_set) {
|
||
10 years ago
|
srslte_uci_data_t uci_data;
|
||
|
bzero(&uci_data, sizeof(srslte_uci_data_t));
|
||
10 years ago
|
return srslte_pusch_uci_encode_rnti(q, cfg, softbuffer, data, uci_data, q->rnti, sf_symbols);
|
||
10 years ago
|
} else {
|
||
10 years ago
|
fprintf(stderr, "Must call srslte_pusch_set_rnti() to set the encoder/decoder RNTI\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
int srslte_pusch_uci_encode(srslte_pusch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
|
||
|
uint8_t *data, srslte_uci_data_t uci_data,
|
||
|
cf_t *sf_symbols)
|
||
10 years ago
|
{
|
||
|
if (q->rnti_is_set) {
|
||
10 years ago
|
return srslte_pusch_uci_encode_rnti(q, cfg, softbuffer, data, uci_data, q->rnti, sf_symbols);
|
||
10 years ago
|
} else {
|
||
10 years ago
|
fprintf(stderr, "Must call srslte_pusch_set_rnti() to set the encoder/decoder RNTI\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
/** Converts the PUSCH data bits to symbols mapped to the slot ready for transmission
|
||
|
*/
|
||
10 years ago
|
int srslte_pusch_uci_encode_rnti(srslte_pusch_t *q, srslte_pusch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
|
||
|
uint8_t *data, srslte_uci_data_t uci_data, uint16_t rnti,
|
||
|
cf_t *sf_symbols)
|
||
10 years ago
|
{
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
|
||
10 years ago
|
if (q != NULL &&
|
||
10 years ago
|
cfg != NULL)
|
||
10 years ago
|
{
|
||
|
|
||
10 years ago
|
if (cfg->nbits.nof_re > q->max_re) {
|
||
10 years ago
|
fprintf(stderr, "Error too many RE per subframe (%d). PUSCH configured for %d RE (%d PRB)\n",
|
||
10 years ago
|
cfg->nbits.nof_re, q->max_re, q->cell.nof_prb);
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
INFO("Encoding PUSCH SF: %d, Mod %s, RNTI: %d, TBS: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
|
||
10 years ago
|
cfg->sf_idx, srslte_mod_string(cfg->grant.mcs.mod), rnti,
|
||
10 years ago
|
cfg->grant.mcs.tbs, cfg->nbits.nof_re, cfg->nbits.nof_symb, cfg->nbits.nof_bits, cfg->rv);
|
||
10 years ago
|
|
||
10 years ago
|
bzero(q->q, cfg->nbits.nof_bits);
|
||
10 years ago
|
if (srslte_ulsch_uci_encode(&q->dl_sch, cfg, softbuffer, data, uci_data, q->g, q->q)) {
|
||
10 years ago
|
fprintf(stderr, "Error encoding TB\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
if (rnti != q->rnti || !q->rnti_is_set) {
|
||
10 years ago
|
srslte_sequence_t seq;
|
||
10 years ago
|
if (srslte_sequence_pusch(&seq, rnti, 2 * cfg->sf_idx, q->cell.id, cfg->nbits.nof_bits)) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
9 years ago
|
srslte_scrambling_bytes(&seq, (uint8_t*) q->q, cfg->nbits.nof_bits);
|
||
10 years ago
|
srslte_sequence_free(&seq);
|
||
10 years ago
|
} else {
|
||
9 years ago
|
srslte_scrambling_bytes(&q->seq[cfg->sf_idx], (uint8_t*) q->q, cfg->nbits.nof_bits);
|
||
9 years ago
|
}
|
||
|
|
||
|
// Correct UCI placeholder bits
|
||
|
uint8_t *d = q->q;
|
||
9 years ago
|
for (int i = 0; i < q->dl_sch.nof_ri_ack_bits; i++) {
|
||
|
if (q->dl_sch.ack_ri_bits[i].type == UCI_BIT_PLACEHOLDER) {
|
||
9 years ago
|
d[q->dl_sch.ack_ri_bits[i].position/8] |= (1<<(7-q->dl_sch.ack_ri_bits[i].position%8));
|
||
9 years ago
|
} else if (q->dl_sch.ack_ri_bits[i].type == UCI_BIT_REPETITION) {
|
||
|
if (q->dl_sch.ack_ri_bits[i].position > 1) {
|
||
|
uint32_t p=q->dl_sch.ack_ri_bits[i].position;
|
||
9 years ago
|
uint8_t bit = d[(p-1)/8] & (1<<(7-(p-1)%8));
|
||
9 years ago
|
if (bit) {
|
||
9 years ago
|
d[p/8] |= 1<<(7-p%8);
|
||
9 years ago
|
} else {
|
||
9 years ago
|
d[p/8] &= ~(1<<(7-p%8));
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
srslte_mod_modulate_bytes(&q->mod[cfg->grant.mcs.mod], (uint8_t*) q->q, q->d, cfg->nbits.nof_bits);
|
||
10 years ago
|
srslte_dft_precoding(&q->dft_precoding, q->d, q->z, cfg->grant.L_prb, cfg->nbits.nof_symb);
|
||
10 years ago
|
|
||
|
/* mapping to resource elements */
|
||
10 years ago
|
pusch_put(q, &cfg->grant, q->z, sf_symbols);
|
||
10 years ago
|
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
|
return ret;
|
||
|
}
|
||
9 years ago
|
|