-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathcmd.h
49 lines (39 loc) · 1.53 KB
/
cmd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* @Author: jiejie
* @Github: https://github.com/jiejieTop
* @Date: 2019-12-13 10:48:52
* @LastEditTime: 2019-12-16 21:26:56
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
*/
#ifndef _CMD_H_
#define _CMD_H_
#define CMD_HASH 0xb433e5c6
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */
#define SECTION(x) __attribute__((section(x)))
#define CMD_USED __attribute__((used))
#elif defined (__IAR_SYSTEMS_ICC__) /* IAR Compiler */
#define SECTION(x) @ x
#define CMD_USED __root
#else
#error "not supported tool chain..."
#endif
typedef void (*cmd_handler)(void);
typedef struct cmd {
const char* cmd;
const char* cmd_mess;
unsigned int hash;
cmd_handler handler;
} cmd_t;
#define REGISTER_CMD(cmd, handler,desc) \
const char _register_##cmd##_cmd[] = #cmd; \
const char _register_##cmd##_desc[] = #desc; \
CMD_USED cmd_t _register_##cmd SECTION("CMDS")= \
{ \
_register_##cmd##_cmd, \
_register_##cmd##_desc, \
(unsigned int)CMD_HASH, \
(cmd_handler)&handler \
};
void cmd_init(void);
void cmd_parsing(char *str);
#endif