2.96 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 1 Hz 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

NameDescription
RTT_InitializeInitialize the RTT peripheral
RTT_EnableEnables the Real Time Timer
RTT_DisableDisables the real Time Timer
RTT_PrescalarUpdateUpdates the prescalar for the RTT peripheral
RTT_AlarmValueSetSets the Alarm value for the RTT peripheral
RTT_EnableInterruptEnable RTT interrupts
RTT_DisableInterruptDisable RTT interrupts
RTT_TimerValueGetReturns the current timer value
RTT_FrequencyGetReturns the current RTT frequency
RTT_CallbackRegisterSets the pointer to the function (and it's context) to be called

Data types and constants

NameTypeDescription
RTT_INTERRUPT_TYPEEnumDefines the data type for the RTT INTERRUPT TYPE
RTT_CALLBACKTypedefDefines the data type and function signature for the RTT peripheral callback function
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.