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 #include "tmr.h"
22 #include "tmr_reva.h"
23 #include "tmr_common.h"
24
MXC_TMR_Init(mxc_tmr_regs_t * tmr,mxc_tmr_cfg_t * cfg)25 void MXC_TMR_Init(mxc_tmr_regs_t *tmr, mxc_tmr_cfg_t *cfg)
26 {
27 #ifndef MSDK_NO_GPIO_CLK_INIT
28 int tmr_id = MXC_TMR_GET_IDX(tmr);
29 MXC_ASSERT(tmr_id >= 0);
30
31 //enable peripheral clock and configure gpio pins
32 switch (tmr_id) {
33 case 0:
34 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER0);
35 while (MXC_GCR->rstr0 & MXC_F_GCR_RSTR0_TIMER0) {}
36 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_T0);
37 MXC_GPIO_Config(&gpio_cfg_tmr0);
38 break;
39
40 case 1:
41 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER1);
42 while (MXC_GCR->rstr0 & MXC_F_GCR_RSTR0_TIMER1) {}
43 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_T1);
44 MXC_GPIO_Config(&gpio_cfg_tmr1);
45 break;
46
47 case 2:
48 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER2);
49 while (MXC_GCR->rstr0 & MXC_F_GCR_RSTR0_TIMER2) {}
50 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_T2);
51 MXC_GPIO_Config(&gpio_cfg_tmr2);
52 break;
53
54 case 3:
55 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER3);
56 while (MXC_GCR->rstr0 & MXC_F_GCR_RSTR0_TIMER3) {}
57 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_T3);
58 MXC_GPIO_Config(&gpio_cfg_tmr3);
59 break;
60
61 case 4:
62 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER4);
63 while (MXC_GCR->rstr0 & MXC_F_GCR_RSTR0_TIMER4) {}
64 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_T4);
65 MXC_GPIO_Config(&gpio_cfg_tmr4);
66 break;
67
68 case 5:
69 MXC_SYS_Reset_Periph(MXC_SYS_RESET_TIMER5);
70 while (MXC_GCR->rstr0 & MXC_F_GCR_RSTR0_TIMER5) {}
71 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_T5);
72 MXC_GPIO_Config(&gpio_cfg_tmr5);
73 break;
74 }
75 #endif
76
77 MXC_TMR_RevA_Init((mxc_tmr_reva_regs_t *)tmr, cfg);
78 }
79
MXC_TMR_Shutdown(mxc_tmr_regs_t * tmr)80 void MXC_TMR_Shutdown(mxc_tmr_regs_t *tmr)
81 {
82 int tmr_id = MXC_TMR_GET_IDX(tmr);
83 MXC_ASSERT(tmr_id >= 0);
84
85 MXC_TMR_RevA_Shutdown((mxc_tmr_reva_regs_t *)tmr);
86
87 // System settigns
88 // disable peripheral clock
89 switch (tmr_id) {
90 case 0:
91 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_T0);
92 break;
93
94 case 1:
95 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_T1);
96 break;
97
98 case 2:
99 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_T2);
100 break;
101
102 case 3:
103 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_T3);
104 break;
105
106 case 4:
107 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_T4);
108 break;
109
110 case 5:
111 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_T5);
112 break;
113 }
114 }
115
MXC_TMR_Start(mxc_tmr_regs_t * tmr)116 void MXC_TMR_Start(mxc_tmr_regs_t *tmr)
117 {
118 MXC_TMR_RevA_Start((mxc_tmr_reva_regs_t *)tmr);
119 }
120
MXC_TMR_Stop(mxc_tmr_regs_t * tmr)121 void MXC_TMR_Stop(mxc_tmr_regs_t *tmr)
122 {
123 MXC_TMR_RevA_Stop((mxc_tmr_reva_regs_t *)tmr);
124 }
125
MXC_TMR_SetPWM(mxc_tmr_regs_t * tmr,uint32_t pwm)126 int MXC_TMR_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm)
127 {
128 return MXC_TMR_RevA_SetPWM((mxc_tmr_reva_regs_t *)tmr, pwm);
129 }
130
MXC_TMR_GetCompare(mxc_tmr_regs_t * tmr)131 uint32_t MXC_TMR_GetCompare(mxc_tmr_regs_t *tmr)
132 {
133 return MXC_TMR_RevA_GetCompare((mxc_tmr_reva_regs_t *)tmr);
134 }
135
MXC_TMR_GetCapture(mxc_tmr_regs_t * tmr)136 uint32_t MXC_TMR_GetCapture(mxc_tmr_regs_t *tmr)
137 {
138 return MXC_TMR_RevA_GetCapture((mxc_tmr_reva_regs_t *)tmr);
139 }
140
MXC_TMR_GetCount(mxc_tmr_regs_t * tmr)141 uint32_t MXC_TMR_GetCount(mxc_tmr_regs_t *tmr)
142 {
143 return MXC_TMR_RevA_GetCount((mxc_tmr_reva_regs_t *)tmr);
144 }
145
MXC_TMR_ClearFlags(mxc_tmr_regs_t * tmr)146 void MXC_TMR_ClearFlags(mxc_tmr_regs_t *tmr)
147 {
148 MXC_TMR_RevA_ClearFlags((mxc_tmr_reva_regs_t *)tmr);
149 }
150
MXC_TMR_GetFlags(mxc_tmr_regs_t * tmr)151 uint32_t MXC_TMR_GetFlags(mxc_tmr_regs_t *tmr)
152 {
153 return MXC_TMR_RevA_GetFlags((mxc_tmr_reva_regs_t *)tmr);
154 }
155
MXC_TMR_SetCompare(mxc_tmr_regs_t * tmr,uint32_t cmp_cnt)156 void MXC_TMR_SetCompare(mxc_tmr_regs_t *tmr, uint32_t cmp_cnt)
157 {
158 MXC_TMR_RevA_SetCompare((mxc_tmr_reva_regs_t *)tmr, cmp_cnt);
159 }
160
MXC_TMR_SetCount(mxc_tmr_regs_t * tmr,uint32_t cnt)161 void MXC_TMR_SetCount(mxc_tmr_regs_t *tmr, uint32_t cnt)
162 {
163 MXC_TMR_RevA_SetCount((mxc_tmr_reva_regs_t *)tmr, cnt);
164 }
165
MXC_TMR_Delay(mxc_tmr_regs_t * tmr,uint32_t us)166 void MXC_TMR_Delay(mxc_tmr_regs_t *tmr, uint32_t us)
167 {
168 MXC_TMR_Common_Delay(tmr, us);
169 }
170
MXC_TMR_TO_Start(mxc_tmr_regs_t * tmr,uint32_t us)171 void MXC_TMR_TO_Start(mxc_tmr_regs_t *tmr, uint32_t us)
172 {
173 MXC_TMR_RevA_TO_Start((mxc_tmr_reva_regs_t *)tmr, us);
174 }
175
MXC_TMR_TO_Check(mxc_tmr_regs_t * tmr)176 int MXC_TMR_TO_Check(mxc_tmr_regs_t *tmr)
177 {
178 return MXC_TMR_Common_TO_Check(tmr);
179 }
180
MXC_TMR_TO_Stop(mxc_tmr_regs_t * tmr)181 void MXC_TMR_TO_Stop(mxc_tmr_regs_t *tmr)
182 {
183 MXC_TMR_Common_TO_Stop(tmr);
184 }
185
MXC_TMR_TO_Clear(mxc_tmr_regs_t * tmr)186 void MXC_TMR_TO_Clear(mxc_tmr_regs_t *tmr)
187 {
188 MXC_TMR_Common_TO_Clear(tmr);
189 }
190
MXC_TMR_TO_Elapsed(mxc_tmr_regs_t * tmr)191 unsigned int MXC_TMR_TO_Elapsed(mxc_tmr_regs_t *tmr)
192 {
193 return MXC_TMR_Common_TO_Elapsed(tmr);
194 }
195
MXC_TMR_TO_Remaining(mxc_tmr_regs_t * tmr)196 unsigned int MXC_TMR_TO_Remaining(mxc_tmr_regs_t *tmr)
197 {
198 return MXC_TMR_Common_TO_Remaining(tmr);
199 }
200
MXC_TMR_SW_Start(mxc_tmr_regs_t * tmr)201 void MXC_TMR_SW_Start(mxc_tmr_regs_t *tmr)
202 {
203 MXC_TMR_Common_SW_Start(tmr);
204 }
205
MXC_TMR_SW_Stop(mxc_tmr_regs_t * tmr)206 unsigned int MXC_TMR_SW_Stop(mxc_tmr_regs_t *tmr)
207 {
208 return MXC_TMR_Common_SW_Stop(tmr);
209 }
210
MXC_TMR_GetTime(mxc_tmr_regs_t * tmr,uint32_t ticks,uint32_t * time,mxc_tmr_unit_t * units)211 int MXC_TMR_GetTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, mxc_tmr_unit_t *units)
212 {
213 return MXC_TMR_RevA_GetTime((mxc_tmr_reva_regs_t *)tmr, ticks, time, units);
214 }
215