• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2023 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 /**
10  * @addtogroup DriverUtils
11  * @{
12  *
13  * @brief Defines common macros and interfaces of the driver module.
14  *
15  * This module provides interfaces such as log printing, doubly linked list operations, and work queues.
16  *
17  * @since 1.0
18  * @version 1.0
19  */
20 
21 /**
22  * @file hdf_base.h
23  *
24  * @brief Declares driver common types, including the enumerated values returned by the function
25  * and the macro for obtaining the array size.
26  *
27  * @since 1.0
28  * @version 1.0
29  */
30 #ifndef HDF_BASE_TYPE_H
31 #define HDF_BASE_TYPE_H
32 
33 #include "hdf_types.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38 
39 /**
40  * @brief Enumerates HDF return value types.
41  */
42 typedef enum {
43     HDF_SUCCESS  = 0, /**< The operation is successful. */
44     HDF_FAILURE = -1, /**< Failed to invoke the OS underlying function. */
45     HDF_ERR_NOT_SUPPORT = -2, /**< Not supported. */
46     HDF_ERR_INVALID_PARAM = -3, /**< Invalid parameter. */
47     HDF_ERR_INVALID_OBJECT = -4, /**< Invalid object. */
48     HDF_ERR_MALLOC_FAIL    = -6, /**< Memory allocation fails. */
49     HDF_ERR_TIMEOUT        = -7, /**< Timeout occurs. */
50     HDF_ERR_THREAD_CREATE_FAIL = -10, /**< Failed to create a thread. */
51     HDF_ERR_QUEUE_FULL  = -15, /**< The queue is full. */
52     HDF_ERR_DEVICE_BUSY = -16, /**< The device is busy. */
53     HDF_ERR_IO          = -17, /**< I/O error. */
54     HDF_ERR_BAD_FD      = -18, /**< Incorrect file descriptor. */
55     HDF_ERR_NOPERM      = -19, /**< No permission. */
56     HDF_ERR_OUT_OF_RANGE = -20, /**< Failed to get all result */
57 
58 #define HDF_BSP_ERR_START (-100) /**< Defines the start of the Board Support Package (BSP) module error codes. */
59 #define HDF_BSP_ERR_NUM(v) (HDF_BSP_ERR_START + (v)) /**< Defines the BSP module error codes. */
60     HDF_BSP_ERR_OP = HDF_BSP_ERR_NUM(-1), /**< Failed to operate a BSP module. */
61     HDF_ERR_BSP_PLT_API_ERR = HDF_BSP_ERR_NUM(-2), /**< The platform API of the BSP module is incorrect. */
62     HDF_PAL_ERR_DEV_CREATE = HDF_BSP_ERR_NUM(-3), /**< Failed to create a BSP module device. */
63     HDF_PAL_ERR_INNER = HDF_BSP_ERR_NUM(-4), /**< Internal error codes of the BSP module. */
64 
65 #define HDF_DEV_ERR_START (-200) /**< Defines the start of the device module error codes. */
66 #define HDF_DEV_ERR_NUM(v) (HDF_DEV_ERR_START + (v)) /**< Defines the device module error codes. */
67     HDF_DEV_ERR_NO_MEMORY               = HDF_DEV_ERR_NUM(-1), /**< Failed to allocate memory to the device module. */
68     HDF_DEV_ERR_NO_DEVICE               = HDF_DEV_ERR_NUM(-2), /**< The device module has no device. */
69     HDF_DEV_ERR_NO_DEVICE_SERVICE       = HDF_DEV_ERR_NUM(-3), /**< The device module has no device service. */
70     HDF_DEV_ERR_DEV_INIT_FAIL           = HDF_DEV_ERR_NUM(-4), /**< Failed to initialize a device module. */
71     HDF_DEV_ERR_PUBLISH_FAIL            = HDF_DEV_ERR_NUM(-5), /**< The device module failed to release a service. */
72     HDF_DEV_ERR_ATTACHDEV_FAIL          = HDF_DEV_ERR_NUM(-6), /**< Failed to attach a device to a device module. */
73     HDF_DEV_ERR_NODATA                  = HDF_DEV_ERR_NUM(-7), /**< Failed to read data from a device module. */
74     HDF_DEV_ERR_NORANGE                 = HDF_DEV_ERR_NUM(-8), /**< The device module data is out of range. */
75     HDF_DEV_ERR_OP                      = HDF_DEV_ERR_NUM(-10), /**< Failed to operate a device module. */
76     HDF_DEV_ERR_NETDOWN                 = HDF_DEV_ERR_NUM(-11), /**< The network is down. */
77 } HDF_STATUS;
78 
79 /**
80  * @brief Indicates that the function keeps waiting to obtain a semaphore or mutex.
81  */
82 #define HDF_WAIT_FOREVER 0xFFFFFFFF
83 
84 /**
85  * @brief Defines the array size.
86  */
87 #define HDF_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
88 
89 /**
90  * @brief Defines a time conversion unit, for example, the unit for converting from second to millisecond.
91  */
92 #define HDF_KILO_UNIT 1000
93 
94 #ifdef __LITEOS__
95 /**
96  * @brief Declares the full path of the HDF module library.
97  */
98 #define HDF_LIBRARY_FULL_PATH(x) "/usr/lib/" x ".so"
99 
100 /**
101  * @brief Declares the directory of the HDF module library.
102  */
103 #define HDF_LIBRARY_DIR "/usr/lib"
104 
105 /**
106  * @brief Declares the directory of the HDF module configuration files.
107  */
108 #define HDF_ETC_DIR "/etc"
109 
110 /**
111  * @brief Declares the configuration directory of the HDF module.
112  */
113 #define HDF_CONFIG_DIR "/etc"
114 
115 /**
116  * @brief Declares the directory of the HCS configuration file of the HDF.
117  */
118 #define HDF_CHIP_PROD_CONFIG_DIR "/etc"
119 
120 /**
121  * @brief Declares the name of the HDF module library.
122  */
123 #define HDF_LIBRARY_NAME(x) x ".so"
124 #else
125 /**
126  * @brief Declares the full path of the HDF module library.
127  */
128 #ifdef __aarch64__
129 #define HDF_LIBRARY_FULL_PATH(x) "/vendor/lib64/" x ".z.so"
130 #else
131 #define HDF_LIBRARY_FULL_PATH(x) "/vendor/lib/" x ".z.so"
132 #endif
133 
134 /**
135  * @brief Declares the directory of the HDF module library.
136  */
137 #define HDF_LIBRARY_DIR "/vendor/lib"
138 
139 /**
140  * @brief Declares the directory of the HDF module configuration files.
141  */
142 #define HDF_ETC_DIR "/vendor/etc"
143 
144 /**
145  * @brief Declares the configuration directory of the HDF module.
146  */
147 #define HDF_CONFIG_DIR "/vendor/etc/hdfconfig"
148 
149 /**
150  * @brief Declares the directory of the HCS configuration file of the HDF.
151  */
152 #define HDF_CHIP_PROD_CONFIG_DIR "/chip_prod/etc/hdfconfig"
153 
154 /**
155  * @brief Declares the installation directory of the HDF kernel-mode service module driver.
156  */
157 #define HDF_MODULE_DIR "/vendor/modules/"
158 
159 /**
160  * @brief Declares the name of the HDF module library.
161  */
162 #define HDF_LIBRARY_NAME(x) x ".z.so"
163 #endif
164 
165 #ifdef __cplusplus
166 }
167 #endif /* __cplusplus */
168 
169 #endif /* HDF_BASE_TYPE_H */
170 /** @} */
171