Skip to content

Commit

Permalink
fix verbose_list_gains() in rtl_test and e4000_set_bw() applied_bw
Browse files Browse the repository at this point in the history
Signed-off-by: hayati ayguen <[email protected]>
  • Loading branch information
hayguen committed Nov 12, 2023
1 parent a6a094c commit 7e8bb3e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/tuner_e4k.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int e4k_tune_params(struct e4k_state *e4k, struct e4k_pll_params *p);
uint32_t e4k_compute_pll_params(struct e4k_pll_params *oscp, uint32_t fosc, uint32_t intended_flo);
int e4k_if_filter_bw_get(struct e4k_state *e4k, enum e4k_if_filter filter);
int e4k_if_filter_bw_set(struct e4k_state *e4k, enum e4k_if_filter filter,
uint32_t bandwidth);
uint32_t bandwidth, int apply, uint32_t *applied_bw);
int e4k_if_filter_chan_enable(struct e4k_state *e4k, int on);
int e4k_rf_filter_set(struct e4k_state *e4k);

Expand Down
2 changes: 1 addition & 1 deletion src/convenience/rtl_convenience.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void verbose_list_bandwidths(rtlsdr_dev_t *dev)
int r;
uint32_t in_bw, out_bw, last_bw = 0;
fprintf(stderr, "Supported bandwidth values in kHz: ");
for ( in_bw = 1; in_bw < 3200; ++in_bw )
for ( in_bw = 1; in_bw < 5500; ++in_bw )
{
r = rtlsdr_set_and_get_tuner_bandwidth(dev, in_bw*1000, &out_bw, 0 /* =apply_bw */);
if ( r == 0 && out_bw != 0 && ( out_bw != last_bw || in_bw == 1 ) )
Expand Down
17 changes: 12 additions & 5 deletions src/librtlsdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,20 @@ int e4000_set_freq(void *dev, uint32_t freq) {

int e4000_set_bw(void *dev, int bw, uint32_t *applied_bw, int apply) {
int r = 0;
uint32_t abw, abw_min = (uint32_t)-1;
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
if(!apply)
return 0;

r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_MIX, bw);
r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_RC, bw);
r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_CHAN, bw);
r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_MIX, bw, apply, &abw);
abw_min = (abw < abw_min) ? abw : abw_min;

r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_RC, bw, apply, &abw);
abw_min = (abw < abw_min) ? abw : abw_min;

r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_CHAN, bw, apply, &abw);
abw_min = (abw < abw_min) ? abw : abw_min;

if (applied_bw)
*applied_bw = abw_min;

return r;
}
Expand Down
23 changes: 16 additions & 7 deletions src/tuner_e4k.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,31 +277,40 @@ static const struct reg_field if_filter_fields[] = {
}
};

static int find_if_bw(enum e4k_if_filter filter, uint32_t bw)
static int find_if_bw(enum e4k_if_filter filter, uint32_t bw, uint32_t *applied_bw)
{
int idx;
if (filter >= ARRAY_SIZE(if_filter_bw))
return -EINVAL;

return closest_arr_idx(if_filter_bw[filter],
idx = closest_arr_idx(if_filter_bw[filter],
if_filter_bw_len[filter], bw);
if (applied_bw)
*applied_bw = if_filter_bw[filter][idx];
return idx;
}

/*! \brief Set the filter band-width of any of the IF filters
* \param[in] e4k reference to the tuner chip
* \param[in] filter filter to be configured
* \param[in] bandwidth bandwidth to be configured
* \param[in] apply flag (0/1), if bandwidth should be applied - or just get applied_bw
* \param[out] effectıvely configured bandwidth
* \returns positive actual filter band-width, negative in case of error
*/
int e4k_if_filter_bw_set(struct e4k_state *e4k, enum e4k_if_filter filter,
uint32_t bandwidth)
uint32_t bandwidth, int apply, uint32_t *applied_bw)
{
int bw_idx;
const struct reg_field *field;

if (filter >= ARRAY_SIZE(if_filter_bw))
return -EINVAL;

bw_idx = find_if_bw(filter, bandwidth);
bw_idx = find_if_bw(filter, bandwidth, applied_bw);

if (!apply)
return 0;

field = &if_filter_fields[filter];

Expand Down Expand Up @@ -991,9 +1000,9 @@ int e4k_init(struct e4k_state *e4k)
e4k_if_gain_set(e4k, 6, 9);

/* Set the most narrow filter we can possibly use */
e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_MIX, KHZ(1900));
e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_RC, KHZ(1000));
e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_CHAN, KHZ(2150));
e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_MIX, KHZ(1900), 1, NULL);
e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_RC, KHZ(1000), 1, NULL);
e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_CHAN, KHZ(2150), 1, NULL);
e4k_if_filter_chan_enable(e4k, 1);

/* Disable time variant DC correction and LUT */
Expand Down

0 comments on commit 7e8bb3e

Please sign in to comment.