• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef TIMER_IF_H
10 #define TIMER_IF_H
11 
12 #include "platform_if.h"
13 
14 #ifdef __cplusplus
15 #if __cplusplus
16 extern "C" {
17 #endif
18 #endif /* __cplusplus */
19 
20 /**
21  * @brief Defines a callback that will be invoked when a timer's interrupt involved.
22  */
23 typedef int32_t (*TimerHandleCb)(uint32_t number);
24 
25 /**
26  * @brief Gets a hardware timer.
27  * This function must be called to get its device handle before operating the timer.
28  * @param number Indicates a timer id.
29  * @return If the operation is successful, a pointer to the timer device handle is returned.
30  * @since 1.0
31  */
32 DevHandle HwTimerOpen(const uint32_t number);
33 
34 /**
35  * @brief Close a hardware timer.
36  * If you no longer need the timer, call this function to close it
37  * @param handle Represents a pointer to the timer device handle.
38  * @since 1.0
39  */
40 void HwTimerClose(DevHandle handle);
41 
42 /**
43  * @brief Start a timer.
44  * If you need the timer run, call this function to  start it
45  * @param handle Represents a pointer to the timer device handle.
46  * @return success or fail
47  * @since 1.0
48  */
49 int32_t HwTimerStart(DevHandle handle);
50 
51 /**
52  * @brief Stop a timer.
53  * If you no longer need the timer run, call this function to  stop it
54  * @param handle Represents a pointer to the timer device handle.
55  * @return success or fail
56  * @since 1.0
57  */
58 int32_t HwTimerStop(DevHandle handle);
59 
60 /**
61  * @brief Set a period timer.
62  * If you need the timer run, call this function to set timer info
63  * @param handle Represents a pointer to the timer device handle.
64  * @param useconds Represents the timer interval.
65  * @param cb Represents the timer callback function.
66  * @return success or fail
67  * @since 1.0
68  */
69 int32_t HwTimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
70 
71 /**
72  * @brief Set a oneshot timer.
73  * If you need the timer run, call this function to set timer info
74  * @param useconds Represents the timer interval.
75  * @param cb Represents the timer callback function.
76  * @return success or fail
77  * @since 1.0
78  */
79 int32_t HwTimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
80 
81 /**
82  * @brief Get the timer info.
83  * If you need the timer info, call this function get
84  * @param handle Represents a pointer to the timer device handle.
85  * @param useconds Represents the timer interval.
86  * @param isPeriod Represents whether the timer call once
87  * @return success or fail
88  * @since 1.0
89  */
90 int32_t HwTimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod);
91 
92 /**
93  * @brief Enumerates TIMER I/O commands.
94  *
95  * @since 1.0
96  */
97 enum TimerIoCmd {
98     TIMER_IO_OPEN = 0, /**< Open the TIMER device. */
99     TIMER_IO_CLOSE,    /**< Close the TIMER device. */
100     TIMER_IO_START,    /**< Start the TIMER. */
101     TIMER_IO_STOP,     /**< Stop the TIMER. */
102     TIMER_IO_SET,      /**< Set the period TIMER info. */
103     TIMER_IO_SETONCE,  /**< Set the once TIMER info. */
104     TIMER_IO_GET,      /**< Get the TIMER info. */
105 };
106 
107 #pragma pack(push, 4)
108 struct TimerConfig {
109     uint32_t number;
110     uint32_t useconds;
111     bool isPeriod;
112 };
113 #pragma pack(pop)
114 
115 #ifdef __cplusplus
116 #if __cplusplus
117 }
118 #endif
119 #endif /* __cplusplus */
120 
121 #endif /* TIMER_IF_H */
122 /** @} */
123