2010-03-22 07:49:57 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2010-03-22 07:49:57 +08:00
|
|
|
*
|
2018-10-14 19:28:18 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2010-03-22 07:49:57 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2010-03-22 Bernard first version
|
|
|
|
*/
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifndef __FINSH_H__
|
|
|
|
#define __FINSH_H__
|
|
|
|
|
2022-05-30 18:00:26 +08:00
|
|
|
#include <rtdef.h>
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2022-05-30 18:00:26 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma section("FSymTab$f",read)
|
|
|
|
#endif /* _MSC_VER */
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-09-27 12:34:05 +08:00
|
|
|
#ifdef FINSH_USING_OPTION_COMPLETION
|
|
|
|
#define FINSH_COND(opt) opt,
|
|
|
|
#else
|
|
|
|
#define FINSH_COND(opt)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FINSH_USING_DESCRIPTION
|
|
|
|
#define FINSH_DESC(cmd, desc) __fsym_##cmd##_desc,
|
|
|
|
#else
|
|
|
|
#define FINSH_DESC(cmd, desc)
|
|
|
|
#endif
|
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
typedef long (*syscall_func)(void);
|
|
|
|
#ifdef FINSH_USING_SYMTAB
|
2023-09-27 12:34:05 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#ifdef __TI_COMPILER_VERSION__
|
2022-05-30 18:00:26 +08:00
|
|
|
#define __TI_FINSH_EXPORT_FUNCTION(f) PRAGMA(DATA_SECTION(f,"FSymTab"))
|
|
|
|
#endif /* __TI_COMPILER_VERSION__ */
|
2023-09-27 12:34:05 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#ifdef _MSC_VER
|
2023-09-27 12:34:05 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc, opt) \
|
2021-08-23 17:30:05 +08:00
|
|
|
const char __fsym_##cmd##_name[] = #cmd; \
|
|
|
|
const char __fsym_##cmd##_desc[] = #desc; \
|
|
|
|
__declspec(allocate("FSymTab$f")) \
|
|
|
|
const struct finsh_syscall __fsym_##cmd = \
|
|
|
|
{ \
|
|
|
|
__fsym_##cmd##_name, \
|
2023-09-27 12:34:05 +08:00
|
|
|
FINSH_DESC(cmd, desc) \
|
|
|
|
FINSH_COND(opt) \
|
2021-08-23 17:30:05 +08:00
|
|
|
(syscall_func)&name \
|
|
|
|
};
|
|
|
|
#pragma comment(linker, "/merge:FSymTab=mytext")
|
|
|
|
|
|
|
|
#elif defined(__TI_COMPILER_VERSION__)
|
2022-10-20 11:41:13 +08:00
|
|
|
#ifdef __TMS320C28XX__
|
|
|
|
#define RT_NOBLOCKED __attribute__((noblocked))
|
|
|
|
#else
|
|
|
|
#define RT_NOBLOCKED
|
|
|
|
#endif
|
2023-09-27 12:34:05 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc, opt) \
|
|
|
|
__TI_FINSH_EXPORT_FUNCTION(__fsym_##cmd); \
|
|
|
|
const char __fsym_##cmd##_name[] = #cmd; \
|
|
|
|
const char __fsym_##cmd##_desc[] = #desc; \
|
|
|
|
rt_used RT_NOBLOCKED const struct finsh_syscall __fsym_##cmd = \
|
2021-08-23 17:30:05 +08:00
|
|
|
{ \
|
|
|
|
__fsym_##cmd##_name, \
|
2023-09-27 12:34:05 +08:00
|
|
|
FINSH_DESC(cmd, desc) \
|
|
|
|
FINSH_COND(opt) \
|
2021-08-23 17:30:05 +08:00
|
|
|
(syscall_func)&name \
|
|
|
|
};
|
2023-09-27 12:34:05 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#else
|
2023-09-27 12:34:05 +08:00
|
|
|
#define MSH_FUNCTION_EXPORT_CMD(name, cmd, desc, opt) \
|
2022-12-12 02:12:03 +08:00
|
|
|
const char __fsym_##cmd##_name[] rt_section(".rodata.name") = #cmd; \
|
|
|
|
const char __fsym_##cmd##_desc[] rt_section(".rodata.name") = #desc; \
|
|
|
|
rt_used const struct finsh_syscall __fsym_##cmd rt_section("FSymTab")= \
|
2021-08-23 17:30:05 +08:00
|
|
|
{ \
|
|
|
|
__fsym_##cmd##_name, \
|
2023-09-27 12:34:05 +08:00
|
|
|
FINSH_DESC(cmd, desc) \
|
|
|
|
FINSH_COND(opt) \
|
2021-08-23 17:30:05 +08:00
|
|
|
(syscall_func)&name \
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-09-27 12:34:05 +08:00
|
|
|
#endif /* _MSC_VER */
|
|
|
|
#endif /* end of FINSH_USING_SYMTAB */
|
2021-08-23 17:30:05 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-09-27 12:34:05 +08:00
|
|
|
#define __MSH_GET_MACRO(_1, _2, _3, _FUN, ...) _FUN
|
|
|
|
#define __MSH_GET_EXPORT_MACRO(_1, _2, _3, _4, _FUN, ...) _FUN
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-09-27 12:34:05 +08:00
|
|
|
#define _MSH_FUNCTION_CMD2(a0, a1) \
|
|
|
|
MSH_FUNCTION_EXPORT_CMD(a0, a0, a1, 0)
|
|
|
|
|
2023-11-15 13:54:22 +08:00
|
|
|
#define _MSH_FUNCTION_CMD2_OPT(a0, a1, a2) \
|
2023-09-27 12:34:05 +08:00
|
|
|
MSH_FUNCTION_EXPORT_CMD(a0, a0, a1, a0##_msh_options)
|
|
|
|
|
|
|
|
#define _MSH_FUNCTION_EXPORT_CMD3(a0, a1, a2) \
|
|
|
|
MSH_FUNCTION_EXPORT_CMD(a0, a1, a2, 0)
|
|
|
|
|
2023-11-15 13:54:22 +08:00
|
|
|
#define _MSH_FUNCTION_EXPORT_CMD3_OPT(a0, a1, a2, a3) \
|
2023-09-27 12:34:05 +08:00
|
|
|
MSH_FUNCTION_EXPORT_CMD(a0, a1, a2, a0##_msh_options)
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This macro exports a system function to finsh shell.
|
|
|
|
*
|
|
|
|
* @param name the name of function.
|
|
|
|
* @param desc the description of function, which will show in help.
|
|
|
|
*/
|
2021-08-23 18:37:58 +08:00
|
|
|
#define FINSH_FUNCTION_EXPORT(name, desc)
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
/**
|
|
|
|
* @ingroup finsh
|
|
|
|
*
|
|
|
|
* This macro exports a system function with an alias name to finsh shell.
|
|
|
|
*
|
|
|
|
* @param name the name of function.
|
|
|
|
* @param alias the alias name of function.
|
|
|
|
* @param desc the description of function, which will show in help.
|
|
|
|
*/
|
2021-08-23 18:37:58 +08:00
|
|
|
#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2010-11-29 08:04:55 +08:00
|
|
|
/**
|
2021-09-06 00:07:35 +08:00
|
|
|
* @ingroup msh
|
2021-08-23 17:30:05 +08:00
|
|
|
*
|
|
|
|
* This macro exports a command to module shell.
|
|
|
|
*
|
2021-09-06 00:07:35 +08:00
|
|
|
* @param command is the name of the command.
|
|
|
|
* @param desc is the description of the command, which will show in help list.
|
2023-09-27 12:34:05 +08:00
|
|
|
* @param opt This is an option, enter any content to enable option completion
|
2010-11-29 08:04:55 +08:00
|
|
|
*/
|
2023-09-27 12:34:05 +08:00
|
|
|
/* MSH_CMD_EXPORT(command, desc) or MSH_CMD_EXPORT(command, desc, opt) */
|
|
|
|
#define MSH_CMD_EXPORT(...) \
|
2023-11-15 13:54:22 +08:00
|
|
|
__MSH_GET_MACRO(__VA_ARGS__, _MSH_FUNCTION_CMD2_OPT, \
|
2023-09-27 12:34:05 +08:00
|
|
|
_MSH_FUNCTION_CMD2)(__VA_ARGS__)
|
2021-09-06 00:07:35 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup msh
|
|
|
|
*
|
|
|
|
* 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.
|
2023-09-27 12:34:05 +08:00
|
|
|
* @param opt This is an option, enter any content to enable option completion
|
2021-09-06 00:07:35 +08:00
|
|
|
*/
|
2023-09-27 12:34:05 +08:00
|
|
|
/* #define MSH_CMD_EXPORT_ALIAS(command, alias, desc) or
|
|
|
|
#define MSH_CMD_EXPORT_ALIAS(command, alias, desc, opt) */
|
|
|
|
#define MSH_CMD_EXPORT_ALIAS(...) \
|
2023-11-15 13:54:22 +08:00
|
|
|
__MSH_GET_EXPORT_MACRO(__VA_ARGS__, _MSH_FUNCTION_EXPORT_CMD3_OPT, \
|
2023-09-27 12:34:05 +08:00
|
|
|
_MSH_FUNCTION_EXPORT_CMD3)(__VA_ARGS__)
|
2021-08-23 17:30:05 +08:00
|
|
|
|
|
|
|
/* system call table */
|
|
|
|
struct finsh_syscall
|
|
|
|
{
|
|
|
|
const char *name; /* the name of system call */
|
|
|
|
#if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB)
|
|
|
|
const char *desc; /* description of system call */
|
|
|
|
#endif
|
2023-09-27 12:34:05 +08:00
|
|
|
|
|
|
|
#ifdef FINSH_USING_OPTION_COMPLETION
|
|
|
|
struct msh_cmd_opt *opt;
|
|
|
|
#endif
|
2021-08-23 17:30:05 +08:00
|
|
|
syscall_func func; /* the function address of system call */
|
|
|
|
};
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
/* system call item */
|
|
|
|
struct finsh_syscall_item
|
|
|
|
{
|
2021-08-23 17:30:05 +08:00
|
|
|
struct finsh_syscall_item *next; /* next item */
|
2018-03-01 21:01:20 +08:00
|
|
|
struct finsh_syscall syscall; /* syscall */
|
2009-07-03 06:48:23 +08:00
|
|
|
};
|
|
|
|
|
2023-09-27 12:34:05 +08:00
|
|
|
#ifdef FINSH_USING_OPTION_COMPLETION
|
|
|
|
typedef struct msh_cmd_opt
|
|
|
|
{
|
2023-11-15 13:54:22 +08:00
|
|
|
rt_uint32_t id;
|
|
|
|
const char *name;
|
|
|
|
const char *des;
|
2023-09-27 12:34:05 +08:00
|
|
|
} msh_cmd_opt_t;
|
|
|
|
|
|
|
|
#define CMD_OPTIONS_STATEMENT(command) static struct msh_cmd_opt command##_msh_options[];
|
|
|
|
#define CMD_OPTIONS_NODE_START(command) static struct msh_cmd_opt command##_msh_options[] = {
|
|
|
|
#define CMD_OPTIONS_NODE(_id, _name, _des) {.id = _id, .name = #_name, .des = #_des},
|
|
|
|
#define CMD_OPTIONS_NODE_END {0},};
|
|
|
|
|
|
|
|
void msh_opt_list_dump(void *options);
|
|
|
|
int msh_cmd_opt_id_get(int argc, char *argv[], void *options);
|
|
|
|
#define MSH_OPT_ID_GET(fun) msh_cmd_opt_id_get(argc, argv, (void*) fun##_msh_options)
|
|
|
|
#define MSH_OPT_DUMP(fun) msh_opt_list_dump((void*) fun##_msh_options)
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define CMD_OPTIONS_STATEMENT(command)
|
|
|
|
#define CMD_OPTIONS_NODE_START(command)
|
|
|
|
#define CMD_OPTIONS_NODE(_id, _name, _des)
|
|
|
|
#define CMD_OPTIONS_NODE_END
|
2023-11-15 13:54:22 +08:00
|
|
|
#define MSH_OPT_ID_GET(fun) ((int)(-1UL))
|
|
|
|
#define MSH_OPT_DUMP(fun) do{}while(0)
|
2023-09-27 12:34:05 +08:00
|
|
|
#endif
|
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
extern struct finsh_syscall_item *global_syscall_list;
|
|
|
|
extern struct finsh_syscall *_syscall_table_begin, *_syscall_table_end;
|
2012-10-22 11:12:21 +08:00
|
|
|
|
2013-01-22 12:44:47 +08:00
|
|
|
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__))
|
2021-08-23 17:30:05 +08:00
|
|
|
struct finsh_syscall *finsh_syscall_next(struct finsh_syscall *call);
|
|
|
|
#define FINSH_NEXT_SYSCALL(index) index=finsh_syscall_next(index)
|
2012-12-29 16:11:38 +08:00
|
|
|
#else
|
2021-08-23 17:30:05 +08:00
|
|
|
#define FINSH_NEXT_SYSCALL(index) index++
|
2012-12-29 16:11:38 +08:00
|
|
|
#endif
|
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
/* find out system call, which should be implemented in user program */
|
|
|
|
struct finsh_syscall *finsh_syscall_lookup(const char *name);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2022-01-03 06:51:44 +08:00
|
|
|
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
|
2021-10-21 09:44:01 +08:00
|
|
|
void finsh_set_device(const char *device_name);
|
2009-09-28 07:58:05 +08:00
|
|
|
#endif
|
2009-07-03 06:48:23 +08:00
|
|
|
|
|
|
|
#endif
|