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