Using PMM in Application

Perform the following steps to use PMM in application:
  1. 1.Include pmm.h to application. In end-device demo application, PMM is included in main.c.
  2. 2.Implement a call back function to be invoked after wake up. This function must have the prototype of pmmWakeupCallback function pointer defined in PMM_SleepReq_t structure. PMM_SleepReq_t is available in pmm.h.
  3. 3.Invoke PMM_Sleep function from the application to request the PMM to put the system to sleep. PMM may deny a sleep request if the stack is not ready to sleep. User can supply NULL pointer to pmmWakeupCallback if wake-up callback function is not implemented.

Application sleep request time is configured by the macro DEMO_CONF_DEFAULT_APP_SLEEP_TIME_MS. It is present in conf_app.h file. By default, application sleep time is 1 second and it can be changed to the desired values. But, the sleep duration must fall within the acceptable range which is given in the following table.

Table 1. PMM Parameters
Parameter Value Unit Description
PMM_SLEEP_TIME_MIN 100 milliseconds Minimum allowed sleep time
PMM_SLEEP_TIME_MAX 0x7CED900 milliseconds Maximum allowed sleep time is approximately 36 hours, 26 minutes
PMM_WAKEUP_TIME 10 milliseconds Time to account for wake up

When the end-device is put to sleep, it can wake up from interrupt by either sleep timer, or transceiver interrupt or GPIO interrupt. When the end-device wakes up, the PMM_Wakeup() function is called and it returns the elapsed duration from sleep to application. In case of the application maintaining its own timers, this slept duration returned from PMM_Wakeup can be used to resume those timers. MLS automatically calls PMM_Wakeup whenever it receives a sleep timer interrupt or external interrupt. However, the end-device must also call PMM_Wakeup for GPIO interrupts. For those GPIO used by the application that can generate interrupts during sleep, the user must call PMM_Wakeup in those ISR callbacks. In case of polling, this is not required since polling code works only after wake up.