RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
components/finsh/finsh.h
浏览该文件的文档.
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 * 2010-03-22 Bernard first version
9 */
10#ifndef __FINSH_H__
11#define __FINSH_H__
12
13#include <rtdef.h>
14
15#ifdef _MSC_VER
16#pragma section("FSymTab$f",read)
17#endif /* _MSC_VER */
18
19#ifdef FINSH_USING_OPTION_COMPLETION
20#define FINSH_COND(opt) opt,
21#else
22#define FINSH_COND(opt)
23#endif
24
25#ifdef FINSH_USING_DESCRIPTION
26#define FINSH_DESC(cmd, desc) __fsym_##cmd##_desc,
27#else
28#define FINSH_DESC(cmd, desc)
29#endif
30
31typedef long (*syscall_func)(void);
32#ifdef FINSH_USING_SYMTAB
33
34#ifdef __TI_COMPILER_VERSION__
35#define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab"))
36#endif /* __TI_COMPILER_VERSION__ */
37
45#ifdef _MSC_VER
46#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc, opt) \
47 const char __fsym_##cmd##_name[] = #cmd; \
48 const char __fsym_##cmd##_desc[] = #desc; \
49 __declspec(allocate("FSymTab$f")) \
50 const struct finsh_syscall __fsym_##cmd = \
51 { \
52 __fsym_##cmd##_name, \
53 FINSH_DESC(cmd, desc) \
54 FINSH_COND(opt) \
55 (syscall_func)&name \
56 };
57#pragma comment(linker, "/merge:FSymTab=mytext")
58
59#elif defined(__TI_COMPILER_VERSION__)
60#ifdef __TMS320C28XX__
61#define RT_NOBLOCKED __attribute__((noblocked))
62#else
63#define RT_NOBLOCKED
64#endif
65#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc, opt) \
66 __TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \
67 const char __fsym_##cmd##_name[] = #cmd; \
68 const char __fsym_##cmd##_desc[] = #desc; \
69 rt_used RT_NOBLOCKED const struct finsh_syscall __fsym_##cmd = \
70 { \
71 __fsym_##cmd##_name, \
72 FINSH_DESC(cmd, desc) \
73 FINSH_COND(opt) \
74 (syscall_func)&name \
75 };
76
77#else
78#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc, opt) \
79 const char __fsym_##cmd##_name[] rt_section(".rodata.name") = #cmd; \
80 const char __fsym_##cmd##_desc[] rt_section(".rodata.name") = #desc; \
81 rt_used const struct finsh_syscall __fsym_##cmd rt_section("FSymTab")= \
82 { \
83 __fsym_##cmd##_name, \
84 FINSH_DESC(cmd, desc) \
85 FINSH_COND(opt) \
86 (syscall_func)&name \
87 };
88
89#endif /* _MSC_VER */
90#endif /* FINSH_USING_SYMTAB */
91
95#define __MSH_GET_MACRO(_1, _2, _3, _FUN, ...) _FUN
96#define __MSH_GET_EXPORT_MACRO(_1, _2, _3, _4, _FUN, ...) _FUN
97
98#define _MSH_FUNCTION_CMD2(a0, a1) \
99 MSH_FUNCTION_EXPORT_CMD(a0, a0, a1, 0)
100
101#define _MSH_FUNCTION_CMD2_OPT(a0, a1, a2) \
102 MSH_FUNCTION_EXPORT_CMD(a0, a0, a1, a0##_msh_options)
103
104#define _MSH_FUNCTION_EXPORT_CMD3(a0, a1, a2) \
105 MSH_FUNCTION_EXPORT_CMD(a0, a1, a2, 0)
106
107#define _MSH_FUNCTION_EXPORT_CMD3_OPT(a0, a1, a2, a3) \
108 MSH_FUNCTION_EXPORT_CMD(a0, a1, a2, a0##_msh_options)
109
110
119#define FINSH_FUNCTION_EXPORT(name, desc)
120
130#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
131
141/* MSH_CMD_EXPORT(command, desc) or MSH_CMD_EXPORT(command, desc, opt) */
142#define MSH_CMD_EXPORT(...) \
143 __MSH_GET_MACRO(__VA_ARGS__, _MSH_FUNCTION_CMD2_OPT, \
144 _MSH_FUNCTION_CMD2)(__VA_ARGS__)
145
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__)
163
164/* system call table */
166{
167 const char *name; /* the name of system call */
168#if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB)
169 const char *desc; /* description of system call */
170#endif
171
172#ifdef FINSH_USING_OPTION_COMPLETION
173 struct msh_cmd_opt *opt;
174#endif
175 syscall_func func; /* the function address of system call */
176};
177
178/* system call item */
180{
181 struct finsh_syscall_item *next; /* next item */
182 struct finsh_syscall syscall; /* syscall */
183};
184
185#ifdef FINSH_USING_OPTION_COMPLETION
186typedef struct msh_cmd_opt
187{
188 rt_uint32_t id;
189 const char *name;
190 const char *des;
191} msh_cmd_opt_t;
192
193/* Command options declaration and definition macros */
194
199#define CMD_OPTIONS_STATEMENT(command) static struct msh_cmd_opt command##_msh_options[];
200
205#define CMD_OPTIONS_NODE_START(command) static struct msh_cmd_opt command##_msh_options[] = {
206
213#define CMD_OPTIONS_NODE(_id, _name, _des) {.id = _id, .name = #_name, .des = #_des},
214
218#define CMD_OPTIONS_NODE_END {0},};
219
220void msh_opt_list_dump(void *options);
221int msh_cmd_opt_id_get(int argc, char *argv[], void *options);
222#define MSH_OPT_ID_GET(fun) msh_cmd_opt_id_get(argc, argv, (void*) fun##_msh_options)
223#define MSH_OPT_DUMP(fun) msh_opt_list_dump((void*) fun##_msh_options)
224
225#else
226#define CMD_OPTIONS_STATEMENT(command)
227#define CMD_OPTIONS_NODE_START(command)
228#define CMD_OPTIONS_NODE(_id, _name, _des)
229#define CMD_OPTIONS_NODE_END
230#define MSH_OPT_ID_GET(fun) ((int)(-1UL))
231#define MSH_OPT_DUMP(fun) do{}while(0)
232#endif
233
236
237#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
238 struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call);
239 #define FINSH_NEXT_SYSCALL(index) index=finsh_syscall_next(index)
240#else
241 #define FINSH_NEXT_SYSCALL(index) index++
242#endif
243
244#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
245void finsh_set_device(const char *device_name);
246#endif
247
248#endif
long(* syscall_func)(void)
struct finsh_syscall * _syscall_table_end
struct finsh_syscall_item * global_syscall_list
struct finsh_syscall * _syscall_table_begin
定义 shell.c:50
void finsh_set_device(const char *device_name)
unsigned int rt_uint32_t
struct finsh_syscall_item * next