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.
153 lines
4.3 KiB
C
153 lines
4.3 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
|
|
||
11 years ago
|
#include <strings.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
11 years ago
|
#include <stdio.h>
|
||
11 years ago
|
#include <math.h>
|
||
|
|
||
10 years ago
|
#include "srslte/sync/sss.h"
|
||
10 years ago
|
#include "srslte/dft/dft.h"
|
||
10 years ago
|
#include "srslte/utils/convolution.h"
|
||
|
#include "srslte/utils/vector.h"
|
||
11 years ago
|
|
||
10 years ago
|
void generate_sss_all_tables(srslte_sss_tables_t *tables, uint32_t N_id_2);
|
||
|
void convert_tables(srslte_sss_fc_tables_t *fc_tables, srslte_sss_tables_t *in);
|
||
11 years ago
|
void generate_N_id_1_table(uint32_t table[30][30]);
|
||
|
|
||
10 years ago
|
int srslte_sss_synch_init(srslte_sss_synch_t *q, uint32_t fft_size) {
|
||
11 years ago
|
|
||
|
if (q != NULL &&
|
||
11 years ago
|
fft_size <= 2048)
|
||
11 years ago
|
{
|
||
|
uint32_t N_id_2;
|
||
10 years ago
|
srslte_sss_tables_t sss_tables;
|
||
11 years ago
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_sss_synch_t));
|
||
11 years ago
|
|
||
10 years ago
|
if (srslte_dft_plan(&q->dftp_input, fft_size, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) {
|
||
|
srslte_sss_synch_free(q);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
srslte_dft_plan_set_mirror(&q->dftp_input, true);
|
||
|
srslte_dft_plan_set_dc(&q->dftp_input, true);
|
||
10 years ago
|
|
||
11 years ago
|
q->fft_size = fft_size;
|
||
|
|
||
|
generate_N_id_1_table(q->N_id_1_table);
|
||
|
|
||
|
for (N_id_2=0;N_id_2<3;N_id_2++) {
|
||
|
generate_sss_all_tables(&sss_tables, N_id_2);
|
||
|
convert_tables(&q->fc_tables[N_id_2], &sss_tables);
|
||
|
}
|
||
|
q->N_id_2 = 0;
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
10 years ago
|
int srslte_sss_synch_realloc(srslte_sss_synch_t *q, uint32_t fft_size) {
|
||
11 years ago
|
if (q != NULL &&
|
||
11 years ago
|
fft_size <= 2048)
|
||
11 years ago
|
{
|
||
10 years ago
|
srslte_dft_plan_free(&q->dftp_input);
|
||
|
if (srslte_dft_plan(&q->dftp_input, fft_size, SRSLTE_DFT_FORWARD, SRSLTE_DFT_COMPLEX)) {
|
||
|
srslte_sss_synch_free(q);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
srslte_dft_plan_set_mirror(&q->dftp_input, true);
|
||
|
srslte_dft_plan_set_norm(&q->dftp_input, true);
|
||
|
srslte_dft_plan_set_dc(&q->dftp_input, true);
|
||
11 years ago
|
|
||
|
q->fft_size = fft_size;
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
10 years ago
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_sss_synch_free(srslte_sss_synch_t *q) {
|
||
|
srslte_dft_plan_free(&q->dftp_input);
|
||
|
bzero(q, sizeof(srslte_sss_synch_t));
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/** Sets the N_id_2 to search for */
|
||
10 years ago
|
int srslte_sss_synch_set_N_id_2(srslte_sss_synch_t *q, uint32_t N_id_2) {
|
||
10 years ago
|
if (!srslte_N_id_2_isvalid(N_id_2)) {
|
||
11 years ago
|
fprintf(stderr, "Invalid N_id_2 %d\n", N_id_2);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
} else {
|
||
|
q->N_id_2 = N_id_2;
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
/** 36.211 10.3 section 6.11.2.2
|
||
|
*/
|
||
10 years ago
|
void srslte_sss_put_slot(float *sss, cf_t *slot, uint32_t nof_prb, srslte_cp_t cp) {
|
||
11 years ago
|
uint32_t i, k;
|
||
11 years ago
|
|
||
10 years ago
|
k = (SRSLTE_CP_NSYMB(cp) - 2) * nof_prb * SRSLTE_NRE + nof_prb * SRSLTE_NRE / 2 - 31;
|
||
11 years ago
|
|
||
|
if (k > 5) {
|
||
|
memset(&slot[k - 5], 0, 5 * sizeof(cf_t));
|
||
10 years ago
|
for (i = 0; i < SRSLTE_SSS_LEN; i++) {
|
||
11 years ago
|
__real__ slot[k + i] = sss[i];
|
||
|
__imag__ slot[k + i] = 0;
|
||
11 years ago
|
}
|
||
10 years ago
|
memset(&slot[k + SRSLTE_SSS_LEN], 0, 5 * sizeof(cf_t));
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Sets the SSS correlation peak detection threshold */
|
||
10 years ago
|
void srslte_sss_synch_set_threshold(srslte_sss_synch_t *q, float threshold) {
|
||
11 years ago
|
q->corr_peak_threshold = threshold;
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Returns the subframe index based on the m0 and m1 values */
|
||
10 years ago
|
uint32_t srslte_sss_synch_subframe(uint32_t m0, uint32_t m1) {
|
||
11 years ago
|
if (m1 > m0) {
|
||
|
return 0;
|
||
|
} else {
|
||
|
return 5;
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
/** Returns the N_id_1 value based on the m0 and m1 values */
|
||
10 years ago
|
int srslte_sss_synch_N_id_1(srslte_sss_synch_t *q, uint32_t m0, uint32_t m1) {
|
||
11 years ago
|
if (m0==m1 || m0 > 29 || m1 > 29) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
11 years ago
|
}
|
||
10 years ago
|
int N_id_1;
|
||
11 years ago
|
if (m1 > m0) {
|
||
10 years ago
|
N_id_1 = q->N_id_1_table[m0][m1 - 1];
|
||
11 years ago
|
} else {
|
||
10 years ago
|
N_id_1 = q->N_id_1_table[m1][m0 - 1];
|
||
11 years ago
|
}
|
||
10 years ago
|
return N_id_1;
|
||
11 years ago
|
}
|