[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 <lk/debug.h>
|
||||||
#include <lib/console.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) {
|
static void shell_entry(const struct app_descriptor *app, void *args) {
|
||||||
console_start();
|
console_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
APP_START(shell)
|
APP_START(shell)
|
||||||
.init = shell_init,
|
|
||||||
.entry = shell_entry,
|
.entry = shell_entry,
|
||||||
APP_END
|
APP_END
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#include <lib/env.h>
|
#include <lib/env.h>
|
||||||
#endif
|
#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
|
#ifndef CONSOLE_ENABLE_HISTORY
|
||||||
#define CONSOLE_ENABLE_HISTORY 1
|
#define CONSOLE_ENABLE_HISTORY 1
|
||||||
#endif
|
#endif
|
||||||
@@ -36,8 +38,6 @@
|
|||||||
|
|
||||||
#define MAX_NUM_ARGS 16
|
#define MAX_NUM_ARGS 16
|
||||||
|
|
||||||
#define HISTORY_LEN 16
|
|
||||||
|
|
||||||
#define LOCAL_TRACE 0
|
#define LOCAL_TRACE 0
|
||||||
|
|
||||||
#define WHITESPACE " \t"
|
#define WHITESPACE " \t"
|
||||||
@@ -55,10 +55,10 @@ static bool abort_script;
|
|||||||
|
|
||||||
#if CONSOLE_ENABLE_HISTORY
|
#if CONSOLE_ENABLE_HISTORY
|
||||||
/* command history stuff */
|
/* command history stuff */
|
||||||
static char *history; // HISTORY_LEN rows of LINE_LEN chars a piece
|
#define HISTORY_LEN 16
|
||||||
static uint history_next;
|
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 void add_history(const char *line);
|
||||||
static uint start_history_cursor(void);
|
static uint start_history_cursor(void);
|
||||||
static const char *next_history(uint *cursor);
|
static const char *next_history(uint *cursor);
|
||||||
@@ -98,16 +98,6 @@ STATIC_COMMAND("repeat", "repeats command multiple times", &cmd_repeat)
|
|||||||
#endif
|
#endif
|
||||||
STATIC_COMMAND_END(help);
|
STATIC_COMMAND_END(help);
|
||||||
|
|
||||||
int console_init(void) {
|
|
||||||
LTRACE_ENTRY;
|
|
||||||
|
|
||||||
#if CONSOLE_ENABLE_HISTORY
|
|
||||||
init_history();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CONSOLE_ENABLE_HISTORY
|
#if CONSOLE_ENABLE_HISTORY
|
||||||
static int cmd_history(int argc, const cmd_args *argv) {
|
static int cmd_history(int argc, const cmd_args *argv) {
|
||||||
dump_history();
|
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) {
|
static void add_history(const char *line) {
|
||||||
// reject some stuff
|
// reject some stuff
|
||||||
if (line[0] == 0)
|
if (line[0] == 0)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <lib/console/cmd.h>
|
#include <lib/console/cmd.h>
|
||||||
|
|
||||||
/* external api */
|
/* external api */
|
||||||
int console_init(void);
|
|
||||||
void console_start(void);
|
void console_start(void);
|
||||||
int console_run_script(const char *string);
|
int console_run_script(const char *string);
|
||||||
int console_run_script_locked(const char *string); // special case from inside a command
|
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
|
MODULE_SRCS := $(LOCAL_DIR)/target.c
|
||||||
|
|
||||||
# set some global defines based on capability
|
# set some global defines based on capability
|
||||||
|
GLOBAL_DEFINES += CONSOLE_ENABLE_HISTORY=0
|
||||||
GLOBAL_DEFINES += PLATFORM_HAS_DYNAMIC_TIMER=1
|
GLOBAL_DEFINES += PLATFORM_HAS_DYNAMIC_TIMER=1
|
||||||
GLOBAL_DEFINES += ARCH_RISCV_CLINT_BASE=0x02000000
|
GLOBAL_DEFINES += ARCH_RISCV_CLINT_BASE=0x02000000
|
||||||
GLOBAL_DEFINES += ARCH_RISCV_MTIME_RATE=32768
|
GLOBAL_DEFINES += ARCH_RISCV_MTIME_RATE=32768
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ STELLARIS_CHIP := LM4F120H5QR
|
|||||||
PLATFORM := stellaris
|
PLATFORM := stellaris
|
||||||
|
|
||||||
GLOBAL_DEFINES += \
|
GLOBAL_DEFINES += \
|
||||||
|
CONSOLE_ENABLE_HISTORY=0 \
|
||||||
TARGET_HAS_DEBUG_LED=1 \
|
TARGET_HAS_DEBUG_LED=1 \
|
||||||
CRYSTAL_FREQ=16000000
|
CRYSTAL_FREQ=16000000
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user