mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Huge reduce flash usage (about 5k), remove cal_data and _frequencies properties from data section
Use void loadDefaultProps() for load default properties (default loaded also on error load from flash) Move some constants to nanovna.h
This commit is contained in:
parent
cc3370c962
commit
ccb3693516
19
flash.c
19
flash.c
|
|
@ -122,12 +122,15 @@ config_recall(void)
|
|||
|
||||
#define SAVEAREA_MAX 5
|
||||
|
||||
const uint32_t saveareas[] =
|
||||
{ 0x08018800, 0x0801a000, 0x0801b800, 0x0801d000, 0x0801e800 };
|
||||
const uint32_t saveareas[SAVEAREA_MAX] = {
|
||||
SAVE_CONFIG_0_ADDR,
|
||||
SAVE_CONFIG_1_ADDR,
|
||||
SAVE_CONFIG_2_ADDR,
|
||||
SAVE_CONFIG_3_ADDR,
|
||||
SAVE_CONFIG_4_ADDR };
|
||||
|
||||
int16_t lastsaveid = 0;
|
||||
|
||||
|
||||
int
|
||||
caldata_save(int id)
|
||||
{
|
||||
|
|
@ -172,15 +175,15 @@ caldata_recall(int id)
|
|||
void *dst = ¤t_props;
|
||||
|
||||
if (id < 0 || id >= SAVEAREA_MAX)
|
||||
return -1;
|
||||
goto load_default;
|
||||
|
||||
// point to saved area on the flash memory
|
||||
src = (properties_t*)saveareas[id];
|
||||
|
||||
if (src->magic != CONFIG_MAGIC)
|
||||
return -1;
|
||||
goto load_default;
|
||||
if (checksum(src, sizeof *src - sizeof src->checksum) != src->checksum)
|
||||
return -1;
|
||||
goto load_default;
|
||||
|
||||
/* active configuration points to save data on flash memory */
|
||||
active_props = src;
|
||||
|
|
@ -188,8 +191,10 @@ caldata_recall(int id)
|
|||
|
||||
/* duplicated saved data onto sram to be able to modify marker/trace */
|
||||
memcpy(dst, src, sizeof(properties_t));
|
||||
|
||||
return 0;
|
||||
load_default:
|
||||
loadDefaultProps();
|
||||
return -1;
|
||||
}
|
||||
|
||||
const properties_t *
|
||||
|
|
|
|||
83
main.c
83
main.c
|
|
@ -725,28 +725,43 @@ config_t config = {
|
|||
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR, DEFAULT_TRACE_4_COLOR },
|
||||
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
||||
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
||||
.default_loadcal = 0,
|
||||
.harmonic_freq_threshold = 300000000
|
||||
};
|
||||
|
||||
properties_t current_props = {
|
||||
.magic = CONFIG_MAGIC,
|
||||
._frequency0 = 50000, // start = 50kHz
|
||||
._frequency1 = 900000000, // end = 900MHz
|
||||
._sweep_points = POINTS_COUNT,
|
||||
._trace = {/*enable, type, channel, reserved, scale, refpos*/
|
||||
properties_t current_props;
|
||||
properties_t *active_props = ¤t_props;
|
||||
|
||||
// NanoVNA Default settings
|
||||
static const trace_t def_trace[TRACES_MAX] = {//enable, type, channel, reserved, scale, refpos
|
||||
{ 1, TRC_LOGMAG, 0, 0, 10.0, NGRIDY-1 },
|
||||
{ 1, TRC_LOGMAG, 1, 0, 10.0, NGRIDY-1 },
|
||||
{ 1, TRC_SMITH, 0, 0, 1.0, 0 },
|
||||
{ 1, TRC_PHASE, 1, 0, 90.0, NGRIDY/2 }
|
||||
},
|
||||
._markers = {
|
||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||
},
|
||||
._velocity_factor = 0.7,
|
||||
._marker_smith_format = MS_RLC
|
||||
};
|
||||
properties_t *active_props = ¤t_props;
|
||||
|
||||
static const marker_t def_markers[MARKERS_MAX] = {
|
||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||
};
|
||||
|
||||
// Load propeties default settings
|
||||
void loadDefaultProps(void){
|
||||
current_props.magic = CONFIG_MAGIC;
|
||||
current_props._frequency0 = 50000; // start = 50kHz
|
||||
current_props._frequency1 = 900000000; // end = 900MHz
|
||||
current_props._sweep_points = POINTS_COUNT;
|
||||
current_props._cal_status = 0;
|
||||
//This data not loaded by default
|
||||
//current_props._frequencies[POINTS_COUNT];
|
||||
//current_props._cal_data[5][POINTS_COUNT][2];
|
||||
//=============================================
|
||||
current_props._electrical_delay = 0.0;
|
||||
memcpy(current_props._trace, def_trace, sizeof(def_trace));
|
||||
memcpy(current_props._markers, def_markers, sizeof(def_markers));
|
||||
current_props._velocity_factor = 0.7;
|
||||
current_props._active_marker = 0;
|
||||
current_props._domain_mode = 0;
|
||||
current_props._marker_smith_format = MS_RLC;
|
||||
}
|
||||
|
||||
void
|
||||
ensure_edit_config(void)
|
||||
|
|
@ -768,20 +783,19 @@ bool sweep(bool break_on_operation)
|
|||
int i;
|
||||
// blink LED while scanning
|
||||
palClearPad(GPIOC, GPIOC_LED);
|
||||
for (i = 0; i < sweep_points; i++) {
|
||||
int delay = set_frequency(frequencies[i]);
|
||||
tlv320aic3204_select(0); // CH0:REFLECT
|
||||
wait_dsp(delay);
|
||||
for (i = 0; i < sweep_points; i++) { // 8365
|
||||
int delay = set_frequency(frequencies[i]); // 1560
|
||||
tlv320aic3204_select(0); // 60 CH0:REFLECT
|
||||
|
||||
/* calculate reflection coefficient */
|
||||
(*sample_func)(measured[0][i]);
|
||||
|
||||
tlv320aic3204_select(1); // CH1:TRANSMISSION
|
||||
wait_dsp(DELAY_CHANNEL_CHANGE);
|
||||
|
||||
/* calculate transmission coefficient */
|
||||
(*sample_func)(measured[1][i]);
|
||||
wait_dsp(delay); // 3270
|
||||
// calculate reflection coefficient
|
||||
(*sample_func)(measured[0][i]); // 60
|
||||
|
||||
tlv320aic3204_select(1); // 60 CH1:TRANSMISSION
|
||||
wait_dsp(DELAY_CHANNEL_CHANGE); // 2700
|
||||
// calculate transmission coefficient
|
||||
(*sample_func)(measured[1][i]); // 60
|
||||
// ======== 170 ===========
|
||||
if (cal_status & CALSTAT_APPLY)
|
||||
apply_error_term_at(i);
|
||||
|
||||
|
|
@ -928,9 +942,6 @@ freq_mode_centerspan(void)
|
|||
}
|
||||
}
|
||||
|
||||
#define START_MIN 50000
|
||||
#define STOP_MAX 2700000000U
|
||||
|
||||
void
|
||||
set_sweep_frequency(int type, uint32_t freq)
|
||||
{
|
||||
|
|
@ -1472,14 +1483,12 @@ VNA_SHELL_FUNCTION(cmd_recall)
|
|||
int id = my_atoi(argv[0]);
|
||||
if (id < 0 || id >= SAVEAREA_MAX)
|
||||
goto usage;
|
||||
|
||||
if (caldata_recall(id) == 0) {
|
||||
// success
|
||||
// Check for success
|
||||
if (caldata_recall(id) == -1)
|
||||
shell_printf("Err, default load\r\n");
|
||||
update_frequencies();
|
||||
redraw_request |= REDRAW_CAL_STATUS;
|
||||
}
|
||||
return;
|
||||
|
||||
usage:
|
||||
shell_printf("recall {id}\r\n");
|
||||
}
|
||||
|
|
@ -2203,6 +2212,8 @@ int main(void)
|
|||
|
||||
/* restore config */
|
||||
config_recall();
|
||||
/* restore frequencies and calibration 0 slot properties from flash memory */
|
||||
caldata_recall(0);
|
||||
|
||||
dac1cfg1.init = config.dac_value;
|
||||
/*
|
||||
|
|
@ -2214,10 +2225,6 @@ int main(void)
|
|||
/* initial frequencies */
|
||||
update_frequencies();
|
||||
|
||||
/* restore frequencies and calibration properties from flash memory */
|
||||
if (config.default_loadcal >= 0)
|
||||
caldata_recall(config.default_loadcal);
|
||||
|
||||
/*
|
||||
* I2S Initialize
|
||||
*/
|
||||
|
|
|
|||
16
nanovna.h
16
nanovna.h
|
|
@ -25,6 +25,8 @@
|
|||
/*
|
||||
* main.c
|
||||
*/
|
||||
#define START_MIN 50000
|
||||
#define STOP_MAX 2700000000U
|
||||
|
||||
#define POINTS_COUNT 101
|
||||
extern float measured[2][POINTS_COUNT][2];
|
||||
|
|
@ -82,9 +84,21 @@ uint32_t get_sweep_frequency(int type);
|
|||
double my_atof(const char *p);
|
||||
|
||||
void toggle_sweep(void);
|
||||
void loadDefaultProps(void);
|
||||
|
||||
extern int8_t sweep_enabled;
|
||||
|
||||
/*
|
||||
* flash.c
|
||||
*/
|
||||
#define SAVEAREA_MAX 5
|
||||
|
||||
#define SAVE_CONFIG_0_ADDR 0x08018800
|
||||
#define SAVE_CONFIG_1_ADDR 0x0801a000
|
||||
#define SAVE_CONFIG_2_ADDR 0x0801b800
|
||||
#define SAVE_CONFIG_3_ADDR 0x0801d000
|
||||
#define SAVE_CONFIG_4_ADDR 0x0801e800
|
||||
|
||||
/*
|
||||
* ui.c
|
||||
*/
|
||||
|
|
@ -223,7 +237,7 @@ typedef struct {
|
|||
uint16_t menu_active_color;
|
||||
uint16_t trace_color[TRACES_MAX];
|
||||
int16_t touch_cal[4];
|
||||
int8_t default_loadcal;
|
||||
int8_t reserved_1;
|
||||
uint32_t harmonic_freq_threshold;
|
||||
|
||||
uint8_t _reserved[24];
|
||||
|
|
|
|||
Loading…
Reference in a new issue