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.
141 lines
3.1 KiB
C
141 lines
3.1 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
11 years ago
|
*
|
||
|
* \section LICENSE
|
||
11 years ago
|
*
|
||
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
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
11 years ago
|
#include <stdio.h>
|
||
11 years ago
|
#include <strings.h>
|
||
|
#include <assert.h>
|
||
|
|
||
10 years ago
|
#include "srslte/common/sequence.h"
|
||
9 years ago
|
#include "srslte/utils/vector.h"
|
||
9 years ago
|
#include "srslte/utils/bit.h"
|
||
10 years ago
|
|
||
11 years ago
|
#define Nc 1600
|
||
|
|
||
|
|
||
|
/*
|
||
|
* Pseudo Random Sequence generation.
|
||
|
* It follows the 3GPP Release 8 (LTE) 36.211
|
||
|
* Section 7.2
|
||
|
*/
|
||
10 years ago
|
void srslte_sequence_set_LTE_pr(srslte_sequence_t *q, uint32_t seed) {
|
||
11 years ago
|
int n;
|
||
11 years ago
|
uint32_t *x1, *x2;
|
||
11 years ago
|
|
||
11 years ago
|
x1 = calloc(Nc + q->len + 31, sizeof(uint32_t));
|
||
11 years ago
|
if (!x1) {
|
||
|
perror("calloc");
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
x2 = calloc(Nc + q->len + 31, sizeof(uint32_t));
|
||
11 years ago
|
if (!x2) {
|
||
|
free(x1);
|
||
|
perror("calloc");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
for (n = 0; n < 31; n++) {
|
||
|
x2[n] = (seed >> n) & 0x1;
|
||
|
}
|
||
|
x1[0] = 1;
|
||
|
|
||
|
for (n = 0; n < Nc + q->len; n++) {
|
||
|
x1[n + 31] = (x1[n + 3] + x1[n]) & 0x1;
|
||
|
x2[n + 31] = (x2[n + 3] + x2[n + 2] + +x2[n+1] + x2[n]) & 0x1;
|
||
|
}
|
||
|
|
||
|
for (n = 0; n < q->len; n++) {
|
||
|
q->c[n] = (x1[n + Nc] + x2[n + Nc]) & 0x1;
|
||
|
}
|
||
|
|
||
|
free(x1);
|
||
|
free(x2);
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_sequence_LTE_pr(srslte_sequence_t *q, uint32_t len, uint32_t seed) {
|
||
|
if (srslte_sequence_init(q, len)) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
|
q->len = len;
|
||
10 years ago
|
srslte_sequence_set_LTE_pr(q, seed);
|
||
9 years ago
|
srslte_bit_pack_vector(q->c, q->c_bytes, len);
|
||
9 years ago
|
for (int i=0;i<len;i++) {
|
||
|
q->c_float[i] = (1-2*q->c[i]);
|
||
9 years ago
|
q->c_short[i] = (int16_t) q->c_float[i];
|
||
9 years ago
|
}
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_sequence_init(srslte_sequence_t *q, uint32_t len) {
|
||
11 years ago
|
if (q->c && (q->len != len)) {
|
||
|
free(q->c);
|
||
9 years ago
|
if (q->c_bytes) {
|
||
|
free(q->c_bytes);
|
||
|
}
|
||
9 years ago
|
if (q->c_float) {
|
||
|
free(q->c_float);
|
||
|
}
|
||
9 years ago
|
if (q->c_short) {
|
||
|
free(q->c_short);
|
||
|
}
|
||
11 years ago
|
}
|
||
|
if (!q->c) {
|
||
9 years ago
|
q->c = srslte_vec_malloc(len * sizeof(uint8_t));
|
||
11 years ago
|
if (!q->c) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
9 years ago
|
q->c_bytes = srslte_vec_malloc(len * sizeof(uint8_t)/8+8);
|
||
9 years ago
|
if (!q->c_bytes) {
|
||
|
return SRSLTE_ERROR;
|
||
|
}
|
||
9 years ago
|
q->c_float = srslte_vec_malloc(len * sizeof(float));
|
||
|
if (!q->c_float) {
|
||
|
return SRSLTE_ERROR;
|
||
|
}
|
||
9 years ago
|
q->c_short = srslte_vec_malloc(len * sizeof(short));
|
||
|
if (!q->c_short) {
|
||
|
return SRSLTE_ERROR;
|
||
|
}
|
||
10 years ago
|
q->len = len;
|
||
11 years ago
|
}
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_sequence_free(srslte_sequence_t *q) {
|
||
11 years ago
|
if (q->c) {
|
||
|
free(q->c);
|
||
|
}
|
||
9 years ago
|
if (q->c_bytes) {
|
||
|
free(q->c_bytes);
|
||
|
}
|
||
9 years ago
|
if (q->c_float) {
|
||
|
free(q->c_float);
|
||
|
}
|
||
10 years ago
|
bzero(q, sizeof(srslte_sequence_t));
|
||
11 years ago
|
}
|
||
|
|
||
|
|