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.
241 lines
6.6 KiB
C
241 lines
6.6 KiB
C
10 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
10 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
10 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
|
||
10 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,
|
||
10 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.
|
||
10 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
10 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <strings.h>
|
||
|
#include <assert.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
10 years ago
|
#include "srslte/ue/ue_mib.h"
|
||
10 years ago
|
|
||
10 years ago
|
#include "srslte/utils/debug.h"
|
||
|
#include "srslte/utils/vector.h"
|
||
10 years ago
|
|
||
10 years ago
|
int srslte_ue_mib_init(srslte_ue_mib_t * q,
|
||
10 years ago
|
srslte_cell_t cell)
|
||
10 years ago
|
{
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
|
||
10 years ago
|
if (q != NULL &&
|
||
10 years ago
|
cell.nof_ports <= SRSLTE_MAX_PORTS)
|
||
10 years ago
|
{
|
||
10 years ago
|
|
||
10 years ago
|
ret = SRSLTE_ERROR;
|
||
10 years ago
|
bzero(q, sizeof(srslte_ue_mib_t));
|
||
10 years ago
|
|
||
10 years ago
|
if (srslte_pbch_init(&q->pbch, cell)) {
|
||
|
fprintf(stderr, "Error initiating PBCH\n");
|
||
|
goto clean_exit;
|
||
|
}
|
||
|
|
||
|
if (cell.nof_ports == 0) {
|
||
|
cell.nof_ports = SRSLTE_MAX_PORTS;
|
||
|
}
|
||
|
|
||
10 years ago
|
q->sf_symbols = srslte_vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
|
||
10 years ago
|
if (!q->sf_symbols) {
|
||
10 years ago
|
perror("malloc");
|
||
|
goto clean_exit;
|
||
|
}
|
||
|
|
||
10 years ago
|
for (int i=0;i<cell.nof_ports;i++) {
|
||
10 years ago
|
q->ce[i] = srslte_vec_malloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t));
|
||
10 years ago
|
if (!q->ce[i]) {
|
||
|
perror("malloc");
|
||
|
goto clean_exit;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
if (srslte_ofdm_rx_init(&q->fft, cell.cp, cell.nof_prb)) {
|
||
10 years ago
|
fprintf(stderr, "Error initializing FFT\n");
|
||
|
goto clean_exit;
|
||
|
}
|
||
10 years ago
|
if (srslte_chest_dl_init(&q->chest, cell)) {
|
||
10 years ago
|
fprintf(stderr, "Error initializing reference signal\n");
|
||
|
goto clean_exit;
|
||
|
}
|
||
10 years ago
|
srslte_ue_mib_reset(q);
|
||
10 years ago
|
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
|
|
||
|
clean_exit:
|
||
10 years ago
|
if (ret == SRSLTE_ERROR) {
|
||
10 years ago
|
srslte_ue_mib_free(q);
|
||
10 years ago
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
10 years ago
|
void srslte_ue_mib_free(srslte_ue_mib_t * q)
|
||
10 years ago
|
{
|
||
10 years ago
|
if (q->sf_symbols) {
|
||
|
free(q->sf_symbols);
|
||
10 years ago
|
}
|
||
10 years ago
|
for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
|
||
10 years ago
|
if (q->ce[i]) {
|
||
|
free(q->ce[i]);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
srslte_sync_free(&q->sfind);
|
||
10 years ago
|
srslte_chest_dl_free(&q->chest);
|
||
10 years ago
|
srslte_pbch_free(&q->pbch);
|
||
10 years ago
|
srslte_ofdm_rx_free(&q->fft);
|
||
10 years ago
|
|
||
10 years ago
|
bzero(q, sizeof(srslte_ue_mib_t));
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
10 years ago
|
void srslte_ue_mib_reset(srslte_ue_mib_t * q)
|
||
10 years ago
|
{
|
||
10 years ago
|
q->frame_cnt = 0;
|
||
10 years ago
|
srslte_pbch_decode_reset(&q->pbch);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
int srslte_ue_mib_decode(srslte_ue_mib_t * q, cf_t *input,
|
||
9 years ago
|
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, int *sfn_offset)
|
||
10 years ago
|
{
|
||
10 years ago
|
int ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
cf_t *ce_slot1[SRSLTE_MAX_PORTS];
|
||
10 years ago
|
|
||
|
/* Run FFT for the slot symbols */
|
||
10 years ago
|
srslte_ofdm_rx_sf(&q->fft, input, q->sf_symbols);
|
||
10 years ago
|
|
||
10 years ago
|
/* Get channel estimates of sf idx #0 for each port */
|
||
10 years ago
|
ret = srslte_chest_dl_estimate(&q->chest, q->sf_symbols, q->ce, 0);
|
||
10 years ago
|
if (ret < 0) {
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
/* Reset decoder if we missed a frame */
|
||
10 years ago
|
if (q->frame_cnt > 8) {
|
||
|
INFO("Resetting PBCH decoder after %d frames\n", q->frame_cnt);
|
||
10 years ago
|
srslte_ue_mib_reset(q);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
|
||
10 years ago
|
ce_slot1[i] = &q->ce[i][SRSLTE_SLOT_LEN_RE(q->chest.cell.nof_prb, q->chest.cell.cp)];
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
10 years ago
|
/* Decode PBCH */
|
||
10 years ago
|
ret = srslte_pbch_decode(&q->pbch, &q->sf_symbols[SRSLTE_SLOT_LEN_RE(q->chest.cell.nof_prb, q->chest.cell.cp)],
|
||
9 years ago
|
ce_slot1, srslte_chest_dl_get_noise_estimate(&q->chest),
|
||
10 years ago
|
bch_payload, nof_tx_ports, sfn_offset);
|
||
9 years ago
|
|
||
9 years ago
|
|
||
10 years ago
|
if (ret < 0) {
|
||
10 years ago
|
fprintf(stderr, "Error decoding PBCH (%d)\n", ret);
|
||
10 years ago
|
} else if (ret == 1) {
|
||
10 years ago
|
INFO("MIB decoded: %u\n", q->frame_cnt);
|
||
10 years ago
|
srslte_ue_mib_reset(q);
|
||
|
ret = SRSLTE_UE_MIB_FOUND;
|
||
10 years ago
|
} else {
|
||
9 years ago
|
ret = SRSLTE_UE_MIB_NOTFOUND;
|
||
9 years ago
|
INFO("MIB not decoded: %u\n", q->frame_cnt);
|
||
10 years ago
|
q->frame_cnt++;
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
10 years ago
|
return ret;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
int srslte_ue_mib_sync_init(srslte_ue_mib_sync_t *q,
|
||
10 years ago
|
uint32_t cell_id,
|
||
10 years ago
|
srslte_cp_t cp,
|
||
10 years ago
|
int (recv_callback)(void*, void*, uint32_t, srslte_timestamp_t*),
|
||
10 years ago
|
void *stream_handler)
|
||
10 years ago
|
{
|
||
10 years ago
|
srslte_cell_t cell;
|
||
10 years ago
|
// If the ports are set to 0, ue_mib goes through 1, 2 and 4 ports to blindly detect nof_ports
|
||
|
cell.nof_ports = 0;
|
||
10 years ago
|
cell.id = cell_id;
|
||
|
cell.cp = cp;
|
||
10 years ago
|
cell.nof_prb = SRSLTE_UE_MIB_NOF_PRB;
|
||
10 years ago
|
|
||
10 years ago
|
if (srslte_ue_mib_init(&q->ue_mib, cell)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating ue_mib\n");
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
if (srslte_ue_sync_init(&q->ue_sync, cell, recv_callback, stream_handler)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating ue_sync\n");
|
||
10 years ago
|
srslte_ue_mib_free(&q->ue_mib);
|
||
10 years ago
|
return SRSLTE_ERROR;
|
||
10 years ago
|
}
|
||
10 years ago
|
srslte_ue_sync_decode_sss_on_track(&q->ue_sync, true);
|
||
10 years ago
|
return SRSLTE_SUCCESS;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
void srslte_ue_mib_sync_free(srslte_ue_mib_sync_t *q) {
|
||
|
srslte_ue_mib_free(&q->ue_mib);
|
||
|
srslte_ue_sync_free(&q->ue_sync);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void srslte_ue_mib_sync_reset(srslte_ue_mib_sync_t * q) {
|
||
|
srslte_ue_mib_reset(&q->ue_mib);
|
||
|
srslte_ue_sync_reset(&q->ue_sync);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
int srslte_ue_mib_sync_decode(srslte_ue_mib_sync_t * q,
|
||
10 years ago
|
uint32_t max_frames_timeout,
|
||
10 years ago
|
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN],
|
||
10 years ago
|
uint32_t *nof_tx_ports,
|
||
9 years ago
|
int *sfn_offset)
|
||
10 years ago
|
{
|
||
|
|
||
10 years ago
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
||
10 years ago
|
cf_t *sf_buffer = NULL;
|
||
|
uint32_t nof_frames = 0;
|
||
10 years ago
|
int mib_ret = SRSLTE_UE_MIB_NOTFOUND;
|
||
10 years ago
|
|
||
|
if (q != NULL)
|
||
|
{
|
||
10 years ago
|
ret = SRSLTE_SUCCESS;
|
||
10 years ago
|
do {
|
||
10 years ago
|
mib_ret = SRSLTE_UE_MIB_NOTFOUND;
|
||
|
ret = srslte_ue_sync_get_buffer(&q->ue_sync, &sf_buffer);
|
||
10 years ago
|
if (ret < 0) {
|
||
10 years ago
|
fprintf(stderr, "Error calling srslte_ue_sync_work()\n");
|
||
10 years ago
|
break;
|
||
10 years ago
|
} else if (srslte_ue_sync_get_sfidx(&q->ue_sync) == 0) {
|
||
10 years ago
|
if (ret == 1) {
|
||
10 years ago
|
mib_ret = srslte_ue_mib_decode(&q->ue_mib, sf_buffer, bch_payload, nof_tx_ports, sfn_offset);
|
||
10 years ago
|
} else {
|
||
10 years ago
|
DEBUG("Resetting PBCH decoder after %d frames\n", q->ue_mib.frame_cnt);
|
||
10 years ago
|
srslte_ue_mib_reset(&q->ue_mib);
|
||
10 years ago
|
}
|
||
|
nof_frames++;
|
||
10 years ago
|
}
|
||
10 years ago
|
} while (mib_ret == SRSLTE_UE_MIB_NOTFOUND && ret >= 0 && nof_frames < max_frames_timeout);
|
||
10 years ago
|
if (mib_ret < 0) {
|
||
|
ret = mib_ret;
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
return mib_ret;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
|