diff --git a/main.c b/main.c index 68ea355..669ab29 100644 --- a/main.c +++ b/main.c @@ -130,6 +130,8 @@ systime_t last_auto_save = 0; #ifdef TINYSA4 static THD_WORKING_AREA(waThread1, 1224); +systime_t restart_set_time = 0; +systime_t restart_interval = 0; #else static THD_WORKING_AREA(waThread1, 768); bool has_esd = false; @@ -169,11 +171,15 @@ static THD_FUNCTION(Thread1, arg) b.data.reflevel = setting.reflevel + 140; if (setting.rbw_x10 == 0) b.data.RBW = 0; - else + else { #ifdef TINYSA4 b.data.RBW = SI4463_rbw_selected+1; #else b.data.RBW = SI4432_rbw_selected+1; +#endif + } +#ifdef TINYSA4 + b.data.harmonic = setting.harmonic; #endif b.data.mode = setting.mode; b.data.checksum = 0; @@ -207,6 +213,15 @@ static THD_FUNCTION(Thread1, arg) config._mode = old_mode; } #endif +#ifdef __USE_RTC__ + if (restart_set_time) { + if ( chVTGetSystemTimeX() - restart_set_time > restart_interval) { + chThdSleepMilliseconds(200); + NVIC_SystemReset(); + } + } +#endif + if (sweep_once_count>1) { sweep_once_count--; @@ -407,6 +422,22 @@ static int get_str_index(const char *v, const char *list) return -1; } +#ifdef __USE_RTC__ +VNA_SHELL_FUNCTION(cmd_restart) +{ + (void)argc; + (void)argv; + if (argc == 1) { + restart_interval = S2ST(my_atoi(argv[0])); + if (restart_interval) { + restart_set_time = chVTGetSystemTimeX(); + if (restart_set_time == 0) + restart_set_time = 1; + } else + restart_set_time = 0; + } +} +#endif VNA_SHELL_FUNCTION(cmd_pause) @@ -2330,6 +2361,7 @@ static const VNAShellCommand commands[] = {"touchcal" , cmd_touchcal , CMD_WAIT_MUTEX}, {"touchtest" , cmd_touchtest , CMD_WAIT_MUTEX}, {"pause" , cmd_pause , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, + {"restart" , cmd_restart , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, {"resume" , cmd_resume , CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD}, {"wait" , cmd_wait , CMD_RUN_IN_LOAD}, // This lets the sweep continue {"repeat" , cmd_repeat , CMD_RUN_IN_LOAD}, @@ -3158,6 +3190,7 @@ int main(void) menu_push_submenu(menu_highoutputmode); break; } + set_harmonic(b.data.harmonic); #endif set_external_gain(b.data.external_gain/2); if (b.data.frequency0 != 0 || b.data.frequency1 != 0) { diff --git a/nanovna.h b/nanovna.h index b70a61e..cdabd7a 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1488,7 +1488,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e67 +#define CONFIG_MAGIC 0x434f4e68 #define SETTING_MAGIC 0x434f4e68 extern int16_t lastsaveid; @@ -1769,7 +1769,7 @@ typedef struct { uint8_t RBW; uint8_t mode; int8_t external_gain; - uint8_t dummy1,dummy2; + uint8_t harmonic,dummy2; uint8_t checksum; } data; }; @@ -1782,6 +1782,9 @@ typedef struct { #if USED_BACKUP_SIZE > MAX_BACKUP_SIZE #error "backup_t too large" #endif +//#if sizeof(backup_t) != USED_BACKUP_SIZE // does not work +//#error "backup_t size incorrect" +//#endif /* * misclinous */ diff --git a/sa_core.c b/sa_core.c index d1d280d..f3dd0d1 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1733,6 +1733,8 @@ void toggle_spur(void) #ifdef __HARMONIC__ void set_harmonic(int h) { + if (h < 0 || h > 5 || h == 1) + return; setting.harmonic = h; #if 0 minFreq = 684000000.0;