PSoC 6 Hardware Abstraction Layer (HAL)
RTC (Real-Time Clock)

General Description

High level interface for interacting with the Cypress RTC.

The real time clock provides tracking of the current time and date, as well as the ability to trigger a callback at a specific time in the future.

If a suitable clock source is available, the RTC can continue timekeeping operations even when the device is in a low power operating mode. See the device datasheet for more details.

Data Structures

struct  cyhal_alarm_active_t
 Defines which fields should be active for the alarm. More...
 

Macros

#define CY_RSLT_RTC_NOT_INITIALIZED   CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_RTC, 0)
 

Typedefs

typedef void(* cyhal_rtc_event_callback_t) (void *callback_arg, cyhal_rtc_event_t event)
 

Enumerations

enum  cyhal_rtc_event_t { CYHAL_RTC_ALARM }
 

Functions

cy_rslt_t cyhal_rtc_init (cyhal_rtc_t *obj)
 
void cyhal_rtc_free (cyhal_rtc_t *obj)
 
bool cyhal_rtc_is_enabled (cyhal_rtc_t *obj)
 
cy_rslt_t cyhal_rtc_read (cyhal_rtc_t *obj, struct tm *time)
 
cy_rslt_t cyhal_rtc_write (cyhal_rtc_t *obj, const struct tm *time)
 
cy_rslt_t cyhal_rtc_set_alarm (cyhal_rtc_t *obj, const struct tm *time, cyhal_alarm_active_t active)
 
void cyhal_rtc_register_callback (cyhal_rtc_t *obj, cyhal_rtc_event_callback_t callback, void *callback_arg)
 
void cyhal_rtc_enable_event (cyhal_rtc_t *obj, cyhal_rtc_event_t event, uint8_t intrPriority, bool enable)
 

Data Structure Documentation

◆ cyhal_alarm_active_t

struct cyhal_alarm_active_t
Data Fields
uint8_t en_sec: 1
uint8_t en_min: 1

!< Enable match of seconds

uint8_t en_hour: 1

!< Enable match of minutes

uint8_t en_day: 1

!< Enable match of hours

uint8_t en_date: 1

!< Enable match of day of week

uint8_t en_month: 1

!< Enable match of date in month

Macro Definition Documentation

◆ CY_RSLT_RTC_NOT_INITIALIZED

#define CY_RSLT_RTC_NOT_INITIALIZED   CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CYHAL_RSLT_MODULE_RTC, 0)

RTC not initialized

Typedef Documentation

◆ cyhal_rtc_event_callback_t

typedef void(* cyhal_rtc_event_callback_t) (void *callback_arg, cyhal_rtc_event_t event)

Handler for RTC events

Enumeration Type Documentation

◆ cyhal_rtc_event_t

RTC interrupt triggers

Function Documentation

◆ cyhal_rtc_init()

cy_rslt_t cyhal_rtc_init ( cyhal_rtc_t *  obj)

Initialize the RTC peripheral

Powerup the RTC in preparation for access. This function must be called before any other RTC functions are called. This does not change the state of the RTC. It just enables access to it. NOTE: Before calling this, make sure all necessary System Clocks are setup correctly. Generally this means making sure the RTC has access to a Crystal for optimal accuracy and operation in low power.

Parameters
[out]objRTC object
Returns
The status of the init request

◆ cyhal_rtc_free()

void cyhal_rtc_free ( cyhal_rtc_t *  obj)

Deinitialize RTC

Frees resources associated with the RTC and disables CPU access. This only affects the CPU domain and not the time keeping logic. After this function is called no other RTC functions should be called except for rtc_init.

Parameters
[in,out]objRTC object

◆ cyhal_rtc_is_enabled()

bool cyhal_rtc_is_enabled ( cyhal_rtc_t *  obj)

Check if the RTC has the time set and is counting

Parameters
[in]objRTC object
Returns
Whether the RTC is enabled or not

◆ cyhal_rtc_read()

cy_rslt_t cyhal_rtc_read ( cyhal_rtc_t *  obj,
struct tm *  time 
)

Get the current time from the RTC peripheral

Parameters
[in]objRTC object
[out]timeThe current time (see: https://en.cppreference.com/w/cpp/chrono/c/tm)
Returns
The status of the read request

◆ cyhal_rtc_write()

cy_rslt_t cyhal_rtc_write ( cyhal_rtc_t *  obj,
const struct tm *  time 
)

Write the current time in seconds to the RTC peripheral

Parameters
[in]objRTC object
[in]timeThe time to be set (see: https://en.cppreference.com/w/cpp/chrono/c/tm)
Returns
The status of the write request

◆ cyhal_rtc_set_alarm()

cy_rslt_t cyhal_rtc_set_alarm ( cyhal_rtc_t *  obj,
const struct tm *  time,
cyhal_alarm_active_t  active 
)

Set an alarm for the specified time in seconds to the RTC peripheral

Parameters
[in]objRTC object
[in]timeThe alarm time to be set (see: https://en.cppreference.com/w/cpp/chrono/c/tm)
[in]activeThe set of fields that are checked to trigger the alarm
Returns
The status of the set_alarm request

◆ cyhal_rtc_register_callback()

void cyhal_rtc_register_callback ( cyhal_rtc_t *  obj,
cyhal_rtc_event_callback_t  callback,
void *  callback_arg 
)

The RTC event callback handler registration

Parameters
[in]objThe RTC object
[in]callbackThe callback handler which will be invoked when the alarm fires
[in]callback_argGeneric argument that will be provided to the callback when called

◆ cyhal_rtc_enable_event()

void cyhal_rtc_enable_event ( cyhal_rtc_t *  obj,
cyhal_rtc_event_t  event,
uint8_t  intrPriority,
bool  enable 
)

Configure RTC event enablement.

Parameters
[in]objThe RTC object
[in]eventThe RTC event type
[in]intrPriorityThe priority for NVIC interrupt events
[in]enableTrue to turn on interrupts, False to turn off