1 /* 2 * Copyright (c) 2006-2018, 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 #ifndef FINSH_USING_MSH_ONLY 78 struct finsh_parser parser; 79 #endif 80 81 char line[FINSH_CMD_SIZE]; 82 rt_uint8_t line_position; 83 rt_uint8_t line_curpos; 84 85 #ifndef RT_USING_POSIX 86 rt_device_t device; 87 #endif 88 89 #ifdef FINSH_USING_AUTH 90 char password[FINSH_PASSWORD_MAX]; 91 #endif 92 }; 93 94 void finsh_set_echo(rt_uint32_t echo); 95 rt_uint32_t finsh_get_echo(void); 96 97 int finsh_system_init(void); 98 void finsh_set_device(const char* device_name); 99 const char* finsh_get_device(void); 100 101 rt_uint32_t finsh_get_prompt_mode(void); 102 void finsh_set_prompt_mode(rt_uint32_t prompt_mode); 103 104 #ifdef FINSH_USING_AUTH 105 rt_err_t finsh_set_password(const char *password); 106 const char *finsh_get_password(void); 107 #endif 108 109 #endif 110 111