|
| 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_t * | R_RTC_W_GetCtrl (void) |
| |
Driver for the RTC peripheral on RAFW MCUs. This module implements the RTC Interface.
Overview
The RTC module controls clock and calendar functions.
Features
- RTC local time and date get and set.
- RTC boot time get.
- RTC timezone get and set.
- RTC GMT time get.
- RTC time passed check.
- RTC time to human readable string convertor.
- RTC time and date alarm get and set - not supported.
- RTC alarm and periodic event notification - not supported.
- RTC time capture - not supported.
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:
| Configuration | Options | Default | Description |
| 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:
- R_RTC_W is not suitable for bare-metal system, FREERTOS OS is in use.
- R_RTC_W ctrl & cfg structures inputs for RTC_OPEN must be shared globally.
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)
void rtc_w_example(void);
{
};
{
};
{
.tm_sec = 10,
.tm_min = 11,
.tm_hour = 12,
.tm_mday = 18,
.tm_wday = 4,
.tm_mon = 9,
.tm_year = YEARS_SINCE_1900,
};
{
.tm_sec = 0,
.tm_min = 0,
.tm_hour = 6,
.tm_mday = 1,
.tm_wday = 1,
.tm_mon = 9,
.tm_year = YEARS_SINCE_1900,
};
void rtc_w_example (void)
{
assert(0 == err);
assert(FSP_SUCCESS == err);
long int timezone_example = (2 * 3600);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
long get_timezone;
assert(FSP_SUCCESS == err);
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));
bool comp_res;
assert(FSP_SUCCESS == err);
if ( comp_res == true )
{
printf("given time already passed");
}
else
{
printf("given time didn't passed yet");
}
}
◆ 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. |
◆ RTC_W_OPEN
"RTC" in ASCII, used to determine if device is open.
◆ R_RTC_W_Open()
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:
assert(0 == err);
assert(FSP_SUCCESS == err);
- Return values
-
| FSP_SUCCESS | Initialization was successful and RTC has started. |
| FSP_ERR_ASSERTION | Invalid p_ctrl or p_cfg pointer. |
| FSP_ERR_ALREADY_OPEN | Module is already open. |
| FSP_ERR_INVALID_HW_CONDITION | Invalid Low-Power clock selected. ` |
◆ R_RTC_W_Close()
Close the RTC driver. Implements rtc_api_t::close
- Return values
-
| FSP_SUCCESS | De-Initialization was successful and RTC driver closed. |
| FSP_ERR_ASSERTION | Invalid p_ctrl. |
| FSP_ERR_NOT_OPEN | Driver not open already for close. |
◆ R_RTC_W_ClockSourceSet()
Sets the RTC clock source. Implements rtc_api_t::clockSourceSet.
- Return values
-
| FSP_ERR_UNSUPPORTED | Clock source is the LP clock and which is selected during System Init. |
◆ R_RTC_W_CalendarTimeSet()
Set the calendar time.
Implements rtc_api_t::calendarTimeSet.
- Return values
-
| FSP_SUCCESS | Calendar time set operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_CalendarTimeGet()
Get the calendar time.
Implements rtc_api_t::calendarTimeGet
- Return values
-
| FSP_SUCCESS | Calendar time get operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_CalendarAlarmSet()
◆ R_RTC_W_CalendarAlarmGet()
◆ R_RTC_W_PeriodicIrqRateSet()
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
-
◆ R_RTC_W_InfoGet()
Get RTC clock source and running status information and store it in provided pointer p_rtc_info
Implements rtc_api_t::infoGet
- Return values
-
◆ R_RTC_W_ErrorAdjustmentSet()
This function sets time error adjustment
- Return values
-
| FSP_ERR_UNSUPPORTED | Time error adjustment functionality is not supported. |
◆ R_RTC_W_CallbackSet()
Updates the user callback and has option of providing memory for callback structure.
Implements rtc_api_t::callbackSet
- Return values
-
◆ R_RTC_W_TimeCaptureSet()
◆ R_RTC_W_TimeCaptureGet()
◆ R_RTC_W_CalendarBootTimeGet()
Get the system boot time.
- Parameters
-
| [in] | p_ctrl | Pointer to RTC device handle |
| [out] | p_time | Pointer to a time structure that contains the boot time. |
- Return values
-
| FSP_SUCCESS | Calendar Boot time get operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_CalendarTimeZoneSet()
Set the timezone offset from GMT.
- Parameters
-
| [in] | p_ctrl | Pointer to RTC device handle |
| [in] | p_timezone | Pointer to a timezone to set (in seconds) |
- Return values
-
| FSP_SUCCESS | Calendar TimeZone set operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_CalendarTimeZoneGet()
Get the timezone offset from GMT.
- Parameters
-
| [in] | p_ctrl | Pointer to RTC device handle |
| [out] | p_timezone | Pointer to the current timezone (in seconds) |
- Return values
-
| FSP_SUCCESS | Calendar TimeZone get operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_CalendarGMTTimeGet()
Get the GMT calendar time.
- Parameters
-
| [in] | p_ctrl | Pointer to RTC device handle |
| [out] | p_time | Pointer to GMT time |
- Return values
-
| FSP_SUCCESS | Calendar GMT time get operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_CalendarTimePassed()
Compare a given time to the current time.
- Parameters
-
| [in] | p_ctrl | Pointer to RTC device handle |
| [in] | p_time | Pointer to the given time |
| [out] | p_comp | Set to 'true' if the given time already passed (in compare to current time) and to 'false' otherwise. |
- Return values
-
| FSP_SUCCESS | Calendar Time Passed operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_Time2Str()
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_ctrl | Pointer to RTC device handle |
| [in] | p_time | Pointer to the time to convert to a string |
| [out] | str_buff_ptr | Buffer to contain a string converted from p_time |
| [out] | maxsize | Max size of str_buff_ptr |
| [in] | format | Format string |
- Return values
-
| FSP_SUCCESS | Time to Str operation was successful. |
| FSP_ERR_ASSERTION | Invalid input argument. |
| FSP_ERR_NOT_OPEN | Driver not open already for operation. |
◆ R_RTC_W_GetCtrl()
Get RTC_W control block.
- Return values
-
| p_ctrl | Pointer to the RTC_W control block. |