45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
#ifndef __COMMAND_H_
|
|
#define __COMMAND_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define SECTION(x) __attribute__((section(x)))
|
|
#define UNUSED __attribute__((unused))
|
|
#define USED __attribute__((used))
|
|
#define ALIGN(n) __attribute__((aligned(n)))
|
|
#define WEAK __attribute__((weak))
|
|
|
|
//##后的参数本身也是一个宏的话,##会阻止这个宏的展开,也就是只替换一次,故需要中继
|
|
#define __command_func_line_connect_(func, line) func##line
|
|
#define __command_func_line_define_(func, line) __command_func_line_connect_(func, line)
|
|
#define __command_func_line_(func, line) __command_func_line_define_(func, line)
|
|
|
|
extern void * __start_command;
|
|
extern void * __stop_command;
|
|
|
|
#define CMD_LENGTH(x) (sizeof(x)/sizeof(x[0]))
|
|
|
|
//声明command_func为函数指针
|
|
typedef void (*command_func)(int argc, char *argv[]);
|
|
|
|
//定义命令结构体
|
|
typedef struct cmd
|
|
{
|
|
char *cmd_name; //命令名称
|
|
command_func cmd_func;//命令处理函数
|
|
}command_t;
|
|
|
|
#define __command_initialize(cmd, func) USED SECTION("command") ALIGN(sizeof(void*)) \
|
|
command_t __command_func_line_(func, __LINE__) = {cmd, func}
|
|
|
|
//分析、分配命令
|
|
extern int execute_command(char *command, command_t *list, int list_size);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|