setting_t stricture optimization

Less size, less code size
Move waterfall setting to setting_t
Add comments to used structure
!! Old config and settings data lost after!!
Removed_REF_marker
DiSlord 5 years ago committed by erikkaashoek
parent df9d7276cc
commit 1ddcf5893e

@ -285,7 +285,7 @@ void set_harmonic(int);
//extern int setting.harmonic; //extern int setting.harmonic;
int search_is_greater(void); int search_is_greater(void);
void set_auto_attenuation(void); void set_auto_attenuation(void);
void set_auto_reflevel(int); void set_auto_reflevel(bool);
int is_paused(void); int is_paused(void);
void set_actual_power(float); void set_actual_power(float);
void SetGenerate(int); void SetGenerate(int);
@ -586,6 +586,7 @@ typedef struct trace {
typedef struct config { typedef struct config {
int32_t magic; int32_t magic;
uint32_t deviceid;
uint16_t lcd_palette[MAX_PALETTE]; uint16_t lcd_palette[MAX_PALETTE];
int16_t touch_cal[4]; int16_t touch_cal[4];
uint32_t _serial_speed; uint32_t _serial_speed;
@ -598,11 +599,10 @@ typedef struct config {
float high_level_offset; float high_level_offset;
float low_level_output_offset; float low_level_output_offset;
float high_level_output_offset; float high_level_output_offset;
float low_correction_value[CORRECTION_POINTS];
float high_correction_value[CORRECTION_POINTS];
freq_t low_correction_frequency[CORRECTION_POINTS]; freq_t low_correction_frequency[CORRECTION_POINTS];
float low_correction_value[CORRECTION_POINTS];
freq_t high_correction_frequency[CORRECTION_POINTS]; freq_t high_correction_frequency[CORRECTION_POINTS];
float high_correction_value[CORRECTION_POINTS];
uint32_t deviceid;
#ifdef TINYSA4 #ifdef TINYSA4
freq_t setting_frequency_30mhz; freq_t setting_frequency_30mhz;
#else #else
@ -842,87 +842,97 @@ void show_version(void);
/* /*
* flash.c * flash.c
*/ */
typedef struct setting typedef struct setting
{ {
uint32_t magic; uint32_t magic;
// freq_t _frequency0; bool auto_reflevel; // bool
// freq_t _frequency1; bool auto_attenuation; // bool
int mode; bool mirror_masking; // bool
bool subtract_stored; // bool
bool show_stored; // bool
bool tracking_output; // bool
bool mute; // bool
bool auto_IF; // bool
uint8_t mode; // enum
uint8_t below_IF; // enum
uint8_t unit; // enum
uint8_t agc; // enum
uint8_t lna; // enum
uint8_t modulation; // enum
uint8_t trigger; // enum
uint8_t trigger_mode; // enum
uint8_t trigger_direction; // enum
uint8_t step_delay_mode; // enum
uint8_t waterfall; // enum
uint8_t average; // enum
uint8_t measurement; // enum
uint8_t spur_removal; // enum
int8_t tracking; // -1...1 !!! need convert to bool
uint8_t atten_step; // 0...1 !!! need convert to bool
int8_t _active_marker; // -1...MARKER_MAX
uint8_t unit_scale_index; // table index
uint8_t repeat; // 1...100
uint8_t noise; // 2...50
uint8_t lo_drive; // 0-3 , 3dB steps
uint8_t rx_drive; // 0-15 , 7=+20dBm, 3dB steps
uint8_t test; // current test number
uint8_t harmonic; // used harmonic number 1...5
uint8_t fast_speedup; // 0 - 20
uint16_t linearity_step; // range equal POINTS_COUNT
uint16_t _sweep_points; uint16_t _sweep_points;
int16_t attenuate_x2; int16_t attenuate_x2; // 0...60 !!! in calculation can be < 0
uint8_t auto_attenuation;
uint8_t below_IF; uint16_t step_delay; // KM_SAMPLETIME 250...10000, 0=auto
int8_t _active_marker; uint16_t offset_delay; // KM_OFFSET_DELAY 250...10000, 0=auto
int8_t unit;
uint8_t mirror_masking; uint16_t freq_mode; // 0...1!!! need convert to bool or bit field
uint8_t subtract_stored; // uint8_t increases size int16_t refer; // -1 disabled
uint8_t agc;
uint8_t lna; uint16_t modulation_frequency; // 50...6000
uint8_t auto_reflevel; int decay; // KM_DECAY < 1000000
uint8_t dummy2; int attack; // KM_ATTACK < 20000
int modulation;
int show_stored; int32_t slider_position;
int atten_step; uint32_t slider_span;
int test;
int harmonic;
uint32_t rbw_x10; uint32_t rbw_x10;
int average; uint32_t vbw_x10;
int lo_drive; // 0-3 , 3dB steps
int rx_drive; // 0-15 , 7=+20dBm, 3dB steps
float reflevel; float reflevel;
float scale; float scale;
int tracking; float offset;
int step_delay; float trigger_level;
float level;
float level_sweep;
float unit_scale;
float normalize_level; // Level to set normalize to, zero if not doing anything
freq_t frequency_step; freq_t frequency_step;
int decay;
int attack;
int noise;
uint32_t vbw_x10;
int tracking_output;
int repeat;
freq_t frequency0; freq_t frequency0;
freq_t frequency1; freq_t frequency1;
freq_t frequency_IF; freq_t frequency_IF;
int freq_mode;
int measurement;
int refer;
int spur_removal;
trace_t _trace[TRACES_MAX]; trace_t _trace[TRACES_MAX];
marker_t _markers[MARKERS_MAX]; marker_t _markers[MARKERS_MAX];
float offset;
float trigger_level; systime_t sweep_time_us;
int trigger_direction;
int trigger;
int linearity_step;
float level;
float level_sweep;
uint32_t sweep_time_us;
systime_t measure_sweep_time_us; systime_t measure_sweep_time_us;
uint32_t actual_sweep_time_us; systime_t actual_sweep_time_us;
uint32_t additional_step_delay_us; systime_t additional_step_delay_us;
int test_argument;
int auto_IF; freq_t *correction_frequency;
unsigned int unit_scale_index;
float unit_scale;
int mute;
int step_delay_mode;
int offset_delay;
int fast_speedup;
float normalize_level; // Level to set normalize to, zero if not doing anything
int modulation_frequency;
int trigger_mode;
int slider_position;
int32_t slider_span;
freq_t *correction_frequency;
float *correction_value; float *correction_value;
#ifdef TINYSA4 #ifdef TINYSA4
int extra_lna; bool extra_lna;
int ultra; uint8_t ultra; // enum ??
int R; int R; // KM_R
#endif #endif
uint16_t dummy; int test_argument; // used for tests
uint32_t checksum; // must be last and at 4 byte boundary uint32_t checksum; // must be last and at 4 byte boundary
}setting_t; }setting_t;
@ -930,13 +940,14 @@ extern setting_t setting;
void reset_settings(int m); void reset_settings(int m);
#define S_IS_AUTO(x) ((x)&2) #define S_IS_AUTO(x) ((x)&2)
#define S_STATE(X) ((X)&1) #define S_STATE(X) ((X)&1)
enum { S_OFF=0, S_ON=1, S_AUTO_OFF=2, S_AUTO_ON=3 }; enum { S_OFF=0, S_ON=1, S_AUTO_OFF=2, S_AUTO_ON=3 };
enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL }; enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL };
enum {W_OFF, W_SMALL, W_BIG};
#ifdef __FAST_SWEEP__ #ifdef __FAST_SWEEP__
#define MINIMUM_SWEEP_TIME 1800U // Minimum sweep time on zero span in uS #define MINIMUM_SWEEP_TIME 1800U // Minimum sweep time on zero span in uS
#else #else
@ -1029,7 +1040,7 @@ typedef struct properties {
//sizeof(properties_t) == 0x1200 //sizeof(properties_t) == 0x1200
#define CONFIG_MAGIC 0x434f4e47 /* 'CONF' */ #define CONFIG_MAGIC 0x434f4e48 /* 'CONF' */
extern int16_t lastsaveid; extern int16_t lastsaveid;
//extern properties_t *active_props; //extern properties_t *active_props;

@ -31,7 +31,6 @@
#ifdef __SCROLL__ #ifdef __SCROLL__
uint16_t _grid_y = (CHART_BOTTOM / NGRIDY); uint16_t _grid_y = (CHART_BOTTOM / NGRIDY);
uint16_t graph_bottom = CHART_BOTTOM; uint16_t graph_bottom = CHART_BOTTOM;
static int waterfall = false;
#endif #endif
static void cell_draw_marker_info(int x0, int y0); static void cell_draw_marker_info(int x0, int y0);
static void cell_grid_line_info(int x0, int y0); static void cell_grid_line_info(int x0, int y0);
@ -517,7 +516,7 @@ draw_on_strut(int v0, int d, int color)
#define SQRT_50 ((float)7.0710678118654) #define SQRT_50 ((float)7.0710678118654)
#define LOG_10_SQRT_50 ((float)0.84948500216800) #define LOG_10_SQRT_50 ((float)0.84948500216800)
#define POW_30_20 ((float) 0.215443469) #define POW_30_20 ((float) 0.215443469)
#define POW_SQRT ((float)1.5234153789) #define POW_SQRT ((float)0.2236067950725555419921875)
#define LOG_10_SQRT_50_x20_plus30 ((float)46.98970004336) #define LOG_10_SQRT_50_x20_plus30 ((float)46.98970004336)
#define LOG_10_SQRT_50_x20_plus90 ((float)106.98970004336) #define LOG_10_SQRT_50_x20_plus90 ((float)106.98970004336)
@ -538,20 +537,20 @@ value(const float v)
switch(setting.unit) switch(setting.unit)
{ {
case U_DBMV: case U_DBMV:
// return v + 30.0 + 20.0*log10f(sqrt(50)); // return v + 30.0 + 20.0*log10f(sqrtf(50));
return v + LOG_10_SQRT_50_x20_plus30; // + 30.0 + 20.0*LOG_10_SQRT_50; //TODO convert constants to single float number as GCC compiler does runtime calculation return v + LOG_10_SQRT_50_x20_plus30; // + 30.0 + 20.0*LOG_10_SQRT_50; //TODO convert constants to single float number as GCC compiler does runtime calculation
break; break;
case U_DBUV: case U_DBUV:
// return v + 90.0 + 20.0*log10f(sqrt(50.0)); //TODO convert constants to single float number as GCC compiler does runtime calculation // return v + 90.0 + 20.0*log10f(sqrtf(50.0)); //TODO convert constants to single float number as GCC compiler does runtime calculation
return v + LOG_10_SQRT_50_x20_plus90; // 90.0 + 20.0*LOG_10_SQRT_50; return v + LOG_10_SQRT_50_x20_plus90; // 90.0 + 20.0*LOG_10_SQRT_50;
break; break;
case U_VOLT: case U_VOLT:
// return powf(10, (v-30.0)/20.0) * sqrt((float)50.0); // return powf(10.0, (v-30.0)/20.0) * sqrtf(50.0);
return powf((float)10.0, (v-(float)30.0)/(float)20.0)*SQRT_50; // Do NOT change pow to powf as this will increase the size // return powf(10.0, (v-30.0)/20.0) * SQRT_50; //
// return pow(10, v/20.0) * POW_SQRT; //TODO there is an error in this calculation as the outcome is different from the not optimized version return powf(10.0, v/20) * POW_SQRT; // powf(10.0,v/20.0) * powf(10, -30.0/20.0) * sqrtf(50)
break; break;
case U_WATT: case U_WATT:
return powf((float)10.0, v/10.0)/1000.0; // Do NOT change pow to powf as this will increase the size return powf((float)10.0, v/10.0)/1000.0; //
break; break;
} }
// case U_DBM: // case U_DBM:
@ -565,16 +564,16 @@ to_dBm(const float v)
switch(setting.unit) switch(setting.unit)
{ {
case U_DBMV: case U_DBMV:
// return v - 30.0 - 20.0*log10f(sqrt(50)); // return v - 30.0 - 20.0*log10f(sqrtf(50));
return v - LOG_10_SQRT_50_x20_plus30; // (30.0 + 20.0*LOG_10_SQRT_50); return v - LOG_10_SQRT_50_x20_plus30; // (30.0 + 20.0*LOG_10_SQRT_50);
break; break;
case U_DBUV: case U_DBUV:
// return v - 90.0 - 20.0*log10f(sqrt(50.0)); //TODO convert constants to single float number as GCC compiler does runtime calculation // return v - 90.0 - 20.0*log10f(sqrtf(50.0)); //TODO convert constants to single float number as GCC compiler does runtime calculation
return v - LOG_10_SQRT_50_x20_plus90; // (90.0 + 20.0*LOG_10_SQRT_50); return v - LOG_10_SQRT_50_x20_plus90; // (90.0 + 20.0*LOG_10_SQRT_50);
break; break;
case U_VOLT: case U_VOLT:
// return log10f( v / (sqrt(50.0))) * 20.0 + 30.0 ; // return log10f( v / (sqrtf(50.0))) * 20.0 + 30.0 ;
return log10f( v / (SQRT_50)) * 20.0 + 30.0 ; return log10f( v / SQRT_50) * 20.0 + 30.0 ;
break; break;
case U_WATT: case U_WATT:
return log10f(v*1000.0)*10.0; return log10f(v*1000.0)*10.0;
@ -1072,7 +1071,7 @@ mark_cells_from_index(void)
for (t = 0; t < TRACES_MAX; t++) { for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled) if (!trace[t].enabled)
continue; continue;
index_t *index = &trace_index[t][0]; index_t *index = trace_index[t];
int m0 = CELL_X(index[0]) / CELLWIDTH; int m0 = CELL_X(index[0]) / CELLWIDTH;
int n0 = CELL_Y(index[0]) / CELLHEIGHT; int n0 = CELL_Y(index[0]) / CELLHEIGHT;
map[n0] |= 1 << m0; map[n0] |= 1 << m0;
@ -1481,7 +1480,7 @@ draw_cell(int m, int n)
for (y = 0; y < h; y++) { for (y = 0; y < h; y++) {
if (rectangular_grid_y(y + y0)) { if (rectangular_grid_y(y + y0)) {
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
if (x + x0 >= CELLOFFSETX && x + x0 <= WIDTH + CELLOFFSETX) if ((uint32_t)(x + x0 - CELLOFFSETX) <= WIDTH)
cell_buffer[y * CELLWIDTH + x] = c; cell_buffer[y * CELLWIDTH + x] = c;
} }
} }
@ -1665,8 +1664,8 @@ draw_all(bool flush)
draw_all_cells(flush); draw_all_cells(flush);
#ifdef __SCROLL__ #ifdef __SCROLL__
// START_PROFILE // START_PROFILE
if (waterfall) if (setting.waterfall)
update_waterfall(); update_waterfall();
// STOP_PROFILE // STOP_PROFILE
#endif #endif
} }
@ -2374,26 +2373,25 @@ static void update_waterfall(void){
int get_waterfall(void) int get_waterfall(void)
{ {
return(waterfall); return(setting.waterfall);
} }
enum {W_OFF, W_SMALL, W_BIG};
void void
toggle_waterfall(void) toggle_waterfall(void)
{ {
if (waterfall == W_OFF) { if (setting.waterfall == W_OFF) {
w_min = (int)min_level; w_min = (int)min_level;
w_max = (int)peakLevel; w_max = (int)peakLevel;
if (w_max < w_min + 20) if (w_max < w_min + 20)
w_max = w_min + 20; w_max = w_min + 20;
graph_bottom = SMALL_WATERFALL; graph_bottom = SMALL_WATERFALL;
waterfall = W_SMALL; setting.waterfall = W_SMALL;
} else if (waterfall == W_SMALL) { } else if (setting.waterfall == W_SMALL) {
graph_bottom = BIG_WATERFALL; graph_bottom = BIG_WATERFALL;
waterfall = W_BIG; setting.waterfall = W_BIG;
} else { } else {
graph_bottom = NO_WATERFALL; graph_bottom = NO_WATERFALL;
waterfall = W_OFF; setting.waterfall = W_OFF;
} }
_grid_y = graph_bottom / NGRIDY; _grid_y = graph_bottom / NGRIDY;
ili9341_set_background(LCD_BG_COLOR); ili9341_set_background(LCD_BG_COLOR);
@ -2405,7 +2403,7 @@ void
disable_waterfall(void) disable_waterfall(void)
{ {
graph_bottom = NO_WATERFALL; graph_bottom = NO_WATERFALL;
waterfall = W_OFF; setting.waterfall = W_OFF;
_grid_y = graph_bottom / NGRIDY; _grid_y = graph_bottom / NGRIDY;
ili9341_set_background(LCD_BG_COLOR); ili9341_set_background(LCD_BG_COLOR);
ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom); ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom);

@ -190,6 +190,7 @@ void reset_settings(int m)
setting.auto_attenuation = false; setting.auto_attenuation = false;
setting.subtract_stored = false; setting.subtract_stored = false;
setting.normalize_level = 0.0; setting.normalize_level = 0.0;
setting.waterfall = W_OFF;
#ifdef TINYSA4 #ifdef TINYSA4
setting.lo_drive=1; setting.lo_drive=1;
#else #else
@ -614,7 +615,7 @@ void set_auto_attenuation(void)
dirty = true; dirty = true;
} }
void set_auto_reflevel(int v) void set_auto_reflevel(bool v)
{ {
setting.auto_reflevel = v; setting.auto_reflevel = v;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.