Low-Level

group group_rtc_low_level_functions

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.

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.

Return

Returns a day of the week, see Day of the week definitions.

Parameters
  • day: The day of the month, Valid range 1..31.

  • month: The month of the year, see Month definitions.

  • year: The year value. Valid range non-zero value.

__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.

Return

False - The year is not leap. True - The year is leap.

Parameters
  • year: The year to be checked. Valid range non-zero value.

__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.

Return

A number of days in a month in the year passed through the parameters.

Parameters
  • month: The month of the year, see Month definitions.

  • year: A year value. Valid range non-zero value.

__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.

__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.

Return

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.

Parameters

__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.

Return

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

__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.

Return

The current RTC hours format. See cy_en_rtc_hours_format_t.

__STATIC_INLINE bool Cy_RTC_IsExternalResetOccurred (void)

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

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.

Return

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.

__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.

[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.

[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.
Parameters
  • timeBcd: The BCD-formatted time variable which has the same bit masks as the RTC_TIME register:

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

__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.

[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.

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.
Parameters
  • alarmTimeBcd: The BCD-formatted time variable which has the same bit masks as the ALMx_TIME register time fields:

Parameters
  • alarmDateBcd: The 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.

  • alarmIndex: The alarm index to be configured, see cy_en_rtc_alarm_t.

__STATIC_INLINE uint32_t Cy_RTC_ConvertBcdToDec (uint32_t bcdNum)

Converts an 8-bit BCD number into an 8-bit hexadecimal number.

Each byte is converted individually and returned as an individual byte in the 32-bit variable.

For example, for 0x11223344 BCD number, the function returns 0x2C in hexadecimal format.

Return

decNum An 8-bit hexadecimal equivalent number of the BCD number.

Parameters
  • bcdNum: An 8-bit BCD number. Each byte represents BCD.

note

This API is available for CAT1A devices.

__STATIC_INLINE uint32_t Cy_RTC_ConvertDecToBcd (uint32_t decNum)

Converts an 8-bit hexadecimal number into an 8-bit BCD number.

Each byte is converted individually and returned as an individual byte in the 32-bit variable.

For example, for 0x11223344 hexadecimal number, the function returns 0x20 BCD number.

Return

An 8-bit BCD equivalent of the passed hexadecimal number.

Parameters
  • decNum: An 8-bit hexadecimal number. Each byte is represented in hex. 0x11223344 -> 0x20 hex format.

note

This API is available for CAT1A devices.