From a5646ff6b17758c507d4f5713be6c0e61915b129 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 7 Jul 2020 10:14:03 +0200 Subject: [PATCH] Hidden HW refresh and wide offset scanning --- sa_core.c | 35 ++++++++++++++++++++++++++++------- si4432.c | 16 ++++++++-------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/sa_core.c b/sa_core.c index 06eccfa..933a3c4 100644 --- a/sa_core.c +++ b/sa_core.c @@ -919,6 +919,8 @@ void setupSA(void) extern int SI4432_frequency_changed; extern int SI4432_offset_changed; +//#define __WIDE_OFFSET__ + void set_freq(int V, unsigned long freq) // translate the requested frequency into a setting of the SI4432 { if (old_freq[V] != freq) { // Do not change HW if not needed @@ -930,11 +932,11 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency } #if 1 if (setting.step_delay_mode == SD_FAST) { // If in extra fast scanning mode - int delta = freq - real_old_freq[V]; + int delta = ((int32_t)freq) - (int32_t)real_old_freq[V]; // subtracting uint can't create a negative number if (real_old_freq[V] >= 480000000) // 480MHz, high band delta = delta >> 1; - if (delta > 0 && delta < 80000) { // and requested frequency can be reached by using the offset registers + if (delta > -80000 && delta < 80000) { // 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]); @@ -950,16 +952,29 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency } } #endif +#ifdef __WIDE_OFFSET__ + if (freq >= 480000000) { + SI4432_Set_Frequency(freq + 160000 ); // Impossible to use offset so set SI4432 to new frequency + SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to most negative + SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0x02); + real_old_freq[V] = freq + 160000; + } else { + SI4432_Set_Frequency(freq + 80000 ); // Impossible to use offset so set SI4432 to new frequency + SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to most negative + SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0x02); + real_old_freq[V] = freq + 80000; + } +#else SI4432_Set_Frequency(freq); // Impossible to use offset so set SI4432 to new frequency SI4432_Write_Byte(SI4432_FREQ_OFFSET1, 0); // set offset to zero SI4432_Write_Byte(SI4432_FREQ_OFFSET2, 0); +#endif #ifdef __ULTRA_SA__ } else { ADF4351_set_frequency(V-2,freq,3); #endif } old_freq[V] = freq; - real_old_freq[V] = freq; } } @@ -1661,14 +1676,18 @@ static bool sweep(bool break_on_operation) // shell_printf("\r\n"); modulation_counter = 0; // init modulation counter in case needed - - if (sweep_counter > 5000 && setting.average == AV_OFF && setting.frequency_step > 0) // refresh HW after 5000 sweeps - dirty = true; + int refreshing = false; if (dirty) // Calculate new scanning solution sweep_counter = 0; - else + else if ( MODE_INPUT(setting.mode) && setting.frequency_step > 0) { sweep_counter++; + if (sweep_counter > 50 ) { // refresh HW after 50 sweeps + dirty = true; + refreshing = true; + sweep_counter = 0; + } + } again: // Waiting for a trigger jumps back to here setting.measure_sweep_time_us = 0; // start measure sweep time @@ -1682,6 +1701,8 @@ sweep_again: // stay in sweep loop when output mo RSSI = perform(break_on_operation, i, frequencies[i], setting.tracking); // Measure RSSI for one of the frequencies // if break back to top level to handle ui operation + if (refreshing) + scandirty = false; if (break_on_operation && operation_requested) { // break loop if needed if (setting.actual_sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) { ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, WIDTH, 1, 0); // Erase progress bar diff --git a/si4432.c b/si4432.c index dc71229..c7e5893 100644 --- a/si4432.c +++ b/si4432.c @@ -188,7 +188,7 @@ void SI4432_Reset(void) SI4432_Read_Byte (SI4432_INT_STATUS2); // always perform a system reset (don't send 0x87) SI4432_Write_Byte(SI4432_STATE, 0x80); - chThdSleepMilliseconds(50); + chThdSleepMilliseconds(10); // wait for chiprdy bit while (count++ < 100 && ( SI4432_Read_Byte (SI4432_INT_STATUS2) & 0x02 ) == 0) { chThdSleepMilliseconds(10); @@ -206,11 +206,11 @@ void SI4432_Transmit(int d) SI4432_Write_Byte(SI4432_TX_POWER, (byte) (0x18+(d & 7))); if (( SI4432_Read_Byte(SI4432_DEV_STATUS) & 0x03 ) == 2) return; // Already in transmit mode - chThdSleepMilliseconds(20); + chThdSleepMilliseconds(3); SI4432_Write_Byte(SI4432_STATE, 0x02); - chThdSleepMilliseconds(20); + chThdSleepMilliseconds(3); SI4432_Write_Byte(SI4432_STATE, 0x0b); - chThdSleepMilliseconds(100); + chThdSleepMilliseconds(10); while (count++ < 100 && ( SI4432_Read_Byte(SI4432_DEV_STATUS) & 0x03 ) != 2) { chThdSleepMilliseconds(10); } @@ -221,11 +221,11 @@ void SI4432_Receive(void) int count = 0; if (( SI4432_Read_Byte (SI4432_DEV_STATUS) & 0x03 ) == 1) return; // Already in receive mode - chThdSleepMilliseconds(20); + chThdSleepMilliseconds(3); SI4432_Write_Byte(SI4432_STATE, 0x02); - chThdSleepMilliseconds(20); + chThdSleepMilliseconds(3); SI4432_Write_Byte(SI4432_STATE, 0x07); - chThdSleepMilliseconds(100); + chThdSleepMilliseconds(10); while (count++ < 100 && ( SI4432_Read_Byte(SI4432_DEV_STATUS) & 0x03 ) != 1) { chThdSleepMilliseconds(5); } @@ -602,7 +602,7 @@ void SI4432_Init() SPI2_SDI_LOW; // will be set with any data out palClearPad(GPIOB, GPIO_RF_PWR); // Drop power - chThdSleepMilliseconds(20); // Wait + chThdSleepMilliseconds(10); // Wait palSetPad(GPIOB, GPIO_RF_PWR); // Restore power CS_SI0_HIGH; // And set chip select lines back to inactive CS_SI1_HIGH;