2019-04-26 12:27:38 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2013-2019 Software Radio Systems Limited
|
2015-01-29 16:15:09 -08:00
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* This file is part of srsLTE.
|
2015-01-29 16:15:09 -08:00
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* 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
|
2015-01-29 16:15:09 -08:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-20 05:01:08 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2015-01-29 16:15:09 -08:00
|
|
|
* 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-01-29 16:15:09 -08:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2015-01-29 16:15:09 -08:00
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
#include "srslte/srslte.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
2015-01-29 16:15:09 -08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2019-04-23 01:53:11 -07:00
|
|
|
#include <stdlib.h>
|
2015-01-29 16:15:09 -08:00
|
|
|
#include <string.h>
|
|
|
|
#include <strings.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-01-29 16:15:09 -08:00
|
|
|
|
2015-03-18 05:59:29 -07:00
|
|
|
#define MAX_PUSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12)
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
#define ACK_SNR_TH -1.0
|
2015-01-29 16:15:09 -08:00
|
|
|
|
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-06-12 08:49:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
/* Allocate/deallocate PUSCH RBs to the resource grid
|
|
|
|
*/
|
2019-04-23 01:53:11 -07:00
|
|
|
static int pusch_cp(
|
|
|
|
srslte_pusch_t* q, srslte_pusch_grant_t* grant, cf_t* input, cf_t* output, bool is_shortened, bool advance_input)
|
2015-06-12 08:49:11 -07:00
|
|
|
{
|
2019-04-23 01:53:11 -07:00
|
|
|
cf_t* in_ptr = input;
|
|
|
|
cf_t* out_ptr = output;
|
|
|
|
|
2015-06-12 08:49:11 -07:00
|
|
|
uint32_t L_ref = 3;
|
|
|
|
if (SRSLTE_CP_ISEXT(q->cell.cp)) {
|
|
|
|
L_ref = 2;
|
|
|
|
}
|
2019-04-23 01:53:11 -07:00
|
|
|
for (uint32_t slot = 0; slot < 2; slot++) {
|
|
|
|
uint32_t N_srs = 0;
|
|
|
|
if (is_shortened && slot == 1) {
|
2015-06-14 13:11:49 -07:00
|
|
|
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++) {
|
2015-02-14 05:20:16 -08:00
|
|
|
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];
|
|
|
|
}
|
2015-04-27 09:14:28 -07:00
|
|
|
memcpy(out_ptr, in_ptr, grant->L_prb * SRSLTE_NRE * sizeof(cf_t));
|
2015-02-15 23:55:17 -08:00
|
|
|
if (advance_input) {
|
2015-04-27 09:14:28 -07:00
|
|
|
in_ptr += grant->L_prb*SRSLTE_NRE;
|
2015-02-15 23:55:17 -08:00
|
|
|
} else {
|
2015-04-27 09:14:28 -07:00
|
|
|
out_ptr += grant->L_prb*SRSLTE_NRE;
|
2015-02-14 05:20:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-21 10:06:48 -07:00
|
|
|
if (advance_input) {
|
|
|
|
return in_ptr - input;
|
|
|
|
} else {
|
|
|
|
return out_ptr - output;
|
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
static int pusch_put(srslte_pusch_t* q, srslte_pusch_grant_t* grant, cf_t* input, cf_t* output, bool is_shortened)
|
|
|
|
{
|
|
|
|
return pusch_cp(q, grant, input, output, is_shortened, true);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
static int pusch_get(srslte_pusch_t* q, srslte_pusch_grant_t* grant, cf_t* input, cf_t* output, bool is_shortened)
|
|
|
|
{
|
|
|
|
return pusch_cp(q, grant, input, output, is_shortened, false);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Initializes the PDCCH transmitter and receiver */
|
2019-04-23 01:53:11 -07:00
|
|
|
static int pusch_init(srslte_pusch_t* q, uint32_t max_prb, bool is_ue)
|
|
|
|
{
|
2015-03-18 05:31:13 -07:00
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
2015-01-29 16:15:09 -08:00
|
|
|
int i;
|
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
if (q != NULL)
|
2015-01-29 16:15:09 -08:00
|
|
|
{
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
bzero(q, sizeof(srslte_pusch_t));
|
2015-03-18 05:31:13 -07:00
|
|
|
ret = SRSLTE_ERROR;
|
2017-09-01 04:29:11 -07:00
|
|
|
q->max_re = max_prb * MAX_PUSCH_RE(SRSLTE_CP_NORM);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
INFO("Init PUSCH: %d PRBs\n", max_prb);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2015-10-05 00:58:44 -07:00
|
|
|
if (srslte_modem_table_lte(&q->mod[i], modulations[i])) {
|
2015-01-29 16:15:09 -08:00
|
|
|
goto clean;
|
|
|
|
}
|
2015-09-18 13:47:37 -07:00
|
|
|
srslte_modem_table_bytes(&q->mod[i]);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2017-09-01 04:29:11 -07:00
|
|
|
|
|
|
|
q->is_ue = is_ue;
|
|
|
|
|
|
|
|
q->users = calloc(sizeof(srslte_pusch_user_t*), q->is_ue?1:(1+SRSLTE_SIRNTI));
|
2016-11-20 08:36:21 -08:00
|
|
|
if (!q->users) {
|
|
|
|
perror("malloc");
|
|
|
|
goto clean;
|
|
|
|
}
|
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
if (srslte_sequence_init(&q->tmp_seq, q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM))) {
|
|
|
|
goto clean;
|
2015-02-15 23:55:17 -08:00
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2016-05-09 03:38:39 -07:00
|
|
|
srslte_sch_init(&q->ul_sch);
|
2017-09-01 04:29:11 -07:00
|
|
|
|
|
|
|
if (srslte_dft_precoding_init(&q->dft_precoding, max_prb, is_ue)) {
|
2019-04-23 01:53:11 -07:00
|
|
|
ERROR("Error initiating DFT transform precoding\n");
|
2015-02-14 05:20:16 -08:00
|
|
|
goto clean;
|
|
|
|
}
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2016-04-27 08:23:36 -07:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-04-27 08:23:36 -07:00
|
|
|
// 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) {
|
2015-01-29 16:15:09 -08:00
|
|
|
goto clean;
|
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
|
|
|
if (!q->d) {
|
2015-09-05 02:51:19 -07:00
|
|
|
goto clean;
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
if (!q->is_ue) {
|
|
|
|
q->ce = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
|
|
|
if (!q->ce) {
|
|
|
|
goto clean;
|
|
|
|
}
|
2015-02-13 01:02:10 -08:00
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
q->z = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
|
|
|
if (!q->z) {
|
2015-02-13 01:02:10 -08:00
|
|
|
goto clean;
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
ret = SRSLTE_SUCCESS;
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
clean:
|
2015-03-18 05:31:13 -07:00
|
|
|
if (ret == SRSLTE_ERROR) {
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_pusch_free(q);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
int srslte_pusch_init_ue(srslte_pusch_t *q, uint32_t max_prb) {
|
|
|
|
return pusch_init(q, max_prb, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int srslte_pusch_init_enb(srslte_pusch_t *q, uint32_t max_prb) {
|
|
|
|
return pusch_init(q, max_prb, false);
|
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
void srslte_pusch_free(srslte_pusch_t *q) {
|
2015-01-29 16:15:09 -08:00
|
|
|
int i;
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
if (q->q) {
|
|
|
|
free(q->q);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
if (q->d) {
|
|
|
|
free(q->d);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
if (q->g) {
|
|
|
|
free(q->g);
|
2015-02-12 01:38:53 -08:00
|
|
|
}
|
2015-02-13 01:02:10 -08:00
|
|
|
if (q->ce) {
|
|
|
|
free(q->ce);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2015-03-18 11:14:24 -07:00
|
|
|
if (q->z) {
|
|
|
|
free(q->z);
|
2015-02-13 01:02:10 -08:00
|
|
|
}
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_dft_precoding_free(&q->dft_precoding);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
if (q->users) {
|
2017-09-01 04:29:11 -07:00
|
|
|
if (q->is_ue) {
|
2017-09-04 03:26:58 -07:00
|
|
|
srslte_pusch_free_rnti(q, 0);
|
2017-09-01 04:29:11 -07:00
|
|
|
} else {
|
2017-09-05 07:51:44 -07:00
|
|
|
for (int rnti=0;rnti<=SRSLTE_SIRNTI;rnti++) {
|
2017-09-04 03:26:58 -07:00
|
|
|
srslte_pusch_free_rnti(q, rnti);
|
2017-09-01 04:29:11 -07:00
|
|
|
}
|
2016-11-20 08:36:21 -08:00
|
|
|
}
|
|
|
|
free(q->users);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2017-09-01 04:29:11 -07:00
|
|
|
|
|
|
|
srslte_sequence_free(&q->tmp_seq);
|
|
|
|
|
2015-01-29 16:15:09 -08:00
|
|
|
for (i = 0; i < 4; i++) {
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_modem_table_free(&q->mod[i]);
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2016-05-09 03:38:39 -07:00
|
|
|
srslte_sch_free(&q->ul_sch);
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
bzero(q, sizeof(srslte_pusch_t));
|
2015-01-29 16:15:09 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
int srslte_pusch_set_cell(srslte_pusch_t *q, srslte_cell_t cell) {
|
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
if (q != NULL && srslte_cell_isvalid(&cell)) {
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
q->cell = cell;
|
|
|
|
q->max_re = cell.nof_prb * MAX_PUSCH_RE(cell.cp);
|
2017-09-01 04:29:11 -07:00
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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.
|
2016-11-20 08:36:21 -08:00
|
|
|
* 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) {
|
2015-01-29 16:15:09 -08:00
|
|
|
uint32_t i;
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2017-09-05 03:08:43 -07:00
|
|
|
uint32_t rnti_idx = q->is_ue?0:rnti;
|
2017-09-04 03:26:58 -07:00
|
|
|
|
|
|
|
if (!q->users[rnti_idx] || q->is_ue) {
|
|
|
|
if (!q->users[rnti_idx]) {
|
|
|
|
q->users[rnti_idx] = calloc(1, sizeof(srslte_pusch_user_t));
|
|
|
|
if (!q->users[rnti_idx]) {
|
|
|
|
perror("calloc");
|
|
|
|
return -1;
|
2017-07-11 04:17:26 -07:00
|
|
|
}
|
2016-05-09 03:38:39 -07:00
|
|
|
}
|
2018-07-12 09:55:19 -07:00
|
|
|
q->users[rnti_idx]->sequence_generated = false;
|
2019-04-23 01:53:11 -07:00
|
|
|
for (i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) {
|
2017-09-04 03:26:58 -07:00
|
|
|
if (srslte_sequence_pusch(&q->users[rnti_idx]->seq[i], rnti, 2 * i, q->cell.id,
|
|
|
|
q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM)))
|
|
|
|
{
|
2019-04-23 01:53:11 -07:00
|
|
|
ERROR("Error initializing PUSCH scrambling sequence\n");
|
2017-09-04 03:26:58 -07:00
|
|
|
srslte_pusch_free_rnti(q, rnti);
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 01:53:11 -07:00
|
|
|
q->ue_rnti = rnti;
|
2017-09-04 03:26:58 -07:00
|
|
|
q->users[rnti_idx]->cell_id = q->cell.id;
|
|
|
|
q->users[rnti_idx]->sequence_generated = true;
|
|
|
|
} else {
|
2019-04-23 01:53:11 -07:00
|
|
|
ERROR("Error generating PUSCH sequence: rnti=0x%x already generated\n", rnti);
|
2015-03-02 02:11:44 -08:00
|
|
|
}
|
2016-11-20 08:36:21 -08:00
|
|
|
return SRSLTE_SUCCESS;
|
2015-03-02 02:11:44 -08:00
|
|
|
}
|
|
|
|
|
2017-09-04 03:26:58 -07:00
|
|
|
void srslte_pusch_free_rnti(srslte_pusch_t *q, uint16_t rnti) {
|
2017-09-01 04:29:11 -07:00
|
|
|
|
|
|
|
uint32_t rnti_idx = q->is_ue?0:rnti;
|
|
|
|
|
|
|
|
if (q->users[rnti_idx]) {
|
2019-04-23 01:53:11 -07:00
|
|
|
for (int i = 0; i < SRSLTE_NOF_SF_X_FRAME; i++) {
|
2017-09-01 04:29:11 -07:00
|
|
|
srslte_sequence_free(&q->users[rnti_idx]->seq[i]);
|
2016-11-20 08:36:21 -08:00
|
|
|
}
|
2017-09-01 04:29:11 -07:00
|
|
|
free(q->users[rnti_idx]);
|
|
|
|
q->users[rnti_idx] = NULL;
|
2017-09-07 04:19:53 -07:00
|
|
|
q->ue_rnti = 0;
|
2017-09-01 04:29:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
static srslte_sequence_t* get_user_sequence(srslte_pusch_t* q, uint16_t rnti, uint32_t sf_idx, uint32_t len)
|
2017-09-01 04:29:11 -07:00
|
|
|
{
|
|
|
|
uint32_t rnti_idx = q->is_ue?0:rnti;
|
2017-09-04 03:26:58 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
if (SRSLTE_RNTI_ISUSER(rnti)) {
|
2018-09-19 07:41:59 -07:00
|
|
|
// The scrambling sequence is pregenerated for all RNTIs in the eNodeB but only for C-RNTI in the UE
|
2019-04-23 01:53:11 -07:00
|
|
|
if (q->users[rnti_idx] && q->users[rnti_idx]->sequence_generated && q->users[rnti_idx]->cell_id == q->cell.id &&
|
|
|
|
(!q->is_ue || q->ue_rnti == rnti)) {
|
2018-09-19 07:41:59 -07:00
|
|
|
return &q->users[rnti_idx]->seq[sf_idx];
|
|
|
|
} else {
|
|
|
|
if (srslte_sequence_pusch(&q->tmp_seq, rnti, 2 * sf_idx, q->cell.id, len)) {
|
2019-04-23 01:53:11 -07:00
|
|
|
ERROR("Error generating temporal scrambling sequence\n");
|
2018-09-19 07:41:59 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &q->tmp_seq;
|
|
|
|
}
|
2017-09-01 04:29:11 -07:00
|
|
|
} else {
|
2019-04-23 01:53:11 -07:00
|
|
|
ERROR("Invalid RNTI=0x%x\n", rnti);
|
2018-09-19 07:41:59 -07:00
|
|
|
return NULL;
|
2015-03-02 02:11:44 -08:00
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Converts the PUSCH data bits to symbols mapped to the slot ready for transmission
|
|
|
|
*/
|
2019-04-23 01:53:11 -07:00
|
|
|
int srslte_pusch_encode(
|
|
|
|
srslte_pusch_t* q, srslte_ul_sf_cfg_t* sf, srslte_pusch_cfg_t* cfg, srslte_pusch_data_t* data, cf_t* sf_symbols)
|
2015-01-29 16:15:09 -08:00
|
|
|
{
|
2015-03-18 05:31:13 -07:00
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2015-02-13 02:13:56 -08:00
|
|
|
if (q != NULL &&
|
2015-04-27 09:14:28 -07:00
|
|
|
cfg != NULL)
|
2015-01-29 16:15:09 -08:00
|
|
|
{
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
/* Limit UL modulation if not supported by the UE or disabled by higher layers */
|
|
|
|
if (!cfg->enable_64qam) {
|
|
|
|
if (cfg->grant.tb.mod >= SRSLTE_MOD_64QAM) {
|
|
|
|
cfg->grant.tb.mod = SRSLTE_MOD_16QAM;
|
|
|
|
cfg->grant.tb.nof_bits = cfg->grant.nof_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_16QAM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->grant.nof_re > q->max_re) {
|
|
|
|
ERROR("Error too many RE per subframe (%d). PUSCH configured for %d RE (%d PRB)\n",
|
|
|
|
cfg->grant.nof_re,
|
|
|
|
q->max_re,
|
|
|
|
q->cell.nof_prb);
|
2015-03-18 05:31:13 -07:00
|
|
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
2015-03-02 02:11:44 -08:00
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
if (!srslte_dft_precoding_valid_prb(cfg->grant.L_prb)) {
|
|
|
|
ERROR("Error encoding PUSCH: invalid L_prb=%d\n", cfg->grant.L_prb);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->grant.tb.rv < 0 || cfg->grant.tb.rv > 3) {
|
|
|
|
ERROR("Error encoding PUSCH: invalid rv=%d\n", cfg->grant.tb.rv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->grant.tb.tbs < 0) {
|
|
|
|
ERROR("Error encoding PUSCH: invalid tbs=%d\n", cfg->grant.tb.tbs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-06-04 02:48:13 -07:00
|
|
|
INFO("Encoding PUSCH SF: %d, Mod %s, RNTI: %d, TBS: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
|
2019-04-23 01:53:11 -07:00
|
|
|
sf->tti % 10,
|
|
|
|
srslte_mod_string(cfg->grant.tb.mod),
|
|
|
|
cfg->rnti,
|
|
|
|
cfg->grant.tb.tbs,
|
|
|
|
cfg->grant.nof_re,
|
|
|
|
cfg->grant.nof_symb,
|
|
|
|
cfg->grant.tb.nof_bits,
|
|
|
|
cfg->grant.tb.rv);
|
|
|
|
|
|
|
|
bzero(q->q, cfg->grant.tb.nof_bits);
|
|
|
|
if ((ret = srslte_ulsch_encode(&q->ul_sch, cfg, data->ptr, &data->uci, q->g, q->q)) < 0) {
|
|
|
|
ERROR("Error encoding TB\n");
|
2015-03-18 05:31:13 -07:00
|
|
|
return SRSLTE_ERROR;
|
2015-03-02 02:11:44 -08:00
|
|
|
}
|
2015-06-19 04:10:37 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
uint32_t nof_ri_ack_bits = (uint32_t)ret;
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
// Generate scrambling sequence if not pre-generated
|
|
|
|
srslte_sequence_t* seq = get_user_sequence(q, cfg->rnti, sf->tti % 10, cfg->grant.tb.nof_bits);
|
2018-10-04 01:37:59 -07:00
|
|
|
if (!seq) {
|
2019-04-23 01:53:11 -07:00
|
|
|
ERROR("Error getting user sequence for rnti=0x%x\n", cfg->rnti);
|
|
|
|
return -1;
|
2018-10-04 01:37:59 -07:00
|
|
|
}
|
2019-04-23 01:53:11 -07:00
|
|
|
|
|
|
|
// Run scrambling
|
|
|
|
srslte_scrambling_bytes(seq, (uint8_t*)q->q, cfg->grant.tb.nof_bits);
|
2017-09-01 04:29:11 -07:00
|
|
|
|
2017-09-01 10:32:57 -07:00
|
|
|
// Correct UCI placeholder/repetition bits
|
2019-04-23 01:53:11 -07:00
|
|
|
uint8_t* d = q->q;
|
|
|
|
for (int i = 0; i < nof_ri_ack_bits; i++) {
|
2016-05-09 03:38:39 -07:00
|
|
|
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;
|
2019-04-23 01:53:11 -07:00
|
|
|
uint8_t bit = d[(p - 1) / 8] & (1 << (7 - (p - 1) % 8));
|
2015-09-18 06:46:27 -07:00
|
|
|
if (bit) {
|
2019-04-23 01:53:11 -07:00
|
|
|
d[p / 8] |= 1 << (7 - p % 8);
|
2015-09-18 06:46:27 -07:00
|
|
|
} else {
|
2015-09-18 13:47:37 -07:00
|
|
|
d[p/8] &= ~(1<<(7-p%8));
|
2015-09-18 06:46:27 -07:00
|
|
|
}
|
2015-09-05 02:51:19 -07:00
|
|
|
}
|
|
|
|
}
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
2019-04-23 01:53:11 -07:00
|
|
|
|
2016-04-21 10:06:48 -07:00
|
|
|
// Bit mapping
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_mod_modulate_bytes(&q->mod[cfg->grant.tb.mod], (uint8_t*)q->q, q->d, cfg->grant.tb.nof_bits);
|
2016-04-21 10:06:48 -07:00
|
|
|
|
|
|
|
// DFT precoding
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_dft_precoding(&q->dft_precoding, q->d, q->z, cfg->grant.L_prb, cfg->grant.nof_symb);
|
|
|
|
|
2016-04-21 10:06:48 -07:00
|
|
|
// Mapping to resource elements
|
2019-04-23 01:53:11 -07:00
|
|
|
uint32_t n = pusch_put(q, &cfg->grant, q->z, sf_symbols, sf->shortened);
|
|
|
|
if (n != cfg->grant.nof_re) {
|
|
|
|
ERROR("Error trying to allocate %d symbols but %d were allocated (tti=%d, short=%d, L=%d)\n",
|
|
|
|
cfg->grant.nof_re,
|
|
|
|
n,
|
|
|
|
sf->tti,
|
|
|
|
sf->shortened,
|
|
|
|
cfg->grant.L_prb);
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
ret = SRSLTE_SUCCESS;
|
2015-01-29 16:15:09 -08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-21 10:06:48 -07:00
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
/** Decodes the PUSCH from the received symbols
|
|
|
|
*/
|
2019-04-23 01:53:11 -07:00
|
|
|
int srslte_pusch_decode(srslte_pusch_t* q,
|
|
|
|
srslte_ul_sf_cfg_t* sf,
|
|
|
|
srslte_pusch_cfg_t* cfg,
|
|
|
|
srslte_chest_ul_res_t* channel,
|
|
|
|
cf_t* sf_symbols,
|
|
|
|
srslte_pusch_res_t* out)
|
2016-04-27 08:23:36 -07:00
|
|
|
{
|
2019-04-23 01:53:11 -07:00
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
2016-04-21 10:06:48 -07:00
|
|
|
uint32_t n;
|
2019-04-23 01:53:11 -07:00
|
|
|
|
|
|
|
if (q != NULL && sf_symbols != NULL && out != NULL && cfg != NULL) {
|
|
|
|
|
|
|
|
struct timeval t[3];
|
|
|
|
if (cfg->meas_time_en) {
|
|
|
|
gettimeofday(&t[1], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Limit UL modulation if not supported by the UE or disabled by higher layers */
|
|
|
|
if (!cfg->enable_64qam) {
|
|
|
|
if (cfg->grant.tb.mod >= SRSLTE_MOD_64QAM) {
|
|
|
|
cfg->grant.tb.mod = SRSLTE_MOD_16QAM;
|
|
|
|
cfg->grant.tb.nof_bits = cfg->grant.nof_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_16QAM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
INFO("Decoding PUSCH SF: %d, Mod %s, NofBits: %d, NofRE: %d, NofSymbols=%d, NofBitsE: %d, rv_idx: %d\n",
|
2019-04-23 01:53:11 -07:00
|
|
|
sf->tti % 10,
|
|
|
|
srslte_mod_string(cfg->grant.tb.mod),
|
|
|
|
cfg->grant.tb.tbs,
|
|
|
|
cfg->grant.nof_re,
|
|
|
|
cfg->grant.nof_symb,
|
|
|
|
cfg->grant.tb.nof_bits,
|
|
|
|
cfg->grant.tb.rv);
|
2016-11-20 08:36:21 -08:00
|
|
|
|
|
|
|
/* extract symbols */
|
2019-04-23 01:53:11 -07:00
|
|
|
n = pusch_get(q, &cfg->grant, sf_symbols, q->d, sf->shortened);
|
|
|
|
if (n != cfg->grant.nof_re) {
|
|
|
|
ERROR("Error expecting %d symbols but got %d\n", cfg->grant.nof_re, n);
|
2016-11-20 08:36:21 -08:00
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
2019-04-23 01:53:11 -07:00
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
/* extract channel estimates */
|
2019-04-23 01:53:11 -07:00
|
|
|
n = pusch_get(q, &cfg->grant, channel->ce, q->ce, sf->shortened);
|
|
|
|
if (n != cfg->grant.nof_re) {
|
|
|
|
ERROR("Error expecting %d symbols but got %d\n", cfg->grant.nof_re, n);
|
2016-11-20 08:36:21 -08:00
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
2016-07-11 01:40:28 -07:00
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
// Equalization
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_predecoding_single(q->d, q->ce, q->z, NULL, cfg->grant.nof_re, 1.0f, channel->noise_estimate);
|
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
// DFT predecoding
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_dft_precoding(&q->dft_precoding, q->z, q->d, cfg->grant.L_prb, cfg->grant.nof_symb);
|
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
// Soft demodulation
|
2018-09-04 08:51:35 -07:00
|
|
|
if (q->llr_is_8bit) {
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_demod_soft_demodulate_b(cfg->grant.tb.mod, q->d, q->q, cfg->grant.nof_re);
|
2018-09-04 08:51:35 -07:00
|
|
|
} else {
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_demod_soft_demodulate_s(cfg->grant.tb.mod, q->d, q->q, cfg->grant.nof_re);
|
2018-09-04 08:51:35 -07:00
|
|
|
}
|
2016-04-21 10:06:48 -07:00
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
// Generate scrambling sequence if not pre-generated
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_sequence_t* seq = get_user_sequence(q, cfg->rnti, sf->tti % 10, cfg->grant.tb.nof_bits);
|
|
|
|
if (!seq) {
|
|
|
|
ERROR("Error getting user sequence for rnti=0x%x\n", cfg->rnti);
|
|
|
|
return -1;
|
2016-05-09 03:38:39 -07:00
|
|
|
}
|
2017-11-16 05:48:03 -08:00
|
|
|
|
2016-11-20 08:36:21 -08:00
|
|
|
// Descrambling
|
2018-09-04 08:51:35 -07:00
|
|
|
if (q->llr_is_8bit) {
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_scrambling_sb_offset(seq, q->q, 0, cfg->grant.tb.nof_bits);
|
2018-09-04 08:51:35 -07:00
|
|
|
} else {
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_scrambling_s_offset(seq, q->q, 0, cfg->grant.tb.nof_bits);
|
2018-09-04 08:51:35 -07:00
|
|
|
}
|
2017-11-16 05:48:03 -08:00
|
|
|
|
|
|
|
// Decode
|
2019-04-23 01:53:11 -07:00
|
|
|
ret = srslte_ulsch_decode(&q->ul_sch, cfg, q->q, q->g, seq->c, out->data, &out->uci);
|
|
|
|
out->crc = (ret == 0);
|
2017-11-16 05:48:03 -08:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
// Accept ACK only if SNR is above threshold
|
|
|
|
out->uci.ack.valid = channel->snr_db > ACK_SNR_TH;
|
|
|
|
out->avg_iterations_block = q->ul_sch.avg_iterations;
|
|
|
|
|
|
|
|
// Save O_cqi for power control
|
|
|
|
cfg->last_O_cqi = srslte_cqi_size(&cfg->uci_cfg.cqi);
|
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
|
|
|
|
if (cfg->meas_time_en) {
|
|
|
|
gettimeofday(&t[2], NULL);
|
|
|
|
get_time_interval(t);
|
|
|
|
cfg->meas_time_value = t[0].tv_usec;
|
2017-11-16 05:48:03 -08:00
|
|
|
}
|
2016-05-09 03:38:39 -07:00
|
|
|
}
|
2017-11-16 05:48:03 -08:00
|
|
|
|
|
|
|
return ret;
|
2016-05-09 03:38:39 -07:00
|
|
|
}
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
uint32_t srslte_pusch_grant_tx_info(
|
|
|
|
srslte_pusch_grant_t* grant, srslte_uci_cfg_t* uci_cfg, srslte_uci_value_t* uci_data, char* str, uint32_t str_len)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t len = srslte_ra_ul_info(grant, str, str_len);
|
|
|
|
|
|
|
|
if (uci_data) {
|
|
|
|
len += srslte_uci_data_info(uci_cfg, uci_data, &str[len], str_len - len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t srslte_pusch_tx_info(srslte_pusch_cfg_t* cfg, srslte_uci_value_t* uci_data, char* str, uint32_t str_len)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t len = srslte_print_check(str, str_len, 0, "rnti=0x%x", cfg->rnti);
|
|
|
|
|
|
|
|
len += srslte_pusch_grant_tx_info(&cfg->grant, &cfg->uci_cfg, uci_data, &str[len], str_len - len);
|
|
|
|
|
|
|
|
if (cfg->meas_time_en) {
|
|
|
|
len = srslte_print_check(str, str_len, len, ", t=%d us", cfg->meas_time_value);
|
|
|
|
}
|
|
|
|
return len;
|
2016-07-06 12:03:25 -07:00
|
|
|
}
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
uint32_t srslte_pusch_rx_info(srslte_pusch_cfg_t* cfg, srslte_pusch_res_t* res, char* str, uint32_t str_len)
|
|
|
|
{
|
2016-07-06 12:03:25 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
uint32_t len = srslte_print_check(str, str_len, 0, "rnti=0x%x", cfg->rnti);
|
|
|
|
|
|
|
|
len += srslte_ra_ul_info(&cfg->grant, &str[len], str_len);
|
|
|
|
|
|
|
|
len = srslte_print_check(
|
|
|
|
str, str_len, len, ", crc=%s, avg_iter=%.1f", res->crc ? "OK" : "KO", res->avg_iterations_block);
|
|
|
|
|
|
|
|
len += srslte_uci_data_info(&cfg->uci_cfg, &res->uci, &str[len], str_len - len);
|
|
|
|
|
|
|
|
if (cfg->meas_time_en) {
|
|
|
|
len = srslte_print_check(str, str_len, len, ", t=%d us", cfg->meas_time_value);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|