This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Trying to use TIMER2 for FreeRTOS tick with SoftDevice running

Hi,

The established time tick source for FreeRTOS is RTC1 via the APP_TIMER module. I am trying to shift the basis of the APP_TIMER from RTC1 to TIMER2, so that I can use RTC1 to maintain calendar time. I intend to sleep the processor, waking on an external interrupt. Since RTC1 is low power timer, I was planning on keeping that running while the processor was mostly shut down and waiting for the wake-on-interrupt.

Is there any guidance on shifting the APP_TIMER module from RTC1 to TIMER2?

Thanks!

  • Is this an ARM Cortex-M device? If so, then the generic port uses the SysTick timer to generate the tick interrupt by default - but the timer functions are weak symbols, allowing them to be overridden by application code - which seems to be the case here if RTC1 is being used. If RTC1 is a low power timer, then I suspect it is being used so the FreeRTOS's low power tick-less features can be used to greater effect than when using SysTick.

    If you are not using the tick-less features then it is a matter of

    1. Writing code that generates an interrupt at the desired frequency. Call the function that sets up the interrupt vPortSetupTimerInterrupt(), so it replaces the default function of that name.

    2. Install the FreeRTOS tick interrupt handler as the handler for the interrupt. The easiest way of doing that is to install xPortSysTickHandler() systick handler and the handler - xPortSysTickHandler() is defined in the FreeRTOS/Source/portable/[compiler]/[architecture]/port.c file used by your build.

    If you are using the tick-less features then it is a bit more complex, as you need to reprogram the timer before and after going to sleep. I suggest you use whatever is currently provided to you as a reference, along with www.freertos.org/low-power-tickless-rtos.html

  • nFR51 is a Cortex-M0 device but without the SysTick feature. nRF52 has Systick.

  • I wrote an earlier port of FreeRTOS for the nRF51. I have not yet migrated our own code to use the SDK versio of the FreeRTOS yet. I'm not 100% sure of this yet, but probably you can share the RTC1.

    There is no problem putting FreeRTOS into sleep on nRF51. It could be enough it you compile it with configUSE_TICKLESS_IDLE and configUSE_IDLE_HOOK enabled and add the following idle hook:

    void vApplicationIdleHook( void ) {
        /*
           This signals the softdevice handler that we want the CPU to
           sleep until an event/interrupt occurs. During this time the
           softdevice will do what it needs to do; in our case: send
           adverts
        */
    
        uint32_t err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
    

    I'm interested in hearing your experiences.

    Pertti

  • Yes, the processor in question is the nRF51822-QFAC. Once I get the tick to use something other than RTC1, we plan on using the tick-less feature going forward.

    Currently, we are using the tick as follows:

    static void systick_timeout_handler (void * p_context)
    {
        void xPortSysTickHandler (void);
        UNUSED_PARAMETER(p_context);
        tick_cnt++;
        xPortSysTickHandler ();
    }
    

    However, first thing is first -- moving over to TIMER2.

    Thanks!

Related