Skip to content

Commit

Permalink
static inline reduce stack memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cho45 committed Aug 28, 2019
1 parent e1d2b0e commit 480ad0f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage
endif

# C specific options here (added to USE_OPT).
Expand Down
13 changes: 13 additions & 0 deletions chconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,19 @@

#define CHPRINTF_USE_FLOAT TRUE

/**
* ChibiOS/os/various/shell/shell_cmd.c
*/
#define SHELL_CMD_EXIT_ENABLED TRUE
#define SHELL_CMD_INFO_ENABLED TRUE
#define SHELL_CMD_ECHO_ENABLED FALSE
#define SHELL_CMD_SYSTIME_ENABLED FALSE
#define SHELL_CMD_MEM_ENABLED FALSE
#define SHELL_CMD_THREADS_ENABLED TRUE
#define SHELL_CMD_TEST_ENABLED FALSE



#endif /* _CHCONF_H_ */

/** @} */
7 changes: 3 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int8_t cal_auto_interpolate = TRUE;
int8_t redraw_requested = FALSE;
int8_t stop_the_world = FALSE;

static THD_WORKING_AREA(waThread1, 768);
static THD_WORKING_AREA(waThread1, 640);
static THD_FUNCTION(Thread1, arg)
{
(void)arg;
Expand Down Expand Up @@ -1289,7 +1289,7 @@ const struct {
{ "X", 4, 100 }
};

const char *trc_channel_name[] = {
const char * const trc_channel_name[] = {
"CH0", "CH1"
};

Expand Down Expand Up @@ -1737,8 +1737,7 @@ static void cmd_version(BaseSequentialStream *chp, int argc, char *argv[])
chprintf(chp, "%s\r\n", NANOVNA_VERSION);
}

#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(256)
static THD_WORKING_AREA(waThread2, SHELL_WA_SIZE);
static THD_WORKING_AREA(waThread2, /* cmd_* max stack size + alpha */410);

static const ShellCommand commands[] =
{
Expand Down
20 changes: 10 additions & 10 deletions plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#define SWAP(x,y) do { int z=x; x = y; y = z; } while(0)

void cell_draw_marker_info(int m, int n, int w, int h);
static void cell_draw_marker_info(int m, int n, int w, int h);
void draw_frequencies(void);
void frequency_string(char *buf, size_t len, int32_t freq);
void markmap_all_markers(void);
Expand Down Expand Up @@ -534,7 +534,7 @@ trace_into_index(int x, int t, int i, float coeff[2])
return INDEX(x +CELLOFFSETX, y, i);
}

int
static int
string_value_with_prefix(char *buf, int len, float val, char unit)
{
char prefix;
Expand Down Expand Up @@ -591,7 +591,7 @@ string_value_with_prefix(char *buf, int len, float val, char unit)

#define PI2 6.283184

void
static void
gamma2imp(char *buf, int len, const float coeff[2], uint32_t frequency)
{
// z = (gamma+1)/(gamma-1) * z0
Expand All @@ -613,7 +613,7 @@ gamma2imp(char *buf, int len, const float coeff[2], uint32_t frequency)
}
}

void
static void
gamma2resistance(char *buf, int len, const float coeff[2], uint32_t frequency)
{
float z0 = 50;
Expand All @@ -622,7 +622,7 @@ gamma2resistance(char *buf, int len, const float coeff[2], uint32_t frequency)
string_value_with_prefix(buf, len, zr, S_OHM[0]);
}

void
static void
gamma2reactance(char *buf, int len, const float coeff[2], uint32_t frequency)
{
float z0 = 50;
Expand All @@ -631,7 +631,7 @@ gamma2reactance(char *buf, int len, const float coeff[2], uint32_t frequency)
string_value_with_prefix(buf, len, zi, S_OHM[0]);
}

void
static void
trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequency)
{
float v;
Expand Down Expand Up @@ -721,7 +721,7 @@ markmap_upperarea(void)
markmap[current_mappage][0] |= 0xffff;
}

static void
static inline void
swap_markmap(void)
{
current_mappage = 1 - current_mappage;
Expand All @@ -733,7 +733,7 @@ clear_markmap(void)
memset(markmap[current_mappage], 0, sizeof markmap[current_mappage]);
}

void
void inline
force_set_markmap(void)
{
memset(markmap[current_mappage], 0xff, sizeof markmap[current_mappage]);
Expand Down Expand Up @@ -1107,7 +1107,7 @@ markmap_all_markers(void)
}


void
static void
draw_cell(int m, int n)
{
int x0 = m * CELLWIDTH;
Expand Down Expand Up @@ -1330,7 +1330,7 @@ cell_drawstring_invert_5x7(int w, int h, char *str, int x, int y, uint16_t fg, i
}
}

void
static void
cell_draw_marker_info(int m, int n, int w, int h)
{
char buf[24];
Expand Down
27 changes: 14 additions & 13 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void draw_menu(void);
void leave_ui_mode(void);
void erase_menu_buttons(void);
void ui_process_keypad(void);
void ui_process_numeric(void);
static void ui_process_numeric(void);

static void menu_push_submenu(const menuitem_t *submenu);

Expand Down Expand Up @@ -1042,7 +1042,7 @@ const keypads_t keypads_time[] = {
{ 0, 0, -1 }
};

const keypads_t *keypads_mode_tbl[] = {
const keypads_t * const keypads_mode_tbl[] = {
keypads_freq, // start
keypads_freq, // stop
keypads_freq, // center
Expand All @@ -1053,7 +1053,7 @@ const keypads_t *keypads_mode_tbl[] = {
keypads_time // electrical delay
};

const char *keypad_mode_label[] = {
const char * const keypad_mode_label[] = {
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY"
};

Expand Down Expand Up @@ -1409,7 +1409,7 @@ ui_mode_normal(void)
ui_mode = UI_NORMAL;
}

void
static void
ui_process_normal(void)
{
int status = btn_check();
Expand Down Expand Up @@ -1438,7 +1438,7 @@ ui_process_normal(void)
}
}

void
static void
ui_process_menu(void)
{
int status = btn_check();
Expand All @@ -1463,7 +1463,7 @@ ui_process_menu(void)
}
}

int
static int
keypad_click(int key)
{
int c = keypads[key].c;
Expand Down Expand Up @@ -1527,7 +1527,7 @@ keypad_click(int key)
return KP_CONTINUE;
}

int
static int
keypad_apply_touch(void)
{
int touch_x, touch_y;
Expand Down Expand Up @@ -1556,7 +1556,7 @@ keypad_apply_touch(void)
return -1;
}

void
static void
numeric_apply_touch(void)
{
int touch_x, touch_y;
Expand Down Expand Up @@ -1597,7 +1597,7 @@ numeric_apply_touch(void)
return;
}

void
static void
ui_process_numeric(void)
{
int status = btn_check();
Expand Down Expand Up @@ -1720,7 +1720,7 @@ ui_process_keypad(void)
touch_start_watchdog();
}

void
static void
ui_process_lever(void)
{
switch (ui_mode) {
Expand All @@ -1740,7 +1740,8 @@ ui_process_lever(void)
}


void drag_marker(int t, int m)
static void
drag_marker(int t, int m)
{
int status;
/* wait touch release */
Expand All @@ -1767,7 +1768,7 @@ sq_distance(int x0, int y0)
return x0*x0 + y0*y0;
}

int
static int
touch_pickup_marker(void)
{
int touch_x, touch_y;
Expand Down Expand Up @@ -1807,7 +1808,7 @@ touch_pickup_marker(void)
}



static
void ui_process_touch(void)
{
awd_count++;
Expand Down

0 comments on commit 480ad0f

Please sign in to comment.