diff --git a/flash.c b/flash.c index bb90a12..598230d 100644 --- a/flash.c +++ b/flash.c @@ -71,8 +71,9 @@ checksum(const void *start, size_t len) uint32_t *tail = (uint32_t*)(start + len); uint32_t value = 0; while (p < tail) { - value = __ROR(value, 31) + *p++; - // if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("%x\r\n", value); + value = __ROR(value, 31) + *p; +// if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("%x, %x\r\n", *p, value); + p++; } return value; } @@ -109,6 +110,7 @@ config_recall(void) if (src->magic != CONFIG_MAGIC) return -1; +// if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("Checksum %x\r\n", src->checksum); if (checksum(src, sizeof config - sizeof config.checksum) != src->checksum) return -1; @@ -132,8 +134,9 @@ caldata_save(uint16_t id) dst = (uint16_t*)(SAVE_PROP_CONFIG_ADDR + id * SAVE_PROP_CONFIG_SIZE); setting.magic = CONFIG_MAGIC; + setting.checksum = 0x12345678; setting.checksum = checksum( - &setting, sizeof setting - sizeof setting.checksum); + &setting, (sizeof (setting)) - sizeof setting.checksum); flash_unlock(); @@ -179,7 +182,8 @@ caldata_recall(uint16_t id) if (src->magic != CONFIG_MAGIC) return -1; - if (checksum(src, sizeof setting - sizeof src->checksum) != src->checksum) +// if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("Checksum %x\r\n", src->checksum); + if (checksum(src, (sizeof (setting)) - sizeof src->checksum) != src->checksum) return -1; /* active configuration points to save data on flash memory */ diff --git a/nanovna.h b/nanovna.h index a4c2f82..5caee68 100644 --- a/nanovna.h +++ b/nanovna.h @@ -858,6 +858,7 @@ typedef struct setting uint8_t agc; uint8_t lna; uint8_t auto_reflevel; + uint8_t dummy2; int modulation; int show_stored; int atten_step; @@ -918,8 +919,8 @@ typedef struct setting int ultra; int R; #endif - uint32_t dummy; - uint32_t checksum; // must be last + uint16_t dummy; + uint32_t checksum; // must be last and at 4 byte boundary }setting_t; extern setting_t setting; diff --git a/sa_core.c b/sa_core.c index f6ed6ff..55e9e03 100644 --- a/sa_core.c +++ b/sa_core.c @@ -103,7 +103,7 @@ const int8_t drive_dBm [16] = {-38, -32, -30, -27, -24, -19, -15, -12, -5, -2, 0 #define MAX_DRIVE (setting.mode == M_GENHIGH ? 15 : 11) #define MIN_DRIVE 8 #define SL_GENHIGH_LEVEL_MIN -38 -#define SL_GENHIGH_LEVEL_RANGE 51 +#define SL_GENHIGH_LEVEL_RANGE 54 #define SL_GENLOW_LEVEL_MIN -76 #define SL_GENLOW_LEVEL_RANGE 70 #endif @@ -670,8 +670,12 @@ void set_level(float v) // Set the output level in dB in high/low output // d = 7; set_lo_drive(d); } else { + if (v < SL_GENLOW_LEVEL_MIN) + v = SL_GENLOW_LEVEL_MIN; + if (v > SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE) + v = SL_GENLOW_LEVEL_MIN + SL_GENLOW_LEVEL_RANGE; setting.level = v; - set_attenuation(setting.level - config.low_level_output_offset); +// set_attenuation(setting.level - config.low_level_output_offset); } dirty = true; } @@ -681,7 +685,7 @@ float get_level(void) if (setting.mode == M_GENHIGH) { return drive_dBm[setting.lo_drive] + config.high_level_output_offset; } else { - setting.level = get_attenuation() + config.low_level_output_offset; +// setting.level = get_attenuation() + config.low_level_output_offset; return setting.level; } } @@ -701,8 +705,9 @@ float get_attenuation(void) return(actual_attenuation); } -void set_attenuation(float a) // Is used both in low output mode and high/low input mode +void set_attenuation(float a) // Is used both only in high/low input mode { +#if 0 if (setting.mode == M_GENLOW) { a = a - level_max(); // Move to zero for max power if (a > 0) @@ -719,7 +724,9 @@ void set_attenuation(float a) // Is used both in low output mode and high/ } a -= BELOW_MAX_DRIVE(setting.rx_drive); a = -a; - } else { + } else +#endif + { if (setting.mode == M_LOW && a > 31.5) { setting.atten_step = 1; a = a - RECEIVE_SWITCH_ATTENUATION; diff --git a/ui_sa.c b/ui_sa.c index 566b3c4..da9dc02 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -404,7 +404,7 @@ static const keypads_t keypads_time[] = { enum { KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, // These must be first to share common help text KM_REFLEVEL, KM_SCALE, KM_ATTENUATION, - KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, + KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, #ifdef TINYSA4 KM_30MHZ, #else @@ -439,7 +439,6 @@ static const struct { {keypads_plusmin_unit, "ACTUAL\nPOWER"}, // actual power {keypads_freq , "IF"}, // IF {keypads_positive , "SAMPLE\nDELAY"}, // sample delay - {keypads_positive , "DRIVE"}, // KM_DRIVE {keypads_plusmin , "LEVEL"}, // KM_LOWOUTLEVEL {keypads_positive , "DECAY"}, // KM_DECAY {keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE @@ -2256,10 +2255,6 @@ static void fetch_numeric_target(void) uistat.value = setting.repeat; plot_printf(uistat.text, sizeof uistat.text, "%2d", ((int32_t)uistat.value)); break; - case KM_DRIVE: - uistat.value = setting.rx_drive; - plot_printf(uistat.text, sizeof uistat.text, "%3ddB", ((int32_t)uistat.value)); - break; case KM_LOWOUTLEVEL: uistat.value = get_level(); // compensation for dB offset during low output mode int end_level = ((int32_t)uistat.value)+setting.level_sweep; @@ -2422,9 +2417,6 @@ set_numeric_value(void) case KM_REPEAT: set_repeat(uistat.value); break; - case KM_DRIVE: - set_rx_drive(uistat.value); - break; case KM_LOWOUTLEVEL: set_level(uistat.value - setting.offset); break;