[finsh] Use standard uint type for data type.
Use uint8_t/uint32_t etc to replace u_char/u_long etc; Use getchar for shell input.
This commit is contained in:
parent
9a131b9452
commit
95ab8c02aa
|
@ -6,6 +6,10 @@ config RT_USING_FINSH
|
|||
|
||||
if RT_USING_FINSH
|
||||
|
||||
config FINSH_USING_HISTORY
|
||||
bool "Enable command history feature"
|
||||
default y
|
||||
|
||||
config FINSH_USING_SYMTAB
|
||||
bool "Using symbol table for commands"
|
||||
default y
|
||||
|
@ -18,18 +22,25 @@ config FINSH_THREAD_STACK_SIZE
|
|||
int "The stack size for finsh thread"
|
||||
default 4096
|
||||
|
||||
config FINSH_CMD_SIZE
|
||||
int "The command line size for shell"
|
||||
default 80
|
||||
|
||||
config FINSH_USING_AUTH
|
||||
bool "shell support authentication"
|
||||
default n
|
||||
|
||||
if FINSH_USING_AUTH
|
||||
config FINSH_DEFAULT_PASSWORD
|
||||
string "The default password for shell authentication"
|
||||
default "rtthread"
|
||||
endif
|
||||
|
||||
config FINSH_USING_MSH
|
||||
bool "Using module shell"
|
||||
default y
|
||||
|
||||
if FINSH_USING_MSH
|
||||
config FINSH_USING_MSH_DEFAULT
|
||||
bool "Using module shell in default"
|
||||
default y
|
||||
|
@ -37,6 +48,7 @@ config FINSH_USING_MSH_DEFAULT
|
|||
config FINSH_USING_MSH_ONLY
|
||||
bool "Only using module shell"
|
||||
default n
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
|
|
|
@ -121,13 +121,15 @@ static long _list_thread(struct rt_list_node *list)
|
|||
rt_kprintf( " --- ------- ---------- ---------- ------ ---------- ---\n");
|
||||
for (node = list->next; node != list; node = node->next)
|
||||
{
|
||||
rt_uint8_t stat;
|
||||
thread = rt_list_entry(node, struct rt_thread, list);
|
||||
rt_kprintf("%-*.*s %3d ", maxlen, RT_NAME_MAX, thread->name, thread->current_priority);
|
||||
|
||||
if (thread->stat == RT_THREAD_READY) rt_kprintf(" ready ");
|
||||
else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
|
||||
else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init ");
|
||||
else if (thread->stat == RT_THREAD_CLOSE) rt_kprintf(" close ");
|
||||
stat = (thread->stat & RT_THREAD_STAT_MASK);
|
||||
if (stat == RT_THREAD_READY) rt_kprintf(" ready ");
|
||||
else if (stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
|
||||
else if (stat == RT_THREAD_INIT) rt_kprintf(" init ");
|
||||
else if (stat == RT_THREAD_CLOSE) rt_kprintf(" close ");
|
||||
|
||||
ptr = (rt_uint8_t *)thread->stack_addr;
|
||||
while (*ptr == '#')ptr ++;
|
||||
|
@ -613,14 +615,17 @@ int list_mod_detail(const char *name)
|
|||
/* list main thread in module */
|
||||
if (module->module_thread != RT_NULL)
|
||||
{
|
||||
rt_uint8_t stat;
|
||||
|
||||
rt_kprintf("main thread pri status sp stack size max used left tick error\n");
|
||||
rt_kprintf("------------- ---- ------- ---------- ---------- ---------- ---------- ---\n");
|
||||
thread = module->module_thread;
|
||||
rt_kprintf("%-8.*s 0x%02x", RT_NAME_MAX, thread->name, thread->current_priority);
|
||||
|
||||
if (thread->stat == RT_THREAD_READY) rt_kprintf(" ready ");
|
||||
else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
|
||||
else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init ");
|
||||
stat = (thread->stat & RT_THREAD_STAT_MASK);
|
||||
if (stat == RT_THREAD_READY) rt_kprintf(" ready ");
|
||||
else if (stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
|
||||
else if (stat == RT_THREAD_INIT) rt_kprintf(" init ");
|
||||
|
||||
ptr = (rt_uint8_t *)thread->stack_addr;
|
||||
while (*ptr == '#')ptr ++;
|
||||
|
|
|
@ -56,38 +56,12 @@
|
|||
|
||||
/* -- the end of option -- */
|
||||
|
||||
#if defined(RT_USING_NEWLIB) || defined (RT_USING_MINILIBC)
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#else
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned short u_short;
|
||||
typedef unsigned long u_long;
|
||||
|
||||
#if !defined(__CC_ARM) && \
|
||||
!defined(__IAR_SYSTEMS_ICC__) && \
|
||||
!defined(__ADSPBLACKFIN__) && \
|
||||
!defined(_MSC_VER)
|
||||
|
||||
/* only for GNU GCC */
|
||||
|
||||
#if !(defined(__GNUC__) && defined(__x86_64__))
|
||||
typedef unsigned int size_t;
|
||||
#else
|
||||
/* std header file */
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL RT_NULL
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* use libc of armcc */
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define FINSH_VERSION_MAJOR 1
|
||||
#define FINSH_VERSION_MINOR 0
|
||||
|
@ -144,7 +118,7 @@ struct finsh_sysvar
|
|||
#if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB)
|
||||
const char* desc; /* description of system variable */
|
||||
#endif
|
||||
u_char type; /* the type of variable */
|
||||
uint8_t type; /* the type of variable */
|
||||
void* var ; /* the address of variable */
|
||||
};
|
||||
|
||||
|
@ -360,16 +334,16 @@ struct finsh_token
|
|||
char replay;
|
||||
|
||||
int position;
|
||||
u_char current_token;
|
||||
uint8_t current_token;
|
||||
|
||||
union {
|
||||
char char_value;
|
||||
int int_value;
|
||||
long long_value;
|
||||
} value;
|
||||
u_char string[FINSH_STRING_MAX];
|
||||
uint8_t string[FINSH_STRING_MAX];
|
||||
|
||||
u_char* line;
|
||||
uint8_t* line;
|
||||
};
|
||||
|
||||
#define FINSH_IDTYPE_VAR 0x01
|
||||
|
@ -378,9 +352,9 @@ struct finsh_token
|
|||
#define FINSH_IDTYPE_ADDRESS 0x08
|
||||
struct finsh_node
|
||||
{
|
||||
u_char node_type; /* node node_type */
|
||||
u_char data_type; /* node data node_type */
|
||||
u_char idtype; /* id node information */
|
||||
uint8_t node_type; /* node node_type */
|
||||
uint8_t data_type; /* node data node_type */
|
||||
uint8_t idtype; /* id node information */
|
||||
|
||||
union { /* value node */
|
||||
char char_value;
|
||||
|
@ -403,7 +377,7 @@ struct finsh_node
|
|||
|
||||
struct finsh_parser
|
||||
{
|
||||
u_char* parser_string;
|
||||
uint8_t* parser_string;
|
||||
|
||||
struct finsh_token token;
|
||||
struct finsh_node* root;
|
||||
|
@ -455,9 +429,9 @@ struct finsh_var* finsh_var_lookup(const char* name);
|
|||
long finsh_stack_bottom(void);
|
||||
|
||||
/* get error number of finsh */
|
||||
u_char finsh_errno(void);
|
||||
uint8_t finsh_errno(void);
|
||||
/* get error string */
|
||||
const char* finsh_error_string(u_char type);
|
||||
const char* finsh_error_string(uint8_t type);
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
/**
|
||||
|
@ -477,6 +451,6 @@ void finsh_syscall_append(const char* name, syscall_func func);
|
|||
* @param type the data type of system variable
|
||||
* @param addr the address of system variable
|
||||
*/
|
||||
void finsh_sysvar_append(const char* name, u_char type, void* addr);
|
||||
void finsh_sysvar_append(const char* name, uint8_t type, void* addr);
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "finsh_ops.h"
|
||||
|
||||
union finsh_value* finsh_compile_sp; /* stack pointer */
|
||||
u_char* finsh_compile_pc; /* PC */
|
||||
uint8_t* finsh_compile_pc; /* PC */
|
||||
|
||||
#define finsh_code_byte(x) do { *finsh_compile_pc = (x); finsh_compile_pc ++; } while(0)
|
||||
#define finsh_code_word(x) do { FINSH_SET16(finsh_compile_pc, x); finsh_compile_pc +=2; } while(0)
|
||||
|
@ -210,7 +210,7 @@ static int finsh_compile(struct finsh_node* node)
|
|||
case FINSH_NODE_VALUE_NULL:
|
||||
case FINSH_NODE_VALUE_STRING:
|
||||
finsh_code_byte(FINSH_OP_LD_DWORD);
|
||||
finsh_code_dword((u_long)node->value.ptr);
|
||||
finsh_code_dword((uint32_t)node->value.ptr);
|
||||
break;
|
||||
|
||||
/* arithmetic operation */
|
||||
|
@ -756,7 +756,7 @@ static int finsh_compile(struct finsh_node* node)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int finsh_type_check(struct finsh_node* node, u_char is_addr)
|
||||
static int finsh_type_check(struct finsh_node* node, uint8_t is_addr)
|
||||
{
|
||||
if (node != NULL)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*/
|
||||
#include "finsh_error.h"
|
||||
|
||||
u_char global_errno;
|
||||
uint8_t global_errno;
|
||||
|
||||
static const char * finsh_error_string_table[] =
|
||||
{
|
||||
|
@ -56,19 +56,19 @@ int finsh_error_init()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int finsh_error_set(u_char type)
|
||||
int finsh_error_set(uint8_t type)
|
||||
{
|
||||
global_errno = type;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u_char finsh_errno()
|
||||
uint8_t finsh_errno()
|
||||
{
|
||||
return global_errno;
|
||||
}
|
||||
|
||||
const char* finsh_error_string(u_char type)
|
||||
const char* finsh_error_string(uint8_t type)
|
||||
{
|
||||
return finsh_error_string_table[type];
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@
|
|||
int finsh_error_init(void);
|
||||
|
||||
/* get error number */
|
||||
u_char finsh_errno(void);
|
||||
uint8_t finsh_errno(void);
|
||||
|
||||
int finsh_error_set(u_char type);
|
||||
const char* finsh_error_string(u_char type);
|
||||
int finsh_error_set(uint8_t type);
|
||||
const char* finsh_error_string(uint8_t type);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,15 +31,15 @@
|
|||
#include "finsh_var.h"
|
||||
|
||||
ALIGN(RT_ALIGN_SIZE)
|
||||
u_char finsh_heap[FINSH_HEAP_MAX];
|
||||
uint8_t finsh_heap[FINSH_HEAP_MAX];
|
||||
struct finsh_block_header
|
||||
{
|
||||
u_long length;
|
||||
uint32_t length;
|
||||
struct finsh_block_header* next;
|
||||
};
|
||||
#define BLOCK_HEADER(x) (struct finsh_block_header*)(x)
|
||||
#define finsh_block_get_header(data) (struct finsh_block_header*)((u_char*)data - sizeof(struct finsh_block_header))
|
||||
#define finsh_block_get_data(header) (u_char*)((struct finsh_block_header*)header + 1)
|
||||
#define finsh_block_get_header(data) (struct finsh_block_header*)((uint8_t*)data - sizeof(struct finsh_block_header))
|
||||
#define finsh_block_get_data(header) (uint8_t*)((struct finsh_block_header*)header + 1)
|
||||
#define HEAP_ALIGN_SIZE(size) (((size) + HEAP_ALIGNMENT - 1) & ~(HEAP_ALIGNMENT-1))
|
||||
|
||||
static struct finsh_block_header* free_list;
|
||||
|
@ -237,7 +237,7 @@ void finsh_block_split(struct finsh_block_header* header, size_t size)
|
|||
* split header into two node:
|
||||
* header->next->...
|
||||
*/
|
||||
next = BLOCK_HEADER((u_char*)header + sizeof(struct finsh_block_header) + size);
|
||||
next = BLOCK_HEADER((uint8_t*)header + sizeof(struct finsh_block_header) + size);
|
||||
next->length = header->length - sizeof(struct finsh_block_header) - size;
|
||||
header->length = size;
|
||||
next->next = header->next;
|
||||
|
@ -267,13 +267,13 @@ void finsh_block_merge(struct finsh_block_header** list, struct finsh_block_head
|
|||
|
||||
/* merge to previous node */
|
||||
if (prev_node != NULL &&
|
||||
((u_char*)prev_node + prev_node->length + sizeof(struct finsh_block_header)
|
||||
== (u_char*)header))
|
||||
((uint8_t*)prev_node + prev_node->length + sizeof(struct finsh_block_header)
|
||||
== (uint8_t*)header))
|
||||
{
|
||||
/* is it close to next node? */
|
||||
if ((next_node != NULL) &&
|
||||
((u_char*)header + header->length + sizeof(struct finsh_block_header)
|
||||
== (u_char*)next_node))
|
||||
((uint8_t*)header + header->length + sizeof(struct finsh_block_header)
|
||||
== (uint8_t*)next_node))
|
||||
{
|
||||
/* merge three node */
|
||||
prev_node->length += header->length + next_node->length +
|
||||
|
@ -289,8 +289,8 @@ void finsh_block_merge(struct finsh_block_header** list, struct finsh_block_head
|
|||
}
|
||||
else /* merge to last node */
|
||||
if ( (next_node != NULL) &&
|
||||
((u_char*)header + header->length + sizeof(struct finsh_block_header)
|
||||
== (u_char*)next_node))
|
||||
((uint8_t*)header + header->length + sizeof(struct finsh_block_header)
|
||||
== (uint8_t*)next_node))
|
||||
{
|
||||
header->length += next_node->length + sizeof(struct finsh_block_header);
|
||||
header->next = next_node->next;
|
||||
|
|
|
@ -42,7 +42,7 @@ int finsh_node_init()
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct finsh_node* finsh_node_allocate(u_char type)
|
||||
struct finsh_node* finsh_node_allocate(uint8_t type)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -181,7 +181,7 @@ struct finsh_node* finsh_node_new_string(char* s)
|
|||
/* make string */
|
||||
node->value.ptr = finsh_heap_allocate(strlen(s) + 1);
|
||||
strncpy(node->value.ptr, s, strlen(s));
|
||||
((u_char*)node->value.ptr)[strlen(s)] = '\0';
|
||||
((uint8_t*)node->value.ptr)[strlen(s)] = '\0';
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
|
||||
int finsh_node_init(void);
|
||||
|
||||
struct finsh_node* finsh_node_allocate(u_char type);
|
||||
struct finsh_node* finsh_node_allocate(uint8_t type);
|
||||
struct finsh_node* finsh_node_new_id(char* id);
|
||||
struct finsh_node* finsh_node_new_char(char c);
|
||||
struct finsh_node* finsh_node_new_int(int i);
|
||||
|
|
|
@ -61,7 +61,7 @@ static struct finsh_node* proc_postfix_expr(struct finsh_parser* self);
|
|||
static struct finsh_node* proc_primary_expr(struct finsh_parser* self);
|
||||
static struct finsh_node* proc_param_list(struct finsh_parser* self);
|
||||
static struct finsh_node* proc_expr_statement(struct finsh_parser* self);
|
||||
static struct finsh_node* make_sys_node(u_char type, struct finsh_node* node1,
|
||||
static struct finsh_node* make_sys_node(uint8_t type, struct finsh_node* node1,
|
||||
struct finsh_node* node2);
|
||||
|
||||
/* check token */
|
||||
|
@ -894,7 +894,7 @@ node1__
|
|||
\
|
||||
node2
|
||||
*/
|
||||
static struct finsh_node* make_sys_node(u_char type, struct finsh_node* node1, struct finsh_node* node2)
|
||||
static struct finsh_node* make_sys_node(uint8_t type, struct finsh_node* node1, struct finsh_node* node2)
|
||||
{
|
||||
struct finsh_node* node;
|
||||
|
||||
|
@ -913,7 +913,7 @@ static struct finsh_node* make_sys_node(u_char type, struct finsh_node* node1, s
|
|||
/*
|
||||
start -> statement_expr | decl_variable
|
||||
*/
|
||||
void finsh_parser_run(struct finsh_parser* self, const u_char* string)
|
||||
void finsh_parser_run(struct finsh_parser* self, const uint8_t* string)
|
||||
{
|
||||
enum finsh_token_type token;
|
||||
struct finsh_node *node;
|
||||
|
@ -921,7 +921,7 @@ void finsh_parser_run(struct finsh_parser* self, const u_char* string)
|
|||
node = NULL;
|
||||
|
||||
/* init parser */
|
||||
self->parser_string = (u_char*)string;
|
||||
self->parser_string = (uint8_t*)string;
|
||||
|
||||
/* init token */
|
||||
finsh_token_init(&(self->token), self->parser_string);
|
||||
|
|
|
@ -32,6 +32,6 @@
|
|||
#include <finsh.h>
|
||||
|
||||
int finsh_parser_init(struct finsh_parser* self);
|
||||
void finsh_parser_run(struct finsh_parser* self, const u_char* string);
|
||||
void finsh_parser_run(struct finsh_parser* self, const uint8_t* string);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -66,12 +66,12 @@ static long token_spec_number(char* string, int length, int b);
|
|||
static void token_run(struct finsh_token* self);
|
||||
static int token_match_name(struct finsh_token* self, const char* str);
|
||||
static void token_proc_number(struct finsh_token* self);
|
||||
static u_char* token_proc_string(struct finsh_token* self);
|
||||
static uint8_t* token_proc_string(struct finsh_token* self);
|
||||
static void token_trim_space(struct finsh_token* self);
|
||||
static char token_proc_char(struct finsh_token* self);
|
||||
static int token_proc_escape(struct finsh_token* self);
|
||||
|
||||
void finsh_token_init(struct finsh_token* self, u_char* line)
|
||||
void finsh_token_init(struct finsh_token* self, uint8_t* line)
|
||||
{
|
||||
memset(self, 0, sizeof(struct finsh_token));
|
||||
|
||||
|
@ -86,12 +86,12 @@ enum finsh_token_type finsh_token_token(struct finsh_token* self)
|
|||
return (enum finsh_token_type)self->current_token;
|
||||
}
|
||||
|
||||
void finsh_token_get_token(struct finsh_token* self, u_char* token)
|
||||
void finsh_token_get_token(struct finsh_token* self, uint8_t* token)
|
||||
{
|
||||
strncpy((char*)token, (char*)self->string, FINSH_NAME_MAX);
|
||||
}
|
||||
|
||||
int token_get_string(struct finsh_token* self, u_char* str)
|
||||
int token_get_string(struct finsh_token* self, uint8_t* str)
|
||||
{
|
||||
unsigned char *p=str;
|
||||
char ch;
|
||||
|
@ -382,9 +382,9 @@ static char token_proc_char(struct finsh_token* self)
|
|||
return ch;
|
||||
}
|
||||
|
||||
static u_char* token_proc_string(struct finsh_token* self)
|
||||
static uint8_t* token_proc_string(struct finsh_token* self)
|
||||
{
|
||||
u_char* p;
|
||||
uint8_t* p;
|
||||
|
||||
for ( p = &self->string[0]; p - &(self->string[0]) < FINSH_STRING_MAX; )
|
||||
{
|
||||
|
|
|
@ -74,9 +74,9 @@ enum finsh_token_type
|
|||
#define finsh_token_position(self) (self)->position
|
||||
#define finsh_token_replay(self) (self)->replay = 1
|
||||
|
||||
void finsh_token_init(struct finsh_token* self, u_char* script);
|
||||
void finsh_token_init(struct finsh_token* self, uint8_t* script);
|
||||
|
||||
enum finsh_token_type finsh_token_token(struct finsh_token* self);
|
||||
void finsh_token_get_token(struct finsh_token* self, u_char* token);
|
||||
void finsh_token_get_token(struct finsh_token* self, uint8_t* token);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -104,7 +104,7 @@ struct finsh_var* finsh_var_lookup(const char* name)
|
|||
}
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
void finsh_sysvar_append(const char* name, u_char type, void* var_addr)
|
||||
void finsh_sysvar_append(const char* name, uint8_t type, void* var_addr)
|
||||
{
|
||||
/* create a sysvar */
|
||||
struct finsh_sysvar_item* item;
|
||||
|
|
|
@ -39,7 +39,7 @@ struct finsh_var
|
|||
{
|
||||
char name[FINSH_NAME_MAX + 1]; /* the name of variable */
|
||||
|
||||
u_char type; /* the type of variable */
|
||||
uint8_t type; /* the type of variable */
|
||||
|
||||
/* variable value */
|
||||
union {
|
||||
|
|
|
@ -35,10 +35,10 @@
|
|||
/* stack */
|
||||
union finsh_value finsh_vm_stack[FINSH_STACK_MAX];
|
||||
/* text segment */
|
||||
u_char text_segment[FINSH_TEXT_MAX];
|
||||
uint8_t text_segment[FINSH_TEXT_MAX];
|
||||
|
||||
union finsh_value* finsh_sp; /* stack pointer */
|
||||
u_char* finsh_pc; /* PC */
|
||||
uint8_t* finsh_pc; /* PC */
|
||||
|
||||
/* syscall list, for dynamic system call register */
|
||||
struct finsh_syscall_item* global_syscall_list = NULL;
|
||||
|
@ -46,7 +46,7 @@ struct finsh_syscall_item* global_syscall_list = NULL;
|
|||
// #define FINSH_VM_DISASSEMBLE
|
||||
void finsh_vm_run()
|
||||
{
|
||||
u_char op;
|
||||
uint8_t op;
|
||||
|
||||
/* if you want to disassemble the byte code, please define FINSH_VM_DISASSEMBLE */
|
||||
#ifdef FINSH_VM_DISASSEMBLE
|
||||
|
@ -148,7 +148,7 @@ struct finsh_syscall* finsh_syscall_lookup(const char* name)
|
|||
#ifdef FINSH_VM_DISASSEMBLE
|
||||
void finsh_disassemble()
|
||||
{
|
||||
u_char *pc, op;
|
||||
uint8_t *pc, op;
|
||||
|
||||
pc = &text_segment[0];
|
||||
while (*pc != 0)
|
||||
|
|
|
@ -41,12 +41,12 @@ union finsh_value {
|
|||
};
|
||||
|
||||
extern union finsh_value* finsh_sp; /* stack pointer */
|
||||
extern u_char* finsh_pc; /* PC */
|
||||
extern uint8_t* finsh_pc; /* PC */
|
||||
|
||||
/* stack */
|
||||
extern union finsh_value finsh_vm_stack[FINSH_STACK_MAX];
|
||||
/* text segment */
|
||||
extern u_char text_segment[FINSH_TEXT_MAX];
|
||||
extern uint8_t text_segment[FINSH_TEXT_MAX];
|
||||
|
||||
void finsh_vm_run(void);
|
||||
//void finsh_disassemble(void);
|
||||
|
|
|
@ -82,6 +82,23 @@ const char *finsh_get_prompt()
|
|||
}
|
||||
#endif
|
||||
|
||||
static char finsh_getchar(void)
|
||||
{
|
||||
RT_ASSERT(shell != RT_NULL);
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
return getchar();
|
||||
#else
|
||||
char ch;
|
||||
|
||||
while (rt_device_read(shell->device, -1, &ch, 1) != 1)
|
||||
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
|
||||
|
||||
return ch;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
RT_ASSERT(shell != RT_NULL);
|
||||
|
@ -145,6 +162,7 @@ const char *finsh_get_device()
|
|||
RT_ASSERT(shell != RT_NULL);
|
||||
return shell->device->parent.name;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup finsh
|
||||
|
@ -219,15 +237,14 @@ static void finsh_wait_auth(void)
|
|||
|
||||
while (1)
|
||||
{
|
||||
rt_kprintf("Password for finsh: ");
|
||||
rt_kprintf("Password for login: ");
|
||||
while (!input_finish)
|
||||
{
|
||||
/* wait receive */
|
||||
if (rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER) != RT_EOK) continue;
|
||||
|
||||
/* read one character from device */
|
||||
while (rt_device_read(shell->device, 0, &ch, 1) == 1)
|
||||
while (1)
|
||||
{
|
||||
/* read one character from device */
|
||||
ch = finsh_getchar();
|
||||
|
||||
if (ch >= ' ' && ch <= '~' && cur_pos < FINSH_PASSWORD_MAX)
|
||||
{
|
||||
/* change the printable characters to '*' */
|
||||
|
@ -258,8 +275,6 @@ static void finsh_wait_auth(void)
|
|||
cur_pos = 0;
|
||||
input_finish = RT_FALSE;
|
||||
rt_memset(password, '\0', FINSH_PASSWORD_MAX);
|
||||
/* read all last dirty data */
|
||||
while (rt_device_read(shell->device, 0, &ch, 1) == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -397,18 +412,17 @@ void finsh_thread_entry(void *parameter)
|
|||
finsh_init(&shell->parser);
|
||||
#endif
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
/* set console device as shell device */
|
||||
if (shell->device == RT_NULL)
|
||||
{
|
||||
#ifdef RT_USING_CONSOLE
|
||||
shell->device = rt_console_get_device();
|
||||
RT_ASSERT(shell->device);
|
||||
rt_device_set_rx_indicate(shell->device, finsh_rx_ind);
|
||||
rt_device_open(shell->device, (RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX));
|
||||
#else
|
||||
RT_ASSERT(shell->device);
|
||||
#endif
|
||||
rt_device_t console = rt_console_get_device();
|
||||
if (console)
|
||||
{
|
||||
finsh_set_device(console->parent.name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FINSH_USING_AUTH
|
||||
/* set the default password when the password isn't setting */
|
||||
|
@ -427,12 +441,8 @@ void finsh_thread_entry(void *parameter)
|
|||
|
||||
while (1)
|
||||
{
|
||||
/* wait receive */
|
||||
if (rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER) != RT_EOK) continue;
|
||||
ch = finsh_getchar();
|
||||
|
||||
/* read one character from device */
|
||||
while (rt_device_read(shell->device, 0, &ch, 1) == 1)
|
||||
{
|
||||
/*
|
||||
* handle control key
|
||||
* up key : 0x1b 0x5b 0x41
|
||||
|
@ -521,21 +531,10 @@ void finsh_thread_entry(void *parameter)
|
|||
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* handle CR key */
|
||||
if (ch == '\r')
|
||||
{
|
||||
char next;
|
||||
|
||||
if (rt_device_read(shell->device, 0, &next, 1) == 1)
|
||||
{
|
||||
if (next == '\0') ch = '\r'; /* linux telnet will issue '\0' */
|
||||
else ch = next;
|
||||
}
|
||||
else ch = '\r';
|
||||
}
|
||||
if (ch == '\0') continue;
|
||||
/* handle tab key */
|
||||
else if (ch == '\t')
|
||||
{
|
||||
|
@ -615,7 +614,7 @@ void finsh_thread_entry(void *parameter)
|
|||
rt_kprintf(FINSH_PROMPT);
|
||||
memset(shell->line, 0, sizeof(shell->line));
|
||||
shell->line_curpos = shell->line_position = 0;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* it's a large line, discard it */
|
||||
|
@ -656,7 +655,6 @@ void finsh_thread_entry(void *parameter)
|
|||
}
|
||||
} /* end of device read */
|
||||
}
|
||||
}
|
||||
|
||||
void finsh_system_function_init(const void *begin, const void *end)
|
||||
{
|
||||
|
@ -779,5 +777,5 @@ int finsh_system_init(void)
|
|||
rt_thread_startup(&finsh_thread);
|
||||
return 0;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(finsh_system_init);
|
||||
INIT_APP_EXPORT(finsh_system_init);
|
||||
|
||||
|
|
|
@ -33,14 +33,7 @@
|
|||
#include <rtthread.h>
|
||||
#include "finsh.h"
|
||||
|
||||
/* For historical reasons, users don't define FINSH_USING_HISTORY in rtconfig.h
|
||||
* but expect the history feature. So you sould define FINSH_USING_HISTORY to 0
|
||||
* to disable it from the rtconfig.h. */
|
||||
#ifdef FINSH_USING_HISTORY
|
||||
# if FINSH_USING_HISTORY == 0
|
||||
# undef FINSH_USING_HISTORY
|
||||
# endif
|
||||
#else
|
||||
#ifndef FINSH_USING_HISTORY
|
||||
#define FINSH_USING_HISTORY
|
||||
#endif
|
||||
|
||||
|
@ -109,7 +102,9 @@ struct finsh_shell
|
|||
rt_uint8_t line_position;
|
||||
rt_uint8_t line_curpos;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
rt_device_t device;
|
||||
#endif
|
||||
|
||||
#ifdef FINSH_USING_AUTH
|
||||
char password[FINSH_PASSWORD_MAX];
|
||||
|
|
Loading…
Reference in New Issue