From ba64a7459a43652354990855176a7d8dad5b9d54 Mon Sep 17 00:00:00 2001 From: Lucas Teske Date: Wed, 17 Aug 2016 20:31:33 -0300 Subject: [PATCH 01/21] lib: fix direction bit in GPIO code source: http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html * Removed unnecessary comment of old code. Signed-off-by: Fabian P. Schmidt Signed-off-by: Steve Markgraf --- src/librtlsdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 9b7ba52..e2c3c73 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -570,7 +570,7 @@ void rtlsdr_set_gpio_output(rtlsdr_dev_t *dev, uint8_t gpio) gpio = 1 << gpio; r = rtlsdr_read_reg(dev, SYSB, GPD, 1); - rtlsdr_write_reg(dev, SYSB, GPO, r & ~gpio, 1); + rtlsdr_write_reg(dev, SYSB, GPD, r & ~gpio, 1); r = rtlsdr_read_reg(dev, SYSB, GPOE, 1); rtlsdr_write_reg(dev, SYSB, GPOE, r | gpio, 1); } From 2be1612e604f950ba21ef6ff12488eab62e66ad5 Mon Sep 17 00:00:00 2001 From: Lucas Teske Date: Wed, 17 Aug 2016 10:14:57 -0300 Subject: [PATCH 02/21] lib: Use GPIO P0 to toggle an (optional) bias-t At least one distributor of rtl-sdr dongles (rtl-sdr.com) added a bias-t to their dongles which could be toggled via GPIO P0 of the RTL2832U chip. source: http://www.rtl-sdr.com/rtl-sdr-blog-v-3-dongles-user-guide/ Signed-off-by: Steve Markgraf --- include/rtl-sdr.h | 9 +++++++++ src/librtlsdr.c | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h index fe64bea..3ed13ae 100644 --- a/include/rtl-sdr.h +++ b/include/rtl-sdr.h @@ -380,6 +380,15 @@ RTLSDR_API int rtlsdr_read_async(rtlsdr_dev_t *dev, */ RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev); +/*! + * Enable or disable the bias tee on GPIO PIN 0. + * + * \param dev the device handle given by rtlsdr_open() + * \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(rtlsdr_dev_t *dev, int on); + #ifdef __cplusplus } #endif diff --git a/src/librtlsdr.c b/src/librtlsdr.c index e2c3c73..b369a5d 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -1937,3 +1937,14 @@ 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) +{ + if (!dev) + return -1; + + rtlsdr_set_gpio_output(dev, 0); + rtlsdr_set_gpio_bit(dev, 0, on); + + return 0; +} From fa3a113b77b6ed2738778a52ae4f9ce4e6f18ea3 Mon Sep 17 00:00:00 2001 From: Dimitri Stolnikov Date: Mon, 12 Jun 2017 00:04:05 +0200 Subject: [PATCH 03/21] rtl_tcp: add command for bias tee control --- src/rtl_tcp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c index 317e0f3..aef120e 100644 --- a/src/rtl_tcp.c +++ b/src/rtl_tcp.c @@ -355,6 +355,10 @@ static void *command_worker(void *arg) printf("set tuner gain by index %d\n", ntohl(cmd.param)); set_gain_by_index(dev, ntohl(cmd.param)); break; + case 0x0e: + printf("set bias tee %d\n", ntohl(cmd.param)); + rtlsdr_set_bias_tee(dev, (int)ntohl(cmd.param)); + break; default: break; } From 18bf26989c926a5db4fca29e7d859af42af1437c Mon Sep 17 00:00:00 2001 From: hayati ayguen Date: Sun, 11 Jun 2017 00:18:53 +0200 Subject: [PATCH 04/21] Add option '-T' for activating bias-T in rtl_(adsb|fm|power|tcp) * added debug output when activating Signed-off-by: hayati ayguen * fixed options argument Signed-off-by: Fabian P. Schmidt Signed-off-by: Steve Markgraf --- src/rtl_adsb.c | 11 ++++++++++- src/rtl_fm.c | 11 ++++++++++- src/rtl_power.c | 11 ++++++++++- src/rtl_tcp.c | 13 +++++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/rtl_adsb.c b/src/rtl_adsb.c index e611e78..07fdd2a 100644 --- a/src/rtl_adsb.c +++ b/src/rtl_adsb.c @@ -96,6 +96,7 @@ void usage(void) "\t[-e allowed_errors (default: 5)]\n" "\t[-g tuner_gain (default: automatic)]\n" "\t[-p ppm_error (default: 0)]\n" + "\t[-T enable bias-T on GPIO PIN 0 (works for rtl-sdr.com v3 dongles)]\n" "\tfilename (a '-' dumps samples to stdout)\n" "\t (omitting the filename also uses stdout)\n\n" "Streaming with netcat:\n" @@ -371,11 +372,12 @@ int main(int argc, char **argv) int dev_index = 0; int dev_given = 0; int ppm_error = 0; + int enable_biastee = 0; pthread_cond_init(&ready, NULL); pthread_mutex_init(&ready_m, NULL); squares_precompute(); - while ((opt = getopt(argc, argv, "d:g:p:e:Q:VS")) != -1) + while ((opt = getopt(argc, argv, "d:g:p:e:Q:VST")) != -1) { switch (opt) { case 'd': @@ -400,6 +402,9 @@ int main(int argc, char **argv) case 'Q': quality = (int)(atof(optarg) * 10); break; + case 'T': + enable_biastee = 1; + break; default: usage(); return 0; @@ -470,6 +475,10 @@ int main(int argc, char **argv) /* Set the sample rate */ verbose_set_sample_rate(dev, ADSB_RATE); + rtlsdr_set_bias_tee(dev, enable_biastee); + if (enable_biastee) + fprintf(stderr, "activated bias-T on GPIO PIN 0\n"); + /* Reset endpoint before we start reading from it (mandatory) */ verbose_reset_buffer(dev); diff --git a/src/rtl_fm.c b/src/rtl_fm.c index e89e42d..d2d011a 100644 --- a/src/rtl_fm.c +++ b/src/rtl_fm.c @@ -193,6 +193,7 @@ void usage(void) "\t raw mode outputs 2x16 bit IQ pairs\n" "\t[-s sample_rate (default: 24k)]\n" "\t[-d device_index (default: 0)]\n" + "\t[-T enable bias-T on GPIO PIN 0 (works for rtl-sdr.com v3 dongles)]\n" "\t[-g tuner_gain (default: automatic)]\n" "\t[-l squelch_level (default: 0/off)]\n" //"\t for fm squelch is inverted\n" @@ -1042,12 +1043,13 @@ int main(int argc, char **argv) int r, opt; int dev_given = 0; int custom_ppm = 0; + int enable_biastee = 0; dongle_init(&dongle); demod_init(&demod); output_init(&output); controller_init(&controller); - while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:E:F:A:M:h")) != -1) { + while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:E:F:A:M:hT")) != -1) { switch (opt) { case 'd': dongle.dev_index = verbose_device_search(optarg); @@ -1142,6 +1144,9 @@ int main(int argc, char **argv) demod.deemph = 1; demod.squelch_level = 0;} break; + case 'T': + enable_biastee = 1; + break; case 'h': default: usage(); @@ -1205,6 +1210,10 @@ int main(int argc, char **argv) verbose_gain_set(dongle.dev, dongle.gain); } + rtlsdr_set_bias_tee(dongle.dev, enable_biastee); + if (enable_biastee) + fprintf(stderr, "activated bias-T on GPIO PIN 0\n"); + verbose_ppm_set(dongle.dev, dongle.ppm_error); if (strcmp(output.filename, "-") == 0) { /* Write samples to stdout */ diff --git a/src/rtl_power.c b/src/rtl_power.c index aa7a138..00f4d9f 100644 --- a/src/rtl_power.c +++ b/src/rtl_power.c @@ -133,6 +133,7 @@ void usage(void) "\t[-d device_index (default: 0)]\n" "\t[-g tuner_gain (default: automatic)]\n" "\t[-p ppm_error (default: 0)]\n" + "\t[-T enable bias-T on GPIO PIN 0 (works for rtl-sdr.com v3 dongles)]\n" "\tfilename (a '-' dumps samples to stdout)\n" "\t (omitting the filename also uses stdout)\n" "\n" @@ -771,6 +772,7 @@ int main(int argc, char **argv) int single = 0; int direct_sampling = 0; int offset_tuning = 0; + int enable_biastee = 0; double crop = 0.0; char *freq_optarg; time_t next_tick; @@ -781,7 +783,7 @@ int main(int argc, char **argv) double (*window_fn)(int, int) = rectangle; freq_optarg = ""; - while ((opt = getopt(argc, argv, "f:i:s:t:d:g:p:e:w:c:F:1PDOh")) != -1) { + while ((opt = getopt(argc, argv, "f:i:s:t:d:g:p:e:w:c:F:1PDOhT")) != -1) { switch (opt) { case 'f': // lower:upper:bin_size freq_optarg = strdup(optarg); @@ -849,6 +851,9 @@ int main(int argc, char **argv) boxcar = 0; comp_fir_size = atoi(optarg); break; + case 'T': + enable_biastee = 1; + break; case 'h': default: usage(); @@ -925,6 +930,10 @@ int main(int argc, char **argv) verbose_ppm_set(dev, ppm_error); + rtlsdr_set_bias_tee(dev, enable_biastee); + if (enable_biastee) + fprintf(stderr, "activated bias-T on GPIO PIN 0\n"); + if (strcmp(filename, "-") == 0) { /* Write log to stdout */ file = stdout; #ifdef _WIN32 diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c index aef120e..da6057b 100644 --- a/src/rtl_tcp.c +++ b/src/rtl_tcp.c @@ -78,6 +78,7 @@ typedef struct { /* structure size must be multiple of 2 bytes */ static rtlsdr_dev_t *dev = NULL; +static int enable_biastee = 0; static int global_numq = 0; static struct llist *ll_buffers = 0; static int llbuf_num = 500; @@ -95,7 +96,8 @@ void usage(void) "\t[-b number of buffers (default: 15, set by library)]\n" "\t[-n max number of linked list buffers to keep (default: 500)]\n" "\t[-d device index (default: 0)]\n" - "\t[-P ppm_error (default: 0)]\n"); + "\t[-P ppm_error (default: 0)]\n" + "\t[-T enable bias-T on GPIO PIN 0 (works for rtl-sdr.com v3 dongles)]\n"); exit(1); } @@ -395,7 +397,7 @@ int main(int argc, char **argv) struct sigaction sigact, sigign; #endif - while ((opt = getopt(argc, argv, "a:p:f:g:s:b:n:d:P:")) != -1) { + while ((opt = getopt(argc, argv, "a:p:f:g:s:b:n:d:P:T")) != -1) { switch (opt) { case 'd': dev_index = verbose_device_search(optarg); @@ -425,6 +427,9 @@ int main(int argc, char **argv) case 'P': ppm_error = atoi(optarg); break; + case 'T': + enable_biastee = 1; + break; default: usage(); break; @@ -495,6 +500,10 @@ int main(int argc, char **argv) fprintf(stderr, "Tuner gain set to %f dB.\n", gain/10.0); } + rtlsdr_set_bias_tee(dev, enable_biastee); + if (enable_biastee) + fprintf(stderr, "activated bias-T on GPIO PIN 0\n"); + /* Reset endpoint before we start reading from it (mandatory) */ r = rtlsdr_reset_buffer(dev); if (r < 0) From b04c2f9f035c5aede43d731e5d58e4725d2f8bb4 Mon Sep 17 00:00:00 2001 From: Hoernchen Date: Tue, 19 Sep 2017 19:23:00 +0200 Subject: [PATCH 05/21] fix for msvc14 --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0597600..c6c6928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,9 @@ if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32) ADD_DEFINITIONS(-Wdeclaration-after-statement) #http://gcc.gnu.org/wiki/Visibility add_definitions(-fvisibility=hidden) +elseif(MSVC14 OR MSVC14) +#pthread-w32 issue, timespec is now part of time.h + ADD_DEFINITIONS(-D_TIMESPEC_DEFINED) endif() ######################################################################## From a03198c5b7d148ef258f8f7d5c873dd959dd2790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 1 Nov 2014 12:20:45 +0100 Subject: [PATCH 06/21] rtl_test: Support PPM error measurement on Windows. Signed-off-by: Steve Markgraf --- src/rtl_test.c | 58 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/src/rtl_test.c b/src/rtl_test.c index 9a6cfda..42d2c94 100644 --- a/src/rtl_test.c +++ b/src/rtl_test.c @@ -53,6 +53,21 @@ #define PPM_DURATION 10 #define PPM_DUMP_TIME 5 +struct time_generic +/* holds all the platform specific values */ +{ +#ifndef _WIN32 + time_t tv_sec; + long tv_nsec; +#else + long tv_sec; + long tv_nsec; + int init; + LARGE_INTEGER frequency; + LARGE_INTEGER ticks; +#endif +}; + static enum { NO_BENCHMARK, TUNER_BENCHMARK, @@ -134,12 +149,15 @@ static void underrun_test(unsigned char *buf, uint32_t len, int mute) } #ifndef _WIN32 -static int ppm_gettime(struct timespec *ts) +static int ppm_gettime(struct time_generic *tg) { int rv = ENOSYS; + struct timespec ts; #ifdef __unix__ - rv = clock_gettime(CLOCK_MONOTONIC, ts); + rv = clock_gettime(CLOCK_MONOTONIC, &ts); + tg->tv_sec = ts.tv_sec; + tg->tv_nsec = ts.tv_nsec; #elif __APPLE__ struct timeval tv; @@ -149,6 +167,24 @@ static int ppm_gettime(struct timespec *ts) #endif return rv; } +#endif + +#ifdef _WIN32 +static int ppm_gettime(struct time_generic *tg) +{ + int rv; + int64_t frac; + if (!tg->init) { + QueryPerformanceFrequency(&tg->frequency); + tg->init = 1; + } + rv = QueryPerformanceCounter(&tg->ticks); + tg->tv_sec = tg->ticks.QuadPart / tg->frequency.QuadPart; + frac = (int64_t)(tg->ticks.QuadPart - (tg->tv_sec * tg->frequency.QuadPart)); + tg->tv_nsec = (long)(frac * 1000000000L / (int64_t)tg->frequency.QuadPart); + return !rv; +} +#endif static int ppm_report(uint64_t nsamples, uint64_t interval) { @@ -165,8 +201,8 @@ static void ppm_test(uint32_t len) static uint64_t interval = 0; static uint64_t nsamples_total = 0; static uint64_t interval_total = 0; - struct timespec ppm_now; - static struct timespec ppm_recent; + struct time_generic ppm_now; + static struct time_generic ppm_recent; static enum { PPM_INIT_NO, PPM_INIT_DUMP, @@ -174,6 +210,7 @@ static void ppm_test(uint32_t len) } ppm_init = PPM_INIT_NO; ppm_gettime(&ppm_now); + if (ppm_init != PPM_INIT_RUN) { /* * Kyle Keen wrote: @@ -189,11 +226,11 @@ static void ppm_test(uint32_t len) } if (ppm_init == PPM_INIT_DUMP && ppm_recent.tv_sec < ppm_now.tv_sec) return; - ppm_recent.tv_sec = ppm_now.tv_sec; - ppm_recent.tv_nsec = ppm_now.tv_nsec; + ppm_recent = ppm_now; ppm_init = PPM_INIT_RUN; return; } + nsamples += (uint64_t)(len / 2UL); interval = (uint64_t)(ppm_now.tv_sec - ppm_recent.tv_sec); if (interval < ppm_duration) @@ -206,19 +243,16 @@ static void ppm_test(uint32_t len) (int)((1000000000UL * nsamples) / interval), ppm_report(nsamples, interval), ppm_report(nsamples_total, interval_total)); - ppm_recent.tv_sec = ppm_now.tv_sec; - ppm_recent.tv_nsec = ppm_now.tv_nsec; + ppm_recent = ppm_now; nsamples = 0; } -#endif static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) { underrun_test(buf, len, 0); -#ifndef _WIN32 + if (test_mode == PPM_BENCHMARK) ppm_test(len); -#endif } void e4k_benchmark(void) @@ -375,7 +409,7 @@ int main(int argc, char **argv) verbose_reset_buffer(dev); if ((test_mode == PPM_BENCHMARK) && !sync_mode) { - fprintf(stderr, "Reporting PPM error measurement every %i seconds...\n", ppm_duration); + fprintf(stderr, "Reporting PPM error measurement every %u seconds...\n", ppm_duration); fprintf(stderr, "Press ^C after a few minutes.\n"); } From 4520f001d85f01d051eaa42af7b18b6ef0837e14 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Tue, 20 Feb 2018 22:09:56 +0100 Subject: [PATCH 07/21] lib: fix FC0012 reset GPIO Since a typo in rtlsdr_set_gpio_output() was fixed, FC0012 tuners were not detected anymore, as the reset pin is actually 4, not 5. Thanks to David Basden et al for reporting the bug. Signed-off-by: Steve Markgraf --- src/librtlsdr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librtlsdr.c b/src/librtlsdr.c index b369a5d..4fb2128 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -1565,11 +1565,11 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) } /* initialise GPIOs */ - rtlsdr_set_gpio_output(dev, 5); + rtlsdr_set_gpio_output(dev, 4); /* reset tuner before probing */ - rtlsdr_set_gpio_bit(dev, 5, 1); - rtlsdr_set_gpio_bit(dev, 5, 0); + rtlsdr_set_gpio_bit(dev, 4, 1); + rtlsdr_set_gpio_bit(dev, 4, 0); reg = rtlsdr_i2c_read_reg(dev, FC2580_I2C_ADDR, FC2580_CHECK_ADDR); if ((reg & 0x7f) == FC2580_CHECK_VAL) { From e92b11bfb79437818037515210dc0f0392a93cde Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 18 Apr 2018 23:58:20 +0200 Subject: [PATCH 08/21] cosmetic: Fix "implicit fall-through" gcc 7.3.0 warnings --- src/convenience/convenience.c | 4 ++++ src/librtlsdr.c | 1 + src/rtl_eeprom.c | 1 + 3 files changed, 6 insertions(+) diff --git a/src/convenience/convenience.c b/src/convenience/convenience.c index 517dc4e..00cc2cc 100644 --- a/src/convenience/convenience.c +++ b/src/convenience/convenience.c @@ -49,9 +49,11 @@ double atofs(char *s) case 'g': case 'G': suff *= 1e3; + /* fall-through */ case 'm': case 'M': suff *= 1e3; + /* fall-through */ case 'k': case 'K': suff *= 1e3; @@ -76,9 +78,11 @@ double atoft(char *s) case 'h': case 'H': suff *= 60; + /* fall-through */ case 'm': case 'M': suff *= 60; + /* fall-through */ case 's': case 'S': suff *= atof(s); diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 4fb2128..ae933b0 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -1594,6 +1594,7 @@ found: switch (dev->tuner_type) { case RTLSDR_TUNER_R828D: dev->tun_xtal = R828D_XTAL_FREQ; + /* fall-through */ case RTLSDR_TUNER_R820T: /* disable Zero-IF mode */ rtlsdr_demod_write_reg(dev, 1, 0xb1, 0x1a, 1); diff --git a/src/rtl_eeprom.c b/src/rtl_eeprom.c index 5259820..f562d73 100644 --- a/src/rtl_eeprom.c +++ b/src/rtl_eeprom.c @@ -303,6 +303,7 @@ int main(int argc, char **argv) case 'w': flash_file = 1; change = 1; + /* fall-through */ case 'r': filename = optarg; break; From 5a9864c56da1587a198645427e5f14669b04c991 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 18 Apr 2018 23:58:45 +0200 Subject: [PATCH 09/21] fix "-Wshift-negative-value" compiler warning on ggc-7.3.0 --- src/rtl_fm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rtl_fm.c b/src/rtl_fm.c index d2d011a..b163979 100644 --- a/src/rtl_fm.c +++ b/src/rtl_fm.c @@ -503,7 +503,7 @@ int polar_disc_lut(int ar, int aj, int br, int bj) if (x_abs >= atan_lut_size) { /* we can use linear range, but it is not necessary */ - return (cj > 0) ? 1<<13 : -1<<13; + return (cj > 0) ? 1<<13 : -(1<<13); } if (x > 0) { From f7f3e3f6d7992d2ec33b831da704e7cf2748269c Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 18 Apr 2018 23:51:28 +0200 Subject: [PATCH 10/21] configure.ac: Add --enable-sanitize and --enable-werror this is "osmocom standard" these days, and is used by our CI scripts --- configure.ac | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/configure.ac b/configure.ac index b60ca81..5b94828 100644 --- a/configure.ac +++ b/configure.ac @@ -49,6 +49,33 @@ AC_CHECK_LIB(m, atan2, [LIBS="$LIBS -lm"]) dnl librealtime (for rtl_test) AC_CHECK_LIB(rt, clock_gettime, [LIBS="$LIBS -lrt"]) +AC_ARG_ENABLE(sanitize, + [AS_HELP_STRING([--enable-sanitize], [Compile with address sanitizer enabled], )], + [sanitize=$enableval], [sanitize="no"]) +if test x"$sanitize" = x"yes" +then + CFLAGS="$CFLAGS -fsanitize=address -fsanitize=undefined" + CPPFLAGS="$CPPFLAGS -fsanitize=address -fsanitize=undefined" +fi + +AC_ARG_ENABLE(werror, + [AS_HELP_STRING( + [--enable-werror], + [Turn all compiler warnings into errors, with exceptions: + a) deprecation (allow upstream to mark deprecation without breaking builds); + b) "#warning" pragmas (allow to remind ourselves of errors without breaking builds) + ] + )], + [werror=$enableval], [werror="no"]) +if test x"$werror" = x"yes" +then + WERROR_FLAGS="-Werror" + WERROR_FLAGS+=" -Wno-error=deprecated -Wno-error=deprecated-declarations" + WERROR_FLAGS+=" -Wno-error=cpp" # "#warning" + CFLAGS="$CFLAGS $WERROR_FLAGS" + CPPFLAGS="$CPPFLAGS $WERROR_FLAGS" +fi + # The following test is taken from WebKit's webkit.m4 saved_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -fvisibility=hidden " From 2a36e5dd65bcd53bc26dafd5e2e246c612b2542e Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 18 Apr 2018 23:53:26 +0200 Subject: [PATCH 11/21] add contrib/jenkins.sh for build testing --- contrib/jenkins.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 contrib/jenkins.sh diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh new file mode 100755 index 0000000..cb566f1 --- /dev/null +++ b/contrib/jenkins.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# jenkins build helper script for openbsc. This is how we build on jenkins.osmocom.org + +if ! [ -x "$(command -v osmo-build-dep.sh)" ]; then + echo "Error: We need to have scripts/osmo-deps.sh from http://git.osmocom.org/osmo-ci/ in PATH !" + exit 2 +fi + + +set -ex + +base="$PWD" +deps="$base/deps" +inst="$deps/install" +export deps inst + +osmo-clean-workspace.sh + +mkdir "$deps" || true + +set +x +echo +echo +echo +echo " =============================== rtl-sdr ===============================" +echo +set -x + +cd "$base" +autoreconf --install --force +./configure --enable-sanitize --enable-werror +$MAKE $PARALLEL_MAKE +LD_LIBRARY_PATH="$inst/lib" $MAKE check \ + || cat-testlogs.sh +LD_LIBRARY_PATH="$inst/lib" \ + DISTCHECK_CONFIGURE_FLAGS="--enable-werror" \ + $MAKE distcheck \ + || cat-testlogs.sh + +osmo-clean-workspace.sh From 566a1b942f2aa38e044f9199f5294f3f91ff74ff Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 19 Apr 2018 00:09:15 +0200 Subject: [PATCH 12/21] Makefile.am: Fix "permission denied" during "make distcheck" This fixes the following error during "make distcheck": echo 0.5.3.24-2a36 > ../../.version-t && mv ../../.version-t ../../.version /bin/sh: ../../.version-t: Permission denied --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 2ffa532..c49e92a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,7 @@ install-udev-rules: uninstall-udev-rules: rm -rf /etc/udev/rules.d/rtl-sdr.rules -EXTRA_DIST = git-version-gen +EXTRA_DIST = git-version-gen .version if HAVE_DOXYGEN From c403ef0bc1e3ac586495ad0338c56f47e2026b20 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Thu, 26 Apr 2018 23:51:15 +0200 Subject: [PATCH 13/21] rtl_test: fix build on Mac OS Thanks to mot for reporting. closes #3130 Signed-off-by: Steve Markgraf --- src/rtl_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rtl_test.c b/src/rtl_test.c index 42d2c94..9b44097 100644 --- a/src/rtl_test.c +++ b/src/rtl_test.c @@ -162,8 +162,8 @@ static int ppm_gettime(struct time_generic *tg) struct timeval tv; rv = gettimeofday(&tv, NULL); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000; + tg->tv_sec = tv.tv_sec; + tg->tv_nsec = tv.tv_usec * 1000; #endif return rv; } From 9ca8780df71d3fc13f63454ed685434d582006ba Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Sun, 29 Apr 2018 00:30:45 +0200 Subject: [PATCH 14/21] change version to 0.5.4 Signed-off-by: Steve Markgraf --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6c6928..c9fbda6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ endif() # Set the version information here set(VERSION_INFO_MAJOR_VERSION 0) # increment major on api compatibility changes set(VERSION_INFO_MINOR_VERSION 5) # increment minor on feature-level changes -set(VERSION_INFO_PATCH_VERSION git) # increment patch for bug fixes and docs +set(VERSION_INFO_PATCH_VERSION 4) # increment patch for bug fixes and docs include(Version) # setup version info ######################################################################## From d93819d29d8971187df7b8c770af462d769810de Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Tue, 1 May 2018 12:46:31 +0200 Subject: [PATCH 15/21] change version to 0.6git Signed-off-by: Steve Markgraf --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9fbda6..d6fb801 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,8 +39,8 @@ endif() # Set the version information here set(VERSION_INFO_MAJOR_VERSION 0) # increment major on api compatibility changes -set(VERSION_INFO_MINOR_VERSION 5) # increment minor on feature-level changes -set(VERSION_INFO_PATCH_VERSION 4) # increment patch for bug fixes and docs +set(VERSION_INFO_MINOR_VERSION 6) # increment minor on feature-level changes +set(VERSION_INFO_PATCH_VERSION git) # increment patch for bug fixes and docs include(Version) # setup version info ######################################################################## From 326b0e3accc21b47e7b4bc118ed4c4b55b914127 Mon Sep 17 00:00:00 2001 From: Martin Hauke Date: Tue, 1 May 2018 14:04:41 +0200 Subject: [PATCH 16/21] Fix build with MinGW Signed-off-by: Steve Markgraf --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6fb801..abc8f9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,9 @@ endif() ######################################################################## find_package(PkgConfig) find_package(LibUSB) -set(THREADS_USE_PTHREADS_WIN32 true) +if(WIN32 AND NOT MINGW) + set(THREADS_USE_PTHREADS_WIN32 true) +endif() find_package(Threads) if(NOT LIBUSB_FOUND) From a854ae8b48d42e8dad514c75d3a4c6cfb62707da Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Tue, 1 May 2018 14:23:37 +0200 Subject: [PATCH 17/21] lib: use USB zero-copy transfers if possible Decreases CPU load especially for embedded machines. Requires Linux >= 4.6 and libusb >= 1.0.21. If this is not the case or the allocation fails, we will fall back to buffers allocated in userspace. Signed-off-by: Steve Markgraf --- src/librtlsdr.c | 68 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/src/librtlsdr.c b/src/librtlsdr.c index ae933b0..433ed5b 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -103,6 +103,7 @@ struct rtlsdr_dev { void *cb_ctx; enum rtlsdr_async_status async_status; int async_cancel; + int use_zerocopy; /* rtl demod context */ uint32_t rate; /* Hz */ uint32_t rtl_xtal; /* Hz */ @@ -1741,12 +1742,49 @@ static int _rtlsdr_alloc_async_buffers(rtlsdr_dev_t *dev) dev->xfer[i] = libusb_alloc_transfer(0); } - if (!dev->xfer_buf) { - dev->xfer_buf = malloc(dev->xfer_buf_num * - sizeof(unsigned char *)); + if (dev->xfer_buf) + return -2; - for(i = 0; i < dev->xfer_buf_num; ++i) + 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 + fprintf(stderr, "Allocating %d zero-copy buffers\n", dev->xfer_buf_num); + + dev->use_zerocopy = 1; + for (i = 0; i < dev->xfer_buf_num; ++i) { + dev->xfer_buf[i] = libusb_dev_mem_alloc(dev->devh, dev->xfer_buf_len); + + if (!dev->xfer_buf[i]) { + fprintf(stderr, "Failed to allocate zero-copy " + "buffer for transfer %d\nFalling " + "back to buffers in userspace\n", i); + + dev->use_zerocopy = 0; + break; + } + } + + /* zero-copy buffer allocation failed (partially or completely) + * we need to free the buffers again if already allocated */ + if (!dev->use_zerocopy) { + for (i = 0; i < dev->xfer_buf_num; ++i) { + if (dev->xfer_buf[i]) + libusb_dev_mem_free(dev->devh, + dev->xfer_buf[i], + dev->xfer_buf_len); + } + } +#endif + + /* no zero-copy available, allocate buffers in userspace */ + if (!dev->use_zerocopy) { + for (i = 0; i < dev->xfer_buf_num; ++i) { dev->xfer_buf[i] = malloc(dev->xfer_buf_len); + + if (!dev->xfer_buf[i]) + return -ENOMEM; + } } return 0; @@ -1771,9 +1809,18 @@ static int _rtlsdr_free_async_buffers(rtlsdr_dev_t *dev) } if (dev->xfer_buf) { - for(i = 0; i < dev->xfer_buf_num; ++i) { - if (dev->xfer_buf[i]) - free(dev->xfer_buf[i]); + for (i = 0; i < dev->xfer_buf_num; ++i) { + if (dev->xfer_buf[i]) { + if (dev->use_zerocopy) { +#if defined (__linux__) && LIBUSB_API_VERSION >= 0x01000105 + libusb_dev_mem_free(dev->devh, + dev->xfer_buf[i], + dev->xfer_buf_len); +#endif + } else { + free(dev->xfer_buf[i]); + } + } } free(dev->xfer_buf); @@ -1828,7 +1875,12 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx, r = libusb_submit_transfer(dev->xfer[i]); if (r < 0) { - fprintf(stderr, "Failed to submit transfer %i!\n", i); + fprintf(stderr, "Failed to submit transfer %i\n" + "Please increase your allowed " + "usbfs buffer size with the " + "following command:\n" + "echo 0 > /sys/module/usbcore" + "/parameters/usbfs_memory_mb\n", i); dev->async_status = RTLSDR_CANCELING; break; } From ce9595ef537f9f69a88425f97c9e4179ac9db769 Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Sun, 13 May 2018 15:19:31 -0500 Subject: [PATCH 18/21] rtl_adsb: fix hanging upon a signal in Fedora 27 This code stayed unchanged for many years, but for some reason rtl_adsb started hanging upon exit: *b66116a5164b69281eacc42ae950; ^CSignal caught, exiting! <------ hangs here forever Examining it with gdb reveals that the demod thread waits peacefully on the condition variable, which we're trying to destroy. Either the signals killed all threads before, or condition variables were possible to destroy while other threads still waited on them. The easiest fix appears to be just cancel the demod thread and wait for it to exit before proceeding for the door. Signed-off-by: Steve Markgraf --- src/rtl_adsb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rtl_adsb.c b/src/rtl_adsb.c index 07fdd2a..9087de4 100644 --- a/src/rtl_adsb.c +++ b/src/rtl_adsb.c @@ -492,6 +492,8 @@ int main(int argc, char **argv) else { fprintf(stderr, "\nLibrary error %d, exiting...\n", r);} rtlsdr_cancel_async(dev); + pthread_cancel(demod_thread); + pthread_join(demod_thread, NULL); pthread_cond_destroy(&ready); pthread_mutex_destroy(&ready_m); From 5c3073f4179a270eba2f88bca90446e390aa6da5 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Fri, 25 May 2018 00:16:38 +0200 Subject: [PATCH 19/21] tuner_r82xx: turn off loop-through, remove dead code As pointed out by Carl Laufer on the mailing list, turning the loop-through output off reduces the current consumption by 10-20mA which in turn reduces the heat a bit. So far there seem to be no devices that have anything connected to the loop-through output. Signed-off-by: Steve Markgraf --- src/tuner_r82xx.c | 86 +++++++---------------------------------------- 1 file changed, 13 insertions(+), 73 deletions(-) diff --git a/src/tuner_r82xx.c b/src/tuner_r82xx.c index f620238..fe52bd9 100644 --- a/src/tuner_r82xx.c +++ b/src/tuner_r82xx.c @@ -770,78 +770,18 @@ static int r82xx_set_tv_standard(struct r82xx_priv *priv, uint8_t lt_att, flt_ext_widest, polyfil_cur; int need_calibration; - if (delsys == SYS_ISDBT) { - if_khz = 4063; - filt_cal_lo = 59000; - filt_gain = 0x10; /* +3db, 6mhz on */ - img_r = 0x00; /* image negative */ - filt_q = 0x10; /* r10[4]:low q(1'b1) */ - hp_cor = 0x6a; /* 1.7m disable, +2cap, 1.25mhz */ - ext_enable = 0x40; /* r30[6], ext enable; r30[5]:0 ext at lna max */ - loop_through = 0x00; /* r5[7], lt on */ - lt_att = 0x00; /* r31[7], lt att enable */ - flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */ - polyfil_cur = 0x60; /* r25[6:5]:min */ - } else { - if (bw <= 6) { - if_khz = 3570; - filt_cal_lo = 56000; /* 52000->56000 */ - filt_gain = 0x10; /* +3db, 6mhz on */ - img_r = 0x00; /* image negative */ - filt_q = 0x10; /* r10[4]:low q(1'b1) */ - hp_cor = 0x6b; /* 1.7m disable, +2cap, 1.0mhz */ - ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ - loop_through = 0x00; /* r5[7], lt on */ - lt_att = 0x00; /* r31[7], lt att enable */ - flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */ - polyfil_cur = 0x60; /* r25[6:5]:min */ - } else if (bw == 7) { -#if 0 - /* - * There are two 7 MHz tables defined on the original - * driver, but just the second one seems to be visible - * by rtl2832. Keep this one here commented, as it - * might be needed in the future - */ - - if_khz = 4070; - filt_cal_lo = 60000; - filt_gain = 0x10; /* +3db, 6mhz on */ - img_r = 0x00; /* image negative */ - filt_q = 0x10; /* r10[4]:low q(1'b1) */ - hp_cor = 0x2b; /* 1.7m disable, +1cap, 1.0mhz */ - ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ - loop_through = 0x00; /* r5[7], lt on */ - lt_att = 0x00; /* r31[7], lt att enable */ - flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */ - polyfil_cur = 0x60; /* r25[6:5]:min */ -#endif - /* 7 MHz, second table */ - if_khz = 4570; - filt_cal_lo = 63000; - filt_gain = 0x10; /* +3db, 6mhz on */ - img_r = 0x00; /* image negative */ - filt_q = 0x10; /* r10[4]:low q(1'b1) */ - hp_cor = 0x2a; /* 1.7m disable, +1cap, 1.25mhz */ - ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ - loop_through = 0x00; /* r5[7], lt on */ - lt_att = 0x00; /* r31[7], lt att enable */ - flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */ - polyfil_cur = 0x60; /* r25[6:5]:min */ - } else { - if_khz = 4570; - filt_cal_lo = 68500; - filt_gain = 0x10; /* +3db, 6mhz on */ - img_r = 0x00; /* image negative */ - filt_q = 0x10; /* r10[4]:low q(1'b1) */ - hp_cor = 0x0b; /* 1.7m disable, +0cap, 1.0mhz */ - ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ - loop_through = 0x00; /* r5[7], lt on */ - lt_att = 0x00; /* r31[7], lt att enable */ - flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */ - polyfil_cur = 0x60; /* r25[6:5]:min */ - } - } + /* BW < 6 MHz */ + if_khz = 3570; + filt_cal_lo = 56000; /* 52000->56000 */ + filt_gain = 0x10; /* +3db, 6mhz on */ + img_r = 0x00; /* image negative */ + filt_q = 0x10; /* r10[4]:low q(1'b1) */ + hp_cor = 0x6b; /* 1.7m disable, +2cap, 1.0mhz */ + ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */ + loop_through = 0x01; /* r5[7], lt off */ + lt_att = 0x00; /* r31[7], lt att enable */ + flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */ + polyfil_cur = 0x60; /* r25[6:5]:min */ /* Initialize the shadow registers */ memcpy(priv->regs, r82xx_init_array, sizeof(r82xx_init_array)); @@ -1196,7 +1136,7 @@ int r82xx_standby(struct r82xx_priv *priv) rc = r82xx_write_reg(priv, 0x06, 0xb1); if (rc < 0) return rc; - rc = r82xx_write_reg(priv, 0x05, 0x03); + rc = r82xx_write_reg(priv, 0x05, 0xa0); if (rc < 0) return rc; rc = r82xx_write_reg(priv, 0x07, 0x3a); From 8e9d4e6f2a41bc0065b79270b6e45fbbfb9cc814 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 3 Jun 2018 13:20:00 +0200 Subject: [PATCH 20/21] Fix "make uninstall" for documentation During "make uninstall", the documentatin was not deleted properly, if DESTDIR was used. The existing commands expanded to: make[3]: Entering directory '/home/osmocom-build/jenkins/workspace/master-rtl-sdr/a1/default/a2/default/a3/default/label/osmocom-master-debian9/librtlsdr-0.5.4.5-5c30/_build/sub' cd /tmp/am-dc-24621/ && rm -rf /home/osmocom-build/jenkins/workspace/master-rtl-sdr/a1/default/a2/default/a3/default/label/osmocom-master-debian9/librtlsdr-0.5.4.5-5c30/_inst/share/doc/librtlsdr/librtlsdr-0.5.4.5-5c30/html This fixes the "make distcheck" step of rtl-sdr, and hence should also fix the long-standing jenkins build verification for rtl-sdr at https://jenkins.osmocom.org/jenkins/job/master-rtl-sdr/ Signed-off-by: Harald Welte --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index c49e92a..65b2f21 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,7 +40,7 @@ install-data-hook: cd $(DESTDIR)$(doc_htmldir) && tar xf html.tar --strip-components 1 && rm -f html.tar uninstall-hook: - cd $(DESTDIR) && rm -rf $(doc_htmldir) + rm -rf $(DESTDIR)/$(doc_htmldir) DX_CLEAN = doc/{html,latex}/* doc/html.tar From 9573e68d1044ff56a7801374ed934f510e65c107 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 3 Jun 2018 14:31:18 +0200 Subject: [PATCH 21/21] README: Update homepage/wiki URL from old trac to redmine Signed-off-by: Harald Welte --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 7f04203..9098683 100644 --- a/README +++ b/README @@ -3,4 +3,4 @@ turns your Realtek RTL2832 based DVB dongle into a SDR receiver ====================================================================== For more information see: -http://sdr.osmocom.org/trac/wiki/rtl-sdr +https://osmocom.org/projects/rtl-sdr/wiki