Optimize stack usage by shifting test and calibrate to lowest level

tinySA
erikkaashoek 6 years ago
parent 766eecc057
commit 7d64766513

@ -117,7 +117,7 @@ const char *info_about[]={
0 // sentinel 0 // sentinel
}; };
static THD_WORKING_AREA(waThread1, 730); static THD_WORKING_AREA(waThread1, 900);
static THD_FUNCTION(Thread1, arg) static THD_FUNCTION(Thread1, arg)
{ {
(void)arg; (void)arg;
@ -128,6 +128,10 @@ static THD_FUNCTION(Thread1, arg)
if (sweep_mode&(SWEEP_ENABLE|SWEEP_ONCE)) { if (sweep_mode&(SWEEP_ENABLE|SWEEP_ONCE)) {
completed = sweep(true); completed = sweep(true);
sweep_mode&=~SWEEP_ONCE; sweep_mode&=~SWEEP_ONCE;
} else if (sweep_mode & SWEEP_SELFTEST) {
self_test(); // call from lowest level to save stack space
} else if (sweep_mode & SWEEP_CALIBRATE) {
calibrate(); // call from lowest level to save stack space
} else { } else {
__WFI(); __WFI();
} }

@ -139,6 +139,9 @@ enum {
#define SWEEP_ENABLE 0x01 #define SWEEP_ENABLE 0x01
#define SWEEP_ONCE 0x02 #define SWEEP_ONCE 0x02
#define SWEEP_CALIBRATE 0x04
#define SWEEP_SELFTEST 0x08
extern int8_t sweep_mode; extern int8_t sweep_mode;
extern const char *info_about[]; extern const char *info_about[];

@ -1838,6 +1838,15 @@ static void cell_draw_marker_info(int x0, int y0)
cell_drawstring_7x13(buf, xpos, ypos); cell_drawstring_7x13(buf, xpos, ypos);
break; break;
} }
if (i >= 2 && in_selftest) {
plot_printf(buf, sizeof buf, "DO NOT SWITCH OFF!!");
j = 2;
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*(16) - y0;
cell_drawstring_7x13(buf, xpos, ypos);
break;
}
if (!markers[i].enabled) if (!markers[i].enabled)
continue; continue;
int idx = markers[i].index; int idx = markers[i].index;

@ -1074,7 +1074,7 @@ static const struct {
{TC_FLAT, TP_10MHZEXTRA, 10, 4, -25, 20, -70}, // 8 BPF pass band flatness {TC_FLAT, TP_10MHZEXTRA, 10, 4, -25, 20, -70}, // 8 BPF pass band flatness
{TC_BELOW, TP_30MHZ, 430, 60, -75, 0, -85}, // 9 LPF cutoff {TC_BELOW, TP_30MHZ, 430, 60, -75, 0, -85}, // 9 LPF cutoff
{TC_END, 0, 0, 0, 0, 0, 0}, {TC_END, 0, 0, 0, 0, 0, 0},
{TC_MEASURE, TP_30MHZ, 30, 7, -25, 30, -85 }, // 11 Measure power level and noise {TC_MEASURE, TP_30MHZ, 30, 7, -25, 30, -80 }, // 11 Measure power level and noise
{TC_MEASURE, TP_30MHZ, 270, 4, -50, 30, -85 }, // 13 Measure powerlevel and noise {TC_MEASURE, TP_30MHZ, 270, 4, -50, 30, -85 }, // 13 Measure powerlevel and noise
{TC_MEASURE, TPH_30MHZ, 270, 4, -50, 30, -85 }, // 14 Calibrate power high mode {TC_MEASURE, TPH_30MHZ, 270, 4, -50, 30, -85 }, // 14 Calibrate power high mode
{TC_END, 0, 0, 0, 0, 0, 0}, {TC_END, 0, 0, 0, 0, 0, 0},
@ -1129,7 +1129,7 @@ void cell_draw_test_info(int x0, int y0)
do { do {
i++; i++;
int xpos = 25 - x0; int xpos = 25 - x0;
int ypos = 40+i*INFO_SPACING - y0; int ypos = 50+i*INFO_SPACING - y0;
unsigned int color = RGBHEX(0xFFFFFF); unsigned int color = RGBHEX(0xFFFFFF);
if (i == -1) { if (i == -1) {
plot_printf(self_test_status_buf, sizeof self_test_status_buf, "Self test status:"); plot_printf(self_test_status_buf, sizeof self_test_status_buf, "Self test status:");
@ -1341,7 +1341,6 @@ common_silent:
} }
extern void menu_autosettings_cb(int item); extern void menu_autosettings_cb(int item);
extern void touch_wait_release(void);
void self_test(void) void self_test(void)
{ {
@ -1359,25 +1358,25 @@ void self_test(void)
test_prepare(i); test_prepare(i);
test_acquire(i); // Acquire test test_acquire(i); // Acquire test
test_status[i] = test_validate(i); // Validate test test_status[i] = test_validate(i); // Validate test
chThdSleepMilliseconds(1000);
if (test_status[i] != TS_PASS) { if (test_status[i] != TS_PASS) {
touch_wait_release(); wait_user();
} }
i++; i++;
} }
touch_wait_release(); ili9341_set_foreground(BRIGHT_COLOR_GREEN);
// chThdSleepMilliseconds(2000); ili9341_drawstring_7x13("Self test complete", 30, 120);
ili9341_drawstring_7x13("Touch screen to continue", 30, 140);
wait_user();
sweep_mode = SWEEP_ENABLE;
show_test_info = FALSE; show_test_info = FALSE;
trace[TRACE_STORED].enabled = false; trace[TRACE_STORED].enabled = false;
set_trace_refpos(0, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(0, NGRIDY - (-10) / get_trace_scale(0));
set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0));
set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0));
set_refer_output(0); set_refer_output(0);
SetMode(M_LOW); reset_settings(M_LOW);
SetAverage(0);
draw_cal_status();
in_selftest = false; in_selftest = false;
menu_autosettings_cb(0);
} }
void reset_calibration(void) void reset_calibration(void)
@ -1394,18 +1393,21 @@ void calibrate(void)
float last_peak_level; float last_peak_level;
in_selftest = true; in_selftest = true;
SetPowerLevel(100); SetPowerLevel(100);
menu_autosettings_cb(0); reset_settings(M_LOW);
int i = 10; // calibrate low mode power on 30 MHz; int i = 10; // calibrate low mode power on 30 MHz;
for (int j= 0; j < CALIBRATE_RBWS; j++ ) { for (int j= 0; j < CALIBRATE_RBWS; j++ ) {
SetRBW(power_rbw[j]); SetRBW(power_rbw[j]);
test_prepare(i); test_prepare(i);
test_acquire(i); // Acquire test test_acquire(i); // Acquire test
local_test_status = test_validate(i); // Validate test local_test_status = test_validate(i); // Validate test
chThdSleepMilliseconds(1000); // chThdSleepMilliseconds(1000);
if (local_test_status != TS_PASS) { if (local_test_status != TS_PASS) {
// touch_wait_release(); ili9341_set_foreground(BRIGHT_COLOR_RED);
ili9341_drawstring_7x13("Calibration failed", 30, 120);
goto quit;
} else } else
SetPowerLevel(-25); SetPowerLevel(-25);
goto done;
} }
i = 11; // Measure 270MHz in low mode i = 11; // Measure 270MHz in low mode
SetRBW(100); SetRBW(100);
@ -1423,23 +1425,28 @@ void calibrate(void)
test_prepare(i); test_prepare(i);
test_acquire(i); // Acquire test test_acquire(i); // Acquire test
local_test_status = test_validate(i); // Validate test local_test_status = test_validate(i); // Validate test
chThdSleepMilliseconds(1000);
if (local_test_status != TS_PASS) { if (local_test_status != TS_PASS) {
touch_wait_release(); ili9341_set_foreground(BRIGHT_COLOR_RED);
ili9341_drawstring_7x13("Calibration failed", 30, 120);
goto quit;
} else } else
SetPowerLevel(last_peak_level); SetPowerLevel(last_peak_level);
} }
touch_wait_release(); done:
ili9341_set_foreground(BRIGHT_COLOR_GREEN);
ili9341_drawstring_7x13("Calibration complete", 30, 120);
quit:
ili9341_drawstring_7x13("Touch screen to continue", 30, 140);
wait_user();
in_selftest = false;
sweep_mode = SWEEP_ENABLE;
trace[TRACE_STORED].enabled = false; trace[TRACE_STORED].enabled = false;
set_trace_refpos(0, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(0, NGRIDY - (-10) / get_trace_scale(0));
set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0));
set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0));
set_refer_output(0); set_refer_output(0);
SetMode(M_LOW); reset_settings(M_LOW);
SetAverage(0);
draw_cal_status();
in_selftest = false;
menu_autosettings_cb(0);
} }

17
ui.c

@ -2469,3 +2469,20 @@ ui_init()
touch_start_watchdog(); touch_start_watchdog();
} }
void wait_user(void)
{
adc_stop();
touch_wait_release();
#if 0
operation_requested = OP_NONE;
while (true) {
if (operation_requested & OP_TOUCH)
break;
if (operation_requested & OP_LEVER)
break;
}
#endif
touch_start_watchdog();
}

@ -242,7 +242,7 @@ static void menu_calibrate_cb(int item, uint8_t data)
(void)data; (void)data;
switch (item) { switch (item) {
case 1: case 1:
calibrate(); sweep_mode = SWEEP_CALIBRATE;
menu_move_back(); menu_move_back();
ui_mode_normal(); ui_mode_normal();
break; break;
@ -272,7 +272,7 @@ static void menu_config_cb(int item, uint8_t data)
case 2: case 2:
menu_move_back(); menu_move_back();
ui_mode_normal(); ui_mode_normal();
self_test(); sweep_mode = SWEEP_SELFTEST;
break; break;
case 4: case 4:
show_version(); show_version();

Loading…
Cancel
Save

Powered by TurnKey Linux.