srsLTE/srslte/include/srslte/ue/ue_sync.h

167 lines
5.1 KiB
C
Raw Normal View History

/**
*
* \section COPYRIGHT
*
2015-05-08 08:05:40 -07:00
* Copyright 2013-2015 The srsLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the srsLTE library.
*
* 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
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsLTE is distributed in the hope that it will be useful,
* 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.
*
2015-05-08 08:05:40 -07:00
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
/******************************************************************************
* 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:
*****************************************************************************/
#ifndef UE_SYNC_
#define UE_SYNC_
#include <stdbool.h>
#include "srslte/config.h"
#include "srslte/sync/sync.h"
#include "srslte/sync/cfo.h"
2015-04-20 00:25:29 -07:00
#include "srslte/agc/agc.h"
#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"
#include "srslte/common/timestamp.h"
#include "srslte/io/filesource.h"
2015-03-18 11:14:24 -07:00
typedef enum SRSLTE_API { SF_FIND, SF_TRACK} srslte_ue_sync_state_t;
//#define MEASURE_EXEC_TIME
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;
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-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;
cf_t *input_buffer;
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
uint32_t nof_avg_find_frames;
uint32_t frame_find_cnt;
uint32_t sf_len;
/* 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;
uint32_t sf_idx;
2014-12-09 15:29:48 -08:00
bool decode_sss_on_track;
bool correct_cfo;
uint32_t peak_idx;
int time_offset;
float mean_time_offset;
#ifdef MEASURE_EXEC_TIME
float mean_exec_time;
#endif
2015-03-18 11:14:24 -07:00
} srslte_ue_sync_t;
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);
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);
2015-04-20 00:25:29 -07:00
SRSLTE_API int srslte_ue_sync_start_agc(srslte_ue_sync_t *q,
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);
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);
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);
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);
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);
2015-03-18 11:14:24 -07:00
SRSLTE_API uint32_t srslte_ue_sync_get_sfidx(srslte_ue_sync_t *q);
2015-03-18 11:14:24 -07:00
SRSLTE_API float srslte_ue_sync_get_cfo(srslte_ue_sync_t *q);
2015-03-18 11:14:24 -07:00
SRSLTE_API float srslte_ue_sync_get_sfo(srslte_ue_sync_t *q);
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);
#endif // SYNC_FRAME_