The Real-Time Clock (RTC) driver provides an application interface for keeping track of time and date.
The functions and other declarations used in this driver are in cy_rtc.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.
Use the RTC driver when the system requires the current time or date. You can also use the RTC when you do not need the current time and date but you do need accurate timing of events with one-second resolution.
The RTC driver provides these features:
The RTC driver provides access to the HW real-time clock. The HW RTC is located in the Backup domain. You need to choose the clock source for the Backup domain using the Cy_SysClk_ClkBakSetSource() function. If the clock for the Backup domain is set and enabled, the RTC automatically starts counting.
The RTC driver keeps track of second, minute, hour, day of the week, day of the month, month, and year.
DST may be enabled and supports any start and end date. The start and end dates can be a fixed date (like 24 March) or a relative date (like the second Sunday in March).
The RTC has two alarms that you can configure to generate an interrupt. You specify the match value for the time when you want the alarm to occur. Your interrupt handler then handles the response. The alarm flexibility supports periodic alarms (such as every minute), or a single alarm (13:45 on 28 September, 2043).
Clock Source
The Backup domain can be driven by:
The WCO is the recommended clock source for the RTC, if it is present in design. For setting the Backup domain clock source, refer to the SysClk (System Clock) driver.
Before RTC set up, ensure that the Backup domain is clocked with the desired clock source.
To set up an RTC, provide the configuration parameters in the cy_stc_rtc_config_t structure. Then call Cy_RTC_Init(). You can also set the date and time at runtime. Call Cy_RTC_SetDateAndTime() using the filled cy_stc_rtc_config_t structure, or call Cy_RTC_SetDateAndTimeDirect() with valid time and date values.
RTC Interrupt Handling
The RTC driver provides three interrupt handler functions: Cy_RTC_Alarm1Interrupt(), Cy_RTC_Alarm2Interrupt(), and Cy_RTC_CenturyInterrupt(). All three functions are blank functions with the WEAK attribute. For any interrupt you use, redefine the interrupt handler in your source code.
When an interrupt occurs, call the Cy_RTC_Interrupt() function. The RTC hardware provides a single interrupt line to the NVIC for the three RTC interrupts. This function checks the interrupt register to determine which interrupt (out of the three) was generated. It then calls the appropriate handler.
For RTC interrupt handling, the user should:
Alarm functionality
To set up an alarm, enable the required RTC interrupt. Then provide the configuration parameters in the cy_stc_rtc_alarm_t structure. You enable any item you want matched, and provide a match value. You disable any other. You do not need to set match values for disabled elements, as they are ignored.
An example is the best way to explain how this works. If you want an alarm on every hour, then in the cy_stc_rtc_alarm_t structure, you provide these values:
Alarm_1.sec = 0u
Alarm_1.secEn = CY_RTC_ALARM_ENABLE
Alarm_1.min = 0u
Alarm_1.minEn = CY_RTC_ALARM_ENABLE
Alarm_1.hourEn = CY_RTC_ALARM_DISABLE
Alarm_1.dayOfWeekEn = CY_RTC_ALARM_DISABLE
Alarm_1.dateEn = CY_RTC_ALARM_DISABLE
Alarm_1.monthEn = CY_RTC_ALARM_DISABLE
Alarm_1.almEn = CY_RTC_ALARM_ENABLE
With this setup, every time both the second and minute are zero, Alarm1 is asserted. That happens once per hour. Note that, counterintuitively, to have an alarm every hour, Alarm_1.hourEn is disabled. This is disabled because for an hourly alarm you do not match the value of the hour.
After cy_stc_rtc_alarm_t structure is filled, call the Cy_RTC_SetAlarmDateAndTime(). The alarm can also be set without using the cy_stc_rtc_alarm_t structure. Call Cy_RTC_SetAlarmDateAndTimeDirect() with valid values.
The DST Feature
The DST feature is managed by the PDL using the RTC Alarm2 interrupt. Therefore, you cannot have both DST enabled and use the Alarm2 interrupt.
To set up the DST, route the RTC interrupt to NVIC:
After this, provide the configuration parameters in the cy_stc_rtc_dst_t structure. This structure consists of two cy_stc_rtc_dst_format_t structures, one for DST Start time and one for DST Stop time. You also specify whether these times are absolute or relative.
After the cy_stc_rtc_dst_t structure is filled, call Cy_RTC_EnableDstTime()
The RTC provides the callback functions to facilitate the low-power mode transition. The callback Cy_RTC_DeepSleepCallback must be called during execution of Cy_SysPm_CpuEnterDeepSleep, Cy_RTC_HibernateCallback must be called during execution of Cy_SysPm_SystemEnterHibernate. To trigger the callback execution, the callback must be registered before calling the mode transition function. Refer to SysPm (System Power Management) driver for more information about low-power mode transitions.
For more information on the RTC peripheral, refer to the technical reference manual (TRM).
Version | Changes | Reason for Change |
---|---|---|
2.90 | Updated API Cy_RTC_GetInterruptStatus. | Code enhancement. |
2.80 | Added support for TRAVEO™ II Body Entry devices. Pre-processor check for MXS40SRSS version now groups ver. 2 with ver. 3. Previously ver. 2 was grouped with ver. 1. Cleaned up redundant and overlapping conditions in pre-processor directives. | Code enhancement and support for new devices. |
2.70 | Enhanced API's : Cy_RTC_SetDateAndTime(), Cy_RTC_SetDateAndTimeDirect(), Cy_RTC_SetAlarmDateAndTime(), Cy_RTC_SetAlarmDateAndTimeDirect(). | Minor Enhancements to the Driver. |
2.60 | CAT1B, CAT1C, CAT1D devices support. Newly added API's Cy_RTC_WriteEnable() to Set/Clear writeable option for RTC user registers, Cy_RTC_EnableDstTime() to set the DST time and configure the ALARM2 interrupt register with the appropriate DST time, Cy_RTC_DstInterrupt() to handle the DST event. Added a delay in Cy_RTC_SyncFromRtc() to check the RTC busy status. | Support for new devices. |
2.50 | Removed the calls that convert among BCD and Binary. | RTC encoding changed from BCD to Binary. |
2.40 | Fixed/Documented MISRA 2012 violations. | MISRA 2012 compliance. |
2.30.1 | Minor documentation updates. | Documentation enhancement. |
2.30 |
|
|
2.20.1 | Modified header guard CY_IP_MXS40SRSS_RTC. | To enable the PDL compilation with wounded out IP blocks. |
2.20 | Flattened the organization of the driver source code into the single source directory and the single include directory. | Driver library directory-structure simplification. |
Added register access layer. Use register access macros instead of direct register access using dereferenced pointers. | Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number. | |
Documentation update. | Documentation enhancement. | |
2.10 |
|
|
2.0 | Enhancement and defect fixes:
| |
1.0 | Initial version |
API Reference | |
Macros | |
Functions | |
Data Structures | |
Enumerated Types | |