System RTC#
Introduction#
The System Real-Time Clock (SYSRTC) offers precise timekeeping and timer functionality essential for various applications. It serves as a cornerstone for tasks requiring accurate time measurement, event scheduling, and power management. This SYSRTC driver provides a robust set of functions to configure and use this peripheral effectively, ensuring optimal performance and reliability in time-critical applications.
Configuration#
The sl_si91x_sysrtc_configure_clock function allows setting the clock source frequency, choosing between 32kHz RC, 1kHz RO clock sources. Initialization of the SYSRTC is achieved through the sl_si91x_sysrtc_init function, which not only initializes the peripheral but also enables it. Additionally, SYSRTC can be configured to run during debug halt by specifying the appropriate setting in the initialization function.
For more information on configuring available parameters refer to the respective peripheral example readme document.
Usage#
SYSRTC has to be initialised by calling the sl_si91x_sysrtc_configure_clock and sl_si91x_sysrtc_init.
Once configured, the SYSRTC can be tailored to specific application requirements using the functions in the driver. The sl_si91x_sysrtc_configure_group configures group number and enables its compare & capture channels. To handle timer interrupts and execute actions accordingly, users can register callback functions using the sl_si91x_sysrtc_register_callback function. Furthermore, functions such as sl_si91x_sysrtc_set_compare_value and sl_si91x_sysrtc_get_count facilitate setting compare values and retrieving the current counter value, respectively, allowing for fine-grained control over time-sensitive operations. Functions such as sl_si91x_sysrtc_start and sl_si91x_sysrtc_stop enable starting and stopping the timer, while the sl_si91x_sysrtc_lock locks the SYSRTC registers.
Below functions will initiate and configure the SYSRTC, which is the general flow for implementation:
sl_si91x_sysrtc_set_compare_value (If compare channel is enabled)
sl_si91x_sysrtc_is_running (If required to check timer running status)
sl_si91x_sysrtc_get_count (If required to check timer current count)
Modules#
Enumerations#
Enumeration to represent SYSRTC group numbers.
Enumeration to represent SYSRTC channel numbers.
Typedefs#
Typedef for the function pointer of the interrupt callback function.
Functions#
Initializes SYSRTC and enables the peripheral.
Configures the SYSRTC input clock source frequency.
To configure the SYSRTC groups of compare and capture channels.
To register the callback of the timer interrupt.
Unregisters timer interrupt callback and disables interrupts as per selected interrupt flag.
Sets SYSRTC compare value for the selected channel of the given group.
Gets SYSRTC current compare register value for selected channel of selected group.
Sets register-input for the capture channel of the selected group of SYSRTC.
Configures input pins for the SYSRTC capture channel of selected group.
Configures the output pins of the selected compare channel of given group.
Gets the SYSRTC current counter register value.
Gets the SYSRTC capture register value of a given group.
Reads the SYSRTC compare channel output bit value of a given group.
Gets the SYSRTC running status, status is true if running, false if stopped.
Gets the SYSRTC lock status.
Sets the SYSRTC input output mode for the capture and compare channels.
Starts the SYSRTC counter.
Stops the SYSRTC counter.
Restores the SYSRTC to its reset state.
Locks the SYSRTC registers.
Unlocks the SYSRTC registers.
Sets the SYSRTC counter register value of counter This can be used to change the count of SYSRTC, when it is stopped.
Gets the SYSRTC version It returns API version of SYSRTC.
De-initializes the SYSRTC by disabling its clock.
Enumeration Documentation#
sl_sysrtc_group_number_t#
sl_sysrtc_group_number_t
Enumeration to represent SYSRTC group numbers.
Enumerator | |
---|---|
SL_SYSRTC_GROUP_0 | enum for SYSRTC group-0 |
SL_SYSRTC_GROUP_1 | enum for SYSRTC group-1 |
SL_SYSRTC_GROUP_LAST | Last member of enum for validation. |
70
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_sysrtc_channel_number_t#
sl_sysrtc_channel_number_t
Enumeration to represent SYSRTC channel numbers.
Enumerator | |
---|---|
SL_SYSRTC_CHANNEL_0 | enum for SYSRTC channel-0 |
SL_SYSRTC_CHANNEL_1 | enum for SYSRTC channel-1 |
SL_SYSRTC_CHANNEL_LAST | Last member of enum for validation. |
77
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
Typedef Documentation#
sl_clock_sources_t#
typedef rsi_sysrtc_clk_inp_t sl_clock_sources_t
54
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_sysrtc_config_t#
typedef rsi_sysrtc_config_t sl_sysrtc_config_t
55
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_sysrtc_group_config_t#
typedef rsi_sysrtc_group_config_t sl_sysrtc_group_config_t
56
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_sysrtc_group_compare_channel_action_config_t#
typedef rsi_sysrtc_group_channel_compare_config_t sl_sysrtc_group_compare_channel_action_config_t
58
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_sysrtc_group_capture_channel_input_edge_config_t#
typedef rsi_sysrtc_group_channel_capture_config_t sl_sysrtc_group_capture_channel_input_edge_config_t
60
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_sysrtc_callback_t#
typedef void(* sl_sysrtc_callback_t) (void *callback_flag) )(void *callback_flag)
Typedef for the function pointer of the interrupt callback function.
N/A | callback_flag | (void *) parameter for updating flag values |
67
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
Function Documentation#
sl_si91x_sysrtc_init#
sl_status_t sl_si91x_sysrtc_init (const sl_sysrtc_config_t * config_ptr)
Initializes SYSRTC and enables the peripheral.
[in] | config_ptr | Pointer to SYSRTC config structure sl_sysrtc_config_t. |
Also configures that SYSRTC should run during debug halt, as per user input.
Pre-condition:
Returns
status 0 if successful, else error code as follows:
SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.
SL_STATUS_OK (0x0000) - Success, SYSRTC initialized properly.
120
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_configure_clock#
sl_status_t sl_si91x_sysrtc_configure_clock (sl_sysrtc_clock_config_t * clk_ptr)
Configures the SYSRTC input clock source frequency.
[in] | clk_ptr | Pointer to clock configuration structure sl_sysrtc_clock_config_t. |
It configures clock source as 32khz RC, 32khz RO or 1Khz RO clock source as per user input. For using 1KHz clock source, pass division factor value as '16' else pass '0'.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - Clock source parameter has an invalid value.
SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.
SL_STATUS_OK (0x0000) - Success, timer clock-source parameters configured properly.
134
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_configure_group#
sl_status_t sl_si91x_sysrtc_configure_group (sl_sysrtc_group_number_t group_number, sl_sysrtc_group_config_t const * config_ptr)
To configure the SYSRTC groups of compare and capture channels.
[in] | group_number | SYSRTC group number to be used. |
[in] | config_ptr | (const *) Pointer to group configuration structure sl_sysrtc_group_config_t. |
Configures group number and enables its compare & capture channels. Also configures match out actions for respective compare channel and input events for capture
Pre-conditions:
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - Counter direction parameter has an invalid value.
SL_STATUS_NULL_POINTER (0x0022) - The parameter is a null pointer.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
150
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_register_callback#
sl_status_t sl_si91x_sysrtc_register_callback (sl_sysrtc_callback_t on_sysrtc_callback, void * callback_flag_value, sl_sysrtc_group_number_t group_number, sl_sysrtc_interrupt_enables_t * interrupt_enable_ptr)
To register the callback of the timer interrupt.
[in] | on_sysrtc_callback | (function pointer) Callback function pointer to be called when timer interrupt occurred. |
[in] | callback_flag_value | (void *) pointer to interrupt flag value variable sl_sysrtc_callback_t. |
[in] | group_number | SYSRTC group number whose interrupts needs to be enabled. |
[in] | interrupt_enable_ptr | pointer to interrupt enable structure sl_sysrtc_interrupt_enables_t. |
Also enables the respective interrupts as per selected interrupt flags.
Pre-conditions:
sl_si91x_sysrtc_configure_group(), keep respective interrupt channel enable
sl_si91x_sysrtc_unregister_timeout_callback(), if already registered for any interrupt
Returns
status 0 if successful, else error code as follows:
SL_STATUS_NULL_POINTER (0x0022) - interrupt_enable_ptr parameter is a null pointer.
SL_STATUS_BUSY (0x0004) - The callback is already registered, unregister previous callback before registering a new one.
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number parameter has an invalid value.
SL_STATUS_OK (0x0000) - Successfully registered timer timeout callback.
173
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_unregister_callback#
sl_status_t sl_si91x_sysrtc_unregister_callback (sl_sysrtc_group_number_t group_number, sl_sysrtc_interrupt_enables_t * interrupt_enabled_handle)
Unregisters timer interrupt callback and disables interrupts as per selected interrupt flag.
[in] | group_number | pointer to interrupts enable structure sl_sysrtc_interrupt_enables_t. |
[in] | interrupt_enabled_handle | SYSRTC group number whose interrupts needs to be enabled. |
Pre-conditions:
sl_si91x_sysrtc_register_callback(), first register a particular interrupt flag.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number parameter has an invalid value.
SL_STATUS_NULL_POINTER (0x0022) - parameter is a null pointer.
SL_STATUS_OK (0x0000) - Successfully unregistered timer interrupt callback.
190
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_set_compare_value#
sl_status_t sl_si91x_sysrtc_set_compare_value (sl_sysrtc_group_number_t group_number, sl_sysrtc_channel_number_t channel, uint32_t compare_value)
Sets SYSRTC compare value for the selected channel of the given group.
[in] | group_number | SYSRTC group number to use. |
[in] | channel | Channel number to use. |
[in] | compare_value | Compare register value. |
Pre-conditions:
First enable the compare channel of the respective group through sl_si91x_sysrtc_configure_group.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number or channel parameter has an invalid value.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
205
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_get_compare_value#
sl_status_t sl_si91x_sysrtc_get_compare_value (sl_sysrtc_group_number_t group_number, sl_sysrtc_channel_number_t channel, uint32_t * compare_value)
Gets SYSRTC current compare register value for selected channel of selected group.
[in] | group_number | SYSRTC group number to use. |
[in] | channel | Channel number to use. |
[in] | compare_value | Pointer to the variable to store compare value read. |
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number or channel parameter has an invalid value.
SL_STATUS_NULL_POINTER (0x0022) - compare_value parameter is a null pointer.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
219
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_sets_register_capture_input#
sl_status_t sl_si91x_sysrtc_sets_register_capture_input (sl_sysrtc_group_number_t group_number)
Sets register-input for the capture channel of the selected group of SYSRTC.
[in] | group_number | SYSRTC group number to use. |
In other words, configures the SYSRTC Input (Capture) from register.
Pre-conditions:
First, enable and configure the capture channel of the respective group through sl_si91x_sysrtc_configure_group.
Disable GPIO input through sl_si91x_sysrtc_enable_input_output_gpio, by passing false.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number parameter has an invalid value.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
236
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_set_gpio_as_capture_input#
sl_status_t sl_si91x_sysrtc_set_gpio_as_capture_input (sl_sysrtc_group_number_t group_number)
Configures input pins for the SYSRTC capture channel of selected group.
[in] | group_number | SYSRTC group number to use. |
Configures gpio-0 and gpio-1 as input pins for the capture channel of group0 & group-1 respectively. Sets pins mode, mux and direction.
Pre-conditions:
First, enable and configure the capture channel of the respective group through sl_si91x_sysrtc_configure_group.
Enable GPIO IO through sl_si91x_sysrtc_enable_input_output_gpio, by passing true.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number parameter has an invalid value.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
253
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_set_compare_output_gpio#
sl_status_t sl_si91x_sysrtc_set_compare_output_gpio (sl_sysrtc_group_number_t group_number, sl_sysrtc_channel_number_t channel)
Configures the output pins of the selected compare channel of given group.
[in] | group_number | SYSRTC group number to use. |
[in] | channel | Channel number to use. |
Configures gpio-3 and gpio-4 as output pins for compare channel 0 & 1 of group0 respectively. Configures gpio-1 and gpio-2 as output pins for compare channel 0 & 1 of group1 respectively.. Sets pins mode, mux and direction. Also enables pins input buffer.
Pre-conditions:
First, enable and configure the output action of the compare channel of the respective group through
Returns
status 0 if successful, else error code as follows:
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number or channel parameter has an invalid value.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
271
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_get_count#
sl_status_t sl_si91x_sysrtc_get_count (uint32_t * count_value)
Gets the SYSRTC current counter register value.
[in] | count_value | Pointer to the variable to store count value read. |
Updates the current count of the timer to count_value input parameter. Returns
status 0 if successful, else error code as follows:
SL_STATUS_NULL_POINTER (0x0022) - count_value parameter is a null pointer.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
282
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_get_capture_value#
sl_status_t sl_si91x_sysrtc_get_capture_value (sl_sysrtc_group_number_t group_number, uint32_t * capture_value)
Gets the SYSRTC capture register value of a given group.
[in] | group_number | SYSRTC group number to use. |
[in] | capture_value | Pointer to the variable to store capture value read. |
Updates the capture count value of timer to capture_value input parameter. Returns
status 0 if successful, else error code as follows:
SL_STATUS_NULL_POINTER (0x0022) - capture_value parameter is a null pointer.
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number parameter has an invalid value.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
294
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_get_compare_output#
sl_status_t sl_si91x_sysrtc_get_compare_output (sl_sysrtc_group_number_t group_number, sl_sysrtc_channel_number_t channel, uint32_t * compare_output_bit)
Reads the SYSRTC compare channel output bit value of a given group.
[in] | group_number | SYSRTC group number to use. |
[in] | channel | Channel number to use. |
[in] | compare_output_bit | Pointer to the variable to store compare output. |
Updates the bit value to compare_output_bit input parameter.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_NULL_POINTER (0x0022) - compare_output parameter is a null pointer.
SL_STATUS_INVALID_PARAMETER (0x0021) - group_number or channel parameter has an invalid value.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
311
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_is_running#
sl_status_t sl_si91x_sysrtc_is_running (boolean_t * running_status)
Gets the SYSRTC running status, status is true if running, false if stopped.
[in] | running_status | Pointer to the variable to store the SYSRTC running status. |
Updates 'true' if SYSRTC is running else 'false' if not running, to the running_status input parameter.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_NULL_POINTER (0x0022) - running_status parameter is a null pointer.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
326
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_is_locked#
sl_status_t sl_si91x_sysrtc_is_locked (boolean_t * lock_status)
Gets the SYSRTC lock status.
[in] | lock_status | Pointer to the variable to store SYSRTC lock status. |
Updates 'true' if SYSRTC is locked, 'false' if unlocked, to the lock_status input parameter.
Returns
status 0 if successful, else error code as follows:
SL_STATUS_NULL_POINTER (0x0022) - lock_status parameter is a null pointer.
SL_STATUS_OK (0x0000) - Success, parameters configured properly.
339
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_enable_input_output_gpio#
void sl_si91x_sysrtc_enable_input_output_gpio (bool is_gpio_enabled)
Sets the SYSRTC input output mode for the capture and compare channels.
[in] | is_gpio_enabled | Bool to enable or disable IO through GPIO. |
If passed true, then input to capture channel and output of compare channel will be through GPIO, else disabled.
Returns
none
350
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_start#
__STATIC_INLINE void sl_si91x_sysrtc_start (void )
Starts the SYSRTC counter.
N/A |
This function will send a start command to the SYSRTC peripheral. It waits till the start command to be executed.
Pre-conditions:
sl_si91x_sysrtc_configure_clock(), keep software trigger disable here
sl_si91x_sysrtc_configure_group(), keep respective interrupt channel enable
sl_si91x_sysrtc_register_callback, keep respective interrupt enabled
Returns
none
Note
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 rsi_sysrtc_wait_sync() function is used to wait for the start command to be executed.
369
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_stop#
__STATIC_INLINE void sl_si91x_sysrtc_stop (void )
Stops the SYSRTC counter.
N/A |
This function will send a stop command to the SYSRTC peripheral. It waits till the stop command to be executed.
Returns
none
Note
This function requires the SYSRTC to be enabled.
385
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_reset#
__STATIC_INLINE void sl_si91x_sysrtc_reset (void )
Restores the SYSRTC to its reset state.
N/A |
Returns
none
397
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_lock#
__STATIC_INLINE void sl_si91x_sysrtc_lock (void )
Locks the SYSRTC registers.
N/A |
When SYSRTC registers are locked SYSRTC_EN, SYSRTC_CFG, SYSRTC_CMD, SYSRTC_SWRST, SYSRTC_CNT and SYSRTC_TOPCNT registers cannot be written to. Returns
none
409
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_unlock#
__STATIC_INLINE void sl_si91x_sysrtc_unlock (void )
Unlocks the SYSRTC registers.
N/A |
When SYSRTC registers are locked SYSRTC_EN, SYSRTC_CFG, SYSRTC_CMD, SYSRTC_SWRST, SYSRTC_CNT and SYSRTC_TOPCNT registers cannot be written to.
Pre-condition:
Returns
none
423
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_set_count#
__STATIC_INLINE void sl_si91x_sysrtc_set_count (uint32_t value)
Sets the SYSRTC counter register value of counter This can be used to change the count of SYSRTC, when it is stopped.
[in] | value | The new SYSRTC counter value. |
After calling this API user should start SYSRTC.
Pre-condition:
Returns
none
437
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_get_version#
sl_sysrtc_version_t sl_si91x_sysrtc_get_version (void )
Gets the SYSRTC version It returns API version of SYSRTC.
[in] |
Returns
(sl_sysrtc_version_t) type structure.
448
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h
sl_si91x_sysrtc_deinit#
void sl_si91x_sysrtc_deinit (void )
De-initializes the SYSRTC by disabling its clock.
[in] |
Returns
none
Note
Unregisters the SYSRTC callback and disables all interrupts.
456
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_sysrtc.h