Solve slow startup

save_scan
erikkaashoek 3 years ago
parent 7bce9995cf
commit ae025eba5b

@ -109,6 +109,14 @@ int32_t scan_after_dirty = 0;
uint8_t completed = false;
uint8_t enable_after_complete = 0;
#ifdef TINYSA4
freq_t ULTRA_MAX_FREQ; // Start of harmonic mode
freq_t MAX_LO_FREQ;
freq_t MAX_ABOVE_IF_FREQ; // Range to use for below IF
freq_t MIN_BELOW_IF_FREQ; // Range to use for below IF
int max2871;
#endif
void clear_backup(void) {
uint32_t *f = &backup; // Clear backup when no valid config data
int i = USED_BACKUP_SIZE;
@ -1967,7 +1975,7 @@ typedef struct version_t {
#define MAX_VERSION_TEXT 1
const version_t hw_version_text[MAX_VERSION_TEXT] =
{
{ 160, 169, "V0.4.5.1"}
{ 165, 170, "V0.4.5.1"}
};
const char *get_hw_version_text(void)
@ -2799,6 +2807,7 @@ int main(void)
* Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual.
*/
dac_init();
adc_init();
PULSE
DAC->CR|= DAC_CR_EN1 | DAC_CR_EN2; // Use DAC: CH1 and CH2
#ifdef __LCD_BRIGHTNESS__
@ -2821,6 +2830,7 @@ int main(void)
sd_card_inserted_at_boot = SD_Inserted();
#endif
disk_initialize(0);
SI4463_init_rx(); // Needed bacause calldata recall may change SI4463 parameters
PULSE
// SD_PowerOn();
#endif
@ -2838,7 +2848,23 @@ int main(void)
config.switch_offset = -5.0;
#endif
int reset_state = btn_side();
#ifdef TINYSA4
if (adc1_single_read(0)> 1000)
max2871 = true;
if (max2871) {
MAX_LO_FREQ = 6000000000ULL;
ULTRA_MAX_FREQ = 6950000000ULL; // Start of harmonic mode
MAX_ABOVE_IF_FREQ = 5021000000ULL; // Range to use for below IF
MIN_BELOW_IF_FREQ = 4041000000ULL; // Range to use for below IF
} else {
ULTRA_MAX_FREQ = 5340000000ULL; // Start of harmonic mode
MAX_LO_FREQ = 4350000000ULL;
MAX_ABOVE_IF_FREQ = 3360000000ULL; // Range to use for below IF
MIN_BELOW_IF_FREQ = 2310000000ULL; // Range to use for below IF
}
set_jump_freq( MAX_ABOVE_IF_FREQ, ULTRA_MAX_FREQ);
#endif
if (!reset_state) {
if(config_recall()) {
clear_backup();

@ -18,7 +18,7 @@
*/
#include "ch.h"
//#ifdef TINYSA_F303
#ifdef TINYSA_F303
#ifdef TINYSA_F072
#error "Remove comment for #ifdef TINYSA_F303"
#endif
@ -26,7 +26,7 @@
#define TINYSA4
#endif
#define TINYSA4_PROTO
//#endif
#endif
#ifdef TINYSA_F072
#ifdef TINYSA_F303
@ -152,16 +152,11 @@
#define HIGH_MIN_FREQ_MHZ 136// 825
#define HIGH_MAX_FREQ_MHZ 1130
#define MINIMUM_DIRECT_FREQ 823000000ULL
#define ULTRA_MAX_FREQ 5340000000ULL // Start of harmonic mode
#define DEFAULT_ULTRA_THRESHOLD 700000000ULL
#define ULTRA_AUTO 10000000000ULL // 10GHz
//#define ULTRA_MAX_FREQ 2900000000ULL
#define MAX_LO_FREQ 4350000000ULL
#define MAX_ABOVE_IF_FREQ 3360000000ULL // Range to use for below IF
#define MIN_BELOW_IF_FREQ 2310000000ULL // Range to use for below IF
//#define LOW_MAX_FREQ 800000000ULL
#define MIN_BELOW_LO 550000000ULL // not used????
//#define MIN_BELOW_LO 550000000ULL // not used????
#define DRIVE0_MAX_FREQ 600000000ULL // LO drive 0
#define DRIVE1_MAX_FREQ 1200000000ULL // LO drive 1
#define DRIVE2_MAX_FREQ 2100000000ULL // LO drive 2
@ -238,6 +233,13 @@ typedef uint32_t freq_t;
#define CORRECTION_LOW_OUT_ADF 8
#define CORRECTION_LOW_OUT_MIXER 9
#define CORRECTION_SIZE 10
extern freq_t ULTRA_MAX_FREQ; // Start of harmonic mode
extern freq_t MAX_LO_FREQ;
extern freq_t MAX_ABOVE_IF_FREQ; // Range to use for below IF
extern freq_t MIN_BELOW_IF_FREQ; // Range to use for below IF
extern int max2871;
#endif
typedef float measurement_t[TRACES_MAX][POINTS_COUNT];
extern measurement_t measured;
@ -486,6 +488,7 @@ void toggle_high_out_adf4350(void);
extern int high_out_adf4350;
#endif
int set_actual_freq(freq_t);
void set_jump_freq(freq_t a, freq_t b);
int set_freq_corr(int);
void set_IF2(int f);
void set_R(int f);

@ -121,6 +121,9 @@ void update_grid(void)
fspan = setting.actual_sweep_time_us; // Time in uS
fstart = 0;
}
if (config.gridlines == 0) {
grid = fspan/10;
} else {
if (config.gridlines < 3)
config.gridlines = 6;
while (gdigit > 1) {
@ -135,7 +138,7 @@ void update_grid(void)
break;
gdigit /= 10;
}
}
grid_span = grid;
if (grid > 1000) {
grid_offset = (WIDTH) * ((fstart % grid) / 100) / (fspan / 100);
@ -144,6 +147,8 @@ void update_grid(void)
grid_offset = (WIDTH) * ((fstart % grid)) / (fspan);
grid_width = (WIDTH) * (grid) / (fspan/10);
}
if (config.gridlines == 0)
grid_offset = 0;
if (setting.waterfall)
set_waterfall();
#ifdef __LEVEL_METER__

@ -397,7 +397,6 @@ void set_input_path(freq_t f)
if (signal_path == PATH_HIGH) {
return; // TODO setup high input path
}
enable_extra_lna(setting.extra_lna);
enable_rx_output(setting.atten_step);
switch(signal_path) {
@ -405,12 +404,14 @@ void set_input_path(freq_t f)
enable_ultra(false);
enable_direct(false);
enable_high(false);
enable_extra_lna(setting.extra_lna);
goto common;
case PATH_DIRECT:
enable_ultra(true);
enable_direct(true);
enable_high(true);
enable_extra_lna(setting.extra_lna);
if (setting.tracking_output)
enable_ADF_output(true, true);
else
@ -418,8 +419,14 @@ void set_input_path(freq_t f)
goto common2;
case PATH_ULTRA:
enable_ultra(true);
enable_direct(false);
enable_high(false);
if (max2871) {
enable_direct(setting.extra_lna); // Acts as LNA switch in Ultra mode.
enable_extra_lna(false);
} else {
enable_direct(false);
enable_extra_lna(setting.extra_lna);
}
common:
enable_ADF_output(true, setting.tracking_output);
common2:
@ -832,7 +839,7 @@ void set_noise(int d)
void set_gridlines(int d)
{
if (d < 3 || d > 20)
if (d != 0 && (d < 3 || d > 20))
return;
config.gridlines = d;
config_save();
@ -4951,7 +4958,7 @@ static bool sweep(bool break_on_operation)
sweep_again: // stay in sweep loop when output mode and modulation on.
if (setting.trigger_grid) { // for start of sweep in time grid
if (setting.trigger_grid) { // for start of sweep in time grid // return (systime_t)STM32_ST_TIM->CNT; does CH_CFG_ST_FREQUENCY ticks per second
while ((chVTGetSystemTimeX() % (setting.trigger_grid+2)) == 0);
while ((chVTGetSystemTimeX() % (setting.trigger_grid+2)) != 0);
}
@ -7486,8 +7493,12 @@ const int power_rbw [5] = { 100, 300, 30, 10, 3 };
#ifdef TINYSA4
#define JUMP_FREQS 6
const freq_t jump_freqs[JUMP_FREQS] = {LOW_SHIFT_FREQ, LOW_SHIFT_FREQ, DRIVE1_MAX_FREQ, DRIVE2_MAX_FREQ, MAX_ABOVE_IF_FREQ, ULTRA_MAX_FREQ };
freq_t jump_freqs[JUMP_FREQS] = {LOW_SHIFT_FREQ, LOW_SHIFT_FREQ, DRIVE1_MAX_FREQ, DRIVE2_MAX_FREQ, 0, 0};
void set_jump_freq(freq_t a, freq_t b) {
jump_freqs[4] = a;
jump_freqs[5] = b;
}
void set_jump_config(int i, float v) {
switch (i) {

@ -336,7 +336,7 @@ void ADF4351_Setup(void)
ADF4351_set_frequency(0,200000000);
ADF4351_mux(2); // No led
ADF4351_mux(0); // Tristate
// ADF4351_mux(6); // Show lock on led
}
@ -541,11 +541,56 @@ static uint32_t gcd(uint32_t x, uint32_t y)
#endif
uint64_t ADF4351_prepare_frequency(int channel, uint64_t freq) // freq / 10Hz
{
uint32_t output_divider;
target_freq = freq;
if (freq >= 2200000000) {
if (max2871) {
if (freq >= 3000000000) {
output_divider = 1 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 0); // 0
bitWrite (registers[4], 21, 0);
bitWrite (registers[4], 20, 0);
} else if (freq >= 1500000000) {
output_divider = 2 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 0); // 1
bitWrite (registers[4], 21, 0);
bitWrite (registers[4], 20, 1);
} else if (freq >= 750000000) {
output_divider = 4 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 0); // 2
bitWrite (registers[4], 21, 1);
bitWrite (registers[4], 20, 0);
} else if (freq >= 375000000) {
output_divider = 8 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 0); // 3
bitWrite (registers[4], 21, 1);
bitWrite (registers[4], 20, 1);
} else if (freq >= 187500000) {
output_divider = 16 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 1); // 4
bitWrite (registers[4], 21, 0);
bitWrite (registers[4], 20, 0);
} else if (freq >= 137500000) {
output_divider = 32 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 1); // 5
bitWrite (registers[4], 21, 0);
bitWrite (registers[4], 20, 1);
} else if (freq >= 68750000) {
output_divider = 64 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 1); // 6
bitWrite (registers[4], 21, 1);
bitWrite (registers[4], 20, 0);
} else { // > 34375000
output_divider = 128 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 1); // 7
bitWrite (registers[4], 21, 1);
bitWrite (registers[4], 20, 1);
}
} else {
if (freq >= 2200000000) {
output_divider = 1 * FREQ_MULTIPLIER;
bitWrite (registers[4], 22, 0);
bitWrite (registers[4], 21, 0);
@ -571,7 +616,7 @@ uint64_t ADF4351_prepare_frequency(int channel, uint64_t freq) // freq / 10Hz
bitWrite (registers[4], 21, 0);
bitWrite (registers[4], 20, 0);
}
}
uint32_t PFDR = (uint32_t)PFDRFout[channel];
uint32_t MOD = ADF4350_modulo;
if (MOD == 0)
@ -690,7 +735,7 @@ static si446x_state_t SI4463_get_state(void);
static int SI4463_set_state(si446x_state_t);
#define SI4463_READ_CTS (palReadLine(LINE_RX_CTS))
#define SI4463_CTS_TIMEOUT 10000000
#define SI4463_CTS_TIMEOUT 1000000
#ifdef __WAIT_CTS_WHILE_SLEEPING__
extern volatile int sleep;
#if 0

30
ui.c

@ -4525,7 +4525,7 @@ static const menuitem_t menu_settings4[] =
static const menuitem_t menu_settings3[] =
{
#ifdef TINYSA4
// { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"},
// { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions, 0 is always 10"},
#ifndef __NEW_SWITCHES__
{ MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb},
#endif
@ -4737,7 +4737,7 @@ static const menuitem_t menu_config2[] =
#ifdef __ULTRA__
{ MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb},
#endif
{ MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"},
{ MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions, 0 is always 10"},
{ MT_KEYPAD, KM_VAR, "JOG STEP\n\b%s","0 = AUTO"},
{ MT_CALLBACK, 0 , "CLEAR\nCONFIG", menu_clearconfig_cb},
#ifdef __USE_SERIAL_CONSOLE__
@ -4921,11 +4921,13 @@ static const menuitem_t menu_storage[] = {
#ifdef __SD_FILE_BROWSER__
{ MT_CALLBACK, FMT_BMP_FILE, "LOAD\nCAPTURE", menu_sdcard_browse_cb },
{ MT_CALLBACK, FMT_PRS_FILE, "LOAD\nSETTINGS", menu_sdcard_browse_cb },
{ MT_CALLBACK, FMT_CMD_FILE, "LOAD CMD", menu_sdcard_browse_cb },
{ MT_CALLBACK, FMT_CMD_FILE, "LOAD\nCMD", menu_sdcard_browse_cb },
{ MT_CALLBACK, FMT_CFG_FILE, "LOAD\nCONFIG", menu_sdcard_browse_cb },
#endif
{ MT_ADV_CALLBACK, 0, "AUTO NAME", menu_autoname_acb },
{ MT_CALLBACK, FMT_BMP_FILE, "SAVE\nCAPTURE", menu_sdcard_cb},
{ MT_CALLBACK, FMT_PRS_FILE, "SAVE\nSETTINGS", menu_sdcard_cb},
{ MT_CALLBACK, FMT_CFG_FILE, "SAVE\nCONFIG", menu_sdcard_cb},
{ MT_CALLBACK, FMT_CSV_FILE, "SAVE\nTRACES", menu_save_traces_cb},
{ MT_NONE, 0, NULL, menu_back} // next-> menu_back
};
@ -5206,7 +5208,7 @@ static void fetch_numeric_target(uint8_t mode)
plot_printf(uistat.text, sizeof uistat.text, format, uistat.value,unit_string[setting.unit]);
break;
case KM_TRIGGER_GRID:
uistat.value = ((float)ST2US(setting.trigger_grid))/1000000.0;
uistat.value = setting.trigger_grid / CH_CFG_ST_FREQUENCY; // ((float)ST2US(setting.trigger_grid))/1000000.0;
plot_printf(uistat.text, sizeof uistat.text, "%.3F", uistat.value);
break;
@ -5439,7 +5441,7 @@ set_numeric_value(void)
completed = true;
break;
case KM_TRIGGER_GRID:
setting.trigger_grid = US2ST(uistat.value*1000000.0) ;
setting.trigger_grid = (uistat.value + 0.5/(float)CH_CFG_ST_FREQUENCY)* CH_CFG_ST_FREQUENCY; // US2ST(uistat.value*1000000.0) ;
completed = true;
break;
case KM_GRIDLINES:
@ -7436,6 +7438,23 @@ static void sa_save_file(uint8_t format) {
res = f_write(fs_file, src, total, &size);
}
break;
/*
* Dump preset to SD card as prs file
*/
case FMT_CFG_FILE:
{
uint16_t *src = (uint16_t*)&config;
int total = sizeof(config_t);
config.magic = CONFIG_MAGIC;
config.checksum = 0x12345678;
config.checksum = checksum(
&config,
// (sizeof (config)) - sizeof setting.config
(void *)&config.checksum - (void *) &config
);
res = f_write(fs_file, src, total, &size);
}
break;
}
f_close(fs_file);
// shell_printf("Close = %d\r\n", res);
@ -7681,7 +7700,6 @@ handle_touch_interrupt(void)
void
ui_init()
{
adc_init();
// Activates the EXT driver 1.
extStart(&EXTD1, &extcfg);
// Init touch subsystem

@ -305,6 +305,23 @@ finish:
else error = "Format err";
}
break;
/*
* Load preset
*/
case FMT_CFG_FILE:
{
uint32_t magic;
char *src = (char*)&config + sizeof(magic);
uint32_t total = sizeof(config_t) - sizeof(magic);
// Compare file size and try read magic header, if all OK load it
if (fno.fsize == sizeof(config) && f_read(fs_file, &magic, sizeof(magic), &size) == FR_OK &&
magic == CONFIG_MAGIC && f_read(fs_file, src, total, &size) == FR_OK) {
config_save();
drawMessageBox("Info", "Restart tinySA to load new config", 2000);
}
else error = "Format err";
}
break;
default: break;
}
f_close(fs_file);

Loading…
Cancel
Save

Powered by TurnKey Linux.