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#

  • Below functions will initiate and configure the SYSRTC, which is the general flow for implementation:

  1. sl_si91x_sysrtc_configure_clock

  2. sl_si91x_sysrtc_init

  3. sl_si91x_sysrtc_configure_group

  4. sl_si91x_sysrtc_register_callback

  5. sl_si91x_sysrtc_set_count

  6. sl_si91x_sysrtc_set_compare_value (If compare channel is enabled)

  7. sl_si91x_sysrtc_is_running (If required to check timer running status)

  8. sl_si91x_sysrtc_start

  9. sl_si91x_sysrtc_get_count (If required to check timer current count)

  10. sl_si91x_sysrtc_stop

  11. sl_si91x_sysrtc_deinit

Modules#

sl_sysrtc_clock_config_t

sl_sysrtc_interrupt_enables_t

sl_sysrtc_version_t

Enumerations#

enum
SL_SYSRTC_GROUP_0
SL_SYSRTC_GROUP_1
SL_SYSRTC_GROUP_LAST
}

Enumeration to represent SYSRTC group numbers.

enum
SL_SYSRTC_CHANNEL_0
SL_SYSRTC_CHANNEL_1
SL_SYSRTC_CHANNEL_LAST
}

Enumeration to represent SYSRTC channel numbers.

Typedefs#

typedef rsi_sysrtc_clk_inp_t
typedef rsi_sysrtc_config_t
typedef rsi_sysrtc_group_config_t
typedef rsi_sysrtc_group_channel_compare_config_t
typedef rsi_sysrtc_group_channel_capture_config_t
typedef void(*
sl_sysrtc_callback_t)(void *callback_flag)

Typedef for the function pointer of the interrupt callback function.

Functions#

sl_status_t
sl_si91x_sysrtc_init(const sl_sysrtc_config_t *config_ptr)

Initializes SYSRTC and enables the peripheral.

sl_status_t
sl_si91x_sysrtc_configure_clock(sl_sysrtc_clock_config_t *clk_ptr)

Configures the SYSRTC input clock source frequency.

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.

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.

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.

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.

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.

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.

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.

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.

sl_status_t
sl_si91x_sysrtc_get_count(uint32_t *count_value)

Gets the SYSRTC current counter register 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.

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.

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.

sl_status_t
sl_si91x_sysrtc_is_locked(boolean_t *lock_status)

Gets the SYSRTC lock status.

void

Sets the SYSRTC input output mode for the capture and compare channels.

__STATIC_INLINE void

Starts the SYSRTC counter.

__STATIC_INLINE void

Stops the SYSRTC counter.

__STATIC_INLINE void

Restores the SYSRTC to its reset state.

__STATIC_INLINE void

Locks the SYSRTC registers.

__STATIC_INLINE void

Unlocks the SYSRTC registers.

__STATIC_INLINE void

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.

void

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.


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.


Typedef Documentation#

sl_clock_sources_t#

typedef rsi_sysrtc_clk_inp_t sl_clock_sources_t

sl_sysrtc_config_t#

typedef rsi_sysrtc_config_t sl_sysrtc_config_t

sl_sysrtc_group_config_t#

typedef rsi_sysrtc_group_config_t sl_sysrtc_group_config_t

sl_sysrtc_group_compare_channel_action_config_t#

typedef rsi_sysrtc_group_channel_compare_config_t sl_sysrtc_group_compare_channel_action_config_t

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

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.

Parameters
TypeDirectionArgument NameDescription
N/Acallback_flag

(void *) parameter for updating flag values


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.

Parameters
TypeDirectionArgument NameDescription
const sl_sysrtc_config_t *[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.

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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_clock_config_t *[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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

SYSRTC group number to be used.

sl_sysrtc_group_config_t const *[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

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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_callback_t[in]on_sysrtc_callback

(function pointer) Callback function pointer to be called when timer interrupt occurred.

void *[in]callback_flag_value

(void *) pointer to interrupt flag value variable sl_sysrtc_callback_t.

sl_sysrtc_group_number_t[in]group_number

SYSRTC group number whose interrupts needs to be enabled.

sl_sysrtc_interrupt_enables_t *[in]interrupt_enable_ptr

pointer to interrupt enable structure sl_sysrtc_interrupt_enables_t.

Also enables the respective interrupts as per selected interrupt flags.

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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

pointer to interrupts enable structure sl_sysrtc_interrupt_enables_t.

sl_sysrtc_interrupt_enables_t *[in]interrupt_enabled_handle

SYSRTC group number whose interrupts needs to be enabled.

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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

SYSRTC group number to use.

sl_sysrtc_channel_number_t[in]channel

Channel number to use.

uint32_t[in]compare_value

Compare register value.

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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

SYSRTC group number to use.

sl_sysrtc_channel_number_t[in]channel

Channel number to use.

uint32_t *[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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

SYSRTC group number to use.

In other words, configures the SYSRTC Input (Capture) from register.

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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[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.

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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

SYSRTC group number to use.

sl_sysrtc_channel_number_t[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.

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.


sl_si91x_sysrtc_get_count#

sl_status_t sl_si91x_sysrtc_get_count (uint32_t * count_value)

Gets the SYSRTC current counter register value.

Parameters
TypeDirectionArgument NameDescription
uint32_t *[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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

SYSRTC group number to use.

uint32_t *[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.


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.

Parameters
TypeDirectionArgument NameDescription
sl_sysrtc_group_number_t[in]group_number

SYSRTC group number to use.

sl_sysrtc_channel_number_t[in]channel

Channel number to use.

uint32_t *[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.


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.

Parameters
TypeDirectionArgument NameDescription
boolean_t *[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.


sl_si91x_sysrtc_is_locked#

sl_status_t sl_si91x_sysrtc_is_locked (boolean_t * lock_status)

Gets the SYSRTC lock status.

Parameters
TypeDirectionArgument NameDescription
boolean_t *[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.


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.

Parameters
TypeDirectionArgument NameDescription
bool[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


sl_si91x_sysrtc_start#

__STATIC_INLINE void sl_si91x_sysrtc_start (void )

Starts the SYSRTC counter.

Parameters
TypeDirectionArgument NameDescription
voidN/A

This function will send a start command to the SYSRTC peripheral. It waits till the start command to be executed.

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.


sl_si91x_sysrtc_stop#

__STATIC_INLINE void sl_si91x_sysrtc_stop (void )

Stops the SYSRTC counter.

Parameters
TypeDirectionArgument NameDescription
voidN/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.


sl_si91x_sysrtc_reset#

__STATIC_INLINE void sl_si91x_sysrtc_reset (void )

Restores the SYSRTC to its reset state.

Parameters
TypeDirectionArgument NameDescription
voidN/A

Returns

  • none


sl_si91x_sysrtc_lock#

__STATIC_INLINE void sl_si91x_sysrtc_lock (void )

Locks the SYSRTC registers.

Parameters
TypeDirectionArgument NameDescription
voidN/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


sl_si91x_sysrtc_unlock#

__STATIC_INLINE void sl_si91x_sysrtc_unlock (void )

Unlocks the SYSRTC registers.

Parameters
TypeDirectionArgument NameDescription
voidN/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


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.

Parameters
TypeDirectionArgument NameDescription
uint32_t[in]value

The new SYSRTC counter value.

After calling this API user should start SYSRTC.

Returns

  • none


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.

Parameters
TypeDirectionArgument NameDescription
void[in]

Returns


sl_si91x_sysrtc_deinit#

void sl_si91x_sysrtc_deinit (void )

De-initializes the SYSRTC by disabling its clock.

Parameters
TypeDirectionArgument NameDescription
void[in]

Returns

  • none

Note

  • Unregisters the SYSRTC callback and disables all interrupts.