AM62x MCU+ SDK  10.01.00
rtc/v0/rtc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
48 #ifndef RTC_H_
49 #define RTC_H_
50 
51 /* ========================================================================== */
52 /* Include Files */
53 /* ========================================================================== */
54 
55 #include <stdint.h>
56 #include <stdbool.h>
57 #include <kernel/dpl/SemaphoreP.h>
58 #include <kernel/dpl/HwiP.h>
59 #include <drivers/hw_include/cslr_rtc.h>
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /* ========================================================================== */
66 /* Macros & Typedefs */
67 /* ========================================================================== */
68 
70 #define OSCILLATOR_FREQ_HZ ((uint32_t) 32768U)
71 
73 #define RTC_FREEZE_MODE ((uint32_t) 0x02000000U)
74 
76 #define O32K_OSC_DEP_EN_MASK (CSL_RTC_GENRAL_CTL_O32K_OSC_DEP_EN_MASK)
77 
79 #define RD_PEND_MASK (CSL_RTC_SYNCPEND_RD_PEND_MASK)
80 
81 #define WR_PEND_MASK (CSL_RTC_SYNCPEND_WR_PEND_MASK)
82 
84 #define O32K_CLK_OBS_BIT_MASK (CSL_RTC_SYNCPEND_O32K_CLK_OBS_MASK)
85 
87 #define RTC_SW_OFF_MASK (CSL_RTC_GENRAL_CTL_SW_OFF_MASK)
88 
90 #define RTC_UNLOCK_MASK (CSL_RTC_GENRAL_CTL_UNLOCK_MASK)
91 
93 #define OSC_LOCK_WAIT (3U)
94 
96 #define KICK0_UNLOCK_VALUE (uint32_t)0x83E70B13U
97 #define KICK1_UNLOCK_VALUE (uint32_t)0x95A4F1E0U
98 
100 #define KICK0_LOCK_VALUE (CSL_RTC_KICK0_RESETVAL)
101 #define KICK1_LOCK_VALUE (CSL_RTC_KICK1_RESETVAL)
102 
104 #define RTC_BASEADDR (uint32_t)0x2B1F0000U
105 
113 #define RTC_TMR_INT_INT0_STATUS_FLAG (CSL_RTC_IRQSTATUS_SYS_EVENT_ON_OFF_MASK)
114 
115 #define RTC_TMR_INT_INT1_STATUS_FLAG (CSL_RTC_IRQSTATUS_SYS_EVENT_OFF_ON_MASK)
116 
118 #define RTC_TMR_INT_INT0_CLEAR_FLAG (CSL_RTC_IRQENABLE_CLR_SYS_EN_EVENT_ON_OFF_MASK)
119 
120 #define RTC_TMR_INT_INT1_CLEAR_FLAG (CSL_RTC_IRQENABLE_CLR_SYS_EN_EVENT_OFF_ON_MASK)
121 
123 #define RTC_TMR_INT_INT0_SET_FLAG (CSL_RTC_IRQENABLE_SET_SYS_EN_EVENT_ON_OFF_MASK)
124 
125 #define RTC_TMR_INT_INT1_SET_FLAG (CSL_RTC_IRQENABLE_SET_SYS_EN_EVENT_OFF_ON_MASK)
126 
128 #define RTC_TMR_INT_INT0_RAW_STATUS_FLAG (CSL_RTC_IRQSTATUS_RAW_SYS_EVENT_ON_OFF_MASK)
129 
130 #define RTC_TMR_INT_INT1_RAW_STATUS_FLAG (CSL_RTC_IRQSTATUS_RAW_SYS_EVENT_OFF_ON_MASK)
131 
133 #define RTC_TMR_INT_STATUS_ALL (RTC_TMR_INT_INT0_STATUS_FLAG | \
134  RTC_TMR_INT_INT1_STATUS_FLAG)
135 
136 #define RTC_TMR_INT_CLEAR_ALL (RTC_TMR_INT_INT0_CLEAR_FLAG | \
137  RTC_TMR_INT_INT1_CLEAR_FLAG)
138 
139 #define RTC_TMR_INT_REQ_ALL (RTC_TMR_INT_INT0_SET_FLAG | \
140  RTC_TMR_INT_INT1_SET_FLAG)
141 
142 #define RTC_TMR_INT_RAW_STATUS_ALL (RTC_TMR_INT_INT0_RAW_STATUS_FLAG | \
143  RTC_TMR_INT_INT1_RAW_STATUS_FLAG)
144 
146 /* ========================================================================== */
147 /* Structure Declarations */
148 /* ========================================================================== */
149 
153 typedef struct RTC_Config_s *RTC_Handle;
154 
155 /* ========================================================================== */
156 /* Function pointers Declarations */
157 /* ========================================================================== */
158 
167 typedef void (*RTC_OnOffCallbackFxn) (RTC_Handle handle);
168 
177 typedef void (*RTC_OffOnCallbackFxn) (RTC_Handle handle);
178 
179 /* ========================================================================== */
180 /* Structure Declarations */
181 /* ========================================================================== */
182 
186 typedef struct RTC_HwAttrs_s
187 {
188 
190  uint32_t baseAddr;
192  uint32_t intNum;
194  uint16_t eventId;
196  uint32_t inputClk;
200  uint8_t intrPriority;
201 
202 } RTC_HwAttrs;
203 
210 typedef struct RTC_Params_s
211 {
212 
214  uint32_t isfreezemode;
219 
220 } RTC_Params;
221 
225 typedef struct RTC_Object_s
226 {
232  bool isOpen;
235 
244 
245 } RTC_Object;
246 
256 typedef struct RTC_Config_s
257 {
262 } RTC_Config;
263 
267 typedef struct RTC_Time_s
268 {
270  uint32_t second;
272  uint32_t minute;
274  uint32_t hour;
276  uint32_t day;
278  uint32_t month;
280  uint32_t year;
281 } RTC_Time;
282 
283 /* ========================================================================== */
284 /* Function Declarations */
285 /* ========================================================================== */
286 
290 void RTC_init(void);
291 
295 void RTC_deinit(void);
296 
303 
312 RTC_Handle RTC_open(uint32_t idx, const RTC_Params *params);
313 
323 void RTC_close(RTC_Handle handle);
324 
333 int32_t RTC_setTime(RTC_Handle handle, const RTC_Time *rtc_time);
334 
343 int32_t RTC_getTime(RTC_Handle handle, RTC_Time *rtc_time);
344 
353 int32_t RTC_setOff_OnTimerEvent(RTC_Handle handle, const RTC_Time *rtc_time);
354 
363 int32_t RTC_setOn_OffTimerEvent(RTC_Handle handle, const RTC_Time *rtc_time);
364 
373 uint32_t RTC_readScratchRegister(RTC_Handle handle, uint32_t scratchIndex);
374 
384 int32_t RTC_writeScratchRegister(RTC_Handle handle, uint32_t scratchIndex, uint32_t value);
385 
392 RTC_Time RTC_calculateElapsedTime(const RTC_Time *startTime, const RTC_Time *endTime);
393 
402 int32_t RTC_adjustForDrift(RTC_Handle handle, Float32 measuredDriftInSeconds);
403 
411 int32_t RTC_stop(RTC_Handle handle);
412 
420 int32_t RTC_start(RTC_Handle handle);
421 
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 
440 #endif /* #ifndef RTC_H_ */
441 
RTC_start
int32_t RTC_start(RTC_Handle handle)
Start the RTC after it's stopped.
RTC_HwAttrs::baseAddr
uint32_t baseAddr
Definition: rtc/v0/rtc.h:190
RTC_close
void RTC_close(RTC_Handle handle)
Function to close the RTC Peripheral specified by the handle.
RTC_OffOnCallbackFxn
void(* RTC_OffOnCallbackFxn)(RTC_Handle handle)
The definition of a OFF_ON callback function used by the RTC driver.
Definition: rtc/v0/rtc.h:177
RTC_stop
int32_t RTC_stop(RTC_Handle handle)
Stop the RTC.
RTC_HwAttrs::inputClk
uint32_t inputClk
Definition: rtc/v0/rtc.h:196
RTC_Params::offOnCallback
bool offOnCallback
Definition: rtc/v0/rtc.h:218
RTC_setOn_OffTimerEvent
int32_t RTC_setOn_OffTimerEvent(RTC_Handle handle, const RTC_Time *rtc_time)
Set the on-off timer event / Use as timer 2 for RTC.
RTC_paramsInit
void RTC_paramsInit(RTC_Params *params)
Function to set default values of RTC_Params in params.
RTC_Params::isfreezemode
uint32_t isfreezemode
Definition: rtc/v0/rtc.h:214
RTC_HwAttrs
RTC Hardware attributes.
Definition: rtc/v0/rtc.h:187
RTC_Time::day
uint32_t day
Definition: rtc/v0/rtc.h:276
RTC_Time::minute
uint32_t minute
Definition: rtc/v0/rtc.h:272
RTC_Params
RTC Parameters.
Definition: rtc/v0/rtc.h:211
RTC_Object::mutex
SemaphoreP_Object mutex
Definition: rtc/v0/rtc.h:228
SemaphoreP.h
RTC_Time::year
uint32_t year
Definition: rtc/v0/rtc.h:280
RTC_HwAttrs::eventId
uint16_t eventId
Definition: rtc/v0/rtc.h:194
RTC_HwAttrs::intNum
uint32_t intNum
Definition: rtc/v0/rtc.h:192
RTC_Object
RTC driver object.
Definition: rtc/v0/rtc.h:226
RTC_Handle
struct RTC_Config_s * RTC_Handle
A handle that is returned from a RTC_open() call.
Definition: rtc/v0/rtc.h:153
RTC_getTime
int32_t RTC_getTime(RTC_Handle handle, RTC_Time *rtc_time)
Get the current RTC time.
RTC_Object::RTC_params
RTC_Params RTC_params
Definition: rtc/v0/rtc.h:234
RTC_open
RTC_Handle RTC_open(uint32_t idx, const RTC_Params *params)
Open the RTC at index idx with parameters params.
value
uint32_t value
Definition: tisci_otp_revision.h:2
RTC_Time
RTC Time Structure.
Definition: rtc/v0/rtc.h:268
RTC_Object::Off_OnCallbackFunction
RTC_OffOnCallbackFxn Off_OnCallbackFunction
Definition: rtc/v0/rtc.h:243
HwiP.h
RTC_erratumi2327Init
void RTC_erratumi2327Init(void)
RTC Erratum i2327 Workaround.
RTC_Time::hour
uint32_t hour
Definition: rtc/v0/rtc.h:274
RTC_Time::second
uint32_t second
Definition: rtc/v0/rtc.h:270
RTC_Object::On_OffCallbackFunction
RTC_OnOffCallbackFxn On_OffCallbackFunction
Definition: rtc/v0/rtc.h:241
RTC_Object::isOpen
bool isOpen
Definition: rtc/v0/rtc.h:232
RTC_Object::hwiObj
HwiP_Object hwiObj
Definition: rtc/v0/rtc.h:230
RTC_Config::object
RTC_Object * object
Definition: rtc/v0/rtc.h:259
RTC_HwAttrs::enableIntr
bool enableIntr
Definition: rtc/v0/rtc.h:198
RTC_calculateElapsedTime
RTC_Time RTC_calculateElapsedTime(const RTC_Time *startTime, const RTC_Time *endTime)
Calculate Elapsed Time.
RTC_HwAttrs::intrPriority
uint8_t intrPriority
Definition: rtc/v0/rtc.h:200
RTC_setOff_OnTimerEvent
int32_t RTC_setOff_OnTimerEvent(RTC_Handle handle, const RTC_Time *rtc_time)
Set the off-on timer event / Use as timer 1 for RTC.
RTC_OnOffCallbackFxn
void(* RTC_OnOffCallbackFxn)(RTC_Handle handle)
The definition of a ON_OFF callback function used by the RTC driver.
Definition: rtc/v0/rtc.h:167
RTC_deinit
void RTC_deinit(void)
De-initialize the RTC module.
RTC_readScratchRegister
uint32_t RTC_readScratchRegister(RTC_Handle handle, uint32_t scratchIndex)
Read a value from a specific RTC scratch register.
RTC_Config::hwAttrs
RTC_HwAttrs const * hwAttrs
Definition: rtc/v0/rtc.h:261
HwiP_Object
Opaque Hwi object used with the Hwi APIs.
Definition: HwiP.h:93
RTC_Config
RTC Global Configuration.
Definition: rtc/v0/rtc.h:257
RTC_init
void RTC_init(void)
Initialize the RTC module.
SemaphoreP_Object
Opaque semaphore object used with the semaphore APIs.
Definition: SemaphoreP.h:59
RTC_Params::onOffCallback
bool onOffCallback
Definition: rtc/v0/rtc.h:216
RTC_adjustForDrift
int32_t RTC_adjustForDrift(RTC_Handle handle, Float32 measuredDriftInSeconds)
Calculate Elapsed Time.
RTC_Time::month
uint32_t month
Definition: rtc/v0/rtc.h:278
RTC_setTime
int32_t RTC_setTime(RTC_Handle handle, const RTC_Time *rtc_time)
Set the RTC time.
RTC_writeScratchRegister
int32_t RTC_writeScratchRegister(RTC_Handle handle, uint32_t scratchIndex, uint32_t value)
Write a value to a specific RTC scratch register.