![]() |
Synergy Software Package User's Manual
|
The Real-Time Clock (RTC) HAL module implements a high-level API for real-time timing applications and uses the real-time clock module on a Synergy MCU. The RTC HAL module configures the RTC module and controls clock, calendar and alarm functions. A callback can be used to respond to any of the three supported interrupt types: alarm, periodic, or carry.
The following hardware features are, or are not, supported by SSP for the RTC.
Legend:
| Symbol | Meaning |
|---|---|
| ✓ | Available (Tested) |
| ⌧ | Not Available (Not tested/not functional or both) |
| N/A | Not supported by MCU |
| MCU Group | Calendar Mode | Binary Mode | Sub-clock (XCIN) Count Source | LOCO Count Source | 12 hours/24 hours | Alarm interrupt (RTC_ALM) |
|---|---|---|---|---|---|---|
| S124 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S128 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S1JA | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S3A1 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S3A3 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S3A6 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S3A7 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S5D3 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S5D5 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S5D9 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| S7G2 | ✓ | ⌧ | ✓ | ✓ | 24 Hours | ✓ |
| MCU Group | Periodic interrupt (RTC_PRD) | Carry interrupt (RTC_CUP) | Time capture function | Event link function through ELC HAL driver | Start/stop function | Clock error correction function |
|---|---|---|---|---|---|---|
| S124 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S128 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S1JA | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S3A1 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S3A3 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S3A6 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S3A7 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S5D3 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S5D5 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S5D9 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
| S7G2 | ✓ | ✓ | ⌧ | ⌧ | ✓ | ✓ |
The RTC HAL module defines APIs for opening, closing, setting alarms and starting and stopping RTC operations. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.
RTC HAL Module API Summary
| Function Name | Example API Call and Description |
|---|---|
| open | g_rtc0.p_api->open(g_rtc0.p_ctrl, g_rtc0.p_cfg);Open the RTC HAL. |
| close | g_rtc0.p_api->close(g_rtc0.p_ctrl);Close the RTC HAL. |
| configure | g_rtc0.p_api->configure(g_rtc0.p_ctrl, p_extend); |
| calendarTimeSet | g_rtc0.p_api->calendarTimeSet(g_rtc0.p_ctrl, &start_time_struct_in, true);Set the calendar time. |
| calendarTimeGet | g_rtc0.p_api->calendarTimeGet(g_rtc0.p_ctrl, ¤t_time_struct_out);Get the calendar time. |
| calendarAlarmSet | g_rtc0.p_api->calendarAlarmSet(g_rtc0.p_ctrl, &in_alarm_time_struct_in, true);Set the calendar alarm time. |
| calendarAlarmGet | g_rtc0.p_api->calendarAlarmGet(g_rtc0.p_ctrl, &get_alarm_time_struct_out);Get the calendar alarm time. |
| calendarCounterStart | g_rtc0.p_api->calendarCounterStart(g_rtc0.p_ctrl);Start the calendar counter. |
| calendarCounterStop | g_rtc0.p_api->calendarCounterStop(g_rtc0.p_ctrl);Stop the calendar counter. |
| irqEnable | g_rtc0.p_api->irqEnable(g_rtc0.p_ctrl, CALLBACK);Enable the alarm irq. |
| irqDisable | g_rtc0.p_api->irqDisable(g_rtc0.p_ctrl, CALLBACK);Disable the alarm irq. |
| periodicIrqRateSet | g_rtc0.p_api->periodicIrqRateSet(g_rtc0.p_ctrl, Rate);Set the periodic irq rate. |
| infoGet | g_rtc0.p_api->infoGet(g_rtc0.p_ctrl, clk_src);Return the currently configure clock source for the RTC. |
| errorAdjustmentModeSet | |
| errorAdjustmentSet | |
| versionGet | g_rtc0.p_api->versionGet(&version);Retrieve the API version with the version pointer. |
Status Return Values
| Name | Description |
|---|---|
| SSP_SUCCESS | Function executed successfully. |
| SSP_ERR_ASSERTION | API dependent error. |
| SSP_ERR_INVALID MODE | Invalid mode. |
| SSP_ERR_INVALID_PTR | Invalid parameter. |
The RTC HAL module controls the operation of the real-time clock module on a Synergy MCU. The typical RTC application configures the real-time clock controller periodically based on a system configuration driven by the user. Common operations include setting the time, setting an alarm, configuring a periodic interrupt, and starting or stopping operation. An RTC application usually consists of calls to the RTC HAL module and an optional callback from ISR handler.
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 any supported interrupt type. 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.
The RTC HAL module must be opened before any of the other RTC module APIs can be called. A configuration structure is passed to the open call which specifies the clock source, the name of the user callback from ISR handler, and a user-specified context for the callback. Configuration structures can be either manually defined or generated by the ISDE based on user input during the configuration process.
Functions in the driver can be accessed by either making direct calls to the HAL layer or by using the RTC interface structure. The name of this interface structure is based on the name setting entered in the module's configuration. For example, if the name is g_rtc, then the interface structure is called g_rtc_api.
This section describes how to include the RTC HAL Module in an application using the SSP configurator.
To add the RTC Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the RTC Driver is g_rtc0. This name can be changed in the associated Properties window.)
RTC HAL Module Selection Sequence
| Resource | ISDE Tab | Stacks Selection Sequence |
|---|---|---|
| g_rtc0 RTC HAL on r_rtc | Threads | New Stack> Driver> Timers> RTC HAL on r_rtc |
When the RTC Driver on r_rtc is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.
The RTC HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.
Configuration Settings for the RTC HAL Module on r_rtc
| ISDE Property | Value | Description |
|---|---|---|
| Parameter Checking | BSP, Enabled, Disabled Default: BSP | Enable or disable parameter error checking. |
| Name | g_rtc0 | The name to be used for the RTC module control block instance. This name is also used as the prefix of the other variable instances. See the example code below. |
| Clock Source | LOCO, Sub-clock Default: LOCO | Clock source for the RTC block. |
| Configure RTC hardware in open() call | Yes, No Default: Yes | If enabled, the RTC registers and clock source will be initialized in the open() call. If disabled, the user call must call the configure() api to initialize the hardware. |
| Error Adjustment Value | 0 | Warning: Deprecated configuration field. Must be 0. |
| Error Adjustment Type | None | Warning: Deprecated configuration field. Must be 0. |
| Callback | NULL | The name of the ISR that is called when one of the three interrupts fire. The argument passed into this ISR has an indication of which interrupt caused it to be called. See the example code below. |
| Alarm Interrupt Priority | Priority 0 (highest), Priority 1:14 Priority 15 (lowest - not valid if using ThreadX), Disabled Default: Disabled | Alarm interrupt priority selection. |
| Period Interrupt Priority | Priority 0 (highest), Priority 1:14 Priority 15 (lowest - not valid if using ThreadX), Disabled Default: Disabled | Period interrupt priority selection. |
| Carry Interrupt Priority | Priority 0 (highest), Priority 1:14 Priority 15 (lowest - not valid if using ThreadX) Default: Priority 12 | Carry interrupt priority selection. |
The RTC HAL module can use the following clock sources:
The LOCO is the default selection during configuration.
The RTC does not currently support outputs, so no output pin selections are available.
General Usage
The typical RTC application configures the real-time clock controller periodically based on a system configuration driven by the user. Examples include setting the time, setting an alarm, configuring a periodic interrupt, etc. An RTC application consists of calls to the RTC module and an optional callback.
The RTC module must be opened before any of the other APIs can be called. A configuration structure is passed to the open call which specifies the clock source, the name of the callbacks, and user-specified context for the handler. Configuration structures can be either manually defined or generated by the ISDE based on user input during the configuration process. Functions in the module can be accessed by using the RTC interface structure. The name of this interface structure is based on the name setting entered in the module's configuration.
Avoid Drift Issue After Reset
To avoid drift in RTC time across MCU reset, the application needs to follow the following steps:
Make these changes to module configuration settings:
Make these calls in the application code:
These two steps can be performed by using the following initialization sequence in the application:
An alternative way to determine cold start condition (instead of status) is to obtain the information from the reset status registers (RSTSRx).
Date and Time Validation
The "Parameter Checking" setting needs to be enabled in the ISDE configurator if date and time validation is required for the rtc_api_t::calendarTimeSet and rtc_api_t::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 rtc_api_t::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.
Sub-Clock Error Adjustment
The rtc_api_t::errorAdjustmentModeSet and rtc_api_t::errorAdjustmentSet APIs can be used to correct the error in the RTC sub-clock source. These APIs can only be used after the RTC is configured and time is set.
The error adjustment is reset every time the RTC is reconfigured or time is set.
There are two common application uses for the RTC HAL module. The first simply uses the RTC to supply the current time as required by the application. A second use of the RTC HAL modules uses the periodic interrupt capability to initiate a process at a regular period. Examples of both uses are provided below.
The typical steps in using the RTC HAL module in a timing application are:
These common steps are illustrated in a typical operational flow diagram in the following figure:
The typical steps in using the RTC periodic IRQ in an application are:
These common steps are illustrated in a typical operational flow diagram in the following figure: