RA Flexible Software Package Documentation
Release v5.6.0
|
|
Driver for the RTC peripheral on RA MCUs. This module implements the RTC Interface.
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.
The RTC HAL module supports three different interrupt types:
"Parameter Checking" needs to be enabled if date and time validation is required for calendarTimeSet and calendarAlarmSet APIs. If "Parameter Checking" is enabled, the 'day of the week' field is automatically calculated and updated by the driver for the provided date. When using the calendarAlarmSet API, only the fields which have their corresponding match flag set are written to the registers. Other register fields are reset to default value.
The time error adjustment function is used to correct errors, running fast or slow, in the time caused by variation in the precision of oscillation by the sub-clock oscillator. Because 32,768 cycles of the sub-clock oscillator constitute 1 second of operation when the sub-clock oscillator is selected, the clock runs fast if the sub-clock frequency is high and slow if the sub-clock frequency is low. The time error adjustment functions include:
The error adjustment is reset every time RTC is reconfigured or time is set.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Set Source Clock in Open |
| Enabled | If enabled RTC source clock is initialized in R_RTC_Open. If disabled, R_RTC_ClockSourceSet must be called to set the RTC source clock. Disable if user wants to control the setting of RTC source clock after warm start. |
Configuration | Options | Default | Description |
---|---|---|---|
Name | Name must be a valid C symbol | g_rtc0 | Module name. |
Clock Source | MCU Specific Options | Select the RTC clock source. | |
Frequency Comparision Value (LOCO) | Value must be a positive integer between 7 and 511 | 255 | Frequency comparison value when using LOCO |
Automatic Adjustment Mode |
| Enabled | Enable/ Disable the Error Adjustment mode |
Automatic Adjustment Period |
| 10 Seconds | Select the Error Adjustment Period for Automatic Adjustment |
Adjustment Type (Plus-Minus) |
| NONE | Select the Error Adjustment type |
Error Adjustment Value | Value must be a positive integer less than equal to 63 | 0 | Specify the Adjustment Value (the number of sub-clock cycles) from the prescaler |
Callback | Name must be a valid C symbol | NULL | 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 Priority | MCU Specific Options | Select the alarm interrupt priority. | |
Period Interrupt Priority | MCU Specific Options | Select the period interrupt priority. | |
Carry Interrupt Priority | MCU Specific Options | Select the carry interrupt priority. |
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.
The RTC HAL module can use the following clock sources:
Users have to select the right source for their application. LOCO is the default during configuration when it is available.
This module does not use I/O pins.
Set Source Clock in Open
property for RTC and call R_RTC_ClockSourceSet() only when RTC clock source needs to be set. Application should check for the reset type and should accordingly call the R_RTC_ClockSourceSet().Developers should be aware of the following limitations when using the RTC:
VRTC-domain provides power supply to SOSC and RTC on devices with IRTC:
The RTC is capable of storing the month, day, hour, minute and second when detecting an edge of a signal on a time capture event input pin. On RA parts up to three capture channels can be configured.
FSP_ERR_INVALID_STATE
.This is a basic example of minimal use of the RTC in an application.
This is an example of how to handle call to set the RTC clock.
This is an example of periodic interrupt in RTC.
This is an example of alarm interrupt in RTC.
This is an example of modifying error adjustment in RTC.
This is an example of calling RTC API on devices with VRTC-domain.
This is an example of calling Time Capture API on RTC with Independent Power Supply.
Data Structures | |
struct | rtc_extended_cfg_t |
struct | rtc_instance_ctrl_t |
struct rtc_extended_cfg_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_t * | p_cfg |
Pointer to initial configurations. | |
volatile bool | carry_isr_triggered |
Was the carry isr triggered. | |
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.
Example:
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_ARGUMENT | Invalid time parameter field. |
fsp_err_t R_RTC_Close | ( | rtc_ctrl_t *const | p_ctrl | ) |
Close the RTC driver. Implements rtc_api_t::close
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. |
fsp_err_t R_RTC_ClockSourceSet | ( | rtc_ctrl_t *const | p_ctrl | ) |
Sets the RTC clock source. Implements rtc_api_t::clockSourceSet.
Example:
FSP_SUCCESS | Initialization was successful and RTC has started. |
FSP_ERR_ASSERTION | Invalid p_ctrl or p_cfg pointer. |
FSP_ERR_NOT_OPEN | Driver is not opened. |
FSP_ERR_INVALID_ARGUMENT | Invalid clock source. |
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.
FSP_SUCCESS | Calendar time set operation was successful. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
FSP_ERR_INVALID_ARGUMENT | Invalid time parameter field. |
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
FSP_SUCCESS | Calendar time get operation was successful. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
FSP_ERR_IRQ_BSP_DISABLED | User IRQ parameter not valid |
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.
FSP_SUCCESS | Calendar alarm time set operation was successful. |
FSP_ERR_INVALID_ARGUMENT | Invalid time parameter field. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
FSP_ERR_IRQ_BSP_DISABLED | User IRQ parameter not valid |
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
FSP_SUCCESS | Calendar alarm time get operation was successful. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
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
Example:
FSP_SUCCESS | The periodic interrupt rate was successfully set. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
FSP_ERR_IRQ_BSP_DISABLED | User IRQ parameter not valid |
fsp_err_t R_RTC_InfoGet | ( | rtc_ctrl_t *const | p_ctrl, |
rtc_info_t *const | p_rtc_info | ||
) |
Set RTC clock source and running status information ad store it in provided pointer p_rtc_info
Implements rtc_api_t::infoGet
FSP_SUCCESS | Get information Successful. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
fsp_err_t R_RTC_ErrorAdjustmentSet | ( | rtc_ctrl_t *const | p_ctrl, |
rtc_error_adjustment_cfg_t const *const | err_adj_cfg | ||
) |
This function sets time error adjustment
Implements rtc_api_t::errorAdjustmentSet
FSP_SUCCESS | Time error adjustment successful. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open for operation. |
FSP_ERR_UNSUPPORTED | The clock source is not sub-clock. |
FSP_ERR_INVALID_ARGUMENT | Invalid error adjustment value. |
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
FSP_SUCCESS | Baud rate was successfully changed. |
FSP_ERR_ASSERTION | Pointer to RTC control block is NULL or the RTC is not configured to use the internal clock. |
FSP_ERR_NOT_OPEN | The control block has not been opened |
FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |
fsp_err_t R_RTC_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
FSP_SUCCESS | Setting for Time capture was successful. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
FSP_ERR_INVALID_CHANNEL | Invalid input channel set. |
FSP_ERR_UNSUPPORTED | Hardware not support this feature. |
fsp_err_t R_RTC_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
FSP_SUCCESS | Get time capture successful. |
FSP_ERR_ASSERTION | Invalid input argument. |
FSP_ERR_NOT_OPEN | Driver not open already for operation. |
FSP_ERR_INVALID_CHANNEL | Invalid input channel get. |
FSP_ERR_INVALID_STATE | Invalid operation state. |
FSP_ERR_UNSUPPORTED | Hardware not support this feature. |