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