[console] move the history buffer into static memory, remove console_init
No need to malloc this memory if it's always going to be initialized anyway. Add history disabling switch to a few targets to make sure both builds are tested.
This commit is contained in:
@@ -9,16 +9,11 @@
|
||||
#include <lk/debug.h>
|
||||
#include <lib/console.h>
|
||||
|
||||
static void shell_init(const struct app_descriptor *app) {
|
||||
console_init();
|
||||
}
|
||||
|
||||
static void shell_entry(const struct app_descriptor *app, void *args) {
|
||||
console_start();
|
||||
}
|
||||
|
||||
APP_START(shell)
|
||||
.init = shell_init,
|
||||
.entry = shell_entry,
|
||||
APP_END
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <lib/env.h>
|
||||
#endif
|
||||
|
||||
// Whether to enable command line history. Uses a nonzero
|
||||
// amount of memory, probably shouldn't enable for memory constrained devices.
|
||||
#ifndef CONSOLE_ENABLE_HISTORY
|
||||
#define CONSOLE_ENABLE_HISTORY 1
|
||||
#endif
|
||||
@@ -36,8 +38,6 @@
|
||||
|
||||
#define MAX_NUM_ARGS 16
|
||||
|
||||
#define HISTORY_LEN 16
|
||||
|
||||
#define LOCAL_TRACE 0
|
||||
|
||||
#define WHITESPACE " \t"
|
||||
@@ -55,10 +55,10 @@ static bool abort_script;
|
||||
|
||||
#if CONSOLE_ENABLE_HISTORY
|
||||
/* command history stuff */
|
||||
static char *history; // HISTORY_LEN rows of LINE_LEN chars a piece
|
||||
static uint history_next;
|
||||
#define HISTORY_LEN 16
|
||||
static char history[HISTORY_LEN * LINE_LEN];
|
||||
static uint history_next = 0;
|
||||
|
||||
static void init_history(void);
|
||||
static void add_history(const char *line);
|
||||
static uint start_history_cursor(void);
|
||||
static const char *next_history(uint *cursor);
|
||||
@@ -98,16 +98,6 @@ STATIC_COMMAND("repeat", "repeats command multiple times", &cmd_repeat)
|
||||
#endif
|
||||
STATIC_COMMAND_END(help);
|
||||
|
||||
int console_init(void) {
|
||||
LTRACE_ENTRY;
|
||||
|
||||
#if CONSOLE_ENABLE_HISTORY
|
||||
init_history();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CONSOLE_ENABLE_HISTORY
|
||||
static int cmd_history(int argc, const cmd_args *argv) {
|
||||
dump_history();
|
||||
@@ -137,12 +127,6 @@ static void dump_history(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void init_history(void) {
|
||||
/* allocate and set up the history buffer */
|
||||
history = calloc(1, HISTORY_LEN * LINE_LEN);
|
||||
history_next = 0;
|
||||
}
|
||||
|
||||
static void add_history(const char *line) {
|
||||
// reject some stuff
|
||||
if (line[0] == 0)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <lib/console/cmd.h>
|
||||
|
||||
/* external api */
|
||||
int console_init(void);
|
||||
void console_start(void);
|
||||
int console_run_script(const char *string);
|
||||
int console_run_script_locked(const char *string); // special case from inside a command
|
||||
|
||||
@@ -15,6 +15,7 @@ GLOBAL_DEFINES += SIFIVE_FREQ=16000000
|
||||
MODULE_SRCS := $(LOCAL_DIR)/target.c
|
||||
|
||||
# set some global defines based on capability
|
||||
GLOBAL_DEFINES += CONSOLE_ENABLE_HISTORY=0
|
||||
GLOBAL_DEFINES += PLATFORM_HAS_DYNAMIC_TIMER=1
|
||||
GLOBAL_DEFINES += ARCH_RISCV_CLINT_BASE=0x02000000
|
||||
GLOBAL_DEFINES += ARCH_RISCV_MTIME_RATE=32768
|
||||
|
||||
@@ -6,6 +6,7 @@ STELLARIS_CHIP := LM4F120H5QR
|
||||
PLATFORM := stellaris
|
||||
|
||||
GLOBAL_DEFINES += \
|
||||
CONSOLE_ENABLE_HISTORY=0 \
|
||||
TARGET_HAS_DEBUG_LED=1 \
|
||||
CRYSTAL_FREQ=16000000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user