This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

simpleBLEObserver osal_start_timerEx



Hi

I would like to set a LED to on for a certain time.  I am using

osal_start_timerEx( taskID, POWERLED_ON_EVT, 200)


This works fine, but I've realised that if I set the timer value to 2000ms the processor

goes into sleep mode, without waiting the full 2000ms.   When starting the timer does

it generate an interrupt when it reaches the timeout_value?  If so I can't find it.


If I comment out osal_pwrmgr_powerconserve() then the led will actually stay on for the 2000ms.

So this shows that the device is going into sleep before the timer is done.

Regards

Francois

  • Hey Francois,

    It should be ok for the device to sleep between events including the timer event. What happens though is when the device enters sleep, the LEDs state is stored and then they are turned off to conserve power (making it appear as though your timer events are not operating correctly).

    Look for the function HalLedEnterSleep() in hal_led.c to see the LEDs being turned off going into sleep. If you want to keep the LEDs on during sleep I think you only need to comment out the HalLedOnOff() calls in the Enter/Exit sleep functions. 

    -Matt

     

  • Hi Matt


    I will try that, it makes sense.  I've also tried it with the keyfob buzzer by using the osal_start_timerEx.
    It makes a short beep irrecspective of how much I increase the timer's timeout value beyond 500ms.  I would have thought the source code would wait for the timer to finish before going into sleep and the waking again.  The problem with the sleep/wake cycles is that although it remembers the led state, it causes the led to flash instead of staying solid.

    At the end of the day I just need short flashes and beeps but I was just wondering how to use the timeout value

    as it's a 32-bit value.  But I think I will have to make a function for the buzzer when it enters/exits sleep so that it will beep over a period of time.

    Thanks.

  • I can see in the documentation that when you start the timer it returns a success.  But where

    would you see that the timer has completed it's timeout. 

    Would be nice to know the timer is done but I can't figure out from the documentation and source code what is happening when the timeout value is reached.

    On the topic of the device going into sleep is there a way of delaying sleep if there is no more tasks or events to be processed? I know this uses power but would be interesting to know.

    Thanks.

  • The osal_start_timerex is now working properly as documented.  Seems my osal_timers files got corrupted somehow.  Now I can get the correct timeout response when setting the timer.

  • Basically OSAL keeps a list of timeout events and when you call osal_start_timerEx() it adds that timeout to its list. As the device runs, the OSAL clock is kept up to date using HW timers (specifically it looks like the MAC backoff timer is used to update this clock value).

    When the OSAL clock is updated it goes through its list of all OSAL timers (look at osalTimerUpdate() in OSAL_Timers.c) and decrements the timeout values of every timer by the same amount the OSAL clock has increased. When the timeout value of a timer reaches zero an event is generated with the same task_id and event_flag that you originally passed as parameters to osal_start_timerEx().

    That event is then processed by whatever function you declared as the event handler of that task_id. For instance in SimpleBLEPeripheral project the function that handles events for the app task is SimpleBLEPeripheral_ProcessEvent(). You can see in that function that they have a SBP_PERIODIC_EVT which they use to create a periodic event (when they handle the event they create another timer that will again create the same periodic event and that repeats).

    -Matt

  • P.S. I don't know if you can really delay when the device goes to sleep. You can easily disable sleep all together by removing the POWER_SAVING preprocessor define in the project (Project->Options->C/C++ Compiler->Preprocessor).

    There is also a way for tasks to disable sleep when they are running. Check out osal_pwrmgr_task_state() (defined in OSAL_PwrMgr.c). This allows every task to declare whether it is currently safe for the device to sleep and if any task has set their pwrmgr_task_state bit then the device won't go to sleep. This might give you better granularity than disabling the low power modes.

    -Matt

  • Thanks Matt.  Will look into your recommendations.  Appreciate the help.