From ea384b4313f70bb75824521b0050a4af34172d0d Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 30 Nov 2020 13:11:07 +0100 Subject: [PATCH] Reduce warnings --- nanovna.h | 14 +++++++++---- sa_cmd.c | 6 +++--- sa_core.c | 30 +++++++++++++++------------ si4432.c | 62 ++++++++++++++++++++++++++++++++----------------------- 4 files changed, 66 insertions(+), 46 deletions(-) diff --git a/nanovna.h b/nanovna.h index 8903fd4..3a5e1d2 100644 --- a/nanovna.h +++ b/nanovna.h @@ -58,9 +58,9 @@ #define HIGH_MAX_FREQ_MHZ 960 #endif #ifdef TINYSA4 -#define DEFAULT_IF 978000000 -#define DEFAULT_SPUR_IF 979000000 -#define DEFAULT_MAX_FREQ 800000000 +#define DEFAULT_IF ((uint32_t)978000000) +#define DEFAULT_SPUR_IF ((uint32_t)979000000) +#define DEFAULT_MAX_FREQ ((uint32_t)800000000) #define HIGH_MIN_FREQ_MHZ 850 #define HIGH_MAX_FREQ_MHZ 1150 #endif @@ -1085,11 +1085,17 @@ enum { // -------------------- Si4432.c --------------- + +void set_calibration_freq(int ref); +uint16_t set_rbw(uint16_t WISH); +uint16_t force_rbw(int f); + #ifdef __SI4463__ extern int SI4463_R; -void Si4463_set_refer(int ref); +void SI4463_set_freq(uint32_t freq); void SI446x_set_AGC_LNA(uint8_t v); void SI4463_set_gpio(int i, int s); +void SI4463_set_output_level(int t); #define GPIO_HIGH 3 #define GPIO_LOW 2 void SI4463_start_tx(uint8_t CHANNEL); diff --git a/sa_cmd.c b/sa_cmd.c index ca93428..2a4afa7 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -272,8 +272,8 @@ VNA_SHELL_FUNCTION(cmd_if) shell_printf("usage: if {433M..435M}\r\n"); return; } else { - int a = my_atoi(argv[0]); - if (a!= 0 &&( a < (DEFAULT_IF - 2000000) || a>(DEFAULT_IF + 2000000))) + uint32_t a = (uint32_t)my_atoi(argv[0]); + if (a!= 0 &&( a < (DEFAULT_IF - (uint32_t)2000000) || a>(DEFAULT_IF + (uint32_t)2000000))) goto usage; setting.auto_IF = false; set_IF(a); @@ -325,13 +325,13 @@ VNA_SHELL_FUNCTION(cmd_v) VNA_SHELL_FUNCTION(cmd_y) { int rvalue; - int lvalue = 0; if (argc != 1 && argc != 2) { shell_printf("usage: y {addr(0-95)} [value(0-0xFF)]\r\n"); return; } rvalue = my_atoui(argv[0]); #ifdef __SI4432__ + int lvalue = 0; SI4432_Sel = VFO; if (argc == 2){ lvalue = my_atoui(argv[1]); diff --git a/sa_core.c b/sa_core.c index 28ddcb1..f864c28 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1756,8 +1756,8 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) modulation_delay += config.cor_nfm; // -17 default // modulation_index = 0; // default value } - if ((setting.mode == M_GENLOW && f > 480000000 - DEFAULT_IF) || - (setting.mode == M_GENHIGH && f > 480000000) ) + if ((setting.mode == M_GENLOW && f > ((uint32_t)480000000) - DEFAULT_IF) || + (setting.mode == M_GENHIGH && f > ((uint32_t)480000000) ) ) modulation_index += 2; current_fm_modulation = (int *)fm_modulation[modulation_index]; f -= fm_modulation_offset[modulation_index]; // Shift output frequency @@ -1815,13 +1815,14 @@ modulation_again: 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 - int32_t local_IF; + uint32_t local_IF; again: // Spur reduction jumps to here for second measurement - if (MODE_HIGH(setting.mode)) + local_IF=0; // to get rid of warning + if (MODE_HIGH(setting.mode)) { local_IF = 0; - else if (MODE_LOW(setting.mode)){ // All low mode + } else if (MODE_LOW(setting.mode)){ // All low mode if (!setting.auto_IF) { local_IF = setting.frequency_IF; } @@ -1897,7 +1898,7 @@ modulation_again: if (setting.mode == M_LOW && !setting.tracking && S_STATE(setting.below_IF)) // if in low input mode and below IF target_f = local_IF-lf; // set LO SI4432 to below IF frequency else - target_f = local_IF+lf; // otherwise to above IF + target_f = local_IF+lf; // otherwise to above IF, local_IF == 0 in high mode #ifdef __SI4432__ set_freq (SI4432_LO, target_f); // otherwise to above IF #endif @@ -1918,7 +1919,7 @@ modulation_again: ADF4351_R_counter(1); } #endif - +#if 0 uint32_t target_f; if (!setting.tracking && S_STATE(setting.below_IF)) { // if in low input mode and below IF if (lf > local_IF + 138000000) @@ -1927,6 +1928,7 @@ modulation_again: target_f = local_IF-lf; // set LO SI4432 to below IF frequency } else target_f = local_IF+lf; // otherwise to above IF +#endif set_freq(ADF4351_LO, target_f); #if 1 // Compensate frequency ADF4350 error with SI4468 int32_t error_f = 0; @@ -1941,9 +1943,7 @@ modulation_again: local_IF += error_f; } #endif - if (!tracking) - set_freq (SI4463_RX, local_IF); // compensate ADF error with SI446x when not in tracking mode - } else if (setting.mode == M_HIGH || setting.mode == M_GENHIGH) { + } else if (MODE_HIGH(setting.mode)) { set_freq (SI4463_RX, lf); // sweep RX, local_IF = 0 in high mode } // STOP_PROFILE; @@ -1952,10 +1952,13 @@ modulation_again: // ----------- Set IF ------------------ - if (local_IF != 0) + if (local_IF != 0) // When not in one of the high modes { #ifdef __SI4432__ set_freq (SI4432_RX , local_IF); +#endif +#ifdef __SI4463__ + set_freq (SI4463_RX, local_IF); // including compensating ADF error with SI446x when not in tracking mode #endif } @@ -2095,13 +2098,14 @@ static bool sweep(bool break_on_operation) { float RSSI; int16_t downslope; +#ifdef __SI4432__ uint32_t agc_peak_freq = 0; float agc_peak_rssi = -150; float agc_prev_rssi = -150; int last_AGC_value = 0; uint8_t last_AGC_direction_up = false; int AGC_flip_count = 0; - +#endif // if (setting.mode== -1) // return; // START_PROFILE; @@ -3683,7 +3687,7 @@ void self_test(int test) setting.frequency_step = 30000; if (setting.test_argument > 0) setting.frequency_step=setting.test_argument; - int f = 400000; // Start search at 400kHz + uint32_t f = 400000; // Start search at 400kHz // int i = 0; // Index in spur table (temp_t) set_RBW(setting.frequency_step/100); last_spur = 0; diff --git a/si4432.c b/si4432.c index 9963a9a..1906dd4 100644 --- a/si4432.c +++ b/si4432.c @@ -54,7 +54,7 @@ static uint32_t new_port_moder; #define CS_SI0_HIGH palSetPad(GPIOB, GPIOB_RX_SEL) #define CS_SI1_HIGH palSetPad(GPIOB, GPIOB_LO_SEL) -#define CS_PE_HIGH palSetPad(GPIOA, GPIOA_PE_SEL) +//#define CS_PE_HIGH palSetPad(GPIOA, GPIOA_PE_SEL) #define RF_POWER_HIGH palSetPad(GPIOB, GPIOB_RF_PWR) //#define SPI2_CLK_HIGH palSetPad(GPIOB, GPIO_SPI2_CLK) @@ -62,7 +62,7 @@ static uint32_t new_port_moder; #define CS_SI0_LOW palClearPad(GPIOB, GPIOB_RX_SEL) #define CS_SI1_LOW palClearPad(GPIOB, GPIOB_LO_SEL) -#define CS_PE_LOW palClearPad(GPIOA, GPIOA_PE_SEL) +//#define CS_PE_LOW palClearPad(GPIOA, GPIOA_PE_SEL) #define SPI1_CLK_HIGH palSetPad(GPIOB, GPIOB_SPI_SCLK) #define SPI1_CLK_LOW palClearPad(GPIOB, GPIOB_SPI_SCLK) @@ -1121,6 +1121,13 @@ uint32_t ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // // Serial.println( "MOD/FRAC reduced"); } #endif + uint32_t reduce = gcd(MOD, FRAC); + if (reduce) { + FRAC /= reduce; + MOD /= reduce; + if (MOD == 1) + MOD=2; + } uint32_t actual_freq = PFDR *(INTA * MOD +FRAC)/OutputDivider / MOD; volatile int max_delta = 1000000 * PFDRFout[channel]/OutputDivider/MOD; if (actual_freq < freq - max_delta || actual_freq > freq + max_delta ){ @@ -1174,8 +1181,8 @@ uint32_t ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // int SI4463_frequency_changed = false; static int SI4463_band = -1; static int64_t SI4463_outdiv = -1; -static uint32_t SI4463_prev_freq = 0; -static float SI4463_step_size = 100; // Will be recalculated once used +//static uint32_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; int SI4463_R = 5; @@ -1307,6 +1314,7 @@ void SI4463_do_api(void* data, uint8_t len, void* out, uint8_t outLen) } } +#ifdef notused static void SI4463_set_properties(uint16_t prop, void* values, uint8_t len) { // len must not be greater than 12 @@ -1323,6 +1331,7 @@ static void SI4463_set_properties(uint16_t prop, void* values, uint8_t len) SI4463_do_api(data, len + 4, NULL, 0); } +#endif #include "SI446x_cmd.h" @@ -1332,7 +1341,7 @@ static const uint8_t SI4463_config[] = RADIO_CONFIGURATION_DATA_ARRAY; #endif #ifdef __SI4468__ -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #undef RADIO_CONFIGURATION_DATA_ARRAY #include "radio_config_Si4468_default.h" @@ -1344,6 +1353,7 @@ static const uint8_t SI4463_config[] = RADIO_CONFIGURATION_DATA_ARRAY; //#undef RF_MODEM_AGC_CONTROL_1 //#define RF_MODEM_AGC_CONTROL_1 0x11, 0x20, 0x01, 0x35, 0x92 // Override AGC gain increase +#undef RF_MODEM_AGC_CONTROL_1 #define RF_MODEM_AGC_CONTROL_1 0x11, 0x20, 0x01, 0x35, 0xE0 + 0x10 + 0x08 // slow AGC //#undef RF_MODEM_RSSI_JUMP_THRESH_4 //#define RF_MODEM_RSSI_JUMP_THRESH_4 0x11, 0x20, 0x04, 0x4B, 0x06, 0x09, 0x10, 0x45 // Increase RSSI reported value with 2.5dB @@ -1409,7 +1419,7 @@ void SI4463_set_output_level(int t) } void SI4463_start_tx(uint8_t CHANNEL) { - volatile si446x_state_t s; +// volatile si446x_state_t s; #if 0 s = SI4463_get_state(); if (s == SI446X_STATE_RX){ @@ -1444,7 +1454,7 @@ void SI4463_start_tx(uint8_t CHANNEL) SI4463_do_api(data, sizeof(data), NULL, 0); } #endif - retry: +// retry: { uint8_t data[] = { @@ -1498,7 +1508,7 @@ void SI4463_start_rx(uint8_t CHANNEL) 0,// SI446X_CMD_START_RX_ARG_NEXT_STATE2_RXVALID_STATE_ENUM_RX, 0, //SI446X_CMD_START_RX_ARG_NEXT_STATE3_RXINVALID_STATE_ENUM_RX }; -retry: +//retry: SI4463_do_api(data, sizeof(data), NULL, 0); #if 0 @@ -1518,12 +1528,11 @@ void SI4463_short_start_rx(void) uint8_t data[] = { SI446X_CMD_ID_START_RX, }; -retry: SI4463_do_api(data, sizeof(data), NULL, 0); SI4463_in_tx_mode = false; } -void SI4463_clear_int_status() +void SI4463_clear_int_status(void) { uint8_t data[9] = { SI446X_CMD_ID_GET_INT_STATUS @@ -1584,7 +1593,7 @@ void Si446x_getInfo(si446x_info_t* info) info->patch = (data[3]<<8) | data[4]; info->func = data[5]; } - +#ifdef notused static uint8_t SI4463_get_device_status(void) { uint8_t data[2] = @@ -1594,7 +1603,7 @@ static uint8_t SI4463_get_device_status(void) SI4463_do_api(data, 1, data, SI446X_CMD_REPLY_COUNT_REQUEST_DEVICE_STATE); return(data[0]); } - +#endif // Read a fast response register @@ -1666,7 +1675,7 @@ void set_RSSI_comp(void) int16_t Si446x_RSSI(void) { - volatile uint8_t data[3] = { + uint8_t data[3] = { SI446X_CMD_GET_MODEM_STATUS, 0xFF }; @@ -1737,7 +1746,7 @@ void SI446x_set_AGC_LNA(uint8_t v) } - +#ifdef notused // Do an ADC conversion static uint16_t getADC(uint8_t adc_en, uint8_t adc_cfg, uint8_t part) { @@ -1749,6 +1758,7 @@ static uint16_t getADC(uint8_t adc_en, uint8_t adc_cfg, uint8_t part) SI4463_do_api(data, 3, data, 6); return (data[part]<<8 | data[part + 1]); } +#endif #ifndef __SI4468__ // -------------- 0.2 kHz ---------------------------- @@ -1933,7 +1943,7 @@ uint8_t SI4463_RBW_850kHz[] = #else // -------------- 0.2 kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_200Hz.h" #include "radio_config_Si4468_short.h" @@ -1942,7 +1952,7 @@ static const uint8_t SI4463_RBW_02kHz[] = // -------------- 1kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_1kHz.h" #include "radio_config_Si4468_short.h" @@ -1950,7 +1960,7 @@ static const uint8_t SI4463_RBW_1kHz[] = RADIO_CONFIGURATION_DATA_ARRAY; // -------------- 3 kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_3kHz.h" #include "radio_config_Si4468_short.h" @@ -1958,7 +1968,7 @@ static const uint8_t SI4463_RBW_3kHz[] = RADIO_CONFIGURATION_DATA_ARRAY; // -------------- 10 kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_10kHz.h" #include "radio_config_Si4468_short.h" @@ -1966,7 +1976,7 @@ static const uint8_t SI4463_RBW_10kHz[] = RADIO_CONFIGURATION_DATA_ARRAY; // -------------- 30 kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_30kHz.h" #include "radio_config_Si4468_short.h" @@ -1974,7 +1984,7 @@ static const uint8_t SI4463_RBW_30kHz[] = RADIO_CONFIGURATION_DATA_ARRAY; // -------------- 100kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_100kHz.h" #include "radio_config_Si4468_short.h" @@ -1983,7 +1993,7 @@ static const uint8_t SI4463_RBW_100kHz[] = // -------------- 300kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_300kHz.h" #include "radio_config_Si4468_short.h" @@ -1992,7 +2002,7 @@ static const uint8_t SI4463_RBW_300kHz[] = // -------------- 850kHz ---------------------------- -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_850kHz.h" #include "radio_config_Si4468_short.h" @@ -2005,7 +2015,7 @@ static const uint8_t SI4463_RBW_850kHz[] = // Return the first entry of the following triple for the RBW actually achieved #define IF_BW(dwn3, ndec, filset) (((dwn3)<<7)|((ndec)<<4)|(filset)) typedef struct { - uint8_t *reg; // IF_BW(dwn3, ndec, filset) + const uint8_t *reg; // IF_BW(dwn3, ndec, filset) int16_t RSSI_correction_x_10; // Correction * 10 int16_t RBWx10; // RBW in kHz }RBW_t; // sizeof(RBW_t) = 8 bytes @@ -2034,7 +2044,7 @@ uint16_t force_rbw(int f) if (SI4463_in_tx_mode) return(0); SI4463_set_state(SI446X_STATE_READY); - uint8_t *config = RBW_choices[f].reg; + const uint8_t *config = RBW_choices[f].reg; uint16_t i=0; while(config[i] != 0) { @@ -2204,7 +2214,7 @@ void SI4463_set_freq(uint32_t freq) void SI4463_init_rx(void) { -reset: +// reset: SI_SDN_LOW; my_microsecond_delay(100); SI_SDN_HIGH; @@ -2241,7 +2251,7 @@ again: #if 0 -#undef RADIO_CONFIG_H_ +#include "radio_config_Si4468_undef.h" #include "radio_config_Si4468_tx.h" static const uint8_t SI4463_config_tx[] =