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