Exemplo n.º 1
0
/**@brief Handle events from m_pwr_mgmt_timer.
 */
static void nrf_pwr_mgmt_timeout_handler(void * p_context)
{
#if NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED
    uint32_t delta;
    uint32_t ticks;
    uint8_t  cpu_usage;

    ticks = app_timer_cnt_get();
    UNUSED_VARIABLE(app_timer_cnt_diff_compute(ticks, m_ticks_last, &delta));
    cpu_usage = 100 * (delta - m_ticks_sleeping) / delta;

    NRF_LOG_DEBUG("CPU Usage: %d%%\r\n", cpu_usage);
    if (m_max_cpu_usage < cpu_usage)
    {
        m_max_cpu_usage = cpu_usage;
    }

    m_ticks_last        = ticks;
    m_ticks_sleeping    = 0;
#endif // NRF_PWR_MGMT_CONFIG_CPU_USAGE_MONITOR_ENABLED

#if NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY
    if (m_sysoff_guard)
    {
        // Try to continue the shutdown procedure.
        nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_CONTINUE);
        return;
    }
#endif // NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY

#if NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
    if (m_standby_counter < NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S)
    {
        m_standby_counter++;
    }
    else
    {
        nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
    }
#endif // NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
}
Exemplo n.º 2
0
uint32_t ble_dfu_buttonless_bootloader_start_finalize(void)
{
    uint32_t err_code;

    NRF_LOG_DEBUG("In ble_dfu_buttonless_bootloader_start_finalize\r\n");

    err_code = sd_power_gpregret_clr(0, 0xffffffff);
    VERIFY_SUCCESS(err_code);

    err_code = sd_power_gpregret_set(0, BOOTLOADER_DFU_START);
    VERIFY_SUCCESS(err_code);

    // Indicate that the Secure DFU bootloader will be entered
    m_dfu.evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER);

    // Signal that DFU mode is to be enter to the power management module
    nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU);

    return NRF_SUCCESS;
}