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.

Hal sleep timer

Other Parts Discussed in Thread: CC2540

Hello I have searched many "sleep" posts but was not able to find any specifics related to CC2540.

Background: Using Keyfob demo project with 2540 MINI DK. I would like to put the processor into PM2 and have it wakeup after desired time (100msec, 250msec, etc).  I have modified the below code but I can not get it to work and processor is always awake. I have tried different values for TEST_SLEEP_TIME (from ms to s) with no luck. I know the values have to be based on 32khz which that is what I load into this const. I also know that timeout is peeking into radio & os_timers to get shortest time for sleep.

The processor seems to go to sleep OK when I revert code to the original TI code (ie using the timeout var).

hal_sleep.c { function void halSleep( uint32 osal_timeout ) }

      if (timeout != 0)
{
// check if the time to next wake event is greater than max sleep time
if (timeout > MAX_SLEEP_TIME )
{
// it is, so limit to max allowed sleep time (~510s)
halSleepSetTimer( sleepTimer, MAX_SLEEP_TIME );
}
else // not more than allowed sleep time
{
// so set sleep time to actual amount
halSleepSetTimer( sleepTimer, /*timeout*/ TEST_SLEEP_TIME );
}
}

Timer conversion formula .....   TEST_SLEEP_TIME = Desired Time / 30.51usec { this is not the code, just a conversion formula }

Any help is appreciated as to why when I modify the code it does not work.

~LD

  • Hello,

    Why not just use osal timer? 

    BR,

    -Greg

  • I guess I am missing your comments. Are you saying to use OSAL timer to sleep?  ( my problem is when I override the wakeup time the micro does not enter sleep).

  • I think what Greg means is you can set a timer to trigger an event and the OSAL will handle everything for you i.e. Wake up the micro if it is asleep and set the event code you specified for the  task you specified (with no modification of hal_sleep required) e.g.

    osal_start_timerEx(TaskID, EventID, TimeToEventInMilliseconds);

    I take it you have enabled power saving for the device and the task.

    I also found I had to set a timer of period 30s to maintain the real time clock. Even with 60s the real time clock stopped ticking when asleep. This isn't a problem as the max count of the sleep timer is 512s so a periodic wakeup would be required anyway and 30s provides a more regular update of the RTC.

  • Eng351

    Yes, the power saving is enabled. I am performing some bench mark testing to validate the hardware design using the keyfob demo project as a start point to avoid writing everything from scratch (kernel + app) due to timing.  Once the hardware design is validated; then I can begin the task will have to rethink whether to use the OSAL, write our own, pick-n-choose from keyfob demo. That said, if I can not understand why a simple override const keeps the processor from entering sleep mode then something else is happening and hence my question.

    thanks

    ~LD

  • The BLE stack runs on the OSAL, so as I found out you are stuck with it unless you are re-writing the stack too. Have you debugged the timer values that the OSAL is creating and tried to hardcode those?