1 /***************************************************************************//**
2 * \file cy_rtc.h
3 * \version 2.90
4 *
5 * This file provides constants and parameter values for the APIs for the
6 * Real-Time Clock (RTC).
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright (c) (2016-2022), Cypress Semiconductor Corporation (an Infineon company) or
11 * an affiliate of Cypress Semiconductor Corporation.
12 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 *
26 *******************************************************************************/
27
28 /**
29 * \addtogroup group_rtc
30 * \{
31 *
32 * The Real-Time Clock (RTC) driver provides an application interface
33 * for keeping track of time and date.
34 *
35 * The functions and other declarations used in this driver are in cy_rtc.h.
36 * You can include cy_pdl.h to get access to all functions
37 * and declarations in the PDL.
38 *
39 * Use the RTC driver when the system requires the current time or date. You
40 * can also use the RTC when you do not need the current time and date but you
41 * do need accurate timing of events with one-second resolution.
42 *
43 * The RTC driver provides these features:
44 * * Different hour format support.
45 * * Multiple alarm function (two-alarms).
46 * * Daylight Savings Time (DST) support.
47 * * Automatic leap year compensation.
48 * * Option to drive the RTC by an external 50 Hz or 60 Hz clock source
49 *
50 * The RTC driver provides access to the HW real-time clock. The HW RTC is
51 * located in the Backup domain. You need to choose the clock source for the
52 * Backup domain using the Cy_SysClk_ClkBakSetSource() function. If the clock
53 * for the Backup domain is set and enabled, the RTC automatically
54 * starts counting.
55 *
56 * The RTC driver keeps track of second, minute, hour, day of the week, day of
57 * the month, month, and year.
58 *
59 * DST may be enabled and supports any start and end date. The start and end
60 * dates can be a fixed date (like 24 March) or a relative date (like the
61 * second Sunday in March).
62 *
63 * The RTC has two alarms that you can configure to generate an interrupt.
64 * You specify the match value for the time when you want the alarm to occur.
65 * Your interrupt handler then handles the response. The alarm flexibility
66 * supports periodic alarms (such as every minute), or a single alarm
67 * (13:45 on 28 September, 2043).
68 *
69 * <b> Clock Source </b>
70 *
71 * The Backup domain can be driven by:
72 * * Watch-crystal oscillator (WCO). This is a high-accuracy oscillator that is
73 * suitable for RTC applications and requires a 32.768 kHz external crystal
74 * populated on the application board. The WCO can be supplied by Backup domain
75 * and therefore can run without Vddd/Vccd present. This can be used to wake the
76 * chip from Hibernate mode.
77 *
78 * * The Internal Low-speed Oscillator (ILO) routed from Clk_LF or directly
79 * (as alternate backup domain clock source). Depending on the device power
80 * mode the alternate backup domain clock source is set. For example, for
81 * Deep Sleep mode the ILO is routed through Clk_LF. But for Hibernate
82 * power mode the ILO is set directly. Note that, the ILO should be configured to
83 * work in the Hibernate mode. For more info refer to the \ref group_sysclk
84 * driver. The ILO is a low-accuracy RC-oscillator that does not require
85 * any external elements on the board. Its poor accuracy (+/- 30%) means it is
86 * less useful for the RTC. However, current can be supplied by an internal
87 * power supply (Vback) and therefore it can run without Vddd/Vccd present.
88 * This also can be used to wake the chip from Hibernate mode using RTC alarm
89 * interrupt. For more details refer to \ref group_syspm driver description.
90 *
91 * * The Precision Internal Low-speed Oscillator (PILO), routed from Clk_LF
92 * (alternate backup domain clock source). This is an RC-oscillator (ILO) that
93 * can achieve accuracy of +/- 2% with periodic calibration. It is not expected
94 * to be accurate enough for good RTC capability. The PILO requires
95 * Vddd/Vccd present. It can be used in modes down to Deep Sleep, but ceases to
96 * function in Hibernate mode.
97 *
98 * * External 50 Hz or 60 Hz sine-wave clock source or 32.768 kHz square clock
99 * source.
100 * For example, the wall AC frequency can be the clock source. Such a clock
101 * source can be used if the external 32.768 kHz WCO is absent from the board.
102 * For more details, refer to the Cy_RTC_SelectFrequencyPrescaler() function
103 * description.
104 *
105 * The WCO is the recommended clock source for the RTC, if it is present
106 * in design. For setting the Backup domain clock source, refer to the
107 * \ref group_sysclk driver.
108 *
109 * \note If the WCO is enabled, it should source the Backup domain directly.
110 * Do not route the WCO through the Clk_LF. This is because Clk_LF is not
111 * available in all low-power modes.
112 *
113 * \section group_rtc_section_configuration Configuration Considerations
114 *
115 * Before RTC set up, ensure that the Backup domain is clocked with the desired
116 * clock source.
117 *
118 * To set up an RTC, provide the configuration parameters in the
119 * cy_stc_rtc_config_t structure. Then call Cy_RTC_Init(). You can also set the
120 * date and time at runtime. Call Cy_RTC_SetDateAndTime() using the filled
121 * cy_stc_rtc_config_t structure, or call Cy_RTC_SetDateAndTimeDirect() with
122 * valid time and date values.
123 *
124 * <b> RTC Interrupt Handling </b>
125 *
126 * The RTC driver provides three interrupt handler functions:
127 * Cy_RTC_Alarm1Interrupt(), Cy_RTC_Alarm2Interrupt(), and
128 * Cy_RTC_CenturyInterrupt(). All three functions are blank functions with
129 * the WEAK attribute. For any interrupt you use, redefine the interrupt handler
130 * in your source code.
131 *
132 * When an interrupt occurs, call the Cy_RTC_Interrupt() function. The RTC
133 * hardware provides a single interrupt line to the NVIC for the three RTC
134 * interrupts. This function checks the interrupt register to determine which
135 * interrupt (out of the three) was generated. It then calls the
136 * appropriate handler.
137 *
138 * \warning The Cy_RTC_Alarm2Interrupt() is not called if the DST feature is
139 * enabled. If DST is enabled, the Cy_RTC_Interrupt() function redirects that
140 * interrupt to manage daylight savings time using Cy_RTC_DstInterrupt().
141 * In general, the RTC interrupt handler function the Cy_RTC_DstInterrupt()
142 * function is called instead of Cy_RTC_Alarm2Interrupt().
143 *
144 * For RTC interrupt handling, the user should:
145 * -# Implement strong interrupt handling function(s) for the required events
146 * (see above). If DST is enabled, then Alarm2 is not available. The DST handler
147 * is built into the PDL.
148 * -# Implement an RTC interrupt handler and call Cy_RTC_Interrupt()
149 * from there.
150 * -# Configure the RTC interrupt:
151 * - Set the mask for RTC required interrupt using
152 * Cy_RTC_SetInterruptMask().
153 * - Initialize the RTC interrupt by setting priority and the RTC interrupt
154 * vector using the Cy_SysInt_Init() function.
155 * - Enable the RTC interrupt using the CMSIS core function NVIC_EnableIRQ().
156 *
157 * <b> Alarm functionality </b>
158 *
159 * To set up an alarm, enable the required RTC interrupt. Then provide the
160 * configuration parameters in the cy_stc_rtc_alarm_t structure. You enable
161 * any item you want matched, and provide a match value. You disable any other.
162 * You do not need to set match values for disabled elements, as they are
163 * ignored.
164 * \note The alarm itself must be enabled in this structure. When a match
165 * occurs, the alarm is triggered and your interrupt handler is called.
166 *
167 * An example is the best way to explain how this works. If you want an alarm
168 * on every hour, then in the cy_stc_rtc_alarm_t structure, you provide
169 * these values:
170 *
171 * Alarm_1.sec = 0u \n
172 * Alarm_1.secEn = CY_RTC_ALARM_ENABLE \n
173 * Alarm_1.min = 0u \n
174 * Alarm_1.minEn = CY_RTC_ALARM_ENABLE \n
175 * Alarm_1.hourEn = CY_RTC_ALARM_DISABLE \n
176 * Alarm_1.dayOfWeekEn = CY_RTC_ALARM_DISABLE \n
177 * Alarm_1.dateEn = CY_RTC_ALARM_DISABLE \n
178 * Alarm_1.monthEn = CY_RTC_ALARM_DISABLE \n
179 * Alarm_1.almEn = CY_RTC_ALARM_ENABLE \n
180 *
181 * With this setup, every time both the second and minute are zero, Alarm1 is
182 * asserted. That happens once per hour. Note that, counterintuitively, to have
183 * an alarm every hour, Alarm_1.hourEn is disabled. This is disabled because
184 * for an hourly alarm you do not match the value of the hour.
185 *
186 * After cy_stc_rtc_alarm_t structure is filled, call the
187 * Cy_RTC_SetAlarmDateAndTime(). The alarm can also be set without using the
188 * cy_stc_rtc_alarm_t structure. Call Cy_RTC_SetAlarmDateAndTimeDirect() with
189 * valid values.
190 *
191 * <b> The DST Feature </b>
192 *
193 * The DST feature is managed by the PDL using the RTC Alarm2 interrupt.
194 * Therefore, you cannot have both DST enabled and use the Alarm2 interrupt.
195 *
196 * To set up the DST, route the RTC interrupt to NVIC:
197 *
198 * -# Initialize the RTC interrupt by setting priority and the RTC interrupt
199 * vector using Cy_SysInt_Init().
200 * -# Enable the RTC interrupt using the CMSIS core function NVIC_EnableIRQ().
201 *
202 * After this, provide the configuration parameters in the
203 * cy_stc_rtc_dst_t structure. This structure consists of two
204 * cy_stc_rtc_dst_format_t structures, one for DST Start time and one for
205 * DST Stop time. You also specify whether these times are absolute or relative.
206 *
207 * After the cy_stc_rtc_dst_t structure is filled, call Cy_RTC_EnableDstTime()
208 *
209 * \section group_rtc_lp Low Power Support
210 * The RTC provides the callback functions to facilitate
211 * the low-power mode transition. The callback
212 * \ref Cy_RTC_DeepSleepCallback must be called during execution
213 * of \ref Cy_SysPm_CpuEnterDeepSleep, \ref Cy_RTC_HibernateCallback must be
214 * called during execution of \ref Cy_SysPm_SystemEnterHibernate.
215 * To trigger the callback execution, the callback must be registered
216 * before calling the mode transition function.
217 * Refer to \ref group_syspm driver for more
218 * information about low-power mode transitions.
219 *
220 * \section group_rtc_section_more_information More Information
221 *
222 * For more information on the RTC peripheral, refer to the technical reference
223 * manual (TRM).
224 *
225 * \section group_rtc_changelog Changelog
226 * <table class="doxtable">
227 * <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
228 * <tr>
229 * <td>2.90</td>
230 * <td>Updated API \ref Cy_RTC_GetInterruptStatus.</td>
231 * <td>Code enhancement.</td>
232 * </tr>
233 * <tr>
234 * <td>2.80</td>
235 * <td>Added support for TRAVEO™ II Body Entry devices.<br>
236 * Pre-processor check for MXS40SRSS version now groups ver. 2 with ver. 3. Previously ver. 2 was grouped with ver. 1.</td>
237 * Cleaned up redundant and overlapping conditions in pre-processor directives.</td>
238 * <td>Code enhancement and support for new devices.</td>
239 * </tr>
240 * <tr>
241 * <td>2.70</td>
242 * <td>Enhanced API's : Cy_RTC_SetDateAndTime(), Cy_RTC_SetDateAndTimeDirect(), Cy_RTC_SetAlarmDateAndTime(), Cy_RTC_SetAlarmDateAndTimeDirect().</td>
243 * <td>Minor Enhancements to the Driver.</td>
244 * </tr>
245 * <tr>
246 * <td>2.60</td>
247 * <td>CAT1B, CAT1C, CAT1D devices support.<br>Newly added API's Cy_RTC_WriteEnable() to Set/Clear writeable option for RTC user registers,
248 * Cy_RTC_EnableDstTime() to set the DST time and configure the ALARM2 interrupt register
249 * with the appropriate DST time, Cy_RTC_DstInterrupt() to handle the DST event.
250 * <br>Added a delay in Cy_RTC_SyncFromRtc() to check the RTC busy status.</td>
251 * <td>Support for new devices.</td>
252 * </tr>
253 * <tr>
254 * <td>2.50</td>
255 * <td>Removed the calls that convert among BCD and Binary.</td>
256 * <td>RTC encoding changed from BCD to Binary.</td>
257 * </tr>
258 * <tr>
259 * <td>2.40</td>
260 * <td>Fixed/Documented MISRA 2012 violations.</td>
261 * <td>MISRA 2012 compliance.</td>
262 * </tr>
263 * <tr>
264 * <td>2.30.1</td>
265 * <td>Minor documentation updates.</td>
266 * <td>Documentation enhancement.</td>
267 * </tr>
268 * <tr>
269 * <td>2.30</td>
270 * <td>
271 * * Corrected the Cy_RTC_GetDstStatus() and Cy_RTC_SetNextDstTime()
272 * documentation.
273 * * Fixed the Cy_RTC_GetDstStatus() behaviour in the 'an hour before/after the DST stop event' period.
274 * </td>
275 * <td>
276 * * Collateral Review: user experience enhancement.
277 * * Bug fix.
278 * </td>
279 * </tr>
280 * <tr>
281 * <td>2.20.1</td>
282 * <td>Modified header guard CY_IP_MXS40SRSS_RTC.</td>
283 * <td>To enable the PDL compilation with wounded out IP blocks.</td>
284 * </tr>
285 * <tr>
286 * <td rowspan="3">2.20</td>
287 * <td>Flattened the organization of the driver source code into the single
288 * source directory and the single include directory.
289 * </td>
290 * <td>Driver library directory-structure simplification.</td>
291 * </tr>
292 * <tr>
293 * <td>Added register access layer. Use register access macros instead
294 * of direct register access using dereferenced pointers.</td>
295 * <td>Makes register access device-independent, so that the PDL does
296 * not need to be recompiled for each supported part number.</td>
297 * </tr>
298 * <tr>
299 * <td>Documentation update.</td>
300 * <td>Documentation enhancement.</td>
301 * </tr>
302 * <tr>
303 * <td>2.10</td>
304 * <td>
305 * * Corrected Cy_RTC_SetDateAndTimeDirect(), Cy_RTC_SetNextDstTime()
306 * function.
307 * * Corrected internal macro.
308 * * Documentation updates.
309 * </td>
310 * <td>
311 * * Incorrect behavior of \ref Cy_RTC_SetDateAndTimeDirect() and
312 * \ref Cy_RTC_SetNextDstTime() work in debug mode.
313 * * Debug assert correction in \ref Cy_RTC_ConvertDayOfWeek,
314 * \ref Cy_RTC_IsLeapYear, \ref Cy_RTC_DaysInMonth.
315 * </td>
316 * </tr>
317 * <tr>
318 * <td>2.0</td>
319 * <td>
320 * Enhancement and defect fixes:
321 * * Added input parameter(s) validation to all public functions.
322 * * Removed "Cy_RTC_" prefixes from the internal functions names.
323 * * Renamed the elements in the cy_stc_rtc_alarm structure.
324 * * Changed the type of elements with limited set of values, from
325 * uint32_t to enumeration.
326 * </td>
327 * <td></td>
328 * </tr>
329 * <tr>
330 * <td>1.0</td>
331 * <td>Initial version</td>
332 * <td></td>
333 * </tr>
334 * </table>
335 *
336 * \defgroup group_rtc_macros Macros
337 * \defgroup group_rtc_functions Functions
338 * \{
339 * \defgroup group_rtc_general_functions General
340 * \defgroup group_rtc_alarm_functions Alarm
341 * \defgroup group_rtc_dst_functions DST functions
342 * \defgroup group_rtc_low_level_functions Low-Level
343 * \defgroup group_rtc_interrupt_functions Interrupt
344 * \defgroup group_rtc_low_power_functions Low Power Callbacks
345 * \}
346 * \defgroup group_rtc_data_structures Data Structures
347 * \defgroup group_rtc_enums Enumerated Types
348 */
349
350 #if !defined (CY_RTC_H)
351 #define CY_RTC_H
352
353 #include "cy_device.h"
354
355 #if defined (CY_IP_MXS40SRSS_RTC) || defined (CY_IP_MXS28SRSS) || defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
356
357 #include <stdint.h>
358 #include <stddef.h>
359 #include <stdbool.h>
360 #include "cy_syslib.h"
361 #include "cy_syspm.h"
362
363 #if defined(__cplusplus)
364 extern "C" {
365 #endif
366
367 /**
368 * \addtogroup group_rtc_macros
369 * \{
370 */
371
372 /** RTC driver identifier */
373 #define CY_RTC_ID (CY_PDL_DRV_ID(0x28U))
374
375 /** Driver major version */
376 #define CY_RTC_DRV_VERSION_MAJOR 2
377
378 /** Driver minor version */
379 #define CY_RTC_DRV_VERSION_MINOR 90
380
381 /** RTC driver retry macros */
382 #define CY_RTC_ACCESS_BUSY_RETRY_COUNT (200u)
383
384 /** RTC driver retry delay value */
385 #define CY_RTC_BUSY_RETRY_DELAY_US (1u) /* 1 usec */
386
387 /** \} group_rtc_macros */
388
389 /*******************************************************************************
390 * Enumerated Types
391 *******************************************************************************/
392
393 /**
394 * \addtogroup group_rtc_enums
395 * \{
396 */
397
398 /** RTC status enumeration */
399 typedef enum
400 {
401 CY_RTC_SUCCESS = 0x00U, /**< Successful */
402 CY_RTC_BAD_PARAM = CY_RTC_ID | CY_PDL_STATUS_ERROR | 0x01U, /**< One or more invalid parameters */
403 CY_RTC_TIMEOUT = CY_RTC_ID | CY_PDL_STATUS_ERROR | 0x02U, /**< Time-out occurs */
404 CY_RTC_INVALID_STATE = CY_RTC_ID | CY_PDL_STATUS_ERROR | 0x03U, /**< Operation not setup or is in an improper state */
405 CY_RTC_UNKNOWN = CY_RTC_ID | CY_PDL_STATUS_ERROR | 0xFFU /**< Unknown failure */
406 } cy_en_rtc_status_t;
407
408 /** This enumeration is used to set frequency by changing the it pre-scaler */
409 typedef enum
410 {
411 CY_RTC_FREQ_WCO_32768_HZ, /**< prescaler value for 32.768 kHz oscillator */
412 CY_RTC_FREQ_60_HZ, /**< prescaler value for 60 Hz source */
413 CY_RTC_FREQ_50_HZ, /**< prescaler value for 50 Hz source */
414 } cy_en_rtc_clock_freq_t;
415
416 /** This enumeration is used to set/get information for alarm 1 or alarm 2 */
417 typedef enum cy_en_rtc_alarm
418 {
419 CY_RTC_ALARM_1, /**< Alarm 1 enum */
420 CY_RTC_ALARM_2 /**< Alarm 2 enum */
421 } cy_en_rtc_alarm_t;
422
423 /** This enumeration is used to set/get hours format */
424 typedef enum
425 {
426 CY_RTC_24_HOURS, /**< The 24 hour format */
427 CY_RTC_12_HOURS /**< The 12 hour (AM/PM) format */
428 } cy_en_rtc_hours_format_t;
429
430 /** Enumeration to configure the RTC Write register */
431 typedef enum
432 {
433 CY_RTC_WRITE_DISABLED, /**< Writing the RTC is disabled */
434 CY_RTC_WRITE_ENABLED /**< Writing the RTC is enabled */
435 } cy_en_rtc_write_status_t;
436
437 /** Enumeration used to set/get DST format */
438 typedef enum
439 {
440 CY_RTC_DST_RELATIVE, /**< Relative DST format */
441 CY_RTC_DST_FIXED /**< Fixed DST format */
442 } cy_en_rtc_dst_format_t;
443
444 /** Enumeration to indicate the AM/PM period of day */
445 typedef enum
446 {
447 CY_RTC_AM, /**< AM period of day */
448 CY_RTC_PM /**< PM period of day */
449 } cy_en_rtc_am_pm_t;
450
451 /** Enumeration to enable/disable the RTC alarm on match with required value */
452 typedef enum
453 {
454 CY_RTC_ALARM_DISABLE, /**< Disable alarm on match with required value */
455 CY_RTC_ALARM_ENABLE /**< Enable alarm on match with required value */
456 } cy_en_rtc_alarm_enable_t;
457
458
459 /** Enumeration to list all the clock sources for RTC */
460 /**
461 **/
462 typedef enum
463 {
464 CY_RTC_CLK_SELECT_WCO = 0U, /**< Select WCO as input to RTC */
465 CY_RTC_CLK_SELECT_ALTBAK = 1U, /**< Select ALTBAK as input to RTC */
466 CY_RTC_CLK_SELECT_ILO = 2U, /**< Select ILO as input to RTC */
467 CY_RTC_CLK_SELECT_LPECO_PRESCALER = 3U, /**< Select LPECO_PRESCALER as input to RTC */
468 CY_RTC_CLK_SELECT_PILO = 4U, /**< Select PILO as input to RTC */
469 } cy_en_rtc_clk_select_sources_t;
470
471 /** Enumeration to select the sign of calibration for RTC */
472 /**
473 **/
474 typedef enum
475 {
476 CY_RTC_CALIB_SIGN_NEGATIVE = 0, /**< Negative sign: remove pulses */
477 CY_RTC_CALIB_SIGN_POSITIVE = 1, /**< Positive sign: add pulses */
478 } cy_en_rtc_calib_sign_t;
479
480 /** Enumeration to select the calibration wave output signal */
481 /**
482 **/
483 typedef enum
484 {
485 CY_RTC_CAL_SEL_CAL512 = 0, /**< 512Hz wave, not affected by calibration setting, (not supported for 50/60Hz input clock: CTL.PRESCALER!=0) */
486 CY_RTC_CAL_SEL_CAL2 = 2, /**< 2Hz wave, includes the effect of the calibration setting, (not supported for 50/60Hz input clock: CTL.PRESCALER!=0) */
487 CY_RTC_CAL_SEL_CAL1 = 3, /**< 1Hz wave, includes the effect of the calibration setting (supported for all input clocks) */
488 } cy_en_rtc_calib_sel_t;
489
490 /** \} group_rtc_enums */
491
492
493 /*******************************************************************************
494 * Types definition
495 *******************************************************************************/
496
497 /**
498 * \addtogroup group_rtc_data_structures
499 * \{
500 */
501
502 /**
503 * This is the data structure that is used to configure the rtc time
504 * and date values.
505 */
506 typedef struct cy_stc_rtc_config
507 {
508 /* Time information */
509 uint32_t sec; /**< Seconds value, range [0-59] */
510 uint32_t min; /**< Minutes value, range [0-59] */
511 uint32_t hour; /**< Hour, range depends on hrFormat, if hrFormat = CY_RTC_24_HOURS, range [0-23];
512 If hrFormat = CY_RTC_12_HOURS, range [1-12] and appropriate AM/PM day
513 period should be set (amPm) */
514 cy_en_rtc_am_pm_t amPm; /**< AM/PM hour period, see \ref cy_en_rtc_am_pm_t.
515 This element is actual when hrFormat = CY_RTC_12_HOURS. The firmware
516 ignores this element if hrFormat = CY_RTC_24_HOURS */
517 cy_en_rtc_hours_format_t hrFormat; /**< Hours format, see \ref cy_en_rtc_hours_format_t */
518 uint32_t dayOfWeek; /**< Day of the week, range [1-7], see \ref group_rtc_day_of_the_week */
519
520 /* Date information */
521 uint32_t date; /**< Date of month, range [1-31] */
522 uint32_t month; /**< Month, range [1-12]. See \ref group_rtc_month */
523 uint32_t year; /**< Year, range [0-99] */
524 } cy_stc_rtc_config_t;
525
526 /** Decimal data structure that is used to save the Alarms */
527 typedef struct cy_stc_rtc_alarm
528 {
529 /* Alarm time information */
530 uint32_t sec; /**< Alarm seconds, range [0-59].
531 The appropriate ALARMX interrupt is be asserted on matching with this
532 value if secEn is previous enabled (secEn = 1) */
533 cy_en_rtc_alarm_enable_t secEn; /**< Enable alarm on seconds matching, see \ref cy_en_rtc_alarm_enable_t. */
534
535 uint32_t min; /**< Alarm minutes, range [0-59].
536 The appropriate ALARMX interrupt is be asserted on matching with this
537 value if minEn is previous enabled (minEn = 1) */
538 cy_en_rtc_alarm_enable_t minEn; /**< Enable alarm on minutes matching, see \ref cy_en_rtc_alarm_enable_t. */
539
540 uint32_t hour; /**< Alarm hours, range [0-23]
541 The appropriate ALARMX interrupt is be asserted on matching with this
542 value if hourEn is previous enabled (hourEn = 1) */
543 cy_en_rtc_alarm_enable_t hourEn; /**< Enable alarm on hours matching, see \ref cy_en_rtc_alarm_enable_t. */
544
545 uint32_t dayOfWeek; /**< Alarm day of the week, range [1-7]
546 The appropriate ALARMX interrupt is be asserted on matching with this
547 value if dayOfWeek is previous enabled (dayOfWeekEn = 1) */
548 cy_en_rtc_alarm_enable_t dayOfWeekEn; /**< Enable alarm on day of the week matching,
549 see \ref cy_en_rtc_alarm_enable_t */
550
551 /* Alarm date information */
552 uint32_t date; /**< Alarm date, range [1-31].
553 The appropriate ALARMX interrupt is be asserted on matching with this
554 value if dateEn is previous enabled (dateEn = 1) */
555 cy_en_rtc_alarm_enable_t dateEn; /**< Enable alarm on date matching, see \ref cy_en_rtc_alarm_enable_t. */
556
557 uint32_t month; /**< Alarm Month, range [1-12].
558 The appropriate ALARMX interrupt is be asserted on matching with this
559 value if dateEn is previous enabled (dateEn = 1) */
560 cy_en_rtc_alarm_enable_t monthEn; /**< Enable alarm on month matching, see \ref cy_en_rtc_alarm_enable_t. */
561
562 cy_en_rtc_alarm_enable_t almEn; /**< Enable Alarm for appropriate ALARMX, see \ref cy_en_rtc_alarm_enable_t.
563 If all alarm structure elements are enabled (almEn = CY_RTC_ALARM_ENABLE)
564 the alarm interrupt is be asserted every second. */
565 } cy_stc_rtc_alarm_t;
566
567 /**
568 * This is DST structure for DST feature setting. Structure is combined with the
569 * fixed format and the relative format. It is used to save the DST time and date
570 * fixed or relative time format.
571 */
572 typedef struct
573 {
574 cy_en_rtc_dst_format_t format; /**< DST format. See /ref cy_en_rtc_dst_format_t.
575 Based on this value other structure elements
576 should be filled or could be ignored */
577 uint32_t hour; /**< Should be filled for both format types.
578 Hour is always presented in 24hour format, range[0-23] */
579 uint32_t dayOfMonth; /**< Day of Month, range[1-31]. This element should be filled if
580 format = CY_RTC_DST_FIXED. Firmware calculates this value in condition that
581 format = CY_RTC_DST_RELATIVE is selected */
582 uint32_t weekOfMonth; /**< Week of month, range[1-6]. This element should be filled if
583 format = CY_RTC_DST_RELATIVE.
584 Firmware calculates dayOfMonth value based on weekOfMonth
585 and dayOfWeek values */
586 uint32_t dayOfWeek; /**< Day of the week, this element should be filled in condition that
587 format = CY_RTC_DST_RELATIVE. Range[1- 7],
588 see \ref group_rtc_day_of_the_week. Firmware calculates dayOfMonth value
589 based on dayOfWeek and weekOfMonth values */
590 uint32_t month; /**< Month value, range[1-12], see \ref group_rtc_month.
591 This value should be filled for both format types */
592 } cy_stc_rtc_dst_format_t;
593
594 /** This is the DST structure to handle start DST and stop DST */
595 typedef struct
596 {
597 cy_stc_rtc_dst_format_t startDst; /**< DST start time structure */
598 cy_stc_rtc_dst_format_t stopDst; /**< DST stop time structure */
599 } cy_stc_rtc_dst_t;
600
601 /** \} group_rtc_data_structures */
602
603
604 /*******************************************************************************
605 * Function Prototypes
606 *******************************************************************************/
607
608 /**
609 * \addtogroup group_rtc_functions
610 * \{
611 */
612
613 /**
614 * \addtogroup group_rtc_general_functions
615 * \{
616 */
617 cy_en_rtc_status_t Cy_RTC_Init(cy_stc_rtc_config_t const *config);
618 cy_en_rtc_status_t Cy_RTC_SetDateAndTime(cy_stc_rtc_config_t const *dateTime);
619 void Cy_RTC_GetDateAndTime(cy_stc_rtc_config_t *dateTime);
620 cy_en_rtc_status_t Cy_RTC_SetDateAndTimeDirect(uint32_t sec, uint32_t min, uint32_t hour,
621 uint32_t date, uint32_t month, uint32_t year);
622 cy_en_rtc_status_t Cy_RTC_SetHoursFormat(cy_en_rtc_hours_format_t hoursFormat);
623 #if defined (CY_IP_MXS40SRSS_RTC) || defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
624 void Cy_RTC_SelectFrequencyPrescaler(cy_en_rtc_clock_freq_t clkSel);
625 #endif
626 void Cy_RTC_SelectClockSource(cy_en_rtc_clk_select_sources_t clkSel);
627 cy_en_rtc_status_t Cy_RTC_CalibrationControlEnable(uint8_t calib_val, cy_en_rtc_calib_sign_t calib_sign, cy_en_rtc_calib_sel_t calib_sel);
628 cy_en_rtc_status_t Cy_RTC_CalibrationControlDisable(void);
629
630 /** \} group_rtc_general_functions */
631
632 /**
633 * \addtogroup group_rtc_alarm_functions
634 * \{
635 */
636 cy_en_rtc_status_t Cy_RTC_SetAlarmDateAndTime(cy_stc_rtc_alarm_t const *alarmDateTime, cy_en_rtc_alarm_t alarmIndex);
637 void Cy_RTC_GetAlarmDateAndTime(cy_stc_rtc_alarm_t *alarmDateTime, cy_en_rtc_alarm_t alarmIndex);
638 cy_en_rtc_status_t Cy_RTC_SetAlarmDateAndTimeDirect(uint32_t sec, uint32_t min, uint32_t hour,
639 uint32_t date, uint32_t month, cy_en_rtc_alarm_t alarmIndex);
640 /** \} group_rtc_alarm_functions */
641
642 /**
643 * \addtogroup group_rtc_dst_functions
644 * \{
645 */
646 cy_en_rtc_status_t Cy_RTC_EnableDstTime(cy_stc_rtc_dst_t const *dstTime, cy_stc_rtc_config_t const *timeDate);
647 cy_en_rtc_status_t Cy_RTC_SetNextDstTime(cy_stc_rtc_dst_format_t const *nextDst);
648 bool Cy_RTC_GetDstStatus(cy_stc_rtc_dst_t const *dstTime, cy_stc_rtc_config_t const *timeDate);
649 /** \} group_rtc_dst_functions */
650
651 /**
652 * \addtogroup group_rtc_interrupt_functions
653 * \{
654 */
655 void Cy_RTC_Interrupt(cy_stc_rtc_dst_t const *dstTime, bool mode);
656 void Cy_RTC_Alarm1Interrupt(void);
657 void Cy_RTC_Alarm2Interrupt(void);
658 void Cy_RTC_DstInterrupt(cy_stc_rtc_dst_t const *dstTime);
659 void Cy_RTC_CenturyInterrupt(void);
660 uint32_t Cy_RTC_GetInterruptStatus(void);
661 uint32_t Cy_RTC_GetInterruptStatusMasked(void);
662 uint32_t Cy_RTC_GetInterruptMask(void);
663 void Cy_RTC_ClearInterrupt(uint32_t interruptMask);
664 void Cy_RTC_SetInterrupt(uint32_t interruptMask);
665 void Cy_RTC_SetInterruptMask(uint32_t interruptMask);
666 /** \} group_rtc_interrupt_functions */
667
668 /**
669 * \addtogroup group_rtc_low_power_functions
670 * \{
671 */
672 cy_en_syspm_status_t Cy_RTC_DeepSleepCallback(const cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode);
673 cy_en_syspm_status_t Cy_RTC_HibernateCallback(const cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode);
674 /** \} group_rtc_low_power_functions */
675
676 /**
677 * \addtogroup group_rtc_low_level_functions
678 * \{
679 */
680 __STATIC_INLINE uint32_t Cy_RTC_ConvertDayOfWeek(uint32_t day, uint32_t month, uint32_t year);
681 __STATIC_INLINE bool Cy_RTC_IsLeapYear(uint32_t year);
682 __STATIC_INLINE uint32_t Cy_RTC_DaysInMonth(uint32_t month, uint32_t year);
683 __STATIC_INLINE void Cy_RTC_SyncFromRtc(void);
684 __STATIC_INLINE cy_en_rtc_status_t Cy_RTC_WriteEnable(cy_en_rtc_write_status_t writeEnable);
685 __STATIC_INLINE uint32_t Cy_RTC_GetSyncStatus(void);
686 __STATIC_INLINE cy_en_rtc_hours_format_t Cy_RTC_GetHoursFormat(void);
687 __STATIC_INLINE bool Cy_RTC_IsExternalResetOccurred(void);
688
689 __STATIC_INLINE void Cy_RTC_SyncToRtcAhbDateAndTime(uint32_t timeBcd, uint32_t dateBcd);
690 __STATIC_INLINE void Cy_RTC_SyncToRtcAhbAlarm(uint32_t alarmTimeBcd, uint32_t alarmDateBcd, cy_en_rtc_alarm_t alarmIndex);
691
692 /** \} group_rtc_low_level_functions */
693
694 /** \} group_rtc_functions */
695
696 /**
697 * \addtogroup group_rtc_macros
698 * \{
699 */
700
701 /*******************************************************************************
702 * API Constants
703 *******************************************************************************/
704
705 /**
706 * \defgroup group_rtc_day_of_the_week Day of the week definitions
707 * \{
708 * Definitions of days in the week
709 */
710 #define CY_RTC_SUNDAY (1UL) /**< Sequential number of Sunday in the week */
711 #define CY_RTC_MONDAY (2UL) /**< Sequential number of Monday in the week */
712 #define CY_RTC_TUESDAY (3UL) /**< Sequential number of Tuesday in the week */
713 #define CY_RTC_WEDNESDAY (4UL) /**< Sequential number of Wednesday in the week */
714 #define CY_RTC_THURSDAY (5UL) /**< Sequential number of Thursday in the week */
715 #define CY_RTC_FRIDAY (6UL) /**< Sequential number of Friday in the week */
716 #define CY_RTC_SATURDAY (7UL) /**< Sequential number of Saturday in the week */
717 #define CY_RTC_DAY_AUTO (8UL) /**< Calculate the day of the week for the provided date, month, year automatically */
718 /** \} group_rtc_day_of_the_week */
719
720 /**
721 * \defgroup group_rtc_dst_week_of_month Week of month definitions
722 * \{
723 * Week of Month setting constants definitions for Daylight Saving Time feature
724 */
725 #define CY_RTC_FIRST_WEEK_OF_MONTH (1UL) /**< First week in the month */
726 #define CY_RTC_SECOND_WEEK_OF_MONTH (2UL) /**< Second week in the month */
727 #define CY_RTC_THIRD_WEEK_OF_MONTH (3UL) /**< Third week in the month */
728 #define CY_RTC_FOURTH_WEEK_OF_MONTH (4UL) /**< Fourth week in the month */
729 #define CY_RTC_FIFTH_WEEK_OF_MONTH (5UL) /**< Fifth week in the month */
730 #define CY_RTC_LAST_WEEK_OF_MONTH (6UL) /**< Last week in the month */
731 /** \} group_rtc_dst_week_of_month */
732
733 /**
734 * \defgroup group_rtc_month Month definitions
735 * \{
736 * Constants definition for Months
737 */
738 #define CY_RTC_JANUARY (1UL) /**< Sequential number of January in the year */
739 #define CY_RTC_FEBRUARY (2UL) /**< Sequential number of February in the year */
740 #define CY_RTC_MARCH (3UL) /**< Sequential number of March in the year */
741 #define CY_RTC_APRIL (4UL) /**< Sequential number of April in the year */
742 #define CY_RTC_MAY (5UL) /**< Sequential number of May in the year */
743 #define CY_RTC_JUNE (6UL) /**< Sequential number of June in the year */
744 #define CY_RTC_JULY (7UL) /**< Sequential number of July in the year */
745 #define CY_RTC_AUGUST (8UL) /**< Sequential number of August in the year */
746 #define CY_RTC_SEPTEMBER (9UL) /**< Sequential number of September in the year */
747 #define CY_RTC_OCTOBER (10UL) /**< Sequential number of October in the year */
748 #define CY_RTC_NOVEMBER (11UL) /**< Sequential number of November in the year */
749 #define CY_RTC_DECEMBER (12UL) /**< Sequential number of December in the year */
750 /** \} group_rtc_month */
751
752 /**
753 * \defgroup group_rtc_days_in_month Number of days in month definitions
754 * \{
755 * Definition of days in current month
756 */
757 #define CY_RTC_DAYS_IN_JANUARY (31U) /**< Number of days in January */
758 #define CY_RTC_DAYS_IN_FEBRUARY (28U) /**< Number of days in February */
759 #define CY_RTC_DAYS_IN_MARCH (31U) /**< Number of days in March */
760 #define CY_RTC_DAYS_IN_APRIL (30U) /**< Number of days in April */
761 #define CY_RTC_DAYS_IN_MAY (31U) /**< Number of days in May */
762 #define CY_RTC_DAYS_IN_JUNE (30U) /**< Number of days in June */
763 #define CY_RTC_DAYS_IN_JULY (31U) /**< Number of days in July */
764 #define CY_RTC_DAYS_IN_AUGUST (31U) /**< Number of days in August */
765 #define CY_RTC_DAYS_IN_SEPTEMBER (30U) /**< Number of days in September */
766 #define CY_RTC_DAYS_IN_OCTOBER (31U) /**< Number of days in October */
767 #define CY_RTC_DAYS_IN_NOVEMBER (30U) /**< Number of days in November */
768 #define CY_RTC_DAYS_IN_DECEMBER (31U) /**< Number of days in December */
769 /** \} group_rtc_days_in_month */
770
771 /**
772 * \defgroup group_rtc_macros_interrupts RTC Interrupt sources
773 * \{
774 * Definitions for RTC interrupt sources
775 */
776 /** Alarm 1 status */
777 #define CY_RTC_INTR_ALARM1 BACKUP_INTR_ALARM1_Msk
778
779 /** Alarm 2 status */
780 #define CY_RTC_INTR_ALARM2 BACKUP_INTR_ALARM2_Msk
781
782 /**
783 * This interrupt occurs when the year is reached to 2100 which is rolling
784 * over the year field value from 99 to 0
785 */
786 #define CY_RTC_INTR_CENTURY BACKUP_INTR_CENTURY_Msk
787 /** \} group_rtc_macros_interrupts */
788
789 /**
790 * \defgroup group_rtc_busy_status RTC Status definitions
791 * \{
792 * Definitions for indicating the RTC BUSY bit
793 */
794 #define CY_RTC_BUSY (1UL) /**< RTC Busy bit is set, RTC is pending */
795 #define CY_RTC_AVAILABLE (0UL) /**< RTC Busy bit is cleared, RTC is available */
796 /** \} group_rtc_busy_status */
797
798 /*******************************************************************************
799 * Internal Constants
800 *******************************************************************************/
801
802 /** \cond INTERNAL */
803
804 /** Days per week definition */
805 #define CY_RTC_DAYS_PER_WEEK (7UL)
806
807 /** Month per year definition */
808 #define CY_RTC_MONTHS_PER_YEAR (12U)
809
810 /** Maximum value of seconds and minutes */
811 #define CY_RTC_MAX_SEC_OR_MIN (59UL)
812
813 /** Biggest value of hours definition */
814 #define CY_RTC_MAX_HOURS_24H (23UL)
815
816 /** Maximum value of year definition */
817 #define CY_RTC_MAX_DAYS_IN_MONTH (31UL)
818
819 /** Maximum value of year definition */
820 #define CY_RTC_MAX_YEAR (99UL)
821
822 /** Number of RTC interrupts */
823 #define CY_RTC_NUM_OF_INTR (3U)
824
825 /** Number of RTC interrupts */
826 #define CY_RTC_TRYES_TO_SETUP_DST (24U)
827
828 /** RTC AM/PM bit for 12H hour mode */
829 #if defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION >= 2) || defined (CY_IP_MXS22SRSS)
830 #define CY_RTC_12HRS_PM_BIT (0x10UL)
831 #else
832 #define CY_RTC_12HRS_PM_BIT (0x20UL)
833 #endif/* CY_IP_MXS40SSRSS */
834
835 /** Mask for reading RTC AM/PM bit for 12H mode */
836 #define CY_RTC_BACKUP_RTC_TIME_RTC_PM ((uint32_t) (CY_RTC_12HRS_PM_BIT << BACKUP_RTC_TIME_RTC_HOUR_Pos))
837
838 /** Internal define for BCD values converting */
839 #define CY_RTC_BCD_NUMBER_SIZE (4UL)
840
841 /** Internal mask for BCD values converting */
842 #define CY_RTC_BCD_ONE_DIGIT_MASK (0x0000000FUL)
843
844 /** Internal define of dozen degree for BCD values converting */
845 #define CY_RTC_BCD_DOZED_DEGREE (10UL)
846
847 /** Internal define of hundred degree for BCD values converting */
848 #define CY_RTC_BCD_HUNDRED_DEGRE (100UL)
849
850 /** Definition of forty two AHB clocks in microseconds */
851 #define CY_RTC_DELAY_WHILE_READING_US ((42000000UL / cy_AhbFreqHz) + 1UL)
852
853 /** Definition of two WCO clocks in microseconds */
854 #define CY_RTC_DELAY_FOR_NEXT_DST (2000U)
855
856 /** Two thousand years definition */
857 #define CY_RTC_TWO_THOUSAND_YEARS (2000UL)
858
859 /** Two thousand years definition */
860 #define CY_RTC_TWENTY_ONE_HUNDRED_YEARS (2100UL)
861
862 /** Mask for reading RTC hour for 12H mode */
863 #if defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION >= 2) || defined (CY_IP_MXS22SRSS)
864 #define CY_RTC_BACKUP_RTC_TIME_RTC_12HOUR (0xf0000UL)
865 #else
866 #define CY_RTC_BACKUP_RTC_TIME_RTC_12HOUR (0x1f0000UL)
867 #endif/* CY_IP_MXS40SSRSS */
868
869 /** Half day hours definition */
870 #define CY_RTC_HOURS_PER_HALF_DAY (12UL)
871
872 /** First day of the month definition */
873 #define CY_RTC_FIRST_DAY_OF_MONTH (1UL)
874
875 /** Internal definition for DST GetDstStatus() function */
876 #define CY_RTC_DST_MONTH_POSITION (10UL)
877
878 /** Internal definition for DST GetDstStatus() function */
879 #define CY_RTC_DST_DAY_OF_MONTH_POSITION (5UL)
880
881 /** RTC days in months table */
882 extern uint8_t const cy_RTC_daysInMonthTbl[CY_RTC_MONTHS_PER_YEAR];
883
884 /* Internal macro to validate parameters in Cy_RTC_SelectFrequencyPrescaler() function */
885 #if defined (CY_IP_MXS40SRSS_RTC) || defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
886 #define CY_RTC_IS_CLK_VALID(clkSel) (((clkSel) == CY_RTC_FREQ_WCO_32768_HZ) || \
887 ((clkSel) == CY_RTC_FREQ_60_HZ) || \
888 ((clkSel) == CY_RTC_FREQ_50_HZ))
889 #endif
890
891 #if defined (CY_IP_MXS40SRSS_RTC)
892 /* Internal macro to validate parameters in Cy_RTC_SelectClockSource() function */
893 #define CY_RTC_IS_SRC_CLK_SELECT_VALID(clkSel) (((clkSel) == CY_RTC_CLK_SELECT_WCO) || \
894 ((clkSel) == CY_RTC_CLK_SELECT_ALTBAK) || \
895 ((clkSel) == CY_RTC_CLK_SELECT_ILO) || \
896 ((clkSel) == CY_RTC_CLK_SELECT_LPECO_PRESCALER) || \
897 ((clkSel) == CY_RTC_CLK_SELECT_PILO))
898 #endif
899
900 #if defined (CY_IP_MXS28SRSS) || defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
901 /* Internal macro to validate parameters in Cy_RTC_SelectClockSource() function */
902 #define CY_RTC_IS_SRC_CLK_SELECT_VALID(clkSel) (((clkSel) == CY_RTC_CLK_SELECT_WCO) || \
903 ((clkSel) == CY_RTC_CLK_SELECT_ALTBAK) || \
904 ((clkSel) == CY_RTC_CLK_SELECT_ILO) || \
905 ((clkSel) == CY_RTC_CLK_SELECT_PILO))
906 #endif
907
908 /* Internal macro to validate parameters in Cy_RTC_SetHoursFormat() function */
909 #define CY_RTC_IS_HRS_FORMAT_VALID(hoursFormat) (((hoursFormat) == CY_RTC_24_HOURS) || \
910 ((hoursFormat) == CY_RTC_12_HOURS))
911
912 /* Internal macro to validate parameters in Cy_RTC_WriteEnable() function */
913 #define CY_RTC_IS_WRITE_VALID(writeEnable) (((writeEnable) == CY_RTC_WRITE_DISABLED) || \
914 ((writeEnable) == CY_RTC_WRITE_ENABLED))
915
916 /* Internal macro of all possible RTC interrupts */
917 #define CY_RTC_INTR_MASK (CY_RTC_INTR_ALARM1 | CY_RTC_INTR_ALARM2 | CY_RTC_INTR_CENTURY)
918
919 /* Macro to validate parameters in interrupt related functions */
920 #define CY_RTC_INTR_VALID(interruptMask) (0UL == ((interruptMask) & ((uint32_t) ~(CY_RTC_INTR_MASK))))
921
922 /* Internal macro to validate RTC seconds and minutes parameters */
923 #define CY_RTC_IS_SEC_VALID(sec) ((sec) <= CY_RTC_MAX_SEC_OR_MIN)
924
925 /* Internal macro to validate RTC seconds and minutes parameters */
926 #define CY_RTC_IS_MIN_VALID(min) ((min) <= CY_RTC_MAX_SEC_OR_MIN)
927
928 /* Internal macro to validate RTC hour parameter */
929 #define CY_RTC_IS_HOUR_VALID(hour) ((hour) <= CY_RTC_MAX_HOURS_24H)
930
931 /* Internal macro to validate RTC day of the week parameter, To support CY_RTC_DAY_AUTO feature incremented the valid case by 1 */
932 #define CY_RTC_IS_DOW_VALID(dayOfWeek) (((dayOfWeek) > 0U) && ((dayOfWeek) <= (CY_RTC_DAYS_PER_WEEK + 1UL)))
933
934 /* Internal macro to validate RTC day parameter */
935 #define CY_RTC_IS_DAY_VALID(day) (((day) > 0U) && ((day) <= CY_RTC_MAX_DAYS_IN_MONTH))
936
937 /* Internal macro to validate RTC month parameter */
938 #define CY_RTC_IS_MONTH_VALID(month) (((month) > 0U) && ((month) <= CY_RTC_MONTHS_PER_YEAR))
939
940 #define CY_RTC_IS_DATE_VALID(date, DaysInMonth) ((date > 0U) && (date <= DaysInMonth))
941
942 /* Internal macro to validate RTC week day parameter */
943 #define CY_RTC_IS_WEEK_DAY_VALID(dayOfWeek, validDay) ((dayOfWeek == CY_RTC_DAY_AUTO) ? true : (dayOfWeek == validDay))
944
945 /* Internal macro to validate RTC year parameter */
946 #define CY_RTC_IS_YEAR_SHORT_VALID(year) ((year) <= CY_RTC_MAX_YEAR)
947
948 /* Internal macro to validate the year value in the Cy_RTC_ConvertDayOfWeek() */
949 #define CY_RTC_IS_YEAR_LONG_VALID(year) ((year) > 0U)
950
951 /* Internal macro to validate RTC alarm parameter */
952 #define CY_RTC_IS_ALARM_EN_VALID(alarmEn) (((alarmEn) == CY_RTC_ALARM_DISABLE) || \
953 ((alarmEn) == CY_RTC_ALARM_ENABLE))
954
955 /* Internal macro to validate RTC alarm index parameter */
956 #define CY_RTC_IS_ALARM_IDX_VALID(alarmIndex) (((alarmIndex) == CY_RTC_ALARM_1) || ((alarmIndex) == CY_RTC_ALARM_2))
957
958 /* Internal macro to validate RTC alarm index parameter */
959 #define CY_RTC_IS_DST_FORMAT_VALID(format) (((format) == CY_RTC_DST_RELATIVE) || ((format) == CY_RTC_DST_FIXED))
960
961 /** \endcond */
962 /** \} group_rtc_macros */
963
964 /**
965 * \addtogroup group_rtc_low_level_functions
966 * \{
967 */
968
969 /*******************************************************************************
970 * Function Name: Cy_RTC_ConvertDayOfWeek
971 ****************************************************************************//**
972 *
973 * Returns a day of the week for a year, month, and day of month that are passed
974 * through parameters. Zeller's congruence is used to calculate the day of
975 * the week.
976 * RTC HW block does not provide the converting function for day of week. This
977 * function should be called before Cy_RTC_SetDateAndTime() to get the day of
978 * week.
979 *
980 * For the Georgian calendar, Zeller's congruence is:
981 * h = (q + [13 * (m + 1)] + K + [K/4] + [J/4] - 2J) mod 7
982 *
983 * h - The day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ., 6 = Friday).
984 * q - The day of the month.
985 * m - The month (3 = March, 4 = April, 5 = May, ..., 14 = February)
986 * K - The year of the century (year mod 100).
987 * J - The zero-based century (actually [year/100]) For example, the zero-based
988 * centuries for 1995 and 2000 are 19 and 20 respectively (not to be
989 * confused with the common ordinal century enumeration which indicates
990 * 20th for both cases).
991 *
992 * \note In this algorithm January and February are counted as months 13 and 14
993 * of the previous year.
994 *
995 * \param day
996 * The day of the month, Valid range 1..31.
997 *
998 * \param month
999 * The month of the year, see \ref group_rtc_month.
1000 *
1001 * \param year
1002 * The year value. Valid range non-zero value.
1003 *
1004 * \return
1005 * Returns a day of the week, see \ref group_rtc_day_of_the_week.
1006 *
1007 *******************************************************************************/
Cy_RTC_ConvertDayOfWeek(uint32_t day,uint32_t month,uint32_t year)1008 __STATIC_INLINE uint32_t Cy_RTC_ConvertDayOfWeek(uint32_t day, uint32_t month, uint32_t year)
1009 {
1010 uint32_t retVal;
1011
1012 CY_ASSERT_L2(CY_RTC_IS_DAY_VALID(day));
1013 CY_ASSERT_L2(CY_RTC_IS_MONTH_VALID(month));
1014 CY_ASSERT_L2(CY_RTC_IS_YEAR_LONG_VALID(year));
1015
1016 /* Converts month number from regular convention
1017 * (1=January,..., 12=December) to convention required for this
1018 * algorithm (January and February are counted as months 13 and 14 of
1019 * previous year).
1020 */
1021 if (month < CY_RTC_MARCH)
1022 {
1023 month = CY_RTC_MONTHS_PER_YEAR + month;
1024 year--;
1025 }
1026
1027 /* Calculates Day of Week using Zeller's congruence algorithms */
1028 retVal =
1029 (day + (((month + 1UL) * 26UL) / 10UL) + year + (year / 4UL) + (6UL * (year / 100UL)) + (year / 400UL)) % 7UL;
1030
1031 /* Makes correction for Saturday. Saturday number should be 7 instead of 0*/
1032 if (0u == retVal)
1033 {
1034 retVal = CY_RTC_SATURDAY;
1035 }
1036
1037 return(retVal);
1038 }
1039
1040
1041 /*******************************************************************************
1042 * Function Name: Cy_RTC_IsLeapYear
1043 ****************************************************************************//**
1044 *
1045 * Checks whether the year passed through the parameter is leap or not.
1046 *
1047 * This API is for checking an invalid value input for leap year.
1048 * RTC HW block does not provide a validation checker against time/date values,
1049 * the valid range of days in Month should be checked before SetDateAndTime()
1050 * function call. Leap year is identified as a year that is a multiple of 4
1051 * or 400 but not 100.
1052 *
1053 * \param year
1054 * The year to be checked. Valid range non-zero value.
1055 *
1056 * \return
1057 * False - The year is not leap.
1058 * True - The year is leap.
1059 *
1060 *******************************************************************************/
Cy_RTC_IsLeapYear(uint32_t year)1061 __STATIC_INLINE bool Cy_RTC_IsLeapYear(uint32_t year)
1062 {
1063 CY_ASSERT_L2(CY_RTC_IS_YEAR_LONG_VALID(year));
1064
1065 return(((0U == (year % 4UL)) && (0U != (year % 100UL))) || (0U == (year % 400UL)));
1066 }
1067
1068
1069 /*******************************************************************************
1070 * Function Name: Cy_RTC_DaysInMonth
1071 ****************************************************************************//**
1072 *
1073 * Returns a number of days in a month passed through the parameters. This API
1074 * is for checking an invalid value input for days.
1075 * RTC HW block does not provide a validation checker against time/date values,
1076 * the valid range of days in Month should be checked before SetDateAndTime()
1077 * function call.
1078 *
1079 * \param month
1080 * The month of the year, see \ref group_rtc_month.
1081 *
1082 * \param year
1083 * A year value. Valid range non-zero value.
1084 *
1085 * \return
1086 * A number of days in a month in the year passed through the parameters.
1087 *
1088 *******************************************************************************/
Cy_RTC_DaysInMonth(uint32_t month,uint32_t year)1089 __STATIC_INLINE uint32_t Cy_RTC_DaysInMonth(uint32_t month, uint32_t year)
1090 {
1091 uint32_t retVal;
1092
1093 CY_ASSERT_L2(CY_RTC_IS_MONTH_VALID(month));
1094 CY_ASSERT_L2(CY_RTC_IS_YEAR_LONG_VALID(year));
1095
1096 retVal = cy_RTC_daysInMonthTbl[month - 1UL];
1097
1098 if (CY_RTC_FEBRUARY == month)
1099 {
1100 if (Cy_RTC_IsLeapYear(year))
1101 {
1102 retVal++;
1103 }
1104 }
1105 return(retVal);
1106 }
1107
1108
1109 /*******************************************************************************
1110 * Function Name: Cy_RTC_SyncFromRtc
1111 ****************************************************************************//**
1112 *
1113 * The Synchronizer updates RTC values into AHB RTC user registers from the
1114 * actual RTC. By calling this function, the actual RTC register values is
1115 * copied to AHB user registers.
1116 *
1117 * \note Only after calling Cy_RTC_SyncFromRtc(), the RTC time values can be
1118 * read. After Cy_RTC_SyncFromRtc() calling the snapshot of the actual RTC
1119 * registers are copied to the user registers. Meanwhile the RTC continues to
1120 * clock.
1121 *
1122 *******************************************************************************/
Cy_RTC_SyncFromRtc(void)1123 __STATIC_INLINE void Cy_RTC_SyncFromRtc(void)
1124 {
1125 uint32_t interruptState;
1126 uint32_t rtcAccessRetry = CY_RTC_ACCESS_BUSY_RETRY_COUNT;
1127
1128 interruptState = Cy_SysLib_EnterCriticalSection();
1129
1130 /* RTC Write is possible only in the condition that CY_RTC_BUSY bit = 0
1131 * or RTC Write bit is not set.
1132 */
1133 while((Cy_RTC_GetSyncStatus() == CY_RTC_BUSY) && (rtcAccessRetry != 0U))
1134 {
1135 rtcAccessRetry--;
1136 Cy_SysLib_DelayUs(CY_RTC_BUSY_RETRY_DELAY_US);
1137 }
1138
1139 if ((rtcAccessRetry != 0U) && (!_FLD2BOOL(BACKUP_RTC_RW_WRITE, BACKUP_RTC_RW)))
1140 {
1141 /* Setting RTC Read bit */
1142 BACKUP_RTC_RW = BACKUP_RTC_RW_READ_Msk;
1143
1144 /* Delay to guarantee RTC data reading */
1145 Cy_SysLib_DelayUs((uint16_t)CY_RTC_DELAY_WHILE_READING_US);
1146
1147 /* Clearing RTC Read bit */
1148 BACKUP_RTC_RW = 0U;
1149 }
1150 Cy_SysLib_ExitCriticalSection(interruptState);
1151 }
1152
1153
1154 /*******************************************************************************
1155 * Function Name: Cy_RTC_WriteEnable
1156 ****************************************************************************//**
1157 *
1158 * Set/Clear writeable option for RTC user registers. When the Write bit is set,
1159 * data can be written into the RTC user registers. After all the RTC writes are
1160 * done, the firmware must clear (call Cy_RTC_WriteEnable(RTC_WRITE_DISABLED))
1161 * the Write bit for the RTC update to take effect.
1162 *
1163 * Set/Clear cannot be done if the RTC is still busy with a previous update
1164 * (CY_RTC_BUSY = 1) or RTC Reading is executing.
1165 *
1166 * \param writeEnable
1167 * Write status, see \ref cy_en_rtc_write_status_t.
1168 *
1169 * \return
1170 * CY_RTC_SUCCESS - Set/Clear Write bit was successful.
1171 * CY_RTC_INVALID_STATE - RTC is busy with a previous update.
1172 * See \ref cy_en_rtc_status_t.
1173 *
1174 *******************************************************************************/
Cy_RTC_WriteEnable(cy_en_rtc_write_status_t writeEnable)1175 __STATIC_INLINE cy_en_rtc_status_t Cy_RTC_WriteEnable(cy_en_rtc_write_status_t writeEnable)
1176 {
1177 cy_en_rtc_status_t retVal = CY_RTC_INVALID_STATE;
1178 uint32_t rtcAccessRetry = CY_RTC_ACCESS_BUSY_RETRY_COUNT;
1179
1180 CY_ASSERT_L3(CY_RTC_IS_WRITE_VALID(writeEnable));
1181
1182 if (writeEnable == CY_RTC_WRITE_ENABLED)
1183 {
1184 /* RTC Write bit set is possible only in condition that CY_RTC_BUSY bit = 0
1185 * or RTC Read bit is not set
1186 */
1187 while((Cy_RTC_GetSyncStatus() == CY_RTC_BUSY) && (rtcAccessRetry != 0U))
1188 {
1189 rtcAccessRetry--;
1190 Cy_SysLib_DelayUs(CY_RTC_BUSY_RETRY_DELAY_US);
1191 }
1192
1193 if((rtcAccessRetry != 0U) && (!_FLD2BOOL(BACKUP_RTC_RW_READ, BACKUP_RTC_RW)))
1194 {
1195 BACKUP_RTC_RW |= BACKUP_RTC_RW_WRITE_Msk;
1196 retVal = CY_RTC_SUCCESS;
1197 }
1198 }
1199 else
1200 {
1201 /* Clearing Write Bit to complete write procedure */
1202 BACKUP_RTC_RW &= ((uint32_t) ~BACKUP_RTC_RW_WRITE_Msk);
1203
1204 retVal = CY_RTC_SUCCESS;
1205 }
1206
1207 return(retVal);
1208 }
1209
1210
1211 /*******************************************************************************
1212 * Function Name: Cy_RTC_GetSyncStatus
1213 ****************************************************************************//**
1214 *
1215 * Return current status of CY_RTC_BUSY. The status indicates
1216 * synchronization between the RTC user register and the actual RTC register.
1217 * CY_RTC_BUSY bit is set if it is synchronizing. It is not possible to set
1218 * the Read or Write bit until CY_RTC_BUSY clears.
1219 *
1220 * \return
1221 * The status of RTC user register synchronization. See
1222 * \ref group_rtc_busy_status
1223 *
1224 *******************************************************************************/
Cy_RTC_GetSyncStatus(void)1225 __STATIC_INLINE uint32_t Cy_RTC_GetSyncStatus(void)
1226 {
1227 return((_FLD2BOOL(BACKUP_STATUS_RTC_BUSY, BACKUP_STATUS)) ? CY_RTC_BUSY : CY_RTC_AVAILABLE);
1228 }
1229
1230
1231 /*******************************************************************************
1232 * Function Name: Cy_RTC_GetHoursFormat
1233 ****************************************************************************//**
1234 *
1235 * Returns current 12/24 hours format.
1236 *
1237 * \note
1238 * Before getting the RTC current hours format, the Cy_RTC_SyncFromRtc() function
1239 * should be called.
1240 *
1241 * \return
1242 * The current RTC hours format. See \ref cy_en_rtc_hours_format_t.
1243 *
1244 *******************************************************************************/
Cy_RTC_GetHoursFormat(void)1245 __STATIC_INLINE cy_en_rtc_hours_format_t Cy_RTC_GetHoursFormat(void)
1246 {
1247 return((_FLD2BOOL(BACKUP_RTC_TIME_CTRL_12HR, BACKUP_RTC_TIME)) ? CY_RTC_12_HOURS : CY_RTC_24_HOURS);
1248 }
1249
1250
1251 /*******************************************************************************
1252 * Function Name: Cy_RTC_IsExternalResetOccurred
1253 ****************************************************************************//**
1254 *
1255 * The function checks the reset cause and returns the Boolean result.
1256 *
1257 * \return
1258 * True if the reset reason is the power cycle and the XRES (external reset).
1259 * False if the reset reason is other than power cycle and the XRES.
1260 *
1261 * \note Based on a return value the RTC time and date can be updated or skipped
1262 * after the device reset. For example, you should skip the
1263 * Cy_RTC_SetAlarmDateAndTime() call function if internal WDT reset occurs.
1264 *
1265 *******************************************************************************/
Cy_RTC_IsExternalResetOccurred(void)1266 __STATIC_INLINE bool Cy_RTC_IsExternalResetOccurred(void)
1267 {
1268 #if (defined (CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION >= 2))
1269 return(0u != ((CY_SYSLIB_RESET_XRES | CY_SYSLIB_RESET_PORVDDD) & Cy_SysLib_GetResetReason()));
1270 #else
1271 return(0u == Cy_SysLib_GetResetReason());
1272 #endif
1273 }
1274
1275
1276 /*******************************************************************************
1277 * Function Name: Cy_RTC_SyncToRtcAhbDateAndTime
1278 ****************************************************************************//**
1279 *
1280 * This function updates new time and date into the time and date RTC AHB
1281 * registers.
1282 *
1283 * \param timeBcd
1284 * The BCD-formatted time variable which has the same bit masks as the
1285 * RTC_TIME register:
1286 *
1287 * [0:6] - Calendar seconds in BCD, the range 0-59. \n
1288 * [14:8] - Calendar minutes in BCD, the range 0-59. \n
1289 * [21:16] - Calendar hours in BCD, value depends on the 12/24-hour mode. \n
1290 * 12HR: [21]:0 = AM, 1 = PM, [20:16] = 1 - 12; \n
1291 * 24HR: [21:16] = 0-23. \n
1292 * [22] - Selects the 12/24-hour mode: 1 - 12-hour, 0 - 24-hour. \n
1293 * [26:24] - A calendar day of the week, the range 1 - 7, where 1 - Sunday. \n
1294 *
1295 * \param dateBcd
1296 * The BCD-formatted time variable which has the same bit masks as the
1297 * RTC_DATE register:
1298 *
1299 * [5:0] - A calendar day of a month in BCD, the range 1-31. \n
1300 * [12:8] - A calendar month in BCD, the range 1-12. \n
1301 * [23:16] - A calendar year in BCD, the range 0-99. \n
1302 *
1303 * \note Ensure that the parameters are presented in the BCD format. Use the
1304 * ConstructTimeDate() function to construct BCD time and date values.
1305 * Refer to ConstructTimeDate() function description for more details
1306 * about the RTC_TIME and RTC_DATE bit fields format.
1307 *
1308 * The RTC AHB registers can be updated only under condition that the
1309 * Write bit is set and the RTC busy bit is cleared (RTC_BUSY = 0). Call the
1310 * Cy_RTC_WriteEnable(CY_RTC_WRITE_ENABLED) and ensure that Cy_RTC_WriteEnable()
1311 * returned CY_RTC_SUCCESS. Then you can call Cy_RTC_SyncToRtcAhbDateAndTime().
1312 * Do not forget to clear the RTC Write bit to finish an RTC register update by
1313 * calling Cy_RTC_WriteEnable(CY_RTC_WRITE_DISABLED) after you executed
1314 * Cy_RTC_SyncToRtcAhbDateAndTime(). Ensure that Cy_RTC_WriteEnable()
1315 * returned CY_RTC_SUCCESS.
1316 *
1317 *******************************************************************************/
Cy_RTC_SyncToRtcAhbDateAndTime(uint32_t timeBcd,uint32_t dateBcd)1318 __STATIC_INLINE void Cy_RTC_SyncToRtcAhbDateAndTime(uint32_t timeBcd, uint32_t dateBcd)
1319 {
1320 BACKUP_RTC_TIME = timeBcd;
1321 BACKUP_RTC_DATE = dateBcd;
1322 }
1323
1324
1325 /*******************************************************************************
1326 * Function Name: Cy_RTC_SyncToRtcAhbAlarm
1327 ****************************************************************************//**
1328 *
1329 * This function updates new alarm time and date into the alarm tire and date
1330 * RTC AHB registers.
1331 *
1332 * \param alarmTimeBcd
1333 * The BCD-formatted time variable which has the same bit masks as the
1334 * ALMx_TIME register time fields:
1335 *
1336 * [0:6] - Alarm seconds in BCD, the range 0-59. \n
1337 * [7] - Alarm seconds Enable: 0 - ignore, 1 - match. \n
1338 * [14:8] - Alarm minutes in BCD, the range 0-59. \n
1339 * [15] - Alarm minutes Enable: 0 - ignore, 1 - match. \n
1340 * [21:16] - Alarm hours in BCD, value depending on the 12/24-hour mode
1341 * (RTC_CTRL_12HR)\n
1342 * 12HR: [21]:0 = AM, 1 = PM, [20:16] = 1 - 12; \n
1343 * 24HR: [21:16] = the range 0-23. \n
1344 * [23] - Alarm hours Enable: 0 - ignore, 1 - match. \n
1345 * [26:24] - An alarm day of the week, the range 1 - 7, where 1 - Monday. \n
1346 * [31] - An alarm day of the week Enable: 0 - ignore, 1 - match. \n
1347 *
1348 * \param alarmDateBcd
1349 * The BCD-formatted date variable which has the same bit masks as the
1350 * ALMx_DATE register date fields: \n
1351 * [5:0] - An alarm day of a month in BCD, the range 1-31. \n
1352 * [7] - An alarm day of a month Enable: 0 - ignore, 1 - match. \n
1353 * [12:8] - An alarm month in BCD, the range 1-12. \n
1354 * [15] - An alarm month Enable: 0 - ignore, 1 - match. \n
1355 * [31] - The Enable alarm: 0 - Alarm is disabled, 1 - Alarm is enabled. \n
1356 *
1357 * \param alarmIndex
1358 * The alarm index to be configured, see \ref cy_en_rtc_alarm_t.
1359 *
1360 * \note Ensure that the parameters are presented in the BCD format. Use the
1361 * ConstructTimeDate() function to construct BCD time and date values.
1362 * Refer to ConstructTimeDate() function description for more details
1363 * about the RTC ALMx_TIME and ALMx_DATE bit-fields format.
1364 *
1365 * The RTC AHB registers can be updated only under condition that the
1366 * Write bit is set and the RTC busy bit is cleared (RTC_BUSY = 0). Call the
1367 * Cy_RTC_WriteEnable(CY_RTC_WRITE_ENABLED) and ensure that Cy_RTC_WriteEnable()
1368 * returned CY_RTC_SUCCESS. Then you can call Cy_RTC_SyncToRtcAhbDateAndTime().
1369 * Do not forget to clear the RTC Write bit to finish an RTC register update by
1370 * calling the Cy_RTC_WriteEnable(CY_RTC_WRITE_DISABLED) after you executed
1371 * Cy_RTC_SyncToRtcAhbDateAndTime(). Ensure that Cy_RTC_WriteEnable()
1372 * returned CY_RTC_SUCCESS.
1373 *
1374 *******************************************************************************/
Cy_RTC_SyncToRtcAhbAlarm(uint32_t alarmTimeBcd,uint32_t alarmDateBcd,cy_en_rtc_alarm_t alarmIndex)1375 __STATIC_INLINE void Cy_RTC_SyncToRtcAhbAlarm(uint32_t alarmTimeBcd, uint32_t alarmDateBcd, cy_en_rtc_alarm_t alarmIndex)
1376 {
1377 CY_ASSERT_L3(CY_RTC_IS_ALARM_IDX_VALID(alarmIndex));
1378
1379 if (alarmIndex != CY_RTC_ALARM_2)
1380 {
1381 BACKUP_ALM1_TIME = alarmTimeBcd;
1382 BACKUP_ALM1_DATE = alarmDateBcd;
1383 }
1384 else
1385 {
1386 BACKUP_ALM2_TIME = alarmTimeBcd;
1387 BACKUP_ALM2_DATE = alarmDateBcd;
1388 }
1389 }
1390
1391 /** \} group_rtc_low_level_functions */
1392 /** \} group_rtc */
1393
1394 /*******************************************************************************
1395 * Internal Functions
1396 *******************************************************************************/
1397
1398 __STATIC_INLINE uint32_t Cy_RTC_ConvertBcdToDec(uint32_t bcdNum);
1399 __STATIC_INLINE uint32_t Cy_RTC_ConvertDecToBcd(uint32_t decNum);
1400
1401 /*******************************************************************************
1402 * Function Name: Cy_RTC_ConvertBcdToDec
1403 ****************************************************************************//**
1404 *
1405 * Converts an 8-bit BCD number into an 8-bit hexadecimal number. Each byte is
1406 * converted individually and returned as an individual byte in the 32-bit
1407 * variable.
1408 *
1409 * \param
1410 * bcdNum An 8-bit BCD number. Each byte represents BCD.
1411 *
1412 * \return
1413 * decNum An 8-bit hexadecimal equivalent number of the BCD number.
1414 *
1415 * For example, for 0x11223344 BCD number, the function returns
1416 * 0x2C in hexadecimal format.
1417 *
1418 * \note
1419 * This API is available for CAT1A devices.
1420 *
1421 *******************************************************************************/
Cy_RTC_ConvertBcdToDec(uint32_t bcdNum)1422 __STATIC_INLINE uint32_t Cy_RTC_ConvertBcdToDec(uint32_t bcdNum)
1423 {
1424 uint32_t retVal;
1425
1426 retVal =
1427 ((bcdNum & (CY_RTC_BCD_ONE_DIGIT_MASK << CY_RTC_BCD_NUMBER_SIZE))
1428 >> CY_RTC_BCD_NUMBER_SIZE ) * CY_RTC_BCD_DOZED_DEGREE;
1429
1430 retVal += bcdNum & CY_RTC_BCD_ONE_DIGIT_MASK;
1431
1432 return (retVal);
1433 }
1434
1435
1436 /*******************************************************************************
1437 * Function Name: Cy_RTC_ConvertDecToBcd
1438 ****************************************************************************//**
1439 *
1440 * Converts an 8-bit hexadecimal number into an 8-bit BCD number. Each byte
1441 * is converted individually and returned as an individual byte in the 32-bit
1442 * variable.
1443 *
1444 * \param
1445 * decNum An 8-bit hexadecimal number. Each byte is represented in hex.
1446 * 0x11223344 -> 0x20 hex format.
1447 *
1448 * \return
1449 * An 8-bit BCD equivalent of the passed hexadecimal number.
1450 *
1451 * For example, for 0x11223344 hexadecimal number, the function returns
1452 * 0x20 BCD number.
1453 *
1454 * \note
1455 * This API is available for CAT1A devices.
1456 *
1457 *******************************************************************************/
Cy_RTC_ConvertDecToBcd(uint32_t decNum)1458 __STATIC_INLINE uint32_t Cy_RTC_ConvertDecToBcd(uint32_t decNum)
1459 {
1460 uint32_t retVal;
1461 uint32_t tmpVal;
1462
1463 tmpVal = decNum % CY_RTC_BCD_HUNDRED_DEGRE;
1464 retVal = ((uint32_t)(tmpVal / CY_RTC_BCD_DOZED_DEGREE)) << CY_RTC_BCD_NUMBER_SIZE;
1465 retVal += tmpVal % CY_RTC_BCD_DOZED_DEGREE;
1466
1467 return (retVal);
1468 }
1469
1470 #if defined(__cplusplus)
1471 }
1472 #endif
1473
1474 #endif /* CY_IP_MXS40SRSS_RTC, CY_IP_MXS28SRSS, CY_IP_MXS40SSRSS. CY_IP_MXS22SRSS */
1475
1476 #endif /* CY_RTC_H */
1477
1478 /* [] END OF FILE */
1479