From 1baebddaf16697ea45f8a693b68140fcc682ca1a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 15 Apr 2021 13:36:35 +0200 Subject: [PATCH] Reduced drive level --- halconf.h | 4 ++-- main.c | 34 ++++++++++++++++++++-------------- sa_core.c | 25 +++++++++++++++++++++---- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/halconf.h b/halconf.h index 10bb5f0..5299981 100644 --- a/halconf.h +++ b/halconf.h @@ -136,7 +136,7 @@ * @brief Enables the SERIAL subsystem. */ #if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) -#define HAL_USE_SERIAL TRUE +#define HAL_USE_SERIAL FALSE #endif /** @@ -291,7 +291,7 @@ * default configuration. */ #if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__) -#define SERIAL_DEFAULT_BITRATE 38400 +#define SERIAL_DEFAULT_BITRATE 115200 #endif /** diff --git a/main.c b/main.c index 5af9e1e..0408cac 100644 --- a/main.c +++ b/main.c @@ -2546,6 +2546,22 @@ VNA_SHELL_FUNCTION(cmd_help) /* * VNA shell functions */ +// Check USB connection status +static bool usb_IsActive(void){ + return usbGetDriverStateI(&USBD1) == USB_ACTIVE; +} + +// Check active connection for Shell +static bool shell_check_connect(void){ +#ifdef __USE_SERIAL_CONSOLE__ + // Serial connection always active + if (config._mode & _MODE_SERIAL) + return true; +#endif + // USB connection can be USB_SUSPENDED + return usb_IsActive(); +} + // Check Serial connection requirements #ifdef __USE_SERIAL_CONSOLE__ #if HAL_USE_SERIAL == FALSE @@ -2563,10 +2579,6 @@ void shell_update_speed(void){ sdStart(&SD1, &s_config); // USART config } -// Check USB connection status -static bool usb_IsActive(void){ - return usbGetDriverStateI(&USBD1) == USB_ACTIVE; -} void shell_reset_console(void){ // Reset I/O queue over USB (for USB need also connect/disconnect) if (usb_IsActive()){ @@ -2580,14 +2592,6 @@ void shell_reset_console(void){ iqResetI(&SD1.iqueue); } -// Check active connection for Shell -static bool shell_check_connect(void){ - // Serial connection always active - if (config._mode & _MODE_SERIAL) - return true; - // USB connection can be USB_SUSPENDED - return usb_IsActive(); -} static void shell_init_connection(void){ /* @@ -3018,7 +3022,8 @@ int main(void) while (1) { - if (SDU1.config->usbp->state == USB_ACTIVE) { +// if (SDU1.config->usbp->state == USB_ACTIVE) { + if (shell_check_connect()) { #ifdef VNA_SHELL_THREAD #if CH_CFG_USE_WAITEXIT == FALSE #error "VNA_SHELL_THREAD use chThdWait, need enable CH_CFG_USE_WAITEXIT in chconf.h" @@ -3035,7 +3040,8 @@ int main(void) VNAShell_executeLine(shell_line); else chThdSleepMilliseconds(200); - } while (SDU1.config->usbp->state == USB_ACTIVE); +// } while (SDU1.config->usbp->state == USB_ACTIVE); + } while (shell_check_connect()); #endif } chThdSleepMilliseconds(1000); diff --git a/sa_core.c b/sa_core.c index e9cff81..6194e05 100644 --- a/sa_core.c +++ b/sa_core.c @@ -75,7 +75,7 @@ static freq_t real_old_freq[4] = { 0, 0, 0, 0}; #endif #ifdef TINYSA4 -const float si_drive_dBm [] = {-43, -30.1, -19.5, -15.5, -13, -11, -9.5, -8.1, -6.9, -5.9, -5, -4.2, -3.5, -2.8 , -2.2, -1.7, -1, -0.5, 0}; +const float si_drive_dBm [] = {-43.8, -30.0, -21.8, -17.2, -14.2, -11.9, -10.1, -8.6, -7.3, -6.2, -5.2, -4.3, -3.5, -2.8 , -2.2, -1.5, -1, -0.5, 0}; const float adf_drive_dBm[] = {-15,-12,-9,-6}; const uint8_t drive_register[] = {0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; float *drive_dBm = (float *) adf_drive_dBm; @@ -293,9 +293,12 @@ void reset_settings(int m) setting.step_delay_mode = SD_FAST; #ifdef TINYSA4 setting.extra_lna = false; -#endif setting.correction_frequency = config.correction_frequency[CORRECTION_LOW_OUT]; setting.correction_value = config.correction_value[CORRECTION_LOW_OUT]; +#else + setting.correction_frequency = config.correction_frequency[CORRECTION_LOW]; + setting.correction_value = config.correction_value[CORRECTION_LOW]; +#endif level_min = SL_GENLOW_LEVEL_MIN + LOW_OUT_OFFSET; level_max = SL_GENLOW_LEVEL_MAX + LOW_OUT_OFFSET; level_range = level_max - level_min; @@ -1982,7 +1985,11 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# vbwSteps = 1; // starting number for all modes if (!MODE_INPUT(setting.mode)) { actual_rbw_x10 = 1; // To force substepping of the SI4463 +#ifdef TINYSA4 goto done; +#else + return; +#endif } if (setting.frequency_step > 0 && MODE_INPUT(setting.mode)) { setting.vbw_x10 = (setting.frequency_step)/100; @@ -2047,8 +2054,10 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# } else { // in all other modes setting.vbw_x10 = actual_rbw_x10; } +#ifdef TINYSA4 done: fill_spur_table(); // IF frequency depends on selected RBW +#endif } #ifdef TINYSA4 @@ -2591,7 +2600,9 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / correct_RSSI_freq = get_frequency_correction(f); a += PURE_TO_float(correct_RSSI_freq) + 3.0; // Always 3dB in attenuator if (a != old_a) { +#ifdef TINYSA4 int very_low_flag = false; +#endif old_a = a; a = a - level_max; // convert to all settings maximum power output equals a = zero if (a < -SWITCH_ATTENUATION) { @@ -2617,8 +2628,12 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / #else #define LOWEST_LEVEL MIN_DRIVE #endif - int d = MAX_DRIVE; // Reduce level till it fits in attenuator range - while (a - BELOW_MAX_DRIVE(d) < - 31 && d > LOWEST_LEVEL) { + int d = MAX_DRIVE-8; // Start in the middle + + while (a - BELOW_MAX_DRIVE(d) > 0 && d < MAX_DRIVE) { // Increase if needed + d++; + } + while (a - BELOW_MAX_DRIVE(d) < - 31 && d > LOWEST_LEVEL) { // reduce till it fits attenuator d--; } a -= BELOW_MAX_DRIVE(d); @@ -3356,10 +3371,12 @@ again: // Spur redu } #endif +#ifdef TINYSA4 if (LO_shifting) pureRSSI -= float_TO_PURE_RSSI(config.shift_level_offset); if (LO_harmonic) pureRSSI -= float_TO_PURE_RSSI(config.harmonic_level_offset); +#endif if (RSSI < pureRSSI) // Take max during subscanning RSSI = pureRSSI;