RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
finsh shell

宏定义

#define FINSH_FUNCTION_EXPORT(name, desc)
 
#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
 
#define MSH_CMD_EXPORT(...)
 
#define MSH_CMD_EXPORT_ALIAS(...)
 

函数

rt_uint32_t finsh_get_prompt_mode (void)
 
void finsh_set_prompt_mode (rt_uint32_t prompt_mode)
 
void finsh_set_device (const char *device_name)
 
const char * finsh_get_device ()
 
void finsh_set_echo (rt_uint32_t echo)
 
rt_uint32_t finsh_get_echo ()
 
void finsh_thread_entry_sethook (void(*hook)(void))
 

详细描述

finsh shell is a user command shell in RT-Thread RTOS.

finsh shell is a user command shell in RT-Thread RTOS, which is a shell can accept C-expression like syntax in command. From finsh shell, user can access system area, such as memory, variables and function by input C-expression in command.

Figure 3: finsh shell architecture

There is a shell thread, which named as "tshell", in the finsh shell, it read user command from console device, and then invokes system function or access system variable to output result (by rt_kprintf).

宏定义说明

◆ FINSH_FUNCTION_EXPORT

#define FINSH_FUNCTION_EXPORT ( name,
desc )

This macro exports a system function to finsh shell.

参数
namethe name of function.
descthe description of function, which will show in help.

在文件 components/finsh/finsh.h119 行定义.

◆ FINSH_FUNCTION_EXPORT_ALIAS

#define FINSH_FUNCTION_EXPORT_ALIAS ( name,
alias,
desc )

This macro exports a system function with an alias name to finsh shell.

参数
namethe name of function.
aliasthe alias name of function.
descthe description of function, which will show in help.

在文件 components/finsh/finsh.h130 行定义.

◆ MSH_CMD_EXPORT

#define MSH_CMD_EXPORT ( ...)
值:
_MSH_FUNCTION_CMD2)(__VA_ARGS__)
#define _MSH_FUNCTION_CMD2_OPT(a0, a1, a2)
#define _MSH_FUNCTION_CMD2(a0, a1)
#define __MSH_GET_MACRO(_1, _2, _3, _FUN,...)

This macro exports a command to module shell.

param command is the name of the command. param desc is the description of the command, which will show in help list. param opt This is an option, enter any content to enable option completion

在文件 components/finsh/finsh.h142 行定义.

142#define MSH_CMD_EXPORT(...) \
143 __MSH_GET_MACRO(__VA_ARGS__, _MSH_FUNCTION_CMD2_OPT, \
144 _MSH_FUNCTION_CMD2)(__VA_ARGS__)

◆ MSH_CMD_EXPORT_ALIAS

#define MSH_CMD_EXPORT_ALIAS ( ...)
值:
#define _MSH_FUNCTION_EXPORT_CMD3(a0, a1, a2)
#define __MSH_GET_EXPORT_MACRO(_1, _2, _3, _4, _FUN,...)
#define _MSH_FUNCTION_EXPORT_CMD3_OPT(a0, a1, a2, a3)

This macro exports a command with alias to module shell.

param command is the name of the command. param alias is the alias of the command. param desc is the description of the command, which will show in help list. param opt This is an option, enter any content to enable option completion

#define MSH_CMD_EXPORT_ALIAS(command, alias, desc) or
#define MSH_CMD_EXPORT_ALIAS(command, alias, desc, opt)

在文件 components/finsh/finsh.h160 行定义.

160#define MSH_CMD_EXPORT_ALIAS(...) \
161 __MSH_GET_EXPORT_MACRO(__VA_ARGS__, _MSH_FUNCTION_EXPORT_CMD3_OPT, \
162 _MSH_FUNCTION_EXPORT_CMD3)(__VA_ARGS__)

函数说明

◆ finsh_get_prompt_mode()

rt_uint32_t finsh_get_prompt_mode ( void )

This function get the prompt mode of finsh shell.

返回
prompt the prompt mode, 0 disable prompt mode, other values enable prompt mode.

在文件 shell.c136 行定义.

137{
139 return shell->prompt_mode;
140}
#define RT_ASSERT(EX)
#define RT_NULL
struct finsh_shell * shell
定义 shell.c:54

引用了 RT_ASSERT, RT_NULL , 以及 shell.

◆ finsh_set_prompt_mode()

void finsh_set_prompt_mode ( rt_uint32_t prompt_mode)

This function set the prompt mode of finsh shell.

The parameter 0 disable prompt mode, other values enable prompt mode.

参数
prompt_modethe prompt mode

在文件 shell.c151 行定义.

152{
154 shell->prompt_mode = prompt_mode;
155}

引用了 RT_ASSERT, RT_NULL , 以及 shell.

+ 这是这个函数的调用关系图:

◆ finsh_set_device()

void finsh_set_device ( const char * device_name)

This function sets the input device of finsh shell.

参数
device_namethe name of new input device.

在文件 shell.c219 行定义.

220{
221 rt_device_t dev = RT_NULL;
222
224 dev = rt_device_find(device_name);
225 if (dev == RT_NULL)
226 {
227 rt_kprintf("finsh: can not find device: %s\n", device_name);
228 return;
229 }
230
231 /* check whether it's a same device */
232 if (dev == shell->device) return;
233 /* open this device and set the new device in finsh shell */
235 RT_DEVICE_FLAG_STREAM) == RT_EOK)
236 {
237 if (shell->device != RT_NULL)
238 {
239 /* close old finsh device */
240 rt_device_close(shell->device);
242 }
243
244 /* clear line buffer before switch to new device */
245 rt_memset(shell->line, 0, sizeof(shell->line));
246 shell->line_curpos = shell->line_position = 0;
247
248 shell->device = dev;
249 rt_device_set_rx_indicate(dev, finsh_rx_ind);
250 }
251}
rt_err_t rt_device_set_rx_indicate(rt_device_t dev, rt_err_t(*rx_ind)(rt_device_t dev, rt_size_t size))
#define RT_DEVICE_FLAG_INT_RX
#define RT_DEVICE_FLAG_STREAM
rt_device_t rt_device_find(const char *name)
struct rt_device * rt_device_t
rt_err_t rt_device_close(rt_device_t dev)
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
#define RT_DEVICE_OFLAG_RDWR
#define rt_kprintf(...)

引用了 RT_ASSERT, rt_device_close(), rt_device_find(), RT_DEVICE_FLAG_INT_RX, RT_DEVICE_FLAG_STREAM, RT_DEVICE_OFLAG_RDWR, rt_device_open(), rt_device_set_rx_indicate(), rt_kprintf, RT_NULL , 以及 shell.

+ 函数调用图:

◆ finsh_get_device()

const char * finsh_get_device ( void )

This function returns current finsh shell input device.

返回
the finsh shell input device name is returned.

在文件 shell.c260 行定义.

261{
263 return shell->device->parent.name;
264}

引用了 RT_ASSERT, RT_NULL , 以及 shell.

◆ finsh_set_echo()

void finsh_set_echo ( rt_uint32_t echo)

This function set the echo mode of finsh shell.

FINSH_OPTION_ECHO=0x01 is echo mode, other values are none-echo mode.

参数
echothe echo mode

在文件 shell.c276 行定义.

277{
279 shell->echo_mode = (rt_uint8_t)echo;
280}
unsigned char rt_uint8_t

引用了 RT_ASSERT, RT_NULL , 以及 shell.

◆ finsh_get_echo()

rt_uint32_t finsh_get_echo ( void )

This function gets the echo mode of finsh shell.

返回
the echo mode

在文件 shell.c289 行定义.

290{
292
293 return shell->echo_mode;
294}

引用了 RT_ASSERT, RT_NULL , 以及 shell.

◆ finsh_thread_entry_sethook()

void finsh_thread_entry_sethook ( void(* hook )(void))

This function set a hook function at the entry of finsh thread

参数
hookthe function point to be called

在文件 shell.c470 行定义.

471{
472 _finsh_thread_entry_hook = hook;
473}