1.1.10 RTOS Timer

The RTOS Timer is a low-power, 32-bit timer designed to operate on the 32kHz oscillator which is always available

during all chip sleep states. This allows firmware the option to sleep the processor and wake after a programmed amount

of time. The timer may be used as a one-shot timer or a continuous timer. When the timer transitions to 0 it is capable

of generating a wake-capable interrupt to the embedded controller. This timer may be halted during debug by hardware

or via a software control bit

Using the Library

The below example generates periodic timeout using the RTOS peripheral. A callback is registed with the RTOS timer and an LED is toggled in the callback function.
void rtos_tmr_callback(uintptr_t context)
{
    LED0_Toggle();
}

int main ( void )
{
    /* Initialize all modules */
    SYS_Initialize ( NULL );
    
    RTOSTimer_CallbackRegister(rtos_tmr_callback, 0);
    
    RTOSTimer_Start();

    while ( true )
    {
        /* Maintain state machines of all polled MPLAB Harmony modules. */
        SYS_Tasks ( );
    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}

Library Interface

Functions
Name Description
RTOSTimer_Initialize Initializes given instance of RTOS timer peripheral.
RTOSTimer_PeriodGet Returns the period value for the RTOS timer
RTOSTimer_PeriodSet Sets the time period for the RTOS timer
RTOSTimer_Resume Resumes the RTOS timer
RTOSTimer_Start Starts the RTOS timer
RTOSTimer_Stop Stops the RTOS timer
RTOSTimer_Halt Halts the RTOS timer
RTOSTimer_FrequencyGet Returns the input frequency of the RTOS timer
RTOSTimer_CounterGet Returns the timer counter value for the RTOS timer
RTOSTimer_CallbackRegister Allows application to register a callback with the PLIB
Data types and constants
Name Type Description
RTOS_TMR_CALLBACK Typedef Defines the data type and function signature for the RTOS timer peripheral callback function.