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 <stdio.h>
22 #include <stddef.h>
23 #include <stdint.h>
24 #include "mxc_device.h"
25 #include "mxc_assert.h"
26 #include "mxc_lock.h"
27 #include "mxc_sys.h"
28 #include "mxc_delay.h"
29 #include "htmr_regs.h"
30 #include "htmr.h"
31 #include "htmr_reva.h"
32
33 /* ****** Functions ****** */
MXC_HTMR_Init(mxc_htmr_regs_t * htmr,uint32_t longInterval,uint8_t shortInterval)34 int MXC_HTMR_Init(mxc_htmr_regs_t *htmr, uint32_t longInterval, uint8_t shortInterval)
35 {
36 if (htmr == NULL) {
37 return E_NULL_PTR;
38 }
39
40 #ifndef MSDK_NO_GPIO_CLK_INIT
41 if (MXC_SYS_ClockSourceEnable(MXC_SYS_CLOCK_HIRC8) != E_NO_ERROR) {
42 return E_TIME_OUT;
43 }
44
45 if (htmr == MXC_HTMR0) {
46 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_HTMR0);
47 } else if (htmr == MXC_HTMR1) {
48 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_HTMR1);
49 } else {
50 return E_BAD_PARAM;
51 }
52 #endif
53
54 return MXC_HTMR_RevA_Init((mxc_htmr_reva_regs_t *)htmr, longInterval, shortInterval);
55 }
56
MXC_HTMR_Start(mxc_htmr_regs_t * htmr)57 int MXC_HTMR_Start(mxc_htmr_regs_t *htmr)
58 {
59 return MXC_HTMR_RevA_Start((mxc_htmr_reva_regs_t *)htmr);
60 }
61
MXC_HTMR_Stop(mxc_htmr_regs_t * htmr)62 int MXC_HTMR_Stop(mxc_htmr_regs_t *htmr)
63 {
64 return MXC_HTMR_RevA_Stop((mxc_htmr_reva_regs_t *)htmr);
65 }
66
MXC_HTMR_GetShortCount(mxc_htmr_regs_t * htmr)67 int MXC_HTMR_GetShortCount(mxc_htmr_regs_t *htmr)
68 {
69 return MXC_HTMR_RevA_GetShortCount((mxc_htmr_reva_regs_t *)htmr);
70 }
71
MXC_HTMR_GetLongCount(mxc_htmr_regs_t * htmr)72 int MXC_HTMR_GetLongCount(mxc_htmr_regs_t *htmr)
73 {
74 return MXC_HTMR_RevA_GetLongCount((mxc_htmr_reva_regs_t *)htmr);
75 }
76
MXC_HTMR_SetLongAlarm(mxc_htmr_regs_t * htmr,uint32_t interval)77 int MXC_HTMR_SetLongAlarm(mxc_htmr_regs_t *htmr, uint32_t interval)
78 {
79 return MXC_HTMR_RevA_SetLongAlarm((mxc_htmr_reva_regs_t *)htmr, interval);
80 }
81
MXC_HTMR_SetShortAlarm(mxc_htmr_regs_t * htmr,uint32_t interval)82 int MXC_HTMR_SetShortAlarm(mxc_htmr_regs_t *htmr, uint32_t interval)
83 {
84 return MXC_HTMR_RevA_SetShortAlarm((mxc_htmr_reva_regs_t *)htmr, interval);
85 }
86
MXC_HTMR_CheckBusy(mxc_htmr_regs_t * htmr)87 int MXC_HTMR_CheckBusy(mxc_htmr_regs_t *htmr)
88 {
89 return MXC_HTMR_RevA_CheckBusy((mxc_htmr_reva_regs_t *)htmr);
90 }
91
MXC_HTMR_GetFlags(mxc_htmr_regs_t * htmr)92 int MXC_HTMR_GetFlags(mxc_htmr_regs_t *htmr)
93 {
94 return MXC_HTMR_RevA_GetFlags((mxc_htmr_reva_regs_t *)htmr);
95 }
96
MXC_HTMR_ClearFlags(mxc_htmr_regs_t * htmr,int flags)97 int MXC_HTMR_ClearFlags(mxc_htmr_regs_t *htmr, int flags)
98 {
99 return MXC_HTMR_RevA_ClearFlags((mxc_htmr_reva_regs_t *)htmr, flags);
100 }
101
MXC_HTMR_EnableInt(mxc_htmr_regs_t * htmr,uint32_t mask)102 int MXC_HTMR_EnableInt(mxc_htmr_regs_t *htmr, uint32_t mask)
103 {
104 return MXC_HTMR_RevA_EnableInt((mxc_htmr_reva_regs_t *)htmr, mask);
105 }
106
MXC_HTMR_DisableInt(mxc_htmr_regs_t * htmr,uint32_t mask)107 int MXC_HTMR_DisableInt(mxc_htmr_regs_t *htmr, uint32_t mask)
108 {
109 return MXC_HTMR_RevA_DisableInt((mxc_htmr_reva_regs_t *)htmr, mask);
110 }
111