1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2011-06-02     Bernard      Add finsh_get_prompt function declaration
9  */
10 
11 #ifndef __SHELL_H__
12 #define __SHELL_H__
13 
14 #include <rtthread.h>
15 #include "finsh.h"
16 
17 #ifndef FINSH_THREAD_PRIORITY
18     #define FINSH_THREAD_PRIORITY 20
19 #endif
20 #ifndef FINSH_THREAD_STACK_SIZE
21     #define FINSH_THREAD_STACK_SIZE 2048
22 #endif
23 #ifndef FINSH_CMD_SIZE
24     #define FINSH_CMD_SIZE      80
25 #endif
26 
27 #define FINSH_OPTION_ECHO   0x01
28 
29 #define FINSH_PROMPT        finsh_get_prompt()
30 const char *finsh_get_prompt(void);
31 int finsh_set_prompt(const char *prompt);
32 
33 #ifdef FINSH_USING_HISTORY
34     #ifndef FINSH_HISTORY_LINES
35         #define FINSH_HISTORY_LINES 5
36     #endif
37 #endif
38 
39 #ifdef FINSH_USING_AUTH
40     #ifndef FINSH_PASSWORD_MAX
41         #define FINSH_PASSWORD_MAX RT_NAME_MAX
42     #endif
43     #ifndef FINSH_PASSWORD_MIN
44         #define FINSH_PASSWORD_MIN 6
45     #endif
46     #ifndef FINSH_DEFAULT_PASSWORD
47         #define FINSH_DEFAULT_PASSWORD "rtthread"
48     #endif
49 #endif /* FINSH_USING_AUTH */
50 
51 #ifndef FINSH_THREAD_NAME
52     #define FINSH_THREAD_NAME   "tshell"
53 #endif
54 
55 enum input_stat
56 {
57     WAIT_NORMAL,
58     WAIT_SPEC_KEY,
59     WAIT_FUNC_KEY,
60 };
61 struct finsh_shell
62 {
63     struct rt_semaphore rx_sem;
64 
65     enum input_stat stat;
66 
67     rt_uint8_t echo_mode: 1;
68     rt_uint8_t prompt_mode: 1;
69 
70 #ifdef FINSH_USING_HISTORY
71     rt_uint16_t current_history;
72     rt_uint16_t history_count;
73 
74     char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
75 #endif
76 
77     char line[FINSH_CMD_SIZE + 1];
78     rt_uint16_t line_position;
79     rt_uint16_t line_curpos;
80 
81 #if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
82     rt_device_t device;
83 #endif
84 
85 #ifdef FINSH_USING_AUTH
86     char password[FINSH_PASSWORD_MAX];
87 #endif
88 };
89 
90 void finsh_set_echo(rt_uint32_t echo);
91 rt_uint32_t finsh_get_echo(void);
92 
93 int finsh_system_init(void);
94 const char *finsh_get_device(void);
95 int finsh_getchar(void);
96 
97 rt_uint32_t finsh_get_prompt_mode(void);
98 void finsh_set_prompt_mode(rt_uint32_t prompt_mode);
99 
100 #ifdef FINSH_USING_AUTH
101     rt_err_t finsh_set_password(const char *password);
102     const char *finsh_get_password(void);
103 #endif
104 
105 #ifdef RT_USING_HOOK
106 void finsh_thread_entry_sethook(void (*hook)(void));
107 #endif /* RT_USING_HOOK */
108 
109 #endif
110