Revert some changes:

Start/stop generation feature (unstable on segment scan from CPU)
 Calibration on paused sweep (need more stack, need find better solution)
 Variable use optimization
This commit is contained in:
DiSlord 2020-03-07 17:19:43 +03:00
parent a43b6e3acc
commit 12d53738bc
5 changed files with 77 additions and 56 deletions

View file

@ -64,13 +64,13 @@ endif
# Stack size to be allocated to the Cortex-M process stack. This stack is # Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread. # the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),) ifeq ($(USE_PROCESS_STACKSIZE),)
USE_PROCESS_STACKSIZE = 0x300 USE_PROCESS_STACKSIZE = 0x200
endif endif
# Stack size to the allocated to the Cortex-M main/exceptions stack. This # Stack size to the allocated to the Cortex-M main/exceptions stack. This
# stack is used for processing interrupts and exceptions. # stack is used for processing interrupts and exceptions.
ifeq ($(USE_EXCEPTIONS_STACKSIZE),) ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
USE_EXCEPTIONS_STACKSIZE = 0x100 USE_EXCEPTIONS_STACKSIZE = 0x200
endif endif
# #

100
main.c
View file

@ -69,14 +69,17 @@ static void transform_domain(void);
static MUTEX_DECL(mutex); static MUTEX_DECL(mutex);
// Obsolete enable/disable calibration interpolation (always on) #define DRIVE_STRENGTH_AUTO (-1)
#define cal_auto_interpolate TRUE #define FREQ_HARMONICS (config.harmonic_freq_threshold)
#define IS_HARMONIC_MODE(f) ((f) > FREQ_HARMONICS)
// Obsolete, always use interpolate
#define cal_auto_interpolate TRUE
static int32_t frequency_offset = 5000; static int32_t frequency_offset = 5000;
static uint32_t frequency = 10000000; static uint32_t frequency = 10000000;
static int8_t drive_strength = DRIVE_STRENGTH_AUTO; static int8_t drive_strength = DRIVE_STRENGTH_AUTO;
volatile int8_t sweep_mode = SWEEP_MODE_ENABLED; int8_t sweep_enabled = TRUE;
volatile int8_t sweep_once = FALSE;
volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags volatile uint8_t redraw_request = 0; // contains REDRAW_XXX flags
int16_t vbat = 0; int16_t vbat = 0;
@ -88,19 +91,19 @@ static THD_FUNCTION(Thread1, arg)
while (1) { while (1) {
bool completed = false; bool completed = false;
if (sweep_mode&(SWEEP_MODE_ENABLED|SWEEP_MODE_RUN_ONCE)) { if (sweep_enabled || sweep_once) {
chMtxLock(&mutex); chMtxLock(&mutex);
completed = sweep(true); completed = sweep(true);
sweep_mode&=~SWEEP_MODE_RUN_ONCE; sweep_once = FALSE;
chMtxUnlock(&mutex); chMtxUnlock(&mutex);
} else { } else {
si5351_disable_output();
__WFI(); __WFI();
} }
chMtxLock(&mutex); chMtxLock(&mutex);
ui_process(); ui_process();
if (sweep_mode&SWEEP_MODE_ENABLED) {
if (sweep_enabled) {
if (vbat != -1) { if (vbat != -1) {
adc_stop(ADC1); adc_stop(ADC1);
vbat = adc_vbat_read(ADC1); vbat = adc_vbat_read(ADC1);
@ -130,10 +133,23 @@ static THD_FUNCTION(Thread1, arg)
} }
} }
static inline void run_once_sweep(void) {sweep_mode|=SWEEP_MODE_RUN_ONCE;} static inline void
static inline void pause_sweep(void) {sweep_mode&=~SWEEP_MODE_ENABLED;} pause_sweep(void)
static inline void resume_sweep(void){sweep_mode|= SWEEP_MODE_ENABLED;} {
void toggle_sweep(void){sweep_mode^= SWEEP_MODE_ENABLED;} sweep_enabled = FALSE;
}
static inline void
resume_sweep(void)
{
sweep_enabled = TRUE;
}
void
toggle_sweep(void)
{
sweep_enabled = !sweep_enabled;
}
static float static float
bessel0(float x) { bessel0(float x) {
@ -723,8 +739,7 @@ static const marker_t def_markers[MARKERS_MAX] = {
// Load propeties default settings // Load propeties default settings
void loadDefaultProps(void){ void loadDefaultProps(void){
//Magic add on caldata_save current_props.magic = CONFIG_MAGIC;
//current_props.magic = CONFIG_MAGIC;
current_props._frequency0 = 50000; // start = 50kHz current_props._frequency0 = 50000; // start = 50kHz
current_props._frequency1 = 900000000; // end = 900MHz current_props._frequency1 = 900000000; // end = 900MHz
current_props._sweep_points = POINTS_COUNT; current_props._sweep_points = POINTS_COUNT;
@ -740,8 +755,6 @@ void loadDefaultProps(void){
current_props._active_marker = 0; current_props._active_marker = 0;
current_props._domain_mode = 0; current_props._domain_mode = 0;
current_props._marker_smith_format = MS_RLC; current_props._marker_smith_format = MS_RLC;
//Checksum add on caldata_save
//current_props.checksum = 0;
} }
void void
@ -759,23 +772,20 @@ ensure_edit_config(void)
#define DELAY_CHANNEL_CHANGE 2 #define DELAY_CHANNEL_CHANGE 2
// main loop for measurement // main loop for measurement
static bool sweep(bool break_on_operation) bool sweep(bool break_on_operation)
{ {
int i, delay; int i, delay;
// blink LED while scanning // blink LED while scanning
palClearPad(GPIOC, GPIOC_LED); palClearPad(GPIOC, GPIOC_LED);
si5351_enable_output();
wait_dsp(1); // Wait for get optimal timings
for (i = 0; i < sweep_points; i++) { // 5300 for (i = 0; i < sweep_points; i++) { // 5300
delay = set_frequency(frequencies[i]); // 700 delay = set_frequency(frequencies[i]); // 700
tlv320aic3204_select(0); // 60 CH0:REFLECT tlv320aic3204_select(0); // 60 CH0:REFLECT
wait_dsp(delay); // 1900 wait_dsp(delay); // 1900
// calculate reflection coefficient // calculate reflection coefficient
(*sample_func)(measured[0][i]); // 60 (*sample_func)(measured[0][i]); // 60
tlv320aic3204_select(1); // 60 CH1:TRANSMISSION tlv320aic3204_select(1); // 60 CH1:TRANSMISSION
wait_dsp(DELAY_CHANNEL_CHANGE); // 1800 wait_dsp(DELAY_CHANNEL_CHANGE); // 1700
// calculate transmission coefficient // calculate transmission coefficient
(*sample_func)(measured[1][i]); // 60 (*sample_func)(measured[1][i]); // 60
// ======== 170 =========== // ======== 170 ===========
@ -786,9 +796,8 @@ static bool sweep(bool break_on_operation)
apply_edelay_at(i); apply_edelay_at(i);
// back to toplevel to handle ui operation // back to toplevel to handle ui operation
if (operation_requested && break_on_operation){ if (operation_requested && break_on_operation)
return false; return false;
}
} }
// blink LED while scanning // blink LED while scanning
palSetPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);
@ -825,11 +834,11 @@ VNA_SHELL_FUNCTION(cmd_scan)
if (cal_auto_interpolate && (cal_status & CALSTAT_APPLY)) if (cal_auto_interpolate && (cal_status & CALSTAT_APPLY))
cal_interpolate(lastsaveid); cal_interpolate(lastsaveid);
run_once_sweep(); sweep_once = TRUE;
chMtxUnlock(&mutex); chMtxUnlock(&mutex);
// wait finishing sweep // wait finishing sweep
while (sweep_mode&SWEEP_MODE_RUN_ONCE) while (sweep_once)
chThdSleepMilliseconds(10); chThdSleepMilliseconds(10);
} }
@ -1270,21 +1279,36 @@ void
cal_collect(int type) cal_collect(int type)
{ {
ensure_edit_config(); ensure_edit_config();
int dst, src;
switch (type) { switch (type) {
case CAL_LOAD: cal_status|= CALSTAT_LOAD; dst = CAL_LOAD; src = 0; break; case CAL_LOAD:
case CAL_OPEN: cal_status|= CALSTAT_OPEN; dst = CAL_OPEN; src = 0; cal_status&= ~(CALSTAT_ES|CALSTAT_APPLY); break; cal_status |= CALSTAT_LOAD;
case CAL_SHORT: cal_status|= CALSTAT_SHORT; dst = CAL_SHORT; src = 0; cal_status&= ~(CALSTAT_ER|CALSTAT_APPLY); break; memcpy(cal_data[CAL_LOAD], measured[0], sizeof measured[0]);
case CAL_THRU: cal_status|= CALSTAT_THRU; dst = CAL_THRU; src = 1; break; break;
case CAL_ISOLN: cal_status|= CALSTAT_ISOLN; dst = CAL_ISOLN; src = 1; break;
default: case CAL_OPEN:
return; cal_status |= CALSTAT_OPEN;
cal_status &= ~(CALSTAT_ES|CALSTAT_APPLY);
memcpy(cal_data[CAL_OPEN], measured[0], sizeof measured[0]);
break;
case CAL_SHORT:
cal_status |= CALSTAT_SHORT;
cal_status &= ~(CALSTAT_ER|CALSTAT_APPLY);
memcpy(cal_data[CAL_SHORT], measured[0], sizeof measured[0]);
break;
case CAL_THRU:
cal_status |= CALSTAT_THRU;
memcpy(cal_data[CAL_THRU], measured[1], sizeof measured[0]);
break;
case CAL_ISOLN:
cal_status |= CALSTAT_ISOLN;
memcpy(cal_data[CAL_ISOLN], measured[1], sizeof measured[0]);
break;
} }
// Made sweep operation for collect calibration data redraw_request |= REDRAW_CAL_STATUS;
sweep(false);
// Copy calibration data
memcpy(cal_data[dst], measured[src], sizeof measured[0]);
redraw_request|= REDRAW_CAL_STATUS;
} }
void void

View file

@ -86,9 +86,7 @@ double my_atof(const char *p);
void toggle_sweep(void); void toggle_sweep(void);
void loadDefaultProps(void); void loadDefaultProps(void);
#define SWEEP_MODE_ENABLED 0x01 extern int8_t sweep_enabled;
#define SWEEP_MODE_RUN_ONCE 0x02
extern volatile int8_t sweep_mode;
/* /*
* dsp.c * dsp.c
@ -225,10 +223,6 @@ typedef struct config {
extern config_t config; extern config_t config;
#define DRIVE_STRENGTH_AUTO (-1)
#define FREQ_HARMONICS (config.harmonic_freq_threshold)
#define IS_HARMONIC_MODE(f) ((f) > FREQ_HARMONICS)
//extern trace_t trace[TRACES_MAX]; //extern trace_t trace[TRACES_MAX];
void set_trace_type(int t, int type); void set_trace_type(int t, int type);

View file

@ -78,8 +78,8 @@ const uint8_t si5351_configs[] = {
// setup multisynth (832MHz / 104 = 8MHz, 104/2-2=50) // setup multisynth (832MHz / 104 = 8MHz, 104/2-2=50)
9, SI5351_REG_58_MULTISYNTH2, /*P3*/0, 1, /*P1*/0, 50, 0, /*P2|P3*/0, 0, 0, 9, SI5351_REG_58_MULTISYNTH2, /*P3*/0, 1, /*P1*/0, 50, 0, /*P2|P3*/0, 0, 0,
2, SI5351_REG_18_CLK2_CONTROL, SI5351_CLK_DRIVE_STRENGTH_2MA | SI5351_CLK_INPUT_MULTISYNTH_N | SI5351_CLK_INTEGER_MODE, 2, SI5351_REG_18_CLK2_CONTROL, SI5351_CLK_DRIVE_STRENGTH_2MA | SI5351_CLK_INPUT_MULTISYNTH_N | SI5351_CLK_INTEGER_MODE,
2, SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0,
#endif #endif
2, SI5351_REG_3_OUTPUT_ENABLE_CONTROL, ~(SI5351_CLK0_EN|SI5351_CLK1_EN|SI5351_CLK2_EN),
0 // sentinel 0 // sentinel
}; };
@ -118,7 +118,7 @@ static void si5351_reset_pll(uint8_t mask)
{ {
// Writing a 1<<5 will reset PLLA, 1<<7 reset PLLB, this is a self clearing bits. // Writing a 1<<5 will reset PLLA, 1<<7 reset PLLB, this is a self clearing bits.
// !!! Need delay before reset PLL for apply PLL freq changes before // !!! Need delay before reset PLL for apply PLL freq changes before
chThdSleepMicroseconds(200); chThdSleepMicroseconds(400);
si5351_write(SI5351_REG_177_PLL_RESET, mask | 0x0C); si5351_write(SI5351_REG_177_PLL_RESET, mask | 0x0C);
} }
@ -126,6 +126,7 @@ void si5351_disable_output(void)
{ {
si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0xFF); si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0xFF);
si5351_bulk_write(disable_output, sizeof(disable_output)); si5351_bulk_write(disable_output, sizeof(disable_output));
current_band = 0;
} }
void si5351_enable_output(void) void si5351_enable_output(void)
@ -338,7 +339,8 @@ static inline uint8_t si5351_getBand(uint32_t freq){
// Additional delay for band 1 (remove unstable generation at begin) // Additional delay for band 1 (remove unstable generation at begin)
#define DELAY_BAND_1 1 #define DELAY_BAND_1 1
// Band changes need additional delay after reset PLL // Band changes need additional delay after reset PLL
#define DELAY_BANDCHANGE 2 #define DELAY_BANDCHANGE_1 3
#define DELAY_BANDCHANGE_2 3
/* /*
* Maximum supported frequency = FREQ_HARMONICS * 9U * Maximum supported frequency = FREQ_HARMONICS * 9U
@ -358,16 +360,16 @@ si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_streng
uint32_t rdiv = SI5351_R_DIV_1; uint32_t rdiv = SI5351_R_DIV_1;
uint32_t fdiv; uint32_t fdiv;
current_freq = freq; current_freq = freq;
if (freq >= FREQ_HARMONICS * 7U) { if (freq >= config.harmonic_freq_threshold * 7U) {
mul = 9; mul = 9;
omul = 11; omul = 11;
} else if (freq >= FREQ_HARMONICS * 5U) { } else if (freq >= config.harmonic_freq_threshold * 5U) {
mul = 7; mul = 7;
omul = 9; omul = 9;
} else if (freq >= FREQ_HARMONICS * 3U) { } else if (freq >= config.harmonic_freq_threshold * 3U) {
mul = 5; mul = 5;
omul = 7; omul = 7;
} else if (freq >= FREQ_HARMONICS) { } else if (freq >= config.harmonic_freq_threshold) {
mul = 3; mul = 3;
omul = 5; omul = 5;
} }
@ -388,6 +390,7 @@ si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_streng
if (current_band != 1){ if (current_band != 1){
si5351_setupPLL(SI5351_REG_PLL_A, PLL_N, 0, 1); si5351_setupPLL(SI5351_REG_PLL_A, PLL_N, 0, 1);
si5351_set_frequency_fixedpll(2, XTALFREQ * PLL_N, CLK2_FREQUENCY, SI5351_R_DIV_1, SI5351_CLK_DRIVE_STRENGTH_2MA|SI5351_CLK_PLL_SELECT_A); si5351_set_frequency_fixedpll(2, XTALFREQ * PLL_N, CLK2_FREQUENCY, SI5351_R_DIV_1, SI5351_CLK_DRIVE_STRENGTH_2MA|SI5351_CLK_PLL_SELECT_A);
delay+=DELAY_BANDCHANGE_1;
} }
// Calculate and set CH0 and CH1 divider // Calculate and set CH0 and CH1 divider
si5351_set_frequency_fixedpll(0, (uint64_t)omul * XTALFREQ * PLL_N, ofreq, rdiv, drive_strength|SI5351_CLK_PLL_SELECT_A); si5351_set_frequency_fixedpll(0, (uint64_t)omul * XTALFREQ * PLL_N, ofreq, rdiv, drive_strength|SI5351_CLK_PLL_SELECT_A);
@ -401,6 +404,7 @@ si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_streng
if (current_band != band){ if (current_band != band){
si5351_setupMultisynth(0, fdiv, 0, 1, SI5351_R_DIV_1, drive_strength|SI5351_CLK_PLL_SELECT_A); si5351_setupMultisynth(0, fdiv, 0, 1, SI5351_R_DIV_1, drive_strength|SI5351_CLK_PLL_SELECT_A);
si5351_setupMultisynth(1, fdiv, 0, 1, SI5351_R_DIV_1, drive_strength|SI5351_CLK_PLL_SELECT_B); si5351_setupMultisynth(1, fdiv, 0, 1, SI5351_R_DIV_1, drive_strength|SI5351_CLK_PLL_SELECT_B);
delay+=DELAY_BANDCHANGE_2;
} }
// Calculate and set CH0 and CH1 PLL freq // Calculate and set CH0 and CH1 PLL freq
si5351_setupPLL_freq(SI5351_REG_PLL_A, ofreq, fdiv, omul);// set PLLA freq = (ofreq/omul)*fdiv si5351_setupPLL_freq(SI5351_REG_PLL_A, ofreq, fdiv, omul);// set PLLA freq = (ofreq/omul)*fdiv
@ -413,7 +417,6 @@ si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_streng
if (current_band != band) { if (current_band != band) {
si5351_reset_pll(SI5351_PLL_RESET_A|SI5351_PLL_RESET_B); si5351_reset_pll(SI5351_PLL_RESET_A|SI5351_PLL_RESET_B);
current_band = band; current_band = band;
delay+=DELAY_BANDCHANGE;
} }
return delay; return delay;
} }

2
ui.c
View file

@ -1358,7 +1358,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
*fg = config.menu_normal_color; *fg = config.menu_normal_color;
} }
} else if (menu == menu_stimulus) { } else if (menu == menu_stimulus) {
if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_MODE_ENABLED)) { if (item == 5 /* PAUSE */ && !sweep_enabled) {
*bg = DEFAULT_MENU_TEXT_COLOR; *bg = DEFAULT_MENU_TEXT_COLOR;
*fg = config.menu_normal_color; *fg = config.menu_normal_color;
} }