1 // Copyright (C) 2022 Beken Corporation
2 //
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 #include "aon_rtc_ll.h"
16 #include <driver/hal/hal_aon_rtc_types.h>
17 #include "aon_rtc_hal.h"
18
aon_rtc_hal_enable(aon_rtc_hal_t * hal)19 void aon_rtc_hal_enable(aon_rtc_hal_t *hal)
20 {
21 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
22 aon_rtc_ll_enable(hal->hw);
23 }
24
aon_rtc_hal_disable(aon_rtc_hal_t * hal)25 void aon_rtc_hal_disable(aon_rtc_hal_t *hal)
26 {
27 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
28 aon_rtc_ll_disable(hal->hw);
29 }
30
aon_rtc_hal_is_enable(aon_rtc_hal_t * hal)31 bool aon_rtc_hal_is_enable(aon_rtc_hal_t *hal)
32 {
33 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
34 return aon_rtc_ll_is_enable(hal->hw);
35 }
36
aon_rtc_hal_stop_counter(aon_rtc_hal_t * hal)37 void aon_rtc_hal_stop_counter(aon_rtc_hal_t *hal)
38 {
39 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
40 aon_rtc_ll_stop_counter(hal->hw);
41 }
42
aon_rtc_hal_start_counter(aon_rtc_hal_t * hal)43 void aon_rtc_hal_start_counter(aon_rtc_hal_t *hal)
44 {
45 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
46 aon_rtc_ll_start_counter(hal->hw);
47 }
48
aon_rtc_hal_is_counter_stop(aon_rtc_hal_t * hal)49 bool aon_rtc_hal_is_counter_stop(aon_rtc_hal_t *hal)
50 {
51 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
52 return aon_rtc_ll_is_counter_stop(hal->hw);
53 }
54
aon_rtc_hal_reset_counter(aon_rtc_hal_t * hal)55 void aon_rtc_hal_reset_counter(aon_rtc_hal_t *hal)
56 {
57 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
58 aon_rtc_ll_reset_counter(hal->hw);
59 }
60
aon_rtc_hal_clear_reset_counter(aon_rtc_hal_t * hal)61 void aon_rtc_hal_clear_reset_counter(aon_rtc_hal_t *hal)
62 {
63 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
64 aon_rtc_ll_clear_reset_counter(hal->hw);
65 }
66
aon_rtc_hal_is_counter_reset(aon_rtc_hal_t * hal)67 bool aon_rtc_hal_is_counter_reset(aon_rtc_hal_t *hal)
68 {
69 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
70 return aon_rtc_ll_is_counter_reset(hal->hw);
71 }
72
aon_rtc_hal_set_tick_val(aon_rtc_hal_t * hal,uint32_t val)73 void aon_rtc_hal_set_tick_val(aon_rtc_hal_t *hal, uint32_t val)
74 {
75 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
76 aon_rtc_ll_set_tick_val(hal->hw, val);
77 }
78
aon_rtc_hal_get_tick_val(aon_rtc_hal_t * hal)79 uint32_t aon_rtc_hal_get_tick_val(aon_rtc_hal_t *hal)
80 {
81 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
82 return aon_rtc_ll_get_tick_val(hal->hw);
83 }
84
aon_rtc_hal_enable_tick_int(aon_rtc_hal_t * hal)85 void aon_rtc_hal_enable_tick_int(aon_rtc_hal_t *hal)
86 {
87 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
88 aon_rtc_ll_enable_tick_int(hal->hw);
89 }
90
aon_rtc_hal_disable_tick_int(aon_rtc_hal_t * hal)91 void aon_rtc_hal_disable_tick_int(aon_rtc_hal_t *hal)
92 {
93 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
94 aon_rtc_ll_disable_tick_int(hal->hw);
95 }
96
aon_rtc_hal_is_tick_int_enable(aon_rtc_hal_t * hal)97 bool aon_rtc_hal_is_tick_int_enable(aon_rtc_hal_t *hal)
98 {
99 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
100 return aon_rtc_ll_is_tick_int_enable(hal->hw);
101 }
102
aon_rtc_hal_get_tick_int_status(aon_rtc_hal_t * hal)103 bool aon_rtc_hal_get_tick_int_status(aon_rtc_hal_t *hal)
104 {
105 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
106 return aon_rtc_ll_get_tick_int_status(hal->hw);
107 }
108
aon_rtc_hal_clear_tick_int_status(aon_rtc_hal_t * hal)109 void aon_rtc_hal_clear_tick_int_status(aon_rtc_hal_t *hal)
110 {
111 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
112 aon_rtc_ll_clear_tick_int_status(hal->hw);
113 }
114
aon_rtc_hal_set_upper_val(aon_rtc_hal_t * hal,uint32_t up_val)115 void aon_rtc_hal_set_upper_val(aon_rtc_hal_t *hal, uint32_t up_val)
116 {
117 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
118 aon_rtc_ll_set_upper_val(hal->hw, up_val);
119 }
120
aon_rtc_hal_get_upper_val(aon_rtc_hal_t * hal)121 uint32_t aon_rtc_hal_get_upper_val(aon_rtc_hal_t *hal)
122 {
123 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
124 return aon_rtc_ll_get_upper_val(hal->hw);
125 }
126
aon_rtc_hal_enable_upper_int(aon_rtc_hal_t * hal)127 void aon_rtc_hal_enable_upper_int(aon_rtc_hal_t *hal)
128 {
129 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
130 aon_rtc_ll_enable_upper_int(hal->hw);
131 }
132
aon_rtc_hal_disable_upper_int(aon_rtc_hal_t * hal)133 void aon_rtc_hal_disable_upper_int(aon_rtc_hal_t *hal)
134 {
135 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
136 aon_rtc_ll_disable_upper_int(hal->hw);
137 }
138
aon_rtc_hal_is_upper_int_enable(aon_rtc_hal_t * hal)139 bool aon_rtc_hal_is_upper_int_enable(aon_rtc_hal_t *hal)
140 {
141 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
142 return aon_rtc_ll_is_upper_int_enable(hal->hw);
143 }
144
aon_rtc_hal_get_upper_int_status(aon_rtc_hal_t * hal)145 bool aon_rtc_hal_get_upper_int_status(aon_rtc_hal_t *hal)
146 {
147 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
148 return aon_rtc_ll_get_upper_int_status(hal->hw);
149 }
150
aon_rtc_hal_clear_upper_int_status(aon_rtc_hal_t * hal)151 void aon_rtc_hal_clear_upper_int_status(aon_rtc_hal_t *hal)
152 {
153 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
154 aon_rtc_ll_clear_upper_int_status(hal->hw);
155 }
156
aon_rtc_hal_get_counter_val(aon_rtc_hal_t * hal)157 uint32_t aon_rtc_hal_get_counter_val(aon_rtc_hal_t *hal)
158 {
159 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
160 return aon_rtc_ll_get_counter_val(hal->hw);
161 }
162
aon_rtc_hal_get_upper_val_lpo(aon_rtc_hal_t * hal)163 uint32_t aon_rtc_hal_get_upper_val_lpo(aon_rtc_hal_t *hal)
164 {
165 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
166 return aon_rtc_ll_get_upper_val_lpo(hal->hw);
167 }
168
aon_rtc_hal_get_tick_val_lpo(aon_rtc_hal_t * hal)169 uint32_t aon_rtc_hal_get_tick_val_lpo(aon_rtc_hal_t *hal)
170 {
171 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
172 return aon_rtc_ll_get_tick_val_lpo(hal->hw);
173 }
174
aon_rtc_hal_init(aon_rtc_hal_t * hal)175 bk_err_t aon_rtc_hal_init(aon_rtc_hal_t *hal)
176 {
177 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
178
179 aon_rtc_ll_clear_ctrl(hal->hw);
180 aon_rtc_ll_set_tick_val(hal->hw, 0);
181 aon_rtc_ll_set_upper_val(hal->hw, 0);
182 aon_rtc_ll_enable(hal->hw);
183
184 return BK_OK;
185 }
186
aon_rtc_hal_deinit(aon_rtc_hal_t * hal)187 bk_err_t aon_rtc_hal_deinit(aon_rtc_hal_t *hal)
188 {
189 hal->hw = (aon_rtc_hw_t *)AON_RTC_LL_REG_BASE(hal->id);
190
191 aon_rtc_ll_clear_ctrl(hal->hw);
192 aon_rtc_ll_set_tick_val(hal->hw, 0);
193 aon_rtc_ll_set_upper_val(hal->hw, 0);
194 aon_rtc_ll_disable(hal->hw);
195
196 return BK_OK;
197 }
aon_rtc_hal_tick_init()198 bk_err_t aon_rtc_hal_tick_init()
199 {
200 aon_rtc_ll_tick_init();
201
202 return BK_OK;
203 }
aon_rtc_hal_open_rtc_wakeup(uint32_t period)204 bk_err_t aon_rtc_hal_open_rtc_wakeup(uint32_t period)
205 {
206 aon_rtc_ll_open_rtc_wakeup(period);
207
208 return BK_OK;
209 }
aon_rtc_hal_get_current_tick()210 uint32_t aon_rtc_hal_get_current_tick()
211 {
212 return aon_rtc_ll_get_current_tick();
213 }
214
215