diff --git a/cmake/modules/FindbladeRF.cmake b/cmake/modules/FindbladeRF.cmake new file mode 100644 index 000000000..b154a9cf1 --- /dev/null +++ b/cmake/modules/FindbladeRF.cmake @@ -0,0 +1,27 @@ +if(NOT BLADERF_FOUND) + pkg_check_modules (BLADERF_PKG libbladeRF) + find_path(BLADERF_INCLUDE_DIRS NAMES libbladeRF.h + PATHS + ${BLADERF_PKG_INCLUDE_DIRS} + /usr/include + /usr/local/include + ) + + find_library(BLADERF_LIBRARIES NAMES bladeRF + PATHS + ${BLADERF_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + +if(BLADERF_INCLUDE_DIRS AND BLADERF_LIBRARIES) + set(BLADERF_FOUND TRUE CACHE INTERNAL "libbladeRF found") + message(STATUS "Found libbladeRF: ${BLADERF_INCLUDE_DIRS}, ${BLADERF_LIBRARIES}") +else(BLADERF_INCLUDE_DIRS AND BLADERF_LIBRARIES) + set(BLADERF_FOUND FALSE CACHE INTERNAL "libbladeRF found") + message(STATUS "libbladeRF not found.") +endif(BLADERF_INCLUDE_DIRS AND BLADERF_LIBRARIES) + +mark_as_advanced(BLADERF_LIBRARIES BLADERF_INCLUDE_DIRS) + +endif(NOT BLADERF_FOUND) diff --git a/cmake/modules/FindopenLTE.cmake b/cmake/modules/FindopenLTE.cmake deleted file mode 100644 index e48758940..000000000 --- a/cmake/modules/FindopenLTE.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# - Try to find openLTE's liblte - -find_package(PkgConfig) -pkg_check_modules(PC_OPENLTE QUIET srslte) -set(OPENLTE_DEFINITIONS ${PC_OPENLTE_CFLAGS_OTHER}) - -FIND_PATH( - OPENLTE_LIBLTE_DIRS - NAMES liblte_common.h typedefs.h - HINTS ${PC_OPENLTE_SRCDIR}/liblte/hdr - ${PC_OPENLTE_INCLUDEDIR} - ${PC_OPENLTE_INCLUDE_DIRS} - $ENV{OPENLTE_DIR}/liblte/hdr - PATHS /usr/local/include - /usr/include -) - -FIND_PATH( - OPENLTE_COMMON_DIRS - NAMES typedefs.h - HINTS ${PC_OPENLTE_SRCDIR}/cmn_hdr - ${PC_OPENLTE_INCLUDEDIR} - ${PC_OPENLTE_INCLUDE_DIRS} - $ENV{OPENLTE_DIR}/liblte/hdr - PATHS /usr/local/include - /usr/include -) - -FIND_LIBRARY( - OPENLTE_LIBRARIES - NAMES lte - HINTS ${PC_OPENLTE_BUILDDIR}/liblte - ${CMAKE_INSTALL_PREFIX}/lib - ${CMAKE_INSTALL_PREFIX}/lib64 - $ENV{OPENLTE_DIR}/lib - PATHS /usr/local/lib - /usr/local/lib64 - /usr/lib - /usr/lib64 -) - -IF(OPENLTE_LIBLTE_DIRS AND OPENLTE_COMMON_DIRS) - SET(OPENLTE_INCLUDE_DIRS ${OPENLTE_LIBLTE_DIRS} ${OPENLTE_COMMON_DIRS}) -ENDIF(OPENLTE_LIBLTE_DIRS AND OPENLTE_COMMON_DIRS) - -message(STATUS "OPENLTE LIBRARIES " ${OPENLTE_LIBRARIES}) -message(STATUS "OPENLTE INCLUDE DIRS " ${OPENLTE_INCLUDE_DIRS}) - -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENLTE DEFAULT_MSG OPENLTE_LIBRARIES OPENLTE_INCLUDE_DIRS) -MARK_AS_ADVANCED(OPENLTE_LIBRARIES OPENLTE_INCLUDE_DIRS) - diff --git a/srslte/CMakeLists.txt b/srslte/CMakeLists.txt index 53f0412f9..cb1c27107 100644 --- a/srslte/CMakeLists.txt +++ b/srslte/CMakeLists.txt @@ -43,6 +43,13 @@ ADD_CUSTOM_TARGET (add_srslte_headers SOURCES ${HEADERS_ALL}) # Find Dependencies ######################################################################## FIND_PACKAGE(UHD) +FIND_PACKAGE(bladeRF) + +IF(BLADERF_FOUND OR UHD_FOUND) + set(RF_FOUND TRUE CACHE INTERNAL "RF frontend found") +ELSE(BLADERF_FOUND OR UHD_FOUND) + set(RF_FOUND FALSE CACHE INTERNAL "RF frontend found") +ENDIF(BLADERF_FOUND OR UHD_FOUND) ######################################################################## # Add subdirectories diff --git a/srslte/examples/CMakeLists.txt b/srslte/examples/CMakeLists.txt index d2b446ef2..bf0f357e7 100644 --- a/srslte/examples/CMakeLists.txt +++ b/srslte/examples/CMakeLists.txt @@ -40,12 +40,12 @@ target_link_libraries(pdsch_ue srslte pthread) add_executable(pdsch_enodeb pdsch_enodeb.c) target_link_libraries(pdsch_enodeb srslte pthread) -IF(UHD_FOUND) - target_link_libraries(pdsch_ue srslte_uhd) - target_link_libraries(pdsch_enodeb srslte_uhd) -ELSE(UHD_FOUND) - add_definitions(-DDISABLE_UHD) -ENDIF(UHD_FOUND) +IF(RF_FOUND) + target_link_libraries(pdsch_ue srslte_rf) + target_link_libraries(pdsch_enodeb srslte_rf) +ELSE(RF_FOUND) + add_definitions(-DDISABLE_RF) +ENDIF(RF_FOUND) FIND_PACKAGE(SRSGUI) @@ -61,28 +61,28 @@ ENDIF(SRSGUI_FOUND) # These examples need the UHD driver ################################################################# -IF(UHD_FOUND) +IF(RF_FOUND) add_executable(cell_search cell_search.c) - target_link_libraries(cell_search srslte srslte_uhd) + target_link_libraries(cell_search srslte srslte_rf) add_executable(cell_measurement cell_measurement.c) - target_link_libraries(cell_measurement srslte srslte_uhd) + target_link_libraries(cell_measurement srslte srslte_rf) add_executable(usrp_capture usrp_capture.c) - target_link_libraries(usrp_capture srslte srslte_uhd) + target_link_libraries(usrp_capture srslte srslte_rf) add_executable(usrp_capture_sync usrp_capture_sync.c) - target_link_libraries(usrp_capture_sync srslte srslte_uhd) + target_link_libraries(usrp_capture_sync srslte srslte_rf) add_executable(usrp_txrx usrp_txrx.c) - target_link_libraries(usrp_txrx srslte srslte_uhd) + target_link_libraries(usrp_txrx srslte srslte_rf) - MESSAGE(STATUS " UHD examples will be installed.") + MESSAGE(STATUS " examples will be installed.") -ELSE(UHD_FOUND) - MESSAGE(STATUS " UHD examples NOT INSTALLED.") -ENDIF(UHD_FOUND) +ELSE(RF_FOUND) + MESSAGE(STATUS " examples will NOT BE INSTALLED.") +ENDIF(RF_FOUND) # Add subdirectories add_subdirectory(tutorial_examples) diff --git a/srslte/examples/cell_measurement.c b/srslte/examples/cell_measurement.c index 148d40a67..6394440cc 100644 --- a/srslte/examples/cell_measurement.c +++ b/srslte/examples/cell_measurement.c @@ -36,8 +36,8 @@ #include #include "srslte/srslte.h" -#include "srslte/cuhd/cuhd.h" -#include "srslte/cuhd/cuhd_utils.h" +#include "srslte/rf/rf.h" +#include "srslte/rf/rf_utils.h" cell_search_cfg_t cell_detect_config = { 5000, // maximum number of frames to receive for MIB decoding @@ -123,9 +123,9 @@ void sig_int_handler(int signo) } } -int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *q) { +int rf_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *q) { DEBUG(" ---- Receive %d samples ---- \n", nsamples); - return cuhd_recv(h, data, nsamples, 1); + return rf_recv(h, data, nsamples, 1); } enum receiver_state { DECODE_MIB, DECODE_SIB, MEASURE} state; @@ -160,18 +160,18 @@ int main(int argc, char **argv) { if (prog_args.uhd_gain > 0) { printf("Opening UHD device...\n"); - if (cuhd_open(prog_args.uhd_args, &uhd)) { + if (rf_open(prog_args.uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_rx_gain(uhd, prog_args.uhd_gain); + rf_set_rx_gain(uhd, prog_args.uhd_gain); } else { printf("Opening UHD device with threaded RX Gain control ...\n"); - if (cuhd_open_th(prog_args.uhd_args, &uhd, false)) { + if (rf_open_th(prog_args.uhd_args, &uhd, false)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_rx_gain(uhd, 50); + rf_set_rx_gain(uhd, 50); } sigset_t sigset; @@ -180,16 +180,16 @@ int main(int argc, char **argv) { sigprocmask(SIG_UNBLOCK, &sigset, NULL); signal(SIGINT, sig_int_handler); - cuhd_set_master_clock_rate(uhd, 30.72e6); + rf_set_master_clock_rate(uhd, 30.72e6); /* set receiver frequency */ - cuhd_set_rx_freq(uhd, (double) prog_args.uhd_freq); - cuhd_rx_wait_lo_locked(uhd); + rf_set_rx_freq(uhd, (double) prog_args.uhd_freq); + rf_rx_wait_lo_locked(uhd); printf("Tunning receiver to %.3f MHz\n", (double ) prog_args.uhd_freq/1000000); uint32_t ntrial=0; do { - ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell); + ret = rf_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell); if (ret < 0) { fprintf(stderr, "Error searching for cell\n"); exit(-1); @@ -206,12 +206,12 @@ int main(int argc, char **argv) { int srate = srslte_sampling_freq_hz(cell.nof_prb); if (srate != -1) { if (srate < 10e6) { - cuhd_set_master_clock_rate(uhd, 4*srate); + rf_set_master_clock_rate(uhd, 4*srate); } else { - cuhd_set_master_clock_rate(uhd, srate); + rf_set_master_clock_rate(uhd, srate); } printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); - float srate_uhd = cuhd_set_rx_srate(uhd, (double) srate); + float srate_uhd = rf_set_rx_srate(uhd, (double) srate); if (srate_uhd != srate) { fprintf(stderr, "Could not set sampling rate\n"); exit(-1); @@ -222,10 +222,10 @@ int main(int argc, char **argv) { } INFO("Stopping UHD and flushing buffer...\n",0); - cuhd_stop_rx_stream(uhd); - cuhd_flush_buffer(uhd); + rf_stop_rx_stream(uhd); + rf_flush_buffer(uhd); - if (srslte_ue_sync_init(&ue_sync, cell, cuhd_recv_wrapper, uhd)) { + if (srslte_ue_sync_init(&ue_sync, cell, rf_recv_wrapper, uhd)) { fprintf(stderr, "Error initiating ue_sync\n"); return -1; } @@ -261,7 +261,7 @@ int main(int argc, char **argv) { ce[i] = srslte_vec_malloc(sizeof(cf_t) * sf_re); } - cuhd_start_rx_stream(uhd); + rf_start_rx_stream(uhd); float rx_gain_offset = 0; @@ -333,10 +333,10 @@ int main(int argc, char **argv) { if ((nframes%100) == 0 || rx_gain_offset == 0) { - if (cuhd_has_rssi(uhd)) { - rx_gain_offset = 10*log10(rssi)-cuhd_get_rssi(uhd); + if (rf_has_rssi(uhd)) { + rx_gain_offset = 10*log10(rssi)-rf_get_rssi(uhd); } else { - rx_gain_offset = cuhd_get_rx_gain(uhd); + rx_gain_offset = rf_get_rx_gain(uhd); } } @@ -373,7 +373,7 @@ int main(int argc, char **argv) { } // Main loop srslte_ue_sync_free(&ue_sync); - cuhd_close(uhd); + rf_close(uhd); printf("\nBye\n"); exit(0); } diff --git a/srslte/examples/cell_search.c b/srslte/examples/cell_search.c index 7739ce9a7..5fe889e55 100644 --- a/srslte/examples/cell_search.c +++ b/srslte/examples/cell_search.c @@ -37,11 +37,11 @@ #include "srslte/srslte.h" -#include "srslte/cuhd/cuhd_utils.h" +#include "srslte/rf/rf_utils.h" -#ifndef DISABLE_UHD -#include "srslte/cuhd/cuhd.h" +#ifndef DISABLE_RF +#include "srslte/rf/rf.h" #endif #define MHZ 1000000 @@ -123,9 +123,9 @@ void parse_args(int argc, char **argv) { } } -int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { +int rf_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { DEBUG(" ---- Receive %d samples ---- \n", nsamples); - return cuhd_recv(h, data, nsamples, 1); + return rf_recv(h, data, nsamples, 1); } bool go_exit = false; @@ -152,24 +152,24 @@ int main(int argc, char **argv) { if (!config.init_agc) { printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_rx_gain(uhd, uhd_gain); + rf_set_rx_gain(uhd, uhd_gain); } else { printf("Opening UHD device with threaded RX Gain control ...\n"); - if (cuhd_open_th(uhd_args, &uhd, false)) { + if (rf_open_th(uhd_args, &uhd, false)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_rx_gain(uhd, 50); + rf_set_rx_gain(uhd, 50); } - cuhd_set_master_clock_rate(uhd, 30.72e6); + rf_set_master_clock_rate(uhd, 30.72e6); // Supress UHD messages - cuhd_suppress_stdout(); + rf_suppress_stdout(); nof_freqs = srslte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN); if (nof_freqs < 0) { @@ -186,8 +186,8 @@ int main(int argc, char **argv) { for (freq=0;frequhd_args); printf("\t-g UHD fix RX gain [Default AGC]\n"); #else @@ -240,10 +240,10 @@ void sig_int_handler(int signo) } } -#ifndef DISABLE_UHD -int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { +#ifndef DISABLE_RF +int rf_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { DEBUG(" ---- Receive %d samples ---- \n", nsamples); - return cuhd_recv(h, data, nsamples, 1); + return rf_recv(h, data, nsamples, 1); } #endif @@ -264,7 +264,7 @@ int main(int argc, char **argv) { srslte_cell_t cell; int64_t sf_cnt; srslte_ue_mib_t ue_mib; -#ifndef DISABLE_UHD +#ifndef DISABLE_RF void *uhd; #endif uint32_t nof_trials = 0; @@ -290,24 +290,24 @@ int main(int argc, char **argv) { srslte_netsink_set_nonblocking(&net_sink_signal); } -#ifndef DISABLE_UHD +#ifndef DISABLE_RF if (!prog_args.input_file_name) { /* Set receiver gain */ if (prog_args.uhd_gain > 0) { printf("Opening UHD device...\n"); - if (cuhd_open(prog_args.uhd_args, &uhd)) { + if (rf_open(prog_args.uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_rx_gain(uhd, prog_args.uhd_gain); + rf_set_rx_gain(uhd, prog_args.uhd_gain); } else { printf("Opening UHD device with threaded RX Gain control ...\n"); - if (cuhd_open_th(prog_args.uhd_args, &uhd, false)) { + if (rf_open_th(prog_args.uhd_args, &uhd, false)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_rx_gain(uhd, 50); + rf_set_rx_gain(uhd, 50); cell_detect_config.init_agc = 50; } @@ -317,16 +317,16 @@ int main(int argc, char **argv) { sigprocmask(SIG_UNBLOCK, &sigset, NULL); signal(SIGINT, sig_int_handler); - cuhd_set_master_clock_rate(uhd, 30.72e6); + rf_set_master_clock_rate(uhd, 30.72e6); /* set receiver frequency */ - cuhd_set_rx_freq(uhd, (double) prog_args.uhd_freq); - cuhd_rx_wait_lo_locked(uhd); + rf_set_rx_freq(uhd, (double) prog_args.uhd_freq); + rf_rx_wait_lo_locked(uhd); printf("Tunning receiver to %.3f MHz\n", (double ) prog_args.uhd_freq/1000000); uint32_t ntrial=0; do { - ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell); + ret = rf_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell); if (ret < 0) { fprintf(stderr, "Error searching for cell\n"); exit(-1); @@ -342,12 +342,12 @@ int main(int argc, char **argv) { int srate = srslte_sampling_freq_hz(cell.nof_prb); if (srate != -1) { if (srate < 10e6) { - cuhd_set_master_clock_rate(uhd, 4*srate); + rf_set_master_clock_rate(uhd, 4*srate); } else { - cuhd_set_master_clock_rate(uhd, srate); + rf_set_master_clock_rate(uhd, srate); } printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); - float srate_uhd = cuhd_set_rx_srate(uhd, (double) srate); + float srate_uhd = rf_set_rx_srate(uhd, (double) srate); if (srate_uhd != srate) { fprintf(stderr, "Could not set sampling rate\n"); exit(-1); @@ -358,8 +358,8 @@ int main(int argc, char **argv) { } INFO("Stopping UHD and flushing buffer...\r",0); - cuhd_stop_rx_stream(uhd); - cuhd_flush_buffer(uhd); + rf_stop_rx_stream(uhd); + rf_flush_buffer(uhd); } #endif @@ -380,8 +380,8 @@ int main(int argc, char **argv) { } } else { -#ifndef DISABLE_UHD - if (srslte_ue_sync_init(&ue_sync, cell, cuhd_recv_wrapper, uhd)) { +#ifndef DISABLE_RF + if (srslte_ue_sync_init(&ue_sync, cell, rf_recv_wrapper, uhd)) { fprintf(stderr, "Error initiating ue_sync\n"); exit(-1); } @@ -413,9 +413,9 @@ int main(int argc, char **argv) { } #endif -#ifndef DISABLE_UHD +#ifndef DISABLE_RF if (!prog_args.input_file_name) { - cuhd_start_rx_stream(uhd); + rf_start_rx_stream(uhd); } #endif @@ -424,9 +424,9 @@ int main(int argc, char **argv) { float rsrp=0.0, rsrq=0.0, noise=0.0; bool decode_pdsch = false; -#ifndef DISABLE_UHD +#ifndef DISABLE_RF if (prog_args.uhd_gain < 0) { - srslte_ue_sync_start_agc(&ue_sync, cuhd_set_rx_gain_th, cell_detect_config.init_agc); + srslte_ue_sync_start_agc(&ue_sync, rf_set_rx_gain_th, cell_detect_config.init_agc); } #endif #ifdef PRINT_CHANGE_SCHEDULIGN @@ -589,10 +589,10 @@ int main(int argc, char **argv) { srslte_ue_dl_free(&ue_dl); srslte_ue_sync_free(&ue_sync); -#ifndef DISABLE_UHD +#ifndef DISABLE_RF if (!prog_args.input_file_name) { srslte_ue_mib_free(&ue_mib); - cuhd_close(uhd); + rf_close(uhd); } #endif printf("\nBye\n"); diff --git a/srslte/examples/tutorial_examples/CMakeLists.txt b/srslte/examples/tutorial_examples/CMakeLists.txt index d1ce1490e..cf139f515 100644 --- a/srslte/examples/tutorial_examples/CMakeLists.txt +++ b/srslte/examples/tutorial_examples/CMakeLists.txt @@ -26,10 +26,10 @@ IF(SRSGUI_FOUND AND UHD_FOUND) add_executable(pss pss.c) - target_link_libraries(pss srslte ${SRSGUI_LIBRARIES} srslte_uhd) + target_link_libraries(pss srslte ${SRSGUI_LIBRARIES} srslte_rf) add_executable(simple_tx simple_tx.c) - target_link_libraries(simple_tx srslte srslte_uhd) + target_link_libraries(simple_tx srslte srslte_rf) ENDIF(SRSGUI_FOUND AND UHD_FOUND) diff --git a/srslte/examples/tutorial_examples/pss.c b/srslte/examples/tutorial_examples/pss.c index 6640b3c0f..47eb9c035 100644 --- a/srslte/examples/tutorial_examples/pss.c +++ b/srslte/examples/tutorial_examples/pss.c @@ -35,7 +35,7 @@ #include #include "srslte/srslte.h" -#include "srslte/cuhd/cuhd.h" +#include "srslte/rf/rf.h" #ifndef DISABLE_GRAPHICS @@ -177,16 +177,16 @@ int main(int argc, char **argv) { srslte_sss_synch_set_N_id_2(&sss, N_id_2); printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } printf("N_id_2: %d\n", N_id_2); - printf("Set RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, flen*2*100) / 1000000); - printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); - printf("Set RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - cuhd_rx_wait_lo_locked(uhd); - cuhd_start_rx_stream(uhd); + printf("Set RX rate: %.2f MHz\n", rf_set_rx_srate(uhd, flen*2*100) / 1000000); + printf("Set RX gain: %.1f dB\n", rf_set_rx_gain(uhd, uhd_gain)); + printf("Set RX freq: %.2f MHz\n", rf_set_rx_freq(uhd, uhd_freq) / 1000000); + rf_rx_wait_lo_locked(uhd); + rf_start_rx_stream(uhd); printf("Frame length %d samples\n", flen); printf("PSS detection threshold: %.2f\n", threshold); @@ -208,7 +208,7 @@ int main(int argc, char **argv) { while(frame_cnt < nof_frames || nof_frames == -1) { peak_offset = 0; - n = cuhd_recv(uhd, buffer, flen - peak_offset, 1); + n = rf_recv(uhd, buffer, flen - peak_offset, 1); if (n < 0) { fprintf(stderr, "Error receiving samples\n"); exit(-1); @@ -320,7 +320,7 @@ int main(int argc, char **argv) { srslte_pss_synch_free(&pss); free(buffer); - cuhd_close(uhd); + rf_close(uhd); printf("Ok\n"); exit(0); diff --git a/srslte/examples/tutorial_examples/simple_tx.c b/srslte/examples/tutorial_examples/simple_tx.c index ca5b15eed..1836c542a 100644 --- a/srslte/examples/tutorial_examples/simple_tx.c +++ b/srslte/examples/tutorial_examples/simple_tx.c @@ -116,7 +116,7 @@ void parse_args(int argc, char **argv) { exit(-1); } } -#ifdef DISABLE_UHD +#ifdef DISABLE_RF if (!output_file_name) { usage(argv[0]); exit(-1); @@ -138,7 +138,7 @@ void base_init() { exit(-1); } printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } @@ -161,7 +161,7 @@ void base_free() { if (output_buffer) { free(output_buffer); } - cuhd_close(&uhd); + rf_close(&uhd); } @@ -172,7 +172,7 @@ int main(int argc, char **argv) { float sss_signal5[SRSLTE_SSS_LEN]; // for subframe 5 int i; -#ifdef DISABLE_UHD +#ifdef DISABLE_RF if (argc < 3) { usage(argv[0]); exit(-1); @@ -196,10 +196,10 @@ int main(int argc, char **argv) { srslte_sss_generate(sss_signal0, sss_signal5, cell.id); printf("Set TX rate: %.2f MHz\n", - cuhd_set_tx_srate(uhd, srslte_sampling_freq_hz(cell.nof_prb)) / 1000000); - printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain)); + rf_set_tx_srate(uhd, srslte_sampling_freq_hz(cell.nof_prb)) / 1000000); + printf("Set TX gain: %.1f dB\n", rf_set_tx_gain(uhd, uhd_gain)); printf("Set TX freq: %.2f MHz\n", - cuhd_set_tx_freq(uhd, uhd_freq) / 1000000); + rf_set_tx_freq(uhd, uhd_freq) / 1000000); uint32_t nbits; @@ -249,7 +249,7 @@ int main(int argc, char **argv) { /* send to usrp */ srslte_vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, sf_n_samples); - cuhd_send(uhd, output_buffer, sf_n_samples, true); + rf_send(uhd, output_buffer, sf_n_samples, true); } } diff --git a/srslte/examples/usrp_capture.c b/srslte/examples/usrp_capture.c index 870c78d45..dba286a01 100644 --- a/srslte/examples/usrp_capture.c +++ b/srslte/examples/usrp_capture.c @@ -36,7 +36,7 @@ #include #include "srslte/srslte.h" -#include "srslte/cuhd/cuhd.h" +#include "srslte/rf/rf.h" #include "srslte/io/filesink.h" static bool keep_running = true; @@ -117,27 +117,27 @@ int main(int argc, char **argv) { srslte_filesink_init(&sink, output_file_name, SRSLTE_COMPLEX_FLOAT_BIN); printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_master_clock_rate(uhd, 30.72e6); + rf_set_master_clock_rate(uhd, 30.72e6); sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGINT); sigprocmask(SIG_UNBLOCK, &sigset, NULL); - printf("Set RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - printf("Set RX gain: %.2f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); - float srate = cuhd_set_rx_srate(uhd, uhd_rate); + printf("Set RX freq: %.2f MHz\n", rf_set_rx_freq(uhd, uhd_freq) / 1000000); + printf("Set RX gain: %.2f dB\n", rf_set_rx_gain(uhd, uhd_gain)); + float srate = rf_set_rx_srate(uhd, uhd_rate); if (srate != uhd_rate) { if (srate < 10e6) { - cuhd_set_master_clock_rate(uhd, 4*uhd_rate); + rf_set_master_clock_rate(uhd, 4*uhd_rate); } else { - cuhd_set_master_clock_rate(uhd, uhd_rate); + rf_set_master_clock_rate(uhd, uhd_rate); } - srate = cuhd_set_rx_srate(uhd, uhd_rate); + srate = rf_set_rx_srate(uhd, uhd_rate); if (srate != uhd_rate) { fprintf(stderr, "Errror setting samplign frequency %.2f MHz\n", uhd_rate*1e-6); exit(-1); @@ -145,13 +145,13 @@ int main(int argc, char **argv) { } printf("Correctly RX rate: %.2f MHz\n", srate*1e-6); - cuhd_rx_wait_lo_locked(uhd); - cuhd_start_rx_stream(uhd); + rf_rx_wait_lo_locked(uhd); + rf_start_rx_stream(uhd); while((sample_count < nof_samples || nof_samples == -1) && keep_running){ - n = cuhd_recv(uhd, buffer, buflen, 1); + n = rf_recv(uhd, buffer, buflen, 1); if (n < 0) { fprintf(stderr, "Error receiving samples\n"); exit(-1); @@ -163,7 +163,7 @@ int main(int argc, char **argv) { srslte_filesink_free(&sink); free(buffer); - cuhd_close(uhd); + rf_close(uhd); printf("Ok - wrote %d samples\n", sample_count); exit(0); diff --git a/srslte/examples/usrp_capture_sync.c b/srslte/examples/usrp_capture_sync.c index 0ae297fd4..bfa7b8bbc 100644 --- a/srslte/examples/usrp_capture_sync.c +++ b/srslte/examples/usrp_capture_sync.c @@ -36,7 +36,7 @@ #include #include "srslte/srslte.h" -#include "srslte/cuhd/cuhd.h" +#include "srslte/rf/rf.h" static bool keep_running = true; char *output_file_name = NULL; @@ -98,9 +98,9 @@ void parse_args(int argc, char **argv) { } } -int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { +int rf_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { DEBUG(" ---- Receive %d samples ---- \n", nsamples); - return cuhd_recv(h, data, nsamples, 1); + return rf_recv(h, data, nsamples, 1); } int main(int argc, char **argv) { @@ -118,28 +118,28 @@ int main(int argc, char **argv) { srslte_filesink_init(&sink, output_file_name, SRSLTE_COMPLEX_FLOAT_BIN); printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_master_clock_rate(uhd, 30.72e6); + rf_set_master_clock_rate(uhd, 30.72e6); sigset_t sigset; sigemptyset(&sigset); sigaddset(&sigset, SIGINT); sigprocmask(SIG_UNBLOCK, &sigset, NULL); - printf("Set RX freq: %.6f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); + printf("Set RX freq: %.6f MHz\n", rf_set_rx_freq(uhd, uhd_freq) / 1000000); + printf("Set RX gain: %.1f dB\n", rf_set_rx_gain(uhd, uhd_gain)); int srate = srslte_sampling_freq_hz(nof_prb); if (srate != -1) { if (srate < 10e6) { - cuhd_set_master_clock_rate(uhd, 4*srate); + rf_set_master_clock_rate(uhd, 4*srate); } else { - cuhd_set_master_clock_rate(uhd, srate); + rf_set_master_clock_rate(uhd, srate); } printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); - float srate_uhd = cuhd_set_rx_srate(uhd, (double) srate); + float srate_uhd = rf_set_rx_srate(uhd, (double) srate); if (srate_uhd != srate) { fprintf(stderr, "Could not set sampling rate\n"); exit(-1); @@ -148,15 +148,15 @@ int main(int argc, char **argv) { fprintf(stderr, "Invalid number of PRB %d\n", nof_prb); exit(-1); } - cuhd_rx_wait_lo_locked(uhd); - cuhd_start_rx_stream(uhd); + rf_rx_wait_lo_locked(uhd); + rf_start_rx_stream(uhd); cell.cp = SRSLTE_CP_NORM; cell.id = N_id_2; cell.nof_prb = nof_prb; cell.nof_ports = 1; - if (srslte_ue_sync_init(&ue_sync, cell, cuhd_recv_wrapper, uhd)) { + if (srslte_ue_sync_init(&ue_sync, cell, rf_recv_wrapper, uhd)) { fprintf(stderr, "Error initiating ue_sync\n"); exit(-1); } @@ -191,7 +191,7 @@ int main(int argc, char **argv) { } srslte_filesink_free(&sink); - cuhd_close(uhd); + rf_close(uhd); srslte_ue_sync_free(&ue_sync); printf("Ok - wrote %d subframes\n", subframe_count); diff --git a/srslte/examples/usrp_txrx.c b/srslte/examples/usrp_txrx.c index 2399d9b4a..5b129e2e0 100644 --- a/srslte/examples/usrp_txrx.c +++ b/srslte/examples/usrp_txrx.c @@ -33,7 +33,7 @@ #include #include -#include "srslte/cuhd/cuhd.h" +#include "srslte/rf/rf.h" #include "srslte/srslte.h" uint32_t nof_prb = 25; @@ -127,28 +127,28 @@ int main(int argc, char **argv) { // Send through UHD void *uhd; printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } - cuhd_set_master_clock_rate(uhd, 30.72e6); + rf_set_master_clock_rate(uhd, 30.72e6); int srate = srslte_sampling_freq_hz(nof_prb); if (srate < 10e6) { - cuhd_set_master_clock_rate(uhd, 4*srate); + rf_set_master_clock_rate(uhd, 4*srate); } else { - cuhd_set_master_clock_rate(uhd, srate); + rf_set_master_clock_rate(uhd, srate); } - cuhd_set_rx_srate(uhd, (double) srate); - cuhd_set_tx_srate(uhd, (double) srate); + rf_set_rx_srate(uhd, (double) srate); + rf_set_tx_srate(uhd, (double) srate); printf("Subframe len: %d samples\n", flen); printf("Set TX/RX rate: %.2f MHz\n", (float) srate / 1000000); - printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_rx_gain)); - printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_tx_gain)); - printf("Set TX/RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); + printf("Set RX gain: %.1f dB\n", rf_set_rx_gain(uhd, uhd_rx_gain)); + printf("Set TX gain: %.1f dB\n", rf_set_tx_gain(uhd, uhd_tx_gain)); + printf("Set TX/RX freq: %.2f MHz\n", rf_set_rx_freq(uhd, uhd_freq) / 1000000); - cuhd_set_tx_freq_offset(uhd, uhd_freq, 8e6); + rf_set_tx_freq_offset(uhd, uhd_freq, 8e6); sleep(1); if (input_filename) { @@ -162,7 +162,7 @@ int main(int argc, char **argv) { srslte_timestamp_t tstamp; - cuhd_start_rx_stream(uhd); + rf_start_rx_stream(uhd); uint32_t nframe=0; float burst_settle_time = (float) nsamples_adv/srslte_sampling_freq_hz(nof_prb); @@ -171,15 +171,15 @@ int main(int argc, char **argv) { while(nframe #include -#include "srslte/cuhd/cuhd.h" +#include "srslte/rf/rf.h" #include "srslte/srslte.h" #define MAX_LEN 70176 @@ -142,17 +142,17 @@ int main(int argc, char **argv) { // Send through UHD void *uhd; printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } printf("Subframe len: %d samples\n", flen); - printf("Set TX/RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000); - printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); - printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain)); - printf("Set TX/RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - cuhd_set_tx_srate(uhd, srslte_sampling_freq_hz(nof_prb)); - cuhd_set_tx_freq_offset(uhd, uhd_freq, 8e6); + printf("Set TX/RX rate: %.2f MHz\n", rf_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000); + printf("Set RX gain: %.1f dB\n", rf_set_rx_gain(uhd, uhd_gain)); + printf("Set TX gain: %.1f dB\n", rf_set_tx_gain(uhd, uhd_gain)); + printf("Set TX/RX freq: %.2f MHz\n", rf_set_rx_freq(uhd, uhd_freq) / 1000000); + rf_set_tx_srate(uhd, srslte_sampling_freq_hz(nof_prb)); + rf_set_tx_freq_offset(uhd, uhd_freq, 8e6); sleep(1); cf_t *zeros = calloc(sizeof(cf_t),flen); @@ -164,20 +164,20 @@ int main(int argc, char **argv) { srslte_timestamp_t tstamp; - cuhd_start_rx_stream(uhd); + rf_start_rx_stream(uhd); uint32_t nframe=0; while(nframe #include -class cuhd_handler { +class rf_handler { public: uhd::usrp::multi_usrp::sptr usrp; uhd::rx_streamer::sptr rx_stream; diff --git a/srslte/lib/cuhd/src/cuhd_imp.cpp b/srslte/lib/rf/src/rf_imp.cpp similarity index 72% rename from srslte/lib/cuhd/src/cuhd_imp.cpp rename to srslte/lib/rf/src/rf_imp.cpp index e77c0e875..dcbdec446 100644 --- a/srslte/lib/cuhd/src/cuhd_imp.cpp +++ b/srslte/lib/rf/src/rf_imp.cpp @@ -32,13 +32,13 @@ #include #include -#include "cuhd_handler.hpp" -#include "srslte/cuhd/cuhd.h" +#include "rf_handler.hpp" +#include "srslte/rf/rf.h" #include "srslte/srslte.h" //#define METADATA_VERBOSE -cuhd_msg_handler_t msg_handler; +rf_msg_handler_t msg_handler; void suppress_handler(uhd::msg::type_t type, const std::string & msg) { @@ -57,7 +57,7 @@ typedef _Complex float complex_t; bool isLocked(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(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 = @@ -74,7 +74,7 @@ bool isLocked(void *h) } } -bool cuhd_rx_wait_lo_locked(void *h) +bool rf_rx_wait_lo_locked(void *h) { double report = 0.0; @@ -85,9 +85,9 @@ bool cuhd_rx_wait_lo_locked(void *h) return isLocked(h); } -int cuhd_start_rx_stream(void *h) +int rf_start_rx_stream(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(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; @@ -95,9 +95,9 @@ int cuhd_start_rx_stream(void *h) return 0; } -int cuhd_stop_rx_stream(void *h) +int rf_stop_rx_stream(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(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; @@ -105,17 +105,17 @@ int cuhd_stop_rx_stream(void *h) return 0; } -void cuhd_flush_buffer(void *h) +void rf_flush_buffer(void *h) { int n; _Complex float tmp[1024]; do { - n = cuhd_recv(h, tmp, 1024, 0); + n = rf_recv(h, tmp, 1024, 0); } while (n > 0); } -bool cuhd_has_rssi(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); +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()) { @@ -125,9 +125,9 @@ bool cuhd_has_rssi(void *h) { } } -float cuhd_get_rssi(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); - if (cuhd_has_rssi(h)) { +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 { @@ -135,9 +135,9 @@ float cuhd_get_rssi(void *h) { } } -int cuhd_start_rx_stream_nsamples(void *h, uint32_t nsamples) +int rf_start_rx_stream_nsamples(void *h, uint32_t nsamples) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + 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; @@ -146,9 +146,9 @@ int cuhd_start_rx_stream_nsamples(void *h, uint32_t nsamples) return 0; } -double cuhd_set_rx_gain_th(void *h, double gain) +double rf_set_rx_gain_th(void *h, double gain) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + 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); @@ -159,9 +159,9 @@ double cuhd_set_rx_gain_th(void *h, double gain) return gain; } -double cuhd_set_tx_gain_th(void *h, double gain) +double rf_set_tx_gain_th(void *h, double gain) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + 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); @@ -172,14 +172,14 @@ double cuhd_set_tx_gain_th(void *h, double gain) return gain; } -void cuhd_set_tx_rx_gain_offset(void *h, double offset) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); +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) { - cuhd_handler *handler = static_cast < cuhd_handler * >(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 && @@ -189,33 +189,33 @@ static void* thread_gain_fcn(void *h) { } if (handler->new_rx_gain != handler->cur_rx_gain) { handler->cur_rx_gain = handler->new_rx_gain; - cuhd_set_rx_gain(h, handler->cur_rx_gain); + rf_set_rx_gain(h, handler->cur_rx_gain); } if (handler->tx_gain_same_rx) { - cuhd_set_tx_gain(h, handler->cur_rx_gain+handler->tx_rx_gain_offset); + 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; - cuhd_set_tx_gain(h, handler->cur_tx_gain); + rf_set_tx_gain(h, handler->cur_tx_gain); } pthread_mutex_unlock(&handler->mutex); } } -float cuhd_get_rx_gain_offset(void *h) { +float rf_get_rx_gain_offset(void *h) { return 15; } -void cuhd_suppress_stdout() { +void rf_suppress_stdout() { uhd::msg::register_handler(suppress_handler); } -void cuhd_register_msg_handler(cuhd_msg_handler_t h) +void rf_register_msg_handler(rf_msg_handler_t h) { msg_handler = h; uhd::msg::register_handler(translate_handler); } -int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx) +int rf_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx) { *h = NULL; @@ -225,7 +225,7 @@ int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_ /* Get multiusrp handler */ - cuhd_handler *handler = new cuhd_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"); @@ -285,86 +285,86 @@ int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_ return 0; } -int cuhd_open(char *args, void **h) { - return cuhd_open_(args, h, false, false); +int rf_open(char *args, void **h) { + return rf_open_(args, h, false, false); } -int cuhd_open_th(char *args, void **h, bool tx_gain_same_rx) { - return cuhd_open_(args, h, true, tx_gain_same_rx); +int rf_open_th(char *args, void **h, bool tx_gain_same_rx) { + return rf_open_(args, h, true, tx_gain_same_rx); } -int cuhd_close(void *h) +int rf_close(void *h) { - cuhd_stop_rx_stream(h); + rf_stop_rx_stream(h); /** Something else to close the USRP?? */ return 0; } -void cuhd_set_master_clock_rate(void *h, double rate) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); +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 cuhd_is_master_clock_dynamic(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); +bool rf_is_master_clock_dynamic(void *h) { + rf_handler *handler = static_cast < rf_handler * >(h); return handler->dynamic_rate; } -double cuhd_set_rx_srate(void *h, double freq) +double rf_set_rx_srate(void *h, double freq) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); handler->usrp->set_rx_rate(freq); return handler->usrp->get_rx_rate(); } -double cuhd_set_rx_gain(void *h, double gain) +double rf_set_rx_gain(void *h, double gain) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); handler->usrp->set_rx_gain(gain); return handler->usrp->get_rx_gain(); } -double cuhd_get_rx_gain(void *h) +double rf_get_rx_gain(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); return handler->usrp->get_rx_gain(); } -double cuhd_get_tx_gain(void *h) +double rf_get_tx_gain(void *h) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); return handler->usrp->get_tx_gain(); } -double cuhd_set_rx_freq(void *h, double freq) +double rf_set_rx_freq(void *h, double freq) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); handler->usrp->set_rx_freq(freq); return freq; } -double cuhd_set_rx_freq_offset(void *h, double freq, double off) { - cuhd_handler* handler = static_cast(h); +double rf_set_rx_freq_offset(void *h, double freq, double off) { + rf_handler* handler = static_cast(h); handler->usrp->set_rx_freq(uhd::tune_request_t(freq, off)); return handler->usrp->get_rx_freq(); } -int cuhd_recv(void *h, void *data, uint32_t nsamples, bool blocking) +int rf_recv(void *h, void *data, uint32_t nsamples, bool blocking) { - return cuhd_recv_with_time(h, data, nsamples, blocking, NULL, NULL); + return rf_recv_with_time(h, data, nsamples, blocking, NULL, NULL); } -int cuhd_recv_with_time(void *h, +int rf_recv_with_time(void *h, void *data, uint32_t nsamples, bool blocking, time_t *secs, double *frac_secs) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); uhd::rx_metadata_t md, md_first; if (blocking) { int n = 0, p; @@ -397,37 +397,37 @@ int cuhd_recv_with_time(void *h, } return nsamples; } -double cuhd_set_tx_gain(void *h, double gain) +double rf_set_tx_gain(void *h, double gain) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); handler->usrp->set_tx_gain(gain); return gain; } -double cuhd_set_tx_srate(void *h, double freq) +double rf_set_tx_srate(void *h, double freq) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + 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 cuhd_set_tx_freq(void *h, double freq) +double rf_set_tx_freq(void *h, double freq) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); + rf_handler *handler = static_cast < rf_handler * >(h); handler->usrp->set_tx_freq(freq); return handler->usrp->get_tx_freq(); } -double cuhd_set_tx_freq_offset(void *h, double freq, double off) { - cuhd_handler* handler = static_cast(h); +double rf_set_tx_freq_offset(void *h, double freq, double off) { + rf_handler* handler = static_cast(h); handler->usrp->set_tx_freq(uhd::tune_request_t(freq, off)); return handler->usrp->get_tx_freq(); } -void cuhd_get_time(void *h, time_t *secs, double *frac_secs) { - cuhd_handler *handler = static_cast < cuhd_handler * >(h); +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(); @@ -438,7 +438,7 @@ void cuhd_get_time(void *h, time_t *secs, double *frac_secs) { } -int cuhd_send_timed3(void *h, +int rf_send_timed3(void *h, void *data, int nsamples, time_t secs, @@ -448,7 +448,7 @@ int cuhd_send_timed3(void *h, bool is_start_of_burst, bool is_end_of_burst) { - cuhd_handler* handler = static_cast(h); + rf_handler* handler = static_cast(h); uhd::tx_metadata_t md; md.has_time_spec = has_time_spec; if (has_time_spec) { @@ -489,27 +489,27 @@ int cuhd_send_timed3(void *h, } } -int cuhd_send(void *h, void *data, uint32_t nsamples, bool blocking) +int rf_send(void *h, void *data, uint32_t nsamples, bool blocking) { - return cuhd_send2(h, data, nsamples, blocking, true, true); + return rf_send2(h, data, nsamples, blocking, true, true); } -int cuhd_send2(void *h, void *data, uint32_t nsamples, bool blocking, bool start_of_burst, bool end_of_burst) +int rf_send2(void *h, void *data, uint32_t nsamples, bool blocking, bool start_of_burst, bool end_of_burst) { - return cuhd_send_timed3(h, data, nsamples, 0, 0, false, blocking, start_of_burst, end_of_burst); + return rf_send_timed3(h, data, nsamples, 0, 0, false, blocking, start_of_burst, end_of_burst); } -int cuhd_send_timed(void *h, +int rf_send_timed(void *h, void *data, int nsamples, time_t secs, double frac_secs) { - return cuhd_send_timed2(h, data, nsamples, secs, frac_secs, true, true); + return rf_send_timed2(h, data, nsamples, secs, frac_secs, true, true); } -int cuhd_send_timed2(void *h, +int rf_send_timed2(void *h, void *data, int nsamples, time_t secs, @@ -517,5 +517,5 @@ int cuhd_send_timed2(void *h, bool is_start_of_burst, bool is_end_of_burst) { - return cuhd_send_timed3(h, data, nsamples, secs, frac_secs, true, true, is_start_of_burst, is_end_of_burst); + return rf_send_timed3(h, data, nsamples, secs, frac_secs, true, true, is_start_of_burst, is_end_of_burst); } diff --git a/srslte/lib/cuhd/src/cuhd_utils.c b/srslte/lib/rf/src/rf_utils.c similarity index 78% rename from srslte/lib/cuhd/src/cuhd_utils.c rename to srslte/lib/rf/src/rf_utils.c index 1cf802fa8..04336ae74 100644 --- a/srslte/lib/cuhd/src/cuhd_utils.c +++ b/srslte/lib/rf/src/rf_utils.c @@ -36,10 +36,10 @@ #include "srslte/srslte.h" -#include "srslte/cuhd/cuhd.h" -#include "srslte/cuhd/cuhd_utils.h" +#include "srslte/rf/rf.h" +#include "srslte/rf/rf_utils.h" -int cuhd_rssi_scan(void *uhd, float *freqs, float *rssi, int nof_bands, double fs, int nsamp) { +int rf_rssi_scan(void *uhd, float *freqs, float *rssi, int nof_bands, double fs, int nsamp) { int i, j; int ret = -1; _Complex float *buffer; @@ -50,21 +50,21 @@ int cuhd_rssi_scan(void *uhd, float *freqs, float *rssi, int nof_bands, double f goto free_and_exit; } - cuhd_set_rx_gain(uhd, 20.0); - cuhd_set_rx_srate(uhd, fs); + rf_set_rx_gain(uhd, 20.0); + rf_set_rx_srate(uhd, fs); for (i=0;iid, cell->cp, cuhd_recv_wrapper_cs, uhd)) { + if (srslte_ue_mib_sync_init(&ue_mib, cell->id, cell->cp, rf_recv_wrapper_cs, uhd)) { fprintf(stderr, "Error initiating srslte_ue_mib_sync\n"); goto clean_exit; } if (config->init_agc > 0) { - srslte_ue_sync_start_agc(&ue_mib.ue_sync, cuhd_set_rx_gain_th, config->init_agc); + srslte_ue_sync_start_agc(&ue_mib.ue_sync, rf_set_rx_gain_th, config->init_agc); } int srate = srslte_sampling_freq_hz(SRSLTE_UE_MIB_NOF_PRB); INFO("Setting sampling frequency %.2f MHz for PSS search\n", (float) srate/1000000); - cuhd_set_rx_srate(uhd, (float) srate); + rf_set_rx_srate(uhd, (float) srate); INFO("Starting receiver...\n", 0); - cuhd_start_rx_stream(uhd); + rf_start_rx_stream(uhd); /* Find and decody MIB */ ret = srslte_ue_mib_sync_decode(&ue_mib, config->max_frames_pss, bch_payload, &cell->nof_ports, NULL); @@ -129,15 +129,15 @@ int cuhd_mib_decoder(void *uhd, cell_search_cfg_t *config, srslte_cell_t *cell) clean_exit: - cuhd_stop_rx_stream(uhd); + rf_stop_rx_stream(uhd); srslte_ue_mib_sync_free(&ue_mib); return ret; } -/** This function is simply a wrapper to the ue_cell_search module for cuhd devices +/** This function is simply a wrapper to the ue_cell_search module for rf devices */ -int cuhd_cell_search(void *uhd, cell_search_cfg_t *config, +int rf_cell_search(void *uhd, cell_search_cfg_t *config, int force_N_id_2, srslte_cell_t *cell) { int ret = SRSLTE_ERROR; @@ -146,7 +146,7 @@ int cuhd_cell_search(void *uhd, cell_search_cfg_t *config, bzero(found_cells, 3*sizeof(srslte_ue_cellsearch_result_t)); - if (srslte_ue_cellsearch_init(&cs, cuhd_recv_wrapper_cs, uhd)) { + if (srslte_ue_cellsearch_init(&cs, rf_recv_wrapper_cs, uhd)) { fprintf(stderr, "Error initiating UE cell detect\n"); return SRSLTE_ERROR; } @@ -159,14 +159,14 @@ int cuhd_cell_search(void *uhd, cell_search_cfg_t *config, } if (config->init_agc > 0) { - srslte_ue_sync_start_agc(&cs.ue_sync, cuhd_set_rx_gain_th, config->init_agc); + srslte_ue_sync_start_agc(&cs.ue_sync, rf_set_rx_gain_th, config->init_agc); } INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000); - cuhd_set_rx_srate(uhd, SRSLTE_CS_SAMP_FREQ); + rf_set_rx_srate(uhd, SRSLTE_CS_SAMP_FREQ); INFO("Starting receiver...\n", 0); - cuhd_start_rx_stream(uhd); + rf_start_rx_stream(uhd); /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */ uint32_t max_peak_cell = 0; @@ -207,7 +207,7 @@ int cuhd_cell_search(void *uhd, cell_search_cfg_t *config, config->init_agc = srslte_agc_get_gain(&cs.ue_sync.agc); } - cuhd_stop_rx_stream(uhd); + rf_stop_rx_stream(uhd); srslte_ue_cellsearch_free(&cs); return ret; @@ -219,15 +219,15 @@ int cuhd_cell_search(void *uhd, cell_search_cfg_t *config, * 0 if no cell was found or MIB could not be decoded, * -1 on error */ -int cuhd_search_and_decode_mib(void *uhd, cell_search_cfg_t *config, int force_N_id_2, srslte_cell_t *cell) +int rf_search_and_decode_mib(void *uhd, cell_search_cfg_t *config, int force_N_id_2, srslte_cell_t *cell) { int ret = SRSLTE_ERROR; printf("Searching for cell...\n"); - ret = cuhd_cell_search(uhd, config, force_N_id_2, cell); + ret = rf_cell_search(uhd, config, force_N_id_2, cell); if (ret > 0) { printf("Decoding PBCH for cell %d (N_id_2=%d)\n", cell->id, cell->id%3); - ret = cuhd_mib_decoder(uhd, config, cell); + ret = rf_mib_decoder(uhd, config, cell); if (ret < 0) { fprintf(stderr, "Could not decode PBCH from CELL ID %d\n", cell->id); return SRSLTE_ERROR; diff --git a/srslte/lib/sync/test/CMakeLists.txt b/srslte/lib/sync/test/CMakeLists.txt index 1eb40a72f..760b9de8b 100644 --- a/srslte/lib/sync/test/CMakeLists.txt +++ b/srslte/lib/sync/test/CMakeLists.txt @@ -33,7 +33,7 @@ ENDIF(SRSGUI_FOUND) IF(UHD_FOUND) ADD_EXECUTABLE(pss_usrp pss_usrp.c) - TARGET_LINK_LIBRARIES(pss_usrp srslte srslte_uhd) + TARGET_LINK_LIBRARIES(pss_usrp srslte srslte_rf) IF(SRSGUI_FOUND) target_link_libraries(pss_usrp ${SRSGUI_LIBRARIES}) ELSE(SRSGUI_FOUND) diff --git a/srslte/lib/sync/test/pss_usrp.c b/srslte/lib/sync/test/pss_usrp.c index 69daf50e1..d49620e6e 100644 --- a/srslte/lib/sync/test/pss_usrp.c +++ b/srslte/lib/sync/test/pss_usrp.c @@ -35,7 +35,7 @@ #include #include "srslte/srslte.h" -#include "srslte/cuhd/cuhd.h" +#include "srslte/rf/rf.h" #ifndef DISABLE_GRAPHICS @@ -153,21 +153,21 @@ int main(int argc, char **argv) { flen = srate*5/1000; printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { + if (rf_open(uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); exit(-1); } if (srate < 10e6) { - cuhd_set_master_clock_rate(uhd, 4*srate); + rf_set_master_clock_rate(uhd, 4*srate); } else { - cuhd_set_master_clock_rate(uhd, srate); + rf_set_master_clock_rate(uhd, srate); } - printf("Set RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, srate) / 1000000); - printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain)); - printf("Set RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - cuhd_rx_wait_lo_locked(uhd); + printf("Set RX rate: %.2f MHz\n", rf_set_rx_srate(uhd, srate) / 1000000); + printf("Set RX gain: %.1f dB\n", rf_set_rx_gain(uhd, uhd_gain)); + printf("Set RX freq: %.2f MHz\n", rf_set_rx_freq(uhd, uhd_freq) / 1000000); + rf_rx_wait_lo_locked(uhd); buffer = malloc(sizeof(cf_t) * flen * 2); if (!buffer) { @@ -197,7 +197,7 @@ int main(int argc, char **argv) { printf("N_id_2: %d\n", N_id_2); - cuhd_start_rx_stream(uhd); + rf_start_rx_stream(uhd); printf("Frame length %d samples\n", flen); printf("PSS detection threshold: %.2f\n", threshold); @@ -218,7 +218,7 @@ int main(int argc, char **argv) { ssync.fft_size = fft_size; while(frame_cnt < nof_frames || nof_frames == -1) { - n = cuhd_recv(uhd, buffer, flen - peak_offset, 1); + n = rf_recv(uhd, buffer, flen - peak_offset, 1); if (n < 0) { fprintf(stderr, "Error receiving samples\n"); exit(-1); @@ -330,7 +330,7 @@ int main(int argc, char **argv) { srslte_pss_synch_free(&pss); free(buffer); - cuhd_close(uhd); + rf_close(uhd); printf("Ok\n"); exit(0);