aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt14
-rw-r--r--cmake/Modules/FindLibUSB.cmake2
-rw-r--r--configure.ac6
-rw-r--r--include/rtl-sdr.h11
-rw-r--r--src/CMakeLists.txt14
-rw-r--r--src/librtlsdr.c13
-rw-r--r--src/rtl_biast.c101
-rw-r--r--src/rtl_eeprom.c6
-rw-r--r--src/rtlsdr.rc.in2
9 files changed, 154 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index abc8f9b..8b175e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,7 +31,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
-list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
+list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
if(NOT LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR lib)
@@ -80,7 +80,7 @@ endif()
# Setup the include and linker paths
########################################################################
include_directories(
- ${CMAKE_SOURCE_DIR}/include
+ ${PROJECT_SOURCE_DIR}/include
${LIBUSB_INCLUDE_DIR}
${THREADS_PTHREADS_INCLUDE_DIR}
)
@@ -96,7 +96,7 @@ include_directories(
# Create uninstall target
########################################################################
configure_file(
- ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
+ ${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
@ONLY)
@@ -126,6 +126,14 @@ else (DETACH_KERNEL_DRIVER)
message (STATUS "Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable")
endif (DETACH_KERNEL_DRIVER)
+option(ENABLE_ZEROCOPY "Enable usbfs zero-copy support" OFF)
+if (ENABLE_ZEROCOPY)
+ message (STATUS "Building with usbfs zero-copy support enabled")
+ add_definitions(-DENABLE_ZEROCOPY=1)
+else (ENABLE_ZEROCOPY)
+ message (STATUS "Building with usbfs zero-copy support disabled, use -DENABLE_ZEROCOPY=ON to enable")
+endif (ENABLE_ZEROCOPY)
+
########################################################################
# Add subdirectories
########################################################################
diff --git a/cmake/Modules/FindLibUSB.cmake b/cmake/Modules/FindLibUSB.cmake
index c2c3f63..bbf5593 100644
--- a/cmake/Modules/FindLibUSB.cmake
+++ b/cmake/Modules/FindLibUSB.cmake
@@ -9,7 +9,7 @@ if(NOT LIBUSB_FOUND)
)
#standard library name for libusb-1.0
-set(libusb1_library_names usb-1.0)
+set(libusb1_library_names usb-1.0 libusb-1.0)
#libusb-1.0 compatible library on freebsd
if((CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") OR (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD"))
diff --git a/configure.ac b/configure.ac
index 5b94828..1afbfbd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,12 @@ AC_ARG_ENABLE(driver-detach,
CFLAGS="$CFLAGS -DDETACH_KERNEL_DRIVER"
fi])
+AC_ARG_ENABLE(zerocopy,
+[ --enable-zerocopy Enable usbfs zero-copy support (disabled by default)],
+[if test x$enableval = xyes; then
+ CFLAGS="$CFLAGS -DENABLE_ZEROCOPY"
+fi])
+
dnl Generate the output
AC_CONFIG_HEADER(config.h)
diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h
index 3ed13ae..d64701e 100644
--- a/include/rtl-sdr.h
+++ b/include/rtl-sdr.h
@@ -389,6 +389,17 @@ RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev);
*/
RTLSDR_API int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on);
+/*!
+ * Enable or disable the bias tee on the given GPIO pin.
+ *
+ * \param dev the device handle given by rtlsdr_open()
+ * \param gpio the gpio pin to configure as a Bias T control.
+ * \param on 1 for Bias T on. 0 for Bias T off.
+ * \return -1 if device is not initialized. 0 otherwise.
+ */
+RTLSDR_API int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 07d64ab..5d6aff0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -34,7 +34,7 @@ RTLSDR_APPEND_SRCS(
# Set up Windows DLL resource files
########################################################################
IF(MSVC)
- include(${CMAKE_SOURCE_DIR}/cmake/Modules/Version.cmake)
+ include(${PROJECT_SOURCE_DIR}/cmake/Modules/Version.cmake)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/rtlsdr.rc.in
@@ -91,7 +91,8 @@ add_executable(rtl_fm rtl_fm.c)
add_executable(rtl_eeprom rtl_eeprom.c)
add_executable(rtl_adsb rtl_adsb.c)
add_executable(rtl_power rtl_power.c)
-set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power)
+add_executable(rtl_biast rtl_biast.c)
+set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power rtl_biast)
target_link_libraries(rtl_sdr rtlsdr_shared convenience_static
${LIBUSB_LIBRARIES}
@@ -121,11 +122,16 @@ target_link_libraries(rtl_power rtlsdr_shared convenience_static
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
+target_link_libraries(rtl_biast rtlsdr_shared convenience_static
+ ${LIBUSB_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT}
+)
+
if(UNIX)
target_link_libraries(rtl_fm m)
target_link_libraries(rtl_adsb m)
target_link_libraries(rtl_power m)
-if(APPLE)
+if(APPLE OR CMAKE_SYSTEM MATCHES "OpenBSD")
target_link_libraries(rtl_test m)
else()
target_link_libraries(rtl_test m rt)
@@ -140,6 +146,7 @@ target_link_libraries(rtl_fm libgetopt_static)
target_link_libraries(rtl_eeprom libgetopt_static)
target_link_libraries(rtl_adsb libgetopt_static)
target_link_libraries(rtl_power libgetopt_static)
+target_link_libraries(rtl_biast libgetopt_static)
set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_tcp APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_test APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
@@ -147,6 +154,7 @@ set_property(TARGET rtl_fm APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_eeprom APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_adsb APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
set_property(TARGET rtl_power APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
+set_property(TARGET rtl_biast APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
endif()
########################################################################
# Install built library files & utilities
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index d72a0f5..0146298 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -1751,7 +1751,7 @@ static int _rtlsdr_alloc_async_buffers(rtlsdr_dev_t *dev)
dev->xfer_buf = malloc(dev->xfer_buf_num * sizeof(unsigned char *));
memset(dev->xfer_buf, 0, dev->xfer_buf_num * sizeof(unsigned char *));
-#if defined (__linux__) && LIBUSB_API_VERSION >= 0x01000105
+#if defined(ENABLE_ZEROCOPY) && defined (__linux__) && LIBUSB_API_VERSION >= 0x01000105
fprintf(stderr, "Allocating %d zero-copy buffers\n", dev->xfer_buf_num);
dev->use_zerocopy = 1;
@@ -2009,13 +2009,18 @@ int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len)
return -1;
}
-int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on)
+int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on)
{
if (!dev)
return -1;
- rtlsdr_set_gpio_output(dev, 0);
- rtlsdr_set_gpio_bit(dev, 0, on);
+ rtlsdr_set_gpio_output(dev, gpio);
+ rtlsdr_set_gpio_bit(dev, gpio, on);
return 0;
}
+
+int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on)
+{
+ return rtlsdr_set_bias_tee_gpio(dev, 0, on);
+}
diff --git a/src/rtl_biast.c b/src/rtl_biast.c
new file mode 100644
index 0000000..185e838
--- /dev/null
+++ b/src/rtl_biast.c
@@ -0,0 +1,101 @@
+/*
+ * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
+ * rtl_biast, tool to set bias tee gpio output
+ * Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#include <windows.h>
+#include "getopt/getopt.h"
+#endif
+
+#include "rtl-sdr.h"
+#include "convenience/convenience.h"
+
+static rtlsdr_dev_t *dev = NULL;
+
+void usage(void)
+{
+ fprintf(stderr,
+ "rtl_biast, a tool for turning the RTL-SDR.com \n"
+ "bias tee or any GPIO ON and OFF. Example to turn on the \n"
+ "bias tee: rtl_biast -d 0 -b 1\n"
+ "Any GPIO: rtl_biast -d 0 -g 1 -b 1\n\n"
+ "Usage:\n"
+ "\t[-d device_index (default: 0)]\n"
+ "\t[-b bias_on (default: 0)]\n"
+ "\t[-g GPIO select (default: 0)]\n");
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ int i, r, opt;
+ int dev_index = 0;
+ int dev_given = 0;
+ uint32_t bias_on = 0;
+ uint32_t gpio_pin = 0;
+ int device_count;
+
+ while ((opt = getopt(argc, argv, "d:b:g:h?")) != -1) {
+ switch (opt) {
+ case 'd':
+ dev_index = verbose_device_search(optarg);
+ dev_given = 1;
+ break;
+ case 'b':
+ bias_on = atoi(optarg);
+ break;
+ case 'g':
+ gpio_pin = atoi(optarg);
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
+
+ if (!dev_given) {
+ dev_index = verbose_device_search("0");
+ }
+
+ if (dev_index < 0) {
+ exit(1);
+ }
+
+ r = rtlsdr_open(&dev, dev_index);
+ rtlsdr_set_bias_tee_gpio(dev, gpio_pin, bias_on);
+
+exit:
+ /*
+ * Note - rtlsdr_close() in this tree does not clear the bias tee
+ * GPIO line, so it leaves the bias tee enabled if a client program
+ * doesn't explictly disable it.
+ *
+ * If that behaviour changes then another rtlsdr_close() will be
+ * needed that takes some extension flags, and one of them should
+ * be to either explicitly close the biast or leave it alone.
+ */
+ rtlsdr_close(dev);
+
+ return r >= 0 ? r : -r;
+}
diff --git a/src/rtl_eeprom.c b/src/rtl_eeprom.c
index f562d73..24be900 100644
--- a/src/rtl_eeprom.c
+++ b/src/rtl_eeprom.c
@@ -370,14 +370,14 @@ int main(int argc, char **argv)
}
if (manuf_str)
- strncpy((char*)&conf.manufacturer, manuf_str, MAX_STR_SIZE);
+ strncpy((char*)&conf.manufacturer, manuf_str, MAX_STR_SIZE - 1);
if (product_str)
- strncpy((char*)&conf.product, product_str, MAX_STR_SIZE);
+ strncpy((char*)&conf.product, product_str, MAX_STR_SIZE - 1);
if (serial_str) {
conf.have_serial = 1;
- strncpy((char*)&conf.serial, serial_str, MAX_STR_SIZE);
+ strncpy((char*)&conf.serial, serial_str, MAX_STR_SIZE - 1);
}
if (ir_endpoint != 0)
diff --git a/src/rtlsdr.rc.in b/src/rtlsdr.rc.in
index bf603c3..0861ecb 100644
--- a/src/rtlsdr.rc.in
+++ b/src/rtlsdr.rc.in
@@ -1,5 +1,5 @@
-#include <afxres.h>
+#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,0