2014-07-21 07:19:17 -07:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* Copyright 2013-2015 The srsLTE Developers. See the
|
2014-07-21 07:19:17 -07:00
|
|
|
* COPYRIGHT file at the top-level directory of this distribution.
|
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
2015-03-18 05:31:13 -07:00
|
|
|
* This file is part of the srsLTE library.
|
2014-07-21 07:19:17 -07:00
|
|
|
*
|
2015-03-18 05:31:13 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2015-05-08 08:05:40 -07:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2014-07-21 07:19:17 -07:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-18 05:31:13 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2014-07-21 07:19:17 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-05-08 08:05:40 -07:00
|
|
|
* GNU Affero General Public License for more details.
|
2014-07-21 07:19:17 -07:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2014-07-21 07:19:17 -07:00
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-04-03 05:49:12 -07:00
|
|
|
/******************************************************************************
|
|
|
|
* File: ue_sync.h
|
|
|
|
*
|
|
|
|
* Description: This object automatically manages the cell synchronization
|
|
|
|
* procedure.
|
|
|
|
*
|
|
|
|
* The main function is srslte_ue_sync_get_buffer(), which returns
|
|
|
|
* a pointer to the aligned subframe of samples (before FFT). This
|
|
|
|
* function should be called regularly, returning every 1 ms.
|
|
|
|
* It reads from the USRP, aligns the samples to the subframe and
|
|
|
|
* performs time/freq synch.
|
|
|
|
*
|
|
|
|
* It is also possible to read the signal from a file using the
|
|
|
|
* init function srslte_ue_sync_init_file(). The sampling frequency
|
|
|
|
* is derived from the number of PRB.
|
|
|
|
*
|
|
|
|
* The function returns 1 when the signal is correctly acquired and
|
|
|
|
* the returned buffer is aligned with the subframe.
|
|
|
|
*
|
|
|
|
* Reference:
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-07-21 07:19:17 -07:00
|
|
|
#ifndef UE_SYNC_
|
|
|
|
#define UE_SYNC_
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2015-03-18 05:16:28 -07:00
|
|
|
#include "srslte/config.h"
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/sync/sync.h"
|
|
|
|
#include "srslte/sync/cfo.h"
|
2015-04-20 00:25:29 -07:00
|
|
|
#include "srslte/agc/agc.h"
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/ch_estimation/chest_dl.h"
|
|
|
|
#include "srslte/phch/pbch.h"
|
2015-03-18 11:14:24 -07:00
|
|
|
#include "srslte/dft/ofdm.h"
|
2015-03-18 05:31:13 -07:00
|
|
|
#include "srslte/common/timestamp.h"
|
|
|
|
#include "srslte/io/filesource.h"
|
2014-07-21 07:19:17 -07:00
|
|
|
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
typedef enum SRSLTE_API { SF_FIND, SF_TRACK} srslte_ue_sync_state_t;
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2014-11-17 05:04:30 -08:00
|
|
|
//#define MEASURE_EXEC_TIME
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
typedef struct SRSLTE_API {
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_sync_t sfind;
|
|
|
|
srslte_sync_t strack;
|
2015-04-20 00:25:29 -07:00
|
|
|
|
|
|
|
srslte_agc_t agc;
|
|
|
|
bool do_agc;
|
|
|
|
|
2014-07-21 07:19:17 -07:00
|
|
|
void *stream;
|
2015-03-18 08:05:38 -07:00
|
|
|
int (*recv_callback)(void*, void*, uint32_t, srslte_timestamp_t*);
|
|
|
|
srslte_timestamp_t last_timestamp;
|
2015-02-24 02:19:42 -08:00
|
|
|
|
2015-03-18 08:05:38 -07:00
|
|
|
srslte_filesource_t file_source;
|
2015-01-11 20:06:11 -08:00
|
|
|
bool file_mode;
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
srslte_ue_sync_state_t state;
|
2014-07-21 07:19:17 -07:00
|
|
|
|
|
|
|
cf_t *input_buffer;
|
|
|
|
|
2014-12-11 15:04:21 -08:00
|
|
|
uint32_t frame_len;
|
|
|
|
uint32_t fft_size;
|
2015-03-18 11:14:24 -07:00
|
|
|
uint32_t nof_recv_sf; // Number of subframes received each call to srslte_ue_sync_get_buffer
|
2014-12-11 15:04:21 -08:00
|
|
|
uint32_t nof_avg_find_frames;
|
|
|
|
uint32_t frame_find_cnt;
|
|
|
|
uint32_t sf_len;
|
|
|
|
|
2014-07-21 07:19:17 -07:00
|
|
|
/* These count half frames (5ms) */
|
|
|
|
uint64_t frame_ok_cnt;
|
|
|
|
uint32_t frame_no_cnt;
|
|
|
|
uint32_t frame_total_cnt;
|
|
|
|
|
|
|
|
/* this is the system frame number (SFN) */
|
|
|
|
uint32_t frame_number;
|
|
|
|
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_cell_t cell;
|
2014-07-21 07:19:17 -07:00
|
|
|
uint32_t sf_idx;
|
2014-12-09 15:29:48 -08:00
|
|
|
|
2014-07-21 07:19:17 -07:00
|
|
|
bool decode_sss_on_track;
|
2015-03-23 08:03:06 -07:00
|
|
|
bool correct_cfo;
|
2014-07-21 07:19:17 -07:00
|
|
|
|
|
|
|
uint32_t peak_idx;
|
|
|
|
int time_offset;
|
|
|
|
float mean_time_offset;
|
2014-12-11 15:04:21 -08:00
|
|
|
|
2014-07-21 07:19:17 -07:00
|
|
|
#ifdef MEASURE_EXEC_TIME
|
|
|
|
float mean_exec_time;
|
|
|
|
#endif
|
2015-03-18 11:14:24 -07:00
|
|
|
} srslte_ue_sync_t;
|
2014-07-21 07:19:17 -07:00
|
|
|
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API int srslte_ue_sync_init(srslte_ue_sync_t *q,
|
|
|
|
srslte_cell_t cell,
|
|
|
|
int (recv_callback)(void*, void*, uint32_t, srslte_timestamp_t*),
|
|
|
|
void *stream_handler);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API int srslte_ue_sync_init_file(srslte_ue_sync_t *q,
|
|
|
|
uint32_t nof_prb,
|
|
|
|
char *file_name);
|
2015-01-11 20:06:11 -08:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_ue_sync_free(srslte_ue_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-04-20 00:25:29 -07:00
|
|
|
SRSLTE_API int srslte_ue_sync_start_agc(srslte_ue_sync_t *q,
|
2015-04-21 12:05:51 -07:00
|
|
|
double (set_gain_callback)(void*, double),
|
|
|
|
float init_gain_value);
|
2015-04-20 00:25:29 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API uint32_t srslte_ue_sync_sf_len(srslte_ue_sync_t *q);
|
2014-10-24 03:06:04 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API int srslte_ue_sync_get_buffer(srslte_ue_sync_t *q,
|
|
|
|
cf_t **sf_symbols);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-04-14 01:41:17 -07:00
|
|
|
SRSLTE_API void srslte_ue_sync_set_cfo(srslte_ue_sync_t *q,
|
|
|
|
float cfo);
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_ue_sync_reset(srslte_ue_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-19 08:42:31 -07:00
|
|
|
SRSLTE_API void srslte_ue_sync_set_N_id_2(srslte_ue_sync_t *q,
|
2015-03-18 11:14:24 -07:00
|
|
|
uint32_t N_id_2);
|
2014-12-11 15:04:21 -08:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_ue_sync_decode_sss_on_track(srslte_ue_sync_t *q,
|
|
|
|
bool enabled);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API srslte_ue_sync_state_t srslte_ue_sync_get_state(srslte_ue_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API uint32_t srslte_ue_sync_get_sfidx(srslte_ue_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API float srslte_ue_sync_get_cfo(srslte_ue_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API float srslte_ue_sync_get_sfo(srslte_ue_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_ue_sync_get_last_timestamp(srslte_ue_sync_t *q,
|
|
|
|
srslte_timestamp_t *timestamp);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SYNC_FRAME_
|
|
|
|
|