host: test_ctrl: fix rounding, types, and casts
Windows build fixes...
This commit is contained in:
parent
2c7ceb5560
commit
0bc1f8cfcd
4 changed files with 24 additions and 19 deletions
|
|
@ -61,7 +61,7 @@ static failure_count sweep_bandwidths(struct bladerf *dev,
|
|||
bladerf_bandwidth min,
|
||||
bladerf_bandwidth max)
|
||||
{
|
||||
size_t const inc = 250000;
|
||||
bladerf_bandwidth const inc = 250000;
|
||||
|
||||
bladerf_bandwidth b;
|
||||
failure_count failures = 0;
|
||||
|
|
@ -135,8 +135,8 @@ failure_count test_bandwidth(struct bladerf *dev,
|
|||
return status;
|
||||
};
|
||||
|
||||
min = (range->min * range->scale);
|
||||
max = (range->max * range->scale);
|
||||
min = (bladerf_bandwidth)(range->min * range->scale);
|
||||
max = (bladerf_bandwidth)(range->max * range->scale);
|
||||
|
||||
PRINT("%s: %s range: %u to %u\n", __FUNCTION__, direction2str(dir),
|
||||
min, max);
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ static failure_count freq_sweep(struct bladerf *dev,
|
|||
|
||||
PRINT("\n");
|
||||
fflush(stdout);
|
||||
|
||||
return failures;
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +145,7 @@ static failure_count random_tuning(struct bladerf *dev,
|
|||
|
||||
PRINT("\n");
|
||||
fflush(stdout);
|
||||
|
||||
return failures;
|
||||
}
|
||||
|
||||
|
|
@ -175,8 +177,8 @@ failure_count test_frequency(struct bladerf *dev,
|
|||
return status;
|
||||
};
|
||||
|
||||
min = (range->min * range->scale);
|
||||
max = (range->max * range->scale);
|
||||
min = (bladerf_frequency)(range->min * range->scale);
|
||||
max = (bladerf_frequency)(range->max * range->scale);
|
||||
|
||||
PRINT("%s: %s range: %" BLADERF_PRIuFREQ " to %" BLADERF_PRIuFREQ
|
||||
"\n",
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ DECLARE_TEST_CASE(gain);
|
|||
|
||||
#define MAX_STAGES 8
|
||||
|
||||
#define __round_int(x) (x >= 0 ? (int)(x + 0.5) : (int)(x - 0.5))
|
||||
|
||||
struct gain {
|
||||
char const *name;
|
||||
float min;
|
||||
|
|
@ -108,7 +110,7 @@ static failure_count gain_sweep(struct bladerf *dev,
|
|||
for (i = 0; i <= (unsigned)n_stages; i++) {
|
||||
struct bladerf_range const *range;
|
||||
struct gain stage;
|
||||
int gain;
|
||||
float gain;
|
||||
|
||||
if ((unsigned)n_stages == i) {
|
||||
// magic null value
|
||||
|
|
@ -137,13 +139,13 @@ static failure_count gain_sweep(struct bladerf *dev,
|
|||
}
|
||||
}
|
||||
|
||||
stage.min = (range->min * range->scale);
|
||||
stage.max = (range->max * range->scale);
|
||||
stage.inc = range->step;
|
||||
stage.min = (float)(range->min * range->scale);
|
||||
stage.max = (float)(range->max * range->scale);
|
||||
stage.inc = (float)range->step;
|
||||
|
||||
fflush(stdout);
|
||||
for (gain = stage.min; gain <= stage.max; gain += stage.inc) {
|
||||
status = set_and_check(dev, ch, &stage, gain);
|
||||
status = set_and_check(dev, ch, &stage, __round_int(gain));
|
||||
if (status != 0) {
|
||||
failures++;
|
||||
}
|
||||
|
|
@ -151,7 +153,7 @@ static failure_count gain_sweep(struct bladerf *dev,
|
|||
}
|
||||
|
||||
out:
|
||||
free(stages);
|
||||
free((char **)stages);
|
||||
|
||||
return failures;
|
||||
}
|
||||
|
|
@ -185,7 +187,6 @@ static failure_count random_gains(struct bladerf *dev,
|
|||
for (i = 0; i <= (unsigned)n_stages; i++) {
|
||||
struct bladerf_range const *range;
|
||||
struct gain stage;
|
||||
int gain;
|
||||
|
||||
if ((unsigned)n_stages == i) {
|
||||
// magic null value
|
||||
|
|
@ -218,9 +219,11 @@ static failure_count random_gains(struct bladerf *dev,
|
|||
stage.max = (range->max * range->scale);
|
||||
stage.inc = (range->step * range->scale);
|
||||
|
||||
int const n_incs = (stage.max - stage.min) / stage.inc;
|
||||
int const n_incs = __round_int((stage.max - stage.min) / stage.inc);
|
||||
|
||||
for (j = 0; j < iterations; j++) {
|
||||
float gain;
|
||||
|
||||
randval_update(&p->randval_state);
|
||||
gain = stage.min + (p->randval_state % n_incs) * stage.inc;
|
||||
|
||||
|
|
@ -230,7 +233,7 @@ static failure_count random_gains(struct bladerf *dev,
|
|||
gain = stage.min;
|
||||
}
|
||||
|
||||
status = set_and_check(dev, ch, &stage, gain);
|
||||
status = set_and_check(dev, ch, &stage, __round_int(gain));
|
||||
if (status != 0) {
|
||||
failures++;
|
||||
}
|
||||
|
|
@ -238,7 +241,7 @@ static failure_count random_gains(struct bladerf *dev,
|
|||
}
|
||||
|
||||
out:
|
||||
free(stages);
|
||||
free((char **)stages);
|
||||
|
||||
return failures;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ static failure_count sweep_samplerate(struct bladerf *dev,
|
|||
bladerf_sample_rate min,
|
||||
bladerf_sample_rate max)
|
||||
{
|
||||
size_t const inc = 10000;
|
||||
bladerf_sample_rate const inc = 10000;
|
||||
|
||||
bladerf_sample_rate rate;
|
||||
size_t n;
|
||||
|
|
@ -131,7 +131,7 @@ static failure_count random_samplerates(struct bladerf *dev,
|
|||
int status;
|
||||
|
||||
for (i = n = 0; i < interations; i++, n++) {
|
||||
size_t const mod = max - min + 1;
|
||||
bladerf_sample_rate const mod = max - min + 1;
|
||||
|
||||
randval_update(&p->randval_state);
|
||||
|
||||
|
|
@ -246,8 +246,8 @@ failure_count test_samplerate(struct bladerf *dev,
|
|||
return status;
|
||||
};
|
||||
|
||||
min = (range->min * range->scale);
|
||||
max = (range->max * range->scale);
|
||||
min = (bladerf_sample_rate)(range->min * range->scale);
|
||||
max = (bladerf_sample_rate)(range->max * range->scale);
|
||||
|
||||
PRINT("%s: %s range: %u to %u\n", __FUNCTION__, direction2str(dir),
|
||||
min, max);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue