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.
284 lines
8.0 KiB
C
284 lines
8.0 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2013-2014 The libLTE Developers. See the
|
||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
|
* This file is part of the libLTE library.
|
||
|
*
|
||
|
* libLTE is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Lesser General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
|
* libLTE 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
|
||
|
* GNU Lesser General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Lesser 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>
|
||
|
|
||
10 years ago
|
#include "srslte/phy/phch/regs.h"
|
||
|
#include "srslte/phy/phch/pcfich.h"
|
||
|
#include "srslte/phy/common/phy_common.h"
|
||
|
#include "srslte/phy/utils/bit.h"
|
||
|
#include "srslte/phy/utils/vector.h"
|
||
|
#include "srslte/phy/utils/debug.h"
|
||
11 years ago
|
|
||
|
// Table 5.3.4-1
|
||
10 years ago
|
static uint8_t cfi_table[4][PCFICH_CFI_LEN] = {
|
||
|
{ 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1,
|
||
|
1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 },
|
||
|
{ 1, 0, 1,
|
||
11 years ago
|
1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
|
||
10 years ago
|
0, 1, 1, 0 },
|
||
|
{ 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
|
||
|
0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 },
|
||
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||
11 years ago
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } // reserved
|
||
11 years ago
|
};
|
||
|
|
||
|
bool pcfich_exists(int nframe, int nslot) {
|
||
11 years ago
|
return true;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/** Initializes the pcfich channel receiver.
|
||
|
* On error, returns -1 and frees the structrure
|
||
|
*/
|
||
|
int pcfich_init(pcfich_t *q, regs_t *regs, lte_cell_t cell) {
|
||
|
int ret = LIBLTE_ERROR_INVALID_INPUTS;
|
||
|
|
||
|
if (q != NULL &&
|
||
|
regs != NULL &&
|
||
|
lte_cell_isvalid(&cell))
|
||
|
{
|
||
|
ret = LIBLTE_ERROR;
|
||
|
|
||
|
bzero(q, sizeof(pcfich_t));
|
||
|
q->cell = cell;
|
||
|
q->regs = regs;
|
||
10 years ago
|
q->nof_symbols = PCFICH_RE;
|
||
10 years ago
|
|
||
|
if (precoding_init(&q->precoding, SF_LEN_RE(cell.nof_prb, cell.cp))) {
|
||
|
fprintf(stderr, "Error initializing precoding\n");
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
if (modem_table_lte(&q->mod, LTE_QPSK, true)) {
|
||
11 years ago
|
goto clean;
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
demod_soft_init(&q->demod, q->nof_symbols);
|
||
10 years ago
|
demod_soft_table_set(&q->demod, &q->mod);
|
||
|
demod_soft_alg_set(&q->demod, APPROX);
|
||
11 years ago
|
|
||
11 years ago
|
for (int nsf = 0; nsf < NSUBFRAMES_X_FRAME; nsf++) {
|
||
|
if (sequence_pcfich(&q->seq_pcfich[nsf], 2 * nsf, q->cell.id)) {
|
||
|
goto clean;
|
||
|
}
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
|
/* convert cfi bit tables to floats for demodulation */
|
||
|
for (int i=0;i<3;i++) {
|
||
|
for (int j=0;j<PCFICH_CFI_LEN;j++) {
|
||
|
q->cfi_table_float[i][j] = (float) 2.0*cfi_table[i][j]-1.0;
|
||
|
}
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
ret = LIBLTE_SUCCESS;
|
||
|
}
|
||
|
|
||
|
clean:
|
||
|
if (ret == LIBLTE_ERROR) {
|
||
11 years ago
|
pcfich_free(q);
|
||
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
|
|
||
|
void pcfich_free(pcfich_t *q) {
|
||
11 years ago
|
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
|
||
11 years ago
|
sequence_free(&q->seq_pcfich[ns]);
|
||
|
}
|
||
|
modem_table_free(&q->mod);
|
||
10 years ago
|
precoding_free(&q->precoding);
|
||
10 years ago
|
demod_soft_free(&q->demod);
|
||
10 years ago
|
|
||
|
bzero(q, sizeof(pcfich_t));
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Finds the CFI with minimum distance with the vector of received 32 bits.
|
||
|
* Saves the CFI value in the cfi pointer and returns the distance.
|
||
|
*/
|
||
10 years ago
|
float pcfich_cfi_decode(pcfich_t *q, uint32_t *cfi) {
|
||
|
int i;
|
||
|
int index = 0;
|
||
|
float max_corr = 0;
|
||
|
|
||
11 years ago
|
for (i = 0; i < 3; i++) {
|
||
10 years ago
|
float corr = fabsf(vec_dot_prod_fff(q->cfi_table_float[i], q->data_f, PCFICH_CFI_LEN));
|
||
10 years ago
|
if (corr > max_corr) {
|
||
|
max_corr = corr;
|
||
|
index = i;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
if (cfi) {
|
||
11 years ago
|
*cfi = index + 1;
|
||
11 years ago
|
}
|
||
10 years ago
|
return max_corr;
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Encodes the CFI producing a vector of 32 bits.
|
||
|
* 36.211 10.3 section 5.3.4
|
||
|
*/
|
||
10 years ago
|
int pcfich_cfi_encode(int cfi, uint8_t bits[PCFICH_CFI_LEN]) {
|
||
11 years ago
|
if (cfi < 1 || cfi > 3) {
|
||
11 years ago
|
return LIBLTE_ERROR_INVALID_INPUTS;
|
||
|
} else{
|
||
10 years ago
|
memcpy(bits, cfi_table[cfi - 1], PCFICH_CFI_LEN * sizeof(uint8_t));
|
||
11 years ago
|
return LIBLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
/* Decodes the PCFICH channel and saves the CFI in the cfi pointer.
|
||
|
*
|
||
|
* Returns 1 if successfully decoded the CFI, 0 if not and -1 on error
|
||
|
*/
|
||
10 years ago
|
int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS], float noise_estimate,
|
||
10 years ago
|
uint32_t nsubframe, uint32_t *cfi, float *corr_result)
|
||
|
{
|
||
11 years ago
|
|
||
|
/* Set pointers for layermapping & precoding */
|
||
|
int i;
|
||
|
cf_t *x[MAX_LAYERS];
|
||
|
cf_t *ce_precoding[MAX_PORTS];
|
||
|
|
||
11 years ago
|
if (q != NULL &&
|
||
|
slot_symbols != NULL &&
|
||
|
nsubframe < NSUBFRAMES_X_FRAME)
|
||
|
{
|
||
11 years ago
|
|
||
11 years ago
|
/* number of layers equals number of ports */
|
||
|
for (i = 0; i < MAX_PORTS; i++) {
|
||
|
x[i] = q->pcfich_x[i];
|
||
|
}
|
||
|
for (i = 0; i < MAX_PORTS; i++) {
|
||
|
ce_precoding[i] = q->ce[i];
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* extract symbols */
|
||
|
if (q->nof_symbols
|
||
|
!= regs_pcfich_get(q->regs, slot_symbols, q->pcfich_symbols[0])) {
|
||
11 years ago
|
fprintf(stderr, "There was an error getting the PCFICH symbols\n");
|
||
11 years ago
|
return LIBLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/* extract channel estimates */
|
||
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
|
if (q->nof_symbols != regs_pcfich_get(q->regs, ce[i], q->ce[i])) {
|
||
|
fprintf(stderr, "There was an error getting the PCFICH symbols\n");
|
||
|
return LIBLTE_ERROR;
|
||
|
}
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* in control channels, only diversity is supported */
|
||
|
if (q->cell.nof_ports == 1) {
|
||
|
/* no need for layer demapping */
|
||
10 years ago
|
predecoding_single(&q->precoding, q->pcfich_symbols[0], q->ce[0], q->pcfich_d,
|
||
10 years ago
|
q->nof_symbols, noise_estimate);
|
||
11 years ago
|
} else {
|
||
10 years ago
|
predecoding_diversity(&q->precoding, q->pcfich_symbols[0], ce_precoding, x,
|
||
|
q->cell.nof_ports, q->nof_symbols, noise_estimate);
|
||
11 years ago
|
layerdemap_diversity(x, q->pcfich_d, q->cell.nof_ports,
|
||
|
q->nof_symbols / q->cell.nof_ports);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* demodulate symbols */
|
||
10 years ago
|
demod_soft_sigma_set(&q->demod, 1.0);
|
||
|
demod_soft_demodulate(&q->demod, q->pcfich_d, q->data_f, q->nof_symbols);
|
||
11 years ago
|
|
||
11 years ago
|
/* Scramble with the sequence for slot nslot */
|
||
10 years ago
|
scrambling_f(&q->seq_pcfich[nsubframe], q->data_f);
|
||
11 years ago
|
|
||
|
/* decode CFI */
|
||
10 years ago
|
float corr = pcfich_cfi_decode(q, cfi);
|
||
|
if (corr_result) {
|
||
|
*corr_result = corr;
|
||
11 years ago
|
}
|
||
10 years ago
|
return 1;
|
||
11 years ago
|
} else {
|
||
11 years ago
|
return LIBLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Encodes CFI and maps symbols to the slot
|
||
|
*/
|
||
11 years ago
|
int pcfich_encode(pcfich_t *q, uint32_t cfi, cf_t *slot_symbols[MAX_PORTS],
|
||
|
uint32_t subframe) {
|
||
11 years ago
|
int i;
|
||
|
|
||
11 years ago
|
if (q != NULL &&
|
||
|
cfi < 3 &&
|
||
|
slot_symbols != NULL &&
|
||
|
subframe < NSUBFRAMES_X_FRAME)
|
||
|
{
|
||
11 years ago
|
|
||
11 years ago
|
/* Set pointers for layermapping & precoding */
|
||
|
cf_t *x[MAX_LAYERS];
|
||
|
cf_t *symbols_precoding[MAX_PORTS];
|
||
11 years ago
|
|
||
11 years ago
|
/* number of layers equals number of ports */
|
||
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
|
x[i] = q->pcfich_x[i];
|
||
|
}
|
||
|
for (i = 0; i < MAX_PORTS; i++) {
|
||
|
symbols_precoding[i] = q->pcfich_symbols[i];
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* pack CFI */
|
||
|
pcfich_cfi_encode(cfi, q->data);
|
||
11 years ago
|
|
||
11 years ago
|
/* scramble for slot sequence nslot */
|
||
|
scrambling_b(&q->seq_pcfich[subframe], q->data);
|
||
11 years ago
|
|
||
11 years ago
|
mod_modulate(&q->mod, q->data, q->pcfich_d, PCFICH_CFI_LEN);
|
||
11 years ago
|
|
||
11 years ago
|
/* layer mapping & precoding */
|
||
|
if (q->cell.nof_ports > 1) {
|
||
|
layermap_diversity(q->pcfich_d, x, q->cell.nof_ports, q->nof_symbols);
|
||
10 years ago
|
precoding_diversity(&q->precoding, x, symbols_precoding, q->cell.nof_ports,
|
||
11 years ago
|
q->nof_symbols / q->cell.nof_ports);
|
||
|
} else {
|
||
|
memcpy(q->pcfich_symbols[0], q->pcfich_d, q->nof_symbols * sizeof(cf_t));
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* mapping to resource elements */
|
||
|
for (i = 0; i < q->cell.nof_ports; i++) {
|
||
|
if (regs_pcfich_put(q->regs, q->pcfich_symbols[i], slot_symbols[i]) < 0) {
|
||
|
fprintf(stderr, "Error putting PCHICH resource elements\n");
|
||
|
return LIBLTE_ERROR;
|
||
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
return LIBLTE_SUCCESS;
|
||
|
} else {
|
||
|
return LIBLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
|