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.
147 lines
2.9 KiB
C
147 lines
2.9 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/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
|
||
11 years ago
|
#include "liblte/phy/fec/turbocoder.h"
|
||
11 years ago
|
#include <stdio.h>
|
||
|
|
||
11 years ago
|
#define NOF_REGS 3
|
||
|
|
||
11 years ago
|
int tcod_init(tcod_t *h, int max_long_cb) {
|
||
11 years ago
|
|
||
11 years ago
|
if (tc_interl_init(&h->interl, max_long_cb)) {
|
||
11 years ago
|
return -1;
|
||
|
}
|
||
11 years ago
|
h->max_long_cb = max_long_cb;
|
||
11 years ago
|
return 0;
|
||
11 years ago
|
}
|
||
|
|
||
|
void tcod_free(tcod_t *h) {
|
||
11 years ago
|
tc_interl_free(&h->interl);
|
||
11 years ago
|
h->max_long_cb = 0;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
int tcod_encode(tcod_t *h, char *input, char *output, int long_cb) {
|
||
11 years ago
|
|
||
|
char reg1_0, reg1_1, reg1_2, reg2_0, reg2_1, reg2_2;
|
||
|
int i, k = 0, j;
|
||
11 years ago
|
char bit;
|
||
11 years ago
|
char in, out;
|
||
11 years ago
|
int *per;
|
||
11 years ago
|
|
||
11 years ago
|
if (long_cb > h->max_long_cb) {
|
||
|
fprintf(stderr, "Turbo coder initiated for max_long_cb=%d\n",
|
||
|
h->max_long_cb);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
if (tc_interl_LTE_gen(&h->interl, long_cb)) {
|
||
|
fprintf(stderr, "Error initiating TC interleaver\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
per = h->interl.forward;
|
||
|
|
||
|
reg1_0 = 0;
|
||
|
reg1_1 = 0;
|
||
|
reg1_2 = 0;
|
||
|
|
||
|
reg2_0 = 0;
|
||
|
reg2_1 = 0;
|
||
|
reg2_2 = 0;
|
||
|
|
||
|
k = 0;
|
||
|
for (i = 0; i < long_cb; i++) {
|
||
|
bit = input[i];
|
||
|
|
||
|
output[k] = bit;
|
||
11 years ago
|
k++;
|
||
11 years ago
|
|
||
|
in = bit ^ (reg1_2 ^ reg1_1);
|
||
|
out = reg1_2 ^ (reg1_0 ^ in);
|
||
|
|
||
|
reg1_2 = reg1_1;
|
||
|
reg1_1 = reg1_0;
|
||
|
reg1_0 = in;
|
||
|
|
||
|
output[k] = out;
|
||
11 years ago
|
k++;
|
||
11 years ago
|
|
||
|
bit = input[per[i]];
|
||
|
|
||
|
in = bit ^ (reg2_2 ^ reg2_1);
|
||
|
out = reg2_2 ^ (reg2_0 ^ in);
|
||
|
|
||
|
reg2_2 = reg2_1;
|
||
|
reg2_1 = reg2_0;
|
||
|
reg2_0 = in;
|
||
|
|
||
|
output[k] = out;
|
||
11 years ago
|
k++;
|
||
|
}
|
||
11 years ago
|
|
||
|
k = 3 * long_cb;
|
||
|
|
||
11 years ago
|
/* TAILING CODER #1 */
|
||
11 years ago
|
for (j = 0; j < NOF_REGS; j++) {
|
||
|
bit = reg1_2 ^ reg1_1;
|
||
|
|
||
|
output[k] = bit;
|
||
11 years ago
|
k++;
|
||
11 years ago
|
|
||
|
in = bit ^ (reg1_2 ^ reg1_1);
|
||
|
out = reg1_2 ^ (reg1_0 ^ in);
|
||
|
|
||
|
reg1_2 = reg1_1;
|
||
|
reg1_1 = reg1_0;
|
||
|
reg1_0 = in;
|
||
|
|
||
|
output[k] = out;
|
||
11 years ago
|
k++;
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
/* TAILING CODER #2 */
|
||
11 years ago
|
for (j = 0; j < NOF_REGS; j++) {
|
||
|
bit = reg2_2 ^ reg2_1;
|
||
|
|
||
|
output[k] = bit;
|
||
11 years ago
|
k++;
|
||
11 years ago
|
|
||
|
in = bit ^ (reg2_2 ^ reg2_1);
|
||
|
out = reg2_2 ^ (reg2_0 ^ in);
|
||
|
|
||
|
reg2_2 = reg2_1;
|
||
|
reg2_1 = reg2_0;
|
||
|
reg2_0 = in;
|
||
|
|
||
|
output[k] = out;
|
||
11 years ago
|
k++;
|
||
|
}
|
||
11 years ago
|
return 0;
|
||
11 years ago
|
}
|
||
|
|