From a04d69b011874e8ed361dc5f5907507d20ef3981 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 5 Feb 2021 17:41:07 +0100 Subject: [PATCH] Converted to 64 bit frequencies --- chprintf.c | 34 +++++++++-------- main.c | 64 +++++++++++++++---------------- nanovna.h | 65 ++++++++++++++++++-------------- plot.c | 58 ++++++++++++++-------------- sa_cmd.c | 39 +++++++++---------- sa_core.c | 108 ++++++++++++++++++++++++----------------------------- si4432.c | 12 +++--- ui.c | 44 +++++++++++----------- ui_sa.c | 16 ++++---- 9 files changed, 221 insertions(+), 219 deletions(-) diff --git a/chprintf.c b/chprintf.c index 2b9bb62..20627c6 100644 --- a/chprintf.c +++ b/chprintf.c @@ -57,7 +57,7 @@ static char smallPrefix[] = {'m', 0x1d, 'n', 'p', 'f', 'a', 'z', 'y', 0}; #pragma pack(pop) static char *long_to_string_with_divisor(char *p, - uint32_t num, + uint64_t num, uint32_t radix, uint32_t precision) { char *q = p + MAX_FILLER; @@ -84,7 +84,7 @@ static char *long_to_string_with_divisor(char *p, #define FREQ_PREFIX_SPACE 4 static char * -ulong_freq(char *p, uint32_t freq, uint32_t precision) +ulong_freq(char *p, uint64_t freq, uint32_t precision) { uint8_t flag = FREQ_PSET; flag|= precision == 0 ? FREQ_PREFIX_SPACE : FREQ_NO_SPACE; @@ -258,6 +258,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { uint32_t u; int32_t l; float f; + uint64_t x; }value; #if CHPRINTF_USE_FLOAT char tmpbuf[2*MAX_FILLER + 1]; @@ -329,12 +330,12 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { else state|=DEFAULT_PRESCISION; //Get [length] - /* if (c == 'l' || c == 'L') { state|=IS_LONG; if (*fmt) c = *fmt++; } + /* else if ((c >= 'A') && (c <= 'Z')) state|=IS_LONG; */ @@ -356,15 +357,15 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { case 'D': case 'd': case 'I': - case 'i':/* + case 'i': if (state & IS_LONG) - value.l = va_arg(ap, long); - else*/ - value.l = va_arg(ap, uint32_t); - if (value.l < 0) { + value.x = va_arg(ap, uint64_t); + else + value.x = va_arg(ap, uint32_t); + if (value.x < 0) { state|=NEGATIVE; *p++ = '-'; - value.l = -value.l; + value.x = -value.l; } else if (state & POSITIVE) *p++ = '+'; @@ -372,11 +373,14 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { else if (state & PLUS_SPACE) *p++ = ' '; #endif - p = long_to_string_with_divisor(p, value.l, 10, 0); + p = long_to_string_with_divisor(p, (uint64_t)value.x, 10, 0); break; case 'q': - value.u = va_arg(ap, uint32_t); - p=ulong_freq(p, value.u, precision); + if (state & IS_LONG) + value.x = va_arg(ap, uint64_t); + else + value.x = va_arg(ap, uint32_t); + p=ulong_freq(p, value.x, precision); break; #if CHPRINTF_USE_FLOAT case 'F': @@ -411,10 +415,10 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { case 'O': case 'o': c = 8; -unsigned_common:/* +unsigned_common: if (state & IS_LONG) - value.u = va_arg(ap, unsigned long); - else*/ + value.x = va_arg(ap, uint64_t); + else value.u = va_arg(ap, uint32_t); p = long_to_string_with_divisor(p, value.u, c, 0); break; diff --git a/main.c b/main.c index 1988d7a..f44c07d 100644 --- a/main.c +++ b/main.c @@ -35,10 +35,10 @@ #include #include -extern uint32_t minFreq; -extern uint32_t maxFreq; -uint32_t frequencyStart; -uint32_t frequencyStop; +extern freq_t minFreq; +extern freq_t maxFreq; +freq_t frequencyStart; +freq_t frequencyStop; int32_t frequencyExtra; #define START_MIN minFreq #define STOP_MAX maxFreq @@ -91,7 +91,7 @@ static void apply_edelay_at(int i); static void cal_interpolate(int s); #endif void update_frequencies(void); -static void set_frequencies(uint32_t start, uint32_t stop, uint16_t points); +static void set_frequencies(freq_t start, freq_t stop, uint16_t points); static bool sweep(bool break_on_operation); #ifdef __VNA__ static void transform_domain(void); @@ -423,7 +423,7 @@ adjust_gain(uint32_t newfreq) } #endif -int set_frequency(uint32_t freq) +int set_frequency(freq_t freq) { (void) freq; #ifdef __VNA__ @@ -589,7 +589,7 @@ VNA_SHELL_FUNCTION(cmd_freq) if (argc != 1) { goto usage; } - uint32_t freq = my_atoui(argv[0]); + freq_t freq = my_atoui(argv[0]); pause_sweep(); set_frequency(freq); @@ -1091,7 +1091,7 @@ void set_sweep_points(uint16_t points){ VNA_SHELL_FUNCTION(cmd_scan) { - uint32_t start, stop; + freq_t start, stop; uint32_t points = sweep_points; uint32_t i; if (argc < 2 || argc > 4) { @@ -1142,9 +1142,9 @@ update_marker_index(void) for (m = 0; m < MARKERS_MAX; m++) { if (!markers[m].enabled) continue; - uint32_t f = markers[m].frequency; - uint32_t fstart = get_sweep_frequency(ST_START); - uint32_t fstop = get_sweep_frequency(ST_STOP); + freq_t f = markers[m].frequency; + freq_t fstart = get_sweep_frequency(ST_START); + freq_t fstop = get_sweep_frequency(ST_STOP); if (f < fstart) { markers[m].index = 0; markers[m].frequency = fstart; @@ -1163,13 +1163,13 @@ update_marker_index(void) } } -void set_marker_frequency(int m, uint32_t f) +void set_marker_frequency(int m, freq_t f) { if (m < 0 || !markers[m].enabled) return; int i = 1; markers[m].mtype &= ~M_TRACKING; - uint32_t s = (frequencies[1] - frequencies[0])/2; + freq_t s = (frequencies[1] - frequencies[0])/2; while (i< sweep_points - 2){ if (frequencies[i]-s <= f && f < frequencies[i+1]-s) { // Avoid rounding error in s!!!!!!! markers[m].index = i; @@ -1181,14 +1181,14 @@ void set_marker_frequency(int m, uint32_t f) } static void -set_frequencies(uint32_t start, uint32_t stop, uint16_t points) +set_frequencies(freq_t start, freq_t stop, uint16_t points) { uint32_t i; - uint32_t step = (points - 1); - uint32_t span = stop - start; - uint32_t delta = span / step; - uint32_t error = span % step; - uint32_t f = start, df = step>>1; + freq_t step = (points - 1); + freq_t span = stop - start; + freq_t delta = span / step; + freq_t error = span % step; + freq_t f = start, df = step>>1; for (i = 0; i <= step; i++, f+=delta) { frequencies[i] = f; df+=error; @@ -1207,7 +1207,7 @@ set_frequencies(uint32_t start, uint32_t stop, uint16_t points) void update_frequencies(void) { - uint32_t start, stop; + freq_t start, stop; start = get_sweep_frequency(ST_START); stop = get_sweep_frequency(ST_STOP); @@ -1221,7 +1221,7 @@ update_frequencies(void) } void -set_sweep_frequency(int type, uint32_t freq) +set_sweep_frequency(int type, freq_t freq) { #ifdef __VNA__ int cal_applied = cal_status & CALSTAT_APPLY; @@ -1257,9 +1257,9 @@ set_sweep_frequency(int type, uint32_t freq) break; case ST_CENTER: setting.freq_mode |= FREQ_MODE_CENTER_SPAN; - uint32_t center = setting.frequency0 / 2 + setting.frequency1 / 2; + freq_t center = setting.frequency0 / 2 + setting.frequency1 / 2; if (center != freq) { - uint32_t span = setting.frequency1 - setting.frequency0; + freq_t span = setting.frequency1 - setting.frequency0; if (freq < START_MIN + span / 2) { span = (freq - START_MIN) * 2; } @@ -1273,7 +1273,7 @@ set_sweep_frequency(int type, uint32_t freq) case ST_SPAN: setting.freq_mode |= FREQ_MODE_CENTER_SPAN; if (setting.frequency1 - setting.frequency0 != freq) { - uint32_t center = setting.frequency0 / 2 + setting.frequency1 / 2; + freq_t center = setting.frequency0 / 2 + setting.frequency1 / 2; if (center < START_MIN + freq / 2) { center = START_MIN + freq / 2; } @@ -1300,12 +1300,12 @@ set_sweep_frequency(int type, uint32_t freq) #endif } -uint32_t +freq_t get_sweep_frequency(int type) { // Obsolete, ensure correct start/stop, start always must be < stop if (setting.frequency0 > setting.frequency1) { - uint32_t t = setting.frequency0; + freq_t t = setting.frequency0; setting.frequency0 = setting.frequency1; setting.frequency1 = t; } @@ -1327,9 +1327,9 @@ VNA_SHELL_FUNCTION(cmd_sweep) } else if (argc > 3) { goto usage; } - uint32_t value0 = 0; - uint32_t value1 = 0; - uint32_t value2 = 0; + freq_t value0 = 0; + freq_t value1 = 0; + freq_t value2 = 0; if (argc >= 1) value0 = my_atoui(argv[0]); if (argc >= 2) value1 = my_atoui(argv[1]); if (argc >= 3) value2 = my_atoui(argv[2]); @@ -2026,7 +2026,7 @@ VNA_SHELL_FUNCTION(cmd_marker) default: // select active marker and move to index or frequency markers[t].enabled = TRUE; - uint32_t value = my_atoui(argv[1]); + freq_t value = my_atoui(argv[1]); markers[t].mtype &= ~M_TRACKING; active_marker = t; if (value > sweep_points) @@ -2949,12 +2949,12 @@ int main(void) redraw_frame(); #ifdef TINYSA3 set_mode(M_HIGH); - set_sweep_frequency(ST_STOP, (uint32_t) 30000000); + set_sweep_frequency(ST_STOP, (freq_t) 30000000); sweep(false); osalThreadSleepMilliseconds(100); set_mode(M_LOW); - set_sweep_frequency(ST_STOP, (uint32_t) 4000000); + set_sweep_frequency(ST_STOP, (freq_t) 4000000); sweep(false); #endif diff --git a/nanovna.h b/nanovna.h index ff3b304..f303afa 100644 --- a/nanovna.h +++ b/nanovna.h @@ -67,9 +67,9 @@ #define HIGH_MAX_FREQ_MHZ 960 #endif #ifdef TINYSA4 -#define DEFAULT_IF ((uint32_t)977100000) -#define DEFAULT_SPUR_OFFSET ((uint32_t)1500000) -#define DEFAULT_MAX_FREQ ((uint32_t)800000000) +#define DEFAULT_IF ((freq_t)977100000) +#define DEFAULT_SPUR_OFFSET ((freq_t)1500000) +#define DEFAULT_MAX_FREQ ((freq_t)800000000) #define HIGH_MIN_FREQ_MHZ 136// 825 #define HIGH_MAX_FREQ_MHZ 1130 #endif @@ -94,6 +94,13 @@ #define actual_t measured[TRACE_ACTUAL] #define temp_t measured[TRACE_TEMP] +#ifdef TINYSA3 +typedef uint32_t freq_t; +#endif +#ifdef TINYSA4 +typedef uint64_t freq_t; +#endif + #define CORRECTION_POINTS 10 // Frequency dependent level correction table entries typedef float measurement_t[TRACES_MAX][POINTS_COUNT]; @@ -169,15 +176,15 @@ enum stimulus_type { void set_sweep_points(uint16_t points); void update_frequencies(void); -void set_sweep_frequency(int type, uint32_t frequency); -uint32_t get_sweep_frequency(int type); +void set_sweep_frequency(int type, freq_t frequency); +freq_t get_sweep_frequency(int type); void my_microsecond_delay(int t); float my_atof(const char *p); int shell_printf(const char *fmt, ...); void send_region(const char *t, int x, int y, int w, int h); void send_buffer(uint8_t * buf, int s); -void set_marker_frequency(int m, uint32_t f); +void set_marker_frequency(int m, freq_t f); void toggle_sweep(void); void toggle_mute(void); void toggle_extra_lna(void); @@ -241,8 +248,8 @@ extern const char *info_about[]; extern const char * const unit_string[]; extern uint8_t signal_is_AM; extern const int reffer_freq[]; -extern uint32_t minFreq; -extern uint32_t maxFreq; +extern freq_t minFreq; +extern freq_t maxFreq; int level_is_calibrated(void); void reset_settings(int); void update_min_max_freq(void); @@ -315,10 +322,10 @@ void set_attack(int); void set_noise(int); void toggle_tracking_output(void); extern int32_t frequencyExtra; -void set_30mhz(uint32_t f); +void set_30mhz(freq_t f); void set_modulation(int); void set_modulation_frequency(int); -int search_maximum(int m, uint32_t center, int span); +int search_maximum(int m, freq_t center, int span); //extern int setting.modulation; void set_measurement(int); // extern int settingSpeed; @@ -558,17 +565,17 @@ typedef struct config { uint16_t vbat_offset; float low_level_offset; float high_level_offset; - uint32_t correction_frequency[CORRECTION_POINTS]; + freq_t correction_frequency[CORRECTION_POINTS]; float correction_value[CORRECTION_POINTS]; uint32_t deviceid; - uint32_t setting_frequency_30mhz; + freq_t setting_frequency_30mhz; uint16_t gridlines; uint16_t hambands; #ifdef TINYSA4 - uint32_t frequency_IF1; - uint32_t frequency_IF2; - uint32_t ultra_threshold; + freq_t frequency_IF1; + freq_t frequency_IF2; + freq_t ultra_threshold; #endif int8_t _mode; int8_t cor_am; @@ -626,7 +633,7 @@ typedef struct { int8_t enabled; int8_t mtype; int16_t index; - uint32_t frequency; + freq_t frequency; } marker_t; #define MARKERS_MAX 4 @@ -797,8 +804,8 @@ void show_version(void); typedef struct setting { uint32_t magic; -// uint32_t _frequency0; -// uint32_t _frequency1; +// freq_t _frequency0; +// freq_t _frequency1; int mode; uint16_t _sweep_points; int16_t attenuate_x2; @@ -819,7 +826,7 @@ typedef struct setting int tracking; int modulation; int step_delay; - uint32_t frequency_step; + freq_t frequency_step; int test; int harmonic; int decay; @@ -828,9 +835,9 @@ typedef struct setting uint32_t vbw_x10; int tracking_output; int repeat; - uint32_t frequency0; - uint32_t frequency1; - uint32_t frequency_IF; + freq_t frequency0; + freq_t frequency1; + freq_t frequency_IF; int freq_mode; int measurement; int refer; @@ -894,7 +901,7 @@ enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL }; #define REPEAT_TIME 111 // Time per extra repeat in uS #define MEASURE_TIME 127 // Time per single point measurement with vbwstep =1 without step delay in uS -extern uint32_t frequencies[POINTS_COUNT]; +extern freq_t frequencies[POINTS_COUNT]; extern const float unit_scale_value[]; extern const char * const unit_scale_text[]; extern int debug_frequencies; @@ -940,17 +947,17 @@ extern int debug_frequencies; typedef struct properties { uint32_t magic; preset_t setting; -// uint32_t _frequency0; -// uint32_t _frequency1; +// freq_t _frequency0; +// freq_t _frequency1; uint16_t _sweep_points; #ifdef __VNA__ uint16_t _cal_status; #endif #ifdef __SA__ -// uint32_t _frequency_IF; //IF frequency +// freq_t _frequency_IF; //IF frequency #endif -// uint32_t _frequencies[POINTS_COUNT]; +// freq_t _frequencies[POINTS_COUNT]; #ifdef __VNA__ float _cal_data[5][POINTS_COUNT][2]; float _electrical_delay; // picoseconds @@ -1168,7 +1175,7 @@ void wait_user(void); void calibrate(void); float to_dBm(float); uint32_t calc_min_sweep_time_us(void); -pureRSSI_t perform(bool b, int i, uint32_t f, int e); +pureRSSI_t perform(bool b, int i, freq_t f, int e); void interpolate_maximum(int m); enum { @@ -1194,7 +1201,7 @@ extern void SI4463_init_rx(void); extern void SI4463_init_tx(void); extern void SI4463_start_tx(uint8_t CHANNEL); extern void SI4463_set_output_level(int t); -extern uint32_t SI4463_set_freq(uint32_t freq); +extern freq_t SI4463_set_freq(freq_t freq); extern uint16_t set_rbw(uint16_t rbw_x10); extern uint16_t force_rbw(int f); extern void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen); diff --git a/plot.c b/plot.c index 9fdfe48..dedd76c 100644 --- a/plot.c +++ b/plot.c @@ -42,7 +42,7 @@ void cell_draw_test_info(int x0, int y0); static int16_t grid_offset; static int16_t grid_width; -static int32_t grid_span; +static freq_t grid_span; int16_t area_width = AREA_WIDTH_NORMAL; int16_t area_height; // initialized in main() = AREA_HEIGHT_NORMAL; @@ -119,10 +119,10 @@ float2int(float v) void update_grid(void) { - uint32_t gdigit = 100000000; - uint32_t fstart = get_sweep_frequency(ST_START); - uint32_t fspan = get_sweep_frequency(ST_SPAN); - uint32_t grid; + freq_t gdigit = 100000000; + freq_t fstart = get_sweep_frequency(ST_START); + freq_t fspan = get_sweep_frequency(ST_SPAN); + freq_t grid; if (fspan == 0) { fspan = setting.actual_sweep_time_us; // Time in uS @@ -412,8 +412,8 @@ rectangular_grid(int x, int y) #ifdef __HAM_BAND__ typedef const struct { - uint32_t start; - uint32_t stop; + freq_t start; + freq_t stop; } ham_bands_t; const ham_bands_t ham_bands[] = @@ -439,9 +439,9 @@ int ham_band(int x) // Search which index in the frequency tabled matches w { if (!config.hambands) return false; - uint32_t f = frequencies[x]; + freq_t f = frequencies[x]; int L = 0; - int R = (sizeof ham_bands)/sizeof(uint32_t) - 1; + int R = (sizeof ham_bands)/sizeof(freq_t) - 1; while (L <= R) { int m = (L + R) / 2; if (ham_bands[m].stop < f) @@ -909,14 +909,14 @@ void trace_get_value_string( // Only used at one place int t, char *buf, int len, int i, float coeff[POINTS_COUNT], int ri, int mtype, - uint32_t i_freq, uint32_t ref_freq) + freq_t i_freq, freq_t ref_freq) { (void) t; float v; char buf2[16]; char buf3[8]; char *ptr2 = buf2; - uint32_t dfreq = 0; + freq_t dfreq = 0; float rlevel = 0; int ii = i; int unit_index = setting.unit; @@ -961,7 +961,7 @@ void trace_get_value_string( // Only used at one place #endif } else { #if 0 - uint32_t resolution = get_sweep_frequency(ST_SPAN); + freq_t resolution = get_sweep_frequency(ST_SPAN); if (resolution <= 2000*POINTS_COUNT) plot_printf(ptr2, sizeof(buf2) - 2, "%3.3f" , (dfreq + 500) / 1000000.0); else if (resolution <= 20000*POINTS_COUNT) @@ -970,7 +970,7 @@ void trace_get_value_string( // Only used at one place plot_printf(ptr2, sizeof(buf2) - 2, "%3.1f" , (dfreq + 50000) / 1000000.0); } #else - plot_printf(ptr2, sizeof(buf2) - 2, "%9.5qHz" , dfreq); + plot_printf(ptr2, sizeof(buf2) - 2, "%9.5LqHz" , dfreq); } #endif v = value(coeff[i]); @@ -1957,10 +1957,10 @@ cell_draw_marker_info(int x0, int y0) cell_drawstring(buf, xpos, ypos); xpos += 13; //trace_get_info(t, buf, sizeof buf); - uint32_t freq = frequencies[markers[mk].index]; + freq_t freq = frequencies[markers[mk].index]; if (uistat.marker_delta && mk != active_marker) { - uint32_t freq1 = frequencies[markers[active_marker].index]; - uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq; + freq_t freq1 = frequencies[markers[active_marker].index]; + freq_t delta = freq > freq1 ? freq - freq1 : freq1 - freq; plot_printf(buf, sizeof buf, S_DELTA"%.9qHz", delta); } else { plot_printf(buf, sizeof buf, "%.10qHz", freq); @@ -1987,9 +1987,9 @@ cell_draw_marker_info(int x0, int y0) cell_drawstring(buf, xpos, ypos); xpos += 27; if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { - uint32_t freq = frequencies[idx]; - uint32_t freq1 = frequencies[idx0]; - uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq; + freq_t freq = frequencies[idx]; + freq_t freq1 = frequencies[idx0]; + freq_t delta = freq > freq1 ? freq - freq1 : freq1 - freq; plot_printf(buf, sizeof buf, "%c%.13qHz", freq >= freq1 ? '+' : '-', delta); } else { plot_printf(buf, sizeof buf, "%Fs (%Fm)", time_of_index(idx) - time_of_index(idx0), distance_of_index(idx) - distance_of_index(idx0)); @@ -2100,12 +2100,12 @@ static void cell_draw_marker_info(int x0, int y0) for (int i = 0; i < MARKER_COUNT; i++) { if (i == 3) { if (setting.measurement == M_PASS_BAND) { - uint32_t f; + freq_t f; if (markers[2].frequency>markers[1].frequency) f = markers[2].frequency-markers[1].frequency; else f = markers[1].frequency-markers[2].frequency; - plot_printf(buf, sizeof buf, "WIDTH: %8.3qHz", f); + plot_printf(buf, sizeof buf, "WIDTH: %8.3LqHz", f); show_computed: j = 3; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; @@ -2131,17 +2131,17 @@ static void cell_draw_marker_info(int x0, int y0) plot_printf(buf, sizeof buf, "DEPTH: %3d%%", depth); goto show_computed; } else if (setting.measurement == M_FM){ - int32_t dev = ( markers[2].frequency - markers[1].frequency - actual_rbw_x10 * 100 ) >> 1; + freq_t dev = ( markers[2].frequency - markers[1].frequency - actual_rbw_x10 * 100 ) >> 1; if (dev < 0 ) break; - plot_printf(buf, sizeof buf, "DEVIATION:%6.1qHz", dev); + plot_printf(buf, sizeof buf, "DEVIATION:%6.1LqHz", dev); goto show_computed; } else if (setting.measurement == M_THD && markers[0].enabled && (markers[0].index << 5) > sweep_points ) { int old_unit = setting.unit; setting.unit = U_WATT; float p = index_to_value(markers[0].index); int h_i = 2; - uint32_t f = markers[0].frequency; + freq_t f = markers[0].frequency; float h = 0.0; while (f * h_i < frequencies[sweep_points-1]) { if (search_maximum(1, f*h_i, 4*h_i) ) // use marker 1 for searching harmonics @@ -2270,17 +2270,17 @@ draw_frequencies(void) if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { #endif if (FREQ_IS_CW()) { - plot_printf(buf1, sizeof(buf1), " CW %qHz", get_sweep_frequency(ST_CW)); + plot_printf(buf1, sizeof(buf1), " CW %LqHz", get_sweep_frequency(ST_CW)); // Show user actual select sweep time? uint32_t t = setting.actual_sweep_time_us; plot_printf(buf2, sizeof(buf2), " TIME %.3Fs", (float)t/ONE_SECOND_TIME); } else if (FREQ_IS_STARTSTOP()) { - plot_printf(buf1, sizeof(buf1), " START %.3qHz %5.1qHz/", get_sweep_frequency(ST_START), grid_span); - plot_printf(buf2, sizeof(buf2), " STOP %.3qHz", get_sweep_frequency(ST_STOP)); + plot_printf(buf1, sizeof(buf1), " START %.3LqHz %5.1LqHz/", get_sweep_frequency(ST_START), grid_span); + plot_printf(buf2, sizeof(buf2), " STOP %.3LqHz", get_sweep_frequency(ST_STOP)); } else if (FREQ_IS_CENTERSPAN()) { - plot_printf(buf1, sizeof(buf1), " CENTER %.3qHz %5.1qHz/", get_sweep_frequency(ST_CENTER), grid_span); - plot_printf(buf2, sizeof(buf2), " SPAN %.3qHz", get_sweep_frequency(ST_SPAN)); + plot_printf(buf1, sizeof(buf1), " CENTER %.3LqHz %5.1LqHz/", get_sweep_frequency(ST_CENTER), grid_span); + plot_printf(buf2, sizeof(buf2), " SPAN %.3LqHz", get_sweep_frequency(ST_SPAN)); } #ifdef __VNA__ } else { diff --git a/sa_cmd.c b/sa_cmd.c index e4c2020..814a522 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -302,8 +302,8 @@ VNA_SHELL_FUNCTION(cmd_if) shell_printf("usage: if {433M..435M}\r\n%qHz\r\n", setting.frequency_IF); return; } else { - uint32_t a = (uint32_t)my_atoi(argv[0]); - if (a!= 0 &&( a < (DEFAULT_IF - (uint32_t)2000000) || a>(DEFAULT_IF + (uint32_t)2000000))) + freq_t a = (freq_t)my_atoi(argv[0]); + if (a!= 0 &&( a < (DEFAULT_IF - (freq_t)2000000) || a>(DEFAULT_IF + (freq_t)2000000))) goto usage; setting.auto_IF = false; set_IF(a); @@ -316,7 +316,7 @@ VNA_SHELL_FUNCTION(cmd_ultra_start) shell_printf("usage: ultra_start {0..4290M}\r\n%qHz\r\n", config.ultra_threshold); return; } else { - uint32_t a = (uint32_t)my_atoi(argv[0]); + freq_t a = (freq_t)my_atoi(argv[0]); config.ultra_threshold = a; config_save(); } @@ -330,8 +330,8 @@ VNA_SHELL_FUNCTION(cmd_if1) shell_printf("usage: if1 {975M..979M}\r\n%qHz\r\n", config.frequency_IF1); return; } else { - uint32_t a = (uint32_t)my_atoi(argv[0]); - if (a!= 0 &&( a < (DEFAULT_IF - (uint32_t)80000000) || a>(DEFAULT_IF + (uint32_t)80000000))) + freq_t a = (freq_t)my_atoi(argv[0]); + if (a!= 0 &&( a < (DEFAULT_IF - (freq_t)80000000) || a>(DEFAULT_IF + (freq_t)80000000))) goto usage; config.frequency_IF1 = a; config_save(); @@ -520,7 +520,7 @@ int rvalue; VNA_SHELL_FUNCTION(cmd_o) { (void) argc; - uint32_t value = my_atoi(argv[0]); + freq_t value = my_atoi(argv[0]); if (VFO == 0) setting.frequency_IF = value; set_freq(VFO, value); @@ -578,7 +578,7 @@ VNA_SHELL_FUNCTION(cmd_a) shell_printf("a=%u\r\n", frequencyStart); return; } - uint32_t value = my_atoui(argv[0]); + freq_t value = my_atoui(argv[0]); frequencyStart = value; } @@ -590,7 +590,7 @@ VNA_SHELL_FUNCTION(cmd_b) shell_printf("b=%u\r\n", frequencyStop); return; } - uint32_t value = my_atoui(argv[0]); + freq_t value = my_atoui(argv[0]); frequencyStop = value; } @@ -631,11 +631,11 @@ void sweep_remote(void) { uint32_t i; uint32_t step = (points - 1); - uint32_t span = frequencyStop - frequencyStart; - uint32_t delta = span / step; - uint32_t error = span % step; - uint32_t f = frequencyStart - setting.frequency_IF, df = step>>1; - uint32_t old_step = setting.frequency_step; + freq_t span = frequencyStop - frequencyStart; + freq_t delta = span / step; + freq_t error = span % step; + freq_t f = frequencyStart - setting.frequency_IF, df = step>>1; + freq_t old_step = setting.frequency_step; setting.frequency_step = delta; streamPut(shell_stream, '{'); dirty = true; @@ -736,7 +736,7 @@ VNA_SHELL_FUNCTION(cmd_correction) return; } int i = my_atoi(argv[0]); - uint32_t f = my_atoui(argv[1]); + freq_t f = my_atoui(argv[1]); float v = my_atof(argv[2]); config.correction_frequency[i] = f; config.correction_value[i] = v; @@ -746,7 +746,7 @@ VNA_SHELL_FUNCTION(cmd_correction) VNA_SHELL_FUNCTION(cmd_scanraw) { - uint32_t start, stop; + freq_t start, stop; uint32_t points = sweep_points; if (argc < 2 || argc > 3) { shell_printf("usage: scanraw {start(Hz)} {stop(Hz)} [points]\r\n"); @@ -766,12 +766,13 @@ VNA_SHELL_FUNCTION(cmd_scanraw) // if (get_waterfall()) // disable_waterfall(); // display dma hangs when waterfall is enabled - uint32_t old_step = setting.frequency_step; + freq_t old_step = setting.frequency_step; float f_step = (stop-start)/ points; - setting.frequency_step = (uint32_t)f_step; + setting.frequency_step = (freq_t)f_step; streamPut(shell_stream, '{'); - static uint32_t old_start=0, old_stop=0, old_points=0; + static freq_t old_start=0, old_stop=0; + static uint32_t old_points=0; if (old_start != start || old_stop != stop || old_points != points) { // To prevent dirty for every sweep dirty = true; old_start = start; @@ -782,7 +783,7 @@ VNA_SHELL_FUNCTION(cmd_scanraw) dirty = true; for (uint32_t i = 0; i 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 diff --git a/si4432.c b/si4432.c index 85b5c55..05c1f63 100644 --- a/si4432.c +++ b/si4432.c @@ -446,7 +446,7 @@ static int old_freq_band[2] = {-1,-1}; static int written[2]= {0,0}; #endif -void SI4432_Set_Frequency ( uint32_t Freq ) { +void SI4432_Set_Frequency ( freq_t Freq ) { // int mode = SI4432_Read_Byte(0x02) & 0x03; // Disabled as unreliable // SI4432_Write_Byte(0x07, 0x02); // Switch to tune mode @@ -943,7 +943,7 @@ extern int settingAttenuate; //#define LEVEL(i, f, v) (v * (1-(fabs(f - frequencies[i])/actual_rbw/1000))) -float LEVEL(uint32_t i, uint32_t f, int v) +float LEVEL(uint32_t i, freq_t f, int v) { float dv; float df = fabs((float)f - (float)i); @@ -1111,7 +1111,7 @@ void ADF4351_enable_output(void) } #endif -static uint32_t prev_actual_freq = 0; +static freq_t prev_actual_freq = 0; void ADF4351_force_refresh(void) { prev_actual_freq = 0; @@ -1368,7 +1368,7 @@ int SI4463_offset_value = 0; static int SI4463_band = -1; static int64_t SI4463_outdiv = -1; -//static uint32_t SI4463_prev_freq = 0; +//static freq_t SI4463_prev_freq = 0; //static float SI4463_step_size = 100; // Will be recalculated once used static uint8_t SI4463_channel = 0; static uint8_t SI4463_in_tx_mode = false; @@ -2406,7 +2406,7 @@ uint16_t set_rbw(uint16_t WISH) { static int refresh_count = 0; -uint32_t SI4463_set_freq(uint32_t freq) +freq_t SI4463_set_freq(freq_t freq) { // SI4463_set_gpio(3,GPIO_HIGH); int S = 4 ; // Approx 100 Hz channels @@ -2440,7 +2440,7 @@ uint32_t SI4463_set_freq(uint32_t freq) int32_t R = (freq * SI4463_outdiv) / (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz) - 1; // R between 0x00 and 0x7f (127) int64_t MOD = 524288; // = 2^19 int32_t F = ((freq * SI4463_outdiv*MOD) / (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz)) - R*MOD; - uint32_t actual_freq = (R*MOD + F) * (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz)/ SI4463_outdiv/MOD; + freq_t actual_freq = (R*MOD + F) * (Npresc ? 2*config.setting_frequency_30mhz : 4*config.setting_frequency_30mhz)/ SI4463_outdiv/MOD; int delta = freq - actual_freq; if (delta < -100 || delta > 100 ){ while(1) diff --git a/ui.c b/ui.c index 2768698..ef6b254 100644 --- a/ui.c +++ b/ui.c @@ -820,7 +820,7 @@ menu_stimulus_cb(int item, uint8_t data) } #endif -static uint32_t +static freq_t get_marker_frequency(int marker) { if (marker < 0 || marker >= MARKERS_MAX) @@ -833,7 +833,7 @@ get_marker_frequency(int marker) static UI_FUNCTION_CALLBACK(menu_marker_op_cb) { (void)item; - uint32_t freq = get_marker_frequency(active_marker); + freq_t freq = get_marker_frequency(active_marker); if (freq == 0) return; // no active marker @@ -851,12 +851,12 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb) { if (previous_marker == -1 || active_marker == previous_marker) { // if only 1 marker is active, keep center freq and make span the marker comes to the edge - uint32_t center = get_sweep_frequency(ST_CENTER); - uint32_t span = center > freq ? center - freq : freq - center; + freq_t center = get_sweep_frequency(ST_CENTER); + freq_t span = center > freq ? center - freq : freq - center; set_sweep_frequency(ST_SPAN, span * 2); } else { // if 2 or more marker active, set start and stop freq to each marker - uint32_t freq2 = get_marker_frequency(previous_marker); + freq_t freq2 = get_marker_frequency(previous_marker); if (freq2 == 0) return; if (freq > freq2) { @@ -1943,17 +1943,17 @@ void set_keypad_value(int v) set_numeric_value(); } -void check_frequency_slider(uint32_t slider_freq) +void check_frequency_slider(freq_t slider_freq) { - if ( (maxFreq - minFreq) < (uint32_t)setting.slider_span ) { + if ( (maxFreq - minFreq) < (freq_t)setting.slider_span ) { setting.slider_span = maxFreq - minFreq; // absolute mode with max step size } - uint32_t half_span = setting.slider_span >> 1; - if (minFreq + (uint32_t)half_span > slider_freq) { + freq_t half_span = setting.slider_span >> 1; + if (minFreq + (freq_t)half_span > slider_freq) { setting.slider_position -= (minFreq + half_span - slider_freq) / (setting.slider_span / (MENU_FORM_WIDTH-8)); // reposition if needed } - if (maxFreq < slider_freq + (uint32_t)half_span) { + if (maxFreq < slider_freq + (freq_t)half_span) { setting.slider_position += (slider_freq + half_span - maxFreq) / (setting.slider_span /(MENU_FORM_WIDTH-8)); // reposition if needed } } @@ -2009,12 +2009,12 @@ menu_select_touch(int i, int pos) setting.slider_position = new_slider; set_keypad_value(keypad); dirty = false; - perform(false, 0, (uint32_t)uistat.value, false); + perform(false, 0, (freq_t)uistat.value, false); draw_menu(); } else if (mode == SL_SPAN ){ - uint32_t slider_freq; + freq_t slider_freq; first_span: - slider_freq = (uint32_t) uistat.value; + slider_freq = (freq_t) uistat.value; int pw=new_slider + LCD_WIDTH/2; setting.slider_position = pw - LCD_WIDTH/2; // Show delta on slider setting.slider_span = 10; @@ -2030,9 +2030,9 @@ menu_select_touch(int i, int pos) setting.slider_span *= 2; pw -= 12; } - if ((uint32_t)setting.slider_span > (maxFreq - minFreq)) + if ((freq_t)setting.slider_span > (maxFreq - minFreq)) setting.slider_span = (maxFreq - minFreq); - uint32_t old_minFreq = minFreq; // Save when in high mode + freq_t old_minFreq = minFreq; // Save when in high mode minFreq = 0; // And set minFreq to 0 for span display uistat.value = setting.slider_span; set_keypad_value(keypad); @@ -2403,11 +2403,11 @@ lever_search_marker(int status) // ex. 10942 -> 10000 // 6791 -> 5000 // 341 -> 200 -static uint32_t -step_round(uint32_t v) +static freq_t +step_round(freq_t v) { // decade step - uint32_t x = 1; + freq_t x = 1; for (x = 1; x*10 <= v; x*= 10) ; @@ -2423,9 +2423,9 @@ step_round(uint32_t v) static void lever_zoom_span(int status) { - uint32_t span = get_sweep_frequency(ST_SPAN); + freq_t span = get_sweep_frequency(ST_SPAN); if (uistat.auto_center_marker) { - uint32_t freq = get_marker_frequency(active_marker); + freq_t freq = get_marker_frequency(active_marker); search_maximum(active_marker, freq, 10 ); if (freq != 0) set_sweep_frequency(ST_CENTER, freq); @@ -2457,8 +2457,8 @@ lever_zoom_time(int status) static void lever_move(int status, int mode) { - uint32_t center = get_sweep_frequency(mode); - uint32_t span = get_sweep_frequency(ST_SPAN); + freq_t center = get_sweep_frequency(mode); + freq_t span = get_sweep_frequency(ST_SPAN); span = step_round(span / 3); if (status & EVT_UP) { set_sweep_frequency(mode, center + span); diff --git a/ui_sa.c b/ui_sa.c index 2d36ea2..d429c9e 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -988,7 +988,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) markers[i].enabled = M_ENABLED; markers[i].mtype = M_DELTA;// | M_TRACKING; } - uint32_t center, span; + freq_t center, span; markers[0].mtype = M_REFERENCE;// | M_TRACKING; kp_help_text = "Frequency of signal"; ui_mode_keypad(KM_CENTER); @@ -2327,7 +2327,7 @@ static void fetch_numeric_target(void) } { - uint32_t x = uistat.value; + freq_t x = uistat.value; int n = 0; for (; x >= 10 && n < 9; n++) x /= 10; @@ -2341,20 +2341,20 @@ set_numeric_value(void) { switch (keypad_mode) { case KM_START: - set_sweep_frequency(ST_START, (uint32_t)uistat.value); + set_sweep_frequency(ST_START, (freq_t)uistat.value); break; case KM_STOP: - set_sweep_frequency(ST_STOP, (uint32_t)uistat.value); + set_sweep_frequency(ST_STOP, (freq_t)uistat.value); break; case KM_CENTER: - set_sweep_frequency(ST_CENTER, (uint32_t)uistat.value); + set_sweep_frequency(ST_CENTER, (freq_t)uistat.value); break; case KM_SPAN: setting.modulation = MO_NONE; - set_sweep_frequency(ST_SPAN, (uint32_t)uistat.value); + set_sweep_frequency(ST_SPAN, (freq_t)uistat.value); break; case KM_CW: - set_sweep_frequency(ST_CW, (uint32_t)uistat.value); + set_sweep_frequency(ST_CW, (freq_t)uistat.value); break; case KM_SCALE: user_set_scale(uistat.value); @@ -2451,7 +2451,7 @@ set_numeric_value(void) set_gridlines(uistat.value); break; case KM_MARKER: - set_marker_frequency(active_marker, (uint32_t)uistat.value); + set_marker_frequency(active_marker, (freq_t)uistat.value); break; case KM_MODULATION: set_modulation_frequency((int)uistat.value);