2.95 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 registered 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

RTOS Timer peripheral library provides the following interfaces:

Functions

NameDescription
RTOSTimer_InitializeInitializes given instance of RTOS timer peripheral.
RTOSTimer_PeriodGetReturns the period value for the RTOS timer
RTOSTimer_PeriodSetSets the time period for the RTOS timer
RTOSTimer_ResumeResumes the RTOS timer
RTOSTimer_StartStarts the RTOS timer
RTOSTimer_StopStops the RTOS timer
RTOSTimer_HaltHalts the RTOS timer
RTOSTimer_FrequencyGetReturns the input frequency of the RTOS timer
RTOSTimer_CounterGetReturns the timer counter value for the RTOS timer
RTOSTimer_CallbackRegisterAllows application to register a callback with the PLIB

Data types and constants

NameTypeDescription
RTOS_TMR_CALLBACKTypedefDefines the data type and function signature for the RTOS timer peripheral callback function.
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.