1.42.16 Real-time Timer (RTT)

The RTT is built around a 32-bit counter used to count roll-over events of the programmable 16-bit prescaler driven from the 32-kHz slow clock source.

The RTT can also be configured to be driven by the 1Hz RTC signal, thus taking advantage of a calibrated 1Hz clock.

Using The Library

The RTT peripheral generates a periodic interrupt and/or triggers an alarm on a programmed value.

  • Periodic interrupt is generated when the prescaler roll over generates the clock to increment real-time timer counter

  • Alarm interrupt is generated when the time value matches the programmed alarm value The RTT continues to run in the device's low-power sleep modes, and it can be used as a source to wake up the system using the alarm function.

Periodic Interrupt

This example below demonstrates how to use RTT for periodic interrupt generation.

void Timeout_Handler (RTT_INTERRUPT_TYPE type, uintptr_t context)
{
    if(type == RTT_PERIODIC)
    {
        LED_Toggle();
    }
}

int main ( void )
{

    /* Register Callback */
    RTT0_CallbackRegister(Timeout_Handler, (uintptr_t) NULL);

    /* Enable RTT */
    RTT0_Enable();


    while ( true )
    {

    }

}

The below example demonstrates how to set alarm and watch it being triggered when the timer reaches the corresponding value.

void Timeout_Handler (RTT_INTERRUPT_TYPE type, uintptr_t context)
{
    if(type == RTT_ALARM)
    {
        // Alarm has occurred
    }
}

int main ( void )
{

    /* Register Callback */
    RTT0_CallbackRegister(Timeout_Handler, (uintptr_t) NULL);

    /* Set Alarm Value */
    RTT_AlarmValueSet(10);

    /* Enable RTT */
    RTT0_Enable();

    while ( true )
    {

    }

}

Library Interface

Real-time Timer peripheral library provides the following interfaces:

Functions

Name Description
RTT_Initialize Initialize the RTT peripheral
RTT_Enable Enables the Real Time Timer
RTT_Disable Disables the real Time Timer
RTT_PrescalarUpdate Updates the prescalar for the RTT peripheral
RTT_AlarmValueSet Sets the Alarm value for the RTT peripheral
RTT_EnableInterrupt Enable RTT interrupts
RTT_DisableInterrupt Disable RTT interrupts
RTT_TimerValueGet Returns the current timer value
RTT_FrequencyGet Returns the current RTT frequency
RTT_CallbackRegister Sets the pointer to the function (and it's context) to be called

Data types and constants

Name Type Description
RTT_INTERRUPT_TYPE Enum Defines the data type for the RTT INTERRUPT TYPE
RTT_CALLBACK Typedef Defines the data type and function signature for the RTT peripheral callback function
RTT_OBJECT Struct Defines the data type for the RTT OBJECT