Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_WallbotBLE_Challenge by
dfu_app_handler.c
00001 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 */ 00012 00013 #include "dfu_app_handler.h " 00014 #include "bootloader_util.h " 00015 #include "nrf_sdm.h" 00016 #include "app_error.h " 00017 00018 #define IRQ_ENABLED 0x01 /**< Field identifying if an interrupt is enabled. */ 00019 #define MAX_NUMBER_INTERRUPTS 32 /**< Maximum number of interrupts available. */ 00020 00021 static void dfu_app_reset_prepare(void); /**< Forward declare of default reset handler. */ 00022 static dfu_app_reset_prepare_t m_reset_prepare = dfu_app_reset_prepare; /**< Callback function to application to prepare for system reset. Allows application to cleanup of service and memory prior to reset. */ 00023 00024 00025 /**@brief Default reset prepare handler if application hasn't registered a handler. 00026 */ 00027 static void dfu_app_reset_prepare(void) 00028 { 00029 // Reset prepare should be handled by application. 00030 // This function can be extended to include default handling if application does not implement 00031 // own handler. 00032 } 00033 00034 00035 /**@brief Function for disabling all interrupts before jumping from bootloader to application. 00036 */ 00037 static void interrupts_disable(void) 00038 { 00039 uint32_t interrupt_setting_mask; 00040 uint32_t irq = 0; // We start from first interrupt, i.e. interrupt 0. 00041 00042 // Fetch the current interrupt settings. 00043 interrupt_setting_mask = NVIC->ISER[0]; 00044 00045 for (; irq < MAX_NUMBER_INTERRUPTS; irq++) 00046 { 00047 if (interrupt_setting_mask & (IRQ_ENABLED << irq)) 00048 { 00049 // The interrupt was enabled, and hence disable it. 00050 NVIC_DisableIRQ((IRQn_Type)irq); 00051 } 00052 } 00053 } 00054 00055 00056 /**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. 00057 */ 00058 void bootloader_start(void) 00059 { 00060 m_reset_prepare(); 00061 00062 uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); 00063 APP_ERROR_CHECK(err_code); 00064 00065 err_code = sd_softdevice_disable(); 00066 APP_ERROR_CHECK(err_code); 00067 00068 interrupts_disable(); 00069 00070 err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); 00071 APP_ERROR_CHECK(err_code); 00072 00073 bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); 00074 } 00075 00076 00077 00078 void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func) 00079 { 00080 m_reset_prepare = reset_prepare_func; 00081 }
Generated on Tue Jul 12 2022 13:52:30 by
