• 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 OSAL
11  * @{
12  *
13  * @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
14  *
15  * The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally,
16  * including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
17  * atomic, firmware, and I/O operation modules.
18  *
19  * @since 1.0
20  * @version 1.0
21  */
22 
23 /**
24  * @file osal_time.h
25  *
26  * @brief Declares the time, sleep, and delay interfaces.
27  *
28  * @since 1.0
29  * @version 1.0
30  */
31 #ifndef OSAL_TIME_H
32 #define OSAL_TIME_H
33 
34 #include "hdf_base.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39 
40 /**
41  * @brief Defines time.
42  */
43 typedef struct {
44     uint64_t sec; /**< Second */
45     uint64_t usec; /**< Microsecond */
46 } OsalTimespec;
47 
48 /**
49  * @brief Describes thread sleep, in seconds.
50  *
51  * When a thread invokes this function, the CPU is released and the thread enters the sleep state.
52  *
53  * @param sec Indicates the sleep time, in seconds.
54  * @since 1.0
55  * @version 1.0
56  */
57 void OsalSleep(uint32_t sec);
58 
59 /**
60  * @brief Describes thread sleep, in milliseconds.
61  *
62  * When a thread invokes this function, the CPU is released and the thread enters the sleep state.
63  *
64  * @param ms Indicates the sleep time, in milliseconds.
65  * @since 1.0
66  * @version 1.0
67  */
68 void OsalMSleep(uint32_t ms);
69 
70 /**
71  * @brief Describes thread sleep, in microsecond.
72  *
73  * When a thread invokes this function, the CPU is released and the thread enters the sleep state.
74  *
75  * @param us Indicates the sleep time, in microsecond.
76  * @since 1.0
77  * @version 1.0
78  */
79 void OsalUSleep(uint32_t us);
80 
81 /**
82  * @brief Obtains the second and microsecond time.
83  *
84  * @param time Indicates the pointer to the time structure {@link OsalTimespec}.
85  *
86  * @return Returns a value listed below: \n
87  * HDF_STATUS | Description
88  * ----------------------| -----------------------
89  * HDF_SUCCESS | The operation is successful.
90  * HDF_FAILURE | Failed to invoke the system function to obtain time.
91  * HDF_ERR_INVALID_PARAM | Invalid parameter.
92  *
93  * @since 1.0
94  * @version 1.0
95  */
96 int32_t OsalGetTime(OsalTimespec *time);
97 
98 /**
99  * @brief Obtains time difference.
100  *
101  * @param start Indicates the pointer to the start time {@link OsalTimespec}.
102  * @param end Indicates the pointer to the end time {@link OsalTimespec}.
103  * @param diff Indicates the pointer to the time difference {@link OsalTimespec}.
104  *
105  * @return Returns a value listed below: \n
106  * HDF_STATUS | Description
107  * ----------------------| -----------------------
108  * HDF_SUCCESS | The operation is successful.
109  * HDF_ERR_INVALID_PARAM | Invalid parameter.
110  *
111  * @since 1.0
112  * @version 1.0
113  */
114 int32_t OsalDiffTime(const OsalTimespec *start, const OsalTimespec *end, OsalTimespec *diff);
115 
116 /**
117  * @brief Obtains the system time.
118  *
119  * @return Returns the system time, in milliseconds.
120  * @since 1.0
121  * @version 1.0
122  */
123 uint64_t OsalGetSysTimeMs(void);
124 
125 /**
126  * @brief Describes thread delay, in milliseconds.
127  *
128  * When a thread invokes this function, the CPU is not released. This function returns after waiting for milliseconds.
129  *
130  * @param ms Indicates the delay time, in milliseconds.
131  * @since 1.0
132  * @version 1.0
133  */
134 void OsalMDelay(uint32_t ms);
135 
136 /**
137  * @brief Describes thread delay, in microseconds.
138  *
139  * When a thread invokes this function, the CPU is not released. This function returns after waiting for microseconds.
140  *
141  * @param us Indicates the delay time, in microseconds.
142  * @since 1.0
143  * @version 1.0
144  */
145 void OsalUDelay(uint32_t us);
146 
147 #ifdef __cplusplus
148 }
149 #endif /* __cplusplus */
150 
151 #endif /* OSAL_TIME_H */
152 /** @} */
153