• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 
57 #define HDF_BSP_ERR_START (-100) /**< Defines the start of the Board Support Package (BSP) module error codes. */
58 #define HDF_BSP_ERR_NUM(v) (HDF_BSP_ERR_START + (v)) /**< Defines the BSP module error codes. */
59     HDF_BSP_ERR_OP = HDF_BSP_ERR_NUM(-1), /**< Failed to operate a BSP module. */
60     HDF_ERR_BSP_PLT_API_ERR = HDF_BSP_ERR_NUM(-2), /**< The platform API of the BSP module is incorrect. */
61     HDF_PAL_ERR_DEV_CREATE = HDF_BSP_ERR_NUM(-3), /**< Failed to create a BSP module device. */
62     HDF_PAL_ERR_INNER = HDF_BSP_ERR_NUM(-4), /**< Internal error codes of the BSP module. */
63 
64 #define HDF_DEV_ERR_START (-200) /**< Defines the start of the device module error codes. */
65 #define HDF_DEV_ERR_NUM(v) (HDF_DEV_ERR_START + (v)) /**< Defines the device module error codes. */
66     HDF_DEV_ERR_NO_MEMORY               = HDF_DEV_ERR_NUM(-1), /**< Failed to allocate memory to the device module. */
67     HDF_DEV_ERR_NO_DEVICE               = HDF_DEV_ERR_NUM(-2), /**< The device module has no device. */
68     HDF_DEV_ERR_NO_DEVICE_SERVICE       = HDF_DEV_ERR_NUM(-3), /**< The device module has no device service. */
69     HDF_DEV_ERR_DEV_INIT_FAIL           = HDF_DEV_ERR_NUM(-4), /**< Failed to initialize a device module. */
70     HDF_DEV_ERR_PUBLISH_FAIL            = HDF_DEV_ERR_NUM(-5), /**< The device module failed to release a service. */
71     HDF_DEV_ERR_ATTACHDEV_FAIL          = HDF_DEV_ERR_NUM(-6), /**< Failed to attach a device to a device module. */
72     HDF_DEV_ERR_NODATA                  = HDF_DEV_ERR_NUM(-7), /**< Failed to read data from a device module. */
73     HDF_DEV_ERR_NORANGE                 = HDF_DEV_ERR_NUM(-8), /**< The device module data is out of range. */
74     HDF_DEV_ERR_OP                      = HDF_DEV_ERR_NUM(-10), /**< Failed to operate a device module. */
75 } HDF_STATUS;
76 
77 /**
78  * @brief Indicates that the function keeps waiting to obtain a semaphore or mutex.
79  */
80 #define HDF_WAIT_FOREVER 0xFFFFFFFF
81 
82 /**
83  * @brief Defines the array size.
84  */
85 #define HDF_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
86 
87 /**
88  * @brief Defines a time conversion unit, for example, the unit for converting from second to millisecond.
89  */
90 #define HDF_KILO_UNIT 1000
91 
92 #ifdef __LITEOS__
93 #define HDF_LIBRARY_FULL_PATH(x) "/usr/lib/" x ".so"
94 #define HDF_LIBRARY_DIR "/usr/lib"
95 #define HDF_ETC_DIR "/etc"
96 #define HDF_CONFIG_DIR "/etc"
97 #else
98 #ifdef __aarch64__
99 #define HDF_LIBRARY_FULL_PATH(x) "/vendor/lib64/" x ".z.so"
100 #else
101 #define HDF_LIBRARY_FULL_PATH(x) "/vendor/lib/" x ".z.so"
102 #endif
103 #define HDF_LIBRARY_DIR "/vendor/lib"
104 #define HDF_ETC_DIR "/vendor/etc"
105 #define HDF_CONFIG_DIR "/vendor/etc/hdfconfig"
106 #define HDF_CHIP_PROD_CONFIG_DIR "/chip_prod/etc/hdfconfig"
107 #define HDF_MODULE_DIR "/vendor/modules/"
108 #endif
109 
110 #ifdef __cplusplus
111 }
112 #endif /* __cplusplus */
113 
114 #endif /* HDF_BASE_TYPE_H */
115 /** @} */
116