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.
815 lines
21 KiB
C
815 lines
21 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 <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <math.h>
|
||
|
|
||
10 years ago
|
#include "srslte/common/phy_common.h"
|
||
|
#include "srslte/phch/regs.h"
|
||
|
#include "srslte/utils/debug.h"
|
||
11 years ago
|
|
||
10 years ago
|
#define REG_IDX(r, i, n) r->k[i]+r->l*n*SRSLTE_NRE
|
||
11 years ago
|
|
||
|
|
||
10 years ago
|
srslte_regs_reg_t *regs_find_reg(srslte_regs_t *h, uint32_t k, uint32_t l);
|
||
|
int regs_put_reg(srslte_regs_reg_t *reg,
|
||
11 years ago
|
cf_t *reg_data,
|
||
|
cf_t *slot_symbols,
|
||
11 years ago
|
uint32_t nof_prb);
|
||
11 years ago
|
|
||
10 years ago
|
int regs_add_reg(srslte_regs_reg_t *reg,
|
||
11 years ago
|
cf_t *reg_data,
|
||
|
cf_t *slot_symbols,
|
||
11 years ago
|
uint32_t nof_prb);
|
||
11 years ago
|
|
||
10 years ago
|
int regs_get_reg(srslte_regs_reg_t *reg,
|
||
11 years ago
|
cf_t *slot_symbols,
|
||
|
cf_t *reg_data,
|
||
11 years ago
|
uint32_t nof_prb);
|
||
11 years ago
|
|
||
10 years ago
|
int regs_reset_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, uint32_t nof_prb);
|
||
11 years ago
|
|
||
|
|
||
|
/***************************************************************
|
||
|
*
|
||
|
* PDCCH REG ALLOCATION
|
||
|
*
|
||
|
***************************************************************/
|
||
|
|
||
10 years ago
|
void regs_pdcch_free(srslte_regs_t *h) {
|
||
11 years ago
|
int i;
|
||
|
for (i=0;i<3;i++) {
|
||
|
if (h->pdcch[i].regs) {
|
||
|
free(h->pdcch[i].regs);
|
||
10 years ago
|
h->pdcch[i].regs = NULL;
|
||
11 years ago
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
#define PDCCH_NCOLS 32
|
||
10 years ago
|
const uint8_t PDCCH_PERM[PDCCH_NCOLS] =
|
||
11 years ago
|
{ 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, 0, 16, 8,
|
||
|
24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 };
|
||
11 years ago
|
|
||
11 years ago
|
/** Initialize REGs for PDCCH
|
||
|
* 36.211 10.3 section 6.8.5
|
||
|
*/
|
||
10 years ago
|
int regs_pdcch_init(srslte_regs_t *h) {
|
||
11 years ago
|
int i, m, cfi, nof_ctrl_symbols;
|
||
10 years ago
|
int ret = SRSLTE_ERROR;
|
||
11 years ago
|
int nrows, ndummy, j;
|
||
|
uint32_t k, kp;
|
||
10 years ago
|
srslte_regs_reg_t **tmp = NULL;
|
||
11 years ago
|
|
||
10 years ago
|
bzero(&h->pdcch, sizeof(srslte_regs_ch_t));
|
||
11 years ago
|
|
||
|
for (cfi=0;cfi<3;cfi++) {
|
||
11 years ago
|
if (h->cell.nof_prb < 10) {
|
||
11 years ago
|
nof_ctrl_symbols = cfi+2;
|
||
|
} else {
|
||
|
nof_ctrl_symbols = cfi+1;
|
||
|
}
|
||
|
|
||
10 years ago
|
tmp = malloc(sizeof(srslte_regs_reg_t*) * h->nof_regs);
|
||
11 years ago
|
if (!tmp) {
|
||
|
perror("malloc");
|
||
|
goto clean_and_exit;
|
||
|
}
|
||
|
|
||
|
/* Number and count REGs for this CFI */
|
||
|
m=0;
|
||
|
for (i=0;i<h->nof_regs;i++) {
|
||
|
if (h->regs[i].l < nof_ctrl_symbols && !h->regs[i].assigned) {
|
||
|
tmp[m] = &h->regs[i];
|
||
|
m++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
h->pdcch[cfi].nof_regs = m;
|
||
10 years ago
|
|
||
10 years ago
|
h->pdcch[cfi].regs = malloc(sizeof(srslte_regs_reg_t*) * h->pdcch[cfi].nof_regs);
|
||
11 years ago
|
if (!h->pdcch[cfi].regs) {
|
||
|
perror("malloc");
|
||
|
goto clean_and_exit;
|
||
|
}
|
||
|
|
||
|
/* Interleave REGs */
|
||
|
nrows = (h->pdcch[cfi].nof_regs-1)/PDCCH_NCOLS+1;
|
||
|
ndummy = PDCCH_NCOLS*nrows - h->pdcch[cfi].nof_regs;
|
||
|
if (ndummy < 0) {
|
||
|
ndummy = 0;
|
||
|
}
|
||
|
|
||
|
k=0;
|
||
|
for (j = 0; j < PDCCH_NCOLS; j++) {
|
||
|
for (i = 0; i < nrows; i++) {
|
||
|
if (i*PDCCH_NCOLS + PDCCH_PERM[j] >= ndummy) {
|
||
|
m = i*PDCCH_NCOLS + PDCCH_PERM[j]-ndummy;
|
||
11 years ago
|
if (k < h->cell.id) {
|
||
9 years ago
|
kp = (h->pdcch[cfi].nof_regs + k-(h->cell.id%h->pdcch[cfi].nof_regs))%h->pdcch[cfi].nof_regs;
|
||
11 years ago
|
} else {
|
||
|
kp = (k-h->cell.id)%h->pdcch[cfi].nof_regs;
|
||
11 years ago
|
}
|
||
|
h->pdcch[cfi].regs[m] = tmp[kp];
|
||
|
k++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
h->pdcch[cfi].nof_regs = (h->pdcch[cfi].nof_regs/9)*9;
|
||
10 years ago
|
INFO("Init PDCCH REG space CFI %d. %d useful REGs (%d CCEs)\n",cfi+1,
|
||
|
h->pdcch[cfi].nof_regs, h->pdcch[cfi].nof_regs/9);
|
||
11 years ago
|
free(tmp);
|
||
|
tmp = NULL;
|
||
|
}
|
||
|
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
11 years ago
|
clean_and_exit:
|
||
11 years ago
|
if (tmp) {
|
||
|
free(tmp);
|
||
|
}
|
||
10 years ago
|
if (ret == SRSLTE_ERROR) {
|
||
11 years ago
|
regs_pdcch_free(h);
|
||
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_regs_pdcch_nregs(srslte_regs_t *h, uint32_t cfi) {
|
||
11 years ago
|
if (cfi < 1 || cfi > 3) {
|
||
|
fprintf(stderr, "Invalid CFI=%d\n", cfi);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
} else {
|
||
11 years ago
|
return (int) h->pdcch[cfi-1].nof_regs;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Copy quadruplets to REGs and cyclic shift them, according to the
|
||
|
* second part of 6.8.5 in 36.211
|
||
|
*/
|
||
11 years ago
|
|
||
10 years ago
|
int srslte_regs_pdcch_put_offset(srslte_regs_t *h, cf_t *d, cf_t *slot_symbols, uint32_t start_reg, uint32_t nof_regs) {
|
||
11 years ago
|
if (h->cfi_initiated) {
|
||
|
if (start_reg + nof_regs <= h->pdcch[h->cfi].nof_regs) {
|
||
|
uint32_t i, k;
|
||
|
k = 0;
|
||
|
for (i=start_reg;i<start_reg+nof_regs;i++) {
|
||
10 years ago
|
regs_put_reg(h->pdcch[h->cfi].regs[i], &d[k], slot_symbols, h->cell.nof_prb);
|
||
11 years ago
|
k += 4;
|
||
|
}
|
||
|
return k;
|
||
|
} else {
|
||
|
fprintf(stderr, "Out of range: start_reg + nof_reg must be lower than %d\n", h->pdcch[h->cfi].nof_regs);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
} else {
|
||
10 years ago
|
fprintf(stderr, "Must call srslte_regs_set_cfi() first\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_regs_pdcch_put(srslte_regs_t *h, cf_t *d, cf_t *slot_symbols) {
|
||
|
return srslte_regs_pdcch_put_offset(h, d, slot_symbols, 0, h->pdcch[h->cfi].nof_regs);
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_regs_pdcch_get_offset(srslte_regs_t *h, cf_t *slot_symbols, cf_t *d, uint32_t start_reg, uint32_t nof_regs) {
|
||
11 years ago
|
if (h->cfi_initiated) {
|
||
|
if (start_reg + nof_regs <= h->pdcch[h->cfi].nof_regs) {
|
||
|
uint32_t i, k;
|
||
|
k = 0;
|
||
|
for (i=start_reg;i<start_reg + nof_regs;i++) {
|
||
10 years ago
|
regs_get_reg(h->pdcch[h->cfi].regs[i], slot_symbols, &d[k], h->cell.nof_prb);
|
||
11 years ago
|
k += 4;
|
||
|
}
|
||
|
return k;
|
||
|
} else {
|
||
|
fprintf(stderr, "Out of range: start_reg + nof_reg must be lower than %d\n", h->pdcch[h->cfi].nof_regs);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
} else {
|
||
10 years ago
|
fprintf(stderr, "Must call srslte_regs_set_cfi() first\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
10 years ago
|
int srslte_regs_pdcch_get(srslte_regs_t *h, cf_t *slot_symbols, cf_t *d) {
|
||
|
return srslte_regs_pdcch_get_offset(h, slot_symbols, d, 0, h->pdcch[h->cfi].nof_regs);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
|
||
|
|
||
|
|
||
|
/***************************************************************
|
||
|
*
|
||
|
* PHICH REG ALLOCATION
|
||
|
*
|
||
|
***************************************************************/
|
||
|
|
||
|
/** Initialize REGs for PHICH
|
||
|
* 36.211 10.3 section 6.9.3
|
||
|
*/
|
||
10 years ago
|
int regs_phich_init(srslte_regs_t *h) {
|
||
11 years ago
|
float ng;
|
||
11 years ago
|
uint32_t i, ni, li, n[3], nreg, mi;
|
||
10 years ago
|
srslte_regs_reg_t **regs_phich[3];
|
||
10 years ago
|
int ret = SRSLTE_ERROR;
|
||
11 years ago
|
|
||
|
switch(h->phich_res) {
|
||
9 years ago
|
case SRSLTE_PHICH_R_1_6:
|
||
11 years ago
|
ng = (float) 1/6;
|
||
|
break;
|
||
9 years ago
|
case SRSLTE_PHICH_R_1_2:
|
||
11 years ago
|
ng = (float) 1/2;
|
||
|
break;
|
||
10 years ago
|
case SRSLTE_PHICH_R_1:
|
||
11 years ago
|
ng = 1;
|
||
|
break;
|
||
10 years ago
|
case SRSLTE_PHICH_R_2:
|
||
11 years ago
|
ng = 2;
|
||
|
break;
|
||
|
default:
|
||
|
ng = 0;
|
||
|
break;
|
||
|
}
|
||
11 years ago
|
h->ngroups_phich = (int) ceilf(ng * ((float) h->cell.nof_prb/8));
|
||
10 years ago
|
h->phich = malloc(sizeof(srslte_regs_ch_t) * h->ngroups_phich);
|
||
11 years ago
|
if (!h->phich) {
|
||
|
perror("malloc");
|
||
|
return -1;
|
||
|
}
|
||
|
INFO("Creating %d PHICH mapping units. %s length, Ng=%.2f\n",h->ngroups_phich,
|
||
10 years ago
|
h->phich_len==SRSLTE_PHICH_EXT?"Extended":"Normal",ng);
|
||
11 years ago
|
for (i=0;i<h->ngroups_phich;i++) {
|
||
|
h->phich[i].nof_regs = REGS_PHICH_REGS_X_GROUP;
|
||
10 years ago
|
h->phich[i].regs = malloc(sizeof(srslte_regs_reg_t*) * REGS_PHICH_REGS_X_GROUP);
|
||
11 years ago
|
if (!h->phich[i].regs) {
|
||
|
perror("malloc");
|
||
|
goto clean_and_exit;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** Here begins the mapping algorithm */
|
||
|
|
||
|
/* Step 2. Count REGs not assigned to PCFICH */
|
||
|
bzero(n, 3*sizeof(int));
|
||
|
for (i=0;i<h->nof_regs;i++) {
|
||
|
if (h->regs[i].l < 3 && !h->regs[i].assigned) {
|
||
|
n[h->regs[i].l]++;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
bzero(regs_phich, sizeof(srslte_regs_reg_t*) * 3);
|
||
11 years ago
|
for (i=0;i<3;i++) {
|
||
10 years ago
|
regs_phich[i] = malloc(n[i] * sizeof(srslte_regs_reg_t*));
|
||
11 years ago
|
if (!regs_phich[i]) {
|
||
|
perror("malloc");
|
||
|
goto clean_and_exit;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bzero(n, 3 * sizeof(int));
|
||
|
/* Step 3. Number REGs not assigned to PCFICH */
|
||
|
for (i=0;i<h->nof_regs;i++) {
|
||
|
// they are already sorted starting from the REG with the lowest frequency-domain index
|
||
|
if (h->regs[i].l < 3 && !h->regs[i].assigned) {
|
||
|
regs_phich[h->regs[i].l][n[h->regs[i].l]++] = &h->regs[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
nreg=0;
|
||
|
for (mi=0;mi<h->ngroups_phich;mi++) { // here ngroups is the number of mapping units
|
||
|
for (i=0;i<3;i++) {
|
||
10 years ago
|
li=h->phich_len==SRSLTE_PHICH_EXT?i:0; // Step 7
|
||
11 years ago
|
ni=((h->cell.id*n[li]/n[0])+mi+i*n[li]/3) % n[li]; // Step 8
|
||
11 years ago
|
h->phich[mi].regs[i] = regs_phich[li][ni];
|
||
|
h->phich[mi].regs[i]->assigned = true;
|
||
10 years ago
|
DEBUG("Assigned PHICH REG#%d (%d,%d)\n",nreg,h->phich[mi].regs[i]->k0,li);
|
||
11 years ago
|
nreg++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// now the number of mapping units = number of groups for normal cp. For extended cp
|
||
|
// ngroups = 2 * number mapping units
|
||
10 years ago
|
if (SRSLTE_CP_ISEXT(h->cell.cp)) {
|
||
11 years ago
|
h->ngroups_phich *= 2;
|
||
|
}
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
11 years ago
|
|
||
|
clean_and_exit:
|
||
10 years ago
|
if (ret == SRSLTE_ERROR) {
|
||
11 years ago
|
if (h->phich) {
|
||
|
for (i=0;i<h->ngroups_phich;i++) {
|
||
|
if (h->phich[i].regs) {
|
||
|
free(h->phich[i].regs);
|
||
|
}
|
||
|
}
|
||
|
free(h->phich);
|
||
|
}
|
||
|
}
|
||
|
for (i=0;i<3;i++) {
|
||
|
if (regs_phich[i]) {
|
||
|
free(regs_phich[i]);
|
||
|
}
|
||
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void regs_phich_free(srslte_regs_t *h) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
if (h->phich) {
|
||
10 years ago
|
if (SRSLTE_CP_ISEXT(h->cell.cp)) {
|
||
11 years ago
|
h->ngroups_phich /= 2;
|
||
|
}
|
||
|
for (i=0;i<h->ngroups_phich;i++) {
|
||
|
if (h->phich[i].regs) {
|
||
|
free(h->phich[i].regs);
|
||
10 years ago
|
h->phich[i].regs = NULL;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
free(h->phich);
|
||
10 years ago
|
h->phich = NULL;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
uint32_t srslte_regs_phich_nregs(srslte_regs_t *h) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
uint32_t n;
|
||
11 years ago
|
n=0;
|
||
|
for (i=0;i<h->ngroups_phich;i++) {
|
||
|
n += h->phich[i].nof_regs;
|
||
|
}
|
||
|
return n;
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
10 years ago
|
uint32_t srslte_regs_phich_ngroups(srslte_regs_t *h) {
|
||
11 years ago
|
return h->ngroups_phich;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Adds the PHICH symbols to the resource grid pointed by slot_symbols.
|
||
|
*
|
||
10 years ago
|
* Each subframe, the user shall call the srslte_v function before adding PHICH symbols.
|
||
11 years ago
|
*
|
||
|
* Returns the number of written symbols, or -1 on error
|
||
|
*/
|
||
10 years ago
|
int srslte_regs_phich_add(srslte_regs_t *h, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup, cf_t *slot_symbols) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
if (ngroup >= h->ngroups_phich) {
|
||
11 years ago
|
fprintf(stderr, "Error invalid ngroup %d\n", ngroup);
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
10 years ago
|
if (SRSLTE_CP_ISEXT(h->cell.cp)) {
|
||
11 years ago
|
ngroup /= 2;
|
||
|
}
|
||
10 years ago
|
srslte_regs_ch_t *rch = &h->phich[ngroup];
|
||
11 years ago
|
for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PHICH_NSYM; i++) {
|
||
10 years ago
|
regs_add_reg(rch->regs[i], &symbols[i*REGS_RE_X_REG], slot_symbols, h->cell.nof_prb);
|
||
11 years ago
|
}
|
||
|
return i*REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Resets the PHICH symbols
|
||
|
*
|
||
|
* Returns the number of written symbols, or -1 on error
|
||
|
*/
|
||
10 years ago
|
int srslte_regs_phich_reset(srslte_regs_t *h, cf_t *slot_symbols) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
uint32_t ngroup, ng;
|
||
10 years ago
|
for (ngroup = 0;ngroup < h->ngroups_phich;SRSLTE_CP_ISEXT(h->cell.cp)?ngroup+=2:ngroup++) {
|
||
|
if (SRSLTE_CP_ISEXT(h->cell.cp)) {
|
||
11 years ago
|
ng = ngroup/2;
|
||
|
} else {
|
||
|
ng = ngroup;
|
||
|
}
|
||
10 years ago
|
srslte_regs_ch_t *rch = &h->phich[ng];
|
||
11 years ago
|
for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PHICH_NSYM; i++) {
|
||
11 years ago
|
regs_reset_reg(rch->regs[i], slot_symbols, h->cell.nof_prb);
|
||
11 years ago
|
}
|
||
|
}
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets the PHICH symbols from the resource grid pointed by slot_symbols
|
||
|
*
|
||
|
* Returns the number of written symbols, or -1 on error
|
||
|
*/
|
||
10 years ago
|
int srslte_regs_phich_get(srslte_regs_t *h, cf_t *slot_symbols, cf_t symbols[REGS_PHICH_NSYM], uint32_t ngroup) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
if (ngroup >= h->ngroups_phich) {
|
||
11 years ago
|
fprintf(stderr, "Error invalid ngroup %d\n", ngroup);
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
10 years ago
|
if (SRSLTE_CP_ISEXT(h->cell.cp)) {
|
||
11 years ago
|
ngroup /= 2;
|
||
|
}
|
||
10 years ago
|
srslte_regs_ch_t *rch = &h->phich[ngroup];
|
||
11 years ago
|
for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PHICH_NSYM; i++) {
|
||
10 years ago
|
regs_get_reg(rch->regs[i], slot_symbols, &symbols[i*REGS_RE_X_REG], h->cell.nof_prb);
|
||
11 years ago
|
}
|
||
|
return i*REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/***************************************************************
|
||
|
*
|
||
|
* PCFICH REG ALLOCATION
|
||
|
*
|
||
|
***************************************************************/
|
||
|
|
||
|
|
||
|
/** Initialize REGs for PCFICH
|
||
|
* 36.211 10.3 section 6.7.4
|
||
|
*/
|
||
10 years ago
|
int regs_pcfich_init(srslte_regs_t *h) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
uint32_t k_hat, k;
|
||
10 years ago
|
srslte_regs_ch_t *ch = &h->pcfich;
|
||
11 years ago
|
|
||
10 years ago
|
ch->regs = malloc(sizeof(srslte_regs_reg_t*) * REGS_PCFICH_NREGS);
|
||
11 years ago
|
if (!ch->regs) {
|
||
|
perror("malloc");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
ch->nof_regs = REGS_PCFICH_NREGS;
|
||
|
|
||
11 years ago
|
INFO("PCFICH allocating %d regs. CellID: %d, PRB: %d\n", ch->nof_regs, h->cell.id, h->cell.nof_prb);
|
||
11 years ago
|
|
||
10 years ago
|
k_hat = (SRSLTE_NRE / 2) * (h->cell.id % (2 * h->cell.nof_prb));
|
||
11 years ago
|
for (i = 0; i < REGS_PCFICH_NREGS; i++) {
|
||
|
|
||
10 years ago
|
k = (k_hat + (i * h->cell.nof_prb / 2) * (SRSLTE_NRE / 2))
|
||
|
% (h->cell.nof_prb * SRSLTE_NRE);
|
||
11 years ago
|
ch->regs[i] = regs_find_reg(h, k, 0);
|
||
|
if (!ch->regs[i]) {
|
||
|
fprintf(stderr, "Error allocating PCFICH: REG (%d,0) not found\n",
|
||
|
k);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
} else if (ch->regs[i]->assigned) {
|
||
|
fprintf(stderr,
|
||
|
"Error allocating PCFICH: REG (%d,0) already allocated\n",
|
||
|
k);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
} else {
|
||
10 years ago
|
ch->regs[i]->assigned = true;
|
||
10 years ago
|
DEBUG("Assigned PCFICH REG#%d (%d,0)\n", i, k);
|
||
11 years ago
|
}
|
||
|
}
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void regs_pcfich_free(srslte_regs_t *h) {
|
||
11 years ago
|
if (h->pcfich.regs) {
|
||
|
free(h->pcfich.regs);
|
||
10 years ago
|
h->pcfich.regs = NULL;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
uint32_t srslte_regs_pcfich_nregs(srslte_regs_t *h) {
|
||
11 years ago
|
return h->pcfich.nof_regs;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Maps the PCFICH symbols to the resource grid pointed by slot_symbols
|
||
|
*
|
||
|
* Returns the number of written symbols, or -1 on error
|
||
|
*/
|
||
10 years ago
|
int srslte_regs_pcfich_put(srslte_regs_t *h, cf_t symbols[REGS_PCFICH_NSYM], cf_t *slot_symbols) {
|
||
|
srslte_regs_ch_t *rch = &h->pcfich;
|
||
11 years ago
|
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PCFICH_NSYM; i++) {
|
||
10 years ago
|
regs_put_reg(rch->regs[i], &symbols[i*REGS_RE_X_REG], slot_symbols, h->cell.nof_prb);
|
||
11 years ago
|
}
|
||
|
return i*REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets the PCFICH symbols from the resource grid pointed by slot_symbols
|
||
|
*
|
||
|
* Returns the number of written symbols, or -1 on error
|
||
|
*/
|
||
10 years ago
|
int srslte_regs_pcfich_get(srslte_regs_t *h, cf_t *slot_symbols, cf_t ch_data[REGS_PCFICH_NSYM]) {
|
||
|
srslte_regs_ch_t *rch = &h->pcfich;
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
for (i = 0; i < rch->nof_regs && i*REGS_RE_X_REG < REGS_PCFICH_NSYM; i++) {
|
||
11 years ago
|
regs_get_reg(rch->regs[i], slot_symbols, &ch_data[i*REGS_RE_X_REG], h->cell.nof_prb);
|
||
11 years ago
|
}
|
||
|
return i*REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/***************************************************************
|
||
|
*
|
||
|
* COMMON FUNCTIONS
|
||
|
*
|
||
|
***************************************************************/
|
||
|
|
||
10 years ago
|
srslte_regs_reg_t *regs_find_reg(srslte_regs_t *h, uint32_t k, uint32_t l) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
for (i=0;i<h->nof_regs;i++) {
|
||
|
if (h->regs[i].l == l && h->regs[i].k0 == k) {
|
||
|
return &h->regs[i];
|
||
|
}
|
||
|
}
|
||
|
return NULL;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Returns the number of REGs in a PRB
|
||
|
* 36.211 Section 6.2.4
|
||
|
*/
|
||
10 years ago
|
int regs_num_x_symbol(uint32_t symbol, uint32_t nof_port, srslte_cp_t cp) {
|
||
11 years ago
|
|
||
11 years ago
|
switch (symbol) {
|
||
|
case 0:
|
||
|
return 2;
|
||
|
case 1:
|
||
|
switch (nof_port) {
|
||
|
case 1:
|
||
|
case 2:
|
||
|
return 3;
|
||
|
case 4:
|
||
|
return 2;
|
||
|
default:
|
||
10 years ago
|
fprintf(stderr, "Invalid number of ports %d\n", nof_port);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
break;
|
||
|
case 2:
|
||
|
return 3;
|
||
|
case 3:
|
||
10 years ago
|
if (SRSLTE_CP_ISNORM(cp)) {
|
||
11 years ago
|
return 3;
|
||
|
} else {
|
||
|
return 2;
|
||
|
}
|
||
|
default:
|
||
10 years ago
|
fprintf(stderr, "Invalid symbol %d\n", symbol);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Initializes the indices of a REG
|
||
|
* 36.211 Section 6.2.4
|
||
|
*/
|
||
10 years ago
|
int regs_reg_init(srslte_regs_reg_t *reg, uint32_t symbol, uint32_t nreg, uint32_t k0, uint32_t maxreg, uint32_t vo) {
|
||
11 years ago
|
uint32_t i, j, z;
|
||
11 years ago
|
|
||
|
reg->l = symbol;
|
||
|
reg->assigned = false;
|
||
|
|
||
|
switch (maxreg) {
|
||
|
case 2:
|
||
|
reg->k0 = k0 + nreg * 6;
|
||
|
/* there are two references in the middle */
|
||
|
j = z = 0;
|
||
|
for (i = 0; i < vo; i++) {
|
||
|
reg->k[j] = k0 + nreg * 6 + i;
|
||
|
j++;
|
||
|
}
|
||
|
for (i = 0; i < 2; i++) {
|
||
|
reg->k[j] = k0 + nreg * 6 + i + vo + 1;
|
||
|
j++;
|
||
|
}
|
||
|
z = j;
|
||
|
for (i = 0; i < 4 - z; i++) {
|
||
|
reg->k[j] = k0 + nreg * 6 + vo + 3 + i + 1;
|
||
|
j++;
|
||
|
}
|
||
|
if (j != 4) {
|
||
|
fprintf(stderr, "Something went wrong: expected 2 references\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
break;
|
||
|
|
||
|
case 3:
|
||
|
reg->k0 = k0 + nreg * 4;
|
||
|
/* there is no reference */
|
||
|
for (i = 0; i < 4; i++) {
|
||
|
reg->k[i] = k0 + nreg * 4 + i;
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
fprintf(stderr, "Invalid number of REGs per PRB: %d\n", maxreg);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_regs_free(srslte_regs_t *h) {
|
||
11 years ago
|
if (h->regs) {
|
||
|
free(h->regs);
|
||
|
}
|
||
|
regs_pcfich_free(h);
|
||
|
regs_phich_free(h);
|
||
|
regs_pdcch_free(h);
|
||
|
|
||
10 years ago
|
bzero(h, sizeof(srslte_regs_t));
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/** Sets the CFI value for this subframe (CFI must be in the range 1..3).
|
||
|
*/
|
||
10 years ago
|
int srslte_regs_set_cfi(srslte_regs_t *h, uint32_t cfi) {
|
||
11 years ago
|
if (cfi > 0 && cfi <= 3) {
|
||
10 years ago
|
if (h->phich_len == SRSLTE_PHICH_EXT &&
|
||
11 years ago
|
((h->cell.nof_prb < 10 && cfi < 2) || (h->cell.nof_prb >= 10 && cfi < 3))) {
|
||
11 years ago
|
fprintf(stderr, "PHICH length is extended. The number of control symbols should be at least 3.\n");
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
} else {
|
||
11 years ago
|
h->cfi_initiated = true;
|
||
11 years ago
|
h->cfi = cfi - 1;
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
} else {
|
||
|
fprintf(stderr, "Invalid CFI %d\n", cfi);
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Initializes REGs structure.
|
||
|
* Sets all REG indices and initializes PCFICH, PHICH and PDCCH REGs
|
||
|
* Returns 0 if OK, -1 on error
|
||
|
*/
|
||
10 years ago
|
int srslte_regs_init(srslte_regs_t *h, srslte_cell_t cell) {
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
uint32_t i, k;
|
||
11 years ago
|
uint32_t j[4], jmax, prb;
|
||
|
uint32_t n[4], vo;
|
||
11 years ago
|
uint32_t max_ctrl_symbols;
|
||
11 years ago
|
|
||
|
if (h != NULL &&
|
||
10 years ago
|
srslte_cell_isvalid(&cell))
|
||
11 years ago
|
{
|
||
10 years ago
|
bzero(h, sizeof(srslte_regs_t));
|
||
10 years ago
|
ret = SRSLTE_ERROR;
|
||
11 years ago
|
|
||
|
max_ctrl_symbols = cell.nof_prb<10?4:3;
|
||
|
vo = cell.id % 3;
|
||
|
h->cell = cell;
|
||
|
h->max_ctrl_symbols = max_ctrl_symbols;
|
||
|
h->cfi_initiated = false;
|
||
10 years ago
|
h->phich_res = cell.phich_resources;
|
||
|
h->phich_len = cell.phich_length;
|
||
11 years ago
|
|
||
|
h->nof_regs = 0;
|
||
|
for (i = 0; i < max_ctrl_symbols; i++) {
|
||
|
n[i] = regs_num_x_symbol(i, h->cell.nof_ports, h->cell.cp);
|
||
|
if (n[i] == -1) {
|
||
10 years ago
|
goto clean_and_exit;
|
||
11 years ago
|
}
|
||
|
h->nof_regs += h->cell.nof_prb * n[i];
|
||
|
}
|
||
|
INFO("Indexing %d REGs. CellId: %d, %d PRB, CP: %s\n", h->nof_regs, h->cell.id, h->cell.nof_prb,
|
||
10 years ago
|
SRSLTE_CP_ISNORM(h->cell.cp)?"Normal":"Extended");
|
||
10 years ago
|
h->regs = malloc(sizeof(srslte_regs_reg_t) * h->nof_regs);
|
||
11 years ago
|
if (!h->regs) {
|
||
|
perror("malloc");
|
||
|
goto clean_and_exit;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* Sort REGs according to PDCCH mapping, beggining from the lowest l index then k */
|
||
|
bzero(j, sizeof(int) * 4);
|
||
|
k = i = prb = jmax = 0;
|
||
|
while (k < h->nof_regs) {
|
||
|
if (n[i] == 3 || (n[i] == 2 && jmax != 1)) {
|
||
10 years ago
|
if (regs_reg_init(&h->regs[k], i, j[i], prb * SRSLTE_NRE, n[i], vo)) {
|
||
11 years ago
|
fprintf(stderr, "Error initializing REGs\n");
|
||
|
goto clean_and_exit;
|
||
|
}
|
||
|
/*DEBUG("Available REG #%3d: l=%d, prb=%d, nreg=%d (k0=%d)\n", k, i, prb, j[i],
|
||
|
h->regs[k].k0);
|
||
|
*/
|
||
|
j[i]++;
|
||
|
k++;
|
||
11 years ago
|
}
|
||
11 years ago
|
i++;
|
||
|
if (i == max_ctrl_symbols) {
|
||
|
i = 0;
|
||
|
jmax++;
|
||
|
}
|
||
|
if (jmax == 3) {
|
||
|
prb++;
|
||
|
bzero(j, sizeof(int) * 4);
|
||
|
jmax = 0;
|
||
|
}
|
||
|
}
|
||
|
if (regs_pcfich_init(h)) {
|
||
|
fprintf(stderr, "Error initializing PCFICH REGs\n");
|
||
|
goto clean_and_exit;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
if (regs_phich_init(h)) {
|
||
|
fprintf(stderr, "Error initializing PHICH REGs\n");
|
||
|
goto clean_and_exit;
|
||
11 years ago
|
}
|
||
11 years ago
|
if (regs_pdcch_init(h)) {
|
||
|
fprintf(stderr, "Error initializing PDCCH REGs\n");
|
||
|
goto clean_and_exit;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
11 years ago
|
clean_and_exit:
|
||
10 years ago
|
if (ret != SRSLTE_SUCCESS) {
|
||
10 years ago
|
srslte_regs_free(h);
|
||
11 years ago
|
}
|
||
|
return ret;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Puts one REG data (4 symbols) in the slot symbols array
|
||
|
*/
|
||
10 years ago
|
int regs_put_reg(srslte_regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, uint32_t nof_prb) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
for (i = 0; i < REGS_RE_X_REG; i++) {
|
||
|
slot_symbols[REG_IDX(reg, i, nof_prb)] = reg_data[i];
|
||
|
}
|
||
|
return REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Adds one REG data (4 symbols) in the slot symbols array
|
||
|
* Used by PHICH
|
||
|
*/
|
||
10 years ago
|
int regs_add_reg(srslte_regs_reg_t *reg, cf_t *reg_data, cf_t *slot_symbols, uint32_t nof_prb) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
for (i = 0; i < REGS_RE_X_REG; i++) {
|
||
|
slot_symbols[REG_IDX(reg, i, nof_prb)] += reg_data[i];
|
||
|
}
|
||
|
return REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Reset REG data (4 symbols) in the slot symbols array
|
||
|
*/
|
||
10 years ago
|
int regs_reset_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, uint32_t nof_prb) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
for (i = 0; i < REGS_RE_X_REG; i++) {
|
||
|
slot_symbols[REG_IDX(reg, i, nof_prb)] = 0;
|
||
|
}
|
||
|
return REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets one REG data (4 symbols) from the slot symbols array
|
||
|
*/
|
||
10 years ago
|
int regs_get_reg(srslte_regs_reg_t *reg, cf_t *slot_symbols, cf_t *reg_data, uint32_t nof_prb) {
|
||
11 years ago
|
uint32_t i;
|
||
11 years ago
|
for (i = 0; i < REGS_RE_X_REG; i++) {
|
||
|
reg_data[i] = slot_symbols[REG_IDX(reg, i, nof_prb)];
|
||
|
}
|
||
|
return REGS_RE_X_REG;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
|