summaryrefslogtreecommitdiff
path: root/bsp/allwinner/libraries/sunxi-hal/include/hal/sdmmc/cmd/cmd_util.h
blob: 97793c4c3091e355eb7e0f38654123af317f0760 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *    1. Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the
 *       distribution.
 *    3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
 *       its contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _CMD_UTIL_H_
#define _CMD_UTIL_H_

#include <stdlib.h>
#include <string.h>
#include "sys/param.h"
#include "cmd_defs.h"
#include "cmd_debug.h"
//#include "console/console.h"
#include "os.h"

#ifdef __cplusplus
extern "C" {
#endif

/* command format: <command-name> <arg>... */
struct cmd_data {
    char *name;
    enum cmd_status (*exec)(char *);
};

/* command2 format: <command-name>[ <arg>...] */
struct cmd2_data {
    char *name;
    int name_len;
    enum cmd_status (*exec)(char *);
};

enum cmd_status cmd_exec(char *cmd, const struct cmd_data *cdata, int count);
enum cmd_status cmd2_exec(char *cmd, const struct cmd2_data *cdata, int count);

int cmd_parse_argv(char *cmd, char *argv[], int size);

const char *cmd_get_status_desc(enum cmd_status status);
//const char *cmd_get_event_desc(enum cmd_event event);

int cmd_write(enum cmd_code_type type, int code, const char *fmt, ...);

#define cmd_write_respond(status, fmt, arg...) \
    cmd_write(CMD_CODE_TYEP_STATUS, (int)status, fmt, ##arg)

#define cmd_write_event(event, fmt, arg...) \
    cmd_write(CMD_CODE_TYEP_EVENT, (int)event, fmt, ##arg)

int32_t cmd_raw_mode_read(uint8_t *buf, int32_t size, uint32_t msec);
int32_t cmd_raw_mode_write(uint8_t *buf, int32_t size);

#define cmd_raw_mode_enable()   console_disable();
#define cmd_raw_mode_disable()  console_enable();


#define cmd_malloc(l)               malloc(l)
#define cmd_free(p)                 free(p)

#define cmd_memcpy(d, s, n)         memcpy(d, s, n)
#define cmd_memset(s, c, n)         memset(s, c, n)
#define cmd_memcmp(s1, s2, n)       memcmp(s1, s2, n)

#define cmd_strlen(s)               strlen(s)
#define cmd_strcmp(s1, s2)          strcmp(s1, s2)
#define cmd_strncmp(s1, s2, n)      strncmp(s1, s2, n)
#define cmd_strcasecmp(s1, s2)      strcasecmp(s1, s2)
#define cmd_strncasecmp(s1, s2, n)  strncasecmp(s1, s2, n)
#define cmd_strchr(s, c)            strchr(s, c)
#define cmd_strrchr(s, c)           strrchr(s, c)
#define cmd_strstr(s1, s2)          strstr(s1, s2)
#define cmd_strtol(s, p, b)         strtol(s, p, b)
#define cmd_strdup(s)               strdup(s)
#define cmd_strlcpy(d, s, n)        strlcpy(d, s, n)

#define cmd_atoi(s)                 atoi(s)
#define cmd_atol(s)                 atol(s)

#define cmd_sscanf(s, f, a...)      sscanf(s, f, ##a)
#define cmd_sprintf(s, f, a...)     sprintf(s, f, ##a)
#define cmd_snprintf(s, n, f, a...) snprintf(s, n, f, ##a)

#define cmd_nitems(a)               nitems(a)

#define cmd_msleep(msec)            OS_MSleep(msec)

#ifdef __cplusplus
}
#endif

#endif /* _CMD_UTIL_H_ */