From 373e56f006ef328338cfaa6e118e7c984668aa88 Mon Sep 17 00:00:00 2001 From: TT Date: Fri, 20 Jan 2017 08:57:17 +0900 Subject: [PATCH] add clearconfig command --- flash.c | 18 ++++++++++++++++++ main.c | 30 ++++++++++++++++++++++++++---- nanovna.h | 3 +++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/flash.c b/flash.c index 1731f163..ddefcb14 100644 --- a/flash.c +++ b/flash.c @@ -194,3 +194,21 @@ caldata_recall(int id) return 0; } + + +const uint32_t save_config_prop_area_size = 0x8000; + +void +clear_all_config_prop_data(void) +{ + flash_unlock(); + + /* erase flash pages */ + void *p = (void*)save_config_area; + void *tail = p + save_config_prop_area_size; + while (p < tail) { + flash_erase_page((uint32_t)p); + p += FLASH_PAGESIZE; + } +} + diff --git a/main.c b/main.c index 094dae3e..8b0882df 100644 --- a/main.c +++ b/main.c @@ -191,6 +191,22 @@ static void cmd_saveconfig(BaseSequentialStream *chp, int argc, char *argv[]) chprintf(chp, "Config saved.\r\n"); } +static void cmd_clearconfig(BaseSequentialStream *chp, int argc, char *argv[]) +{ + if (argc != 1) { + chprintf(chp, "usage: clearconfig {protection key}\r\n"); + return; + } + + if (strcmp(argv[0], "1234") != 0) { + chprintf(chp, "Key unmatched.\r\n"); + return; + } + + clear_all_config_prop_data(); + chprintf(chp, "Config and all cal data cleared.\r\n"); +} + static struct { int16_t rms[2]; int16_t ave[2]; @@ -313,6 +329,7 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[]) } } +#if 0 static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[]) { float gamma[2]; @@ -327,6 +344,7 @@ static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[]) chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]); } +#endif #if 0 int32_t frequency0 = 1000000; @@ -347,6 +365,7 @@ config_t config = { /* trace_colors[4] */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) }, ///* touch_cal[4] */ { 620, 600, 160, 190 }, /* touch_cal[4] */ { 620, 600, 130, 180 }, + /* default_loadcal */ 0, /* checksum */ 0 }; @@ -385,7 +404,7 @@ ensure_edit_config(void) cal_status = 0; } - +#if 0 static void cmd_scan(BaseSequentialStream *chp, int argc, char *argv[]) { float gamma[2]; @@ -412,6 +431,7 @@ static void cmd_scan(BaseSequentialStream *chp, int argc, char *argv[]) } chMtxUnlock(&mutex); } +#endif // main loop for measurement void sweep(void) @@ -1336,6 +1356,7 @@ static const ShellCommand commands[] = { "time", cmd_time }, { "dac", cmd_dac }, { "saveconfig", cmd_saveconfig }, + { "clearconfig", cmd_clearconfig }, { "data", cmd_data }, { "dump", cmd_dump }, { "frequencies", cmd_frequencies }, @@ -1343,8 +1364,8 @@ static const ShellCommand commands[] = { "stat", cmd_stat }, { "gain", cmd_gain }, { "power", cmd_power }, - { "gamma", cmd_gamma }, - { "scan", cmd_scan }, + //{ "gamma", cmd_gamma }, + //{ "scan", cmd_scan }, { "sweep", cmd_sweep }, { "test", cmd_test }, { "touchcal", cmd_touchcal }, @@ -1427,7 +1448,8 @@ int main(void) dacStart(&DACD2, &dac1cfg1); /* restore frequencies and calibration properties from flash memory */ - caldata_recall(0); + if (config.default_loadcal >= 0) + caldata_recall(config.default_loadcal); /* initial frequencies */ update_frequencies(); diff --git a/nanovna.h b/nanovna.h index 6d6c2c53..b435729a 100644 --- a/nanovna.h +++ b/nanovna.h @@ -178,6 +178,7 @@ typedef struct { uint16_t menu_active_color; uint16_t trace_color[TRACES_MAX]; int16_t touch_cal[4]; + int8_t default_loadcal; int32_t checksum; } config_t; @@ -290,6 +291,8 @@ int caldata_recall(int id); int config_save(void); int config_recall(void); +void clear_all_config_prop_data(void); + /* * ui.c */