mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Change config and properties flash address definitions
Show BW settings at bottom of screen
This commit is contained in:
parent
c572e66231
commit
49b52213cf
46
flash.c
46
flash.c
|
|
@ -22,6 +22,8 @@
|
|||
#include "nanovna.h"
|
||||
#include <string.h>
|
||||
|
||||
int16_t lastsaveid = 0;
|
||||
|
||||
static int flash_wait_for_last_operation(void)
|
||||
{
|
||||
while (FLASH->SR == FLASH_SR_BSY) {
|
||||
|
|
@ -75,9 +77,6 @@ checksum(const void *start, size_t len)
|
|||
return value;
|
||||
}
|
||||
|
||||
|
||||
#define FLASH_PAGESIZE 0x800
|
||||
|
||||
const uint32_t save_config_area = SAVE_CONFIG_ADDR;
|
||||
|
||||
int
|
||||
|
|
@ -120,25 +119,16 @@ config_recall(void)
|
|||
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
|
||||
caldata_save(int id)
|
||||
caldata_save(uint32_t id)
|
||||
{
|
||||
if (id >= SAVEAREA_MAX)
|
||||
return -1;
|
||||
uint16_t *src = (uint16_t*)¤t_props;
|
||||
uint16_t *dst;
|
||||
int count = sizeof(properties_t) / sizeof(uint16_t);
|
||||
|
||||
if (id < 0 || id >= SAVEAREA_MAX)
|
||||
return -1;
|
||||
dst = (uint16_t*)saveareas[id];
|
||||
dst = (uint16_t*)(SAVE_PROP_CONFIG_ADDR + id * SAVE_PROP_CONFIG_SIZE);
|
||||
|
||||
current_props.magic = CONFIG_MAGIC;
|
||||
current_props.checksum = checksum(
|
||||
|
|
@ -161,23 +151,22 @@ caldata_save(int id)
|
|||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
caldata_recall(int id)
|
||||
caldata_recall(uint32_t id)
|
||||
{
|
||||
if (id >= SAVEAREA_MAX)
|
||||
return -1;
|
||||
properties_t *src;
|
||||
void *dst = ¤t_props;
|
||||
|
||||
if (id < 0 || id >= SAVEAREA_MAX)
|
||||
goto load_default;
|
||||
|
||||
// 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)
|
||||
goto load_default;
|
||||
|
|
@ -197,12 +186,13 @@ load_default:
|
|||
}
|
||||
|
||||
const properties_t *
|
||||
caldata_ref(int id)
|
||||
caldata_ref(uint32_t id)
|
||||
{
|
||||
const properties_t *src;
|
||||
if (id < 0 || id >= SAVEAREA_MAX)
|
||||
if (id >= SAVEAREA_MAX)
|
||||
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)
|
||||
return NULL;
|
||||
|
|
@ -211,8 +201,6 @@ caldata_ref(int id)
|
|||
return src;
|
||||
}
|
||||
|
||||
const uint32_t save_config_prop_area_size = SAVE_CONFIG_AREA_SIZE;
|
||||
|
||||
void
|
||||
clear_all_config_prop_data(void)
|
||||
{
|
||||
|
|
@ -220,7 +208,7 @@ clear_all_config_prop_data(void)
|
|||
|
||||
/* erase flash pages */
|
||||
void *p = (void*)save_config_area;
|
||||
void *tail = p + save_config_prop_area_size;
|
||||
void *tail = p + SAVE_FULL_AREA_SIZE;
|
||||
while (p < tail) {
|
||||
flash_erase_page((uint32_t)p);
|
||||
p += FLASH_PAGESIZE;
|
||||
|
|
|
|||
14
main.c
14
main.c
|
|
@ -858,19 +858,23 @@ bool sweep(bool break_on_operation)
|
|||
return true;
|
||||
}
|
||||
|
||||
uint32_t get_bandwidth_frequency(void){
|
||||
return (AUDIO_ADC_FREQ/AUDIO_SAMPLES_COUNT)/(config.bandwidth+1);
|
||||
}
|
||||
|
||||
VNA_SHELL_FUNCTION(cmd_bandwidth)
|
||||
{
|
||||
if (argc != 1)
|
||||
goto result;
|
||||
config.bandwidth = my_atoui(argv[0]);
|
||||
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)
|
||||
{
|
||||
uint32_t start, stop;
|
||||
int16_t points = sweep_points;
|
||||
uint16_t points = sweep_points;
|
||||
int i;
|
||||
if (argc < 2 || argc > 4) {
|
||||
shell_printf("usage: scan {start(Hz)} {stop(Hz)} [points] [outmask]\r\n");
|
||||
|
|
@ -884,8 +888,8 @@ VNA_SHELL_FUNCTION(cmd_scan)
|
|||
return;
|
||||
}
|
||||
if (argc >= 3) {
|
||||
points = my_atoi(argv[2]);
|
||||
if (points <= 0 || points > POINTS_COUNT) {
|
||||
points = my_atoui(argv[2]);
|
||||
if (points == 0 || points > POINTS_COUNT) {
|
||||
shell_printf("sweep points exceeds range "define_to_STR(POINTS_COUNT)"\r\n");
|
||||
return;
|
||||
}
|
||||
|
|
@ -1070,7 +1074,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("%u %u %d\r\n", get_sweep_frequency(ST_START), get_sweep_frequency(ST_STOP), sweep_points);
|
||||
return;
|
||||
} else if (argc > 3) {
|
||||
goto usage;
|
||||
|
|
|
|||
114
nanovna.h
114
nanovna.h
|
|
@ -99,6 +99,7 @@ enum stimulus_type {
|
|||
|
||||
void set_sweep_frequency(int type, uint32_t frequency);
|
||||
uint32_t get_sweep_frequency(int type);
|
||||
uint32_t get_bandwidth_frequency(void);
|
||||
|
||||
double my_atof(const char *p);
|
||||
|
||||
|
|
@ -157,6 +158,7 @@ extern void tlv320aic3204_select(int channel);
|
|||
|
||||
#define FREQUENCIES_XPOS1 OFFSETX
|
||||
#define FREQUENCIES_XPOS2 200
|
||||
#define FREQUENCIES_XPOS3 140
|
||||
#define FREQUENCIES_YPOS (240-7)
|
||||
|
||||
// GRIDX calculated depends from frequency span
|
||||
|
|
@ -199,10 +201,8 @@ extern const uint16_t numfont16x22[];
|
|||
#define S_PI "\034"
|
||||
#define S_MICRO "\035"
|
||||
#define S_OHM "\036"
|
||||
|
||||
// trace
|
||||
|
||||
#define TRACES_MAX 4
|
||||
|
||||
#define MAX_TRACE_TYPE 12
|
||||
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
|
||||
|
|
@ -219,7 +219,7 @@ enum trace_type {
|
|||
|
||||
// Electrical Delay
|
||||
// Phase
|
||||
|
||||
#define TRACES_MAX 4
|
||||
typedef struct trace {
|
||||
uint8_t enabled;
|
||||
uint8_t type;
|
||||
|
|
@ -229,6 +229,17 @@ typedef struct trace {
|
|||
float refpos;
|
||||
} 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_CENTER_SPAN 0x1
|
||||
#define FREQ_MODE_DOTTED_GRID 0x2
|
||||
|
|
@ -251,6 +262,33 @@ typedef struct 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_channel(int t, int channel);
|
||||
void set_trace_scale(int t, float scale);
|
||||
|
|
@ -263,19 +301,6 @@ void set_electrical_delay(float picoseconds);
|
|||
float get_electrical_delay(void);
|
||||
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 update_grid(void);
|
||||
void request_to_redraw_grid(void);
|
||||
|
|
@ -364,47 +389,26 @@ void show_logo(void);
|
|||
/*
|
||||
* flash.c
|
||||
*/
|
||||
|
||||
#define FLASH_PAGESIZE 0x800
|
||||
|
||||
#define SAVEAREA_MAX 5
|
||||
// Begin addr 0x08018000
|
||||
#define SAVE_CONFIG_AREA_SIZE 0x00008000
|
||||
// config save area
|
||||
|
||||
// Depand from config_t size, should be aligned by FLASH_PAGESIZE
|
||||
#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
|
||||
// properties_t save area
|
||||
#define SAVE_PROP_CONFIG_0_ADDR 0x08018800
|
||||
#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 SAVE_PROP_CONFIG_ADDR (SAVE_CONFIG_ADDR + SAVE_CONFIG_SIZE)
|
||||
#define SAVE_FULL_AREA_SIZE (SAVE_CONFIG_SIZE + SAVEAREA_MAX * SAVE_PROP_CONFIG_SIZE)
|
||||
|
||||
#define CONFIG_MAGIC 0x434f4e45 /* 'CONF' */
|
||||
|
||||
extern int16_t lastsaveid;
|
||||
extern properties_t *active_props;
|
||||
extern properties_t current_props;
|
||||
|
||||
#define frequency0 current_props._frequency0
|
||||
#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_CW() (frequency0 == frequency1)
|
||||
|
||||
int caldata_save(int id);
|
||||
int caldata_recall(int id);
|
||||
const properties_t *caldata_ref(int id);
|
||||
int caldata_save(uint32_t id);
|
||||
int caldata_recall(uint32_t id);
|
||||
const properties_t *caldata_ref(uint32_t id);
|
||||
|
||||
int config_save(void);
|
||||
int config_recall(void);
|
||||
|
|
|
|||
3
plot.c
3
plot.c
|
|
@ -1630,6 +1630,9 @@ draw_frequencies(void)
|
|||
buf2[0] = S_SARROW[0];
|
||||
ili9341_drawstring(buf1, FREQUENCIES_XPOS1, 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
|
||||
|
|
|
|||
3
ui.c
3
ui.c
|
|
@ -624,6 +624,7 @@ menu_bandwidth_cb(int item, uint8_t data)
|
|||
{
|
||||
(void)item;
|
||||
config.bandwidth = data;
|
||||
draw_frequencies();
|
||||
draw_menu();
|
||||
}
|
||||
|
||||
|
|
@ -1382,7 +1383,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
|
|||
*fg = 0xffff;
|
||||
}
|
||||
} 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 == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP)
|
||||
|| (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS)
|
||||
|
|
|
|||
Loading…
Reference in a new issue