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.
155 lines
3.8 KiB
C
155 lines
3.8 KiB
C
11 years ago
|
/**
|
||
11 years ago
|
*
|
||
11 years ago
|
* \section COPYRIGHT
|
||
11 years ago
|
*
|
||
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/.
|
||
|
*
|
||
11 years ago
|
*/
|
||
|
|
||
11 years ago
|
#include <string.h>
|
||
11 years ago
|
#include <stdio.h>
|
||
11 years ago
|
#include <stdint.h>
|
||
|
|
||
10 years ago
|
#include "srslte/fec/rm_conv.h"
|
||
11 years ago
|
|
||
|
#define NCOLS 32
|
||
|
#define NROWS_MAX NCOLS
|
||
|
|
||
11 years ago
|
uint8_t RM_PERM_CC[NCOLS] = { 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27,
|
||
11 years ago
|
7, 23, 15, 31, 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 };
|
||
11 years ago
|
uint8_t RM_PERM_CC_INV[NCOLS] =
|
||
11 years ago
|
{ 16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26, 10, 22, 6, 30, 14, 17, 1, 25, 9,
|
||
|
21, 5, 29, 13, 19, 3, 27, 11, 23, 7, 31, 15 };
|
||
11 years ago
|
|
||
10 years ago
|
int srslte_rm_conv_tx(uint8_t *input, uint32_t in_len, uint8_t *output, uint32_t out_len) {
|
||
11 years ago
|
|
||
10 years ago
|
uint8_t tmp[3 * NCOLS * NROWS_MAX];
|
||
11 years ago
|
int nrows, ndummy, K_p;
|
||
|
|
||
|
int i, j, k, s;
|
||
|
|
||
11 years ago
|
nrows = (uint32_t) (in_len / 3 - 1) / NCOLS + 1;
|
||
11 years ago
|
if (nrows > NROWS_MAX) {
|
||
|
fprintf(stderr, "Input too large. Max input length is %d\n",
|
||
11 years ago
|
3 * NCOLS * NROWS_MAX);
|
||
11 years ago
|
return -1;
|
||
|
}
|
||
|
K_p = nrows * NCOLS;
|
||
11 years ago
|
ndummy = K_p - in_len / 3;
|
||
11 years ago
|
if (ndummy < 0) {
|
||
|
ndummy = 0;
|
||
|
}
|
||
|
/* Sub-block interleaver 5.1.4.2.1 */
|
||
11 years ago
|
k = 0;
|
||
11 years ago
|
for (s = 0; s < 3; s++) {
|
||
|
for (j = 0; j < NCOLS; j++) {
|
||
|
for (i = 0; i < nrows; i++) {
|
||
11 years ago
|
if (i * NCOLS + RM_PERM_CC[j] < ndummy) {
|
||
10 years ago
|
tmp[k] = SRSLTE_TX_NULL;
|
||
11 years ago
|
} else {
|
||
11 years ago
|
tmp[k] = input[(i * NCOLS + RM_PERM_CC[j] - ndummy) * 3 + s];
|
||
11 years ago
|
}
|
||
|
k++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
/* Bit collection, selection and transmission 5.1.4.2.2 */
|
||
|
k = 0;
|
||
|
j = 0;
|
||
|
while (k < out_len) {
|
||
10 years ago
|
if (tmp[j] != SRSLTE_TX_NULL) {
|
||
11 years ago
|
output[k] = tmp[j];
|
||
|
k++;
|
||
|
}
|
||
|
j++;
|
||
11 years ago
|
if (j == 3 * K_p) {
|
||
11 years ago
|
j = 0;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/* Undoes Convolutional Code Rate Matching.
|
||
|
* 3GPP TS 36.212 v10.1.0 section 5.1.4.2
|
||
|
*/
|
||
10 years ago
|
int srslte_rm_conv_rx(float *input, uint32_t in_len, float *output, uint32_t out_len) {
|
||
11 years ago
|
|
||
11 years ago
|
int nrows, ndummy, K_p;
|
||
|
int i, j, k;
|
||
|
int d_i, d_j;
|
||
11 years ago
|
|
||
11 years ago
|
float tmp[3 * NCOLS * NROWS_MAX];
|
||
10 years ago
|
|
||
11 years ago
|
nrows = (uint32_t) (out_len / 3 - 1) / NCOLS + 1;
|
||
11 years ago
|
if (nrows > NROWS_MAX) {
|
||
|
fprintf(stderr, "Output too large. Max output length is %d\n",
|
||
11 years ago
|
3 * NCOLS * NROWS_MAX);
|
||
11 years ago
|
return -1;
|
||
|
}
|
||
|
K_p = nrows * NCOLS;
|
||
11 years ago
|
|
||
11 years ago
|
ndummy = K_p - out_len / 3;
|
||
11 years ago
|
if (ndummy < 0) {
|
||
|
ndummy = 0;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
for (i = 0; i < 3 * K_p; i++) {
|
||
10 years ago
|
tmp[i] = SRSLTE_RX_NULL;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* Undo bit collection. Account for dummy bits */
|
||
|
k = 0;
|
||
|
j = 0;
|
||
|
while (k < in_len) {
|
||
|
d_i = (j % K_p) / nrows;
|
||
|
d_j = (j % K_p) % nrows;
|
||
11 years ago
|
|
||
11 years ago
|
if (d_j * NCOLS + RM_PERM_CC[d_i] >= ndummy) {
|
||
10 years ago
|
if (tmp[j] == SRSLTE_RX_NULL) {
|
||
11 years ago
|
tmp[j] = input[k];
|
||
10 years ago
|
} else if (input[k] != SRSLTE_RX_NULL) {
|
||
11 years ago
|
tmp[j] += input[k]; /* soft combine LLRs */
|
||
|
}
|
||
|
k++;
|
||
|
}
|
||
|
j++;
|
||
11 years ago
|
if (j == 3 * K_p) {
|
||
11 years ago
|
j = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* interleaving and bit selection */
|
||
11 years ago
|
for (i = 0; i < out_len / 3; i++) {
|
||
11 years ago
|
d_i = (i + ndummy) / NCOLS;
|
||
|
d_j = (i + ndummy) % NCOLS;
|
||
11 years ago
|
for (j = 0; j < 3; j++) {
|
||
|
float o = tmp[K_p * j + RM_PERM_CC_INV[d_j] * nrows + d_i];
|
||
10 years ago
|
if (o != SRSLTE_RX_NULL) {
|
||
11 years ago
|
output[i * 3 + j] = o;
|
||
11 years ago
|
} else {
|
||
11 years ago
|
output[i * 3 + j] = 0;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
11 years ago
|
}
|
||
|
|