Kacper Michajłow 2014-11-02 05:58:38 +00:00
commit d80f1efa9b
12 zmienionych plików z 146 dodań i 114 usunięć

7
.editorconfig 100755
Wyświetl plik

@ -0,0 +1,7 @@
root = true
[src/**.{c,h}]
indent_style = tab
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

Wyświetl plik

@ -22,6 +22,7 @@
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.6)
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
project(rtlsdr C)
#select the release build type by default to get optimization flags

Wyświetl plik

@ -28,11 +28,9 @@ add_library(rtlsdr_shared SHARED
tuner_fc2580.c
tuner_r82xx.c
)
target_link_libraries(rtlsdr_shared
${LIBUSB_LIBRARIES}
)
set_target_properties(rtlsdr_shared PROPERTIES DEFINE_SYMBOL "rtlsdr_EXPORTS")
set_target_properties(rtlsdr_shared PROPERTIES OUTPUT_NAME rtlsdr)
set_target_properties(rtlsdr_shared PROPERTIES SOVERSION ${MAJOR_VERSION})
@ -46,25 +44,17 @@ add_library(rtlsdr_static STATIC
tuner_fc2580.c
tuner_r82xx.c
)
target_link_libraries(rtlsdr_static
${LIBUSB_LIBRARIES}
)
set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
add_library(convenience_static STATIC
convenience/convenience.c
)
if(WIN32)
add_library(libgetopt_static STATIC
getopt/getopt.c
)
target_link_libraries(convenience_static
rtlsdr_shared
)
endif()
target_link_libraries(rtlsdr_static
${LIBUSB_LIBRARIES}
)
set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
if(NOT WIN32)
# Force same library filename for static and shared variants of the library
@ -83,31 +73,31 @@ 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)
target_link_libraries(rtl_sdr rtlsdr_shared convenience_static
target_link_libraries(rtl_sdr convenience_static rtlsdr_shared
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(rtl_tcp rtlsdr_shared convenience_static
target_link_libraries(rtl_tcp convenience_static rtlsdr_shared
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(rtl_test rtlsdr_shared convenience_static
target_link_libraries(rtl_test convenience_static rtlsdr_shared
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(rtl_fm rtlsdr_shared convenience_static
target_link_libraries(rtl_fm convenience_static rtlsdr_shared
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(rtl_eeprom rtlsdr_shared convenience_static
target_link_libraries(rtl_eeprom convenience_static rtlsdr_shared
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(rtl_adsb rtlsdr_shared convenience_static
target_link_libraries(rtl_adsb convenience_static rtlsdr_shared
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(rtl_power rtlsdr_shared convenience_static
target_link_libraries(rtl_power convenience_static rtlsdr_shared
${LIBUSB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
@ -124,6 +114,9 @@ endif()
endif()
if(WIN32)
add_library(libgetopt_static STATIC
getopt/getopt.c
)
target_link_libraries(rtl_sdr libgetopt_static)
target_link_libraries(rtl_tcp ws2_32 libgetopt_static)
target_link_libraries(rtl_test libgetopt_static)
@ -131,13 +124,6 @@ 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)
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" )
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" )
endif()
########################################################################
# Install built library files & utilities

Wyświetl plik

@ -275,7 +275,7 @@ int verbose_device_search(char *s)
{
int i, device_count, device, offset;
char *s2;
char vendor[256], product[256], serial[256];
char vendor[256] = {0}, product[256] = {0}, serial[256] = {0};
device_count = rtlsdr_get_device_count();
if (!device_count) {
fprintf(stderr, "No supported devices found.\n");
@ -283,8 +283,11 @@ int verbose_device_search(char *s)
}
fprintf(stderr, "Found %d device(s):\n", device_count);
for (i = 0; i < device_count; i++) {
rtlsdr_get_device_usb_strings(i, vendor, product, serial);
fprintf(stderr, " %d: %s, %s, SN: %s\n", i, vendor, product, serial);
if (rtlsdr_get_device_usb_strings(i, vendor, product, serial) == 0) {
fprintf(stderr, " %d: %s, %s, SN: %s\n", i, vendor, product, serial);
} else {
fprintf(stderr, " %d: %s\n", i, "Failed to query data");
}
}
fprintf(stderr, "\n");
/* does string look like raw id number */

Wyświetl plik

@ -705,7 +705,7 @@ int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq)
if (rtlsdr_get_xtal_freq(dev, &rtl_xtal, NULL))
return -2;
if_freq = ((freq * TWO_POW(22)) / rtl_xtal) * (-1);
if_freq = (int32_t)(((freq * TWO_POW(22)) / rtl_xtal) * -1);
tmp = (if_freq >> 16) & 0x3f;
r = rtlsdr_demod_write_reg(dev, 1, 0x19, tmp, 1);
@ -728,7 +728,7 @@ int rtlsdr_set_sample_freq_correction(rtlsdr_dev_t *dev, int ppm)
{
int r = 0;
uint8_t tmp;
int16_t offs = ppm * (-1) * TWO_POW(24) / 1000000;
int16_t offs = (int16_t)(ppm * -1 * TWO_POW(24) / 1000000);
rtlsdr_set_i2c_repeater(dev, 0);
tmp = offs & 0xff;
@ -1103,7 +1103,7 @@ int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
return -EINVAL;
}
rsamp_ratio = (dev->rtl_xtal * TWO_POW(22)) / samp_rate;
rsamp_ratio = (uint32_t)((dev->rtl_xtal * TWO_POW(22)) / samp_rate);
rsamp_ratio &= 0x0ffffffc;
real_rsamp_ratio = rsamp_ratio | ((rsamp_ratio & 0x08000000) << 1);
@ -1853,7 +1853,7 @@ 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 %u!\n", i);
dev->async_status = RTLSDR_CANCELING;
break;
}

Wyświetl plik

@ -43,8 +43,7 @@
#include "rtl-sdr.h"
#include "convenience/convenience.h"
#ifdef _WIN32
#define sleep Sleep
#if defined(_MSC_VER) && _MSC_VER < 1800
#define round(x) (x > 0.0 ? floor(x + 0.5): ceil(x - 0.5))
#endif

Wyświetl plik

@ -63,7 +63,7 @@
#include <io.h>
#include "getopt/getopt.h"
#define usleep(x) Sleep(x/1000)
#ifdef _MSC_VER
#if defined(_MSC_VER) && _MSC_VER < 1800
#define round(x) (x > 0.0 ? floor(x + 0.5): ceil(x - 0.5))
#endif
#define _USE_MATH_DEFINES
@ -252,9 +252,7 @@ void usage(void)
"\t no-mod: enable no-mod direct sampling\n"
"\t offset: enable offset tuning\n"
"\t wav: generate WAV header\n"
#ifndef _WIN32
"\t pad: pad output gaps with zeros\n"
#endif
"\t lrmix: one channel goes to left audio, one to right (broken)\n"
"\t remember to enable stereo (-c 2) in sox\n"
"\tfilename ('-' means stdout)\n"
@ -324,7 +322,7 @@ int cic_9_tables[][10] = {
{9, -199, -362, 5303, -25505, 77489, -25505, 5303, -362, -199},
};
#ifdef _MSC_VER
#if defined(_MSC_VER) && _MSC_VER < 1800
double log2(double n)
{
return log(n) / log(2.0);
@ -757,7 +755,7 @@ void dc_block_filter(struct demod_state *fm)
for (i=0; i < fm->lp_len; i++) {
sum += lp[i];
}
avg = sum / fm->lp_len;
avg = (int)(sum / fm->lp_len);
avg = (avg + fm->dc_avg * 9) / 10;
for (i=0; i < fm->lp_len; i++) {
lp[i] -= avg;
@ -947,13 +945,15 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
{
int i;
struct dongle_state *s = ctx;
struct demod_state *d = s->targets[0];
struct demod_state *d2 = s->targets[1];
struct demod_state *d;
struct demod_state *d2;
if (do_exit) {
return;}
if (!ctx) {
if (!s) {
return;}
d = s->targets[0];
d2 = s->targets[1];
if (s->mute) {
for (i=0; i<s->mute; i++) {
buf[i] = 127;}
@ -1040,11 +1040,18 @@ static void *output_thread_fn(void *arg)
struct output_state *s = arg;
struct buffer_bucket *b0 = &s->results[0];
struct buffer_bucket *b1 = &s->results[1];
int64_t i, duration, samples = 0LL, samples_now;
#ifdef _WIN32
LARGE_INTEGER perfFrequency;
LARGE_INTEGER start_time;
LARGE_INTEGER now_time;
QueryPerformanceFrequency(&perfFrequency);
QueryPerformanceCounter(&start_time);
#else
struct timespec start_time;
struct timespec now_time;
int64_t i, duration, samples, samples_now;
samples = 0L;
#ifndef _WIN32
get_nanotime(&start_time);
#endif
while (!do_exit) {
@ -1071,10 +1078,9 @@ static void *output_thread_fn(void *arg)
pthread_rwlock_unlock(&b0->rw);
continue;
}
#ifndef _WIN32
/* padding requires output at constant rate */
/* pthread_cond_timedwait is terrible, roll our own trycond */
// figure out how to do this with windows HPET
usleep(2000);
pthread_mutex_lock(&b0->trycond_m);
r = b0->trycond;
@ -1088,11 +1094,17 @@ static void *output_thread_fn(void *arg)
pthread_rwlock_unlock(&b0->rw);
continue;
}
#ifdef _WIN32
QueryPerformanceCounter(&now_time);
duration = now_time.QuadPart - start_time.QuadPart;
samples_now = (duration * s->rate) / perfFrequency.QuadPart;
#else
get_nanotime(&now_time);
duration = now_time.tv_sec - start_time.tv_sec;
duration *= 1000000000L;
duration += (now_time.tv_nsec - start_time.tv_nsec);
samples_now = (duration * (int64_t)s->rate) / 1000000000L;
samples_now = (duration * s->rate) / 1000000000UL;
#endif
if (samples_now < samples) {
continue;}
for (i=samples; i<samples_now; i++) {
@ -1100,7 +1112,6 @@ static void *output_thread_fn(void *arg)
fputc(0, s->file);
}
samples = samples_now;
#endif
}
return 0;
}
@ -1392,7 +1403,6 @@ void sanity_checks(void)
int agc_init(struct demod_state *s)
{
int i;
struct agc_state *agc;
agc = malloc(sizeof(struct agc_state));

Wyświetl plik

@ -53,7 +53,7 @@
#include <io.h>
#include "getopt/getopt.h"
#define usleep(x) Sleep(x/1000)
#ifdef _MSC_VER
#if defined(_MSC_VER) && _MSC_VER < 1800
#define round(x) (x > 0.0 ? floor(x + 0.5): ceil(x - 0.5))
#endif
#define _USE_MATH_DEFINES
@ -260,7 +260,7 @@ int cic_9_tables[][10] = {
{9, -199, -362, 5303, -25505, 77489, -25505, 5303, -362, -199},
};
#ifdef _MSC_VER
#if defined(_MSC_VER) && _MSC_VER < 1800
double log2(double n)
{
return log(n) / log(2.0);
@ -830,7 +830,7 @@ int64_t real_conj(int16_t real, int16_t imag)
void scanner(void)
{
int i, j, j2, f, g, n_read, offset, bin_e, bin_len, buf_len, ds, ds_p;
int i, j, j2, n_read, offset, bin_e, bin_len, buf_len, ds, ds_p;
int32_t w;
struct tuning_state *ts;
int16_t *fft_buf;
@ -912,12 +912,11 @@ void scanner(void)
void csv_dbm(struct tuning_state *ts)
{
int i, len, ds;
int i, len;
int64_t tmp;
double dbm;
char *sep = ", ";
len = 1 << ts->bin_e;
ds = ts->downsample;
/* fix FFT stuff quirks */
if (ts->bin_e > 0) {
/* nuke DC component (not effective for all windows) */
@ -972,7 +971,7 @@ int main(int argc, char **argv)
struct sigaction sigact;
#endif
char *filename = NULL;
int i, r, opt, wb_mode = 0;
int i, r, opt;
int f_set = 0;
int dev_index = 0;
int dev_given = 0;

Wyświetl plik

@ -110,11 +110,7 @@ int gettimeofday(struct timeval *tv, void* ignored)
tmp <<= 32;
tmp |= ft.dwLowDateTime;
tmp /= 10;
#ifdef _MSC_VER
tmp -= 11644473600000000Ui64;
#else
tmp -= 11644473600000000ULL;
#endif
tv->tv_sec = (long)(tmp / 1000000UL);
tv->tv_usec = (long)(tmp % 1000000UL);
}
@ -303,23 +299,23 @@ static void *command_worker(void *arg)
}
switch(cmd.cmd) {
case 0x01:
printf("set freq %d\n", ntohl(cmd.param));
printf("set freq %u\n", ntohl(cmd.param));
rtlsdr_set_center_freq(dev,ntohl(cmd.param));
break;
case 0x02:
printf("set sample rate %d\n", ntohl(cmd.param));
printf("set sample rate %u\n", ntohl(cmd.param));
rtlsdr_set_sample_rate(dev, ntohl(cmd.param));
break;
case 0x03:
printf("set gain mode %d\n", ntohl(cmd.param));
printf("set gain mode %u\n", ntohl(cmd.param));
rtlsdr_set_tuner_gain_mode(dev, ntohl(cmd.param));
break;
case 0x04:
printf("set gain %d\n", ntohl(cmd.param));
printf("set gain %u\n", ntohl(cmd.param));
rtlsdr_set_tuner_gain(dev, ntohl(cmd.param));
break;
case 0x05:
printf("set freq correction %d\n", ntohl(cmd.param));
printf("set freq correction %u\n", ntohl(cmd.param));
rtlsdr_set_freq_correction(dev, ntohl(cmd.param));
break;
case 0x06:
@ -328,31 +324,31 @@ static void *command_worker(void *arg)
rtlsdr_set_tuner_if_gain(dev, tmp >> 16, (short)(tmp & 0xffff));
break;
case 0x07:
printf("set test mode %d\n", ntohl(cmd.param));
printf("set test mode %u\n", ntohl(cmd.param));
rtlsdr_set_testmode(dev, ntohl(cmd.param));
break;
case 0x08:
printf("set agc mode %d\n", ntohl(cmd.param));
printf("set agc mode %u\n", ntohl(cmd.param));
rtlsdr_set_agc_mode(dev, ntohl(cmd.param));
break;
case 0x09:
printf("set direct sampling %d\n", ntohl(cmd.param));
printf("set direct sampling %u\n", ntohl(cmd.param));
rtlsdr_set_direct_sampling(dev, ntohl(cmd.param));
break;
case 0x0a:
printf("set offset tuning %d\n", ntohl(cmd.param));
printf("set offset tuning %u\n", ntohl(cmd.param));
rtlsdr_set_offset_tuning(dev, ntohl(cmd.param));
break;
case 0x0b:
printf("set rtl xtal %d\n", ntohl(cmd.param));
printf("set rtl xtal %u\n", ntohl(cmd.param));
rtlsdr_set_xtal_freq(dev, ntohl(cmd.param), 0);
break;
case 0x0c:
printf("set tuner xtal %d\n", ntohl(cmd.param));
printf("set tuner xtal %u\n", ntohl(cmd.param));
rtlsdr_set_xtal_freq(dev, 0, ntohl(cmd.param));
break;
case 0x0d:
printf("set tuner gain by index %d\n", ntohl(cmd.param));
printf("set tuner gain by index %u\n", ntohl(cmd.param));
set_gain_by_index(dev, ntohl(cmd.param));
break;
default:

Wyświetl plik

@ -79,9 +79,7 @@ void usage(void)
"\t[-s samplerate (default: 2048000 Hz)]\n"
"\t[-d device_index (default: 0)]\n"
"\t[-t enable tuner range benchmark]\n"
#ifndef _WIN32
"\t[-p[seconds] enable PPM error measurement (default: 10 seconds)]\n"
#endif
"\t[-b output_block_size (default: 16 * 16384)]\n"
"\t[-S force sync output (default: async)]\n");
exit(1);
@ -151,31 +149,48 @@ static int ppm_gettime(struct timespec *ts)
#endif
return rv;
}
#endif
static int ppm_report(uint64_t nsamples, uint64_t interval)
static double get_rate(uint64_t nsamples, int64_t interval, int64_t divider)
{
double real_rate, ppm;
return nsamples / (interval / (double)divider);
real_rate = nsamples * 1e9 / interval;
ppm = 1e6 * (real_rate / (double)samp_rate - 1.);
}
static int ppm_report(uint64_t nsamples, int64_t interval, int64_t divider)
{
double real_rate = get_rate(nsamples, interval, divider);
double ppm = 1e6 * (real_rate / (double)samp_rate - 1.);
return (int)round(ppm);
}
static void ppm_test(uint32_t len)
{
static uint64_t nsamples = 0;
static uint64_t interval = 0;
static uint64_t nsamples_total = 0;
static uint64_t interval_total = 0;
static int64_t interval = 0;
static int64_t interval_total = 0;
#ifdef _WIN32
static LARGE_INTEGER perfFrequency;
static LARGE_INTEGER ppm_now;
static LARGE_INTEGER ppm_recent;
#else
struct timespec ppm_now;
static struct timespec ppm_recent;
#endif
static enum {
PPM_INIT_NO,
PPM_INIT_DUMP,
PPM_INIT_RUN
} ppm_init = PPM_INIT_NO;
#ifdef _WIN32
QueryPerformanceCounter(&ppm_now);
#else
ppm_gettime(&ppm_now);
#endif
if (ppm_init != PPM_INIT_RUN) {
/*
* Kyle Keen wrote:
@ -185,51 +200,69 @@ static void ppm_test(uint32_t len)
* Discarding the first few seconds allows the value to stabilize much faster.
*/
if (ppm_init == PPM_INIT_NO) {
#ifdef _WIN32
QueryPerformanceFrequency(&perfFrequency);
ppm_recent.QuadPart = ppm_now.QuadPart + (PPM_DUMP_TIME * perfFrequency.QuadPart);
#else
ppm_recent.tv_sec = ppm_now.tv_sec + PPM_DUMP_TIME;
#endif
ppm_init = PPM_INIT_DUMP;
return;
}
#ifdef _WIN32
if (ppm_init == PPM_INIT_DUMP && ppm_recent.QuadPart < ppm_now.QuadPart)
#else
if (ppm_init == PPM_INIT_DUMP && ppm_recent.tv_sec < ppm_now.tv_sec)
#endif
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);
nsamples += len / 2UL;
#ifdef _WIN32
interval = ppm_now.QuadPart - ppm_recent.QuadPart;
if (interval < (ppm_duration * perfFrequency.QuadPart))
return;
#else
interval = ppm_now.tv_sec - ppm_recent.tv_sec;
if (interval < ppm_duration)
return;
interval *= 1000000000UL;
interval += (int64_t)(ppm_now.tv_nsec - ppm_recent.tv_nsec);
#endif
nsamples_total += nsamples;
interval_total += interval;
printf("real sample rate: %i current PPM: %i cumulative PPM: %i\n",
(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;
#ifdef _WIN32
(int)get_rate(nsamples, interval, perfFrequency.QuadPart),
ppm_report(nsamples, interval, perfFrequency.QuadPart),
ppm_report(nsamples_total, interval_total, perfFrequency.QuadPart));
#else
(int)get_rate(nsamples, interval, 1000000000UL),
ppm_report(nsamples, interval, 1000000000UL),
ppm_report(nsamples_total, interval_total, 1000000000UL));
#endif
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
}
/* smallest band or band gap that tuner_benchmark() will notice */
static uint32_t max_step(uint32_t freq) {
if (freq < 1e6)
return 1e4;
if (freq > 1e8)
return 1e6;
return freq / 1e2;
if (freq < 1000000U)
return 10000U;
if (freq > 100000000U)
return 1000000U;
return freq / 100U;
}
/* precision with which tuner_benchmark() will measure the edges of bands */
@ -415,7 +448,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");
}

Wyświetl plik

@ -443,7 +443,7 @@ static uint32_t compute_flo(uint32_t f_osc, uint8_t z, uint16_t x, uint8_t r)
if (fvco == 0)
return -EINVAL;
return fvco / r;
return (uint32_t)(fvco / r);
}
static int e4k_band_set(struct e4k_state *e4k, enum e4k_band band)
@ -482,11 +482,11 @@ uint32_t e4k_compute_pll_params(struct e4k_pll_params *oscp, uint32_t fosc, uint
{
uint32_t i;
uint8_t r = 2;
uint8_t z = 0;
uint8_t three_phase_mixing = 0;
uint64_t intended_fvco, remainder;
uint64_t z = 0;
uint32_t x;
int flo;
int three_phase_mixing = 0;
uint32_t flo;
oscp->r_idx = 0;
if (!is_fosc_valid(fosc))
@ -507,13 +507,13 @@ uint32_t e4k_compute_pll_params(struct e4k_pll_params *oscp, uint32_t fosc, uint
intended_fvco = (uint64_t)intended_flo * r;
/* compute integral component of multiplier */
z = intended_fvco / fosc;
z = (uint8_t)(intended_fvco / fosc);
/* compute fractional part. this will not overflow,
* as fosc(max) = 30MHz and z(max) = 255 */
remainder = intended_fvco - (fosc * z);
/* remainder(max) = 30MHz, E4K_PLL_Y = 65536 -> 64bit! */
x = (remainder * E4K_PLL_Y) / fosc;
x = (uint32_t)((remainder * E4K_PLL_Y) / fosc);
/* x(max) as result of this computation is 65536 */
flo = compute_flo(fosc, z, x, r);

Wyświetl plik

@ -542,7 +542,7 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
* vco_div = 65536*(nint + sdm/65536) = int( 0.5 + 65536 * vco_freq / (2 * pll_ref) )
* vco_div = 65536*nint + sdm = int( (pll_ref + 65536 * vco_freq) / (2 * pll_ref) )
*/
vco_div = (pll_ref + 65536 * vco_freq) / (2 * pll_ref);
nint = (uint32_t) (vco_div / 65536);
sdm = (uint32_t) (vco_div % 65536);
@ -826,9 +826,8 @@ static int r82xx_init_tv_standard(struct r82xx_priv *priv,
{
/* everything that was previously done in r82xx_set_tv_standard
* and doesn't need to be changed when filter settings change */
int rc, i;
int rc;
uint32_t if_khz, filt_cal_lo;
uint8_t data[5], val;
uint8_t filt_gain, img_r, ext_enable, loop_through;
uint8_t lt_att, flt_ext_widest, polyfil_cur;
@ -907,7 +906,7 @@ static int r82xx_init_tv_standard(struct r82xx_priv *priv,
}
static int r82xx_set_if_filter(struct r82xx_priv *priv, int hpf, int lpf) {
int rc, i;
int rc;
uint8_t filt_q, hp_cor;
int cal;
filt_q = 0x10; /* r10[4]:low q(1'b1) */
@ -1076,7 +1075,7 @@ int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain)
int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
{
int rc = -1;
int rc;
uint32_t lo_freq = freq + priv->int_freq;
uint8_t air_cable1_in;
@ -1113,7 +1112,7 @@ err:
int r82xx_set_nomod(struct r82xx_priv *priv)
{
int rc = -1;
int rc;
fprintf(stderr, "Using R820T no-mod direct sampling mode\n");
@ -1285,7 +1284,6 @@ int r82xx_init(struct r82xx_priv *priv)
priv->init_done = 1;
priv->reg_cache = 1;
err:
if (rc < 0)
fprintf(stderr, "%s: failed=%d\n", __FUNCTION__, rc);
return rc;