Change config and properties flash address definitions

Show BW settings at bottom of screen
This commit is contained in:
DiSlord 2020-04-04 08:43:32 +03:00
parent c572e66231
commit 49b52213cf
5 changed files with 91 additions and 91 deletions

46
flash.c
View file

@ -22,6 +22,8 @@
#include "nanovna.h" #include "nanovna.h"
#include <string.h> #include <string.h>
int16_t lastsaveid = 0;
static int flash_wait_for_last_operation(void) static int flash_wait_for_last_operation(void)
{ {
while (FLASH->SR == FLASH_SR_BSY) { while (FLASH->SR == FLASH_SR_BSY) {
@ -75,9 +77,6 @@ checksum(const void *start, size_t len)
return value; return value;
} }
#define FLASH_PAGESIZE 0x800
const uint32_t save_config_area = SAVE_CONFIG_ADDR; const uint32_t save_config_area = SAVE_CONFIG_ADDR;
int int
@ -120,25 +119,16 @@ config_recall(void)
return 0; return 0;
} }
const uint32_t saveareas[SAVEAREA_MAX] = {
SAVE_PROP_CONFIG_0_ADDR,
SAVE_PROP_CONFIG_1_ADDR,
SAVE_PROP_CONFIG_2_ADDR,
SAVE_PROP_CONFIG_3_ADDR,
SAVE_PROP_CONFIG_4_ADDR };
int16_t lastsaveid = 0;
int int
caldata_save(int id) caldata_save(uint32_t id)
{ {
if (id >= SAVEAREA_MAX)
return -1;
uint16_t *src = (uint16_t*)&current_props; uint16_t *src = (uint16_t*)&current_props;
uint16_t *dst; uint16_t *dst;
int count = sizeof(properties_t) / sizeof(uint16_t); int count = sizeof(properties_t) / sizeof(uint16_t);
if (id < 0 || id >= SAVEAREA_MAX) dst = (uint16_t*)(SAVE_PROP_CONFIG_ADDR + id * SAVE_PROP_CONFIG_SIZE);
return -1;
dst = (uint16_t*)saveareas[id];
current_props.magic = CONFIG_MAGIC; current_props.magic = CONFIG_MAGIC;
current_props.checksum = checksum( current_props.checksum = checksum(
@ -161,23 +151,22 @@ caldata_save(int id)
} }
/* after saving data, make active configuration points to flash */ /* after saving data, make active configuration points to flash */
active_props = (properties_t*)saveareas[id]; active_props = (properties_t*)(SAVE_PROP_CONFIG_ADDR + id * SAVE_PROP_CONFIG_SIZE);
lastsaveid = id; lastsaveid = id;
return 0; return 0;
} }
int int
caldata_recall(int id) caldata_recall(uint32_t id)
{ {
if (id >= SAVEAREA_MAX)
return -1;
properties_t *src; properties_t *src;
void *dst = &current_props; void *dst = &current_props;
if (id < 0 || id >= SAVEAREA_MAX)
goto load_default;
// point to saved area on the flash memory // point to saved area on the flash memory
src = (properties_t*)saveareas[id]; src = (properties_t*)(SAVE_PROP_CONFIG_ADDR + id * SAVE_PROP_CONFIG_SIZE);
if (src->magic != CONFIG_MAGIC) if (src->magic != CONFIG_MAGIC)
goto load_default; goto load_default;
@ -197,12 +186,13 @@ load_default:
} }
const properties_t * const properties_t *
caldata_ref(int id) caldata_ref(uint32_t id)
{ {
const properties_t *src; if (id >= SAVEAREA_MAX)
if (id < 0 || id >= SAVEAREA_MAX)
return NULL; return NULL;
src = (const properties_t*)saveareas[id]; const properties_t *src;
src = (const properties_t*)(SAVE_PROP_CONFIG_ADDR + id * SAVE_PROP_CONFIG_SIZE);
if (src->magic != CONFIG_MAGIC) if (src->magic != CONFIG_MAGIC)
return NULL; return NULL;
@ -211,8 +201,6 @@ caldata_ref(int id)
return src; return src;
} }
const uint32_t save_config_prop_area_size = SAVE_CONFIG_AREA_SIZE;
void void
clear_all_config_prop_data(void) clear_all_config_prop_data(void)
{ {
@ -220,7 +208,7 @@ clear_all_config_prop_data(void)
/* erase flash pages */ /* erase flash pages */
void *p = (void*)save_config_area; void *p = (void*)save_config_area;
void *tail = p + save_config_prop_area_size; void *tail = p + SAVE_FULL_AREA_SIZE;
while (p < tail) { while (p < tail) {
flash_erase_page((uint32_t)p); flash_erase_page((uint32_t)p);
p += FLASH_PAGESIZE; p += FLASH_PAGESIZE;

16
main.c
View file

@ -858,19 +858,23 @@ bool sweep(bool break_on_operation)
return true; return true;
} }
uint32_t get_bandwidth_frequency(void){
return (AUDIO_ADC_FREQ/AUDIO_SAMPLES_COUNT)/(config.bandwidth+1);
}
VNA_SHELL_FUNCTION(cmd_bandwidth) VNA_SHELL_FUNCTION(cmd_bandwidth)
{ {
if (argc != 1) if (argc != 1)
goto result; goto result;
config.bandwidth = my_atoui(argv[0]); config.bandwidth = my_atoui(argv[0]);
result: result:
shell_printf("bandwidth %d (%dHz)\r\n", config.bandwidth, (AUDIO_ADC_FREQ/AUDIO_SAMPLES_COUNT)/(config.bandwidth+1)); shell_printf("bandwidth %d (%uHz)\r\n", config.bandwidth, get_bandwidth_frequency());
} }
VNA_SHELL_FUNCTION(cmd_scan) VNA_SHELL_FUNCTION(cmd_scan)
{ {
uint32_t start, stop; uint32_t start, stop;
int16_t points = sweep_points; uint16_t points = sweep_points;
int i; int i;
if (argc < 2 || argc > 4) { if (argc < 2 || argc > 4) {
shell_printf("usage: scan {start(Hz)} {stop(Hz)} [points] [outmask]\r\n"); shell_printf("usage: scan {start(Hz)} {stop(Hz)} [points] [outmask]\r\n");
@ -884,8 +888,8 @@ VNA_SHELL_FUNCTION(cmd_scan)
return; return;
} }
if (argc >= 3) { if (argc >= 3) {
points = my_atoi(argv[2]); points = my_atoui(argv[2]);
if (points <= 0 || points > POINTS_COUNT) { if (points == 0 || points > POINTS_COUNT) {
shell_printf("sweep points exceeds range "define_to_STR(POINTS_COUNT)"\r\n"); shell_printf("sweep points exceeds range "define_to_STR(POINTS_COUNT)"\r\n");
return; return;
} }
@ -933,7 +937,7 @@ update_marker_index(void)
markers[m].index = f < (frequencies[i] / 2 + frequencies[i + 1] / 2) ? i : i + 1; markers[m].index = f < (frequencies[i] / 2 + frequencies[i + 1] / 2) ? i : i + 1;
break; break;
} }
} }
} }
} }
} }
@ -1070,7 +1074,7 @@ get_sweep_frequency(int type)
VNA_SHELL_FUNCTION(cmd_sweep) VNA_SHELL_FUNCTION(cmd_sweep)
{ {
if (argc == 0) { if (argc == 0) {
shell_printf("%d %d %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points); shell_printf("%u %u %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points);
return; return;
} else if (argc > 3) { } else if (argc > 3) {
goto usage; goto usage;

114
nanovna.h
View file

@ -99,6 +99,7 @@ enum stimulus_type {
void set_sweep_frequency(int type, uint32_t frequency); void set_sweep_frequency(int type, uint32_t frequency);
uint32_t get_sweep_frequency(int type); uint32_t get_sweep_frequency(int type);
uint32_t get_bandwidth_frequency(void);
double my_atof(const char *p); double my_atof(const char *p);
@ -157,6 +158,7 @@ extern void tlv320aic3204_select(int channel);
#define FREQUENCIES_XPOS1 OFFSETX #define FREQUENCIES_XPOS1 OFFSETX
#define FREQUENCIES_XPOS2 200 #define FREQUENCIES_XPOS2 200
#define FREQUENCIES_XPOS3 140
#define FREQUENCIES_YPOS (240-7) #define FREQUENCIES_YPOS (240-7)
// GRIDX calculated depends from frequency span // GRIDX calculated depends from frequency span
@ -199,10 +201,8 @@ extern const uint16_t numfont16x22[];
#define S_PI "\034" #define S_PI "\034"
#define S_MICRO "\035" #define S_MICRO "\035"
#define S_OHM "\036" #define S_OHM "\036"
// trace // trace
#define TRACES_MAX 4
#define MAX_TRACE_TYPE 12 #define MAX_TRACE_TYPE 12
enum trace_type { enum trace_type {
TRC_LOGMAG=0, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF TRC_LOGMAG=0, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
@ -219,7 +219,7 @@ enum trace_type {
// Electrical Delay // Electrical Delay
// Phase // Phase
#define TRACES_MAX 4
typedef struct trace { typedef struct trace {
uint8_t enabled; uint8_t enabled;
uint8_t type; uint8_t type;
@ -229,6 +229,17 @@ typedef struct trace {
float refpos; float refpos;
} trace_t; } trace_t;
// marker
#define MARKERS_MAX 4
typedef struct marker {
int8_t enabled;
int16_t index;
uint32_t frequency;
} marker_t;
extern int8_t previous_marker;
extern int8_t marker_tracking;
#define FREQ_MODE_START_STOP 0x0 #define FREQ_MODE_START_STOP 0x0
#define FREQ_MODE_CENTER_SPAN 0x1 #define FREQ_MODE_CENTER_SPAN 0x1
#define FREQ_MODE_DOTTED_GRID 0x2 #define FREQ_MODE_DOTTED_GRID 0x2
@ -251,6 +262,33 @@ typedef struct config {
extern config_t config; extern config_t config;
typedef struct properties {
uint32_t magic;
uint32_t _frequency0;
uint32_t _frequency1;
uint16_t _sweep_points;
uint16_t _cal_status;
uint32_t _frequencies[POINTS_COUNT];
float _cal_data[5][POINTS_COUNT][2];
float _electrical_delay; // picoseconds
trace_t _trace[TRACES_MAX];
marker_t _markers[MARKERS_MAX];
float _velocity_factor; // %
int8_t _active_marker;
uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TD_FUNC m: DOMAIN_MODE */
uint8_t _marker_smith_format;
uint8_t _reserved[51];
uint32_t checksum;
} properties_t;
//sizeof(properties_t) == 0x1200
extern properties_t *active_props;
extern properties_t current_props;
void set_trace_type(int t, int type); void set_trace_type(int t, int type);
void set_trace_channel(int t, int channel); void set_trace_channel(int t, int channel);
void set_trace_scale(int t, float scale); void set_trace_scale(int t, float scale);
@ -263,19 +301,6 @@ void set_electrical_delay(float picoseconds);
float get_electrical_delay(void); float get_electrical_delay(void);
float groupdelay_from_array(int i, float array[POINTS_COUNT][2]); float groupdelay_from_array(int i, float array[POINTS_COUNT][2]);
// marker
#define MARKERS_MAX 4
typedef struct marker {
int8_t enabled;
int16_t index;
uint32_t frequency;
} marker_t;
extern int8_t previous_marker;
extern int8_t marker_tracking;
void plot_init(void); void plot_init(void);
void update_grid(void); void update_grid(void);
void request_to_redraw_grid(void); void request_to_redraw_grid(void);
@ -364,47 +389,26 @@ void show_logo(void);
/* /*
* flash.c * flash.c
*/ */
#define FLASH_PAGESIZE 0x800
#define SAVEAREA_MAX 5 #define SAVEAREA_MAX 5
// Begin addr 0x08018000
#define SAVE_CONFIG_AREA_SIZE 0x00008000 // Depand from config_t size, should be aligned by FLASH_PAGESIZE
// config save area #define SAVE_CONFIG_SIZE 0x00000800
// Depend from properties_t size, should be aligned by FLASH_PAGESIZE
#define SAVE_PROP_CONFIG_SIZE 0x00001800
// Save config_t and properties_t flash area (see flash7 : org = 0x08018000, len = 32k from *.ld settings)
// Properties save area follow after config
// len = SAVE_CONFIG_SIZE + SAVEAREA_MAX * SAVE_PROP_CONFIG_SIZE 0x00008000 32k
#define SAVE_CONFIG_ADDR 0x08018000 #define SAVE_CONFIG_ADDR 0x08018000
// properties_t save area #define SAVE_PROP_CONFIG_ADDR (SAVE_CONFIG_ADDR + SAVE_CONFIG_SIZE)
#define SAVE_PROP_CONFIG_0_ADDR 0x08018800 #define SAVE_FULL_AREA_SIZE (SAVE_CONFIG_SIZE + SAVEAREA_MAX * SAVE_PROP_CONFIG_SIZE)
#define SAVE_PROP_CONFIG_1_ADDR 0x0801a000
#define SAVE_PROP_CONFIG_2_ADDR 0x0801b800
#define SAVE_PROP_CONFIG_3_ADDR 0x0801d000
#define SAVE_PROP_CONFIG_4_ADDR 0x0801e800
typedef struct properties {
uint32_t magic;
uint32_t _frequency0;
uint32_t _frequency1;
uint16_t _sweep_points;
uint16_t _cal_status;
uint32_t _frequencies[POINTS_COUNT];
float _cal_data[5][POINTS_COUNT][2];
float _electrical_delay; // picoseconds
trace_t _trace[TRACES_MAX];
marker_t _markers[MARKERS_MAX];
float _velocity_factor; // %
int8_t _active_marker;
uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TD_FUNC m: DOMAIN_MODE */
uint8_t _marker_smith_format;
uint8_t _reserved[51];
uint32_t checksum;
} properties_t;
//sizeof(properties_t) == 0x1200
#define CONFIG_MAGIC 0x434f4e45 /* 'CONF' */ #define CONFIG_MAGIC 0x434f4e45 /* 'CONF' */
extern int16_t lastsaveid; extern int16_t lastsaveid;
extern properties_t *active_props;
extern properties_t current_props;
#define frequency0 current_props._frequency0 #define frequency0 current_props._frequency0
#define frequency1 current_props._frequency1 #define frequency1 current_props._frequency1
@ -425,9 +429,9 @@ extern properties_t current_props;
#define FREQ_IS_CENTERSPAN() (config.freq_mode&FREQ_MODE_CENTER_SPAN) #define FREQ_IS_CENTERSPAN() (config.freq_mode&FREQ_MODE_CENTER_SPAN)
#define FREQ_IS_CW() (frequency0 == frequency1) #define FREQ_IS_CW() (frequency0 == frequency1)
int caldata_save(int id); int caldata_save(uint32_t id);
int caldata_recall(int id); int caldata_recall(uint32_t id);
const properties_t *caldata_ref(int id); const properties_t *caldata_ref(uint32_t id);
int config_save(void); int config_save(void);
int config_recall(void); int config_recall(void);

3
plot.c
View file

@ -1630,6 +1630,9 @@ draw_frequencies(void)
buf2[0] = S_SARROW[0]; buf2[0] = S_SARROW[0];
ili9341_drawstring(buf1, FREQUENCIES_XPOS1, FREQUENCIES_YPOS); ili9341_drawstring(buf1, FREQUENCIES_XPOS1, FREQUENCIES_YPOS);
ili9341_drawstring(buf2, FREQUENCIES_XPOS2, FREQUENCIES_YPOS); ili9341_drawstring(buf2, FREQUENCIES_XPOS2, FREQUENCIES_YPOS);
plot_printf(buf1, sizeof(buf1), "bw:%uHz", get_bandwidth_frequency());
ili9341_set_foreground(DEFAULT_GRID_COLOR);
ili9341_drawstring(buf1, FREQUENCIES_XPOS3, FREQUENCIES_YPOS);
} }
void void

3
ui.c
View file

@ -624,6 +624,7 @@ menu_bandwidth_cb(int item, uint8_t data)
{ {
(void)item; (void)item;
config.bandwidth = data; config.bandwidth = data;
draw_frequencies();
draw_menu(); draw_menu();
} }
@ -1382,7 +1383,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
*fg = 0xffff; *fg = 0xffff;
} }
} else if (menu == menu_transform) { } else if (menu == menu_transform) {
if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME)
|| (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE) || (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE)
|| (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP) || (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP)
|| (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS) || (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS)