RAFW Flexible Software Package Documentation  Release v2.0.1

 
Realtime Clock (r_rtc_w)

Functions

fsp_err_t R_RTC_W_Open (rtc_ctrl_t *const p_ctrl, rtc_cfg_t const *const p_cfg)
 
fsp_err_t R_RTC_W_Close (rtc_ctrl_t *const p_ctrl)
 
fsp_err_t R_RTC_W_ClockSourceSet (rtc_ctrl_t *const p_ctrl)
 
fsp_err_t R_RTC_W_CalendarTimeSet (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time)
 
fsp_err_t R_RTC_W_CalendarTimeGet (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time)
 
fsp_err_t R_RTC_W_CalendarAlarmSet (rtc_ctrl_t *const p_ctrl, rtc_alarm_time_t *const p_alarm)
 
fsp_err_t R_RTC_W_CalendarAlarmGet (rtc_ctrl_t *const p_ctrl, rtc_alarm_time_t *const p_alarm)
 
fsp_err_t R_RTC_W_PeriodicIrqRateSet (rtc_ctrl_t *const p_ctrl, rtc_periodic_irq_select_t const rate)
 
fsp_err_t R_RTC_W_InfoGet (rtc_ctrl_t *const p_ctrl, rtc_info_t *const p_rtc_info)
 
fsp_err_t R_RTC_W_ErrorAdjustmentSet (rtc_ctrl_t *const p_ctrl, rtc_error_adjustment_cfg_t const *const err_adj_cfg)
 
fsp_err_t R_RTC_W_CallbackSet (rtc_ctrl_t *const p_ctrl, void(*p_callback)(rtc_callback_args_t *), void *const p_context, rtc_callback_args_t *const p_callback_memory)
 
fsp_err_t R_RTC_W_TimeCaptureSet (rtc_ctrl_t *const p_ctrl, rtc_time_capture_t *const p_time_capture)
 
fsp_err_t R_RTC_W_TimeCaptureGet (rtc_ctrl_t *const p_ctrl, rtc_time_capture_t *const p_time_capture)
 
fsp_err_t R_RTC_W_CalendarBootTimeGet (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time)
 
fsp_err_t R_RTC_W_CalendarTimeZoneSet (rtc_ctrl_t *const p_ctrl, long *p_timezone)
 
fsp_err_t R_RTC_W_CalendarTimeZoneGet (rtc_ctrl_t *const p_ctrl, long *p_timezone)
 
fsp_err_t R_RTC_W_CalendarGMTTimeGet (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time)
 
fsp_err_t R_RTC_W_CalendarTimePassed (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time, bool *p_comp)
 
fsp_err_t R_RTC_W_Time2Str (rtc_ctrl_t *const p_ctrl, rtc_time_t *const p_time, char *const str_buff_ptr, size_t maxsize, char const *format)
 
rtc_ctrl_tR_RTC_W_GetCtrl (void)
 

Detailed Description

Driver for the RTC peripheral on RAFW MCUs. This module implements the RTC Interface.

Overview

The RTC module controls clock and calendar functions.

Features

Date and Time validation

"Parameter Checking" needs to be enabled if date and time validation is required for module APIs.

Configuration

Build Time Configurations for r_rtc_w

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

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Clock Configuration

The RTC module use the following relative clock sources:

Pin Configuration

This module does not use I/O pins.

Usage Notes

System Initialization

Limitations

Developers should be aware of the following limitations when using the RTC:

Examples

RTC-W Basic Example

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

#include "r_rtc_w.h"
#define CURRENT_YEAR (2024)
#define YEARS_SINCE_1900 (CURRENT_YEAR - 1900)
rtc_w_instance_ctrl_t g_rtc_w_example_ctrl;
void rtc_w_example(void);
const rtc_extended_cfg_t rtc_w_cfg_extend =
{
.reserved = 0,
};
const rtc_cfg_t g_rtc0_cfg =
{
.p_extend = &rtc_w_cfg_extend,
};
/* 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 = 18,
.tm_wday = 4,
.tm_mon = 9,
.tm_year = YEARS_SINCE_1900,
};
rtc_time_t passed_time =
{
.tm_sec = 0,
.tm_min = 0,
.tm_hour = 6,
.tm_mday = 1,
.tm_wday = 1,
.tm_mon = 9,
.tm_year = YEARS_SINCE_1900,
};
rtc_time_t get_time;
void rtc_w_example (void)
{
fsp_err_t err = FSP_SUCCESS;
// [R_RTC_W_Open]
/* Handle any errors. This function should be defined by the user. */
assert(0 == err);
/* Open the RTC module */
err = R_RTC_W_Open(&g_rtc_w_example_ctrl, &g_rtc0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
// [R_RTC_W_CalendarTimeZoneSet]
/* Set timezone */
long int timezone_example = (2 * 3600);
err = R_RTC_W_CalendarTimeZoneSet(&g_rtc_w_example_ctrl, &timezone_example);
assert(FSP_SUCCESS == err);
// [R_RTC_W_CalendarTimeSet]
/* Set the calendar time */
err = R_RTC_W_CalendarTimeSet(&g_rtc_w_example_ctrl, &set_time);
assert(FSP_SUCCESS == err);
// [R_RTC_W_CalendarTimeGet]
/* Get the calendar time */
err = R_RTC_W_CalendarTimeGet(&g_rtc_w_example_ctrl, &get_time);
assert(FSP_SUCCESS == err);
/* Get timezone */
long get_timezone;
err = R_RTC_W_CalendarTimeZoneGet(&g_rtc_w_example_ctrl, &get_timezone);
assert(FSP_SUCCESS == err);
// [R_RTC_W_Time2Str]
char str_time[80];
err = R_RTC_W_Time2Str(&g_rtc_w_example_ctrl, &get_time, str_time, sizeof (str_time), "%Y.%m.%d %H:%M:%S");
assert(FSP_SUCCESS == err);
printf("- Current Time : %s (GMT %s%02d)\n", str_time, (get_timezone < 0)?"-":"+", (int)(get_timezone));
// [R_RTC_W_CalendarTimePassed]
bool comp_res;
err = R_RTC_W_CalendarTimePassed (&g_rtc_w_example_ctrl, &passed_time, &comp_res);
assert(FSP_SUCCESS == err);
if ( comp_res == true )
{
printf("given time already passed");
}
else
{
printf("given time didn't passed yet");
}
}

Data Structures

struct  rtc_extended_cfg_t
 
struct  rtc_w_instance_ctrl_t
 

Macros

#define RTC_W_OPEN
 

Data Structure Documentation

◆ rtc_extended_cfg_t

struct rtc_extended_cfg_t

RTC extended configuration

Data Fields
uint32_t reserved Reserved.

◆ rtc_w_instance_ctrl_t

struct rtc_w_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_t * p_cfg Pointer to initial configurations.
SemaphoreHandle_t calendar_time_lock Lock for shared Calendar time data.

Macro Definition Documentation

◆ RTC_W_OPEN

#define RTC_W_OPEN

"RTC" in ASCII, used to determine if device is open.

Function Documentation

◆ R_RTC_W_Open()

fsp_err_t R_RTC_W_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.

Note
To start the RTC R_RTC_W_CalendarTimeZoneSet and R_RTC_W_CalendarTimeSet must be called at least once. R_RTC_W_Open should be called once globally.

Example:

/* Handle any errors. This function should be defined by the user. */
assert(0 == err);
/* Open the RTC module */
err = R_RTC_W_Open(&g_rtc_w_example_ctrl, &g_rtc0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
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_HW_CONDITIONInvalid Low-Power clock selected. `

◆ R_RTC_W_Close()

fsp_err_t R_RTC_W_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_W_ClockSourceSet()

fsp_err_t R_RTC_W_ClockSourceSet ( rtc_ctrl_t *const  p_ctrl)

Sets the RTC clock source. Implements rtc_api_t::clockSourceSet.

Return values
FSP_ERR_UNSUPPORTEDClock source is the LP clock and which is selected during System Init.

◆ R_RTC_W_CalendarTimeSet()

fsp_err_t R_RTC_W_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.

◆ R_RTC_W_CalendarTimeGet()

fsp_err_t R_RTC_W_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_W_CalendarAlarmSet()

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

Set the calendar alarm time.

Implements rtc_api_t::calendarAlarmSet.

Return values
FSP_ERR_UNSUPPORTED

◆ R_RTC_W_CalendarAlarmGet()

fsp_err_t R_RTC_W_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_ERR_UNSUPPORTED

◆ R_RTC_W_PeriodicIrqRateSet()

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

Set the periodic interrupt rate and enable periodic interrupt. Periodic interrupts refer to the recurring interrupts when a unit of time rolls over.

Implements rtc_api_t::periodicIrqRateSet

Return values
FSP_ERR_UNSUPPORTED

◆ R_RTC_W_InfoGet()

fsp_err_t R_RTC_W_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

Implements rtc_api_t::infoGet

Return values
FSP_ERR_UNSUPPORTED

◆ R_RTC_W_ErrorAdjustmentSet()

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

This function sets time error adjustment

Return values
FSP_ERR_UNSUPPORTEDTime error adjustment functionality is not supported.

◆ R_RTC_W_CallbackSet()

fsp_err_t R_RTC_W_CallbackSet ( rtc_ctrl_t *const  p_ctrl,
void(*)(rtc_callback_args_t *)  p_callback,
void *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_ERR_UNSUPPORTED

◆ R_RTC_W_TimeCaptureSet()

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

Set time capture configuration for the provided channel.

Implements rtc_api_t::timeCaptureSet

Return values
FSP_ERR_UNSUPPORTED

◆ R_RTC_W_TimeCaptureGet()

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

Get time capture value of the provided channel.

Implements rtc_api_t::timeCaptureGet

Return values
FSP_ERR_UNSUPPORTED

◆ R_RTC_W_CalendarBootTimeGet()

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

Get the system boot time.

Parameters
[in]p_ctrlPointer to RTC device handle
[out]p_timePointer to a time structure that contains the boot time.
Return values
FSP_SUCCESSCalendar Boot time get operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_W_CalendarTimeZoneSet()

fsp_err_t R_RTC_W_CalendarTimeZoneSet ( rtc_ctrl_t *const  p_ctrl,
long *  p_timezone 
)

Set the timezone offset from GMT.

Parameters
[in]p_ctrlPointer to RTC device handle
[in]p_timezonePointer to a timezone to set (in seconds)
Return values
FSP_SUCCESSCalendar TimeZone set operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_W_CalendarTimeZoneGet()

fsp_err_t R_RTC_W_CalendarTimeZoneGet ( rtc_ctrl_t *const  p_ctrl,
long *  p_timezone 
)

Get the timezone offset from GMT.

Parameters
[in]p_ctrlPointer to RTC device handle
[out]p_timezonePointer to the current timezone (in seconds)
Return values
FSP_SUCCESSCalendar TimeZone get operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_W_CalendarGMTTimeGet()

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

Get the GMT calendar time.

Parameters
[in]p_ctrlPointer to RTC device handle
[out]p_timePointer to GMT time
Return values
FSP_SUCCESSCalendar GMT time get operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_W_CalendarTimePassed()

fsp_err_t R_RTC_W_CalendarTimePassed ( rtc_ctrl_t *const  p_ctrl,
rtc_time_t *const  p_time,
bool *  p_comp 
)

Compare a given time to the current time.

Parameters
[in]p_ctrlPointer to RTC device handle
[in]p_timePointer to the given time
[out]p_compSet to 'true' if the given time already passed (in compare to current time) and to 'false' otherwise.
Return values
FSP_SUCCESSCalendar Time Passed operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_W_Time2Str()

fsp_err_t R_RTC_W_Time2Str ( rtc_ctrl_t *const  p_ctrl,
rtc_time_t *const  p_time,
char *const  str_buff_ptr,
size_t  maxsize,
char const *  format 
)

Convert rtc_time struct to a human readable string according to a given format (format example: "%Y.%m.%d %H:%M:%S")

Parameters
[in]p_ctrlPointer to RTC device handle
[in]p_timePointer to the time to convert to a string
[out]str_buff_ptrBuffer to contain a string converted from p_time
[out]maxsizeMax size of str_buff_ptr
[in]formatFormat string
Return values
FSP_SUCCESSTime to Str operation was successful.
FSP_ERR_ASSERTIONInvalid input argument.
FSP_ERR_NOT_OPENDriver not open already for operation.

◆ R_RTC_W_GetCtrl()

rtc_ctrl_t * R_RTC_W_GetCtrl ( void  )

Get RTC_W control block.

Return values
p_ctrlPointer to the RTC_W control block.