- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code looks fine. The critical section is required only for the system low power code. CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) need not be in the Critical section. But the code snippet in which check the BLE state and put the device to deepsleep must be inside critical section.
Thanks,
Hima
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code looks fine. The critical section is required only for the system low power code. CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP) need not be in the Critical section. But the code snippet in which check the BLE state and put the device to deepsleep must be inside critical section.
Thanks,
Hima
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code looks good as @Hima said above. Just so you are aware however, the BLE chip won't necessarily wake up from low power mode upon the CPU waking up. For example, if a SPI or UART bus wakes up the CPU, then the BLE chip may still be asleep. This will cause issues if you then proceed to access the BLE chip APIs/functionality while it is still asleep. But, if you are only using the BLE peripheral to wakeup the device from deep-sleep, then I don't see you running into any problems