CC2340R5: Timer Interrupt with FreeRTOS and BLE Low Power

Part Number: CC2340R5

Tool/software:

Hello,

I am developing a code where i want to perform a specific task on defined interval.This means I need a timer interrupt which works with low power state as well. When the task is not running device will go into low power state. Can any one please help me with this?

For more details. I am using data stream code example. Now on top of that let say want to toggle led on every defined interval to show case device state. What will be the approach for this task. I think timer interrupt will work but any other better suggestion will always welcome.

Thanks
Bhavik

  • Hello Bhavik,

    Please see the Timers section of the BLE5-Stack User's Guide.  I recommend using the ClockP module as it is available through standby mode and includes callback operations.  There is even a usage example in this SLA.

    Regards,
    Ryan

  • Hello Ryan,

    Thanks for the details. To be honest it very confusing and difficult to understand. Let me put down my requirement to get proper recommendation.

    I am using data stream code example where i integrate a sensor from which i want to get data ever x minute and send it via BLE.

    How to achieve this by keeping low power in mind.

    FYI on page calculator is not working and formula is also not given.


    Thanks
    Bhavik

  • I am using data stream code example where i integrate a sensor from which i want to get data ever x minute and send it via BLE.

    How to achieve this by keeping low power in mind.

    Please post a new E2E question if you are looking for advice outside of the low-power timer, the original question which has been answered.  You should perform initial development evaluation and provide specific questions as to the issues you are encountering.

    FYI on page calculator is not working and formula is also not given.

    Agreed, here is ClockP documentation and other BLE SLAs.

    Regards,
    Ryan

  • Please post a new E2E question if you are looking for advice outside of the low-power timer, the original question which has been answered.  You should perform initial development evaluation and provide specific questions as to the issues you are encountering.

    I think it is for low-power timer only becuase ultimately timer interrupt is needed and also since that time mcu can be in any state which means LP timer is also needed.

    I am using data stream code example where i integrate a sensor from which i want to get data ever x minute and send it via BLE.

    How to achieve this by keeping low power in mind.

    This information is to give an idea about the proper scenario of what i am looking for and how you can help in that.


    Agreed, here is ClockP documentation and other BLE SLAs.

    In BLE SLA page calculator is covert the values which is not working, and trying to report about on page issue.

  • Please let me know if you experience any issues while implementing ClockP for during your development.

    Regards,
    Ryan

  • Hi Ryan,
    I tried this SLA and it is not working. 

    ClockP_start(clockHandle); where i have to call this?

    Even I can not call that function outside app_peripheral.c Need help asap.

    Thanks
    Bhavik

  • Can you expand on what exactly is not working when you try to build the project, such as the Console build error?  Have you added the correct include inside the file from which you are calling the ClockP functions?

    #include <ti/drivers/dpl/ClockP.h>

    This should be all you need.

    Regards,
    Ryan

  • Yes library file and path is proper.

    I am using data_stream code example for testing.

    at starting of the app_main.c file added below code.

    #include <ti/drivers/dpl/ClockP.h>
    #include <ti/bleapp/ble_app_util/inc/bleapputil_internal.h>
    
    #define SP_PERIODIC_EVT_PERIOD               5000
    #define CLOCK_MS                  2000
    #define auto_read_time 5 
    
    /* For Timer Interrupt  */
    static ClockP_Struct clkPeriodic;
    ClockP_Params clockpParams;
    ClockP_Handle clockHandle;
    char t_led = 0;
    char spend_ms_counter = 0;
    /* For Timer Interrupt  */

    above to void appMain(void) function added below code

    void Peripheral_AppEventHandler()
    {
        spend_ms_counter++;
        if(spend_ms_counter == auto_read_time)
        {
            GPIO_write( CONFIG_GPIO_LED_BLUE, !t_led );
            t_led = !t_led;
            spend_ms_counter = 0;
        }
    }



    In app_main.c in void appMain(void) just before the BLEAppUtil_init() function I added the below code.

       /* For Timer Interrupt  */
                // Setup parameters.
                 ClockP_Params_init(&clockpParams);
    
                 // Convert clockDuration in milliseconds to ticks.
                 uint64_t clockTicks = SP_PERIODIC_EVT_PERIOD * (CLOCK_MS/ 1);
                 // If period is 0, this is a one-shot timer. If not 0, the it’s a periodic clock.
                 clockpParams.period = 1;  //clockTicks;
    
                 // Starts immediately after construction if true, otherwise wait for a call
                 // to start.
                 clockpParams.startFlag = true;
                 clockpParams.arg = (uintptr_t)Peripheral_AppEventHandler;
    
                 // Initialize clock instance.
                 clockHandle = ClockP_construct(&clkPeriodic, (void *)BLEAppUtil_invokeFunctionNoData, clockTicks, &clockpParams);
                 /* For Timer Interrupt  */
        /* For Timer Interrupt  */

    The expected behaviour is every 10 seconds it will toggle an LED. But it's not working. Can you check and help with solution?


  • Do this inside of bleapputil_task.c and BLEAppUtil_Task for the main code loop after the stack tasks have been established.  Then provide further debug information, for example does the clockHandle return NULL or valid and do you enter the event handler callback?

    I recommend you create a new E2E thread so that a BLE applications expert can further assist you.

    Regards,
    Ryan