@ -34,12 +34,12 @@
int scandirty = true ;
setting_t setting ;
uint32 _t frequencies [ POINTS_COUNT ] ;
freq _t frequencies [ POINTS_COUNT ] ;
uint16_t actual_rbw_x10 = 0 ;
uint16_t vbwSteps = 1 ;
uint32 _t minFreq = 0 ;
uint32 _t maxFreq = 520000000 ;
freq _t minFreq = 0 ;
freq _t maxFreq = 520000000 ;
int spur_gate = 100 ;
uint32_t old_CFGR ;
uint32_t orig_CFGR ;
@ -71,7 +71,7 @@ void update_min_max_freq(void)
case M_LOW :
minFreq = 0 ;
if ( config . ultra )
maxFreq = 4290000000 ;
maxFreq = 5290000000ULL ;
else
maxFreq = 850000000 ;
break ;
@ -92,7 +92,7 @@ void update_min_max_freq(void)
case M_GENHIGH :
if ( high_out_adf4350 ) {
minFreq = 136000000 ;
maxFreq = 4 290000000U ;
maxFreq = 4 390000000ULL ;
} else {
minFreq = 136000000 ;
maxFreq = 1150000000U ;
@ -228,12 +228,6 @@ void reset_settings(int m)
dirty = true ;
}
//static uint32_t extra_vbw_step_time = 0;
//static uint32_t etra_repeat_time = 0;
//static uint32_t minimum_zero_span_sweep_time = 0;
//static uint32_t minimum_sweep_time = 0;
uint32_t calc_min_sweep_time_us ( void ) // Estimate minimum sweep time in uS, needed to calculate the initial delays for the RSSI before first sweep
{
uint32_t t ;
@ -307,7 +301,7 @@ void set_gridlines(int d)
//int setting_frequency_10mhz = 10000000;
void set_30mhz ( uint32 _t f )
void set_30mhz ( freq _t f )
{
if ( f < 29000000 | | f > 31000000 )
return ;
@ -744,7 +738,7 @@ void set_harmonic(int h)
{
setting . harmonic = h ;
minFreq = 684000000.0 ;
if ( ( uint32 _t) ( setting . harmonic * 135000000 ) + config . frequency_IF1 > minFreq )
if ( ( freq _t) ( setting . harmonic * 135000000 ) + config . frequency_IF1 > minFreq )
minFreq = setting . harmonic * 135000000 + config . frequency_IF1 ;
maxFreq = 4290000000.0 ;
if ( setting . harmonic ! = 0 & & ( 4400000000.0 * setting . harmonic + config . frequency_IF1 ) < 4360000000.0 )
@ -1146,7 +1140,7 @@ void apply_settings(void) // Ensure all settings in the setting structure
#if 0
# define CORRECTION_POINTS 10
static const uint32 _t correction_frequency [ CORRECTION_POINTS ] =
static const freq _t correction_frequency [ CORRECTION_POINTS ] =
{ 100000 , 200000 , 400000 , 1000000 , 2000000 , 50000000 , 100000000 , 200000000 , 300000000 , 350000000 } ;
static const float correction_value [ CORRECTION_POINTS ] =
@ -1178,7 +1172,7 @@ void calculate_correction(void)
# pragma GCC push_options
# pragma GCC optimize ("Og") // "Os" causes problem
pureRSSI_t get_frequency_correction ( uint32 _t f ) // Frequency dependent RSSI correction to compensate for imperfect LPF
pureRSSI_t get_frequency_correction ( freq _t f ) // Frequency dependent RSSI correction to compensate for imperfect LPF
{
pureRSSI_t cv = 0 ;
if ( setting . extra_lna ) {
@ -1204,7 +1198,7 @@ pureRSSI_t get_frequency_correction(uint32_t f) // Frequency dependent RSSI
}
f = f - config . correction_frequency [ i - 1 ] ;
#if 0
uint32 _t m = ( config . correction_frequency [ i ] - config . correction_frequency [ i - 1 ] ) > > SCALE_FACTOR ;
freq _t m = ( config . correction_frequency [ i ] - config . correction_frequency [ i - 1 ] ) > > SCALE_FACTOR ;
float multi = ( config . correction_value [ i ] - config . correction_value [ i - 1 ] ) * ( 1 < < ( SCALE_FACTOR - 1 ) ) / ( float ) m ;
float cv = config . correction_value [ i - 1 ] + ( ( f > > SCALE_FACTOR ) * multi ) / ( float ) ( 1 < < ( SCALE_FACTOR - 1 ) ) ;
# else
@ -1220,17 +1214,12 @@ done:
float peakLevel ;
float min_level ;
uint32 _t peakFreq ;
freq _t peakFreq ;
int peakIndex ;
float temppeakLevel ;
int temppeakIndex ;
// volatile int t;
//static uint32_t extra_vbw_step_time = 0;
//static uint32_t etra_repeat_time = 0;
//static uint32_t minimum_zero_span_sweep_time = 0;
//static uint32_t minimum_sweep_time = 0;
void setup_sa ( void )
{
# ifdef __SI4432__
@ -1301,9 +1290,9 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency
if ( delta > OFFSET_LOWER_BOUND & & delta < 79999 ) { // and requested frequency can be reached by using the offset registers
#if 0
if ( real_old_freq [ V ] > = 480000000 )
shell_printf ( " %d: Offs %q HW %d \r \n " , SI4432_Sel , ( uint32 _t) ( real_old_freq [ V ] + delta * 2 ) , real_old_freq [ V ] ) ;
shell_printf ( " %d: Offs %q HW %d \r \n " , SI4432_Sel , ( freq _t) ( real_old_freq [ V ] + delta * 2 ) , real_old_freq [ V ] ) ;
else
shell_printf ( " %d: Offs %q HW %d \r \n " , SI4432_Sel , ( uint32 _t) ( real_old_freq [ V ] + delta * 1 ) , real_old_freq [ V ] ) ;
shell_printf ( " %d: Offs %q HW %d \r \n " , SI4432_Sel , ( freq _t) ( real_old_freq [ V ] + delta * 1 ) , real_old_freq [ V ] ) ;
# endif
delta = delta * 4 / 625 ; // = 156.25; // Calculate and set the offset register i.s.o programming a new frequency
SI4432_Write_2_Byte ( SI4432_FREQ_OFFSET1 , ( uint8_t ) ( delta & 0xff ) , ( uint8_t ) ( ( delta > > 8 ) & 0x03 ) ) ;
@ -1312,7 +1301,7 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency
old_freq [ V ] = freq ;
} else {
# ifdef __WIDE_OFFSET__
uint32 _t target_f ; // Impossible to use offset so set SI4432 to new frequency
freq _t target_f ; // Impossible to use offset so set SI4432 to new frequency
if ( freq < real_old_freq [ V ] ) { // sweeping down
if ( freq - 80000 > = 480000000 ) {
target_f = freq - 160000 ;
@ -1658,12 +1647,12 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (#
# define frequency_seatch_gate 60 // 120% of the RBW
int binary_search_frequency ( uint32 _t f ) // Search which index in the frequency tabled matches with frequency f using actual_rbw
int binary_search_frequency ( freq _t f ) // Search which index in the frequency tabled matches with frequency f using actual_rbw
{
int L = 0 ;
int R = ( sizeof frequencies ) / sizeof ( int ) - 1 ;
uint32 _t fmin = f - actual_rbw_x10 * frequency_seatch_gate ;
uint32 _t fplus = f + actual_rbw_x10 * frequency_seatch_gate ;
freq _t fmin = f - actual_rbw_x10 * frequency_seatch_gate ;
freq _t fplus = f + actual_rbw_x10 * frequency_seatch_gate ;
while ( L < = R ) {
int m = ( L + R ) / 2 ;
if ( frequencies [ m ] < fmin )
@ -1694,7 +1683,7 @@ void interpolate_maximum(int m)
# define MAX_MAX 4
int
search_maximum ( int m , uint32 _t center , int span )
search_maximum ( int m , freq _t center , int span )
{
int center_index = binary_search_frequency ( center ) ;
int from = center_index - span / 2 ;
@ -1761,7 +1750,7 @@ search_maximum(int m, uint32_t center, int span)
//static int spur_old_stepdelay = 0;
//static const unsigned int spur_IF = DEFAULT_IF; // The IF frequency for which the spur table is value
//static const unsigned int spur_alternate_IF = DEFAULT_SPUR_IF; // if the frequency is found in the spur table use this IF frequency
static uint32 _t spur_table [ ] = // Frequencies to avoid
static freq _t spur_table [ ] = // Frequencies to avoid
{
243775000 , // OK
325000000 , // !!! This is a double spur
@ -1811,12 +1800,12 @@ static uint32_t spur_table[] = // Frequencies t
# endif
} ;
int binary_search ( uint32 _t f )
int binary_search ( freq _t f )
{
int L = 0 ;
int R = ( sizeof spur_table ) / sizeof ( int ) - 1 ;
uint32 _t fmin = f - actual_rbw_x10 * spur_gate ;
uint32 _t fplus = f + actual_rbw_x10 * spur_gate ;
freq _t fmin = f - actual_rbw_x10 * spur_gate ;
freq _t fplus = f + actual_rbw_x10 * spur_gate ;
while ( L < = R ) {
int m = ( L + R ) / 2 ;
if ( spur_table [ m ] < fmin )
@ -1860,7 +1849,7 @@ void fill_spur_table(void)
}
}
int avoid_spur ( uint32 _t f ) // find if this frequency should be avoided
int avoid_spur ( freq _t f ) // find if this frequency should be avoided
{
// int window = ((int)actual_rbw ) * 1000*2;
// if (window < 50000)
@ -1940,7 +1929,7 @@ static void calculate_static_correction(void) // Calculate the
- setting . offset ) ;
}
pureRSSI_t perform ( bool break_on_operation , int i , uint32 _t f , int tracking ) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
pureRSSI_t perform ( bool break_on_operation , int i , freq _t f , int tracking ) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup
{
int modulation_delay = 0 ;
int modulation_index = 0 ;
@ -2069,7 +2058,7 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking)
// modulation_index = 0; // default value
}
if ( ( setting . mode = = M_GENLOW ) | |
( setting . mode = = M_GENHIGH & & f > ( ( uint32 _t) 480000000 ) ) )
( setting . mode = = M_GENHIGH & & f > ( ( freq _t) 480000000 ) ) )
modulation_index + = 2 ;
current_fm_modulation = ( int * ) fm_modulation [ modulation_index ] ;
f - = fm_modulation_offset [ modulation_index ] ; // Shift output frequency
@ -2120,7 +2109,7 @@ modulation_again:
# endif
int t = 0 ;
do {
uint32 _t lf = f ;
freq _t lf = f ;
if ( vbwSteps > 1 ) { // Calculate sub steps
int offs_div10 = ( t - ( vbwSteps > > 1 ) ) * 100 ; // steps of x10 * settings.
if ( ( vbwSteps & 1 ) = = 0 ) // Uneven steps, center
@ -2129,16 +2118,17 @@ modulation_again:
// if (setting.step_delay_mode == SD_PRECISE)
// offs>>=1; // steps of a quarter rbw
// if (lf > -offs) // No negative frequencies
if ( offs > = 0 | | lf > - offs )
lf + = offs ;
if ( lf > 4290000000U )
lf = 0 ;
// if (lf > 4290000000U)
// lf = 0;
}
// -------------- Calculate the IF -----------------------------
if ( /* MODE_INPUT(setting.mode) && */ i > 0 & & FREQ_IS_CW ( ) ) // In input mode in zero span mode after first setting of the LO's
goto skip_LO_setting ; // No more LO changes required, save some time and jump over the code
uint32 _t local_IF ;
freq _t local_IF ;
spur_second_pass = false ;
again : // Spur reduction jumps to here for second measurement
@ -2271,11 +2261,11 @@ modulation_again:
if ( setting . R = = 0 ) {
if ( lf < 850000000U & & lf > = TXCO_DIV3 ) {
uint32 _t tf = ( ( lf + actual_rbw_x10 * 100 ) / TCXO ) * TCXO ;
freq _t tf = ( ( lf + actual_rbw_x10 * 100 ) / TCXO ) * TCXO ;
if ( tf + actual_rbw_x10 * 100 > = lf & & tf < lf + actual_rbw_x10 * 100 ) {
// ADF4351_R_counter(8); no impact
} else {
uint32 _t tf = ( ( lf + actual_rbw_x10 * 100 ) / TXCO_DIV3 ) * TXCO_DIV3 ;
freq _t tf = ( ( lf + actual_rbw_x10 * 100 ) / TXCO_DIV3 ) * TXCO_DIV3 ;
if ( tf + actual_rbw_x10 * 100 > = lf & & tf < lf + actual_rbw_x10 * 100 )
ADF4351_R_counter ( 4 ) ;
else
@ -2290,7 +2280,7 @@ modulation_again:
if ( false ) { // Avoid 72MHz spur
# define SPUR 2 * 72000000
uint32 _t tf = ( ( lf + actual_rbw_x10 * 100 ) / SPUR ) * SPUR ;
freq _t tf = ( ( lf + actual_rbw_x10 * 100 ) / SPUR ) * SPUR ;
# undef STM32_USBPRE
int STM32_USBPRE ;
# undef STM32_PLLMUL
@ -2325,7 +2315,7 @@ modulation_again:
# endif
#if 0
uint32 _t target_f ;
freq _t target_f ;
if ( ! setting . tracking & & S_STATE ( setting . below_IF ) ) { // if in low input mode and below IF
if ( lf > local_IF + 138000000 )
target_f = lf - local_IF ; // set LO SI4432 to below IF frequency
@ -2400,7 +2390,7 @@ modulation_again:
}
if ( debug_frequencies ) {
uint32 _t f ;
freq _t f ;
if ( setting . mode = = M_LOW | | setting . mode = = M_GENLOW )
f = real_old_freq [ ADF4351_LO ] - ( real_old_freq [ SI4463_RX ] + real_offset ) ;
else
@ -2592,7 +2582,7 @@ static bool sweep(bool break_on_operation)
float RSSI ;
int16_t downslope ;
# ifdef __SI4432__
uint32 _t agc_peak_freq = 0 ;
freq _t agc_peak_freq = 0 ;
float agc_peak_rssi = - 150 ;
float agc_prev_rssi = - 150 ;
int last_AGC_value = 0 ;
@ -2671,7 +2661,7 @@ sweep_again: // stay in sweep loop when output mo
}
if ( RSSI < AGC_RSSI_THRESHOLD )
agc_prev_rssi = - 150 ;
uint32 _t delta_freq = frequencies [ i ] - agc_peak_freq ;
freq _t delta_freq = frequencies [ i ] - agc_peak_freq ;
if ( agc_peak_freq ! = 0 & & delta_freq < 2000000 ) {
int max_gain = ( - 25 - agc_peak_rssi ) / 4 ;
auto_set_AGC_LNA ( false , 16 + delta_freq * max_gain / 2000000 ) ; // enable LNA and stepwise gain
@ -3065,7 +3055,7 @@ sweep_again: // stay in sweep loop when output mo
#if 0
float v = actual_t [ markers [ m ] . index ] - 10.0 ; // -10dB points
int index = markers [ m ] . index ;
uint32 _t f = markers [ m ] . frequency ;
freq _t f = markers [ m ] . frequency ;
uint32_t s = actual_rbw_x10 * 200 ; // twice the selected RBW
int left = index , right = index ;
while ( t > 0 & & actual_t [ t + 1 ] > v & & markers [ t ] . frequency > f - s ) // Find left point
@ -3116,8 +3106,8 @@ sweep_again: // stay in sweep loop when output mo
markers [ 0 ] . index = l ;
markers [ 1 ] . index = r ;
}
uint32 _t lf = frequencies [ l ] ;
uint32 _t rf = frequencies [ r ] ;
freq _t lf = frequencies [ l ] ;
freq _t rf = frequencies [ r ] ;
markers [ 0 ] . frequency = lf ;
markers [ 1 ] . frequency = rf ;
@ -3770,8 +3760,8 @@ common_silent:
}
trace [ TRACE_STORED ] . enabled = true ;
set_reflevel ( test_case [ i ] . pass + 10 ) ;
set_sweep_frequency ( ST_CENTER , ( uint32 _t) ( test_case [ i ] . center * 1000000 ) ) ;
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( test_case [ i ] . span * 1000000 ) ) ;
set_sweep_frequency ( ST_CENTER , ( freq _t) ( test_case [ i ] . center * 1000000 ) ) ;
set_sweep_frequency ( ST_SPAN , ( freq _t) ( test_case [ i ] . span * 1000000 ) ) ;
draw_cal_status ( ) ;
}
@ -3950,12 +3940,12 @@ void self_test(int test)
shell_printf ( " RBW = %f, " , setting . rbw_x10 / 10.0 ) ;
#if 0
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( setting . rbw_x10 * 1000 ) ) ; // Wide
set_sweep_frequency ( ST_SPAN , ( freq _t) ( setting . rbw_x10 * 1000 ) ) ; // Wide
# else
if ( setting . rbw_x10 < 1000 )
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( setting . rbw_x10 * 5000 ) ) ; // Narrow
set_sweep_frequency ( ST_SPAN , ( freq _t) ( setting . rbw_x10 * 5000 ) ) ; // Narrow
else
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( 18000000 ) ) ;
set_sweep_frequency ( ST_SPAN , ( freq _t) ( 18000000 ) ) ;
# endif
test_acquire ( TEST_RBW ) ; // Acquire test
test_validate ( TEST_RBW ) ; // Validate test
@ -3977,9 +3967,9 @@ void self_test(int test)
setting . step_delay_mode = SD_NORMAL ;
setting . step_delay = setting . step_delay * 4 / 5 ;
if ( setting . rbw_x10 < 1000 )
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( setting . rbw_x10 * 5000 ) ) ;
set_sweep_frequency ( ST_SPAN , ( freq _t) ( setting . rbw_x10 * 5000 ) ) ;
else
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( 18000000 ) ) ;
set_sweep_frequency ( ST_SPAN , ( freq _t) ( 18000000 ) ) ;
// setting.repeat = 10;
test_acquire ( TEST_RBW ) ; // Acquire test
@ -4002,9 +3992,9 @@ void self_test(int test)
setting . offset_delay / = 2 ;
setting . spur_removal = S_OFF ;
if ( setting . rbw_x10 < 1000 )
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( setting . rbw_x10 * 5000 ) ) ; // 50 times RBW
set_sweep_frequency ( ST_SPAN , ( freq _t) ( setting . rbw_x10 * 5000 ) ) ; // 50 times RBW
else
set_sweep_frequency ( ST_SPAN , ( uint32 _t) ( 18000000 ) ) ; // Limit to 18MHz
set_sweep_frequency ( ST_SPAN , ( freq _t) ( 18000000 ) ) ; // Limit to 18MHz
// setting.repeat = 10;
test_acquire ( TEST_RBW ) ; // Acquire test
test_validate ( TEST_RBW ) ; // Validate test