RTCC - Real Time Clock with Capture#
Example#
This example demonstrates how to initialize the RTCC, configure channels for compare mode, set compare values, and handle interrupts.
#include "sl_hal_rtcc.h"
// Flag to indicate compare match event occurred
volatile bool compare_match = false;
// RTCC interrupt handler
void RTCC_IRQHandler(void)
{
// Get enabled and pending interrupts
uint32_t flags = sl_hal_rtcc_get_enabled_interrupts();
// Check if CC0 interrupt is triggered
if (flags & RTCC_IF_CC0) {
// Clear the interrupt flag
sl_hal_rtcc_clear_interrupts(RTCC_IF_CC0);
// Set flag to indicate match
compare_match = true;
}
}
void rtcc_example(void)
{
// Initialize RTCC with default settings
sl_hal_rtcc_init_t rtcc_init = SL_HAL_RTCC_INIT_DEFAULT;
sl_hal_rtcc_init(&rtcc_init);
// Configure channel 0 for compare mode
sl_hal_rtcc_cc_init_t cc_init = SL_HAL_RTCC_CH_INIT_COMPARE_DEFAULT;
sl_hal_rtcc_channel_init(0, &cc_init);
// Set compare value for channel 0
sl_hal_rtcc_set_channel_compare_value(0, 1000); // 1000 counts
// Reset counter
sl_hal_rtcc_set_counter(0);
// Clear any pending interrupt flags
sl_hal_rtcc_clear_interrupts(_RTCC_IF_MASK);
// Enable interrupts for CC0
sl_hal_rtcc_enable_interrupts(RTCC_IEN_CC0);
// Enable NVIC interrupt for RTCC
sl_interrupt_manager_enable_irq(RTCC_IRQn);
// Enable RTCC module
sl_hal_rtcc_enable();
// Start RTCC counter
sl_hal_rtcc_start();
// Wait for compare match
while (!compare_match) {
// Could enter low power mode here
}
// Reset flag
compare_match = false;
// Stop RTCC
sl_hal_rtcc_stop();
}
Modules#
Enumerations#
Counter prescaler selection.
Prescaler mode of the RTCC counter.
Capture/Compare channel mode.
Compare match output action mode.
Input edge select.
Capture/Compare channel compare mode.
Typedefs#
PRS channel number.
Functions#
Initialize RTCC.
Configure the selected capture/compare channel of the RTCC.
Restore RTCC to its reset state.
Wait for the RTCC to complete all synchronization of register changes and commands.
Enable RTCC counting.
Disable RTCC counting.
Start the RTCC counter.
Stop the RTCC counter.
Get the RTCC compare register value for a selected channel.
Set the RTCC compare register value for a selected channel.
Get the RTCC input capture register value for a selected channel.
Get the RTCC capture/compare register value for a selected channel.
Set RTCC capture/compare register value for a selected channel.
Get the combined CNT/PRECNT register content.
Get the RTCC counter value.
Set the RTCC CNT counter.
Clear one or more pending RTCC interrupts.
Disable one or more RTCC interrupts.
Enable one or more RTCC interrupts.
Get pending RTCC interrupt flags.
Get enabled and pending RTCC interrupt flags.
Set one or more pending RTCC interrupts from SW.
Lock RTCC registers.
Unlock RTCC registers.
Get the RTCC pre-counter value.
Set the RTCC pre-counter value.
Get the STATUS register value.
Macros#
Validation of valid RTCC channel for assert statements.
Default RTCC initialization structure.
Default RTCC channel output compare initialization structure.
Default RTCC channel input capture initialization structure.
Enumeration Documentation#
sl_hal_rtcc_counter_prescaler_t#
sl_hal_rtcc_counter_prescaler_t
Counter prescaler selection.
Enumerator | |
---|---|
SL_HAL_RTCC_COUNTER_PRESCALER_1 | Divide clock by 1. |
SL_HAL_RTCC_COUNTER_PRESCALER_2 | Divide clock by 2. |
SL_HAL_RTCC_COUNTER_PRESCALER_4 | Divide clock by 4. |
SL_HAL_RTCC_COUNTER_PRESCALER_8 | Divide clock by 8. |
SL_HAL_RTCC_COUNTER_PRESCALER_16 | Divide clock by 16. |
SL_HAL_RTCC_COUNTER_PRESCALER_32 | Divide clock by 32. |
SL_HAL_RTCC_COUNTER_PRESCALER_64 | Divide clock by 64. |
SL_HAL_RTCC_COUNTER_PRESCALER_128 | Divide clock by 128. |
SL_HAL_RTCC_COUNTER_PRESCALER_256 | Divide clock by 256. |
SL_HAL_RTCC_COUNTER_PRESCALER_512 | Divide clock by 512. |
SL_HAL_RTCC_COUNTER_PRESCALER_1024 | Divide clock by 1024. |
SL_HAL_RTCC_COUNTER_PRESCALER_2048 | Divide clock by 2048. |
SL_HAL_RTCC_COUNTER_PRESCALER_4096 | Divide clock by 4096. |
SL_HAL_RTCC_COUNTER_PRESCALER_8192 | Divide clock by 8192. |
SL_HAL_RTCC_COUNTER_PRESCALER_16384 | Divide clock by 16384. |
SL_HAL_RTCC_COUNTER_PRESCALER_32768 | Divide clock by 32768. |
sl_hal_rtcc_prescaler_mode_t#
sl_hal_rtcc_prescaler_mode_t
Prescaler mode of the RTCC counter.
Enumerator | |
---|---|
SL_HAL_RTCC_COUNTER_TICK_PRESCALER | CNT register ticks according to prescaler value. |
SL_HAL_RTCC_COUNTER_TICK_CCV_0_MATCH | CNT register ticks when PRECNT matches the 15 least significant bits of ch. |
sl_hal_rtcc_capture_compare_channel_mode_t#
sl_hal_rtcc_capture_compare_channel_mode_t
Capture/Compare channel mode.
Enumerator | |
---|---|
SL_HAL_RTCC_CAPTURE_COMPARE_CHANNEL_MODE_OFF | Capture/Compare channel turned off. |
SL_HAL_RTCC_CAPTURE_COMPARE_CHANNEL_MODE_CAPTURE | Capture mode. |
SL_HAL_RTCC_CAPTURE_COMPARE_CHANNEL_MODE_COMPARE | Compare mode. |
sl_hal_rtcc_compare_match_out_action_t#
sl_hal_rtcc_compare_match_out_action_t
Compare match output action mode.
Enumerator | |
---|---|
SL_HAL_RTCC_COMPARE_MATCH_OUT_ACTION_PULSE | Generate a pulse. |
SL_HAL_RTCC_COMPARE_MATCH_OUT_ACTION_TOGGLE | Toggle output. |
SL_HAL_RTCC_COMPARE_MATCH_OUT_ACTION_CLEAR | Clear output. |
SL_HAL_RTCC_COMPARE_MATCH_OUT_ACTION_SET | Set output. |
sl_hal_rtcc_in_edge_select_t#
sl_hal_rtcc_in_edge_select_t
Input edge select.
Enumerator | |
---|---|
SL_HAL_RTCC_IN_EDGE_RISING | Rising edges detected. |
SL_HAL_RTCC_IN_EDGE_FALLING | Falling edges detected. |
SL_HAL_RTCC_IN_EDGE_BOTH | Both edges detected. |
SL_HAL_RTCC_IN_EDGE_NONE | No edge detection, signal is left as is. |
sl_hal_rtcc_compare_base_t#
sl_hal_rtcc_compare_base_t
Capture/Compare channel compare mode.
Enumerator | |
---|---|
SL_HAL_RTCC_COMPBASE_COUNTER_MODE | CCVx is compared with the CNT register. |
SL_HAL_RTCC_COMPARE_PRE_COUNTER_MODE | CCVx is compared with a CNT[16:0] and PRECNT[14:0]. |
Typedef Documentation#
sl_hal_rtcc_prs_select_t#
typedef uint8_t sl_hal_rtcc_prs_select_t
PRS channel number.
This type is used when configuring input capture mode on a RTCC channel.
Function Documentation#
sl_hal_rtcc_init#
void sl_hal_rtcc_init (const sl_hal_rtcc_init_t * init)
Initialize RTCC.
Type | Direction | Argument Name | Description |
---|---|---|---|
const sl_hal_rtcc_init_t * | [in] | init | A pointer to the RTCC initialization structure. |
Note that the compare values must be set separately with sl_hal_rtcc_set_channel_compare_value(), which should probably be done prior to the use of this function if configuring the RTCC to start when initialization is completed.
sl_hal_rtcc_channel_init#
void sl_hal_rtcc_channel_init (uint32_t channel, const sl_hal_rtcc_cc_init_t * init)
Configure the selected capture/compare channel of the RTCC.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | channel | A channel selector. |
const sl_hal_rtcc_cc_init_t * | [in] | init | A pointer to the RTCC channel initialization structure. |
Use this function to configure an RTCC channel. Select capture/compare mode, match output action, overflow output action, and PRS input configuration. See the configuration structure sl_hal_rtcc_cc_init_t for more details.
sl_hal_rtcc_reset#
void sl_hal_rtcc_reset (void )
Restore RTCC to its reset state.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_rtcc_wait_sync#
void sl_hal_rtcc_wait_sync (void )
Wait for the RTCC to complete all synchronization of register changes and commands.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_rtcc_enable#
void sl_hal_rtcc_enable (void )
Enable RTCC counting.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_rtcc_disable#
void sl_hal_rtcc_disable (void )
Disable RTCC counting.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
sl_hal_rtcc_start#
void sl_hal_rtcc_start (void )
Start the RTCC counter.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function will send a start command to the RTCC peripheral. The RTCC peripheral will use some LF clock ticks before the command is executed. The sl_hal_rtcc_wait_sync() function can be used to wait for the start command to be executed.
Note
This function requires the RTCC to be enabled.
sl_hal_rtcc_stop#
void sl_hal_rtcc_stop (void )
Stop the RTCC counter.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function will send a stop command to the RTCC peripheral. The RTCC peripheral will use some LF clock ticks before the command is executed. The sl_hal_rtcc_wait_sync() function can be used to wait for the stop command to be executed.
Note
This function requires the RTCC to be enabled.
sl_hal_rtcc_get_channel_compare_value#
uint32_t sl_hal_rtcc_get_channel_compare_value (uint32_t channel)
Get the RTCC compare register value for a selected channel.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | channel | Channel selector. |
Returns
Compare register value.
sl_hal_rtcc_set_channel_compare_value#
void sl_hal_rtcc_set_channel_compare_value (uint32_t channel, uint32_t value)
Set the RTCC compare register value for a selected channel.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | channel | Channel selector. |
uint32_t | [in] | value | Compare register value |
sl_hal_rtcc_get_channel_capture_value#
uint32_t sl_hal_rtcc_get_channel_capture_value (uint32_t channel)
Get the RTCC input capture register value for a selected channel.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | channel | Channel selector. |
Returns
Capture register value.
sl_hal_rtcc_get_channel_ccv#
uint32_t sl_hal_rtcc_get_channel_ccv (uint32_t channel)
Get the RTCC capture/compare register value for a selected channel.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | channel | Channel selector. |
For parts with separate capture compare value registers, this function returns the compare value.
Returns
Capture/compare register value.
sl_hal_rtcc_set_channel_ccv#
void sl_hal_rtcc_set_channel_ccv (uint32_t channel, uint32_t value)
Set RTCC capture/compare register value for a selected channel.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | channel | Channel selector. |
uint32_t | [in] | value | Capture/compare register value |
For parts with separate capture compare value registers, this function sets the compare value.
sl_hal_rtcc_get_combined_counter#
uint32_t sl_hal_rtcc_get_combined_counter (void )
Get the combined CNT/PRECNT register content.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
CNT/PRECNT register value.
sl_hal_rtcc_get_counter#
uint32_t sl_hal_rtcc_get_counter (void )
Get the RTCC counter value.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Current RTCC counter value.
sl_hal_rtcc_set_counter#
void sl_hal_rtcc_set_counter (uint32_t value)
Set the RTCC CNT counter.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | value | CNT value. |
sl_hal_rtcc_clear_interrupts#
void sl_hal_rtcc_clear_interrupts (uint32_t flags)
Clear one or more pending RTCC interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | flags | RTCC interrupt sources to clear. Use a set of interrupt flags OR-ed together to clear multiple interrupt sources. |
sl_hal_rtcc_disable_interrupts#
void sl_hal_rtcc_disable_interrupts (uint32_t flags)
Disable one or more RTCC interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | flags | RTCC interrupt sources to disable. Use a set of interrupt flags OR-ed together to disable multiple interrupt. |
sl_hal_rtcc_enable_interrupts#
void sl_hal_rtcc_enable_interrupts (uint32_t flags)
Enable one or more RTCC interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | flags | RTCC interrupt sources to enable. Use a set of interrupt flags OR-ed together to set multiple interrupt. |
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_rtcc_clear_interrupts() prior to enabling the interrupt.
sl_hal_rtcc_get_pending_interrupts#
uint32_t sl_hal_rtcc_get_pending_interrupts (void )
Get pending RTCC interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Pending RTCC interrupt sources. Returns a set of interrupt flags OR-ed together for the interrupt sources set.
Note
Event bits are not cleared by using this function.
sl_hal_rtcc_get_enabled_interrupts#
uint32_t sl_hal_rtcc_get_enabled_interrupts (void )
Get enabled and pending RTCC interrupt flags.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Pending and enabled RTCC interrupt sources. Returns a set of interrupt flags OR-ed together for the interrupt sources set.
Useful for handling more interrupt sources in the same interrupt handler.
sl_hal_rtcc_set_interrupts#
void sl_hal_rtcc_set_interrupts (uint32_t flags)
Set one or more pending RTCC interrupts from SW.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | flags | RTCC interrupt sources to set to pending. Use a set of interrupt flags (RTCC_IFS_nnn). |
sl_hal_rtcc_lock#
void sl_hal_rtcc_lock (void )
Lock RTCC registers.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Note
When RTCC registers are locked, RTCC_CTRL, RTCC_PRECNT, RTCC_CNT, RTCC_TIME, RTCC_DATE, RTCC_IEN, RTCC_POWERDOWN and RTCC_CCx_XXX registers cannot be written to.
sl_hal_rtcc_unlock#
void sl_hal_rtcc_unlock (void )
Unlock RTCC registers.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Note
When RTCC registers are locked, RTCC_CTRL, RTCC_PRECNT, RTCC_CNT, RTCC_TIME, RTCC_DATE, RTCC_IEN, RTCC_POWERDOWN and RTCC_CCx_XXX registers cannot be written to.
sl_hal_rtcc_get_pre_counter#
uint32_t sl_hal_rtcc_get_pre_counter (void )
Get the RTCC pre-counter value.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Current RTCC pre-counter value.
sl_hal_rtcc_set_pre_counter#
void sl_hal_rtcc_set_pre_counter (uint32_t pre_counter_value)
Set the RTCC pre-counter value.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | pre_counter_value | RTCC pre-counter value to be set. |
sl_hal_rtcc_get_status#
uint32_t sl_hal_rtcc_get_status (void )
Get the STATUS register value.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
Returns
Current STATUS register value.