Junichi Katsu
/
BLE_MPU6050_test6_challenge_sb
テスト用です。
nRF51822_wallbot/nordic/bootloader_dfu/dfu_app_handler.c@0:8468a4403fea, 2016-10-11 (annotated)
- Committer:
- jksoft
- Date:
- Tue Oct 11 11:09:42 2016 +0000
- Revision:
- 0:8468a4403fea
SB??ver;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8468a4403fea | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:8468a4403fea | 2 | * |
jksoft | 0:8468a4403fea | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
jksoft | 0:8468a4403fea | 4 | * Terms and conditions of usage are described in detail in NORDIC |
jksoft | 0:8468a4403fea | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
jksoft | 0:8468a4403fea | 6 | * |
jksoft | 0:8468a4403fea | 7 | * Licensees are granted free, non-transferable use of the information. NO |
jksoft | 0:8468a4403fea | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jksoft | 0:8468a4403fea | 9 | * the file. |
jksoft | 0:8468a4403fea | 10 | * |
jksoft | 0:8468a4403fea | 11 | */ |
jksoft | 0:8468a4403fea | 12 | |
jksoft | 0:8468a4403fea | 13 | #include "dfu_app_handler.h" |
jksoft | 0:8468a4403fea | 14 | #include "bootloader_util.h" |
jksoft | 0:8468a4403fea | 15 | #include "nrf_sdm.h" |
jksoft | 0:8468a4403fea | 16 | #include "app_error.h" |
jksoft | 0:8468a4403fea | 17 | |
jksoft | 0:8468a4403fea | 18 | #define IRQ_ENABLED 0x01 /**< Field identifying if an interrupt is enabled. */ |
jksoft | 0:8468a4403fea | 19 | #define MAX_NUMBER_INTERRUPTS 32 /**< Maximum number of interrupts available. */ |
jksoft | 0:8468a4403fea | 20 | |
jksoft | 0:8468a4403fea | 21 | static void dfu_app_reset_prepare(void); /**< Forward declare of default reset handler. */ |
jksoft | 0:8468a4403fea | 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. */ |
jksoft | 0:8468a4403fea | 23 | |
jksoft | 0:8468a4403fea | 24 | |
jksoft | 0:8468a4403fea | 25 | /**@brief Default reset prepare handler if application hasn't registered a handler. |
jksoft | 0:8468a4403fea | 26 | */ |
jksoft | 0:8468a4403fea | 27 | static void dfu_app_reset_prepare(void) |
jksoft | 0:8468a4403fea | 28 | { |
jksoft | 0:8468a4403fea | 29 | // Reset prepare should be handled by application. |
jksoft | 0:8468a4403fea | 30 | // This function can be extended to include default handling if application does not implement |
jksoft | 0:8468a4403fea | 31 | // own handler. |
jksoft | 0:8468a4403fea | 32 | } |
jksoft | 0:8468a4403fea | 33 | |
jksoft | 0:8468a4403fea | 34 | |
jksoft | 0:8468a4403fea | 35 | /**@brief Function for disabling all interrupts before jumping from bootloader to application. |
jksoft | 0:8468a4403fea | 36 | */ |
jksoft | 0:8468a4403fea | 37 | static void interrupts_disable(void) |
jksoft | 0:8468a4403fea | 38 | { |
jksoft | 0:8468a4403fea | 39 | uint32_t interrupt_setting_mask; |
jksoft | 0:8468a4403fea | 40 | uint32_t irq = 0; // We start from first interrupt, i.e. interrupt 0. |
jksoft | 0:8468a4403fea | 41 | |
jksoft | 0:8468a4403fea | 42 | // Fetch the current interrupt settings. |
jksoft | 0:8468a4403fea | 43 | interrupt_setting_mask = NVIC->ISER[0]; |
jksoft | 0:8468a4403fea | 44 | |
jksoft | 0:8468a4403fea | 45 | for (; irq < MAX_NUMBER_INTERRUPTS; irq++) |
jksoft | 0:8468a4403fea | 46 | { |
jksoft | 0:8468a4403fea | 47 | if (interrupt_setting_mask & (IRQ_ENABLED << irq)) |
jksoft | 0:8468a4403fea | 48 | { |
jksoft | 0:8468a4403fea | 49 | // The interrupt was enabled, and hence disable it. |
jksoft | 0:8468a4403fea | 50 | NVIC_DisableIRQ((IRQn_Type)irq); |
jksoft | 0:8468a4403fea | 51 | } |
jksoft | 0:8468a4403fea | 52 | } |
jksoft | 0:8468a4403fea | 53 | } |
jksoft | 0:8468a4403fea | 54 | |
jksoft | 0:8468a4403fea | 55 | |
jksoft | 0:8468a4403fea | 56 | /**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. |
jksoft | 0:8468a4403fea | 57 | */ |
jksoft | 0:8468a4403fea | 58 | void bootloader_start(void) |
jksoft | 0:8468a4403fea | 59 | { |
jksoft | 0:8468a4403fea | 60 | m_reset_prepare(); |
jksoft | 0:8468a4403fea | 61 | |
jksoft | 0:8468a4403fea | 62 | uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); |
jksoft | 0:8468a4403fea | 63 | APP_ERROR_CHECK(err_code); |
jksoft | 0:8468a4403fea | 64 | |
jksoft | 0:8468a4403fea | 65 | err_code = sd_softdevice_disable(); |
jksoft | 0:8468a4403fea | 66 | APP_ERROR_CHECK(err_code); |
jksoft | 0:8468a4403fea | 67 | |
jksoft | 0:8468a4403fea | 68 | interrupts_disable(); |
jksoft | 0:8468a4403fea | 69 | |
jksoft | 0:8468a4403fea | 70 | err_code = sd_softdevice_vector_table_base_set(NRF_UICR->BOOTLOADERADDR); |
jksoft | 0:8468a4403fea | 71 | APP_ERROR_CHECK(err_code); |
jksoft | 0:8468a4403fea | 72 | |
jksoft | 0:8468a4403fea | 73 | bootloader_util_app_start(NRF_UICR->BOOTLOADERADDR); |
jksoft | 0:8468a4403fea | 74 | } |
jksoft | 0:8468a4403fea | 75 | |
jksoft | 0:8468a4403fea | 76 | |
jksoft | 0:8468a4403fea | 77 | |
jksoft | 0:8468a4403fea | 78 | void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func) |
jksoft | 0:8468a4403fea | 79 | { |
jksoft | 0:8468a4403fea | 80 | m_reset_prepare = reset_prepare_func; |
jksoft | 0:8468a4403fea | 81 | } |