• 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: Provides V100 rtc register operation API \n
16  *
17  * History: \n
18  * 2023-03-02, Create file. \n
19  */
20 #ifndef HAL_RTC_V100_REGS_OP_H
21 #define HAL_RTC_V100_REGS_OP_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 #include "rtc_porting.h"
26 #include "hal_rtc_v100_regs_def.h"
27 #include "soc_osal.h"
28 #include "debug/osal_debug.h"
29 
30 #ifdef __cplusplus
31 #if __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34 #endif /* __cplusplus */
35 
36 /**
37  * @defgroup drivers_hal_rtc_v100_regs_op RTC V100 Regs Operation
38  * @ingroup  drivers_hal_rtc
39  * @{
40  */
41 
42 extern uintptr_t g_rtc_comm_regs;
43 extern uintptr_t g_rtc_regs[CONFIG_RTC_MAX_NUM];
44 
45 /**
46  * @brief  Get the value of @ref rtc_control_reg_data.enable.
47  * @param  [in]  index Index for one of the rtc.
48  * @return The value of @ref rtc_control_reg_data.enable.
49  */
hal_rtc_control_reg_get_enable(rtc_index_t index)50 static inline uint32_t hal_rtc_control_reg_get_enable(rtc_index_t index)
51 {
52     rtc_control_reg_data_t rtc_control_reg;
53     rtc_control_reg.d32 = ((rtc_regs_info_t *)g_rtc_regs[index])->control_reg;
54     return rtc_control_reg.b.enable;
55 }
56 
57 /**
58  * @brief  Set the value of @ref rtc_control_reg_data.enable.
59  * @param  [in]  index Index for one of the rtc.
60  * @param  [in]  val Enable or not.
61  */
hal_rtc_control_reg_set_enable(rtc_index_t index,uint32_t val)62 static inline void hal_rtc_control_reg_set_enable(rtc_index_t index, uint32_t val)
63 {
64     rtc_control_reg_data_t rtc_control_reg;
65     rtc_control_reg.d32 = ((rtc_regs_info_t *)g_rtc_regs[index])->control_reg;
66     rtc_control_reg.b.enable = val;
67     ((rtc_regs_info_t *)g_rtc_regs[index])->control_reg = rtc_control_reg.d32;
68 }
69 
70 /**
71  * @brief  Get the value of @ref rtc_control_reg_data.mode.
72  * @param  [in]  index Index for one of the rtc.
73  * @return The value of @ref rtc_control_reg_data.mode.
74  */
hal_rtc_control_reg_get_mode(rtc_index_t index)75 static inline uint32_t hal_rtc_control_reg_get_mode(rtc_index_t index)
76 {
77     rtc_control_reg_data_t rtc_control_reg;
78     rtc_control_reg.d32 = ((rtc_regs_info_t *)g_rtc_regs[index])->control_reg;
79     return rtc_control_reg.b.mode;
80 }
81 
82 /**
83  * @brief  Set the value of @ref rtc_control_reg_data.mode.
84  * @param  [in]  index Index for one of the rtc.
85  * @param  [in]  val The work mode of rtc.
86  */
hal_rtc_control_reg_set_mode(rtc_index_t index,uint32_t val)87 static inline void hal_rtc_control_reg_set_mode(rtc_index_t index, uint32_t val)
88 {
89     rtc_control_reg_data_t rtc_control_reg;
90     rtc_control_reg.d32 = ((rtc_regs_info_t *)g_rtc_regs[index])->control_reg;
91     rtc_control_reg.b.mode = val;
92     ((rtc_regs_info_t *)g_rtc_regs[index])->control_reg = rtc_control_reg.d32;
93 }
94 
95 /**
96  * @brief  Get the value of @ref rtc_regs_info.load_count.
97  * @param  [in]  index Index for one of the rtc.
98  * @return The value of @ref rtc_regs_info.load_count.
99  */
hal_rtc_load_count_get(rtc_index_t index)100 static inline uint32_t hal_rtc_load_count_get(rtc_index_t index)
101 {
102     return ((rtc_regs_info_t *)g_rtc_regs[index])->load_count;
103 }
104 
105 /**
106  * @brief  Set the value of @ref rtc_regs_info.load_count.
107  * @param  [in]  index Index for one of the rtc.
108  * @param  [in]  val The load count value.
109  */
hal_rtc_load_count_set(rtc_index_t index,uint32_t val)110 static inline void hal_rtc_load_count_set(rtc_index_t index, uint32_t val)
111 {
112     ((rtc_regs_info_t *)g_rtc_regs[index])->load_count = val;
113 }
114 
115 /**
116  * @brief  Get the value of @ref rtc_regs_info.current_value.
117  * @param  [in]  index Index for one of the rtc.
118  * @return The value of @ref rtc_regs_info.current_value.
119  */
hal_rtc_get_current_load(rtc_index_t index)120 static inline uint32_t hal_rtc_get_current_load(rtc_index_t index)
121 {
122     return ((rtc_regs_info_t *)g_rtc_regs[index])->current_value;
123 }
124 
125 /**
126  * @brief  To clear pending interrupt. Get the value of @ref rtc_regs_info.eoi.
127  * @param  [in]  index Index for one of the rtc.
128  * @return The value of @ref rtc_regs_info.eoi.
129  */
hal_rtc_get_eoi(rtc_index_t index)130 static inline uint32_t hal_rtc_get_eoi(rtc_index_t index)
131 {
132     return ((rtc_regs_info_t *)g_rtc_regs[index])->eoi;
133 }
134 
135 #if defined(CONFIG_RTC_SUPPORT_LPM)
136 /**
137  * @brief  Get rtc interrupt status.
138  * @param  [in]  index Index of the hardware rtc. For detail, see @ref rtc_index_t.
139  * @return The value of @ref rtc_regs_info.int_status.
140  */
hal_rtc_v100_get_int_sts(rtc_index_t index)141 static inline uint32_t hal_rtc_v100_get_int_sts(rtc_index_t index)
142 {
143     return ((rtc_regs_info_t *)g_rtc_regs[index])->int_status;
144 }
145 #endif /* CONFIG_RTC_SUPPORT_LPM */
146 /**
147  * @}
148  */
149 
150 #ifdef __cplusplus
151 #if __cplusplus
152 }
153 #endif /* __cplusplus */
154 #endif /* __cplusplus */
155 
156 #endif