From 10d77ee69141faaec9ba9367ae51b82a05dbfe89 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 7 May 2020 11:43:40 +0200 Subject: [PATCH] stored trace now also saved to flash --- flash.c | 13 ++++++++++++- nanovna.h | 2 +- sa_core.c | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/flash.c b/flash.c index c9cb754..62dc281 100644 --- a/flash.c +++ b/flash.c @@ -166,6 +166,14 @@ caldata_save(int id) dst++; } + // Flash stored trace + count = sizeof(stored_t) / sizeof(uint16_t); + src = (uint16_t*)&stored_t[0]; + while (count-- > 0) { + flash_program_half_word((uint32_t)dst, *src++); + dst++; + } + /* after saving data, make active configuration points to flash */ // active_props = (setting_t*)saveareas[id]; lastsaveid = id; @@ -187,7 +195,7 @@ caldata_recall(int id) if (src->magic != CONFIG_MAGIC) return -1; - if (checksum(src, sizeof *src - sizeof src->checksum) != src->checksum) + if (checksum(src, sizeof setting - sizeof src->checksum) != src->checksum) return -1; /* active configuration points to save data on flash memory */ @@ -196,6 +204,9 @@ caldata_recall(int id) /* duplicated saved data onto sram to be able to modify marker/trace */ memcpy(dst, src, sizeof(setting_t)); + // Restore stored trace + memcpy(stored_t, &src[1], sizeof(stored_t)); + update_frequencies(); set_scale(setting.scale); set_reflevel(setting.reflevel); diff --git a/nanovna.h b/nanovna.h index 71c98f3..70a8dee 100644 --- a/nanovna.h +++ b/nanovna.h @@ -563,8 +563,8 @@ typedef struct setting marker_t _markers[MARKERS_MAX]; int8_t _active_marker; int8_t unit; - uint32_t checksum; float offset; + uint32_t checksum; }setting_t; extern setting_t setting; diff --git a/sa_core.c b/sa_core.c index d1af910..8263be7 100644 --- a/sa_core.c +++ b/sa_core.c @@ -484,7 +484,7 @@ void set_mode(int m) void apply_settings(void) { if (setting.mode == M_HIGH) - PE4302_Write_Byte(40); + PE4302_Write_Byte(40); // Ensure defined input impedance of low port when using high input mode (power calibration) else PE4302_Write_Byte(setting.attenuate * 2); #if 0