<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>[Code with Explaniation] Power Management Example Code with Scheduler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77636/code-with-explaniation-power-management-example-code-with-scheduler</link><description>Hi, I&amp;#39;m using the PWR_MGMT SDK 17.0.2 demo code on my nRF52 DK. 
 Q1) After enabling parameters in the sdk_config.h, the nRF52 DK could enter the Power Off Mode if I press the button manually (LED4 will turn on as the indication). However, by using Scheduler</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Jul 2021 23:28:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77636/code-with-explaniation-power-management-example-code-with-scheduler" /><item><title>RE: [Code with Explaniation] Power Management Example Code with Scheduler</title><link>https://devzone.nordicsemi.com/thread/321004?ContentTypeID=1</link><pubDate>Tue, 20 Jul 2021 23:28:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d190d286-0ff4-4237-a5aa-156bab1906d7</guid><dc:creator>StevenW807</dc:creator><description>&lt;p&gt;Thanks Stian! You&amp;#39;re right! I understand the code now. &lt;strong&gt;To help other people to learn pwr_mgmt example code, I have added a lot of explanations to the sdk_config.h and main.c. Plz correct me if anything if wrong.&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Here is main.c with&amp;nbsp;explanations&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;bsp_nfc.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;       // Power management library

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#if NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
#include &amp;quot;app_scheduler.h&amp;quot;
#define APP_SCHED_MAX_EVENT_SIZE    0   /**&amp;lt; Maximum size of scheduler events. */
#define APP_SCHED_QUEUE_SIZE        4   /**&amp;lt; Maximum number of events in the scheduler queue. */
#endif // NRF_PWR_MGMT_CONFIG_USE_SCHEDULER

#define BTN_ID_READY                0   /**&amp;lt; ID of the button used to change the readiness to sleep. */
#define BTN_ID_SLEEP                1   /**&amp;lt; ID of the button used to put the application into sleep/system OFF mode. */
#define BTN_ID_WAKEUP               1   /**&amp;lt; ID of the button used to wake up the application. */
#define BTN_ID_RESET                2   /**&amp;lt; ID of the button used to reset the application. */

static volatile bool m_stay_in_sysoff;  /**&amp;lt; True if the application should stay in system OFF mode. */
static volatile bool m_is_ready;        /**&amp;lt; True if the application is ready to enter sleep/system OFF mode. */
static volatile bool m_sysoff_started;  /**&amp;lt; True if the application started sleep preparation. */














/**@brief Handler for shutdown preparation.
 * 
 * If the device is ready to enter to enter sleep/system OFF mode, return FALSE directly 
 * Otherwise, decide case by case
 *      1) If shuntdown type is &amp;quot;prepare to stay in System OFF state&amp;quot;, disable all buttons 
 *      2) If shuntdown type is &amp;quot;prepare the wakeup mechanism&amp;quot;, disable all buttons, and only enable the wake up button, and setup NFC tag as the wakeup source 
 *      3) If shuntdown type is &amp;quot;prepare to enter DFU mode.&amp;quot;, print a meesage in hyperterminal. Handle the SDK error if exists: API not implemented
 *      4) If shuntdown type is &amp;quot;Application will prepare to chip reset&amp;quot;, print a meesage in hyperterminal. 
 * Lastly, stop all timers. 
 */
bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
{
    uint32_t err_code;

    if (m_is_ready == false)
    {
        m_sysoff_started = true;
        return false;
    }

    switch (event)
    {
        case NRF_PWR_MGMT_EVT_PREPARE_SYSOFF:
            NRF_LOG_INFO(&amp;quot;NRF_PWR_MGMT_EVT_PREPARE_SYSOFF&amp;quot;);
            /**@brief       Function for disabling all buttons.
             *
             * @details     After calling this function, no buttons will generate events when pressed, and
             *              no buttons will be able to wake the system up from sleep mode.
             *
             * @retval      NRF_SUCCESS              If the buttons were successfully disabled.
             * @retval      NRF_ERROR_NOT_SUPPORTED  If the board has no buttons or BSP_SIMPLE is defined.
             * @return      A propagated error.
             */
            err_code = bsp_buttons_disable();
            APP_ERROR_CHECK(err_code);
            break;

        case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:
            NRF_LOG_INFO(&amp;quot;NRF_PWR_MGMT_EVT_PREPARE_WAKEUP&amp;quot;);
            err_code = bsp_buttons_disable();
            // Suppress NRF_ERROR_NOT_SUPPORTED return code.
            UNUSED_VARIABLE(err_code);

            /**@brief       Function for enabling wakeup from SYSTEM OFF for given button.
             *
             * @details     After calling this function, button can be used to wake up the chip.
             *              This function should only be called immediately before going into sleep.
             *
             * @param[in]   button_idx  Index of the button.
             *
             * @retval      NRF_SUCCESS              If the button was successfully enabled.
             * @retval      NRF_ERROR_NOT_SUPPORTED  If the board has no buttons or BSP_SIMPLE is defined.
             */
             err_code = bsp_wakeup_button_enable(BTN_ID_WAKEUP);
            // Suppress NRF_ERROR_NOT_SUPPORTED return code.
            UNUSED_VARIABLE(err_code);
            

            /**@brief Function for setting up NFCT peripheral as wake-up source.
             *
             * This function must be called before going into System OFF mode.
             *
             * @note This function is only applicable if NFCT is used exclusively for wakeup.
             *       If NFCT is used for a different purpose, this function cannot be used.
             *
             * @retval      NRF_SUCCESS     If NFCT peripheral was prepared successfully. Otherwise,
             *                              a propagated error code is returned.
             */
            err_code = bsp_nfc_sleep_mode_prepare();
            // Suppress NRF_ERROR_NOT_SUPPORTED return code.
            UNUSED_VARIABLE(err_code);
            break;

        case NRF_PWR_MGMT_EVT_PREPARE_DFU:
            NRF_LOG_ERROR(&amp;quot;Entering DFU is not supported by this example.&amp;quot;);
            // Handle the SDK errors: API not implemented
            APP_ERROR_HANDLER(NRF_ERROR_API_NOT_IMPLEMENTED);
            break;

        case NRF_PWR_MGMT_EVT_PREPARE_RESET:
            NRF_LOG_INFO(&amp;quot;NRF_PWR_MGMT_EVT_PREPARE_RESET&amp;quot;);
            break;
    }
    

    /**@brief Function for stopping all running timers.
     * @retval     NRF_SUCCESS               If all timers were successfully stopped.
     * @retval     NRF_ERROR_INVALID_STATE   If the application timer module has not been initialized.
     * @retval     NRF_ERROR_NO_MEM          If the timer operations queue was full.
     */
    err_code = app_timer_stop_all();
    APP_ERROR_CHECK(err_code);

    return true;
}

/**@brief Register application shutdown handler with priority 0. */
/**@brief   Macro for registering a shutdown handler to be called before entering system off sleep mode. 
 * It&amp;#39;s very useful for doing application-level housekeeping before netering System off sleep mode. 
 * Modules that want to get events
 *          from this module must register the handler using this macro.
 *
 * @details This macro places the handler in a section named &amp;quot;pwr_mgmt_data&amp;quot;.
 *
 * @param[in]   _handler    Event handler (@ref nrf_pwr_mgmt_shutdown_handler_t).
 * @param[in]   _priority   Priority of the given handler.
 */
NRF_PWR_MGMT_HANDLER_REGISTER(shutdown_handler, 0);










/**@brief Function for handling BSP events.
 * 
 * If NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED feature is enabled, whenever we press any button, the countdown auto-turn-off timer will be reset
 * Then, based on which button is pressed, do action case by case: 
 * 
 *      1) When BSP_EVENT_KEY_0 event happens (i.e. button 0 is released), 
 *          - If device is at &amp;quot;ready to enter sleep/power off&amp;quot; state, change device state to &amp;quot;NOT ready to sleep/power off&amp;quot;
 *          - If deive is &amp;quot;NOT ready to sleep/power off&amp;quot;, change state to &amp;quot;ready to sleep/power off&amp;quot;
 *         If device is &amp;quot;has started sleep preparation&amp;quot; AND &amp;quot;ready to sleep/power off&amp;quot;, shutdown the device
 *
 *      2) When BSP_EVENT_SYSOFF event happens (i.e. button 1 is LONG pressed foe xxx ms), update device state to &amp;quot;stay in system OFF&amp;quot; mode (no other actions)
 *
 *      3) When BSP_EVENT_SLEEP event happens (i.e. button 1 is released), shutdown the device 
 * 
 *      4) When BSP_EVENT_RESET event happens (i.e. button 2 is released), reset the device 
 * 
 * 
 */
static void bsp_evt_handler(bsp_event_t evt)
{
#if NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
    /*
    *@brief Function for indicating activity.
     *
     * @details Call this function whenever doing something that constitutes &amp;quot;activity&amp;quot;.
     *          For example, whenever sending data, call this function to indicate that the application
     *          is active and should not disconnect any ongoing communication links.
     * This API is only applicable when NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED is enabled.
     * 
     * When we use NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED feature, it uses RTC1 hardware to countdown. 
     * nrf_pwr_mgmt_feed() is called to reset the counter and hence prevent the automatic sleep. 
     */ 
    nrf_pwr_mgmt_feed();
    NRF_LOG_INFO(&amp;quot;bsp_evt_handler: Power management fed&amp;quot;);
#endif // NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED

    switch (evt)
    {
        // BSP_EVENT_KEY_0 = Default event of the push action of BSP_BUTTON_0 (only if this button is present)
        case BSP_EVENT_KEY_0:
            if (m_is_ready)
            {
                m_is_ready = false;
                NRF_LOG_INFO(&amp;quot;System is not ready for shutdown&amp;quot;);
            }
            else
            {
                m_is_ready = true;
                NRF_LOG_INFO(&amp;quot;System is ready for shutdown&amp;quot;);
            }
            if (m_sysoff_started &amp;amp;&amp;amp; m_is_ready)
            {
                /**@brief Function for shutting down the system.
                 * @param[in] shutdown_type     Type of operation.
                 * @details All callbacks will be executed prior to shutdown.
                 */
                 nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_CONTINUE);
            }
            break;

        
        // BSP_EVENT_SYSOFF = The device should enter system off mode (without wakeup)
        case BSP_EVENT_SYSOFF:
            m_stay_in_sysoff = true;
            break;

        
        // BSP_EVENT_SLEEP = The device should enter sleep mode
        case BSP_EVENT_SLEEP:
            if (m_stay_in_sysoff)
            {
                nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_STAY_IN_SYSOFF);
            }
            else
            {
                nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
            }
            break;

        
        // BSP_EVENT_RESET = The device should reset
        case BSP_EVENT_RESET:
            nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_RESET);
            break;

        default:
            return; // no implementation needed
    }
}










/**@brief Function for initializing low-frequency clock.
    In this example, LFCLK is used for 
 */
static void lfclk_config(void)
{
    
    /**
     * @brief Function for initializing the nrf_drv_clock module.
     *
     * After initialization, the module is in power off state (clocks are not requested).
     *
     * @retval NRF_SUCCESS                          If the procedure was successful.
     * @retval NRF_ERROR_MODULE_ALREADY_INITIALIZED If the driver was already initialized.
     */
     ret_code_t err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);

    
    /**
     * @brief Function for requesting the LFCLK.
     *
     * The low-frequency clock can be requested by different modules
     * or contexts. The driver ensures that the clock will be started only when it is requested
     * the first time. If the clock is not ready but it was already started, the handler item that is
     * provided as an input parameter is added to the list of handlers that will be notified
     * when the clock is started. If the clock is already enabled, user callback is called from the
     * current context.
     *
     * The first request will start the selected LFCLK source. If an event handler is
     * provided, it will be called once the LFCLK is started. If the LFCLK was already started at this
     * time, the event handler will be called from the context of this function. Additionally,
     * the @ref nrf_drv_clock_lfclk_is_running function can be polled to check if the clock has started.
     *
     * @note When a SoftDevice is enabled, the LFCLK is always running and the driver cannot control it.
     *
     * @note The handler item provided by the user cannot be an automatic variable.
     *
     * @param[in] p_handler_item A pointer to the event handler structure.
     */
    nrf_drv_clock_lfclk_request(NULL);
}













/**
Note: NOT all cases are used in this project

@brief Function for initializing the BSP module.
#define BTN_ID_READY                0   //&amp;lt; ID of the button used to change the readiness to sleep
#define BTN_ID_SLEEP                1   //&amp;lt; ID of the button used to put the application into sleep/system OFF mode
#define BTN_ID_WAKEUP               1   //&amp;lt; ID of the button used to wake up the application
#define BTN_ID_RESET                2   //&amp;lt; ID of the button used to reset the application
*/
static void bsp_configuration()
{
    uint32_t err_code;

    /**@brief       Function for initializing BSP.
     *
     * @details     The function initializes the board support package to allow state indication and
     *              button reaction. Default events are assigned to buttons.
     * @note        Before calling this function, you must initiate the following required modules:
     *              - @ref app_timer for LED support
     *              - @ref app_gpiote for button support
     *
     * @param[in]   type               Type of peripherals used.
     * @param[in]   callback           Function to be called when button press/event is detected.
     *
     * @retval      NRF_SUCCESS               If the BSP module was successfully initialized.
     * @retval      NRF_ERROR_INVALID_STATE   If the application timer module has not been initialized.
     * @retval      NRF_ERROR_NO_MEM          If the maximum number of timers has already been reached.
     * @retval      NRF_ERROR_INVALID_PARAM   If GPIOTE has too many users.
     * @retval      NRF_ERROR_INVALID_STATE   If button or GPIOTE has not been initialized.
     */
     err_code = bsp_init(BSP_INIT_BUTTONS, bsp_evt_handler);
    APP_ERROR_CHECK(err_code);

    
    /**@brief       Function for assigning a specific event to a button.
     *
     * @details     This function allows redefinition of standard events assigned to buttons.
     *              To unassign events, provide the event @ref BSP_EVENT_NOTHING.
     *
     * @param[in]   button                   Button ID to be redefined.
     * @param[in]   action                   Button action to assign event to.
     * @param[in]   event                    Event to be assigned to button.
     *
     * @retval      NRF_SUCCESS              If the event was successfully assigned to button.
     * @retval      NRF_ERROR_INVALID_PARAM  If the button ID or button action was invalid.
     */
     // When press button 1 for 2000 ms (long press), the device should enter system off mode (without wakeup)
     err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                 BSP_BUTTON_ACTION_LONG_PUSH,
                                                 BSP_EVENT_SYSOFF);
    APP_ERROR_CHECK(err_code);
    
    // When release button 1, The device should enter sleep mode.
    err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                 BSP_BUTTON_ACTION_RELEASE,
                                                 BSP_EVENT_SLEEP);
    APP_ERROR_CHECK(err_code);
    
    //-----------------------------------------
    // When press button 0, assign this event to an action to prevent the action from generating an event (disable the action)
    err_code = bsp_event_to_button_action_assign(BTN_ID_READY,
                                                 BSP_BUTTON_ACTION_PUSH,
                                                 BSP_EVENT_NOTHING);
    APP_ERROR_CHECK(err_code);

    
    // When release button 0, Default event of the push action of BSP_BUTTON_0 (only if this button is present)
    err_code = bsp_event_to_button_action_assign(BTN_ID_READY,
                                                 BSP_BUTTON_ACTION_RELEASE,
                                                 BSP_EVENT_KEY_0);
    APP_ERROR_CHECK(err_code);
    
    //-----------------------------------------
    // When release button 2, The device should reset
    err_code = bsp_event_to_button_action_assign(BTN_ID_RESET,
                                                 BSP_BUTTON_ACTION_RELEASE,
                                                 BSP_EVENT_RESET);
    APP_ERROR_CHECK(err_code);
}

















/**
 * @brief Function for application main entry.
 */
int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO(&amp;quot;Power Management example&amp;quot;);

    // Cnfigure and initialize the LFCLK
    // We need a LFCLK for NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S feature
    // If use SoftDevice, this step is NOT needed because the SoftDevice already tuen on the LFCLK
    lfclk_config();
    uint32_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);


#if NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
    /**@brief Macro for initializing the event scheduler.
     *
     * @details It will also handle dimensioning and allocation of the memory buffer required by the
     *          scheduler, making sure the buffer is correctly aligned.
     *
     * @param[in] EVENT_SIZE   Maximum size of events to be passed through the scheduler.
     * @param[in] QUEUE_SIZE   Number of entries in scheduler queue (i.e. the maximum number of events
     *                         that can be scheduled for execution).
     *
     * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it
     *       several times as long as it is from the same location, e.g. to do a reinitialization).
     */
    APP_SCHED_INIT(APP_SCHED_MAX_EVENT_SIZE, APP_SCHED_QUEUE_SIZE);
#endif // NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
    
    
    bsp_configuration();

    // Initilize the power management library
    ret_code_t ret_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(ret_code);

    while (true)
    {
#if NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
        /**@brief Function for executing all scheduled events.
         *
         * @details This function must be called from within the main loop. It will execute all events
         *          scheduled since the last time it was called.
         */
        app_sched_execute();
#endif // NRF_PWR_MGMT_CONFIG_USE_SCHEDULER

        
        /**@brief Macro for processing a single log entry from a queue of deferred logs.
         *
         * You can call this macro from the main context or from the error handler to process
         * log entries one by one.
         *
         * @note If logs are not deferred, this call has no use and is defined as &amp;#39;false&amp;#39;.
         *
         * @retval true    There are more logs to process in the buffer.
         * @retval false   No more logs in the buffer.
         * 
         * If there is no deferred log to print, enter system on sleep mode. 
         */
        if (NRF_LOG_PROCESS() == false)
        {
            // Function for running power management. Should run in the main loop.
            // Enter system on sleep mode
            // It makes sure that entering and existing sleep in safe and error-free whether SoftDevicce is used or not. 
            nrf_pwr_mgmt_run();
        }
    }
}



&lt;/pre&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here is my SDK &lt;strong&gt;explanations&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// &amp;lt;e&amp;gt; NRF_PWR_MGMT_ENABLED - nrf_pwr_mgmt - Power management module
//==========================================================
#ifndef NRF_PWR_MGMT_ENABLED
#define NRF_PWR_MGMT_ENABLED 1
#endif
// &amp;lt;e&amp;gt; NRF_PWR_MGMT_CONFIG_DEBUG_PIN_ENABLED - Enables pin debug in the module.

// &amp;lt;i&amp;gt; Selected pin will be set when CPU is in sleep mode.
//==========================================================
// Set a GPIO (LED) on/off when the CPU is active/asleep, so that we could track of when the CPU is active or asleep. 
#ifndef NRF_PWR_MGMT_CONFIG_DEBUG_PIN_ENABLED
#define NRF_PWR_MGMT_CONFIG_DEBUG_PIN_ENABLED 1
#endif
// &amp;lt;o&amp;gt; NRF_PWR_MGMT_SLEEP_DEBUG_PIN  - Pin number
 
// &amp;lt;0=&amp;gt; 0 (P0.0) 
// &amp;lt;1=&amp;gt; 1 (P0.1) 
// &amp;lt;2=&amp;gt; 2 (P0.2) 
// &amp;lt;3=&amp;gt; 3 (P0.3) 
// &amp;lt;4=&amp;gt; 4 (P0.4) 
// &amp;lt;5=&amp;gt; 5 (P0.5) 
// &amp;lt;6=&amp;gt; 6 (P0.6) 
// &amp;lt;7=&amp;gt; 7 (P0.7) 
// &amp;lt;8=&amp;gt; 8 (P0.8) 
// &amp;lt;9=&amp;gt; 9 (P0.9) 
// &amp;lt;10=&amp;gt; 10 (P0.10) 
// &amp;lt;11=&amp;gt; 11 (P0.11) 
// &amp;lt;12=&amp;gt; 12 (P0.12) 
// &amp;lt;13=&amp;gt; 13 (P0.13) 
// &amp;lt;14=&amp;gt; 14 (P0.14) 
// &amp;lt;15=&amp;gt; 15 (P0.15) 
// &amp;lt;16=&amp;gt; 16 (P0.16) 
// &amp;lt;17=&amp;gt; 17 (P0.17) 
// &amp;lt;18=&amp;gt; 18 (P0.18) 
// &amp;lt;19=&amp;gt; 19 (P0.19) 
// &amp;lt;20=&amp;gt; 20 (P0.20) 
// &amp;lt;21=&amp;gt; 21 (P0.21) 
// &amp;lt;22=&amp;gt; 22 (P0.22) 
// &amp;lt;23=&amp;gt; 23 (P0.23) 
// &amp;lt;24=&amp;gt; 24 (P0.24) 
// &amp;lt;25=&amp;gt; 25 (P0.25) 
// &amp;lt;26=&amp;gt; 26 (P0.26) 
// &amp;lt;27=&amp;gt; 27 (P0.27) 
// &amp;lt;28=&amp;gt; 28 (P0.28) 
// &amp;lt;29=&amp;gt; 29 (P0.29) 
// &amp;lt;30=&amp;gt; 30 (P0.30) 
// &amp;lt;31=&amp;gt; 31 (P0.31) 
// &amp;lt;4294967295=&amp;gt; Not connected 

// Check the nRF52 DK schematic diagram. 
// We could select the debug pin = LED pin to debug (i.e. display) the sleep mode ON/OFF (For nRF52 DK, LED1/2/3/4 coresponds to P0.17/18/19/20)
// Since the LEDs on nRF52DK are active low, that means the LED will be turned ON when CPU is active. LED will be OFF when CPU is asleep. 
#ifndef NRF_PWR_MGMT_SLEEP_DEBUG_PIN
#define NRF_PWR_MGMT_SLEEP_DEBUG_PIN 20
#endif

// &amp;lt;/e&amp;gt;

// &amp;lt;q&amp;gt; NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED  - Enables CPU usage monitor.
 

// &amp;lt;i&amp;gt; Module will trace percentage of CPU usage in one second intervals.
// This feature is used with the Logger Module to trace and log CPU usage (0% to 100%), and display through RTT/UART every 1 second. 
#ifndef NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED
#define NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED 1
#endif

// &amp;lt;e&amp;gt; NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED - Enable standby timeout.
//==========================================================
// Allow us to configure an auto-sleep after a period of inactivity (Note: requires the RTC1 hardware present on nRF5x to keep the timing)
#ifndef NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
#define NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED 1
#endif
// &amp;lt;o&amp;gt; NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S - Standby timeout (in seconds). 
// &amp;lt;i&amp;gt; Shutdown procedure will begin no earlier than after this number of seconds.

#ifndef NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S
#define NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S 5
#endif

// &amp;lt;/e&amp;gt;

// &amp;lt;q&amp;gt; NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED  - Enables FPU event cleaning.
// To handle &amp;quot;sleep&amp;quot; or &amp;quot;exit sleep&amp;quot; when the Floating Point Unit (FPU) of the SoC is used
#ifndef NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED
#define NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY  - Blocked shutdown procedure will be retried every second.
 

#ifndef NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY
#define NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY 0
#endif

// &amp;lt;q&amp;gt; NRF_PWR_MGMT_CONFIG_USE_SCHEDULER  - Module will use @ref app_scheduler.
// 
#ifndef NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
#define NRF_PWR_MGMT_CONFIG_USE_SCHEDULER 1
#endif

// &amp;lt;o&amp;gt; NRF_PWR_MGMT_CONFIG_HANDLER_PRIORITY_COUNT - The number of priorities for module handlers. 
// &amp;lt;i&amp;gt; The number of stages of the shutdown process.

#ifndef NRF_PWR_MGMT_CONFIG_HANDLER_PRIORITY_COUNT
#define NRF_PWR_MGMT_CONFIG_HANDLER_PRIORITY_COUNT 3
#endif

// &amp;lt;/e&amp;gt;

// &amp;lt;q&amp;gt; NRF_SECTION_ITER_ENABLED  - nrf_section_iter - Section iterator
 

#ifndef NRF_SECTION_ITER_ENABLED
#define NRF_SECTION_ITER_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRF_SORTLIST_ENABLED  - nrf_sortlist - Sorted list
 

#ifndef NRF_SORTLIST_ENABLED
#define NRF_SORTLIST_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRF_STRERROR_ENABLED  - nrf_strerror - Library for converting error code to string.
 

#ifndef NRF_STRERROR_ENABLED
#define NRF_STRERROR_ENABLED 1
#endif

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1626824080126v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Power Management Scheduler doesn't work SysOff handler 0x00003979 =&gt; blocking</title><link>https://devzone.nordicsemi.com/thread/320677?ContentTypeID=1</link><pubDate>Mon, 19 Jul 2021 12:05:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0ee9935-c44a-4047-bfa5-b5b8c3105e12</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Hi, I assume that you are running the peripheral/pwr_mgmt application in the SDK? It demonstrates how the application can automatically enter system OFF mode after the application is &amp;quot;ready&amp;quot;, if the application is ready or not is given in the m_is_ready variable. If you just push button 2 on the DK, the application is not ready, and you will get the =&amp;gt; blocking message, meaning that the application will enter system OFF mode as soon as this variable is set to true. The way to set this &amp;quot;ready&amp;quot; variable is to push button 1. So in order to enter system OFF, you have two options, press button 1 and wait for the timeout. Or press button 1, followed by button 2.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>