fix the bug of tos shell
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
#define SHELL_PARSER_TASK_STACK_SIZE 1024
|
||||
#define SHELL_PARSER_TASK_PRIO 3
|
||||
|
||||
typedef void (*shell_output_t)(const char *str);
|
||||
typedef void (*shell_output_t)(const char ch);
|
||||
|
||||
typedef struct shell_control_st {
|
||||
k_task_t parser;
|
||||
@@ -53,6 +53,8 @@ __API__ int tos_shell_cmd_set_unregiser(const shell_cmd_set_t *cmd_set);
|
||||
|
||||
__API__ void tos_shell_printf(const char *format, ...);
|
||||
|
||||
__API__ void tos_shell_printfln(const char *format, ...);
|
||||
|
||||
__API__ void tos_shell_input_byte(uint8_t data);
|
||||
|
||||
#endif /* _TOS_SHELL_H_ */
|
||||
|
@@ -33,6 +33,8 @@ typedef struct shell_command_set_st {
|
||||
const shell_cmd_t *const commands;
|
||||
} shell_cmd_set_t;
|
||||
|
||||
__KNL__ int cmd_help(int argc, char *argv[]);
|
||||
|
||||
__KNL__ int shell_cmd_set_regiser(const shell_cmd_set_t *cmd_set);
|
||||
|
||||
__KNL__ int shell_cmd_set_unregiser(const shell_cmd_set_t *cmd_set);
|
||||
|
@@ -35,10 +35,23 @@ __STATIC__ int shell_getchar(void)
|
||||
return err == K_ERR_NONE ? chr : -1;
|
||||
}
|
||||
|
||||
__STATIC__ void shell_putchar(const char ch)
|
||||
{
|
||||
SHELL_CTL->output(ch);
|
||||
}
|
||||
|
||||
__STATIC__ void shell_puts(const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
SHELL_CTL->output(*s++);
|
||||
}
|
||||
}
|
||||
|
||||
__STATIC__ int shell_readline(void)
|
||||
{
|
||||
int chr, last_chr = 0;
|
||||
int chr;
|
||||
char *buf = SHELL_CTL->cmd_buffer;
|
||||
uint16_t line_length = 0;
|
||||
|
||||
while (K_TRUE) {
|
||||
if (buf - SHELL_CTL->cmd_buffer >= (SHELL_CTL->cmd_buffer_size - 1)) {
|
||||
@@ -50,23 +63,29 @@ __STATIC__ int shell_readline(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (chr == '\n' && last_chr == '\r') {
|
||||
*--buf = '\0';
|
||||
return 0;
|
||||
} else if (chr == '\n') {
|
||||
if (chr == '\n' || chr == '\r') {
|
||||
*buf = '\0';
|
||||
return 0;
|
||||
tos_shell_printf("\r\n");
|
||||
break;
|
||||
} else if (chr == '\t'){
|
||||
*buf = '\0';
|
||||
tos_shell_printf("\r\n");
|
||||
cmd_help(0, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
*buf++ = chr;
|
||||
last_chr = chr;
|
||||
|
||||
shell_putchar(chr);
|
||||
|
||||
*buf++ = chr;
|
||||
line_length++;
|
||||
}
|
||||
return line_length;
|
||||
}
|
||||
|
||||
__STATIC__ void shell_cmd_do_process(int argc, char *argv[])
|
||||
{
|
||||
const shell_cmd_t *cmd;
|
||||
static const char *cmd_not_found = "command not found\n";
|
||||
static const char *cmd_not_found = "command not found\r\n";
|
||||
|
||||
cmd = shell_cmd_find(argv[0]);
|
||||
if (!cmd) {
|
||||
@@ -82,8 +101,6 @@ __STATIC__ void shell_cmd_process(void)
|
||||
static char *argv[SHELL_CMD_ARGV_MAX];
|
||||
char *pos = SHELL_CTL->cmd_buffer;
|
||||
|
||||
tos_shell_printf("%s\n", SHELL_CTL->cmd_buffer);
|
||||
|
||||
// left strip
|
||||
while (*pos == ' ' || *pos == '\t') {
|
||||
++pos;
|
||||
@@ -113,7 +130,7 @@ __STATIC__ void shell_cmd_process(void)
|
||||
|
||||
__STATIC__ void shell_prompt(void)
|
||||
{
|
||||
tos_shell_printf("> ");
|
||||
tos_shell_printf("tshell>");
|
||||
}
|
||||
|
||||
__STATIC__ void shell_parser(void *arg)
|
||||
@@ -125,7 +142,7 @@ __STATIC__ void shell_parser(void *arg)
|
||||
while (K_TRUE) {
|
||||
rc = shell_readline();
|
||||
|
||||
if (!rc) {
|
||||
if (rc > 0) {
|
||||
shell_cmd_process();
|
||||
}
|
||||
|
||||
@@ -208,7 +225,20 @@ __API__ void tos_shell_printf(const char *format, ...)
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
va_end(args);
|
||||
|
||||
(SHELL_CTL->output)(buffer);
|
||||
shell_puts(buffer);
|
||||
}
|
||||
|
||||
__API__ void tos_shell_printfln(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
static char buffer[SHELL_OUTPUT_MAX];
|
||||
|
||||
va_start(args, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
va_end(args);
|
||||
|
||||
shell_puts(buffer);
|
||||
shell_puts("\r\n");
|
||||
}
|
||||
|
||||
__API__ void tos_shell_input_byte(uint8_t data)
|
||||
|
@@ -20,23 +20,72 @@
|
||||
|
||||
__STATIC__ TOS_SLIST_DEFINE(cmd_set_list);
|
||||
|
||||
__STATIC__ int cmd_help(int argc, char *argv[])
|
||||
int cmd_help(int argc, char *argv[])
|
||||
{
|
||||
shell_cmd_set_t *cmd_set;
|
||||
const shell_cmd_t *cmd;
|
||||
|
||||
TOS_SLIST_FOR_EACH_ENTRY(cmd_set, shell_cmd_set_t, list, &cmd_set_list) {
|
||||
for (cmd = cmd_set->commands; cmd->name; ++cmd) {
|
||||
tos_shell_printf("%-8s: %s\n", cmd->name, cmd->help);
|
||||
tos_shell_printf("%-8s: %s\r\n", cmd->name, cmd->help);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void task_shell_walker(k_task_t *task)
|
||||
{
|
||||
char *state_str = "ABNORMAL";
|
||||
|
||||
if (!task) {
|
||||
return;
|
||||
}
|
||||
|
||||
state_str = state_str;
|
||||
tos_shell_printfln("task name: %s", task->name);
|
||||
|
||||
if (tos_task_curr_task_get() == task) {
|
||||
state_str = "RUNNING";
|
||||
} else if (task->state == K_TASK_STATE_PENDTIMEOUT_SUSPENDED) {
|
||||
state_str = "PENDTIMEOUT_SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_PEND_SUSPENDED) {
|
||||
state_str = "PEND_SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_SLEEP_SUSPENDED) {
|
||||
state_str = "SLEEP_SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_PENDTIMEOUT) {
|
||||
state_str = "PENDTIMEOUT";
|
||||
} else if (task->state == K_TASK_STATE_SUSPENDED) {
|
||||
state_str = "SUSPENDED";
|
||||
} else if (task->state == K_TASK_STATE_PEND) {
|
||||
state_str = "PEND";
|
||||
} else if (task->state == K_TASK_STATE_SLEEP) {
|
||||
state_str = "SLEEP";
|
||||
} else if (task->state == K_TASK_STATE_READY) {
|
||||
state_str = "READY";
|
||||
}
|
||||
|
||||
tos_shell_printfln("task stat: %s", state_str);
|
||||
tos_shell_printfln("stk size : %d", task->stk_size);
|
||||
tos_shell_printfln("stk base : 0x%p", task->stk_base);
|
||||
tos_shell_printfln("stk top : 0x%p", task->stk_base + task->stk_size);
|
||||
|
||||
#if TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN > 0u
|
||||
int depth;
|
||||
|
||||
if (tos_task_stack_draught_depth(task, &depth) != K_ERR_NONE) {
|
||||
depth = -1;
|
||||
}
|
||||
|
||||
tos_shell_printfln("stk depth: %d", depth);
|
||||
#endif /* TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN */
|
||||
|
||||
tos_shell_printf("\r\n");
|
||||
}
|
||||
|
||||
__STATIC__ int cmd_ps(int argc, char *argv[])
|
||||
{
|
||||
tos_task_info_display();
|
||||
tos_task_walkthru(task_shell_walker);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user