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.
177 lines
4.5 KiB
C++
177 lines
4.5 KiB
C++
10 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2013-2014 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
|
||
|
* it under the terms of the GNU Lesser 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
|
||
|
* GNU Lesser General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Lesser 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/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <unistd.h>
|
||
|
|
||
10 years ago
|
#include "srslte/utils/debug.h"
|
||
10 years ago
|
#include "srsapps/ue/phy/phy.h"
|
||
|
#include "srsapps/common/tti_sync_cv.h"
|
||
|
#include "srsapps/radio/radio_uhd.h"
|
||
10 years ago
|
|
||
|
|
||
|
/**********************************************************************
|
||
|
* Program arguments processing
|
||
|
***********************************************************************/
|
||
|
typedef struct {
|
||
|
float uhd_freq;
|
||
|
float uhd_gain;
|
||
|
}prog_args_t;
|
||
|
|
||
|
void args_default(prog_args_t *args) {
|
||
|
args->uhd_freq = -1.0;
|
||
|
args->uhd_gain = 60.0;
|
||
|
}
|
||
|
|
||
|
void usage(prog_args_t *args, char *prog) {
|
||
|
printf("Usage: %s [gv] -f rx_frequency (in Hz)\n", prog);
|
||
|
printf("\t-g UHD RX gain [Default %.2f dB]\n", args->uhd_gain);
|
||
|
printf("\t-v [increase verbosity, default none]\n");
|
||
|
}
|
||
|
|
||
|
void parse_args(prog_args_t *args, int argc, char **argv) {
|
||
|
int opt;
|
||
|
args_default(args);
|
||
|
while ((opt = getopt(argc, argv, "gfv")) != -1) {
|
||
|
switch (opt) {
|
||
|
case 'g':
|
||
|
args->uhd_gain = atof(argv[optind]);
|
||
|
break;
|
||
|
case 'f':
|
||
|
args->uhd_freq = atof(argv[optind]);
|
||
|
break;
|
||
|
case 'v':
|
||
|
srslte_verbose++;
|
||
|
break;
|
||
|
default:
|
||
|
usage(args, argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
if (args->uhd_freq < 0) {
|
||
|
usage(args, argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
10 years ago
|
srslte::ue::phy phy;
|
||
|
|
||
10 years ago
|
uint32_t total_pkts=0;
|
||
|
uint32_t total_dci=0;
|
||
|
uint32_t total_errors=0;
|
||
10 years ago
|
uint8_t payload[1024];
|
||
|
|
||
10 years ago
|
// This is the MAC implementation
|
||
10 years ago
|
void run_tti(uint32_t tti) {
|
||
10 years ago
|
srslte::ue::dl_sched_grant grant(SRSLTE_SIRNTI);
|
||
10 years ago
|
INFO("MAC running tti: %d\n", tti);
|
||
10 years ago
|
|
||
10 years ago
|
// SIB1 is scheduled in subframe #5 of even frames
|
||
10 years ago
|
if ((phy.tti_to_SFN(tti)%2) == 0 && phy.tti_to_subf(tti) == 5) {
|
||
10 years ago
|
// Get buffer
|
||
|
srslte::ue::dl_buffer *buffer = phy.get_dl_buffer(tti);
|
||
|
|
||
|
// Get DL grant
|
||
10 years ago
|
if (buffer->get_dl_grant(&grant))
|
||
10 years ago
|
{
|
||
10 years ago
|
total_dci++;
|
||
10 years ago
|
// MAC sets RV
|
||
10 years ago
|
grant.set_rv(((uint32_t) ceilf((float)3*((phy.tti_to_SFN(tti)/2)%4)/2))%4);
|
||
10 years ago
|
|
||
10 years ago
|
// Decode packet
|
||
10 years ago
|
if (!buffer->decode_data(&grant, payload)) {
|
||
10 years ago
|
total_errors++;
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
total_pkts++;
|
||
10 years ago
|
}
|
||
10 years ago
|
if (srslte_verbose == SRSLTE_VERBOSE_NONE) {
|
||
|
printf("PDCCH BLER %.1f \%% PDSCH BLER %.1f \%% (total pkts: %5u) \r",
|
||
|
100-(float) 100*total_dci/total_pkts,
|
||
|
(float) 100*total_errors/total_pkts,
|
||
10 years ago
|
total_pkts);
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
10 years ago
|
srslte_cell_t cell;
|
||
10 years ago
|
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
|
||
10 years ago
|
prog_args_t prog_args;
|
||
10 years ago
|
srslte::ue::tti_sync_cv ttisync(10240);
|
||
10 years ago
|
srslte::radio_uhd radio_uhd;
|
||
10 years ago
|
|
||
|
parse_args(&prog_args, argc, argv);
|
||
|
|
||
10 years ago
|
// Init Radio
|
||
|
radio_uhd.init();
|
||
|
|
||
10 years ago
|
// Init PHY
|
||
10 years ago
|
phy.init(&radio_uhd, &ttisync);
|
||
10 years ago
|
|
||
|
// Give it time to create thread
|
||
10 years ago
|
sleep(1);
|
||
|
|
||
10 years ago
|
// Set default parameters
|
||
|
phy.set_param(srslte::ue::phy_params::PRACH_CONFIG_INDEX, 0);
|
||
|
phy.set_param(srslte::ue::phy_params::PRACH_ROOT_SEQ_IDX, 0);
|
||
|
phy.set_param(srslte::ue::phy_params::PRACH_HIGH_SPEED_FLAG, 0);
|
||
|
phy.set_param(srslte::ue::phy_params::PRACH_ZC_CONFIG, 1);
|
||
|
|
||
10 years ago
|
// Set RX freq and gain
|
||
10 years ago
|
phy.get_radio()->set_rx_freq(prog_args.uhd_freq);
|
||
|
phy.get_radio()->set_rx_gain(prog_args.uhd_gain);
|
||
10 years ago
|
|
||
10 years ago
|
/* Instruct the PHY to decode BCH */
|
||
10 years ago
|
if (!phy.decode_mib_best(&cell, bch_payload)) {
|
||
10 years ago
|
exit(-1);
|
||
|
}
|
||
10 years ago
|
// Print MIB
|
||
10 years ago
|
srslte_cell_fprint(stdout, &cell, phy.get_current_tti()/10);
|
||
10 years ago
|
|
||
10 years ago
|
// Set the current PHY cell to the detected cell
|
||
|
if (!phy.set_cell(cell)) {
|
||
|
printf("Error setting cell\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
10 years ago
|
/* Instruct the PHY to start RX streaming and synchronize */
|
||
10 years ago
|
if (!phy.start_rxtx()) {
|
||
10 years ago
|
printf("Could not start RX\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
/* go to idle and process each tti */
|
||
|
while(1) {
|
||
10 years ago
|
uint32_t tti = ttisync.wait();
|
||
|
run_tti(tti);
|
||
10 years ago
|
}
|
||
|
}
|