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 "mxc_device.h"
22 #include "rtc_regs.h"
23 #include "rtc.h"
24 #include "mxc_sys.h"
25 #include "mxc_delay.h"
26 #include "gpio_regs.h"
27 #include "mxc_errors.h"
28 #include "mcr_regs.h"
29 #include "rtc_reva.h"
30
31 /* ***** Functions ***** */
32
MXC_RTC_EnableInt(uint32_t mask)33 int MXC_RTC_EnableInt(uint32_t mask)
34 {
35 return MXC_RTC_RevA_EnableInt(MXC_RTC, mask);
36 }
37
MXC_RTC_DisableInt(uint32_t mask)38 int MXC_RTC_DisableInt(uint32_t mask)
39 {
40 return MXC_RTC_RevA_DisableInt(MXC_RTC, mask);
41 }
42
MXC_RTC_SetTimeofdayAlarm(uint32_t ras)43 int MXC_RTC_SetTimeofdayAlarm(uint32_t ras)
44 {
45 return MXC_RTC_RevA_SetTimeofdayAlarm(MXC_RTC, ras);
46 }
47
MXC_RTC_SetSubsecondAlarm(uint32_t rssa)48 int MXC_RTC_SetSubsecondAlarm(uint32_t rssa)
49 {
50 return MXC_RTC_RevA_SetSubsecondAlarm(MXC_RTC, rssa);
51 }
52
MXC_RTC_Start(void)53 int MXC_RTC_Start(void)
54 {
55 return MXC_RTC_RevA_Start(MXC_RTC);
56 }
57
MXC_RTC_Stop(void)58 int MXC_RTC_Stop(void)
59 {
60 return MXC_RTC_RevA_Stop(MXC_RTC);
61 }
62
MXC_RTC_Init(uint32_t sec,uint8_t ssec)63 int MXC_RTC_Init(uint32_t sec, uint8_t ssec)
64 {
65 // Enable clock
66 MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN;
67
68 return MXC_RTC_RevA_Init(MXC_RTC, sec, ssec);
69 }
70
MXC_RTC_SquareWave(mxc_rtc_sqwave_en_t sqe,mxc_rtc_freq_sel_t ft)71 int MXC_RTC_SquareWave(mxc_rtc_sqwave_en_t sqe, mxc_rtc_freq_sel_t ft)
72 {
73 MXC_GPIO_Config(&gpio_cfg_rtcsqw);
74
75 return MXC_RTC_RevA_SquareWave(MXC_RTC, sqe, ft);
76 }
77
MXC_RTC_Trim(int8_t trm)78 int MXC_RTC_Trim(int8_t trm)
79 {
80 return MXC_RTC_RevA_Trim(MXC_RTC, trm);
81 }
82
MXC_RTC_GetFlags(void)83 int MXC_RTC_GetFlags(void)
84 {
85 return MXC_RTC_RevA_GetFlags();
86 }
87
MXC_RTC_ClearFlags(int flags)88 int MXC_RTC_ClearFlags(int flags)
89 {
90 return MXC_RTC_RevA_ClearFlags(flags);
91 }
92
MXC_RTC_GetSubSecond(void)93 int MXC_RTC_GetSubSecond(void)
94 {
95 return MXC_RTC_RevA_GetSubSecond((mxc_rtc_reva_regs_t *)MXC_RTC);
96 }
97
MXC_RTC_GetSecond(void)98 int MXC_RTC_GetSecond(void)
99 {
100 return MXC_RTC_RevA_GetSecond((mxc_rtc_reva_regs_t *)MXC_RTC);
101 }
102
MXC_RTC_GetSubSeconds(uint32_t * ssec)103 int MXC_RTC_GetSubSeconds(uint32_t *ssec)
104 {
105 MXC_RTC->ctrl &= ~MXC_F_RTC_CTRL_RDY; // Ensure valid data is in SSEC register
106 while (!(MXC_RTC->ctrl & MXC_F_RTC_CTRL_RDY)) {}
107
108 return MXC_RTC_RevA_GetSubSeconds((mxc_rtc_reva_regs_t *)MXC_RTC, ssec);
109 }
110
MXC_RTC_GetSeconds(uint32_t * sec)111 int MXC_RTC_GetSeconds(uint32_t *sec)
112 {
113 MXC_RTC->ctrl &= ~MXC_F_RTC_CTRL_RDY; // Ensure valid data is in SEC register
114 while (!(MXC_RTC->ctrl & MXC_F_RTC_CTRL_RDY)) {}
115
116 return MXC_RTC_RevA_GetSeconds((mxc_rtc_reva_regs_t *)MXC_RTC, sec);
117 }
118
MXC_RTC_GetTime(uint32_t * sec,uint32_t * subsec)119 int MXC_RTC_GetTime(uint32_t *sec, uint32_t *subsec)
120 {
121 return MXC_RTC_RevA_GetTime(sec, subsec);
122 }
123
MXC_RTC_GetBusyFlag(void)124 int MXC_RTC_GetBusyFlag(void)
125 {
126 return MXC_RTC_RevA_GetBusyFlag();
127 }
128