RZT Flexible Software Package Documentation  Release v2.2.0

 
Real Time Clock (r_rtc)

Functions

fsp_err_t R_RTC_Open (rtc_ctrl_t *const p_ctrl, rtc_cfg_t const *const p_cfg)
 
fsp_err_t R_RTC_Close (rtc_ctrl_t *const p_ctrl)
 
fsp_err_t R_RTC_ClockSourceSet (rtc_ctrl_t *const p_ctrl)
 
fsp_err_t R_RTC_CalendarTimeSet (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time)
 
fsp_err_t R_RTC_CalendarTimeGet (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time)
 
fsp_err_t R_RTC_CalendarAlarmSet (rtc_ctrl_t *const p_ctrl, rtc_alarm_time_t *const p_alarm)
 
fsp_err_t R_RTC_CalendarAlarmGet (rtc_ctrl_t *const p_ctrl, rtc_alarm_time_t *const p_alarm)
 
fsp_err_t R_RTC_PeriodicIrqRateSet (rtc_ctrl_t *const p_ctrl, rtc_periodic_irq_select_t const rate)
 
fsp_err_t R_RTC_ErrorAdjustmentSet (rtc_ctrl_t *const p_ctrl, rtc_error_adjustment_cfg_t const *const err_adj_cfg)
 
fsp_err_t R_RTC_InfoGet (rtc_ctrl_t *const p_ctrl, rtc_info_t *const p_rtc_info)
 
fsp_err_t R_RTC_CallbackSet (rtc_ctrl_t *const p_ctrl, void(*p_callback)(rtc_callback_args_t *), void const *const p_context, rtc_callback_args_t *const p_callback_memory)
 
fsp_err_t R_RTC_TimeCaptureSet (rtc_ctrl_t *const p_ctrl, rtc_time_capture_t *const p_time_capture)
 
fsp_err_t R_RTC_TimeCaptureGet (rtc_ctrl_t *const p_ctrl, rtc_time_capture_t *const p_time_capture)
 

Detailed Description

Driver for the RTC peripheral on RZ microprocessor. This module implements the RTC Interface.

Overview

The RTC HAL module configures the RTC module and controls clock, calendar and alarm functions. A callback can be used to respond to the alarm and periodic interrupt.

Features

The RTC HAL module supports two different interrupt types:

A user-defined callback function can be registered (in the rtc_api_t::open API call) and will be called from the interrupt service routine (ISR) for alarm and periodic interrupt. When called, it is passed a pointer to a structure (rtc_callback_args_t) that holds a user-defined context pointer and an indication of which type of interrupt was fired.

Date and Time validation

"Parameter Checking" needs to be enabled if date and time validation is required for calendarTimeSet and calendarAlarmSet APIs. If "Parameter Checking" is enabled when using the calendarTimeSet API, the 'day of the week' field is automatically calculated and updated by the driver for the provided date.

Configuration

Build Time Configurations for r_rtc

The following build time configurations are defined in fsp_cfg/r_rtc_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
Multiplex Interrupt
  • Enabled
  • Disabled
Disabled Enable multiplex interrupt for a single driver.

Configurations for Timers > Realtime Clock (r_rtc)

This module can be added to the Stacks tab via New Stack > Timers > Realtime Clock (r_rtc).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_rtc0 Module name.
Frequency Comparison Value
  • 195311
  • 195312
195311 Frequency comparison value. This value is set in the register as it is.
CallbackName must be a valid C symbolNULL A user callback function can be provided. If this callback function is provided, it will be called from the interrupt service routine (ISR).
Alarm Interrupt PriorityMCU Specific OptionsSelect the alarm interrupt priority.
Period Interrupt PriorityMCU Specific OptionsSelect the period interrupt priority.

Note
See section "RTCA0SCMP : RTC Sub Count Compare Register" of the RZ microprocessor manual for more details

Interrupt Configuration

To activate interrupts for the RTC module, the desired interrupts must be enabled, The underlying implementation will be expected to handle any interrupts it can support and notify higher layers via callback.

Clock Configuration

The RTC HAL module uses the following clock sources:

Pin Configuration

This module does not use I/O pins.

Usage Notes

System Initialization

rtc_alarm_time_t when Setting Calendar Alarm

rtc_alarm_time_t when Getting Calendar Alarm

Examples

RTC Basic Example

This is a basic example of minimal use of the RTC in an application.

/* rtc_time_t is an alias for the C Standard time.h struct 'tm' */
rtc_time_t set_time =
{
.tm_sec = 10,
.tm_min = 11,
.tm_hour = 12,
.tm_mday = 6,
.tm_wday = 5,
.tm_mon = 11,
.tm_year = YEARS_SINCE_1900,
};
rtc_time_t get_time;
void rtc_example ()
{
fsp_err_t err = FSP_SUCCESS;
/* Initialize the RTC module */
err = R_RTC_Open(&g_rtc0_ctrl, &g_rtc0_cfg);
/* Handle any errors. This function should be defined by the user. */
handle_error(err);
/* Set the calendar time */
R_RTC_CalendarTimeSet(&g_rtc0_ctrl, &set_time);
/* Get the calendar time */
R_RTC_CalendarTimeGet(&g_rtc0_ctrl, &get_time);
}

RTC Periodic interrupt example

This is an example of periodic interrupt in RTC.

void rtc_periodic_irq_example ()
{
fsp_err_t err = FSP_SUCCESS;
/* Initialize the RTC module*/
err = R_RTC_Open(&g_rtc0_ctrl, &g_rtc0_cfg);
/* Handle any errors. This function should be defined by the user. */
handle_error(err);
/* R_RTC_CalendarTimeSet must be called at least once to start the RTC */
R_RTC_CalendarTimeSet(&g_rtc0_ctrl, &set_time);
/* Set the periodic interrupt rate to 1 second */
/* Wait for the periodic interrupt */
while (1)
{
/* Wait for interrupt */
}
}

RTC Alarm interrupt example

This is an example of alarm interrupt in RTC.

void rtc_alarm_irq_example ()
{
fsp_err_t err = FSP_SUCCESS;
/*Initialize the RTC module*/
err = R_RTC_Open(&g_rtc0_ctrl, &g_rtc0_cfg);
/* Handle any errors. This function should be defined by the user. */
handle_error(err);
R_RTC_CalendarTimeSet(&g_rtc0_ctrl, &set_time);
R_RTC_CalendarAlarmSet(&g_rtc0_ctrl, &set_time1);
/* Wait for the Alarm interrupt */
while (1)
{
/* Wait for interrupt */
}
}

Data Structures

struct  rtc_instance_ctrl_t
 

Data Structure Documentation

◆ rtc_instance_ctrl_t

struct rtc_instance_ctrl_t

Channel control block. DO NOT INITIALIZE. Initialization occurs when rtc_api_t::open is called

Data Fields

uint32_t open
 Whether or not driver is open.
 
const rtc_cfg_tp_cfg
 Pointer to initial configurations.
 

Function Documentation

◆ R_RTC_Open()

fsp_err_t R_RTC_Open ( rtc_ctrl_t *const  p_ctrl,
rtc_cfg_t const *const  p_cfg 
)

Opens and configures the RTC driver module. Implements rtc_api_t::open. Configuration includes clock source, and interrupt callback function.

Return values
FSP_SUCCESSInitialization was successful and RTC has started.
FSP_ERR_ASSERTIONInvalid p_ctrl or p_cfg pointer.
FSP_ERR_ALREADY_OPENModule is already open.
FSP_ERR_INVALID_ARGUMENTInvalid parameter.

◆ R_RTC_Close()

fsp_err_t R_RTC_Close ( rtc_ctrl_t *const  p_ctrl)

Close the RTC driver. Implements rtc_api_t::close

Return values
FSP_SUCCESSDe-Initialization was successful and RTC driver closed.
FSP_ERR_ASSERTIONInvalid p_ctrl.
FSP_ERR_NOT_OPENDriver not open already for close.

◆ R_RTC_ClockSourceSet()

fsp_err_t R_RTC_ClockSourceSet ( rtc_ctrl_t *const  p_ctrl)

rtc_api_t::clockSourceSet is not supported on the RTC.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_RTC_CalendarTimeSet()

fsp_err_t R_RTC_CalendarTimeSet ( rtc_ctrl_t *const  p_ctrl,
rtc_time_t *const  p_time 
)

Set the calendar time.

Implements rtc_api_t::calendarTimeSet.

Return values
FSP_SUCCESSCalendar time set operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.
FSP_ERR_INVALID_ARGUMENTInvalid time parameter field.

◆ R_RTC_CalendarTimeGet()

fsp_err_t R_RTC_CalendarTimeGet ( rtc_ctrl_t *const  p_ctrl,
rtc_time_t *const  p_time 
)

Get the calendar time.

Implements rtc_api_t::calendarTimeGet

Return values
FSP_SUCCESSCalendar time get operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_CalendarAlarmSet()

fsp_err_t R_RTC_CalendarAlarmSet ( rtc_ctrl_t *const  p_ctrl,
rtc_alarm_time_t *const  p_alarm 
)

Set the calendar alarm time.

Implements rtc_api_t::calendarAlarmSet.

Precondition
The calendar counter must be running before the alarm can be set.
Return values
FSP_SUCCESSCalendar alarm time set operation was successful.
FSP_ERR_INVALID_ARGUMENTInvalid time parameter field.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.
FSP_ERR_IRQ_BSP_DISABLEDUser IRQ parameter not valid

◆ R_RTC_CalendarAlarmGet()

fsp_err_t R_RTC_CalendarAlarmGet ( rtc_ctrl_t *const  p_ctrl,
rtc_alarm_time_t *const  p_alarm 
)

Get the calendar alarm time.

Implements rtc_api_t::calendarAlarmGet

Return values
FSP_SUCCESSCalendar alarm time get operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_PeriodicIrqRateSet()

fsp_err_t R_RTC_PeriodicIrqRateSet ( rtc_ctrl_t *const  p_ctrl,
rtc_periodic_irq_select_t const  rate 
)

Set the periodic interrupt rate and enable periodic interrupt.

Implements rtc_api_t::periodicIrqRateSet

Note
To start the RTC R_RTC_CalendarTimeSet must be called at least once.
Return values
FSP_SUCCESSThe periodic interrupt rate was successfully set.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.
FSP_ERR_IRQ_BSP_DISABLEDUser IRQ parameter not valid
FSP_ERR_INVALID_ARGUMENTInvalid periodic IRQ rate value

◆ R_RTC_ErrorAdjustmentSet()

fsp_err_t R_RTC_ErrorAdjustmentSet ( rtc_ctrl_t *const  p_ctrl,
rtc_error_adjustment_cfg_t const *const  err_adj_cfg 
)

rtc_api_t::errorAdjustmentSet is not supported on the RTC.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_RTC_InfoGet()

fsp_err_t R_RTC_InfoGet ( rtc_ctrl_t *const  p_ctrl,
rtc_info_t *const  p_rtc_info 
)

Get RTC clock source and running status information and store it in provided pointer p_rtc_info. Before or immediately after the first call to R_RTC_CalendarTimeSet, RTC_STATUS_STOPPED will be returned. Two PCLKRTC after the first call to R_RTC_CalendarTimeSet, RTC_STATUS_RUNNING will be returned.

Implements rtc_api_t::infoGet

Return values
FSP_SUCCESSGet information Successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_CallbackSet()

fsp_err_t R_RTC_CallbackSet ( rtc_ctrl_t *const  p_ctrl,
void(*)(rtc_callback_args_t *)  p_callback,
void const *const  p_context,
rtc_callback_args_t *const  p_callback_memory 
)

Updates the user callback and has option of providing memory for callback structure. Implements rtc_api_t::callbackSet

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened

◆ R_RTC_TimeCaptureSet()

fsp_err_t R_RTC_TimeCaptureSet ( rtc_ctrl_t *const  p_ctrl,
rtc_time_capture_t *const  p_time_capture 
)

rtc_api_t::timeCaptureSet is not supported on the RTC.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_RTC_TimeCaptureGet()

fsp_err_t R_RTC_TimeCaptureGet ( rtc_ctrl_t *const  p_ctrl,
rtc_time_capture_t *const  p_time_capture 
)

rtc_api_t::timeCaptureGet is not supported on the RTC.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.