Skip to content

Commit 537475f

Browse files
committed
Added API for no_os_rtc and platform driver for maxim_rtc
Signed-off-by: Francisroi-Manabat_adi <[email protected]>
1 parent ab9d192 commit 537475f

File tree

4 files changed

+291
-20
lines changed

4 files changed

+291
-20
lines changed

drivers/api/no_os_rtc.c

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/***************************************************************************//**
2+
* @file no_os_rtc.c
3+
* @brief Implementation of the RTC
4+
* @author Francis Roi Manabat ([email protected])
5+
********************************************************************************
6+
* Copyright 2025(c) Analog Devices, Inc.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* 3. Neither the name of Analog Devices, Inc. nor the names of its
19+
* contributors may be used to endorse or promote products derived from this
20+
* software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
23+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
25+
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*******************************************************************************/
33+
34+
#include <inttypes.h>
35+
#include "no_os_rtc.h"
36+
#include <stdlib.h>
37+
#include "no_os_error.h"
38+
#include "no_os_alloc.h"
39+
40+
/*
41+
* @brief Initialize the RTC communication peripheral.
42+
* @param desc - The RTC descriptor.
43+
* @param param - The structure that contains the RTC parameters.
44+
* @return 0 in case of success, -ERROR otherwise.
45+
*/
46+
int32_t no_os_rtc_init(struct no_os_rtc_desc **device,
47+
struct no_os_rtc_init_param *init_param)
48+
{
49+
int ret;
50+
51+
/* Check if device pointer is NULL */
52+
if (!device) {
53+
return -EINVAL;
54+
}
55+
56+
/* Check if Platform Ops is not NULL */
57+
if (!init_param || !init_param->platform_ops) {
58+
return -EINVAL;
59+
}
60+
/* Check if platform specific init function exists */
61+
if (!init_param->platform_ops->init)
62+
return -ENOSYS;
63+
64+
/* Initilize RTC descriptor */
65+
ret = init_param->platform_ops->init(device, init_param);
66+
67+
if (ret)
68+
return ret;
69+
70+
(*device)->id = init_param->id;
71+
(*device)->extra = init_param->extra;
72+
(*device)->freq = init_param->freq;
73+
(*device)->load = init_param->load;
74+
(*device)->platform_ops = init_param->platform_ops;
75+
76+
return 0;
77+
}
78+
79+
/**
80+
* @brief Free the resources allocated by no_os_rtc_init().
81+
* @param device - The RTC descriptor.
82+
* @return 0 in case of success, negative error code otherwise.
83+
*/
84+
int32_t no_os_rtc_remove(struct no_os_rtc_desc *device)
85+
{
86+
/* Check if device pointer is NULL */
87+
if (!device || !device->platform_ops)
88+
return -EINVAL;
89+
/* Check if Platform Specific remove function is NULL */
90+
if (!device->platform_ops->remove)
91+
return -ENOSYS;
92+
93+
return device->platform_ops->remove(device);
94+
}
95+
96+
97+
/**
98+
* @brief Start the RTC device.
99+
* @param device - The RTC descriptor.
100+
* @return 0 in case of success, negative error code otherwise.
101+
*/
102+
int32_t no_os_rtc_start(struct no_os_rtc_desc *device)
103+
{
104+
/* Check if device pointer is NULL */
105+
if (!device || !device->platform_ops)
106+
return -EINVAL;
107+
/* Check if Platform Specific start function is NULL */
108+
if (!device->platform_ops->start)
109+
return -ENOSYS;
110+
111+
return device->platform_ops->start(device);
112+
}
113+
114+
/**
115+
* @brief Stop the RTC device.
116+
* @param device - The RTC descriptor.
117+
* @return 0 in case of success, negative error code otherwise.
118+
*/
119+
int32_t no_os_rtc_stop(struct no_os_rtc_desc *device)
120+
{
121+
int32_t ret = 0;
122+
123+
/* Check if device pointer is NULL */
124+
if (!device || !device->platform_ops)
125+
return -EINVAL;
126+
127+
/* Check if Platform Specific stop function is NULL */
128+
if (!device->platform_ops->stop)
129+
return -ENOSYS;
130+
131+
ret = device->platform_ops->stop(device);
132+
if (ret)
133+
return ret;
134+
135+
return 0;
136+
}
137+
138+
/**
139+
* @brief Stop the RTC device.
140+
* @param device - The RTC descriptor.
141+
* @param tmr_cnt - Stores the current timer count value.
142+
* @return 0 in case of success, negative error code otherwise.
143+
*/
144+
int32_t no_os_rtc_get_cnt(struct no_os_rtc_desc *device,
145+
uint32_t *tmr_cnt)
146+
{
147+
/* Check if device pointer or tmr_cnt is NULL */
148+
if (!device || !device->platform_ops)
149+
return -EINVAL;
150+
151+
/* Check if Platform Specific get_cnt function is NULL */
152+
if (!device->platform_ops->get_cnt)
153+
return -ENOSYS;
154+
155+
return device->platform_ops->get_cnt(device, tmr_cnt);
156+
}
157+
158+
/**
159+
* @brief Stop the RTC device.
160+
* @param device - The RTC descriptor.
161+
* @param tmr_cnt - The starting timer count value to set.
162+
* @return 0 in case of success, negative error code otherwise.
163+
*/
164+
int32_t no_os_rtc_set_cnt(struct no_os_rtc_desc *device,
165+
uint32_t tmr_cnt)
166+
{
167+
/* Check if device pointer is NULL */
168+
if (!device || !device->platform_ops)
169+
return -EINVAL;
170+
171+
/* Check if Platform Specific set_cnt function is NULL */
172+
if (!device->platform_ops->set_cnt)
173+
return -ENOSYS;
174+
175+
return device->platform_ops->set_cnt(device, tmr_cnt);
176+
}
177+
178+
/**
179+
* @brief Stop the RTC device.
180+
* @param device - The RTC descriptor.
181+
* @param irq_time - The time in seconds to set the IRQ.
182+
* @return 0 in case of success, negative error code otherwise.
183+
*/
184+
185+
int32_t no_os_rtc_set_irq_time(struct no_os_rtc_desc *device, uint32_t irq_time)
186+
{
187+
/* Check if device pointer is NULL */
188+
if (!device || !device->platform_ops)
189+
return -EINVAL;
190+
/* Check if Platform Specific set_irq_time function is NULL */
191+
if (!device->platform_ops->set_irq_time)
192+
return -ENOSYS;
193+
194+
/* Check if irq_time is valid */
195+
if (irq_time < 0 || !irq_time)
196+
return -EINVAL;
197+
198+
return device->platform_ops->set_irq_time(device, irq_time);
199+
}

drivers/platform/maxim/max32690/maxim_rtc.c

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* @file maxim_rtc.c
33
* @brief Implementation of RTC driver.
44
* @author Ciprian Regus ([email protected])
5+
* @author Francis Roi Manabat ([email protected])
56
********************************************************************************
6-
* Copyright 2023(c) Analog Devices, Inc.
7+
* Copyright 2025(c) Analog Devices, Inc.
78
*
89
* Redistribution and use in source and binary forms, with or without
910
* modification, are permitted provided that the following conditions are met:
@@ -48,8 +49,8 @@
4849
* @param init_param - The structure that contains the RTC initialization.
4950
* @return 0 in case of success, errno codes otherwise.
5051
*/
51-
int32_t no_os_rtc_init(struct no_os_rtc_desc **device,
52-
struct no_os_rtc_init_param *init_param)
52+
int32_t max_rtc_init(struct no_os_rtc_desc **device,
53+
struct no_os_rtc_init_param *init_param)
5354
{
5455
int32_t ret;
5556
struct no_os_rtc_desc *dev;
@@ -86,7 +87,7 @@ int32_t no_os_rtc_init(struct no_os_rtc_desc **device,
8687
* @param dev - The RTC descriptor.
8788
* @return 0 in case of success, errno codes otherwise.
8889
*/
89-
int32_t no_os_rtc_remove(struct no_os_rtc_desc *dev)
90+
int32_t max_rtc_remove(struct no_os_rtc_desc *dev)
9091
{
9192
if (!dev)
9293
return -EINVAL;
@@ -101,9 +102,11 @@ int32_t no_os_rtc_remove(struct no_os_rtc_desc *dev)
101102
* @param dev - The RTC descriptor.
102103
* @return 0 in case of success, errno codes otherwise.
103104
*/
104-
int32_t no_os_rtc_start(struct no_os_rtc_desc *dev)
105+
int32_t max_rtc_start(struct no_os_rtc_desc *dev)
105106
{
106-
MXC_RTC_Wait_BusyToClear();
107+
while (MXC_RTC_GetBusyFlag() == E_BUSY) {
108+
/* Wait for the RTC to be ready */
109+
};
107110
MXC_RTC_Start();
108111

109112
return 0;
@@ -114,9 +117,11 @@ int32_t no_os_rtc_start(struct no_os_rtc_desc *dev)
114117
* @param dev - The RTC descriptor.
115118
* @return 0 in case of success, errno codes otherwise.
116119
*/
117-
int32_t no_os_rtc_stop(struct no_os_rtc_desc *dev)
120+
int32_t max_rtc_stop(struct no_os_rtc_desc *dev)
118121
{
119-
MXC_RTC_Wait_BusyToClear();
122+
while (MXC_RTC_GetBusyFlag() == E_BUSY) {
123+
/* Wait for the RTC to be ready */
124+
};
120125
MXC_RTC_Stop();
121126

122127
return 0;
@@ -128,7 +133,7 @@ int32_t no_os_rtc_stop(struct no_os_rtc_desc *dev)
128133
* @param tmr_cnt - Pointer where the read counter will be stored.
129134
* @return 0 in case of success, errno codes otherwise.
130135
*/
131-
int32_t no_os_rtc_get_cnt(struct no_os_rtc_desc *dev, uint32_t *tmr_cnt)
136+
int32_t max_rtc_get_cnt(struct no_os_rtc_desc *dev, uint32_t *tmr_cnt)
132137
{
133138
*tmr_cnt = MXC_RTC_GetSecond();
134139

@@ -141,7 +146,7 @@ int32_t no_os_rtc_get_cnt(struct no_os_rtc_desc *dev, uint32_t *tmr_cnt)
141146
* @param tmr_cnt - New value of the timer counter.
142147
* @return 0 in case of success, errno codes otherwise.
143148
*/
144-
int32_t no_os_rtc_set_cnt(struct no_os_rtc_desc *dev, uint32_t tmr_cnt)
149+
int32_t max_rtc_set_cnt(struct no_os_rtc_desc *dev, uint32_t tmr_cnt)
145150
{
146151
mxc_rtc_regs_t *rtc_regs;
147152

@@ -150,19 +155,29 @@ int32_t no_os_rtc_set_cnt(struct no_os_rtc_desc *dev, uint32_t tmr_cnt)
150155

151156
rtc_regs = MXC_RTC;
152157

153-
MXC_RTC_Wait_BusyToClear();
158+
while (MXC_RTC_GetBusyFlag() == E_BUSY) {
159+
/* Wait for the RTC to be ready */
160+
};
154161
rtc_regs->ctrl |= MXC_F_RTC_REVA_CTRL_WR_EN;
155162

156-
MXC_RTC_Wait_BusyToClear();
163+
while (MXC_RTC_GetBusyFlag() == E_BUSY) {
164+
/* Wait for the RTC to be ready */
165+
};
157166
no_os_rtc_stop(dev);
158167

159-
MXC_RTC_Wait_BusyToClear();
168+
while (MXC_RTC_GetBusyFlag() == E_BUSY) {
169+
/* Wait for the RTC to be ready */
170+
};
160171
rtc_regs->sec = tmr_cnt;
161172

162-
MXC_RTC_Wait_BusyToClear();
173+
while (MXC_RTC_GetBusyFlag() == E_BUSY) {
174+
/* Wait for the RTC to be ready */
175+
};
163176
no_os_rtc_start(dev);
164177

165-
MXC_RTC_Wait_BusyToClear();
178+
while (MXC_RTC_GetBusyFlag() == E_BUSY) {
179+
/* Wait for the RTC to be ready */
180+
};
166181
rtc_regs->ctrl &= ~MXC_F_RTC_REVA_CTRL_WR_EN;
167182

168183
return 0;
@@ -174,9 +189,21 @@ int32_t no_os_rtc_set_cnt(struct no_os_rtc_desc *dev, uint32_t tmr_cnt)
174189
* @param irq_time - The number of seconds at which the interrupt must occur.
175190
* @return 0
176191
*/
177-
int32_t no_os_rtc_set_irq_time(struct no_os_rtc_desc *dev, uint32_t irq_time)
192+
int32_t max_rtc_set_irq_time(struct no_os_rtc_desc *dev, uint32_t irq_time)
178193
{
179-
MXC_RTC_SetTimeofdayAlarm(irq_time);
194+
if (MXC_RTC_SetTimeofdayAlarm(irq_time) != E_NO_ERROR) {
195+
return -EINVAL;
196+
}
180197

181198
return 0;
182199
}
200+
201+
const struct no_os_rtc_platform_ops max_rtc_ops = {
202+
.init = &max_rtc_init,
203+
.remove = &max_rtc_remove,
204+
.start = &max_rtc_start,
205+
.stop = &max_rtc_stop,
206+
.get_cnt = &max_rtc_get_cnt,
207+
.set_cnt = &max_rtc_set_cnt,
208+
.set_irq_time = &max_rtc_set_irq_time,
209+
};

drivers/platform/maxim/max32690/maxim_rtc.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/***************************************************************************//**
22
* @file maxim_rtc.h
33
* @brief Header file of RTC driver.
4-
* @author Ciprian Regus (ciprian.regus@analog.com)
4+
* @author Francis Roi Manabat (francisroi.manabat@analog.com)
55
********************************************************************************
6-
* Copyright 2023(c) Analog Devices, Inc.
6+
* Copyright 2025(c) Analog Devices, Inc.
77
*
88
* Redistribution and use in source and binary forms, with or without
99
* modification, are permitted provided that the following conditions are met:
1010
*
1111
* 1. Redistributions of source code must retain the above copyright notice,
12-
* this list of conditions and the following disclaimer.
12+
* this list of conditions and the following discl aimer.
1313
*
1414
* 2. Redistributions in binary form must reproduce the above copyright notice,
1515
* this list of conditions and the following disclaimer in the documentation
@@ -34,4 +34,21 @@
3434
#ifndef MAXIM_RTC_H_
3535
#define MAXIM_RTC_H_
3636

37+
extern const struct no_os_rtc_platform_ops max_rtc_ops;
38+
39+
int32_t max_rtc_init(struct no_os_rtc_desc **device,
40+
struct no_os_rtc_init_param *init_param);
41+
42+
int32_t max_rtc_remove(struct no_os_rtc_desc *dev);
43+
44+
int32_t max_rtc_start(struct no_os_rtc_desc *dev);
45+
46+
int32_t max_rtc_stop(struct no_os_rtc_desc *dev);
47+
48+
int32_t max_rtc_get_cnt(struct no_os_rtc_desc *dev, uint32_t *tmr_cnt);
49+
50+
int32_t max_rtc_set_cnt(struct no_os_rtc_desc *dev, uint32_t tmr_cnt);
51+
52+
int32_t max_rtc_set_irq_time(struct no_os_rtc_desc *dev, uint32_t irq_time);
53+
3754
#endif

0 commit comments

Comments
 (0)