SYSRTC - System RTC#
Example#
This example demonstrates how to configure and use the System Real-Time Counter (SYSRTC) to generate periodic interrupts.
#include "sl_hal_sysrtc.h"
#include "sl_clock_manager.h"
#include "sl_interrupt_manager.h"
// SYSRTC group 0 compare 0 interrupt handler
void SYSRTC_APP_IRQHandler(void)
{
uint32_t flags = sl_hal_sysrtc_get_group_interrupts(0);
if (flags & SYSRTC_GRP0_IF_CMP0) {
// Handle compare match 0 interrupt
sl_hal_sysrtc_clear_group_interrupts(0, SYSRTC_GRP0_IF_CMP0);
// Add your application code here (e.g., toggle an LED)
}
}
void sysrtc_example(void)
{
// Enable SYSRTC clock
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_SYSRTC0);
// Initialize SYSRTC with default config
sl_hal_sysrtc_init_t sysrtc_init = SL_HAL_SYSRTC_INIT_DEFAULT;
sl_hal_sysrtc_init(&sysrtc_init);
// Initialize group 0 and enable compare channel 0 with config
sl_hal_sysrtc_group_init_t group_init = SL_HAL_SYSRTC_GROUP_INIT_DEFAULT;
sl_hal_sysrtc_group_channel_compare_config_t compare0_config = SL_HAL_SYSRTC_GROUP_CHANNEL_COMPARE_INIT_DEFAULT;
group_init.compare_channel0_enable = true;
group_init.p_compare_channel0_config = &compare0_config;
sl_hal_sysrtc_init_group(0, &group_init);
// Set compare value for group 0, channel 0
sl_hal_sysrtc_set_group_compare_channel_value(0, 0, 1000);
// Enable group 0 compare 0 interrupt
sl_hal_sysrtc_enable_group_interrupts(0, SYSRTC_GRP0_IF_CMP0);
// Enable SYSRTC interrupt in NVIC
sl_interrupt_manager_clear_irq_pending(SYSRTC_APP_IRQn);
sl_interrupt_manager_enable_irq(SYSRTC_APP_IRQn);
// Start SYSRTC
sl_hal_sysrtc_enable();
sl_hal_sysrtc_wait_sync();
// Application main loop
while (1) {
// Read current counter value if needed
uint32_t count = sl_hal_sysrtc_get_counter();
// Sleep or perform other tasks
}
}
Modules#
sl_hal_sysrtc_group_channel_compare_config_t
sl_hal_sysrtc_group_channel_capture_config_t
Enumerations#
Capture input edge select.
Compare match output action mode.
Functions#
Initializes SYSRTC module.
Enables the SYSRTC module and starts the counter.
Stops the counter and disables the SYSRTC.
Waits for the SYSRTC to complete all synchronization of register changes and commands.
Waits for the SYSRTC to complete resetting or disabling procedure.
Starts SYSRTC counter.
Stops the SYSRTC counter.
Restores SYSRTC to its reset state.
Gets SYSRTC STATUS register value.
Locks SYSRTC registers.
Unlocks SYSRTC registers.
Gets SYSRTC counter value.
Sets the SYSRTC counter value.
Waits for the SYSRTC group to complete all synchronization of register changes and commands.
Initializes the selected SYSRTC group.
Enables one or more SYSRTC interrupts for the given group.
Disables one or more SYSRTC interrupts for the given group.
Clears one or more pending SYSRTC interrupts for the given group.
Gets pending SYSRTC interrupt flags for the given group.
Gets enabled and pending SYSRTC interrupt flags for the given group.
Sets one or more pending SYSRTC interrupts for the given group from Software.
Gets SYSRTC compare register value for selected channel of given group.
Sets SYSRTC compare register value for selected channel of given group.
Gets SYSRTC input capture register value for capture channel of given group.
Macros#
Minimum compare channels for SYSRTC group.
Maximum compare channels for SYSRTC group.
Minimum capture channels for SYSRTC group.
Maximum capture channels for SYSRTC group.
SYSRTC group number.
Validation of valid SYSRTC group for assert statements.
Suggested default values for SYSRTC configuration structure.
Suggested default values for compare channel configuration structure.
Compare channel configuration for starting HFXO using PRS.
Suggested default values for capture channel configuration structure.
Suggested default values for SYSRTC group configuration structure.
Enumeration Documentation#
sl_hal_sysrtc_capture_edge_t#
sl_hal_sysrtc_capture_edge_t
Capture input edge select.
Enumerator | |
---|---|
SL_HAL_SYSRTC_CAPTURE_EDGE_RISING | Rising edges detected. |
SL_HAL_SYSRTC_CAPTURE_EDGE_FALLING | Falling edges detected. |
SL_HAL_SYSRTC_CAPTURE_EDGE_BOTH | Both edges detected. |
sl_hal_sysrtc_compare_match_out_action_t#
sl_hal_sysrtc_compare_match_out_action_t
Compare match output action mode.
Enumerator | |
---|---|
SL_HAL_SYSRTC_COMPARE_MATCH_OUT_ACTION_CLEAR | Clear output. |
SL_HAL_SYSRTC_COMPARE_MATCH_OUT_ACTION_SET | Set output. |
SL_HAL_SYSRTC_COMPARE_MATCH_OUT_ACTION_PULSE | Generate a pulse. |
SL_HAL_SYSRTC_COMPARE_MATCH_OUT_ACTION_TOGGLE | Toggle output. |
SL_HAL_SYSRTC_COMPARE_MATCH_OUT_ACTION_CMPIF | Export CMPIF. |
Function Documentation#
sl_hal_sysrtc_init#
void sl_hal_sysrtc_init (const sl_hal_sysrtc_init_t * init)
Initializes SYSRTC module.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_hal_sysrtc_init_t * | [in] | init | A pointer to the SYSRTC initialization structure variable. |
@Note that the compare values must be set separately with (sl_hal_sysrtc_set_group_compare_channel_value()), which should probably be done prior to the use of this function if configuring the SYSRTC to start when initialization is completed.
sl_hal_sysrtc_enable#
void sl_hal_sysrtc_enable (void )
Enables the SYSRTC module and starts the counter.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_sysrtc_disable#
void sl_hal_sysrtc_disable (void )
Stops the counter and disables the SYSRTC.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_sysrtc_wait_sync#
void sl_hal_sysrtc_wait_sync (void )
Waits for the SYSRTC to complete all synchronization of register changes and commands.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Wait for synchronization of register changes to low frequency domain.
Note
This function will stall execution until the synchronization is complete.
sl_hal_sysrtc_wait_ready#
void sl_hal_sysrtc_wait_ready (void )
Waits for the SYSRTC to complete resetting or disabling procedure.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_sysrtc_start#
void sl_hal_sysrtc_start (void )
Starts SYSRTC counter.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function will send a start command to the SYSRTC peripheral. The SYSRTC peripheral will use some LF clock ticks before the command is executed. The sl_hal_sysrtc_wait_sync() function can be used to wait for the start command to be executed.
Note
This function requires the SYSRTC to be enabled.
sl_hal_sysrtc_stop#
void sl_hal_sysrtc_stop (void )
Stops the SYSRTC counter.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function will send a stop command to the SYSRTC peripheral. The SYSRTC peripheral will use some LF clock ticks before the command is executed. The sl_hal_sysrtc_wait_sync() function can be used to wait for the stop command to be executed.
Note
This function requires the SYSRTC to be enabled.
sl_hal_sysrtc_reset#
void sl_hal_sysrtc_reset (void )
Restores SYSRTC to its reset state.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_sysrtc_get_status#
uint32_t sl_hal_sysrtc_get_status (void )
Gets SYSRTC STATUS register value.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Current STATUS register value.
sl_hal_sysrtc_lock#
void sl_hal_sysrtc_lock (void )
Locks SYSRTC registers.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Note
When SYSRTC registers are locked SYSRTC_EN, SYSRTC_CFG, SYSRTC_CMD, SYSRTC_SWRST, SYSRTC_CNT and SYSRTC_TOPCNT registers cannot be written to.
sl_hal_sysrtc_unlock#
void sl_hal_sysrtc_unlock (void )
Unlocks SYSRTC registers.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Note
When SYSRTC registers are locked SYSRTC_EN, SYSRTC_CFG, SYSRTC_CMD, SYSRTC_SWRST, SYSRTC_CNT and SYSRTC_TOPCNT registers cannot be written to.
sl_hal_sysrtc_get_counter#
uint32_t sl_hal_sysrtc_get_counter (void )
Gets SYSRTC counter value.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Current SYSRTC counter value.
sl_hal_sysrtc_set_counter#
void sl_hal_sysrtc_set_counter (uint32_t value)
Sets the SYSRTC counter value.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | value | The new SYSRTC counter value. |
sl_hal_sysrtc_wait_sync_group#
void sl_hal_sysrtc_wait_sync_group (uint8_t group_number)
Waits for the SYSRTC group to complete all synchronization of register changes and commands.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
sl_hal_sysrtc_init_group#
void sl_hal_sysrtc_init_group (uint8_t group_number, const sl_hal_sysrtc_group_init_t * group_init)
Initializes the selected SYSRTC group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
const sl_hal_sysrtc_group_init_t * | [in] | group_init | Pointer to group initialization structure variable. |
sl_hal_sysrtc_enable_group_interrupts#
void sl_hal_sysrtc_enable_group_interrupts (uint8_t group_number, uint32_t flags)
Enables one or more SYSRTC interrupts for the given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
uint32_t | [in] | flags | SYSRTC interrupt sources to enable. Use a set of interrupt flags OR-ed together to set multiple interrupt sources for the given SYSRTC group. |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using sl_hal_sysrtc_clear_group_interrupts() prior to enabling the interrupt.
sl_hal_sysrtc_disable_group_interrupts#
void sl_hal_sysrtc_disable_group_interrupts (uint8_t group_number, uint32_t flags)
Disables one or more SYSRTC interrupts for the given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
uint32_t | [in] | flags | SYSRTC interrupt sources to disable. Use a set of interrupt flags OR-ed together to disable multiple interrupt sources for the given SYSRTC group. |
sl_hal_sysrtc_clear_group_interrupts#
void sl_hal_sysrtc_clear_group_interrupts (uint8_t group_number, uint32_t flags)
Clears one or more pending SYSRTC interrupts for the given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
uint32_t | [in] | flags | SYSRTC interrupt sources to clear. Use a set of interrupt flags OR-ed together to clear multiple interrupt sources for the given SYSRTC group. |
sl_hal_sysrtc_get_group_interrupts#
uint32_t sl_hal_sysrtc_get_group_interrupts (uint8_t group_number)
Gets pending SYSRTC interrupt flags for the given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
Note
Event bits are not cleared by using this function.
Returns
Pending SYSRTC interrupt sources. Returns a set of interrupt flags OR-ed together for multiple interrupt sources in the SYSRTC group.
sl_hal_sysrtc_get_group_enabled_interrupts#
uint32_t sl_hal_sysrtc_get_group_enabled_interrupts (uint8_t group_number)
Gets enabled and pending SYSRTC interrupt flags for the given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
Useful for handling more interrupt sources in the same interrupt handler.
Note
Interrupt flags are not cleared by using this function.
Returns
Pending and enabled SYSRTC interrupt sources. The return value is the bitwise AND of
the enabled interrupt sources in SYSRTC_GRPx_IEN and
the pending interrupt flags SYSRTC_GRPx_IF.
sl_hal_sysrtc_set_group_interrupts#
void sl_hal_sysrtc_set_group_interrupts (uint8_t group_number, uint32_t flags)
Sets one or more pending SYSRTC interrupts for the given group from Software.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
uint32_t | [in] | flags | SYSRTC interrupt sources to set to pending. Use a set of interrupt flags OR-ed together to set multiple interrupt sources for the SYSRTC group. |
sl_hal_sysrtc_get_group_compare_channel_value#
uint32_t sl_hal_sysrtc_get_group_compare_channel_value (uint8_t group_number, uint8_t channel)
Gets SYSRTC compare register value for selected channel of given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
uint8_t | [in] | channel | Channel selector. |
Returns
Compare register value.
sl_hal_sysrtc_set_group_compare_channel_value#
void sl_hal_sysrtc_set_group_compare_channel_value (uint8_t group_number, uint8_t channel, uint32_t value)
Sets SYSRTC compare register value for selected channel of given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
uint8_t | [in] | channel | Channel selector. |
uint32_t | [in] | value | Compare register value. |
sl_hal_sysrtc_get_group_capture_channel_value#
uint32_t sl_hal_sysrtc_get_group_capture_channel_value (uint8_t group_number)
Gets SYSRTC input capture register value for capture channel of given group.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | group_number | SYSRTC group number to use. |
Returns
Capture register value.