mirror of https://github.com/pvnis/srsRAN_4G.git
Added bladeRF API skeleton. Moved uhd code into rf_uhd
parent
ba5b14ee3d
commit
96f7639ea0
@ -0,0 +1,153 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \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 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <libbladeRF.h>
|
||||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "srslte/srslte.h"
|
||||
#include "rf_blade_imp.h"
|
||||
#include "srslte/rf/rf.h"
|
||||
|
||||
typedef struct {
|
||||
} rf_blade_handler_t;
|
||||
|
||||
|
||||
void rf_blade_suppress_stdout(void *h) {
|
||||
}
|
||||
|
||||
void rf_blade_register_msg_handler(void *notused, rf_msg_handler_t new_handler)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool rf_blade_rx_wait_lo_locked(void *h)
|
||||
{
|
||||
}
|
||||
|
||||
int rf_blade_start_rx_stream(void *h)
|
||||
{
|
||||
}
|
||||
|
||||
int rf_blade_stop_rx_stream(void *h)
|
||||
{
|
||||
}
|
||||
|
||||
void rf_blade_flush_buffer(void *h)
|
||||
{
|
||||
}
|
||||
|
||||
bool rf_blade_has_rssi(void *h) {
|
||||
}
|
||||
|
||||
float rf_blade_get_rssi(void *h) {
|
||||
}
|
||||
|
||||
double rf_blade_set_rx_gain_th(void *h, double gain)
|
||||
{
|
||||
}
|
||||
|
||||
void rf_blade_set_tx_rx_gain_offset(void *h, double offset) {
|
||||
}
|
||||
|
||||
/* This thread listens for set_rx_gain commands to the USRP */
|
||||
static void* thread_gain_fcn(void *h) {
|
||||
}
|
||||
|
||||
int rf_blade_open(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int rf_blade_close(void *h)
|
||||
{
|
||||
}
|
||||
|
||||
void rf_blade_set_master_clock_rate(void *h, double rate) {
|
||||
}
|
||||
|
||||
bool rf_blade_is_master_clock_dynamic(void *h) {
|
||||
}
|
||||
|
||||
double rf_blade_set_rx_srate(void *h, double freq)
|
||||
{
|
||||
}
|
||||
|
||||
double rf_blade_set_tx_srate(void *h, double freq)
|
||||
{
|
||||
}
|
||||
|
||||
double rf_blade_set_rx_gain(void *h, double gain)
|
||||
{
|
||||
}
|
||||
|
||||
double rf_blade_set_tx_gain(void *h, double gain)
|
||||
{
|
||||
}
|
||||
|
||||
double rf_blade_get_rx_gain(void *h)
|
||||
{
|
||||
}
|
||||
|
||||
double rf_blade_get_tx_gain(void *h)
|
||||
{
|
||||
}
|
||||
|
||||
double rf_blade_set_rx_freq(void *h, double freq)
|
||||
{
|
||||
}
|
||||
|
||||
double rf_blade_set_tx_freq(void *h, double freq)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void rf_blade_get_time(void *h, time_t *secs, double *frac_secs) {
|
||||
}
|
||||
|
||||
int rf_blade_recv_with_time(void *h,
|
||||
void *data,
|
||||
uint32_t nsamples,
|
||||
bool blocking,
|
||||
time_t *secs,
|
||||
double *frac_secs)
|
||||
{
|
||||
}
|
||||
|
||||
int rf_blade_send_timed(void *h,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool has_time_spec,
|
||||
bool blocking,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst)
|
||||
{
|
||||
}
|
||||
|
@ -0,0 +1,116 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \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 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/rf/rf.h"
|
||||
|
||||
SRSLTE_API int rf_blade_open(char *args,
|
||||
void **handler,
|
||||
bool agc_thread,
|
||||
bool tx_gain_same_rx);
|
||||
|
||||
SRSLTE_API int rf_blade_close(void *h);
|
||||
|
||||
SRSLTE_API int rf_blade_start_rx_stream(void *h);
|
||||
|
||||
SRSLTE_API int rf_blade_start_rx_stream_nsamples(void *h,
|
||||
uint32_t nsamples);
|
||||
|
||||
SRSLTE_API int rf_blade_stop_rx_stream(void *h);
|
||||
|
||||
SRSLTE_API void rf_blade_flush_buffer(void *h);
|
||||
|
||||
SRSLTE_API bool rf_blade_has_rssi(void *h);
|
||||
|
||||
SRSLTE_API float rf_blade_get_rssi(void *h);
|
||||
|
||||
SRSLTE_API bool rf_blade_rx_wait_lo_locked(void *h);
|
||||
|
||||
SRSLTE_API void rf_blade_set_master_clock_rate(void *h,
|
||||
double rate);
|
||||
|
||||
SRSLTE_API bool rf_blade_is_master_clock_dynamic(void *h);
|
||||
|
||||
SRSLTE_API double rf_blade_set_rx_srate(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API double rf_blade_set_rx_gain(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API void rf_blade_set_tx_rx_gain_offset(void *h,
|
||||
double offset);
|
||||
|
||||
SRSLTE_API double rf_blade_set_rx_gain_th(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API double rf_blade_set_tx_gain_th(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API float rf_blade_get_rx_gain_offset(void *h);
|
||||
|
||||
SRSLTE_API double rf_blade_get_rx_gain(void *h);
|
||||
|
||||
SRSLTE_API double rf_blade_get_tx_gain(void *h);
|
||||
|
||||
SRSLTE_API void rf_blade_suppress_stdout(void *h);
|
||||
|
||||
SRSLTE_API void rf_blade_register_msg_handler(void *h, rf_msg_handler_t msg_handler);
|
||||
|
||||
SRSLTE_API double rf_blade_set_rx_freq(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API int rf_blade_recv_with_time(void *h,
|
||||
void *data,
|
||||
uint32_t nsamples,
|
||||
bool blocking,
|
||||
time_t *secs,
|
||||
double *frac_secs);
|
||||
|
||||
SRSLTE_API double rf_blade_set_tx_srate(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API double rf_blade_set_tx_gain(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API double rf_blade_set_tx_freq(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API void rf_blade_get_time(void *h,
|
||||
time_t *secs,
|
||||
double *frac_secs);
|
||||
|
||||
SRSLTE_API int rf_blade_send_timed(void *h,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool has_time_spec,
|
||||
bool blocking,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst);
|
||||
|
||||
|
@ -0,0 +1,139 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \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 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* RF frontend API */
|
||||
typedef struct {
|
||||
const char *name;
|
||||
bool (*rf_rx_wait_lo_locked) (void*);
|
||||
int (*rf_start_rx_stream)(void *h);
|
||||
int (*rf_stop_rx_stream)(void *h);
|
||||
void (*rf_flush_buffer)(void *h);
|
||||
bool (*rf_has_rssi)(void *h);
|
||||
float (*rf_get_rssi)(void *h);
|
||||
double (*rf_set_rx_gain_th)(void *h, double gain);
|
||||
void (*rf_set_tx_rx_gain_offset)(void *h, double offset);
|
||||
void (*rf_suppress_stdout)(void *h);
|
||||
void (*rf_register_msg_handler)(void *h, rf_msg_handler_t msg_handler);
|
||||
int (*rf_open)(char *args, void **h, bool agc_thread, bool tx_gain_same_rx);
|
||||
int (*rf_close)(void *h);
|
||||
void (*rf_set_master_clock_rate)(void *h, double rate);
|
||||
bool (*rf_is_master_clock_dynamic)(void *h);
|
||||
double (*rf_set_rx_srate)(void *h, double freq);
|
||||
double (*rf_set_rx_gain)(void *h, double gain);
|
||||
double (*rf_set_tx_gain)(void *h, double gain);
|
||||
double (*rf_get_rx_gain)(void *h);
|
||||
double (*rf_get_tx_gain)(void *h);
|
||||
double (*rf_set_rx_freq)(void *h, double freq);
|
||||
double (*rf_set_tx_srate)(void *h, double freq);
|
||||
double (*rf_set_tx_freq)(void *h, double freq);
|
||||
void (*rf_get_time)(void *h, time_t *secs, double *frac_secs);
|
||||
int (*rf_recv_with_time)(void *h, void *data, uint32_t nsamples,
|
||||
bool blocking, time_t *secs,double *frac_secs);
|
||||
int (*rf_send_timed)(void *h, void *data, int nsamples,
|
||||
time_t secs, double frac_secs, bool has_time_spec,
|
||||
bool blocking, bool is_start_of_burst, bool is_end_of_burst);
|
||||
} rf_dev_t;
|
||||
|
||||
/* Define implementation for UHD */
|
||||
#ifdef ENABLE_UHD
|
||||
|
||||
#include "rf_uhd_imp.h"
|
||||
|
||||
static rf_dev_t dev_uhd = {
|
||||
"UHD",
|
||||
rf_uhd_rx_wait_lo_locked,
|
||||
rf_uhd_start_rx_stream,
|
||||
rf_uhd_stop_rx_stream,
|
||||
rf_uhd_flush_buffer,
|
||||
rf_uhd_has_rssi,
|
||||
rf_uhd_get_rssi,
|
||||
rf_uhd_set_rx_gain_th,
|
||||
rf_uhd_set_tx_rx_gain_offset,
|
||||
rf_uhd_suppress_stdout,
|
||||
rf_uhd_register_msg_handler,
|
||||
rf_uhd_open,
|
||||
rf_uhd_close,
|
||||
rf_uhd_set_master_clock_rate,
|
||||
rf_uhd_is_master_clock_dynamic,
|
||||
rf_uhd_set_rx_srate,
|
||||
rf_uhd_set_rx_gain,
|
||||
rf_uhd_set_tx_gain,
|
||||
rf_uhd_get_rx_gain,
|
||||
rf_uhd_get_tx_gain,
|
||||
rf_uhd_set_rx_freq,
|
||||
rf_uhd_set_tx_srate,
|
||||
rf_uhd_set_tx_freq,
|
||||
rf_uhd_get_time,
|
||||
rf_uhd_recv_with_time,
|
||||
rf_uhd_send_timed
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Define implementation for bladeRF */
|
||||
#ifdef ENABLE_BLADERF
|
||||
|
||||
#include "rf_blade_imp.h"
|
||||
|
||||
static rf_dev_t dev_blade = {
|
||||
"bladeRF",
|
||||
rf_blade_rx_wait_lo_locked,
|
||||
rf_blade_start_rx_stream,
|
||||
rf_blade_stop_rx_stream,
|
||||
rf_blade_flush_buffer,
|
||||
rf_blade_has_rssi,
|
||||
rf_blade_get_rssi,
|
||||
rf_blade_set_rx_gain_th,
|
||||
rf_blade_set_tx_rx_gain_offset,
|
||||
rf_blade_suppress_stdout,
|
||||
rf_blade_register_msg_handler,
|
||||
rf_blade_open,
|
||||
rf_blade_close,
|
||||
rf_blade_set_master_clock_rate,
|
||||
rf_blade_is_master_clock_dynamic,
|
||||
rf_blade_set_rx_srate,
|
||||
rf_blade_set_rx_gain,
|
||||
rf_blade_set_tx_gain,
|
||||
rf_blade_get_rx_gain,
|
||||
rf_blade_get_tx_gain,
|
||||
rf_blade_set_rx_freq,
|
||||
rf_blade_set_tx_srate,
|
||||
rf_blade_set_tx_freq,
|
||||
rf_blade_get_time,
|
||||
rf_blade_recv_with_time,
|
||||
rf_blade_send_timed
|
||||
};
|
||||
#endif
|
||||
|
||||
static rf_dev_t *available_devices[] = {
|
||||
#ifdef ENABLE_UHD
|
||||
&dev_uhd,
|
||||
#endif
|
||||
#ifdef ENABLE_BLADERF
|
||||
&dev_blade,
|
||||
#endif
|
||||
NULL
|
||||
};
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <uhd/usrp/multi_usrp.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
class rf_handler {
|
||||
public:
|
||||
uhd::usrp::multi_usrp::sptr usrp;
|
||||
uhd::rx_streamer::sptr rx_stream;
|
||||
bool rx_stream_enable;
|
||||
uhd::tx_streamer::sptr tx_stream;
|
||||
|
||||
// The following variables are for threaded RX gain control
|
||||
pthread_t thread_gain;
|
||||
pthread_cond_t cond;
|
||||
pthread_mutex_t mutex;
|
||||
double cur_rx_gain;
|
||||
double new_rx_gain;
|
||||
double cur_tx_gain;
|
||||
double new_tx_gain;
|
||||
bool tx_gain_same_rx;
|
||||
float tx_rx_gain_offset;
|
||||
uhd::gain_range_t rx_gain_range;
|
||||
uhd::gain_range_t tx_gain_range;
|
||||
size_t rx_nof_samples;
|
||||
size_t tx_nof_samples;
|
||||
double tx_rate;
|
||||
bool dynamic_rate;
|
||||
};
|
@ -0,0 +1,238 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \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 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "srslte/rf/rf.h"
|
||||
#include "srslte/srslte.h"
|
||||
#include "rf_dev.h"
|
||||
|
||||
bool rf_rx_wait_lo_locked(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_rx_wait_lo_locked(rf->handler);
|
||||
}
|
||||
|
||||
int rf_start_rx_stream(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_start_rx_stream(rf->handler);
|
||||
}
|
||||
|
||||
int rf_stop_rx_stream(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_stop_rx_stream(rf->handler);
|
||||
}
|
||||
|
||||
void rf_flush_buffer(rf_t *rf)
|
||||
{
|
||||
((rf_dev_t*) rf->dev)->rf_flush_buffer(rf->handler);
|
||||
}
|
||||
|
||||
bool rf_has_rssi(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_has_rssi(rf->handler);
|
||||
}
|
||||
|
||||
float rf_get_rssi(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_get_rssi(rf->handler);
|
||||
}
|
||||
|
||||
double rf_set_rx_gain_th(rf_t *rf, double gain)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_set_rx_gain_th(rf->handler, gain);
|
||||
}
|
||||
|
||||
void rf_set_tx_rx_gain_offset(rf_t *rf, double offset)
|
||||
{
|
||||
((rf_dev_t*) rf->dev)->rf_set_tx_rx_gain_offset(rf->handler, offset);
|
||||
}
|
||||
|
||||
void rf_suppress_stdout(rf_t *rf)
|
||||
{
|
||||
((rf_dev_t*) rf->dev)->rf_suppress_stdout(rf->handler);
|
||||
}
|
||||
|
||||
void rf_register_msg_handler(rf_t *rf, rf_msg_handler_t msg_handler)
|
||||
{
|
||||
((rf_dev_t*) rf->dev)->rf_register_msg_handler(rf->handler, msg_handler);
|
||||
}
|
||||
|
||||
int rf_open_devname(rf_t *rf, char *devname, char *args, bool agc_thread, bool tx_gain_same_rx) {
|
||||
/* Try to open the device if name is provided */
|
||||
if (devname) {
|
||||
int i=0;
|
||||
while(available_devices[i] != NULL) {
|
||||
if (!strcmp(available_devices[i]->name, devname)) {
|
||||
rf->dev = &available_devices[i];
|
||||
return available_devices[i]->rf_open(args, &rf->handler, agc_thread, tx_gain_same_rx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If in auto mode, try to open in order of apperance in available_devices[] array */
|
||||
int i=0;
|
||||
while(available_devices[i] != NULL) {
|
||||
if (!available_devices[i]->rf_open(args, &rf->handler, agc_thread, tx_gain_same_rx)) {
|
||||
rf->dev = &available_devices[i];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "No compatible RF frontend found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rf_open(rf_t *h, char *args)
|
||||
{
|
||||
return rf_open_devname(h, NULL, args, false, false);
|
||||
}
|
||||
|
||||
int rf_open_th(rf_t *h, char *args, bool tx_gain_same_rx)
|
||||
{
|
||||
return rf_open_devname(h, NULL, args, false, tx_gain_same_rx);
|
||||
}
|
||||
|
||||
int rf_close(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_close(rf->handler);
|
||||
}
|
||||
|
||||
void rf_set_master_clock_rate(rf_t *rf, double rate)
|
||||
{
|
||||
((rf_dev_t*) rf->dev)->rf_set_master_clock_rate(rf->handler, rate);
|
||||
}
|
||||
|
||||
bool rf_is_master_clock_dynamic(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_is_master_clock_dynamic(rf->handler);
|
||||
}
|
||||
|
||||
double rf_set_rx_srate(rf_t *rf, double freq)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_set_rx_srate(rf->handler, freq);
|
||||
}
|
||||
|
||||
double rf_set_rx_gain(rf_t *rf, double gain)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_set_rx_gain(rf->handler, gain);
|
||||
}
|
||||
|
||||
double rf_get_rx_gain(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_get_rx_gain(rf->handler);
|
||||
}
|
||||
|
||||
double rf_get_tx_gain(rf_t *rf)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_get_tx_gain(rf->handler);
|
||||
}
|
||||
|
||||
double rf_set_rx_freq(rf_t *rf, double freq)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_set_rx_freq(rf->handler, freq);
|
||||
}
|
||||
|
||||
|
||||
int rf_recv(rf_t *rf, void *data, uint32_t nsamples, bool blocking)
|
||||
{
|
||||
return rf_recv_with_time(rf, data, nsamples, blocking, NULL, NULL);
|
||||
}
|
||||
|
||||
int rf_recv_with_time(rf_t *rf,
|
||||
void *data,
|
||||
uint32_t nsamples,
|
||||
bool blocking,
|
||||
time_t *secs,
|
||||
double *frac_secs)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_recv_with_time(rf->handler, data, nsamples, blocking, secs, frac_secs);
|
||||
}
|
||||
|
||||
double rf_set_tx_gain(rf_t *rf, double gain)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_set_tx_gain(rf->handler, gain);
|
||||
}
|
||||
|
||||
double rf_set_tx_srate(rf_t *rf, double freq)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_set_tx_srate(rf->handler, freq);
|
||||
}
|
||||
|
||||
double rf_set_tx_freq(rf_t *rf, double freq)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_set_tx_freq(rf->handler, freq);
|
||||
}
|
||||
|
||||
void rf_get_time(rf_t *rf, time_t *secs, double *frac_secs)
|
||||
{
|
||||
return ((rf_dev_t*) rf->dev)->rf_get_time(rf->handler, secs, frac_secs);
|
||||
}
|
||||
|
||||
|
||||
int rf_send_timed3(rf_t *rf,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool has_time_spec,
|
||||
bool blocking,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst)
|
||||
{
|
||||
|
||||
return ((rf_dev_t*) rf->dev)->rf_send_timed(rf->handler, data, nsamples, secs, frac_secs,
|
||||
has_time_spec, blocking, is_start_of_burst, is_end_of_burst);
|
||||
}
|
||||
|
||||
int rf_send(rf_t *rf, void *data, uint32_t nsamples, bool blocking)
|
||||
{
|
||||
return rf_send2(rf, data, nsamples, blocking, true, true);
|
||||
}
|
||||
|
||||
int rf_send2(rf_t *rf, void *data, uint32_t nsamples, bool blocking, bool start_of_burst, bool end_of_burst)
|
||||
{
|
||||
return rf_send_timed3(rf, data, nsamples, 0, 0, false, blocking, start_of_burst, end_of_burst);
|
||||
}
|
||||
|
||||
|
||||
int rf_send_timed(rf_t *rf,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs)
|
||||
{
|
||||
return rf_send_timed2(rf, data, nsamples, secs, frac_secs, true, true);
|
||||
}
|
||||
|
||||
int rf_send_timed2(rf_t *rf,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst)
|
||||
{
|
||||
return rf_send_timed3(rf, data, nsamples, secs, frac_secs, true, true, is_start_of_burst, is_end_of_burst);
|
||||
}
|
@ -1,521 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \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 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <uhd/utils/thread_priority.hpp>
|
||||
#include <uhd/usrp/multi_usrp.hpp>
|
||||
#include <iostream>
|
||||
#include <complex>
|
||||
#include <cstdio>
|
||||
#include <uhd/utils/msg.hpp>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "rf_handler.hpp"
|
||||
#include "srslte/rf/rf.h"
|
||||
#include "srslte/srslte.h"
|
||||
|
||||
//#define METADATA_VERBOSE
|
||||
|
||||
rf_msg_handler_t msg_handler;
|
||||
|
||||
void suppress_handler(uhd::msg::type_t type, const std::string & msg)
|
||||
{
|
||||
//handle the message...
|
||||
}
|
||||
|
||||
void translate_handler(uhd::msg::type_t type, const std::string & msg)
|
||||
{
|
||||
if(msg_handler)
|
||||
msg_handler(msg.c_str());
|
||||
}
|
||||
|
||||
typedef _Complex float complex_t;
|
||||
|
||||
#define SAMPLE_SZ sizeof(complex_t)
|
||||
|
||||
bool isLocked(void *h)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
std::vector < std::string > mb_sensors =
|
||||
handler->usrp->get_mboard_sensor_names();
|
||||
std::vector < std::string > rx_sensors =
|
||||
handler->usrp->get_rx_sensor_names(0);
|
||||
if (std::find(rx_sensors.begin(), rx_sensors.end(), "lo_locked") !=
|
||||
rx_sensors.end()) {
|
||||
return handler->usrp->get_rx_sensor("lo_locked", 0).to_bool();
|
||||
} else if (std::find(mb_sensors.begin(), mb_sensors.end(), "ref_locked") !=
|
||||
mb_sensors.end()) {
|
||||
return handler->usrp->get_mboard_sensor("ref_locked", 0).to_bool();
|
||||
} else {
|
||||
usleep(500);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool rf_rx_wait_lo_locked(void *h)
|
||||
{
|
||||
|
||||
double report = 0.0;
|
||||
while (isLocked(h) && report < 30.0) {
|
||||
report += 0.1;
|
||||
usleep(1000);
|
||||
}
|
||||
return isLocked(h);
|
||||
}
|
||||
|
||||
int rf_start_rx_stream(void *h)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
|
||||
cmd.time_spec = handler->usrp->get_time_now();
|
||||
cmd.stream_now = true;
|
||||
handler->usrp->issue_stream_cmd(cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rf_stop_rx_stream(void *h)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
|
||||
cmd.time_spec = handler->usrp->get_time_now();
|
||||
cmd.stream_now = true;
|
||||
handler->usrp->issue_stream_cmd(cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rf_flush_buffer(void *h)
|
||||
{
|
||||
int n;
|
||||
_Complex float tmp[1024];
|
||||
do {
|
||||
n = rf_recv(h, tmp, 1024, 0);
|
||||
} while (n > 0);
|
||||
}
|
||||
|
||||
bool rf_has_rssi(void *h) {
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
std::vector < std::string > mb_sensors = handler->usrp->get_mboard_sensor_names();
|
||||
std::vector < std::string > rx_sensors = handler->usrp->get_rx_sensor_names(0);
|
||||
if (std::find(rx_sensors.begin(), rx_sensors.end(), "rssi") != rx_sensors.end()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
float rf_get_rssi(void *h) {
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
if (rf_has_rssi(h)) {
|
||||
uhd::sensor_value_t value = handler->usrp->get_rx_sensor("rssi");
|
||||
return value.to_real();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int rf_start_rx_stream_nsamples(void *h, uint32_t nsamples)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE);
|
||||
cmd.time_spec = handler->usrp->get_time_now();
|
||||
cmd.stream_now = true;
|
||||
cmd.num_samps = nsamples;
|
||||
handler->usrp->issue_stream_cmd(cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
double rf_set_rx_gain_th(void *h, double gain)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
gain = handler->rx_gain_range.clip(gain);
|
||||
if (gain > handler->new_rx_gain + 0.5 || gain < handler->new_rx_gain - 0.5) {
|
||||
pthread_mutex_lock(&handler->mutex);
|
||||
handler->new_rx_gain = gain;
|
||||
pthread_cond_signal(&handler->cond);
|
||||
pthread_mutex_unlock(&handler->mutex);
|
||||
}
|
||||
return gain;
|
||||
}
|
||||
|
||||
double rf_set_tx_gain_th(void *h, double gain)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
gain = handler->tx_gain_range.clip(gain);
|
||||
if (gain > handler->new_tx_gain + 0.5 || gain < handler->new_tx_gain - 0.5) {
|
||||
pthread_mutex_lock(&handler->mutex);
|
||||
handler->new_tx_gain = gain;
|
||||
pthread_cond_signal(&handler->cond);
|
||||
pthread_mutex_unlock(&handler->mutex);
|
||||
}
|
||||
return gain;
|
||||
}
|
||||
|
||||
void rf_set_tx_rx_gain_offset(void *h, double offset) {
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
handler->tx_rx_gain_offset = offset;
|
||||
}
|
||||
|
||||
/* This thread listens for set_rx_gain commands to the USRP */
|
||||
static void* thread_gain_fcn(void *h) {
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
while(1) {
|
||||
pthread_mutex_lock(&handler->mutex);
|
||||
while(handler->cur_rx_gain == handler->new_rx_gain &&
|
||||
handler->cur_tx_gain == handler->new_tx_gain)
|
||||
{
|
||||
pthread_cond_wait(&handler->cond, &handler->mutex);
|
||||
}
|
||||
if (handler->new_rx_gain != handler->cur_rx_gain) {
|
||||
handler->cur_rx_gain = handler->new_rx_gain;
|
||||
rf_set_rx_gain(h, handler->cur_rx_gain);
|
||||
}
|
||||
if (handler->tx_gain_same_rx) {
|
||||
rf_set_tx_gain(h, handler->cur_rx_gain+handler->tx_rx_gain_offset);
|
||||
} else if (handler->new_tx_gain != handler->cur_tx_gain) {
|
||||
handler->cur_tx_gain = handler->new_tx_gain;
|
||||
rf_set_tx_gain(h, handler->cur_tx_gain);
|
||||
}
|
||||
pthread_mutex_unlock(&handler->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
float rf_get_rx_gain_offset(void *h) {
|
||||
return 15;
|
||||
}
|
||||
|
||||
void rf_suppress_stdout() {
|
||||
uhd::msg::register_handler(suppress_handler);
|
||||
}
|
||||
|
||||
void rf_register_msg_handler(rf_msg_handler_t h)
|
||||
{
|
||||
msg_handler = h;
|
||||
uhd::msg::register_handler(translate_handler);
|
||||
}
|
||||
|
||||
int rf_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx)
|
||||
{
|
||||
|
||||
*h = NULL;
|
||||
|
||||
/* Set priority to UHD threads */
|
||||
uhd::set_thread_priority_safe();
|
||||
|
||||
|
||||
/* Get multiusrp handler */
|
||||
rf_handler *handler = new rf_handler();
|
||||
std::string _args = std::string(args);
|
||||
handler->usrp = uhd::usrp::multi_usrp::make(_args);// + ", recv_frame_size=9232,num_recv_frames=64,send_frame_size=9232,num_send_frames=64");
|
||||
|
||||
/* Initialize rx and tx stremers */
|
||||
std::string otw, cpu;
|
||||
otw = "sc16";
|
||||
cpu = "fc32";
|
||||
uhd::stream_args_t stream_args(cpu, otw);
|
||||
handler->rx_stream = handler->usrp->get_rx_stream(stream_args);
|
||||
handler->tx_stream = handler->usrp->get_tx_stream(stream_args);
|
||||
|
||||
handler->rx_nof_samples = handler->rx_stream->get_max_num_samps();
|
||||
handler->tx_nof_samples = handler->tx_stream->get_max_num_samps();
|
||||
|
||||
handler->tx_gain_same_rx = tx_gain_same_rx;
|
||||
handler->tx_rx_gain_offset = 0.0;
|
||||
handler->rx_gain_range = handler->usrp->get_rx_gain_range();
|
||||
handler->tx_gain_range = handler->usrp->get_tx_gain_range();
|
||||
|
||||
/* Create auxiliary thread and mutexes for AGC */
|
||||
if (create_thread_gain) {
|
||||
if (pthread_mutex_init(&handler->mutex, NULL)) {
|
||||
return -1;
|
||||
}
|
||||
if (pthread_cond_init(&handler->cond, NULL)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pthread_create(&handler->thread_gain, NULL, thread_gain_fcn, handler)) {
|
||||
perror("pthread_create");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find out if the master clock rate is configurable */
|
||||
double cur_clock = handler->usrp->get_master_clock_rate();
|
||||
printf("Trying to dynamically change Master clock...\n");
|
||||
handler->usrp->set_master_clock_rate(cur_clock/2);
|
||||
if (handler->usrp->get_master_clock_rate() == cur_clock) {
|
||||
handler->dynamic_rate = false;
|
||||
/* Master clock rate is not configurable. Check if it is compatible with LTE */
|
||||
int cur_clock_i = (int) cur_clock;
|
||||
if (cur_clock_i % 1920000) {
|
||||
fprintf(stderr, "Error: LTE sampling rates are not supported. Master clock rate is %.1f MHz\n", cur_clock/1e6);
|
||||
return -1;
|
||||
} else {
|
||||
printf("Master clock is not configurable. Using standard symbol sizes and sampling rates.\n");
|
||||
srslte_use_standard_symbol_size(true);
|
||||
}
|
||||
} else {
|
||||
printf("Master clock is configurable. Using reduced symbol sizes and sampling rates.\n");
|
||||
handler->dynamic_rate = true;
|
||||
}
|
||||
|
||||
*h = handler;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rf_open(char *args, void **h) {
|
||||
return rf_open_(args, h, false, false);
|
||||
}
|
||||
|
||||
int rf_open_th(char *args, void **h, bool tx_gain_same_rx) {
|
||||
return rf_open_(args, h, true, tx_gain_same_rx);
|
||||
}
|
||||
|
||||
|
||||
int rf_close(void *h)
|
||||
{
|
||||
rf_stop_rx_stream(h);
|
||||
/** Something else to close the USRP?? */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rf_set_master_clock_rate(void *h, double rate) {
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
if (handler->dynamic_rate) {
|
||||
handler->usrp->set_master_clock_rate(rate);
|
||||
}
|
||||
}
|
||||
|
||||
bool rf_is_master_clock_dynamic(void *h) {
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
return handler->dynamic_rate;
|
||||
}
|
||||
|
||||
double rf_set_rx_srate(void *h, double freq)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
handler->usrp->set_rx_rate(freq);
|
||||
return handler->usrp->get_rx_rate();
|
||||
}
|
||||
|
||||
double rf_set_rx_gain(void *h, double gain)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
handler->usrp->set_rx_gain(gain);
|
||||
return handler->usrp->get_rx_gain();
|
||||
}
|
||||
|
||||
double rf_get_rx_gain(void *h)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
return handler->usrp->get_rx_gain();
|
||||
}
|
||||
|
||||
double rf_get_tx_gain(void *h)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
return handler->usrp->get_tx_gain();
|
||||
}
|
||||
|
||||
double rf_set_rx_freq(void *h, double freq)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
handler->usrp->set_rx_freq(freq);
|
||||
return freq;
|
||||
}
|
||||
|
||||
double rf_set_rx_freq_offset(void *h, double freq, double off) {
|
||||
rf_handler* handler = static_cast<rf_handler*>(h);
|
||||
handler->usrp->set_rx_freq(uhd::tune_request_t(freq, off));
|
||||
return handler->usrp->get_rx_freq();
|
||||
}
|
||||
|
||||
int rf_recv(void *h, void *data, uint32_t nsamples, bool blocking)
|
||||
{
|
||||
return rf_recv_with_time(h, data, nsamples, blocking, NULL, NULL);
|
||||
}
|
||||
|
||||
int rf_recv_with_time(void *h,
|
||||
void *data,
|
||||
uint32_t nsamples,
|
||||
bool blocking,
|
||||
time_t *secs,
|
||||
double *frac_secs)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
uhd::rx_metadata_t md, md_first;
|
||||
if (blocking) {
|
||||
int n = 0, p;
|
||||
complex_t *data_c = (complex_t *) data;
|
||||
do {
|
||||
size_t rx_samples = handler->rx_nof_samples;
|
||||
if (rx_samples > nsamples - n) {
|
||||
rx_samples = nsamples - n;
|
||||
}
|
||||
p = handler->rx_stream->recv(&data_c[n], rx_samples, n==0?md_first:md);
|
||||
if (p == -1) {
|
||||
return -1;
|
||||
}
|
||||
n += p;
|
||||
#ifdef METADATA_VERBOSE
|
||||
if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE) {
|
||||
std::cout << "\nError code: " << md.to_pp_string() << "\n\n";
|
||||
}
|
||||
#endif
|
||||
} while (n < nsamples &&
|
||||
md.error_code == uhd::rx_metadata_t::ERROR_CODE_NONE);
|
||||
} else {
|
||||
return handler->rx_stream->recv(data, nsamples, md, 0.0);
|
||||
}
|
||||
if (secs) {
|
||||
*secs = md_first.time_spec.get_full_secs();
|
||||
}
|
||||
if (frac_secs) {
|
||||
*frac_secs = md_first.time_spec.get_frac_secs();
|
||||
}
|
||||
return nsamples;
|
||||
}
|
||||
double rf_set_tx_gain(void *h, double gain)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
handler->usrp->set_tx_gain(gain);
|
||||
return gain;
|
||||
}
|
||||
|
||||
double rf_set_tx_srate(void *h, double freq)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
handler->usrp->set_tx_rate(freq);
|
||||
handler->tx_rate = handler->usrp->get_tx_rate();
|
||||
return handler->tx_rate;
|
||||
}
|
||||
|
||||
double rf_set_tx_freq(void *h, double freq)
|
||||
{
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
handler->usrp->set_tx_freq(freq);
|
||||
return handler->usrp->get_tx_freq();
|
||||
}
|
||||
|
||||
|
||||
double rf_set_tx_freq_offset(void *h, double freq, double off) {
|
||||
rf_handler* handler = static_cast<rf_handler*>(h);
|
||||
handler->usrp->set_tx_freq(uhd::tune_request_t(freq, off));
|
||||
return handler->usrp->get_tx_freq();
|
||||
}
|
||||
|
||||
void rf_get_time(void *h, time_t *secs, double *frac_secs) {
|
||||
rf_handler *handler = static_cast < rf_handler * >(h);
|
||||
uhd::time_spec_t now = handler->usrp->get_time_now();
|
||||
if (secs) {
|
||||
*secs = now.get_full_secs();
|
||||
}
|
||||
if (frac_secs) {
|
||||
*frac_secs = now.get_frac_secs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int rf_send_timed3(void *h,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool has_time_spec,
|
||||
bool blocking,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst)
|
||||
{
|
||||
rf_handler* handler = static_cast<rf_handler*>(h);
|
||||
uhd::tx_metadata_t md;
|
||||
md.has_time_spec = has_time_spec;
|
||||
if (has_time_spec) {
|
||||
md.time_spec = uhd::time_spec_t(secs, frac_secs);
|
||||
}
|
||||
|
||||
if (blocking) {
|
||||
int n = 0, p;
|
||||
complex_t *data_c = (complex_t *) data;
|
||||
do {
|
||||
size_t tx_samples = handler->tx_nof_samples;
|
||||
|
||||
// First packet is start of burst if so defined, others are never
|
||||
if (n == 0) {
|
||||
md.start_of_burst = is_start_of_burst;
|
||||
} else {
|
||||
md.start_of_burst = false;
|
||||
}
|
||||
|
||||
// middle packets are never end of burst, last one as defined
|
||||
if (nsamples - n > tx_samples) {
|
||||
md.end_of_burst = false;
|
||||
} else {
|
||||
tx_samples = nsamples - n;
|
||||
md.end_of_burst = is_end_of_burst;
|
||||
}
|
||||
p = handler->tx_stream->send(&data_c[n], tx_samples, md);
|
||||
if (p == -1) {
|
||||
return -1;
|
||||
}
|
||||
// Increase time spec
|
||||
md.time_spec += tx_samples/handler->tx_rate;
|
||||
n += p;
|
||||
} while (n < nsamples);
|
||||
return nsamples;
|
||||
} else {
|
||||
return handler->tx_stream->send(data, nsamples, md, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
int rf_send(void *h, void *data, uint32_t nsamples, bool blocking)
|
||||
{
|
||||
return rf_send2(h, data, nsamples, blocking, true, true);
|
||||
}
|
||||
|
||||
int rf_send2(void *h, void *data, uint32_t nsamples, bool blocking, bool start_of_burst, bool end_of_burst)
|
||||
{
|
||||
return rf_send_timed3(h, data, nsamples, 0, 0, false, blocking, start_of_burst, end_of_burst);
|
||||
}
|
||||
|
||||
|
||||
int rf_send_timed(void *h,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs)
|
||||
{
|
||||
return rf_send_timed2(h, data, nsamples, secs, frac_secs, true, true);
|
||||
}
|
||||
|
||||
int rf_send_timed2(void *h,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst)
|
||||
{
|
||||
return rf_send_timed3(h, data, nsamples, secs, frac_secs, true, true, is_start_of_burst, is_end_of_burst);
|
||||
}
|
@ -0,0 +1,548 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \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 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <uhd.h>
|
||||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "srslte/srslte.h"
|
||||
#include "rf_uhd_imp.h"
|
||||
#include "srslte/rf/rf.h"
|
||||
#include "uhd_c_api.h"
|
||||
|
||||
typedef struct {
|
||||
uhd_usrp_handle usrp;
|
||||
uhd_rx_streamer_handle rx_stream;
|
||||
uhd_tx_streamer_handle tx_stream;
|
||||
|
||||
uhd_rx_metadata_handle rx_md, rx_md_first;
|
||||
uhd_tx_metadata_handle tx_md;
|
||||
|
||||
// The following variables are for threaded RX gain control
|
||||
uhd_meta_range_handle rx_gain_range;
|
||||
pthread_t thread_gain;
|
||||
pthread_cond_t cond;
|
||||
pthread_mutex_t mutex;
|
||||
double cur_rx_gain;
|
||||
double new_rx_gain;
|
||||
bool tx_gain_same_rx;
|
||||
float tx_rx_gain_offset;
|
||||
size_t rx_nof_samples;
|
||||
size_t tx_nof_samples;
|
||||
double tx_rate;
|
||||
bool dynamic_rate;
|
||||
} rf_uhd_handler_t;
|
||||
|
||||
void suppress_handler(const char *x)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void rf_uhd_suppress_stdout(void *h) {
|
||||
rf_uhd_register_msg_handler(h, suppress_handler);
|
||||
}
|
||||
|
||||
void rf_uhd_register_msg_handler(void *notused, rf_msg_handler_t new_handler)
|
||||
{
|
||||
rf_uhd_register_msg_handler_c(new_handler);
|
||||
}
|
||||
|
||||
static bool find_string(uhd_string_vector_handle h, char *str)
|
||||
{
|
||||
char buff[128];
|
||||
size_t n;
|
||||
uhd_string_vector_size(h, &n);
|
||||
for (int i=0;i<n;i++) {
|
||||
uhd_string_vector_at(h, i, buff, 128);
|
||||
if (!strcmp(buff, str)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isLocked(rf_uhd_handler_t *handler, char *sensor_name, uhd_sensor_value_handle *value_h)
|
||||
{
|
||||
bool val_out = false;
|
||||
|
||||
if (sensor_name) {
|
||||
uhd_usrp_get_rx_sensor(handler->usrp, sensor_name, 0, value_h);
|
||||
uhd_sensor_value_to_bool(*value_h, &val_out);
|
||||
} else {
|
||||
usleep(500);
|
||||
val_out = true;
|
||||
}
|
||||
|
||||
return val_out;
|
||||
}
|
||||
|
||||
bool rf_uhd_rx_wait_lo_locked(void *h)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
|
||||
uhd_string_vector_handle mb_sensors;
|
||||
uhd_string_vector_handle rx_sensors;
|
||||
char *sensor_name;
|
||||
uhd_sensor_value_handle value_h;
|
||||
|
||||
uhd_string_vector_make(&mb_sensors);
|
||||
uhd_string_vector_make(&rx_sensors);
|
||||
|
||||
uhd_usrp_get_mboard_sensor_names(handler->usrp, 0, &mb_sensors);
|
||||
uhd_usrp_get_rx_sensor_names(handler->usrp, 0, &rx_sensors);
|
||||
|
||||
if (find_string(rx_sensors, "lo_locked")) {
|
||||
sensor_name = "lo_locked";
|
||||
} else if (find_string(mb_sensors, "ref_locked")) {
|
||||
sensor_name = "ref_locked";
|
||||
} else {
|
||||
sensor_name = NULL;
|
||||
}
|
||||
|
||||
double report = 0.0;
|
||||
while (isLocked(handler, sensor_name, &value_h) && report < 30.0) {
|
||||
report += 0.1;
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
bool val = isLocked(handler, sensor_name, &value_h);
|
||||
|
||||
uhd_string_vector_free(&mb_sensors);
|
||||
uhd_string_vector_free(&rx_sensors);
|
||||
uhd_sensor_value_free(&value_h);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int rf_uhd_start_rx_stream(void *h)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_stream_cmd_t stream_cmd = {
|
||||
.stream_mode = UHD_STREAM_MODE_START_CONTINUOUS,
|
||||
.stream_now = true
|
||||
};
|
||||
uhd_rx_streamer_issue_stream_cmd(handler->rx_stream, &stream_cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rf_uhd_stop_rx_stream(void *h)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_stream_cmd_t stream_cmd = {
|
||||
.stream_mode = UHD_STREAM_MODE_STOP_CONTINUOUS,
|
||||
.stream_now = true
|
||||
};
|
||||
uhd_rx_streamer_issue_stream_cmd(handler->rx_stream, &stream_cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rf_uhd_flush_buffer(void *h)
|
||||
{
|
||||
int n;
|
||||
cf_t tmp[1024];
|
||||
do {
|
||||
n = rf_uhd_recv_with_time(h, tmp, 1024, 0, NULL, NULL);
|
||||
} while (n > 0);
|
||||
}
|
||||
|
||||
bool rf_uhd_has_rssi(void *h) {
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_string_vector_handle rx_sensors;
|
||||
uhd_usrp_get_rx_sensor_names(handler->usrp, 0, &rx_sensors);
|
||||
bool ret = find_string(rx_sensors, "rssi");
|
||||
uhd_string_vector_free(&rx_sensors);
|
||||
return ret;
|
||||
}
|
||||
|
||||
float rf_uhd_get_rssi(void *h) {
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_sensor_value_handle value;
|
||||
uhd_usrp_get_rx_sensor(handler->usrp, "rssi", 0, &value);
|
||||
double val_out;
|
||||
uhd_sensor_value_to_realnum(value, &val_out);
|
||||
uhd_sensor_value_free(&value);
|
||||
return val_out;
|
||||
}
|
||||
|
||||
double rf_uhd_set_rx_gain_th(void *h, double gain)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
double gain_clipped;
|
||||
uhd_meta_range_clip(handler->rx_gain_range, gain, true, &gain_clipped);
|
||||
if (gain_clipped > handler->new_rx_gain + 0.5 || gain_clipped < handler->new_rx_gain - 0.5) {
|
||||
pthread_mutex_lock(&handler->mutex);
|
||||
handler->new_rx_gain = gain_clipped;
|
||||
pthread_cond_signal(&handler->cond);
|
||||
pthread_mutex_unlock(&handler->mutex);
|
||||
}
|
||||
return gain_clipped;
|
||||
}
|
||||
|
||||
void rf_uhd_set_tx_rx_gain_offset(void *h, double offset) {
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
handler->tx_rx_gain_offset = offset;
|
||||
}
|
||||
|
||||
/* This thread listens for set_rx_gain commands to the USRP */
|
||||
static void* thread_gain_fcn(void *h) {
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
while(1) {
|
||||
pthread_mutex_lock(&handler->mutex);
|
||||
while(handler->cur_rx_gain == handler->new_rx_gain)
|
||||
{
|
||||
pthread_cond_wait(&handler->cond, &handler->mutex);
|
||||
}
|
||||
if (handler->new_rx_gain != handler->cur_rx_gain) {
|
||||
handler->cur_rx_gain = handler->new_rx_gain;
|
||||
rf_uhd_set_rx_gain(h, handler->cur_rx_gain);
|
||||
}
|
||||
if (handler->tx_gain_same_rx) {
|
||||
rf_uhd_set_tx_gain(h, handler->cur_rx_gain+handler->tx_rx_gain_offset);
|
||||
}
|
||||
pthread_mutex_unlock(&handler->mutex);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rf_uhd_open(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx)
|
||||
{
|
||||
char err_msg[256];
|
||||
*h = NULL;
|
||||
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) malloc(sizeof(rf_uhd_handler_t));
|
||||
if (!handler) {
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
*h = handler;
|
||||
|
||||
/* Set priority to UHD threads */
|
||||
uhd_set_thread_priority(uhd_default_thread_priority, true);
|
||||
|
||||
/* Find available USRP devices in case args is empty */
|
||||
if (args[0] == '\0') {
|
||||
uhd_string_vector_handle devices_str;
|
||||
uhd_string_vector_make(&devices_str);
|
||||
uhd_usrp_find("", &devices_str);
|
||||
|
||||
if (find_string(devices_str, "b200")) {
|
||||
// build args here
|
||||
}
|
||||
}
|
||||
|
||||
/* Create UHD handler */
|
||||
uhd_error error = uhd_usrp_make(&handler->usrp, args);
|
||||
if (error) {
|
||||
uhd_usrp_last_error(handler->usrp, err_msg, 256);
|
||||
fprintf(stderr, "Error opening UHD: %s\n", err_msg);
|
||||
}
|
||||
|
||||
size_t channel = 0;
|
||||
uhd_stream_args_t stream_args = {
|
||||
.cpu_format = "fc32",
|
||||
.otw_format = "sc16",
|
||||
.args = "",
|
||||
.channel_list = &channel,
|
||||
.n_channels = 1
|
||||
};
|
||||
|
||||
/* Initialize rx and tx stremers */
|
||||
uhd_rx_streamer_make(&handler->rx_stream);
|
||||
error = uhd_usrp_get_rx_stream(handler->usrp, &stream_args, handler->rx_stream);
|
||||
if (error) {
|
||||
uhd_rx_streamer_last_error(handler->rx_stream, err_msg, 256);
|
||||
fprintf(stderr, "Error opening RX stream: %s\n", err_msg);
|
||||
}
|
||||
uhd_tx_streamer_make(&handler->tx_stream);
|
||||
error = uhd_usrp_get_tx_stream(handler->usrp, &stream_args, handler->tx_stream);
|
||||
if (error) {
|
||||
uhd_tx_streamer_last_error(handler->tx_stream, err_msg, 256);
|
||||
fprintf(stderr, "Error opening TX stream: %s\n", err_msg);
|
||||
}
|
||||
|
||||
uhd_rx_streamer_num_channels(handler->rx_stream, &handler->rx_nof_samples);
|
||||
uhd_tx_streamer_num_channels(handler->tx_stream, &handler->tx_nof_samples);
|
||||
|
||||
handler->tx_gain_same_rx = tx_gain_same_rx;
|
||||
handler->tx_rx_gain_offset = 0.0;
|
||||
uhd_meta_range_make(&handler->rx_gain_range);
|
||||
uhd_usrp_get_rx_gain_range(handler->usrp, "", 0, handler->rx_gain_range);
|
||||
|
||||
// Make metadata objects for RX/TX
|
||||
uhd_rx_metadata_make(&handler->rx_md);
|
||||
uhd_rx_metadata_make(&handler->rx_md_first);
|
||||
uhd_tx_metadata_make(&handler->tx_md, false, 0, 0, false, false);
|
||||
|
||||
/* Create auxiliary thread and mutexes for AGC */
|
||||
if (create_thread_gain) {
|
||||
if (pthread_mutex_init(&handler->mutex, NULL)) {
|
||||
return -1;
|
||||
}
|
||||
if (pthread_cond_init(&handler->cond, NULL)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pthread_create(&handler->thread_gain, NULL, thread_gain_fcn, handler)) {
|
||||
perror("pthread_create");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find out if the master clock rate is configurable */
|
||||
double cur_clock, new_clock;
|
||||
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &cur_clock);
|
||||
printf("Trying to dynamically change Master clock...\n");
|
||||
uhd_usrp_set_master_clock_rate(handler->usrp, cur_clock/2, 0);
|
||||
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &new_clock);
|
||||
if (new_clock == cur_clock) {
|
||||
handler->dynamic_rate = false;
|
||||
/* Master clock rate is not configurable. Check if it is compatible with LTE */
|
||||
int cur_clock_i = (int) cur_clock;
|
||||
if (cur_clock_i % 1920000) {
|
||||
fprintf(stderr, "Error: LTE sampling rates are not supported. Master clock rate is %.1f MHz\n", cur_clock/1e6);
|
||||
return -1;
|
||||
} else {
|
||||
printf("Master clock is not configurable. Using standard symbol sizes and sampling rates.\n");
|
||||
srslte_use_standard_symbol_size(true);
|
||||
}
|
||||
} else {
|
||||
printf("Master clock is configurable. Using reduced symbol sizes and sampling rates.\n");
|
||||
handler->dynamic_rate = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int rf_uhd_close(void *h)
|
||||
{
|
||||
rf_uhd_stop_rx_stream(h);
|
||||
|
||||
/** Something else to close the USRP?? */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rf_uhd_set_master_clock_rate(void *h, double rate) {
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
if (handler->dynamic_rate) {
|
||||
uhd_usrp_set_master_clock_rate(handler->usrp, rate, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool rf_uhd_is_master_clock_dynamic(void *h) {
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
return handler->dynamic_rate;
|
||||
}
|
||||
|
||||
double rf_uhd_set_rx_srate(void *h, double freq)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_usrp_set_rx_rate(handler->usrp, freq, 0);
|
||||
uhd_usrp_get_rx_rate(handler->usrp, 0, &freq);
|
||||
return freq;
|
||||
}
|
||||
|
||||
double rf_uhd_set_tx_srate(void *h, double freq)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_usrp_set_tx_rate(handler->usrp, freq, 0);
|
||||
uhd_usrp_get_tx_rate(handler->usrp, 0, &freq);
|
||||
handler->tx_rate = freq;
|
||||
return freq;
|
||||
}
|
||||
|
||||
double rf_uhd_set_rx_gain(void *h, double gain)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_usrp_set_rx_gain(handler->usrp, gain, 0, "");
|
||||
uhd_usrp_get_rx_gain(handler->usrp, 0, "", &gain);
|
||||
return gain;
|
||||
}
|
||||
|
||||
double rf_uhd_set_tx_gain(void *h, double gain)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_usrp_set_tx_gain(handler->usrp, gain, 0, "");
|
||||
uhd_usrp_get_tx_gain(handler->usrp, 0, "", &gain);
|
||||
return gain;
|
||||
}
|
||||
|
||||
double rf_uhd_get_rx_gain(void *h)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
double gain;
|
||||
uhd_usrp_get_rx_gain(handler->usrp, 0, "", &gain);
|
||||
return gain;
|
||||
}
|
||||
|
||||
double rf_uhd_get_tx_gain(void *h)
|
||||
{
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
double gain;
|
||||
uhd_usrp_get_tx_gain(handler->usrp, 0, "", &gain);
|
||||
return gain;
|
||||
}
|
||||
|
||||
double rf_uhd_set_rx_freq(void *h, double freq)
|
||||
{
|
||||
uhd_tune_request_t tune_request = {
|
||||
.target_freq = freq,
|
||||
.rf_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO,
|
||||
.dsp_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO,
|
||||
};
|
||||
uhd_tune_result_t tune_result;
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_usrp_set_rx_freq(handler->usrp, &tune_request, 0, &tune_result);
|
||||
uhd_usrp_get_rx_freq(handler->usrp, 0, &freq);
|
||||
return freq;
|
||||
}
|
||||
|
||||
double rf_uhd_set_tx_freq(void *h, double freq)
|
||||
{
|
||||
uhd_tune_request_t tune_request = {
|
||||
.target_freq = freq,
|
||||
.rf_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO,
|
||||
.dsp_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO,
|
||||
};
|
||||
uhd_tune_result_t tune_result;
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_usrp_set_tx_freq(handler->usrp, &tune_request, 0, &tune_result);
|
||||
uhd_usrp_get_tx_freq(handler->usrp, 0, &freq);
|
||||
return freq;
|
||||
}
|
||||
|
||||
|
||||
void rf_uhd_get_time(void *h, time_t *secs, double *frac_secs) {
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
uhd_usrp_get_time_now(handler->usrp, 0, secs, frac_secs);
|
||||
}
|
||||
|
||||
int rf_uhd_recv_with_time(void *h,
|
||||
void *data,
|
||||
uint32_t nsamples,
|
||||
bool blocking,
|
||||
time_t *secs,
|
||||
double *frac_secs)
|
||||
{
|
||||
char err_msg[256];
|
||||
|
||||
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
|
||||
size_t rxd_samples;
|
||||
uhd_rx_metadata_handle *md = &handler->rx_md_first;
|
||||
if (blocking) {
|
||||
int n = 0;
|
||||
cf_t *data_c = (cf_t*) data;
|
||||
do {
|
||||
size_t rx_samples = handler->rx_nof_samples;
|
||||
|
||||
if (rx_samples > nsamples - n) {
|
||||
rx_samples = nsamples - n;
|
||||
}
|
||||
void *buff = (void*) &data_c[n];
|
||||
void **buffs_ptr = (void**) &buff;
|
||||
uhd_error error = uhd_rx_streamer_recv(handler->rx_stream, buffs_ptr,
|
||||
rx_samples, md, 3.0, false, &rxd_samples);
|
||||
if (error) {
|
||||
uhd_rx_streamer_last_error(handler->rx_stream, err_msg, 256);
|
||||
fprintf(stderr, "Error receiving from UHD: %s\n", err_msg);
|
||||
return -1;
|
||||
}
|
||||
md = &handler->rx_md;
|
||||
n += rxd_samples;
|
||||
} while (n < nsamples);
|
||||
} else {
|
||||
void **buffs_ptr = (void**) &data;
|
||||
return uhd_rx_streamer_recv(handler->rx_stream, buffs_ptr,
|
||||
nsamples, md, 0.0, false, &rxd_samples);
|
||||
}
|
||||
if (secs && frac_secs) {
|
||||
uhd_rx_metadata_time_spec(handler->rx_md_first, secs, frac_secs);
|
||||
}
|
||||
return nsamples;
|
||||
}
|
||||
|
||||
int rf_uhd_send_timed(void *h,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool has_time_spec,
|
||||
bool blocking,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst)
|
||||
{
|
||||
rf_uhd_handler_t* handler = (rf_uhd_handler_t*) h;
|
||||
char err_msg[256];
|
||||
|
||||
size_t txd_samples;
|
||||
if (has_time_spec) {
|
||||
uhd_tx_metadata_set_time_spec(&handler->tx_md, secs, frac_secs);
|
||||
}
|
||||
if (blocking) {
|
||||
int n = 0;
|
||||
cf_t *data_c = (cf_t*) data;
|
||||
do {
|
||||
size_t tx_samples = handler->tx_nof_samples;
|
||||
|
||||
// First packet is start of burst if so defined, others are never
|
||||
if (n == 0) {
|
||||
uhd_tx_metadata_set_start(&handler->tx_md, is_start_of_burst);
|
||||
} else {
|
||||
uhd_tx_metadata_set_start(&handler->tx_md, false);
|
||||
}
|
||||
|
||||
// middle packets are never end of burst, last one as defined
|
||||
if (nsamples - n > tx_samples) {
|
||||
uhd_tx_metadata_set_end(&handler->tx_md, false);
|
||||
} else {
|
||||
tx_samples = nsamples - n;
|
||||
uhd_tx_metadata_set_end(&handler->tx_md, is_end_of_burst);
|
||||
}
|
||||
|
||||
void *buff = (void*) &data_c[n];
|
||||
const void **buffs_ptr = (const void**) &buff;
|
||||
uhd_error error = uhd_tx_streamer_send(handler->tx_stream, buffs_ptr,
|
||||
tx_samples, &handler->tx_md, 3.0, &txd_samples);
|
||||
if (error) {
|
||||
uhd_tx_streamer_last_error(handler->tx_stream, err_msg, 256);
|
||||
fprintf(stderr, "Error sending to UHD: %s\n", err_msg);
|
||||
return -1;
|
||||
}
|
||||
// Increase time spec
|
||||
uhd_tx_metadata_add_time_spec(&handler->tx_md, txd_samples/handler->tx_rate);
|
||||
n += txd_samples;
|
||||
} while (n < nsamples);
|
||||
return nsamples;
|
||||
} else {
|
||||
const void **buffs_ptr = (const void**) &data;
|
||||
uhd_tx_metadata_set_start(&handler->tx_md, is_start_of_burst);
|
||||
uhd_tx_metadata_set_end(&handler->tx_md, is_end_of_burst);
|
||||
return uhd_tx_streamer_send(handler->tx_stream, buffs_ptr, nsamples, &handler->tx_md, 0.0, &txd_samples);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,117 @@
|
||||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \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 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/rf/rf.h"
|
||||
|
||||
SRSLTE_API int rf_uhd_open(char *args,
|
||||
void **handler,
|
||||
bool agc_thread,
|
||||
bool tx_gain_same_rx);
|
||||
|
||||
SRSLTE_API int rf_uhd_close(void *h);
|
||||
|
||||
SRSLTE_API int rf_uhd_start_rx_stream(void *h);
|
||||
|
||||
SRSLTE_API int rf_uhd_start_rx_stream_nsamples(void *h,
|
||||
uint32_t nsamples);
|
||||
|
||||
SRSLTE_API int rf_uhd_stop_rx_stream(void *h);
|
||||
|
||||
SRSLTE_API void rf_uhd_flush_buffer(void *h);
|
||||
|
||||
SRSLTE_API bool rf_uhd_has_rssi(void *h);
|
||||
|
||||
SRSLTE_API float rf_uhd_get_rssi(void *h);
|
||||
|
||||
SRSLTE_API bool rf_uhd_rx_wait_lo_locked(void *h);
|
||||
|
||||
SRSLTE_API void rf_uhd_set_master_clock_rate(void *h,
|
||||
double rate);
|
||||
|
||||
SRSLTE_API bool rf_uhd_is_master_clock_dynamic(void *h);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_rx_srate(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_rx_gain(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API void rf_uhd_set_tx_rx_gain_offset(void *h,
|
||||
double offset);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_rx_gain_th(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_tx_gain_th(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API float rf_uhd_get_rx_gain_offset(void *h);
|
||||
|
||||
SRSLTE_API double rf_uhd_get_rx_gain(void *h);
|
||||
|
||||
SRSLTE_API double rf_uhd_get_tx_gain(void *h);
|
||||
|
||||
SRSLTE_API void rf_uhd_suppress_stdout(void *h);
|
||||
|
||||
SRSLTE_API void rf_uhd_register_msg_handler(void *h, rf_msg_handler_t msg_handler);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_rx_freq(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API int rf_uhd_recv_with_time(void *h,
|
||||
void *data,
|
||||
uint32_t nsamples,
|
||||
bool blocking,
|
||||
time_t *secs,
|
||||
double *frac_secs);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_tx_srate(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_tx_gain(void *h,
|
||||
double gain);
|
||||
|
||||
SRSLTE_API double rf_uhd_set_tx_freq(void *h,
|
||||
double freq);
|
||||
|
||||
SRSLTE_API void rf_uhd_get_time(void *h,
|
||||
time_t *secs,
|
||||
double *frac_secs);
|
||||
|
||||
SRSLTE_API int rf_uhd_send_timed(void *h,
|
||||
void *data,
|
||||
int nsamples,
|
||||
time_t secs,
|
||||
double frac_secs,
|
||||
bool has_time_spec,
|
||||
bool blocking,
|
||||
bool is_start_of_burst,
|
||||
bool is_end_of_burst);
|
||||
|
@ -0,0 +1,45 @@
|
||||
|
||||
|
||||
/* This file implements a few features not currently provided by the UHD C-API */
|
||||
#include <uhd.h>
|
||||
#include <uhd/usrp/multi_usrp.hpp>
|
||||
|
||||
extern "C" {
|
||||
#include "srslte/rf/rf.h"
|
||||
#include "uhd_c_api.h"
|
||||
}
|
||||
|
||||
static rf_msg_handler_t msg_handler;
|
||||
|
||||
void translate_handler(uhd::msg::type_t type, const std::string & msg)
|
||||
{
|
||||
if(msg_handler)
|
||||
msg_handler(msg.c_str());
|
||||
}
|
||||
|
||||
void rf_uhd_register_msg_handler_c(rf_msg_handler_t new_handler)
|
||||
{
|
||||
msg_handler = new_handler;
|
||||
uhd::msg::register_handler(translate_handler);
|
||||
}
|
||||
|
||||
void uhd_tx_metadata_set_time_spec(uhd_tx_metadata_handle *md, time_t secs, double frac_secs)
|
||||
{
|
||||
(*md)->tx_metadata_cpp.time_spec = uhd::time_spec_t(secs, frac_secs);
|
||||
}
|
||||
|
||||
void uhd_tx_metadata_set_start(uhd_tx_metadata_handle *md, bool is_start_of_burst)
|
||||
{
|
||||
(*md)->tx_metadata_cpp.start_of_burst = is_start_of_burst;
|
||||
}
|
||||
|
||||
void uhd_tx_metadata_set_end(uhd_tx_metadata_handle *md, bool is_end_of_burst)
|
||||
{
|
||||
(*md)->tx_metadata_cpp.end_of_burst = is_end_of_burst;
|
||||
}
|
||||
|
||||
void uhd_tx_metadata_add_time_spec(uhd_tx_metadata_handle *md, double frac_secs)
|
||||
{
|
||||
(*md)->tx_metadata_cpp.time_spec += frac_secs;
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
|
||||
#include <uhd.h>
|
||||
#include "srslte/config.h"
|
||||
#include "srslte/rf/rf.h"
|
||||
|
||||
/* Declare functions not currently provided by the C-API */
|
||||
SRSLTE_API void rf_uhd_register_msg_handler_c(rf_msg_handler_t new_handler);
|
||||
SRSLTE_API void uhd_tx_metadata_set_time_spec(uhd_tx_metadata_handle *md, time_t secs, double frac_secs);
|
||||
SRSLTE_API void uhd_tx_metadata_set_start(uhd_tx_metadata_handle *md, bool is_start_of_burst);
|
||||
SRSLTE_API void uhd_tx_metadata_set_end(uhd_tx_metadata_handle *md, bool is_end_of_burst);
|
||||
SRSLTE_API void uhd_tx_metadata_add_time_spec(uhd_tx_metadata_handle *md, double frac_secs);
|
Loading…
Reference in New Issue