1 /******************************************************************************
2 *
3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4 * Analog Devices, Inc.),
5 * Copyright (C) 2023-2024 Analog Devices, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************************/
20
21 /* **** Includes **** */
22 #include "mxc_errors.h"
23 #include "mxc_assert.h"
24 #include "mxc_sys.h"
25 #include "tmr.h"
26 #include "tmr_reva.h"
27 #include "tmr_common.h"
28 #include "gpio.h"
29
30 /* **** Definitions **** */
31
32 /* **** Globals **** */
33
34 /* **** Functions **** */
35
36 /* ************************************************************************** */
MXC_TMR_Init(mxc_tmr_regs_t * tmr,mxc_tmr_cfg_t * cfg)37 void MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg)
38 {
39 #ifndef MSDK_NO_GPIO_CLK_INIT
40 int tmr_id = MXC_TMR_GET_IDX(tmr);
41
42 switch (tmr_id) {
43 case 0:
44 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER0);
45 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TIMER0);
46 MXC_GPIO_Config(&gpio_cfg_tmr0);
47 break;
48 case 1:
49 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER1);
50 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TIMER1);
51 MXC_GPIO_Config(&gpio_cfg_tmr1);
52 break;
53 case 2:
54 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER2);
55 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TIMER2);
56 MXC_GPIO_Config(&gpio_cfg_tmr2);
57 break;
58 case 3:
59 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER3);
60 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TIMER3);
61 MXC_GPIO_Config(&gpio_cfg_tmr3);
62 break;
63 case 4:
64 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER4);
65 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TIMER4);
66 MXC_GPIO_Config(&gpio_cfg_tmr4);
67 break;
68 case 5:
69 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER5);
70 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_TIMER5);
71 MXC_GPIO_Config(&gpio_cfg_tmr5);
72 break;
73 default:
74 return;
75 }
76 #endif
77
78 MXC_TMR_RevA_Init((mxc_tmr_reva_regs_t *)tmr, cfg);
79 }
80
81 /* ************************************************************************** */
MXC_TMR_Shutdown(mxc_tmr_regs_t * tmr)82 void MXC_TMR_Shutdown(mxc_tmr_regs_t *tmr)
83 {
84 int tmr_id = MXC_TMR_GET_IDX(tmr);
85
86 MXC_TMR_RevA_Shutdown((mxc_tmr_reva_regs_t *)tmr);
87
88 switch (tmr_id) {
89 case 0:
90 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER0);
91 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TIMER0);
92 break;
93 case 1:
94 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER1);
95 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TIMER1);
96 break;
97 case 2:
98 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER2);
99 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TIMER2);
100 break;
101 case 3:
102 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER3);
103 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TIMER3);
104 break;
105 case 4:
106 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER4);
107 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TIMER4);
108 break;
109 case 5:
110 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER5);
111 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_TIMER5);
112 break;
113 default:
114 return;
115 }
116 }
117
118 /* ************************************************************************** */
MXC_TMR_Start(mxc_tmr_regs_t * tmr)119 void MXC_TMR_Start(mxc_tmr_regs_t *tmr)
120 {
121 MXC_TMR_RevA_Start((mxc_tmr_reva_regs_t *)tmr);
122 }
123
124 /* ************************************************************************** */
MXC_TMR_Stop(mxc_tmr_regs_t * tmr)125 void MXC_TMR_Stop(mxc_tmr_regs_t *tmr)
126 {
127 MXC_TMR_RevA_Stop((mxc_tmr_reva_regs_t *)tmr);
128 }
129
130 /* ************************************************************************** */
MXC_TMR_SetPWM(mxc_tmr_regs_t * tmr,uint32_t pwm)131 int MXC_TMR_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm)
132 {
133 return MXC_TMR_RevA_SetPWM((mxc_tmr_reva_regs_t *)tmr, pwm);
134 }
135
136 /* ************************************************************************** */
MXC_TMR_GetCompare(mxc_tmr_regs_t * tmr)137 uint32_t MXC_TMR_GetCompare(mxc_tmr_regs_t *tmr)
138 {
139 return MXC_TMR_RevA_GetCompare((mxc_tmr_reva_regs_t *)tmr);
140 }
141
142 /* ************************************************************************** */
MXC_TMR_GetCapture(mxc_tmr_regs_t * tmr)143 uint32_t MXC_TMR_GetCapture(mxc_tmr_regs_t *tmr)
144 {
145 return MXC_TMR_RevA_GetCapture((mxc_tmr_reva_regs_t *)tmr);
146 }
147
148 /* ************************************************************************* */
MXC_TMR_GetCount(mxc_tmr_regs_t * tmr)149 uint32_t MXC_TMR_GetCount(mxc_tmr_regs_t *tmr)
150 {
151 return MXC_TMR_RevA_GetCount((mxc_tmr_reva_regs_t *)tmr);
152 }
153
154 /* ************************************************************************* */
MXC_TMR_ClearFlags(mxc_tmr_regs_t * tmr)155 void MXC_TMR_ClearFlags(mxc_tmr_regs_t *tmr)
156 {
157 MXC_TMR_RevA_ClearFlags((mxc_tmr_reva_regs_t *)tmr);
158 }
159
160 /* ************************************************************************* */
MXC_TMR_GetFlags(mxc_tmr_regs_t * tmr)161 uint32_t MXC_TMR_GetFlags(mxc_tmr_regs_t *tmr)
162 {
163 return MXC_TMR_RevA_GetFlags((mxc_tmr_reva_regs_t *)tmr);
164 }
165
166 /* ************************************************************************* */
MXC_TMR_SetCompare(mxc_tmr_regs_t * tmr,uint32_t cmp_cnt)167 void MXC_TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt)
168 {
169 MXC_TMR_RevA_SetCompare((mxc_tmr_reva_regs_t *)tmr, cmp_cnt);
170 }
171
172 /* ************************************************************************* */
MXC_TMR_SetCount(mxc_tmr_regs_t * tmr,uint32_t cnt)173 void MXC_TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt)
174 {
175 MXC_TMR_RevA_SetCount((mxc_tmr_reva_regs_t *)tmr, cnt);
176 }
177
178 /* ************************************************************************* */
MXC_TMR_Delay(mxc_tmr_regs_t * tmr,uint32_t us)179 void MXC_TMR_Delay(mxc_tmr_regs_t *tmr, uint32_t us)
180 {
181 MXC_TMR_Common_Delay(tmr, us);
182 }
183
184 /* ************************************************************************* */
MXC_TMR_TO_Start(mxc_tmr_regs_t * tmr,uint32_t us)185 void MXC_TMR_TO_Start(mxc_tmr_regs_t *tmr, uint32_t us)
186 {
187 MXC_TMR_RevA_TO_Start((mxc_tmr_reva_regs_t *)tmr, us);
188 }
189
190 /* ************************************************************************* */
MXC_TMR_TO_Check(mxc_tmr_regs_t * tmr)191 int MXC_TMR_TO_Check(mxc_tmr_regs_t *tmr)
192 {
193 return MXC_TMR_Common_TO_Check(tmr);
194 }
195
196 /* ************************************************************************* */
MXC_TMR_TO_Stop(mxc_tmr_regs_t * tmr)197 void MXC_TMR_TO_Stop(mxc_tmr_regs_t *tmr)
198 {
199 MXC_TMR_Common_TO_Stop(tmr);
200 }
201
202 /* ************************************************************************* */
MXC_TMR_TO_Clear(mxc_tmr_regs_t * tmr)203 void MXC_TMR_TO_Clear(mxc_tmr_regs_t *tmr)
204 {
205 MXC_TMR_Common_TO_Clear(tmr);
206 }
207
208 /* ************************************************************************* */
MXC_TMR_TO_Elapsed(mxc_tmr_regs_t * tmr)209 unsigned int MXC_TMR_TO_Elapsed(mxc_tmr_regs_t *tmr)
210 {
211 return MXC_TMR_Common_TO_Elapsed(tmr);
212 }
213
214 /* ************************************************************************* */
MXC_TMR_TO_Remaining(mxc_tmr_regs_t * tmr)215 unsigned int MXC_TMR_TO_Remaining(mxc_tmr_regs_t *tmr)
216 {
217 return MXC_TMR_Common_TO_Remaining(tmr);
218 }
219
220 /* ************************************************************************* */
MXC_TMR_SW_Start(mxc_tmr_regs_t * tmr)221 void MXC_TMR_SW_Start(mxc_tmr_regs_t *tmr)
222 {
223 MXC_TMR_Common_SW_Start(tmr);
224 }
225
226 /* ************************************************************************* */
MXC_TMR_SW_Stop(mxc_tmr_regs_t * tmr)227 unsigned int MXC_TMR_SW_Stop(mxc_tmr_regs_t *tmr)
228 {
229 return MXC_TMR_Common_SW_Stop(tmr);
230 }
231
232 /* ************************************************************************* */
MXC_TMR_GetTime(mxc_tmr_regs_t * tmr,uint32_t ticks,uint32_t * time,mxc_tmr_unit_t * units)233 int MXC_TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, mxc_tmr_unit_t *units)
234 {
235 return MXC_TMR_RevA_GetTime((mxc_tmr_reva_regs_t *)tmr, ticks, time, units);
236 }
237