Disable unused ChibiOS options:

CH_CFG_USE_WAITEXIT (used only is Shell run as thread)
CH_CFG_USE_EVENTS (NanoVNA not use events)
CH_CFG_USE_EVENTS_TIMEOUT (NanoVNA not use events)

Implement stack use check in "threads" command, now free stack space show in table as "stk free" in hex
Check stack usage by sweep, and main threads (seems all ok, but add 64 bytes to sweep)

Replace some const values to defined
This commit is contained in:
DiSlord 2020-02-27 20:53:45 +03:00
parent d386b0823c
commit 17734f257d
4 changed files with 129 additions and 113 deletions

View file

@ -156,7 +156,7 @@
* *
* @note The default is @p TRUE. * @note The default is @p TRUE.
*/ */
#define CH_CFG_USE_WAITEXIT TRUE #define CH_CFG_USE_WAITEXIT FALSE
/** /**
* @brief Semaphores APIs. * @brief Semaphores APIs.
@ -221,7 +221,7 @@
* *
* @note The default is @p TRUE. * @note The default is @p TRUE.
*/ */
#define CH_CFG_USE_EVENTS TRUE #define CH_CFG_USE_EVENTS FALSE
/** /**
* @brief Events Flags APIs with timeout. * @brief Events Flags APIs with timeout.
@ -231,7 +231,7 @@
* @note The default is @p TRUE. * @note The default is @p TRUE.
* @note Requires @p CH_CFG_USE_EVENTS. * @note Requires @p CH_CFG_USE_EVENTS.
*/ */
#define CH_CFG_USE_EVENTS_TIMEOUT TRUE #define CH_CFG_USE_EVENTS_TIMEOUT FALSE
/** /**
* @brief Synchronous Messages APIs. * @brief Synchronous Messages APIs.

64
main.c
View file

@ -80,7 +80,11 @@ int8_t cal_auto_interpolate = TRUE;
uint16_t redraw_request = 0; // contains REDRAW_XXX flags uint16_t redraw_request = 0; // contains REDRAW_XXX flags
int16_t vbat = 0; int16_t vbat = 0;
static THD_WORKING_AREA(waThread1, 512); //
// Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show:
// Stack maximum usage = 480 bytes, free stack = 32+64 bytes
//
static THD_WORKING_AREA(waThread1, 512+64);
static THD_FUNCTION(Thread1, arg) static THD_FUNCTION(Thread1, arg)
{ {
(void)arg; (void)arg;
@ -110,7 +114,7 @@ static THD_FUNCTION(Thread1, arg)
draw_battery_status(); draw_battery_status();
} }
/* calculate trace coordinates and plot only if scan completed */ // calculate trace coordinates and plot only if scan completed
if (completed) { if (completed) {
plot_into_index(measured); plot_into_index(measured);
redraw_request |= REDRAW_CELLS; redraw_request |= REDRAW_CELLS;
@ -124,8 +128,7 @@ static THD_FUNCTION(Thread1, arg)
} }
} }
} }
// plot trace and other indications as raster
/* plot trace and other indications as raster */
draw_all(completed); // flush markmap only if scan completed to prevent remaining traces draw_all(completed); // flush markmap only if scan completed to prevent remaining traces
chMtxUnlock(&mutex); chMtxUnlock(&mutex);
} }
@ -207,6 +210,7 @@ transform_domain(void)
break; break;
} }
for (int ch = 0; ch < 2; ch++) { for (int ch = 0; ch < 2; ch++) {
memcpy(tmp, measured[ch], sizeof(measured[0])); memcpy(tmp, measured[ch], sizeof(measured[0]));
for (int i = 0; i < POINTS_COUNT; i++) { for (int i = 0; i < POINTS_COUNT; i++) {
@ -1939,12 +1943,22 @@ VNA_SHELL_FUNCTION(cmd_threads) {
thread_t *tp; thread_t *tp;
(void)argc; (void)argc;
(void)argv; (void)argv;
chprintf(chp, "stklimit stack addr refs prio state name"VNA_SHELL_NEWLINE_STR); shell_printf("stklimit| stack|stk free| addr|refs|prio| state| name"VNA_SHELL_NEWLINE_STR);
tp = chRegFirstThread(); tp = chRegFirstThread();
do { do {
uint32_t max_stack_use = 0U;
#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
uint32_t stklimit = (uint32_t)tp->wabase; uint32_t stklimit = (uint32_t)tp->wabase;
shell_printf("%08x %08x %08x %4u %4u %9s %12s"VNA_SHELL_NEWLINE_STR, #if CH_DBG_FILL_THREADS == TRUE
stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp, uint8_t *p = (uint8_t *)tp->wabase; while(p[max_stack_use]==CH_DBG_STACK_FILL_VALUE) max_stack_use++;
#endif
#else
uint32_t stklimit = 0U;
#endif
shell_printf("%08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s"VNA_SHELL_NEWLINE_STR,
stklimit, (uint32_t)tp->ctx.sp, max_stack_use, (uint32_t)tp,
(uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state],
tp->name == NULL ? "" : tp->name); tp->name == NULL ? "" : tp->name);
tp = chRegNextThread(tp); tp = chRegNextThread(tp);
@ -2142,6 +2156,11 @@ static DACConfig dac1cfg1 = {
datamode: DAC_DHRM_12BIT_RIGHT datamode: DAC_DHRM_12BIT_RIGHT
}; };
// Main thread stack size defined in makefile USE_PROCESS_STACKSIZE = 0x200
// Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show:
// Stack maximum usage = 472 bytes (need test more and run all commands), free stack = 40 bytes
//
int main(void) int main(void)
{ {
halInit(); halInit();
@ -2156,13 +2175,12 @@ int main(void)
// MCO on PA8 // MCO on PA8
//palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(0)); //palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(0));
/* /*
* Initializes a serial-over-USB CDC driver. * Initializes a serial-over-USB CDC driver.
*/ */
sduObjectInit(&SDU1); sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg); sduStart(&SDU1, &serusbcfg);
/*
/*
* Activates the USB driver and then the USB bus pull-up on D+. * Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable * Note, a delay is inserted in order to not have to disconnect the cable
* after a reset. * after a reset.
@ -2172,36 +2190,29 @@ int main(void)
usbStart(serusbcfg.usbp, &usbcfg); usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp); usbConnectBus(serusbcfg.usbp);
/* /*
* SPI LCD Initialize * SPI LCD Initialize
*/ */
ili9341_init(); ili9341_init();
/* /* restore config */
* Initialize graph plotting
*/
plot_init();
/* restore config */
config_recall(); config_recall();
dac1cfg1.init = config.dac_value; dac1cfg1.init = config.dac_value;
/* /*
* Starting DAC1 driver, setting up the output pin as analog as suggested * Starting DAC1 driver, setting up the output pin as analog as suggested
* by the Reference Manual. * by the Reference Manual.
*/ */
dacStart(&DACD2, &dac1cfg1); dacStart(&DACD2, &dac1cfg1);
/* initial frequencies */ /* initial frequencies */
update_frequencies(); update_frequencies();
/* restore frequencies and calibration properties from flash memory */ /* restore frequencies and calibration properties from flash memory */
if (config.default_loadcal >= 0) if (config.default_loadcal >= 0)
caldata_recall(config.default_loadcal); caldata_recall(config.default_loadcal);
redraw_frame(); /*
/*
* I2S Initialize * I2S Initialize
*/ */
tlv320aic3204_init(); tlv320aic3204_init();
@ -2211,12 +2222,17 @@ int main(void)
i2sStartExchange(&I2SD2); i2sStartExchange(&I2SD2);
ui_init(); ui_init();
//Initialize graph plotting
plot_init();
redraw_frame();
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL);
while (1) { while (1) {
if (SDU1.config->usbp->state == USB_ACTIVE) { if (SDU1.config->usbp->state == USB_ACTIVE) {
#ifdef VNA_SHELL_THREAD #ifdef VNA_SHELL_THREAD
#if CH_CFG_USE_WAITEXIT == FALSE
#error "VNA_SHELL_THREAD use chThdWait, need enable CH_CFG_USE_WAITEXIT in chconf.h"
#endif
thread_t *shelltp = chThdCreateStatic(waThread2, sizeof(waThread2), thread_t *shelltp = chThdCreateStatic(waThread2, sizeof(waThread2),
NORMALPRIO + 1, NORMALPRIO + 1,
myshellThread, NULL); myshellThread, NULL);

29
plot.c
View file

@ -1462,7 +1462,7 @@ cell_drawstring(char *str, int x, int y)
static void static void
cell_draw_marker_info(int x0, int y0) cell_draw_marker_info(int x0, int y0)
{ {
char buf[32]; char buf[24];
int t; int t;
if (active_marker < 0) if (active_marker < 0)
return; return;
@ -1474,8 +1474,8 @@ cell_draw_marker_info(int x0, int y0)
for (mk = 0; mk < MARKERS_MAX; mk++) { for (mk = 0; mk < MARKERS_MAX; mk++) {
if (!markers[mk].enabled) if (!markers[mk].enabled)
continue; continue;
int xpos = 1 + (j%2)*146 + CELLOFFSETX - x0; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8 - y0; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
setForegroundColor(config.trace_color[t]); setForegroundColor(config.trace_color[t]);
if (mk == active_marker) if (mk == active_marker)
@ -1507,13 +1507,13 @@ cell_draw_marker_info(int x0, int y0)
// draw marker delta // draw marker delta
if (!uistat.marker_delta && previous_marker >= 0 && active_marker != previous_marker && markers[previous_marker].enabled) { if (!uistat.marker_delta && previous_marker >= 0 && active_marker != previous_marker && markers[previous_marker].enabled) {
int idx0 = markers[previous_marker].index; int idx0 = markers[previous_marker].index;
int xpos = 180 + CELLOFFSETX - x0; int xpos = (WIDTH/2+30) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8 - y0; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
plot_printf(buf, sizeof buf, S_DELTA"%d-%d", active_marker+1, previous_marker+1); plot_printf(buf, sizeof buf, S_DELTA"%d-%d:", active_marker+1, previous_marker+1);
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
cell_drawstring(buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
xpos += 24; xpos += 27;
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
uint32_t freq = frequencies[idx]; uint32_t freq = frequencies[idx];
uint32_t freq1 = frequencies[idx0]; uint32_t freq1 = frequencies[idx0];
@ -1528,8 +1528,8 @@ cell_draw_marker_info(int x0, int y0)
for (t = 0; t < TRACES_MAX; t++) { for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled) if (!trace[t].enabled)
continue; continue;
int xpos = 1 + (j%2)*146 + CELLOFFSETX - x0; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8 - y0; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
setForegroundColor(config.trace_color[t]); setForegroundColor(config.trace_color[t]);
if (t == uistat.current_trace) if (t == uistat.current_trace)
@ -1550,8 +1550,8 @@ cell_draw_marker_info(int x0, int y0)
} }
// draw marker frequency // draw marker frequency
int xpos = 185 + CELLOFFSETX - x0; int xpos = (WIDTH/2+40) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8 - y0; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
if (uistat.lever_mode == LM_MARKER) if (uistat.lever_mode == LM_MARKER)
@ -1572,7 +1572,7 @@ cell_draw_marker_info(int x0, int y0)
if (electrical_delay != 0) { if (electrical_delay != 0) {
// draw electrical delay // draw electrical delay
int xpos = 21 + CELLOFFSETX - x0; int xpos = 21 + CELLOFFSETX - x0;
int ypos = 1 + ((j+1)/2)*8 - y0; int ypos = 1 + ((j+1)/2)*(FONT_GET_HEIGHT+1) - y0;
float light_speed_ps = 299792458e-12; //(m/ps) float light_speed_ps = 299792458e-12; //(m/ps)
plot_printf(buf, sizeof buf, "Edelay %Fs %Fm", electrical_delay * 1e-12, plot_printf(buf, sizeof buf, "Edelay %Fs %Fm", electrical_delay * 1e-12,
@ -1663,7 +1663,7 @@ draw_battery_status(void)
{ {
if (vbat<=0) if (vbat<=0)
return; return;
uint8_t string_buf[25]; uint8_t string_buf[16];
// Set battery color // Set battery color
setForegroundColor(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR); setForegroundColor(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR);
setBackgroundColor(DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
@ -1697,7 +1697,8 @@ request_to_redraw_grid(void)
void void
redraw_frame(void) redraw_frame(void)
{ {
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
clearScreen();
draw_frequencies(); draw_frequencies();
draw_cal_status(); draw_cal_status();
} }

15
ui.c
View file

@ -1271,7 +1271,7 @@ draw_numeric_area_frame(void)
ili9341_fill(0, 240-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, DEFAULT_MENU_COLOR); ili9341_fill(0, 240-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, DEFAULT_MENU_COLOR);
setForegroundColor(DEFAULT_MENU_TEXT_COLOR); setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
setBackgroundColor(DEFAULT_MENU_COLOR); setBackgroundColor(DEFAULT_MENU_COLOR);
ili9341_drawstring(keypad_mode_label[keypad_mode], 10, 240-FONT_GET_HEIGHT-(NUM_INPUT_HEIGHT-FONT_GET_HEIGHT)/2); ili9341_drawstring(keypad_mode_label[keypad_mode], 10, 240-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2);
//ili9341_drawfont(KP_KEYPAD, 300, 216); //ili9341_drawfont(KP_KEYPAD, 300, 216);
} }
@ -1297,8 +1297,8 @@ draw_numeric_input(const char *buf)
if (ui_mode == UI_NUMERIC && uistat.digit == 8-i) { if (ui_mode == UI_NUMERIC && uistat.digit == 8-i) {
fg = DEFAULT_SPEC_INPUT_COLOR; fg = DEFAULT_SPEC_INPUT_COLOR;
focused = TRUE; focused = TRUE;
if (uistat.digit_mode) // if (uistat.digit_mode)
bg = DEFAULT_MENU_COLOR; // bg = DEFAULT_MENU_COLOR;
} }
setForegroundColor(fg); setForegroundColor(fg);
setBackgroundColor(bg); setBackgroundColor(bg);
@ -1307,12 +1307,12 @@ draw_numeric_input(const char *buf)
else if (focused) // c not number, but focused else if (focused) // c not number, but focused
ili9341_drawfont(0, x, 240-NUM_INPUT_HEIGHT+4); ili9341_drawfont(0, x, 240-NUM_INPUT_HEIGHT+4);
else // erase else // erase
ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, 20, 24, bg); ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_HEIGHT, NUM_FONT_GET_WIDTH+2+8, bg);
x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2; x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2;
} }
// erase last // erase last
ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_WIDTH+2+8, 24, DEFAULT_MENU_COLOR); ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_WIDTH+2+8, NUM_FONT_GET_WIDTH+2+8, DEFAULT_MENU_COLOR);
} }
static int static int
@ -1607,7 +1607,7 @@ ui_mode_numeric(int _keypad_mode)
keypad_mode = _keypad_mode; keypad_mode = _keypad_mode;
ui_mode = UI_NUMERIC; ui_mode = UI_NUMERIC;
area_width = AREA_WIDTH_NORMAL; area_width = AREA_WIDTH_NORMAL;
area_height = 240-32;//AREA_HEIGHT_NORMAL - 32; area_height = 240-NUM_INPUT_HEIGHT;//AREA_HEIGHT_NORMAL - 32;
draw_numeric_area_frame(); draw_numeric_area_frame();
fetch_numeric_target(); fetch_numeric_target();
@ -1629,7 +1629,7 @@ ui_mode_keypad(int _keypad_mode)
keypads_last_index = i; keypads_last_index = i;
ui_mode = UI_KEYPAD; ui_mode = UI_KEYPAD;
area_width = AREA_WIDTH_NORMAL - 60; area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH;
area_height = HEIGHT - 32; area_height = HEIGHT - 32;
draw_menu(); draw_menu();
draw_keypad(); draw_keypad();
@ -2051,7 +2051,6 @@ ui_process_lever(void)
} }
} }
static void static void
drag_marker(int t, int m) drag_marker(int t, int m)
{ {