srsLTE/srslte/lib/phch/src/pucch.c

206 lines
5.5 KiB
C
Raw Normal View History

2015-03-17 10:26:23 -07:00
/**
*
* \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>
#include "srslte/phch/pucch.h"
#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"
2015-03-18 11:14:24 -07:00
#include "srslte/dft/dft_precoding.h"
2015-03-17 10:26:23 -07:00
2015-03-18 05:59:29 -07:00
#define MAX_PUSCH_RE(cp) (2 * SRSLTE_CP_NSYMB(cp) * 12)
2015-03-17 10:26:23 -07:00
2015-03-18 11:14:24 -07:00
bool srslte_pucch_cfg_isvalid(srslte_pucch_cfg_t *cfg) {
2015-03-17 10:26:23 -07:00
return true;
}
/* Generates n_cs_cell according to Sec 5.4 of 36.211 */
2015-03-18 11:14:24 -07:00
int srslte_generate_n_cs_cell(srslte_cell_t cell, uint32_t n_cs_cell[SRSLTE_NSLOTS_X_FRAME][SRSLTE_SRSLTE_SRSLTE_CP_NORM_NSYMB])
2015-03-17 10:26:23 -07:00
{
2015-03-18 08:05:38 -07:00
srslte_sequence_t seq;
bzero(&seq, sizeof(srslte_sequence_t));
2015-03-17 10:26:23 -07:00
2015-03-18 08:05:38 -07:00
srslte_sequence_LTE_pr(&seq, 8*SRSLTE_CP_NSYMB(cell.cp)*SRSLTE_NSLOTS_X_FRAME, cell.id);
2015-03-17 10:26:23 -07:00
2015-03-18 05:41:50 -07:00
for (uint32_t ns=0;ns<SRSLTE_NSLOTS_X_FRAME;ns++) {
2015-03-18 05:59:29 -07:00
for (uint32_t l=0;l<SRSLTE_CP_NSYMB(cell.cp);l++) {
2015-03-17 10:26:23 -07:00
n_cs_cell[ns][l] = 0;
for (uint32_t i=0;i<8;i++) {
2015-03-18 05:59:29 -07:00
n_cs_cell[ns][l] += seq.c[8*SRSLTE_CP_NSYMB(cell.cp)*ns+8*l+i]<<i;
2015-03-17 10:26:23 -07:00
}
}
}
2015-03-18 08:05:38 -07:00
srslte_sequence_free(&seq);
return SRSLTE_SUCCESS;
2015-03-17 10:26:23 -07:00
}
/* Calculates alpha according to 5.5.2.2.2 of 36.211 */
2015-03-18 11:14:24 -07:00
float srslte_pucch_get_alpha(uint32_t n_cs_cell[SRSLTE_NSLOTS_X_FRAME][SRSLTE_SRSLTE_SRSLTE_CP_NORM_NSYMB],
srslte_pucch_cfg_t *cfg,
2015-03-18 05:41:50 -07:00
srslte_cp_t cp, bool is_drms,
2015-03-17 10:26:23 -07:00
uint32_t ns, uint32_t l,
uint32_t *n_oc_ptr)
{
2015-03-18 05:59:29 -07:00
uint32_t c = SRSLTE_CP_ISNORM(cp)?3:2;
2015-03-17 10:26:23 -07:00
uint32_t N_prime = (cfg->n_pucch < c*cfg->N_cs/cfg->delta_pucch_shift)?cfg->N_cs:12;
uint32_t n_prime = cfg->n_pucch;
if (cfg->n_pucch >= c*cfg->N_cs/cfg->delta_pucch_shift) {
n_prime = (cfg->n_pucch-c*cfg->N_cs/cfg->delta_pucch_shift)%(cfg->N_cs/cfg->delta_pucch_shift);
}
2015-03-18 05:59:29 -07:00
uint32_t n_oc_div = (!is_drms && SRSLTE_CP_ISEXT(cp))?2:1;
2015-03-17 10:26:23 -07:00
uint32_t n_oc = n_prime*cfg->delta_pucch_shift/N_prime;
2015-03-18 05:59:29 -07:00
if (!is_drms && SRSLTE_CP_ISEXT(cp)) {
2015-03-17 10:26:23 -07:00
n_oc *= 2;
}
if (n_oc_ptr) {
*n_oc_ptr = n_oc;
}
uint32_t n_cs = 0;
2015-03-18 05:59:29 -07:00
if (SRSLTE_CP_ISNORM(cp)) {
2015-03-17 10:26:23 -07:00
n_cs = (n_cs_cell[ns][l]+(n_prime*cfg->delta_pucch_shift+(n_oc%cfg->delta_pucch_shift))%N_prime)%12;
} else {
n_cs = (n_cs_cell[ns][l]+(n_prime*cfg->delta_pucch_shift+n_oc/n_oc_div)%N_prime)%12;
}
return 2 * M_PI * (n_cs) / 12;
}
2015-03-18 11:14:24 -07:00
int pucch_cp(srslte_pucch_t *q, srslte_harq_t *harq, cf_t *input, cf_t *output, bool advance_input)
2015-03-17 10:26:23 -07:00
{
return SRSLTE_ERROR;
2015-03-17 10:26:23 -07:00
}
2015-03-18 11:14:24 -07:00
int pucch_put(srslte_pucch_t *q, srslte_harq_t *harq, cf_t *input, cf_t *output) {
2015-03-17 10:26:23 -07:00
return pucch_cp(q, harq, input, output, true);
}
2015-03-18 11:14:24 -07:00
int pucch_get(srslte_pucch_t *q, srslte_harq_t *harq, cf_t *input, cf_t *output) {
2015-03-17 10:26:23 -07:00
return pucch_cp(q, harq, input, output, false);
}
/** Initializes the PDCCH transmitter and receiver */
2015-03-18 11:14:24 -07:00
int srslte_pucch_init(srslte_pucch_t *q, srslte_cell_t cell) {
int ret = SRSLTE_ERROR_INVALID_INPUTS;
2015-03-18 05:59:29 -07:00
if (q != NULL && srslte_cell_isvalid(&cell)) {
ret = SRSLTE_ERROR;
2015-03-18 11:14:24 -07:00
bzero(q, sizeof(srslte_pucch_t));
2015-03-17 10:26:23 -07:00
q->cell = cell;
2015-03-18 11:14:24 -07:00
if (srslte_generate_n_cs_cell(q->cell, q->n_cs_cell)) {
return SRSLTE_ERROR;
2015-03-17 10:26:23 -07:00
}
ret = SRSLTE_SUCCESS;
2015-03-17 10:26:23 -07:00
}
return ret;
}
2015-03-18 11:14:24 -07:00
void srslte_pucch_free(srslte_pucch_t *q) {
bzero(q, sizeof(srslte_pucch_t));
2015-03-17 10:26:23 -07:00
}
/** Decodes the PUSCH from the received symbols
*/
2015-03-18 11:14:24 -07:00
int pucch_decode(srslte_pucch_t *q, srslte_harq_t *harq, cf_t *sf_symbols, cf_t *ce, float noise_estimate, uint8_t *data)
2015-03-17 10:26:23 -07:00
{
return SRSLTE_ERROR_INVALID_INPUTS;
2015-03-17 10:26:23 -07:00
}
static cf_t uci_encode_format1() {
return 1.0;
}
static cf_t uci_encode_format1a(uint8_t bit) {
return bit?1.0:-1.0;
}
static cf_t uci_encode_format1b(uint8_t bits[2]) {
if (bits[0] == 0) {
if (bits[1] == 0) {
return 1;
} else {
return -I;
}
} else {
if (bits[1] == 0) {
return I;
} else {
return -1.0;
}
}
}
2015-03-18 11:14:24 -07:00
static void uci_mod_bits(srslte_pucch_t *q, srslte_pucch_cfg_t *cfg, uint8_t bits[SRSLTE_PUCCH_MAX_BITS])
2015-03-17 10:26:23 -07:00
{
cf_t d_0 = 0;
uint8_t tmp[2];
switch(cfg->format) {
2015-03-18 11:14:24 -07:00
case SRSLTE_PUCCH_FORMAT_1:
2015-03-17 10:26:23 -07:00
d_0 = uci_encode_format1();
break;
2015-03-18 11:14:24 -07:00
case SRSLTE_PUCCH_FORMAT_1A:
2015-03-17 10:26:23 -07:00
d_0 = uci_encode_format1a(bits[0]);
break;
2015-03-18 11:14:24 -07:00
case SRSLTE_PUCCH_FORMAT_1B:
2015-03-17 10:26:23 -07:00
tmp[0] = bits[0];
tmp[1] = bits[1];
d_0 = uci_encode_format1b(tmp);
default:
fprintf(stderr, "PUCCH format 2 not supported\n");
return;
}
/*
2015-03-18 11:14:24 -07:00
for (uint32_t n=0;n<SRSLTE_PUCCH_N_SEQ;n++) {
2015-03-17 10:26:23 -07:00
q->y[n] = d_0+
}
*/
}
2015-03-18 11:14:24 -07:00
int srslte_pucch_encode(srslte_pucch_t *q, srslte_pucch_cfg_t *cfg, uint8_t bits[SRSLTE_PUCCH_MAX_BITS], cf_t *sf_symbols)
2015-03-17 10:26:23 -07:00
{
uci_mod_bits(q, cfg, bits);
return SRSLTE_ERROR;
2015-03-17 10:26:23 -07:00
}