![](/media/cache/profiles/312e53ccba0b2ddfefd4a1f05b55bcdd.jpg.50x50_q85.jpg)
BLE FOTA APP
It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.
nRF51822/nordic/bootloader_dfu/dfu_app_handler.c@1:a607cd9655d7, 2014-10-10 (annotated)
- Committer:
- yihui
- Date:
- Fri Oct 10 03:36:28 2014 +0000
- Revision:
- 1:a607cd9655d7
use NVIC_SystemReset() to run bootloader
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 1:a607cd9655d7 | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
yihui | 1:a607cd9655d7 | 2 | * |
yihui | 1:a607cd9655d7 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
yihui | 1:a607cd9655d7 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
yihui | 1:a607cd9655d7 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
yihui | 1:a607cd9655d7 | 6 | * |
yihui | 1:a607cd9655d7 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
yihui | 1:a607cd9655d7 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
yihui | 1:a607cd9655d7 | 9 | * the file. |
yihui | 1:a607cd9655d7 | 10 | * |
yihui | 1:a607cd9655d7 | 11 | */ |
yihui | 1:a607cd9655d7 | 12 | |
yihui | 1:a607cd9655d7 | 13 | #include "dfu_app_handler.h" |
yihui | 1:a607cd9655d7 | 14 | #include "bootloader_util.h" |
yihui | 1:a607cd9655d7 | 15 | #include "nrf_sdm.h" |
yihui | 1:a607cd9655d7 | 16 | #include "app_error.h" |
yihui | 1:a607cd9655d7 | 17 | |
yihui | 1:a607cd9655d7 | 18 | #define IRQ_ENABLED 0x01 /**< Field identifying if an interrupt is enabled. */ |
yihui | 1:a607cd9655d7 | 19 | #define MAX_NUMBER_INTERRUPTS 32 /**< Maximum number of interrupts available. */ |
yihui | 1:a607cd9655d7 | 20 | |
yihui | 1:a607cd9655d7 | 21 | static void dfu_app_reset_prepare(void); /**< Forward declare of default reset handler. */ |
yihui | 1:a607cd9655d7 | 22 | 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. */ |
yihui | 1:a607cd9655d7 | 23 | |
yihui | 1:a607cd9655d7 | 24 | |
yihui | 1:a607cd9655d7 | 25 | /**@brief Default reset prepare handler if application hasn't registered a handler. |
yihui | 1:a607cd9655d7 | 26 | */ |
yihui | 1:a607cd9655d7 | 27 | static void dfu_app_reset_prepare(void) |
yihui | 1:a607cd9655d7 | 28 | { |
yihui | 1:a607cd9655d7 | 29 | // Reset prepare should be handled by application. |
yihui | 1:a607cd9655d7 | 30 | // This function can be extended to include default handling if application does not implement |
yihui | 1:a607cd9655d7 | 31 | // own handler. |
yihui | 1:a607cd9655d7 | 32 | } |
yihui | 1:a607cd9655d7 | 33 | |
yihui | 1:a607cd9655d7 | 34 | /**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. |
yihui | 1:a607cd9655d7 | 35 | */ |
yihui | 1:a607cd9655d7 | 36 | void bootloader_start(void) |
yihui | 1:a607cd9655d7 | 37 | { |
yihui | 1:a607cd9655d7 | 38 | m_reset_prepare(); |
yihui | 1:a607cd9655d7 | 39 | |
yihui | 1:a607cd9655d7 | 40 | uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); |
yihui | 1:a607cd9655d7 | 41 | APP_ERROR_CHECK(err_code); |
yihui | 1:a607cd9655d7 | 42 | |
yihui | 1:a607cd9655d7 | 43 | NVIC_SystemReset(); |
yihui | 1:a607cd9655d7 | 44 | } |
yihui | 1:a607cd9655d7 | 45 | |
yihui | 1:a607cd9655d7 | 46 | |
yihui | 1:a607cd9655d7 | 47 | |
yihui | 1:a607cd9655d7 | 48 | void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func) |
yihui | 1:a607cd9655d7 | 49 | { |
yihui | 1:a607cd9655d7 | 50 | m_reset_prepare = reset_prepare_func; |
yihui | 1:a607cd9655d7 | 51 | } |