2 Replies Latest reply on Aug 22, 2017 9:38 AM by e.pratt_1639216

    Delay between CyBle_ProcessEvents(), CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) and CySysPmDeepSleep()?

    pieter_2521576

      Hi everyone!

       

      My code works and I have not observed a bug (yet), but I was wondering what the recommended / correct sequence is. In pseudo code, I do the following after waking up from any interrupt:

       

      // Step 1. Woke up from a interrupt. Process BLE events:

      CyBle_ProcessEvents();

       

      // Step 2. Event close state?

      if(CyBle_GetBleSsState() == CYBLE_BLESS_STATE_EVENT_CLOSE)

      {

          // Update manufacturer specific part of advertisement packet

          ble_app_update_adv_packet();

      }

       

      // Step 3. Manage BLESS power modes

      CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);

       

      // Step 4. ****** Now perform all other tasks; this can take long, e.g. 40 ms ******

       

      // Step 5. Go into low power sleep mode (redacted example)

      interrupt_status = CyEnterCriticalSection();

      if(CyBle_GetBleSsState() == CYBLE_BLESS_STATE_DEEPSLEEP)

      {

          CySysPmDeepSleep();

      }

      CyExitCriticalSection(interrupt_status);

       

      Please observe step 4 where other tasks are performed and can introduce a long delay between step 3 and step 5.

       

      Is this correct and the lowest power solution, or must I swap step 3 and step 4 so that CyBle_EnterLPM() is called just before CyEnterCriticalSection()? Why?

       

      Thanks in advance,

      Pieter