Power-Save Options
CYW920706WCDEVAL Hardware User Guide Doc. No.: 002-16535 Rev. **
44
Applications can register callback functions to be notified of deep sleep transition attempts, possible transition aborts, and to
allow or disallow the actual transition to deep sleep:
wiced_power_save_register_approve_cback
– register callback to approve or disapprove transition
The callback registered with this function is called when the device has decided to transition to deep sleep, to allow an
application to approve or disapprove of CYW20706 transitioning to the power-save mode. The application may allow the
transition by returning a non-zero value from the callback, or return zero to disallow. If the transition is disallowed, the original
request to transition to deep sleep remains active, and the device will continue to request the transition with further invocations
to this callback. Applications may choose to disallow to temporarily delay the sleep transition until the application is ready.
wiced_power_save_register_enter_cback
– register callback to be notified of imminent transition
The callback registered with this function is called just before CYW20706 transitions to the deep sleep power save mode to
allow the application to save state information with
wiced_power_save_store_state
.
wiced_power_save_register_abort_cback
– register callback to be notified if a pending transition is aborted.
The callback registered with this function is invoked if a transition to the power-save mode is aborted by the device. In this
state, the original request to transition to deep sleep is no longer active. An application can react to a power-save abort by
once again invoking
wiced_power_save_start
.
Use
wiced_power_save_stop
to instruct CYW20706 to cancel a previously requested deep sleep transition. This can be
called by the application any time after the call to
wiced_power_save_start
and before the callback registered for transition
entry notification is called (from
wiced_power_save_register_enter_cback
). Once that notification callback has been
invoked, it is too late to try to stop the transition.
The following code examples show how to use the
wiced_power_save_*
API functions:
uint16_t persistent_state_info = 0; /* application specific info to survive sleep */
/* normal application initializations (GPIOs, etc) occur from the callback function
* registered with wiced_bt_stack_init() handling BTM_ENABLED_EVT notification.
* call this function from that context after those initialization */
void deep_sleep_init(void)
{
/* retrieve stored state from previous execution */
stored_state_info = wiced_power_save_retrieve_state());
/* register callbacks */
wiced_power_save_register_approve_cback(power_save_approve);
wiced_power_save_register_enter_cback(power_save_enter);
wiced_power_save_register_abort_cback(power_save_abort);
}
/* function to be called when app wants to init deep sleep,
* e.g. battery monitor or idle time handler */
void sample_interrupt_handler(void)
{
/* request deep sleep, to be woken either on GPIO interrupt or a 10000ms timeout */
wiced_power_save_start(WICED_WAKE_SOURCE_ALL, 10000);
}
uint32_t power_save_approve(void)
{
if( isAppWillingToSleepNow )
{
WICED_BT_TRACE("Approving deep sleep request...\n");
return ~0;
}
else /* not willing to approve */
{
/* app will return 0 to disapprove, which will allow device to retry */
/* unless we want to stop it now */
if ( doesAppWantToCancelSleep )
{