MTB CAT1 Peripheral driver library

General Description

Functions

__STATIC_INLINE uint32_t Cy_RTC_ConvertDayOfWeek (uint32_t day, uint32_t month, uint32_t year)
 Returns a day of the week for a year, month, and day of month that are passed through parameters. More...
 
__STATIC_INLINE bool Cy_RTC_IsLeapYear (uint32_t year)
 Checks whether the year passed through the parameter is leap or not. More...
 
__STATIC_INLINE uint32_t Cy_RTC_DaysInMonth (uint32_t month, uint32_t year)
 Returns a number of days in a month passed through the parameters. More...
 
__STATIC_INLINE void Cy_RTC_SyncFromRtc (void)
 The Synchronizer updates RTC values into AHB RTC user registers from the actual RTC. More...
 
__STATIC_INLINE cy_en_rtc_status_t Cy_RTC_WriteEnable (cy_en_rtc_write_status_t writeEnable)
 Set/Clear writeable option for RTC user registers. More...
 
__STATIC_INLINE uint32_t Cy_RTC_GetSyncStatus (void)
 Return current status of CY_RTC_BUSY. More...
 
__STATIC_INLINE cy_en_rtc_hours_format_t Cy_RTC_GetHoursFormat (void)
 Returns current 12/24 hours format. More...
 
__STATIC_INLINE bool Cy_RTC_IsExternalResetOccurred (void)
 The function checks the reset cause and returns the Boolean result. More...
 
__STATIC_INLINE void Cy_RTC_SyncToRtcAhbDateAndTime (uint32_t timeBcd, uint32_t dateBcd)
 This function updates new time and date into the time and date RTC AHB registers. More...
 
__STATIC_INLINE void Cy_RTC_SyncToRtcAhbAlarm (uint32_t alarmTimeBcd, uint32_t alarmDateBcd, cy_en_rtc_alarm_t alarmIndex)
 This function updates new alarm time and date into the alarm tire and date RTC AHB registers. More...
 

Function Documentation

◆ Cy_RTC_ConvertDayOfWeek()

__STATIC_INLINE uint32_t Cy_RTC_ConvertDayOfWeek ( uint32_t  day,
uint32_t  month,
uint32_t  year 
)

Returns a day of the week for a year, month, and day of month that are passed through parameters.

Zeller's congruence is used to calculate the day of the week. RTC HW block does not provide the converting function for day of week. This function should be called before Cy_RTC_SetDateAndTime() to get the day of week.

For the Georgian calendar, Zeller's congruence is: h = (q + [13 * (m + 1)] + K + [K/4] + [J/4] - 2J) mod 7

h - The day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ., 6 = Friday). q - The day of the month. m - The month (3 = March, 4 = April, 5 = May, ..., 14 = February) K - The year of the century (year mod 100). J - The zero-based century (actually [year/100]) For example, the zero-based centuries for 1995 and 2000 are 19 and 20 respectively (not to be confused with the common ordinal century enumeration which indicates 20th for both cases).

Note
In this algorithm January and February are counted as months 13 and 14 of the previous year.
Parameters
dayThe day of the month, Valid range 1..31.
monthThe month of the year, see Month definitions.
yearThe year value. Valid range non-zero value.
Returns
Returns a day of the week, see Day of the week definitions.

◆ Cy_RTC_IsLeapYear()

__STATIC_INLINE bool Cy_RTC_IsLeapYear ( uint32_t  year)

Checks whether the year passed through the parameter is leap or not.

This API is for checking an invalid value input for leap year. RTC HW block does not provide a validation checker against time/date values, the valid range of days in Month should be checked before SetDateAndTime() function call. Leap year is identified as a year that is a multiple of 4 or 400 but not 100.

Parameters
yearThe year to be checked. Valid range non-zero value.
Returns
False - The year is not leap. True - The year is leap.

◆ Cy_RTC_DaysInMonth()

__STATIC_INLINE uint32_t Cy_RTC_DaysInMonth ( uint32_t  month,
uint32_t  year 
)

Returns a number of days in a month passed through the parameters.

This API is for checking an invalid value input for days. RTC HW block does not provide a validation checker against time/date values, the valid range of days in Month should be checked before SetDateAndTime() function call.

Parameters
monthThe month of the year, see Month definitions.
yearA year value. Valid range non-zero value.
Returns
A number of days in a month in the year passed through the parameters.

◆ Cy_RTC_SyncFromRtc()

__STATIC_INLINE void Cy_RTC_SyncFromRtc ( void  )

The Synchronizer updates RTC values into AHB RTC user registers from the actual RTC.

By calling this function, the actual RTC register values is copied to AHB user registers.

Note
Only after calling Cy_RTC_SyncFromRtc(), the RTC time values can be read. After Cy_RTC_SyncFromRtc() calling the snapshot of the actual RTC registers are copied to the user registers. Meanwhile the RTC continues to clock.

◆ Cy_RTC_WriteEnable()

__STATIC_INLINE cy_en_rtc_status_t Cy_RTC_WriteEnable ( cy_en_rtc_write_status_t  writeEnable)

Set/Clear writeable option for RTC user registers.

When the Write bit is set, data can be written into the RTC user registers. After all the RTC writes are done, the firmware must clear (call Cy_RTC_WriteEnable(RTC_WRITE_DISABLED)) the Write bit for the RTC update to take effect.

Set/Clear cannot be done if the RTC is still busy with a previous update (CY_RTC_BUSY = 1) or RTC Reading is executing.

Parameters
writeEnableWrite status, see cy_en_rtc_write_status_t.
Returns
CY_RTC_SUCCESS - Set/Clear Write bit was successful. CY_RTC_INVALID_STATE - RTC is busy with a previous update. See cy_en_rtc_status_t.

◆ Cy_RTC_GetSyncStatus()

__STATIC_INLINE uint32_t Cy_RTC_GetSyncStatus ( void  )

Return current status of CY_RTC_BUSY.

The status indicates synchronization between the RTC user register and the actual RTC register. CY_RTC_BUSY bit is set if it is synchronizing. It is not possible to set the Read or Write bit until CY_RTC_BUSY clears.

Returns
The status of RTC user register synchronization. See RTC Status definitions

◆ Cy_RTC_GetHoursFormat()

__STATIC_INLINE cy_en_rtc_hours_format_t Cy_RTC_GetHoursFormat ( void  )

Returns current 12/24 hours format.

Note
Before getting the RTC current hours format, the Cy_RTC_SyncFromRtc() function should be called.
Returns
The current RTC hours format. See cy_en_rtc_hours_format_t.

◆ Cy_RTC_IsExternalResetOccurred()

__STATIC_INLINE bool Cy_RTC_IsExternalResetOccurred ( void  )

The function checks the reset cause and returns the Boolean result.

Returns
True if the reset reason is the power cycle and the XRES (external reset). False if the reset reason is other than power cycle and the XRES.
Note
Based on a return value the RTC time and date can be updated or skipped after the device reset. For example, you should skip the Cy_RTC_SetAlarmDateAndTime() call function if internal WDT reset occurs.

◆ Cy_RTC_SyncToRtcAhbDateAndTime()

__STATIC_INLINE void Cy_RTC_SyncToRtcAhbDateAndTime ( uint32_t  timeBcd,
uint32_t  dateBcd 
)

This function updates new time and date into the time and date RTC AHB registers.

Parameters
timeBcdThe BCD-formatted time variable which has the same bit masks as the RTC_TIME register:

[0:6] - Calendar seconds in BCD, the range 0-59.
[14:8] - Calendar minutes in BCD, the range 0-59.
[21:16] - Calendar hours in BCD, value depends on the 12/24-hour mode.
12HR: [21]:0 = AM, 1 = PM, [20:16] = 1 - 12;
24HR: [21:16] = 0-23.
[22] - Selects the 12/24-hour mode: 1 - 12-hour, 0 - 24-hour.
[26:24] - A calendar day of the week, the range 1 - 7, where 1 - Sunday.

Parameters
dateBcdThe BCD-formatted time variable which has the same bit masks as the RTC_DATE register:

[5:0] - A calendar day of a month in BCD, the range 1-31.
[12:8] - A calendar month in BCD, the range 1-12.
[23:16] - A calendar year in BCD, the range 0-99.

Note
Ensure that the parameters are presented in the BCD format. Use the ConstructTimeDate() function to construct BCD time and date values. Refer to ConstructTimeDate() function description for more details about the RTC_TIME and RTC_DATE bit fields format.

The RTC AHB registers can be updated only under condition that the Write bit is set and the RTC busy bit is cleared (RTC_BUSY = 0). Call the Cy_RTC_WriteEnable(CY_RTC_WRITE_ENABLED) and ensure that Cy_RTC_WriteEnable() returned CY_RTC_SUCCESS. Then you can call Cy_RTC_SyncToRtcAhbDateAndTime(). Do not forget to clear the RTC Write bit to finish an RTC register update by calling Cy_RTC_WriteEnable(CY_RTC_WRITE_DISABLED) after you executed Cy_RTC_SyncToRtcAhbDateAndTime(). Ensure that Cy_RTC_WriteEnable() returned CY_RTC_SUCCESS.

◆ Cy_RTC_SyncToRtcAhbAlarm()

__STATIC_INLINE void Cy_RTC_SyncToRtcAhbAlarm ( uint32_t  alarmTimeBcd,
uint32_t  alarmDateBcd,
cy_en_rtc_alarm_t  alarmIndex 
)

This function updates new alarm time and date into the alarm tire and date RTC AHB registers.

Parameters
alarmTimeBcdThe BCD-formatted time variable which has the same bit masks as the ALMx_TIME register time fields:

[0:6] - Alarm seconds in BCD, the range 0-59.
[7] - Alarm seconds Enable: 0 - ignore, 1 - match.
[14:8] - Alarm minutes in BCD, the range 0-59.
[15] - Alarm minutes Enable: 0 - ignore, 1 - match.
[21:16] - Alarm hours in BCD, value depending on the 12/24-hour mode (RTC_CTRL_12HR)
12HR: [21]:0 = AM, 1 = PM, [20:16] = 1 - 12;
24HR: [21:16] = the range 0-23.
[23] - Alarm hours Enable: 0 - ignore, 1 - match.
[26:24] - An alarm day of the week, the range 1 - 7, where 1 - Monday.
[31] - An alarm day of the week Enable: 0 - ignore, 1 - match.

Parameters
alarmDateBcdThe BCD-formatted date variable which has the same bit masks as the ALMx_DATE register date fields:
[5:0] - An alarm day of a month in BCD, the range 1-31.
[7] - An alarm day of a month Enable: 0 - ignore, 1 - match.
[12:8] - An alarm month in BCD, the range 1-12.
[15] - An alarm month Enable: 0 - ignore, 1 - match.
[31] - The Enable alarm: 0 - Alarm is disabled, 1 - Alarm is enabled.
alarmIndexThe alarm index to be configured, see cy_en_rtc_alarm_t.
Note
Ensure that the parameters are presented in the BCD format. Use the ConstructTimeDate() function to construct BCD time and date values. Refer to ConstructTimeDate() function description for more details about the RTC ALMx_TIME and ALMx_DATE bit-fields format.

The RTC AHB registers can be updated only under condition that the Write bit is set and the RTC busy bit is cleared (RTC_BUSY = 0). Call the Cy_RTC_WriteEnable(CY_RTC_WRITE_ENABLED) and ensure that Cy_RTC_WriteEnable() returned CY_RTC_SUCCESS. Then you can call Cy_RTC_SyncToRtcAhbDateAndTime(). Do not forget to clear the RTC Write bit to finish an RTC register update by calling the Cy_RTC_WriteEnable(CY_RTC_WRITE_DISABLED) after you executed Cy_RTC_SyncToRtcAhbDateAndTime(). Ensure that Cy_RTC_WriteEnable() returned CY_RTC_SUCCESS.