srsLTE/lib/src/phy/phch/pusch.c

573 lines
18 KiB
C
Raw Normal View History

/**
*
* \section COPYRIGHT
*
2015-11-13 04:22:33 -08:00
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsLTE library.
*
* srsLTE is free software: you can redistribute it and/or modify
2015-05-08 08:05:40 -07:00
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2015-05-08 08:05:40 -07:00
* GNU Affero General Public License for more details.
*
2015-05-08 08:05:40 -07:00
* A copy of the GNU Affero General Public License can be found in
* 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>
2017-05-18 00:48:24 -07:00
#include "srslte/phy/ch_estimation/refsignal_ul.h"
#include "srslte/phy/phch/pusch.h"
#include "srslte/phy/phch/pusch_cfg.h"
#include "srslte/phy/phch/uci.h"
#include "srslte/phy/common/phy_common.h"
#include "srslte/phy/utils/bit.h"
#include "srslte/phy/utils/debug.h"
#include "srslte/phy/utils/vector.h"
#include "srslte/phy/dft/dft_precoding.h"
2015-03-18 05:59:29 -07:00
#define MAX_PUSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12)
2015-03-18 05:59:29 -07:00
const static srslte_mod_t modulations[4] =
2015-03-18 11:14:24 -07:00
{ SRSLTE_MOD_BPSK, SRSLTE_MOD_QPSK, SRSLTE_MOD_16QAM, SRSLTE_MOD_64QAM };
2015-03-18 11:14:24 -07:00
static int f_hop_sum(srslte_pusch_t *q, uint32_t i) {
2015-02-15 23:55:17 -08:00
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;
}
2015-03-18 11:14:24 -07:00
static int f_hop(srslte_pusch_t *q, srslte_pusch_hopping_cfg_t *hopping, int i) {
2015-02-15 23:55:17 -08:00
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;
}
}
}
2015-07-19 13:52:56 -07:00
static int f_m(srslte_pusch_t *q, srslte_pusch_hopping_cfg_t *hopping, uint32_t i, uint32_t current_tx_nb) {
2015-02-15 23:55:17 -08:00
if (hopping->n_sb == 1) {
2015-03-18 11:14:24 -07:00
if (hopping->hop_mode == SRSLTE_PUSCH_HOP_MODE_INTER_SF) {
2015-07-19 13:52:56 -07:00
return current_tx_nb%2;
2015-02-15 23:55:17 -08:00
} else {
return i%2;
}
} else {
return q->seq_type2_fo.c[i*10];
}
}
2015-06-12 08:49:11 -07:00
/* Computes PUSCH frequency hopping as defined in Section 8.4 of 36.213 */
2015-06-14 13:11:49 -07:00
void compute_freq_hopping(srslte_pusch_t *q, srslte_ra_ul_grant_t *grant,
srslte_pusch_hopping_cfg_t *hopping,
2015-07-19 13:52:56 -07:00
uint32_t sf_idx, uint32_t current_tx_nb)
{
2015-06-12 08:49:11 -07:00
for (uint32_t slot=0;slot<2;slot++) {
INFO("PUSCH Freq hopping: %d\n", grant->freq_hopping);
uint32_t n_prb_tilde = grant->n_prb[slot];
2015-06-12 08:49:11 -07:00
if (grant->freq_hopping == 1) {
2015-03-18 11:14:24 -07:00
if (hopping->hop_mode == SRSLTE_PUSCH_HOP_MODE_INTER_SF) {
2015-07-19 13:52:56 -07:00
n_prb_tilde = grant->n_prb[current_tx_nb%2];
2015-02-15 23:55:17 -08:00
} else {
n_prb_tilde = grant->n_prb[slot];
2015-02-15 23:55:17 -08:00
}
}
if (grant->freq_hopping == 2) {
2015-02-15 23:55:17 -08:00
/* Freq hopping type 2 as defined in 5.3.4 of 36.211 */
uint32_t n_vrb_tilde = grant->n_prb[0];
2015-02-15 23:55:17 -08:00
if (hopping->n_sb > 1) {
n_vrb_tilde -= (hopping->hopping_offset-1)/2+1;
}
int i=0;
2015-03-18 11:14:24 -07:00
if (hopping->hop_mode == SRSLTE_PUSCH_HOP_MODE_INTER_SF) {
i = sf_idx;
2015-02-15 23:55:17 -08:00
} else {
i = 2*sf_idx+slot;
2015-02-15 23:55:17 -08:00
}
2015-06-14 13:11:49 -07:00
uint32_t n_rb_sb = q->cell.nof_prb;
2015-02-15 23:55:17 -08:00
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+
2015-07-19 13:52:56 -07:00
(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);
2015-02-15 23:55:17 -08:00
2015-03-11 09:42:36 -07:00
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);
2015-02-15 23:55:17 -08:00
if (hopping->n_sb > 1) {
n_prb_tilde += (hopping->hopping_offset-1)/2+1;
}
}
grant->n_prb_tilde[slot] = n_prb_tilde;
2015-06-12 08:49:11 -07:00
}
}
/* 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++) {
2015-06-14 13:11:49 -07:00
uint32_t N_srs = 0;
if (q->shortened && slot == 1) {
N_srs = 1;
}
2016-04-21 10:06:48 -07:00
INFO("%s PUSCH %d PRB to index %d at slot %d\n",advance_input?"Allocating":"Getting",grant->L_prb, grant->n_prb_tilde[slot], slot);
2015-06-14 13:11:49 -07:00
for (uint32_t l=0;l<SRSLTE_CP_NSYMB(q->cell.cp)-N_srs;l++) {
if (l != L_ref) {
2015-03-18 05:59:29 -07:00
uint32_t idx = SRSLTE_RE_IDX(q->cell.nof_prb, l+slot*SRSLTE_CP_NSYMB(q->cell.cp),
2015-06-12 08:49:11 -07:00
grant->n_prb_tilde[slot]*SRSLTE_NRE);
2015-02-15 23:55:17 -08:00
if (advance_input) {
out_ptr = &output[idx];
} else {
in_ptr = &input[idx];
}
memcpy(out_ptr, in_ptr, grant->L_prb * SRSLTE_NRE * sizeof(cf_t));
2015-02-15 23:55:17 -08:00
if (advance_input) {
in_ptr += grant->L_prb*SRSLTE_NRE;
2015-02-15 23:55:17 -08:00
} else {
out_ptr += grant->L_prb*SRSLTE_NRE;
}
}
}
}
2016-04-21 10:06:48 -07:00
if (advance_input) {
return in_ptr - input;
} else {
return out_ptr - output;
}
}
2015-06-14 13:11:49 -07:00
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);
}
2015-06-14 13:11:49 -07:00
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);
}
/** Initializes the PDCCH transmitter and receiver */
2015-03-18 11:14:24 -07:00
int srslte_pusch_init(srslte_pusch_t *q, srslte_cell_t cell) {
int ret = SRSLTE_ERROR_INVALID_INPUTS;
int i;
if (q != NULL &&
2015-03-18 05:59:29 -07:00
srslte_cell_isvalid(&cell))
{
2015-03-18 11:14:24 -07:00
bzero(q, sizeof(srslte_pusch_t));
ret = SRSLTE_ERROR;
q->cell = cell;
q->max_re = q->cell.nof_prb * MAX_PUSCH_RE(q->cell.cp);
INFO("Init PUSCH: %d ports %d PRBs, max_symbols: %d\n", q->cell.nof_ports,
q->cell.nof_prb, q->max_re);
for (i = 0; i < 4; i++) {
if (srslte_modem_table_lte(&q->mod[i], modulations[i])) {
goto clean;
}
2015-09-18 13:47:37 -07:00
srslte_modem_table_bytes(&q->mod[i]);
}
2015-02-15 23:55:17 -08:00
q->users = calloc(sizeof(srslte_pusch_user_t*), 1+SRSLTE_SIRNTI);
if (!q->users) {
perror("malloc");
goto clean;
}
2015-02-15 23:55:17 -08:00
/* Precompute sequence for type2 frequency hopping */
2015-03-18 08:05:38 -07:00
if (srslte_sequence_LTE_pr(&q->seq_type2_fo, 210, q->cell.id)) {
2015-02-15 23:55:17 -08:00
fprintf(stderr, "Error initiating type2 frequency hopping sequence\n");
goto clean;
}
2016-05-09 03:38:39 -07:00
srslte_sch_init(&q->ul_sch);
2015-03-18 11:14:24 -07:00
if (srslte_dft_precoding_init(&q->dft_precoding, cell.nof_prb)) {
fprintf(stderr, "Error initiating DFT transform precoding\n");
goto clean;
}
// Allocate int16 for reception (LLRs). Buffer casted to uint8_t for transmission
q->q = srslte_vec_malloc(sizeof(int16_t) * q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM));
2015-03-18 11:14:24 -07:00
if (!q->q) {
2015-02-11 23:57:37 -08:00
goto clean;
}
// Allocate int16 for reception (LLRs). Buffer casted to uint8_t for transmission
q->g = srslte_vec_malloc(sizeof(int16_t) * q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM));
2015-03-18 11:14:24 -07:00
if (!q->g) {
goto clean;
}
2015-03-18 11:14:24 -07:00
q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
if (!q->d) {
goto clean;
}
2015-03-18 11:14:24 -07:00
q->ce = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
if (!q->ce) {
goto clean;
}
2015-03-18 11:14:24 -07:00
q->z = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
if (!q->z) {
goto clean;
}
ret = SRSLTE_SUCCESS;
}
clean:
if (ret == SRSLTE_ERROR) {
2015-03-18 11:14:24 -07:00
srslte_pusch_free(q);
}
return ret;
}
2015-03-18 11:14:24 -07:00
void srslte_pusch_free(srslte_pusch_t *q) {
int i;
2015-03-18 11:14:24 -07:00
if (q->q) {
free(q->q);
}
2015-03-18 11:14:24 -07:00
if (q->d) {
free(q->d);
}
2015-03-18 11:14:24 -07:00
if (q->g) {
free(q->g);
2015-02-12 01:38:53 -08:00
}
if (q->ce) {
free(q->ce);
}
2015-03-18 11:14:24 -07:00
if (q->z) {
free(q->z);
}
2015-03-18 11:14:24 -07:00
srslte_dft_precoding_free(&q->dft_precoding);
if (q->users) {
for (int rnti=0;rnti<SRSLTE_SIRNTI;rnti++) {
srslte_pusch_clear_rnti(q, rnti);
}
free(q->users);
}
2015-06-14 13:11:49 -07:00
srslte_sequence_free(&q->seq_type2_fo);
for (i = 0; i < 4; i++) {
2015-03-18 11:14:24 -07:00
srslte_modem_table_free(&q->mod[i]);
}
2016-05-09 03:38:39 -07:00
srslte_sch_free(&q->ul_sch);
2015-03-18 11:14:24 -07:00
bzero(q, sizeof(srslte_pusch_t));
}
/* 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
*/
2015-07-19 13:52:56 -07:00
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)
{
2015-07-19 13:52:56 -07:00
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);
return SRSLTE_ERROR;
}
2015-07-19 13:52:56 -07:00
/* 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 */
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);
2015-07-19 13:52:56 -07:00
for (uint32_t ns=0;ns<2 && q->shortened;ns++) {
2015-11-06 03:32:27 -08:00
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
2015-07-19 13:52:56 -07:00
{
q->shortened = false;
}
2015-06-14 13:11:49 -07:00
}
}
2015-07-19 13:52:56 -07:00
// 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;
}
}
}
}
}
2015-11-06 03:32:27 -08:00
}
2015-07-19 13:52:56 -07:00
/* Compute final number of bits and RE */
srslte_ra_ul_grant_to_nbits(&cfg->grant, q->cell.cp, q->shortened?1:0, &cfg->nbits);
2015-06-12 08:49:11 -07:00
2015-07-19 13:52:56 -07:00
cfg->sf_idx = tti%10;
cfg->tti = tti;
cfg->rv = rv_idx;
cfg->cp = q->cell.cp;
// Save UCI configuration
2015-08-04 08:27:14 -07:00
if (uci_cfg) {
memcpy(&cfg->uci_cfg, uci_cfg, sizeof(srslte_uci_cfg_t));
}
2015-07-19 13:52:56 -07:00
return SRSLTE_SUCCESS;
} else {
return SRSLTE_ERROR_INVALID_INPUTS;
}
}
2015-03-02 02:11:44 -08:00
/* 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.
* For the connection procedure, use srslte_pusch_encode() functions */
2015-03-18 11:14:24 -07:00
int srslte_pusch_set_rnti(srslte_pusch_t *q, uint16_t rnti) {
uint32_t i;
2016-05-09 03:38:39 -07:00
if (!q->users[rnti]) {
q->users[rnti] = malloc(sizeof(srslte_pusch_user_t));
if (q->users[rnti]) {
for (i = 0; i < SRSLTE_NSUBFRAMES_X_FRAME; i++) {
if (srslte_sequence_pusch(&q->users[rnti]->seq[i], rnti, 2 * i, q->cell.id,
q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM))) {
return SRSLTE_ERROR;
}
}
q->users[rnti]->sequences_generated = true;
2016-05-09 03:38:39 -07:00
}
2015-03-02 02:11:44 -08:00
}
return SRSLTE_SUCCESS;
2015-03-02 02:11:44 -08:00
}
void srslte_pusch_clear_rnti(srslte_pusch_t *q, uint16_t rnti) {
if (q->users[rnti]) {
for (int i = 0; i < SRSLTE_NSUBFRAMES_X_FRAME; i++) {
srslte_sequence_free(&q->users[rnti]->seq[i]);
}
free(q->users[rnti]);
q->users[rnti] = NULL;
2015-03-02 02:11:44 -08:00
}
}
/** Converts the PUSCH data bits to symbols mapped to the slot ready for transmission
*/
int srslte_pusch_encode(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)
{
int ret = SRSLTE_ERROR_INVALID_INPUTS;
if (q != NULL &&
cfg != NULL)
{
if (cfg->nbits.nof_re > q->max_re) {
2015-03-02 02:11:44 -08:00
fprintf(stderr, "Error too many RE per subframe (%d). PUSCH configured for %d RE (%d PRB)\n",
cfg->nbits.nof_re, q->max_re, q->cell.nof_prb);
return SRSLTE_ERROR_INVALID_INPUTS;
2015-03-02 02:11:44 -08:00
}
INFO("Encoding PUSCH SF: %d, Mod %s, RNTI: %d, TBS: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
cfg->sf_idx, srslte_mod_string(cfg->grant.mcs.mod), rnti,
cfg->grant.mcs.tbs, cfg->nbits.nof_re, cfg->nbits.nof_symb, cfg->nbits.nof_bits, cfg->rv);
2015-03-02 02:11:44 -08:00
bzero(q->q, cfg->nbits.nof_bits);
2016-05-09 03:38:39 -07:00
if (srslte_ulsch_uci_encode(&q->ul_sch, cfg, softbuffer, data, uci_data, q->g, q->q)) {
2015-03-02 02:11:44 -08:00
fprintf(stderr, "Error encoding TB\n");
return SRSLTE_ERROR;
2015-03-02 02:11:44 -08:00
}
if (q->users[rnti] && q->users[rnti]->sequences_generated) {
srslte_scrambling_bytes(&q->users[rnti]->seq[cfg->sf_idx], (uint8_t*) q->q, cfg->nbits.nof_bits);
} else {
srslte_sequence_t seq;
if (srslte_sequence_pusch(&seq, rnti, 2 * cfg->sf_idx, q->cell.id, cfg->nbits.nof_bits)) {
return SRSLTE_ERROR;
}
srslte_scrambling_bytes(&seq, (uint8_t*) q->q, cfg->nbits.nof_bits);
2015-03-18 08:05:38 -07:00
srslte_sequence_free(&seq);
}
// Correct UCI placeholder/repetition bits
uint8_t *d = q->q;
2016-05-09 03:38:39 -07:00
for (int i = 0; i < q->ul_sch.nof_ri_ack_bits; i++) {
if (q->ul_sch.ack_ri_bits[i].type == UCI_BIT_PLACEHOLDER) {
d[q->ul_sch.ack_ri_bits[i].position/8] |= (1<<(7-q->ul_sch.ack_ri_bits[i].position%8));
} else if (q->ul_sch.ack_ri_bits[i].type == UCI_BIT_REPETITION) {
if (q->ul_sch.ack_ri_bits[i].position > 1) {
uint32_t p=q->ul_sch.ack_ri_bits[i].position;
2015-09-18 13:47:37 -07:00
uint8_t bit = d[(p-1)/8] & (1<<(7-(p-1)%8));
if (bit) {
2015-09-18 13:47:37 -07:00
d[p/8] |= 1<<(7-p%8);
} else {
2015-09-18 13:47:37 -07:00
d[p/8] &= ~(1<<(7-p%8));
}
}
}
}
2016-04-21 10:06:48 -07:00
// Bit mapping
2015-09-18 13:47:37 -07:00
srslte_mod_modulate_bytes(&q->mod[cfg->grant.mcs.mod], (uint8_t*) q->q, q->d, cfg->nbits.nof_bits);
2016-04-21 10:06:48 -07:00
// DFT precoding
srslte_dft_precoding(&q->dft_precoding, q->d, q->z, cfg->grant.L_prb, cfg->nbits.nof_symb);
2015-03-02 02:11:44 -08:00
2016-04-21 10:06:48 -07:00
// Mapping to resource elements
2015-06-14 13:11:49 -07:00
pusch_put(q, &cfg->grant, q->z, sf_symbols);
2015-03-02 02:11:44 -08:00
ret = SRSLTE_SUCCESS;
}
return ret;
}
2016-04-21 10:06:48 -07:00
/** Decodes the PUSCH from the received symbols
*/
2016-04-21 10:06:48 -07:00
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, uint16_t rnti,
uint8_t *data, srslte_uci_data_t *uci_data)
{
2016-04-21 10:06:48 -07:00
uint32_t n;
if (q != NULL &&
sf_symbols != NULL &&
data != NULL &&
cfg != NULL)
{
INFO("Decoding PUSCH SF: %d, Mod %s, NofBits: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
cfg->sf_idx, srslte_mod_string(cfg->grant.mcs.mod), cfg->grant.mcs.tbs,
cfg->nbits.nof_re, cfg->nbits.nof_symb, cfg->nbits.nof_bits, cfg->rv);
/* extract symbols */
n = pusch_get(q, &cfg->grant, sf_symbols, q->d);
if (n != cfg->nbits.nof_re) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
return SRSLTE_ERROR;
}
/* extract channel estimates */
n = pusch_get(q, &cfg->grant, ce, q->ce);
if (n != cfg->nbits.nof_re) {
fprintf(stderr, "Error expecting %d symbols but got %d\n", cfg->nbits.nof_re, n);
return SRSLTE_ERROR;
}
2016-07-11 01:40:28 -07:00
// Equalization
srslte_predecoding_single(q->d, q->ce, q->z, cfg->nbits.nof_re, noise_estimate);
// DFT predecoding
srslte_dft_predecoding(&q->dft_precoding, q->z, q->d, cfg->grant.L_prb, cfg->nbits.nof_symb);
// Soft demodulation
srslte_demod_soft_demodulate_s(cfg->grant.mcs.mod, q->d, q->q, cfg->nbits.nof_re);
2016-04-21 10:06:48 -07:00
srslte_sequence_t *seq = NULL;
2017-01-09 08:15:36 -08:00
// Create sequence if does not exist
if (q->users[rnti] && q->users[rnti]->sequences_generated) {
seq = &q->users[rnti]->seq[cfg->sf_idx];
} else {
seq = &q->tmp_seq;
if (srslte_sequence_pusch(seq, rnti, 2 * cfg->sf_idx, q->cell.id, cfg->nbits.nof_bits)) {
return SRSLTE_ERROR;
}
}
// Decode RI/HARQ bits before descrambling
if (srslte_ulsch_uci_decode_ri_ack(&q->ul_sch, cfg, softbuffer, q->q, seq->c, uci_data)) {
fprintf(stderr, "Error decoding RI/HARQ bits\n");
2016-05-09 03:38:39 -07:00
return SRSLTE_ERROR;
}
// Descrambling
srslte_scrambling_s_offset(seq, q->q, 0, cfg->nbits.nof_bits);
if (!(q->users[rnti] && q->users[rnti]->sequences_generated)) {
srslte_sequence_free(seq);
}
2017-01-09 08:15:36 -08:00
return srslte_ulsch_uci_decode(&q->ul_sch, cfg, softbuffer, q->q, q->g, data, uci_data);
2016-05-09 03:38:39 -07:00
} else {
return SRSLTE_ERROR_INVALID_INPUTS;
2016-05-09 03:38:39 -07:00
}
}
2016-07-06 12:03:25 -07:00
uint32_t srslte_pusch_last_noi(srslte_pusch_t *q) {
return q->ul_sch.nof_iterations;
}
2015-11-13 04:22:33 -08:00