• 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 V150 timer register operation API \n
16  *
17  * History: \n
18  * 2022-12-07, Create file. \n
19  */
20 #ifndef HAL_TIMER_V150_REGS_OP_H
21 #define HAL_TIMER_V150_REGS_OP_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 #include "timer_porting.h"
26 #include "hal_timer_v150_regs_def.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 #endif /* __cplusplus */
33 
34 /**
35  * @defgroup drivers_hal_timer_v150_regs_op TIMER V150 Regs Operation
36  * @ingroup  drivers_hal_timer
37  * @{
38  */
39 
40 extern uintptr_t g_timer_comm_regs;
41 extern uintptr_t g_timer_regs[CONFIG_TIMER_MAX_NUM];
42 
43 /**
44  * @brief  Reg addr associated with timer.
45  */
46 #define timer_regs(index) ((timer_v150_regs_t *)(g_timer_regs[index]))
47 
48 /**
49  * @brief  Set the value of @ref timer_v150_control_reg_data.enable.
50  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
51  * @param  [in]  val Enable or not.
52  */
hal_timer_v150_control_reg_set_enable(timer_index_t index,uint32_t val)53 static inline void hal_timer_v150_control_reg_set_enable(timer_index_t index, uint32_t val)
54 {
55     timer_v150_control_reg_data_t timer_control_reg;
56     timer_control_reg.d32 = timer_regs(index)->control;
57     timer_control_reg.b.enable = val;
58     timer_regs(index)->control = timer_control_reg.d32;
59 }
60 
61 /**
62  * @brief  Get the value of @ref timer_v150_control_reg_data_t.enable.
63  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
64  * @return The value of @ref timer_v150_control_reg_data_t.enable.
65  */
hal_timer_v150_control_reg_get_enable(timer_index_t index)66 static inline uint32_t hal_timer_v150_control_reg_get_enable(timer_index_t index)
67 {
68     timer_v150_control_reg_data_t timer_control_reg;
69     timer_control_reg.d32 = timer_regs(index)->control;
70     return timer_control_reg.b.enable;
71 }
72 
73 /**
74  * @brief  Set the value of @ref timer_v150_control_reg_data.mode.
75  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
76  * @param  [in]  val The work mode of timer.
77  */
hal_timer_v150_control_reg_set_mode(timer_index_t index,uint32_t val)78 static inline void hal_timer_v150_control_reg_set_mode(timer_index_t index, uint32_t val)
79 {
80     timer_v150_control_reg_data_t timer_control_reg;
81     timer_control_reg.d32 = timer_regs(index)->control;
82     timer_control_reg.b.mode = val;
83     timer_regs(index)->control = timer_control_reg.d32;
84 }
85 
86 /**
87  * @brief  Get the value of @ref timer_v150_regs.current_value0.
88  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
89  * @return The value of @ref timer_v150_regs.current_value0.
90  */
hal_timer_v150_get_current_value0(timer_index_t index)91 static inline uint32_t hal_timer_v150_get_current_value0(timer_index_t index)
92 {
93     return timer_regs(index)->current_value0;
94 }
95 
96 /**
97  * @brief  Get the value of @ref timer_v150_regs.current_value1.
98  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
99  * @return The value of @ref timer_v150_regs.current_value1.
100  */
hal_timer_v150_get_current_value1(timer_index_t index)101 static inline uint32_t hal_timer_v150_get_current_value1(timer_index_t index)
102 {
103     return timer_regs(index)->current_value1;
104 }
105 
106 /**
107  * @brief  Set the value of @ref timer_v150_regs.load_count0.
108  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
109  * @param  [in]  val The load count value.
110  */
hal_timer_v150_set_load_count0(timer_index_t index,uint32_t val)111 static inline void hal_timer_v150_set_load_count0(timer_index_t index, uint32_t val)
112 {
113     timer_regs(index)->load_count0 = val;
114 }
115 
116 /**
117  * @brief  Set the value of @ref timer_v150_regs.load_count1.
118  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
119  * @param  [in]  val The load count value.
120  */
hal_timer_v150_set_load_count1(timer_index_t index,uint32_t val)121 static inline void hal_timer_v150_set_load_count1(timer_index_t index, uint32_t val)
122 {
123     timer_regs(index)->load_count1 = val;
124 }
125 
126 /**
127  * @brief  Clear timer interrupt.
128  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
129  */
hal_timer_v150_int_clr(timer_index_t index)130 static inline void hal_timer_v150_int_clr(timer_index_t index)
131 {
132     timer_regs(index)->eoi_ren = 0x1;
133 }
134 
135 /**
136  * @brief  Set the value of @ref timers_v150_regs.lock.
137  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
138  * @param  [in]  val The lock password.
139  */
hal_timer_v150_set_load_lock(timer_index_t index,uint32_t val)140 static inline void hal_timer_v150_set_load_lock(timer_index_t index, uint32_t val)
141 {
142     unused(index);
143     ((timers_v150_regs_t *)g_timer_comm_regs)->lock = val;
144 }
145 
146 /**
147  * @brief  Set the value of @ref timer_v150_control_reg_data_t.cnt_req.
148  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
149  */
hal_timer_v150_ctrl_set_cnt_req(timer_index_t index)150 static inline void hal_timer_v150_ctrl_set_cnt_req(timer_index_t index)
151 {
152     timer_v150_control_reg_data_t timer_control_reg;
153     timer_control_reg.d32 = timer_regs(index)->control;
154     timer_control_reg.b.cnt_req = 1;
155     timer_regs(index)->control = timer_control_reg.d32;
156 }
157 
158 /**
159  * @brief  Get the value of @ref timer_v150_control_reg_data_t.cnt_lock.
160  * @param  [in]  index Index of the hardware timer. For detail, see @ref timer_index_t.
161  * @return The value of @ref timer_v150_control_reg_data_t.cnt_lock.
162  */
hal_timer_v150_ctrl_get_cnt_lock(timer_index_t index)163 static inline uint32_t hal_timer_v150_ctrl_get_cnt_lock(timer_index_t index)
164 {
165     timer_v150_control_reg_data_t timer_control_reg;
166     timer_control_reg.d32 = timer_regs(index)->control;
167     return timer_control_reg.b.cnt_lock;
168 }
169 
170 /**
171  * @}
172  */
173 
174 #ifdef __cplusplus
175 #if __cplusplus
176 }
177 #endif /* __cplusplus */
178 #endif /* __cplusplus */
179 
180 #endif
181