• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description:  \n
16  *
17  * History: \n
18  * 2023-03-02, Create file. \n
19  */
20 #ifndef HAL_RTC_H
21 #define HAL_RTC_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 #include "rtc_porting.h"
26 
27 #ifdef __cplusplus
28 #if __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 #endif /* __cplusplus */
32 
33 /**
34  * @defgroup drivers_hal_rtc_api RTC
35  * @ingroup  drivers_hal_rtc
36  * @{
37  */
38 
39 /**
40  * @if Eng
41  * @brief  Callback of RTC.
42  * @param  [in]  index Index of the hardware rtc. For detail, see @ref rtc_index_t.
43  * @else
44  * @brief  RTC的回调函数。
45  * @param  [in]  index 硬件定时器索引值,参考 @ref rtc_index_t 。
46  * @endif
47  */
48 typedef void (*hal_rtc_callback_t)(rtc_index_t index);
49 
50 /**
51  * @if Eng
52  * @brief  HAL RTC initialize interface.
53  * @param  [in]  index Index of the hardware rtc. For detail, see @ref rtc_index_t.
54  * @param  [in]  callback Callback of RTC.
55  * @retval ERRCODE_SUCC   Success.
56  * @retval Other          Failure. For details, see @ref errcode_t
57  * @else
58  * @brief  HAL层RTC的初始化接口。
59  * @param  [in]  index 硬件定时器索引值,参考 @ref rtc_index_t 。
60  * @param  [in]  callback RTC的回调函数。
61  * @retval ERRCODE_SUCC 成功。
62  * @retval Other        失败,参考 @ref errcode_t 。
63  * @endif
64  */
65 errcode_t hal_rtc_init(rtc_index_t index, hal_rtc_callback_t callback);
66 
67 /**
68  * @if Eng
69  * @brief  HAL RTC deinitialize interface.
70  * @param  [in]  index Index of the hardware rtc. For detail, see @ref rtc_index_t.
71  * @else
72  * @brief  HAL层RTC的去初始化接口。
73  * @param  [in]  index 硬件定时器索引值,参考 @ref rtc_index_t 。
74  * @endif
75  */
76 void hal_rtc_deinit(rtc_index_t index);
77 
78 /**
79  * @if Eng
80  * @brief  HAL RTC start the load count of hardware RTC interface.
81  * @param  [in]  index Index of low layer RTC. For detail, see @ref rtc_index_t.
82  * @else
83  * @brief  HAL层启动硬件定时器计数的接口。
84  * @param  [in]  index RTC底层索引值,参考 @ref rtc_index_t 。
85  * @endif
86  */
87 void hal_rtc_start(rtc_index_t index);
88 
89 /**
90  * @if Eng
91  * @brief  HAL RTC stop the load count of hardware RTC interface.
92  * @param  [in]  index Index of low layer RTC. For detail, see @ref rtc_index_t.
93  * @else
94  * @brief  HAL层停止硬件定时器计数的接口。
95  * @param  [in]  index rtc底层索引值,参考 @ref rtc_index_t 。
96  * @endif
97  */
98 void hal_rtc_stop(rtc_index_t index);
99 
100 /**
101  * @if Eng
102  * @brief  HAL RTC set the load count of hardware RTC interface.
103  * @param  [in]  index Index of low layer RTC. For detail, see @ref rtc_index_t.
104  * @param  [in]  delay_count Time for load count.
105  * @else
106  * @brief  HAL层设置硬件计时器计数的接口。
107  * @param  [in]  index rtc底层索引值,参考 @ref rtc_index_t 。
108  * @param  [in]  delay_count 计时的时间。
109  * @endif
110  */
111 void hal_rtc_config_load(rtc_index_t index, uint64_t delay_count);
112 
113 /**
114  * @if Eng
115  * @brief  HAL RTC get the current value of hardware RTC interface.
116  * @param  [in]  index Index of low layer RTC. For detail, see @ref rtc_index_t.
117  * @return RTC load count.
118  * @else
119  * @brief  HAL层获取硬件当时计时器剩余计数的接口。
120  * @param  [in]  index rtc底层索引值,参考 @ref rtc_index_t 。
121  * @return rtc计数值。
122  * @endif
123  */
124 uint64_t hal_rtc_get_current_value(rtc_index_t index);
125 
126 /**
127  * @if Eng
128  * @brief  HAL RTC get the count of RTC IRQ.
129  * @return RTC irq count.
130  * @else
131  * @brief  HAL层获取RTC发生中断的次数的值。
132  * @return rtc中断计数值。
133  * @endif
134  */
135 uint32_t hal_rtc_get_int_cnt_record(void);
136 
137 /**
138  * @if Eng
139  * @brief  HAL RTC get the current interrupt status of hardware RTC interface.
140  * @param  [in]  index Index of low layer RTC. For detail, see @ref rtc_index_t.
141  * @return RTC load count.
142  * @else
143  * @brief  HAL层获取硬件当时计时器中断状态。
144  * @param  [in]  index rtc底层索引值,参考 @ref rtc_index_t 。
145  * @return rtc计数值。
146  * @endif
147  */
148 uint32_t hal_rtc_get_int_status(rtc_index_t index);
149 
150 /**
151  * @if Eng
152  * @brief  Init the RTC which will set the base address of registers.
153  * @param  [in]  index Index of low layer RTC. For detail, see @ref rtc_index_t.
154  * @retval ERRCODE_SUCC   Success.
155  * @retval Other          Failure. For details, see @ref errcode_t.
156  * @else
157  * @brief  初始化rtc,设置寄存器的基地址。
158  * @param  [in]  index rtc底层索引值,参考 @ref rtc_index_t 。
159  * @retval ERRCODE_SUCC 成功。
160  * @retval Other        失败,参考 @ref errcode_t 。
161  * @endif
162  */
163 errcode_t hal_rtc_regs_init(rtc_index_t index);
164 
165 /**
166  * @if Eng
167  * @brief  Deinit the hal_drv_rtc which will clear the base address of registers has been
168  *         set by @ref hal_rtc_regs_init.
169  * @param  [in]  index Index of low layer RTC. For detail, see @ref rtc_index_t.
170  * @else
171  * @brief  去初始化,然后清除在 @ref hal_rtc_regs_init 中设置的寄存器地址。
172  * @param  [in]  index rtc底层索引值,参考 @ref rtc_index_t 。
173  * @endif
174  */
175 void hal_rtc_regs_deinit(rtc_index_t index);
176 
177 
178 /**
179  * @}
180  */
181 
182 #ifdef __cplusplus
183 #if __cplusplus
184 }
185 #endif /* __cplusplus */
186 #endif /* __cplusplus */
187 
188 #endif