• 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_timer.h
25  *
26  * @brief Declares timer types and interfaces.
27  *
28  * @since 1.0
29  * @version 1.0
30  */
31 #ifndef OSAL_TIMER_H
32 #define OSAL_TIMER_H
33 
34 #include "hdf_base.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39 
40 /**
41  * @brief Describes a timer.
42  */
43 typedef struct {
44     void *realTimer; /**< Pointer to a timer object */
45 } OsalTimer;
46 
47 /**
48  * @brief Describes a timer execution function type.
49  */
50 typedef void (*OsalTimerFunc)(uintptr_t arg);
51 
52 /**
53  * @brief Defines a timer macro.
54  */
55 #define OSAL_DECLARE_TIMER(timer) OsalTimer timer
56 
57 /**
58  * @brief Creates a timer.
59  *
60  * @param timer Indicates the pointer to the timer {@link OsalTimer}.
61  * @param interval Indicates the timer interval.
62  * @param func Indicates the timer execution function {@link OsalTimerFunc}.
63  * @param arg Indicates the argument passed to the timer execution function.
64  *
65  * @return Returns a value listed below: \n
66  * HDF_STATUS | Description
67  * ----------------------| -----------------------
68  * HDF_SUCCESS | The operation is successful.
69  * HDF_FAILURE | Failed to invoke the system function.
70  * HDF_ERR_INVALID_PARAM | Invalid parameter.
71  * HDF_ERR_MALLOC_FAIL | Memory allocation fails.
72  *
73  * @since 1.0
74  * @version 1.0
75  */
76 int32_t OsalTimerCreate(OsalTimer *timer, uint32_t interval, OsalTimerFunc func, uintptr_t arg);
77 
78 /**
79  * @brief Deletes a timer.
80  *
81  * @param timer Indicates the pointer to the timer {@link OsalTimer}.
82  *
83  * @return Returns a value listed below: \n
84  * HDF_STATUS | Description
85  * ----------------------| -----------------------
86  * HDF_SUCCESS | The operation is successful.
87  * HDF_FAILURE | Failed to invoke the system function to delete the timer.
88  * HDF_ERR_INVALID_PARAM | Invalid parameter.
89  *
90  * @since 1.0
91  * @version 1.0
92  */
93 int32_t OsalTimerDelete(OsalTimer *timer);
94 
95 /**
96  * @brief Starts a timer.
97  *
98  * @param timer Indicates the pointer to the timer {@link OsalTimer}.
99  *
100  * @return Returns a value listed below: \n
101  * HDF_STATUS | Description
102  * ----------------------| -----------------------
103  * HDF_SUCCESS | The operation is successful.
104  * HDF_FAILURE | Failed to invoke the system function to start the timer.
105  * HDF_ERR_INVALID_PARAM | Invalid parameter.
106  *
107  * @since 1.0
108  * @version 1.0
109  */
110 int32_t OsalTimerStartOnce(OsalTimer *timer);
111 
112 /**
113  * @brief Starts a periodic timer.
114  *
115  * @param timer Indicates the pointer to the timer {@link OsalTimer}.
116  * @param interval Indicates the timer interval, in milliseconds.
117  *
118  * @return Returns a value listed below: \n
119  * HDF_STATUS | Description
120  * ----------------------| -----------------------
121  * HDF_SUCCESS | The operation is successful.
122  * HDF_FAILURE | Failed to invoke the system function to start the timer.
123  * HDF_ERR_INVALID_PARAM | Invalid parameter.
124  *
125  * @since 1.0
126  * @version 1.0
127  */
128 int32_t OsalTimerStartLoop(OsalTimer *timer);
129 
130 /**
131  * @brief Sets the interval of a timer.
132  *
133  * @param timer Indicates the pointer to the timer {@link OsalTimer}.
134  * @param interval Indicates the timer interval, in milliseconds.
135  *
136  * @return Returns a value listed below: \n
137  * HDF_STATUS | Description
138  * ----------------------| -----------------------
139  * HDF_SUCCESS | The operation is successful.
140  * HDF_FAILURE | Failed to invoke the system function.
141  * HDF_ERR_INVALID_PARAM | Invalid parameter.
142  *
143  * @since 1.0
144  * @version 1.0
145  */
146 int32_t OsalTimerSetTimeout(OsalTimer *timer, uint32_t interval);
147 
148 #ifdef __cplusplus
149 }
150 #endif /* __cplusplus */
151 
152 #endif /* OSAL_TIMER_H */
153 /** @} */
154