mirror of https://github.com/PentHertz/srsLTE.git
Fixed compilation issue with ratematching
This commit is contained in:
parent
eb52aeb1ab
commit
225ae44e0e
|
@ -32,7 +32,6 @@
|
|||
|
||||
#define NCOLS 32
|
||||
#define NROWS_MAX NCOLS
|
||||
#define RATE 3
|
||||
|
||||
unsigned char RM_PERM_TC[NCOLS] =
|
||||
{ 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, 0, 16, 8,
|
||||
|
@ -43,19 +42,19 @@ unsigned char RM_PERM_TC_INV[NCOLS] = { 16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26,
|
|||
|
||||
int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
|
||||
|
||||
char tmp[RATE * NCOLS * NROWS_MAX];
|
||||
char tmp[3 * NCOLS * NROWS_MAX];
|
||||
int nrows, ndummy, K_p;
|
||||
|
||||
int i, j, k, s;
|
||||
|
||||
nrows = (int) (in_len / RATE - 1) / NCOLS + 1;
|
||||
nrows = (int) (in_len / 3 - 1) / NCOLS + 1;
|
||||
if (nrows > NROWS_MAX) {
|
||||
fprintf(stderr, "Input too large. Max input length is %d\n",
|
||||
RATE * NCOLS * NROWS_MAX);
|
||||
3 * NCOLS * NROWS_MAX);
|
||||
return -1;
|
||||
}
|
||||
K_p = nrows * NCOLS;
|
||||
ndummy = K_p - in_len / RATE;
|
||||
ndummy = K_p - in_len / 3;
|
||||
if (ndummy < 0) {
|
||||
ndummy = 0;
|
||||
}
|
||||
|
@ -82,7 +81,7 @@ int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
|
|||
k++;
|
||||
}
|
||||
j++;
|
||||
if (j == RATE * K_p) {
|
||||
if (j == 3 * K_p) {
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
@ -99,22 +98,22 @@ int rm_conv_rx(float *input, int in_len, float *output, int out_len) {
|
|||
int i, j, k;
|
||||
int d_i, d_j;
|
||||
|
||||
float tmp[RATE * NCOLS * NROWS_MAX];
|
||||
float tmp[3 * NCOLS * NROWS_MAX];
|
||||
|
||||
nrows = (int) (out_len / RATE - 1) / NCOLS + 1;
|
||||
nrows = (int) (out_len / 3 - 1) / NCOLS + 1;
|
||||
if (nrows > NROWS_MAX) {
|
||||
fprintf(stderr, "Output too large. Max output length is %d\n",
|
||||
RATE * NCOLS * NROWS_MAX);
|
||||
3 * NCOLS * NROWS_MAX);
|
||||
return -1;
|
||||
}
|
||||
K_p = nrows * NCOLS;
|
||||
|
||||
ndummy = K_p - out_len / RATE;
|
||||
ndummy = K_p - out_len / 3;
|
||||
if (ndummy < 0) {
|
||||
ndummy = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < RATE * K_p; i++) {
|
||||
for (i = 0; i < 3 * K_p; i++) {
|
||||
tmp[i] = RX_NULL;
|
||||
}
|
||||
|
||||
|
@ -134,22 +133,22 @@ int rm_conv_rx(float *input, int in_len, float *output, int out_len) {
|
|||
k++;
|
||||
}
|
||||
j++;
|
||||
if (j == RATE * K_p) {
|
||||
if (j == 3 * K_p) {
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* interleaving and bit selection */
|
||||
for (i = 0; i < out_len / RATE; i++) {
|
||||
for (i = 0; i < out_len / 3; i++) {
|
||||
d_i = (i + ndummy) / NCOLS;
|
||||
d_j = (i + ndummy) % NCOLS;
|
||||
for (j = 0; j < RATE; j++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
float o = tmp[K_p * j + RM_PERM_TC_INV[d_j] * nrows
|
||||
+ d_i];
|
||||
if (o != RX_NULL) {
|
||||
output[i * RATE + j] = o;
|
||||
output[i * 3 + j] = o;
|
||||
} else {
|
||||
output[i * RATE + j] = 0;
|
||||
output[i * 3 + j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,11 +165,11 @@ int rm_conv_initialize(rm_conv_hl* h) {
|
|||
/** This function can be called in a subframe (1ms) basis */
|
||||
int rm_conv_work(rm_conv_hl* hl) {
|
||||
if (hl->init.direction) {
|
||||
//rm_conv_tx(hl->input, hl->output, hl->in_len, hl->ctrl_in.S);
|
||||
hl->out_len = hl->ctrl_in.S;
|
||||
} else {
|
||||
rm_conv_rx(hl->input, hl->output, hl->in_len, hl->ctrl_in.E);
|
||||
rm_conv_tx(hl->input, hl->in_len, hl->output, hl->ctrl_in.E);
|
||||
hl->out_len = hl->ctrl_in.E;
|
||||
} else {
|
||||
rm_conv_rx(hl->input, hl->in_len, hl->output, hl->ctrl_in.S);
|
||||
hl->out_len = hl->ctrl_in.S;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
|
||||
#define NCOLS 32
|
||||
#define NROWS_MAX NCOLS
|
||||
#define RATE 3
|
||||
|
||||
unsigned char RM_PERM_TC[NCOLS] =
|
||||
{ 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30, 1, 17, 9,
|
||||
|
@ -48,11 +47,6 @@ int rm_turbo_init(rm_turbo_t *q, int buffer_len) {
|
|||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
q->d2_perm = malloc(buffer_len * sizeof(int) / 3 + 1);
|
||||
if (!q->d2_perm) {
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -74,7 +68,7 @@ int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_le
|
|||
|
||||
int i, j, k, s, kidx, N_cb, k0;
|
||||
|
||||
nrows = (int) (in_len / RATE - 1) / NCOLS + 1;
|
||||
nrows = (int) (in_len / 3 - 1) / NCOLS + 1;
|
||||
K_p = nrows * NCOLS;
|
||||
if (3 * K_p > q->buffer_len) {
|
||||
fprintf(stderr,
|
||||
|
@ -83,7 +77,7 @@ int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_le
|
|||
return -1;
|
||||
}
|
||||
|
||||
ndummy = K_p - in_len / RATE;
|
||||
ndummy = K_p - in_len / 3;
|
||||
if (ndummy < 0) {
|
||||
ndummy = 0;
|
||||
}
|
||||
|
@ -148,7 +142,7 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
|
|||
|
||||
float *tmp = (float*) q->buffer;
|
||||
|
||||
nrows = (int) (out_len / RATE - 1) / NCOLS + 1;
|
||||
nrows = (int) (out_len / 3 - 1) / NCOLS + 1;
|
||||
K_p = nrows * NCOLS;
|
||||
if (3 * K_p > q->buffer_len) {
|
||||
fprintf(stderr,
|
||||
|
@ -157,12 +151,12 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
|
|||
return -1;
|
||||
}
|
||||
|
||||
ndummy = K_p - out_len / RATE;
|
||||
ndummy = K_p - out_len / 3;
|
||||
if (ndummy < 0) {
|
||||
ndummy = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < RATE * K_p; i++) {
|
||||
for (i = 0; i < 3 * K_p; i++) {
|
||||
tmp[i] = RX_NULL;
|
||||
}
|
||||
|
||||
|
@ -170,15 +164,12 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
|
|||
N_cb = 3 * K_p; // TODO: Soft buffer size limitation
|
||||
k0 = nrows * (2 * (int) ceilf((float) N_cb / (float) (8 * nrows))
|
||||
* rv_idx + 2);
|
||||
|
||||
k = 0;
|
||||
j = 0;
|
||||
while (k < in_len) {
|
||||
jp = (k0 + j) % N_cb;
|
||||
|
||||
if (jp == 32 || jp == 95 || jp == 0) {
|
||||
i=0;
|
||||
}
|
||||
|
||||
if (jp < K_p || !(jp%2)) {
|
||||
if (jp >= K_p) {
|
||||
d_i = ((jp-K_p) / 2) / nrows;
|
||||
|
@ -195,7 +186,6 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
|
|||
} else {
|
||||
int jpp = (jp-K_p-1)/2;
|
||||
kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p;
|
||||
q->d2_perm[kidx] = jpp; // save the permutation in a temporary buffer
|
||||
if ((kidx - ndummy) < 0) {
|
||||
isdummy = true;
|
||||
} else {
|
||||
|
@ -215,21 +205,23 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
|
|||
}
|
||||
|
||||
/* interleaving and bit selection */
|
||||
for (i = 0; i < out_len / RATE; i++) {
|
||||
for (i = 0; i < out_len / 3; i++) {
|
||||
d_i = (i + ndummy) / NCOLS;
|
||||
d_j = (i + ndummy) % NCOLS;
|
||||
for (j = 0; j < RATE; j++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
if (j != 2) {
|
||||
kidx = K_p * j + (j+1)*(RM_PERM_TC[d_j] * nrows + d_i);
|
||||
} else {
|
||||
// use the saved permuatation function to avoid computing the inverse
|
||||
kidx = 2*q->d2_perm[(i+ndummy)%K_p]+K_p+1;
|
||||
|
||||
k=(i+ndummy-1)%K_p;
|
||||
if (k<0) k+=K_p;
|
||||
kidx = (k / NCOLS + nrows * RM_PERM_TC[k % NCOLS]) % K_p;
|
||||
kidx = 2*kidx+K_p+1;
|
||||
}
|
||||
float o = tmp[kidx];
|
||||
if (o != RX_NULL) {
|
||||
output[i * RATE + j] = o;
|
||||
if (tmp[kidx] != RX_NULL) {
|
||||
output[i * 3 + j] = tmp[kidx];
|
||||
} else {
|
||||
output[i * RATE + j] = 0;
|
||||
output[i * 3 + j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,11 @@ TARGET_LINK_LIBRARIES(rm_turbo_test lte)
|
|||
ADD_TEST(rm_conv_test_1 rm_conv_test -t 480 -r 1920)
|
||||
ADD_TEST(rm_conv_test_2 rm_conv_test -t 1920 -r 480)
|
||||
|
||||
ADD_TEST(rm_turbo_test_1 rm_turbo_test -t 480 -r 1920 -i 0)
|
||||
ADD_TEST(rm_turbo_test_2 rm_turbo_test -t 1920 -r 480 -i 1)
|
||||
ADD_TEST(rm_turbo_test_1 rm_turbo_test -t 480 -r 1920 -i 2)
|
||||
ADD_TEST(rm_turbo_test_2 rm_turbo_test -t 1920 -r 480 -i 3)
|
||||
|
||||
|
||||
########################################################################
|
||||
# Turbo Coder TEST
|
||||
|
|
|
@ -71,6 +71,7 @@ void parse_args(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
char *bits, *rm_bits;
|
||||
|
@ -105,7 +106,7 @@ int main(int argc, char **argv) {
|
|||
bits[i] = rand()%2;
|
||||
}
|
||||
|
||||
rm_turbo_init(&rm_turbo, 1000);
|
||||
rm_turbo_init(&rm_turbo, 2000);
|
||||
|
||||
rm_turbo_tx(&rm_turbo, bits, nof_tx_bits, rm_bits, nof_rx_bits, rv_idx);
|
||||
|
||||
|
@ -117,9 +118,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
nof_errors = 0;
|
||||
for (i=0;i<nof_tx_bits;i++) {
|
||||
if ((unrm_symbols[i] > 0) != bits[i]) {
|
||||
if (unrm_symbols[i] > 0 && ((unrm_symbols[i] > 0) != bits[i])) {
|
||||
nof_errors++;
|
||||
printf("%.2f != %d\n", unrm_symbols[i], bits[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,11 +130,9 @@ int main(int argc, char **argv) {
|
|||
free(rm_symbols);
|
||||
free(unrm_symbols);
|
||||
|
||||
if (nof_tx_bits >= nof_rx_bits) {
|
||||
if (nof_errors) {
|
||||
printf("nof_errors=%d\n", nof_errors);
|
||||
exit(-1);
|
||||
}
|
||||
if (nof_errors) {
|
||||
printf("nof_errors=%d\n", nof_errors);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
printf("Ok\n");
|
||||
|
|
Loading…
Reference in New Issue