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.
566 lines
17 KiB
C
566 lines
17 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
11 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
11 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
|
||
11 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,
|
||
11 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.
|
||
11 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
11 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 "prb_dl.h"
|
||
10 years ago
|
#include "srslte/phch/pdsch.h"
|
||
10 years ago
|
#include "srslte/phch/sch.h"
|
||
10 years ago
|
#include "srslte/common/phy_common.h"
|
||
|
#include "srslte/utils/bit.h"
|
||
|
#include "srslte/utils/debug.h"
|
||
|
#include "srslte/utils/vector.h"
|
||
11 years ago
|
|
||
|
|
||
10 years ago
|
#define MAX_PDSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12)
|
||
11 years ago
|
|
||
11 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 };
|
||
11 years ago
|
|
||
10 years ago
|
//#define DEBUG_IDX
|
||
10 years ago
|
|
||
10 years ago
|
#ifdef DEBUG_IDX
|
||
|
cf_t *offset_original=NULL;
|
||
10 years ago
|
extern int indices[100000];
|
||
10 years ago
|
extern int indices_ptr;
|
||
10 years ago
|
#endif
|
||
11 years ago
|
|
||
10 years ago
|
|
||
10 years ago
|
int srslte_pdsch_cp(srslte_pdsch_t *q, cf_t *input, cf_t *output, srslte_ra_dl_grant_t *grant, uint32_t lstart_grant, uint32_t nsubframe, bool put)
|
||
|
{
|
||
11 years ago
|
uint32_t s, n, l, lp, lstart, lend, nof_refs;
|
||
11 years ago
|
bool is_pbch, is_sss;
|
||
|
cf_t *in_ptr = input, *out_ptr = output;
|
||
10 years ago
|
uint32_t offset = 0;
|
||
11 years ago
|
|
||
10 years ago
|
#ifdef DEBUG_IDX
|
||
10 years ago
|
indices_ptr = 0;
|
||
|
if (put) {
|
||
|
offset_original = output;
|
||
|
} else {
|
||
|
offset_original = input;
|
||
|
}
|
||
10 years ago
|
#endif
|
||
|
|
||
11 years ago
|
if (q->cell.nof_ports == 1) {
|
||
11 years ago
|
nof_refs = 2;
|
||
|
} else {
|
||
|
nof_refs = 4;
|
||
|
}
|
||
|
|
||
|
for (s = 0; s < 2; s++) {
|
||
10 years ago
|
for (l = 0; l < SRSLTE_CP_NSYMB(q->cell.cp); l++) {
|
||
10 years ago
|
for (n = 0; n < q->cell.nof_prb; n++) {
|
||
|
|
||
|
// If this PRB is assigned
|
||
10 years ago
|
if (grant->prb_idx[s][n]) {
|
||
10 years ago
|
if (s == 0) {
|
||
10 years ago
|
lstart = lstart_grant;
|
||
10 years ago
|
} else {
|
||
|
lstart = 0;
|
||
11 years ago
|
}
|
||
10 years ago
|
lend = SRSLTE_CP_NSYMB(q->cell.cp);
|
||
10 years ago
|
is_pbch = is_sss = false;
|
||
|
|
||
|
// Skip PSS/SSS signals
|
||
|
if (s == 0 && (nsubframe == 0 || nsubframe == 5)) {
|
||
|
if (n >= q->cell.nof_prb / 2 - 3
|
||
9 years ago
|
&& n < q->cell.nof_prb / 2 + 3 + (q->cell.nof_prb%2)) {
|
||
10 years ago
|
lend = SRSLTE_CP_NSYMB(q->cell.cp) - 2;
|
||
10 years ago
|
is_sss = true;
|
||
|
}
|
||
11 years ago
|
}
|
||
10 years ago
|
// Skip PBCH
|
||
|
if (s == 1 && nsubframe == 0) {
|
||
|
if (n >= q->cell.nof_prb / 2 - 3
|
||
9 years ago
|
&& n < q->cell.nof_prb / 2 + 3 + (q->cell.nof_prb%2)) {
|
||
10 years ago
|
lstart = 4;
|
||
|
is_pbch = true;
|
||
11 years ago
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
lp = l + s * SRSLTE_CP_NSYMB(q->cell.cp);
|
||
10 years ago
|
if (put) {
|
||
|
out_ptr = &output[(lp * q->cell.nof_prb + n)
|
||
10 years ago
|
* SRSLTE_NRE];
|
||
11 years ago
|
} else {
|
||
10 years ago
|
in_ptr = &input[(lp * q->cell.nof_prb + n)
|
||
10 years ago
|
* SRSLTE_NRE];
|
||
11 years ago
|
}
|
||
10 years ago
|
// This is a symbol in a normal PRB with or without references
|
||
|
if (l >= lstart && l < lend) {
|
||
10 years ago
|
if (SRSLTE_SYMBOL_HAS_REF(l, q->cell.cp, q->cell.nof_ports)) {
|
||
9 years ago
|
if (nof_refs == 2) {
|
||
|
if (l == 0) {
|
||
|
offset = q->cell.id % 6;
|
||
|
} else {
|
||
|
offset = (q->cell.id + 3) % 6;
|
||
|
}
|
||
10 years ago
|
} else {
|
||
|
offset = q->cell.id % 3;
|
||
|
}
|
||
|
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs, put);
|
||
11 years ago
|
} else {
|
||
10 years ago
|
prb_cp(&in_ptr, &out_ptr, 1);
|
||
11 years ago
|
}
|
||
10 years ago
|
}
|
||
|
// This is a symbol in a PRB with PBCH or Synch signals (SS).
|
||
|
// If the number or total PRB is odd, half of the the PBCH or SS will fall into the symbol
|
||
|
if ((q->cell.nof_prb % 2) && ((is_pbch && l < lstart) || (is_sss && l >= lend))) {
|
||
|
if (n == q->cell.nof_prb / 2 - 3) {
|
||
10 years ago
|
if (SRSLTE_SYMBOL_HAS_REF(l, q->cell.cp, q->cell.nof_ports)) {
|
||
10 years ago
|
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs/2, put);
|
||
|
} else {
|
||
|
prb_cp_half(&in_ptr, &out_ptr, 1);
|
||
|
}
|
||
|
} else if (n == q->cell.nof_prb / 2 + 3) {
|
||
|
if (put) {
|
||
|
out_ptr += 6;
|
||
|
} else {
|
||
|
in_ptr += 6;
|
||
|
}
|
||
10 years ago
|
if (SRSLTE_SYMBOL_HAS_REF(l, q->cell.cp, q->cell.nof_ports)) {
|
||
10 years ago
|
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, nof_refs/2, put);
|
||
|
} else {
|
||
|
prb_cp_half(&in_ptr, &out_ptr, 1);
|
||
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
|
int r;
|
||
11 years ago
|
if (put) {
|
||
10 years ago
|
r = abs((int) (input - in_ptr));
|
||
11 years ago
|
} else {
|
||
10 years ago
|
r = abs((int) (output - out_ptr));
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
|
return r;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Puts PDSCH in slot number 1
|
||
|
*
|
||
|
* Returns the number of symbols written to sf_symbols
|
||
|
*
|
||
|
* 36.211 10.3 section 6.3.5
|
||
|
*/
|
||
10 years ago
|
int srslte_pdsch_put(srslte_pdsch_t *q, cf_t *symbols, cf_t *sf_symbols,
|
||
10 years ago
|
srslte_ra_dl_grant_t *grant, uint32_t lstart, uint32_t subframe)
|
||
|
{
|
||
|
return srslte_pdsch_cp(q, symbols, sf_symbols, grant, lstart, subframe, true);
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Extracts PDSCH from slot number 1
|
||
|
*
|
||
|
* Returns the number of symbols written to PDSCH
|
||
|
*
|
||
|
* 36.211 10.3 section 6.3.5
|
||
|
*/
|
||
10 years ago
|
int srslte_pdsch_get(srslte_pdsch_t *q, cf_t *sf_symbols, cf_t *symbols,
|
||
10 years ago
|
srslte_ra_dl_grant_t *grant, uint32_t lstart, uint32_t subframe)
|
||
|
{
|
||
|
return srslte_pdsch_cp(q, sf_symbols, symbols, grant, lstart, subframe, false);
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Initializes the PDCCH transmitter and receiver */
|
||
10 years ago
|
int srslte_pdsch_init(srslte_pdsch_t *q, srslte_cell_t cell) {
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
int i;
|
||
|
|
||
10 years ago
|
if (q != NULL &&
|
||
10 years ago
|
srslte_cell_isvalid(&cell))
|
||
11 years ago
|
{
|
||
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_pdsch_t));
|
||
10 years ago
|
ret = SRSLTE_ERROR;
|
||
11 years ago
|
|
||
|
q->cell = cell;
|
||
10 years ago
|
q->max_re = q->cell.nof_prb * MAX_PDSCH_RE(q->cell.cp);
|
||
11 years ago
|
|
||
11 years ago
|
INFO("Init PDSCH: %d ports %d PRBs, max_symbols: %d\n", q->cell.nof_ports,
|
||
10 years ago
|
q->cell.nof_prb, q->max_re);
|
||
11 years ago
|
|
||
11 years ago
|
for (i = 0; i < 4; i++) {
|
||
9 years ago
|
if (srslte_modem_table_lte(&q->mod[i], modulations[i])) {
|
||
11 years ago
|
goto clean;
|
||
|
}
|
||
9 years ago
|
srslte_modem_table_bytes(&q->mod[i]);
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
srslte_sch_init(&q->dl_sch);
|
||
10 years ago
|
|
||
10 years ago
|
q->rnti_is_set = false;
|
||
11 years ago
|
|
||
9 years ago
|
// Allocate int16_t for reception (LLRs)
|
||
|
q->e = srslte_vec_malloc(sizeof(int16_t) * q->max_re * srslte_mod_bits_x_symbol(SRSLTE_MOD_64QAM));
|
||
10 years ago
|
if (!q->e) {
|
||
11 years ago
|
goto clean;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
q->d = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
||
|
if (!q->d) {
|
||
11 years ago
|
goto clean;
|
||
|
}
|
||
|
|
||
11 years ago
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
10 years ago
|
q->ce[i] = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
||
11 years ago
|
if (!q->ce[i]) {
|
||
|
goto clean;
|
||
|
}
|
||
10 years ago
|
q->x[i] = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
||
|
if (!q->x[i]) {
|
||
11 years ago
|
goto clean;
|
||
|
}
|
||
10 years ago
|
q->symbols[i] = srslte_vec_malloc(sizeof(cf_t) * q->max_re);
|
||
|
if (!q->symbols[i]) {
|
||
11 years ago
|
goto clean;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
clean:
|
||
10 years ago
|
if (ret == SRSLTE_ERROR) {
|
||
10 years ago
|
srslte_pdsch_free(q);
|
||
11 years ago
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_pdsch_free(srslte_pdsch_t *q) {
|
||
11 years ago
|
int i;
|
||
|
|
||
10 years ago
|
if (q->e) {
|
||
|
free(q->e);
|
||
11 years ago
|
}
|
||
10 years ago
|
if (q->d) {
|
||
|
free(q->d);
|
||
11 years ago
|
}
|
||
11 years ago
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
11 years ago
|
if (q->ce[i]) {
|
||
|
free(q->ce[i]);
|
||
|
}
|
||
10 years ago
|
if (q->x[i]) {
|
||
|
free(q->x[i]);
|
||
11 years ago
|
}
|
||
10 years ago
|
if (q->symbols[i]) {
|
||
|
free(q->symbols[i]);
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
for (i = 0; i < SRSLTE_NSUBFRAMES_X_FRAME; i++) {
|
||
10 years ago
|
srslte_sequence_free(&q->seq[i]);
|
||
11 years ago
|
}
|
||
|
|
||
|
for (i = 0; i < 4; i++) {
|
||
10 years ago
|
srslte_modem_table_free(&q->mod[i]);
|
||
11 years ago
|
}
|
||
9 years ago
|
|
||
10 years ago
|
srslte_sch_free(&q->dl_sch);
|
||
10 years ago
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_pdsch_t));
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
10 years ago
|
/* Configures the structure srslte_pdsch_cfg_t from the DL DCI allocation dci_msg.
|
||
|
* If dci_msg is NULL, the grant is assumed to be already stored in cfg->grant
|
||
|
*/
|
||
9 years ago
|
int srslte_pdsch_cfg(srslte_pdsch_cfg_t *cfg, srslte_cell_t cell, srslte_ra_dl_grant_t *grant, uint32_t cfi, uint32_t sf_idx, uint32_t rvidx)
|
||
10 years ago
|
{
|
||
9 years ago
|
|
||
|
if (cfg && grant) {
|
||
|
memcpy(&cfg->grant, grant, sizeof(srslte_ra_dl_grant_t));
|
||
10 years ago
|
}
|
||
|
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;
|
||
|
}
|
||
|
srslte_ra_dl_grant_to_nbits(&cfg->grant, cfi, cell, sf_idx, &cfg->nbits);
|
||
|
cfg->sf_idx = sf_idx;
|
||
9 years ago
|
cfg->rv = rvidx;
|
||
|
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
|
}
|
||
|
|
||
|
|
||
10 years ago
|
/* Precalculate the PDSCH scramble sequences for a given RNTI. This function takes a while
|
||
10 years ago
|
* to execute, so shall be called once the final C-RNTI has been allocated for the session.
|
||
|
*/
|
||
10 years ago
|
int srslte_pdsch_set_rnti(srslte_pdsch_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_pdsch(&q->seq[i], rnti, 0, 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
|
}
|
||
11 years ago
|
|
||
10 years ago
|
int srslte_pdsch_decode(srslte_pdsch_t *q,
|
||
|
srslte_pdsch_cfg_t *cfg, srslte_softbuffer_rx_t *softbuffer,
|
||
|
cf_t *sf_symbols, cf_t *ce[SRSLTE_MAX_PORTS], float noise_estimate,
|
||
|
uint8_t *data)
|
||
|
{
|
||
10 years ago
|
if (q != NULL &&
|
||
|
sf_symbols != NULL &&
|
||
|
data != NULL &&
|
||
10 years ago
|
cfg != NULL)
|
||
10 years ago
|
{
|
||
|
if (q->rnti_is_set) {
|
||
10 years ago
|
return srslte_pdsch_decode_rnti(q, cfg, softbuffer, sf_symbols, ce, noise_estimate, q->rnti, data);
|
||
10 years ago
|
} else {
|
||
10 years ago
|
fprintf(stderr, "Must call srslte_pdsch_set_rnti() before calling srslte_pdsch_decode()\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
} else {
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
}
|
||
|
}
|
||
11 years ago
|
|
||
|
/** Decodes the PDSCH from the received symbols
|
||
|
*/
|
||
10 years ago
|
int srslte_pdsch_decode_rnti(srslte_pdsch_t *q,
|
||
|
srslte_pdsch_cfg_t *cfg, srslte_softbuffer_rx_t *softbuffer,
|
||
|
cf_t *sf_symbols, cf_t *ce[SRSLTE_MAX_PORTS], float noise_estimate,
|
||
|
uint16_t rnti, uint8_t *data)
|
||
10 years ago
|
{
|
||
11 years ago
|
|
||
|
/* Set pointers for layermapping & precoding */
|
||
10 years ago
|
uint32_t i, n;
|
||
10 years ago
|
cf_t *x[SRSLTE_MAX_LAYERS];
|
||
11 years ago
|
|
||
10 years ago
|
if (q != NULL &&
|
||
|
sf_symbols != NULL &&
|
||
|
data != NULL &&
|
||
|
cfg != NULL)
|
||
11 years ago
|
{
|
||
|
|
||
9 years ago
|
INFO("Decoding PDSCH SF: %d, RNTI: 0x%x, Mod %s, TBS: %d, NofSymbols: %d, NofBitsE: %d, rv_idx: %d, C_prb=%d\n",
|
||
10 years ago
|
cfg->sf_idx, rnti, srslte_mod_string(cfg->grant.mcs.mod), cfg->grant.mcs.tbs, cfg->nbits.nof_re,
|
||
9 years ago
|
cfg->nbits.nof_bits, cfg->rv, cfg->grant.nof_prb);
|
||
10 years ago
|
|
||
10 years ago
|
/* number of layers equals number of ports */
|
||
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
10 years ago
|
x[i] = q->x[i];
|
||
10 years ago
|
}
|
||
10 years ago
|
memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports));
|
||
10 years ago
|
|
||
|
/* extract symbols */
|
||
10 years ago
|
n = srslte_pdsch_get(q, sf_symbols, q->symbols[0], &cfg->grant, cfg->nbits.lstart, cfg->sf_idx);
|
||
|
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 */
|
||
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
10 years ago
|
n = srslte_pdsch_get(q, ce[i], q->ce[i], &cfg->grant, cfg->nbits.lstart, cfg->sf_idx);
|
||
|
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;
|
||
11 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
/* TODO: only diversity is supported */
|
||
|
if (q->cell.nof_ports == 1) {
|
||
|
/* no need for layer demapping */
|
||
9 years ago
|
srslte_predecoding_single(q->symbols[0], q->ce[0], q->d, cfg->nbits.nof_re, noise_estimate);
|
||
11 years ago
|
} else {
|
||
9 years ago
|
srslte_predecoding_diversity(q->symbols[0], q->ce, x, q->cell.nof_ports,
|
||
|
cfg->nbits.nof_re);
|
||
10 years ago
|
srslte_layerdemap_diversity(x, q->d, q->cell.nof_ports,
|
||
10 years ago
|
cfg->nbits.nof_re / q->cell.nof_ports);
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||
9 years ago
|
DEBUG("SAVED FILE pdsch_symbols.dat: symbols after equalization\n",0);
|
||
|
srslte_vec_save_file("pdsch_symbols.dat", q->d, cfg->nbits.nof_re*sizeof(cf_t));
|
||
9 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_s(cfg->grant.mcs.mod, q->d, q->e, cfg->nbits.nof_re);
|
||
9 years ago
|
|
||
9 years ago
|
/*
|
||
|
printf("WARNING REMOVE ME!\n");
|
||
|
int16_t *e=q->e;
|
||
|
for (int i=0;i<cfg->nbits.nof_bits;i++) {
|
||
|
e[i] = e[i]>0?10:-10;
|
||
|
}
|
||
|
*/
|
||
|
|
||
10 years ago
|
/* descramble */
|
||
|
if (rnti != q->rnti) {
|
||
10 years ago
|
srslte_sequence_t seq;
|
||
10 years ago
|
if (srslte_sequence_pdsch(&seq, rnti, 0, 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_s_offset(&seq, q->e, 0, cfg->nbits.nof_bits);
|
||
10 years ago
|
srslte_sequence_free(&seq);
|
||
10 years ago
|
} else {
|
||
9 years ago
|
srslte_scrambling_s_offset(&q->seq[cfg->sf_idx], q->e, 0, cfg->nbits.nof_bits);
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
if (SRSLTE_VERBOSE_ISDEBUG()) {
|
||
|
DEBUG("SAVED FILE llr.dat: LLR estimates after demodulation and descrambling\n",0);
|
||
|
srslte_vec_save_file("llr.dat", q->e, cfg->nbits.nof_bits*sizeof(int16_t));
|
||
|
}
|
||
|
|
||
10 years ago
|
return srslte_dlsch_decode(&q->dl_sch, cfg, softbuffer, q->e, data);
|
||
10 years ago
|
|
||
11 years ago
|
} else {
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_pdsch_encode(srslte_pdsch_t *q,
|
||
|
srslte_pdsch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
|
||
|
uint8_t *data, cf_t *sf_symbols[SRSLTE_MAX_PORTS])
|
||
10 years ago
|
{
|
||
10 years ago
|
if (q != NULL &&
|
||
|
data != NULL &&
|
||
|
cfg != NULL)
|
||
10 years ago
|
{
|
||
|
if (q->rnti_is_set) {
|
||
10 years ago
|
return srslte_pdsch_encode_rnti(q, cfg, softbuffer, data, q->rnti, sf_symbols);
|
||
10 years ago
|
} else {
|
||
10 years ago
|
fprintf(stderr, "Must call srslte_pdsch_set_rnti() to set the encoder/decoder RNTI\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
} else {
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
}
|
||
|
}
|
||
11 years ago
|
|
||
|
/** Converts the PDSCH data bits to symbols mapped to the slot ready for transmission
|
||
|
*/
|
||
10 years ago
|
int srslte_pdsch_encode_rnti(srslte_pdsch_t *q,
|
||
|
srslte_pdsch_cfg_t *cfg, srslte_softbuffer_tx_t *softbuffer,
|
||
|
uint8_t *data, uint16_t rnti, cf_t *sf_symbols[SRSLTE_MAX_PORTS])
|
||
10 years ago
|
{
|
||
11 years ago
|
int i;
|
||
|
/* Set pointers for layermapping & precoding */
|
||
10 years ago
|
cf_t *x[SRSLTE_MAX_LAYERS];
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
|
||
10 years ago
|
if (q != NULL &&
|
||
11 years ago
|
data != NULL &&
|
||
10 years ago
|
cfg != NULL)
|
||
11 years ago
|
{
|
||
11 years ago
|
|
||
10 years ago
|
for (i=0;i<q->cell.nof_ports;i++) {
|
||
|
if (sf_symbols[i] == NULL) {
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
if (cfg->grant.mcs.tbs == 0) {
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
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). PDSCH 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
|
}
|
||
11 years ago
|
|
||
10 years ago
|
INFO("Encoding PDSCH SF: %d, Mod %s, NofBits: %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_bits, cfg->rv);
|
||
11 years ago
|
|
||
10 years ago
|
/* number of layers equals number of ports */
|
||
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
10 years ago
|
x[i] = q->x[i];
|
||
10 years ago
|
}
|
||
10 years ago
|
memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (SRSLTE_MAX_LAYERS - q->cell.nof_ports));
|
||
11 years ago
|
|
||
10 years ago
|
if (srslte_dlsch_encode(&q->dl_sch, cfg, softbuffer, data, q->e)) {
|
||
10 years ago
|
fprintf(stderr, "Error encoding TB\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
|
|
||
|
if (rnti != q->rnti) {
|
||
10 years ago
|
srslte_sequence_t seq;
|
||
10 years ago
|
if (srslte_sequence_pdsch(&seq, rnti, 0, 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->e, 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->e, cfg->nbits.nof_bits);
|
||
10 years ago
|
}
|
||
11 years ago
|
|
||
9 years ago
|
srslte_mod_modulate_bytes(&q->mod[cfg->grant.mcs.mod], (uint8_t*) q->e, q->d, cfg->nbits.nof_bits);
|
||
|
|
||
10 years ago
|
/* TODO: only diversity supported */
|
||
|
if (q->cell.nof_ports > 1) {
|
||
10 years ago
|
srslte_layermap_diversity(q->d, x, q->cell.nof_ports, cfg->nbits.nof_re);
|
||
9 years ago
|
srslte_precoding_diversity(x, q->symbols, q->cell.nof_ports,
|
||
10 years ago
|
cfg->nbits.nof_re / q->cell.nof_ports);
|
||
11 years ago
|
} else {
|
||
10 years ago
|
memcpy(q->symbols[0], q->d, cfg->nbits.nof_re * sizeof(cf_t));
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
|
/* mapping to resource elements */
|
||
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
10 years ago
|
srslte_pdsch_put(q, q->symbols[i], sf_symbols[i], &cfg->grant, cfg->nbits.lstart, cfg->sf_idx);
|
||
10 years ago
|
}
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
9 years ago
|
|
||
|
float srslte_pdsch_average_noi(srslte_pdsch_t *q)
|
||
|
{
|
||
|
return q->dl_sch.average_nof_iterations;
|
||
|
}
|
||
|
|
||
|
uint32_t srslte_pdsch_last_noi(srslte_pdsch_t *q) {
|
||
|
return q->dl_sch.nof_iterations;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
9 years ago
|
|