From 5ba6bdbe45fd567212663958cc6acfd641a2def0 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 6 Feb 2021 15:21:01 +0100 Subject: [PATCH] Saveconfig working and console command 64 bit frequencies --- chprintf.c | 10 +++++----- flash.c | 8 +++++--- main.c | 21 +++++++++++---------- nanovna.h | 2 +- sa_cmd.c | 8 ++++---- sa_core.c | 2 ++ 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/chprintf.c b/chprintf.c index 20627c6..a854f05 100644 --- a/chprintf.c +++ b/chprintf.c @@ -254,11 +254,11 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { int precision, width; int n = 0; uint32_t state; - union { + volatile union { uint32_t u; int32_t l; float f; - uint64_t x; + int64_t x; }value; #if CHPRINTF_USE_FLOAT char tmpbuf[2*MAX_FILLER + 1]; @@ -359,9 +359,9 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { case 'I': case 'i': if (state & IS_LONG) - value.x = va_arg(ap, uint64_t); + value.x = va_arg(ap, int64_t); else - value.x = va_arg(ap, uint32_t); + value.x = va_arg(ap, int32_t); if (value.x < 0) { state|=NEGATIVE; *p++ = '-'; @@ -373,7 +373,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { else if (state & PLUS_SPACE) *p++ = ' '; #endif - p = long_to_string_with_divisor(p, (uint64_t)value.x, 10, 0); + p = long_to_string_with_divisor(p, (int64_t)value.x, 10, 0); break; case 'q': if (state & IS_LONG) diff --git a/flash.c b/flash.c index b204a95..ada40b1 100644 --- a/flash.c +++ b/flash.c @@ -21,7 +21,7 @@ #include "hal.h" #include "nanovna.h" #include - +#include "usbcfg.h" static int flash_wait_for_last_operation(void) { while (FLASH->SR == FLASH_SR_BSY) { @@ -70,8 +70,10 @@ checksum(const void *start, size_t len) uint32_t *p = (uint32_t*)start; uint32_t *tail = (uint32_t*)(start + len); uint32_t value = 0; - while (p < tail) + while (p < tail) { value = __ROR(value, 31) + *p++; + if (SDU1.config->usbp->state == USB_ACTIVE) shell_printf("%x\r\n", value); + } return value; } @@ -107,7 +109,7 @@ config_recall(void) if (src->magic != CONFIG_MAGIC) return -1; - if (checksum(src, sizeof *src - sizeof src->checksum) != src->checksum) + if (checksum(src, sizeof config - sizeof config.checksum) != src->checksum) return -1; /* duplicated saved data onto sram to be able to modify marker/trace */ diff --git a/main.c b/main.c index f44c07d..f53542a 100644 --- a/main.c +++ b/main.c @@ -443,9 +443,9 @@ int set_frequency(freq_t freq) // Rewrite universal standart str to value functions to more compact // // Convert string to int32 -static int32_t my_atoi(const char *p) +static int64_t my_atoi(const char *p) { - int32_t value = 0; + int64_t value = 0; uint32_t c; bool neg = false; @@ -466,9 +466,9 @@ static int32_t my_atoi(const char *p) // 0o - for oct radix // 0b - for bin radix // default dec radix -uint32_t my_atoui(const char *p) +uint64_t my_atoui(const char *p) { - uint32_t value = 0, radix = 10, c; + uint64_t value = 0, radix = 10, c; if (*p == '+') p++; if (*p == '0') { switch (p[1]) { @@ -1124,7 +1124,7 @@ VNA_SHELL_FUNCTION(cmd_scan) uint16_t mask = my_atoui(argv[3]); if (mask) { for (i = 0; i < points; i++) { - if (mask & 1) shell_printf("%u ", frequencies[i]); + if (mask & 1) shell_printf("%Lu ", frequencies[i]); if (mask & 2) shell_printf("%f %f ", value(measured[2][i]), 0.0); if (mask & 4) shell_printf("%f %f ", value(measured[1][i]), 0.0); if (mask & 8) shell_printf("%f %f ", value(measured[0][i]), 0.0); @@ -1322,7 +1322,7 @@ get_sweep_frequency(int type) VNA_SHELL_FUNCTION(cmd_sweep) { if (argc == 0) { - shell_printf("%d %d %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points); + shell_printf("%Ld %Ld %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points); return; } else if (argc > 3) { goto usage; @@ -1990,7 +1990,7 @@ VNA_SHELL_FUNCTION(cmd_marker) if (argc == 0) { for (t = 0; t < MARKERS_MAX; t++) { if (markers[t].enabled) { - shell_printf("%d %d %d %f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index])); + shell_printf("%d %d %Ld %f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index])); } } return; @@ -2007,7 +2007,7 @@ VNA_SHELL_FUNCTION(cmd_marker) goto usage; if (argc == 1) { display_marker: - shell_printf("%d %d %d %.2f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index])); + shell_printf("%d %d %Ld %.2f\r\n", t+1, markers[t].index, markers[t].frequency, value(actual_t[markers[t].index])); active_marker = t; // select active marker markers[t].enabled = TRUE; @@ -2075,7 +2075,7 @@ VNA_SHELL_FUNCTION(cmd_frequencies) (void)argv; for (i = 0; i < sweep_points; i++) { if (frequencies[i] != 0) - shell_printf("%u\r\n", frequencies[i]); + shell_printf("%Lu\r\n", frequencies[i]); } } @@ -2907,10 +2907,11 @@ int main(void) /* restore config */ config_recall(); +#if 1 if (caldata_recall(0) == -1) { load_LCD_properties(); } - +#endif /* * Init Shell console connection data (after load config for settings) */ diff --git a/nanovna.h b/nanovna.h index f303afa..5a97791 100644 --- a/nanovna.h +++ b/nanovna.h @@ -582,7 +582,7 @@ typedef struct config { int8_t cor_wfm; int8_t cor_nfm; int8_t ultra; - int8_t dummy; + uint32_t dummy; // uint8_t _reserved[22]; uint32_t checksum; } config_t; diff --git a/sa_cmd.c b/sa_cmd.c index 814a522..b52e8e0 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -575,7 +575,7 @@ VNA_SHELL_FUNCTION(cmd_a) { (void)argc; if (argc != 1) { - shell_printf("a=%u\r\n", frequencyStart); + shell_printf("a=%Lu\r\n", frequencyStart); return; } freq_t value = my_atoui(argv[0]); @@ -587,7 +587,7 @@ VNA_SHELL_FUNCTION(cmd_b) { (void)argc; if (argc != 1) { - shell_printf("b=%u\r\n", frequencyStop); + shell_printf("b=%Lu\r\n", frequencyStop); return; } freq_t value = my_atoui(argv[0]); @@ -720,7 +720,7 @@ VNA_SHELL_FUNCTION(cmd_correction) if (argc == 0) { shell_printf("index frequency value\r\n"); for (int i=0; i fmin && config.frequency_IF1 < fplus) return true; + if(4*config.frequency_IF1 > fmin && 4*config.frequency_IF1 < fplus) + return true; return false; }