Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
TARGET_MCU_NRF51822/sdk/source/libraries/bootloader_dfu/dfu_app_handler.h@639:4794dfdc59c0, 2017-11-09 (annotated)
- Committer:
- amithy
- Date:
- Thu Nov 09 22:13:54 2017 +0000
- Revision:
- 639:4794dfdc59c0
- Parent:
- 638:c90ae1400bf2
for testing export
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
638:c90ae1400bf2 | 1 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
638:c90ae1400bf2 | 3 | * All rights reserved. |
Vincent Coubard |
638:c90ae1400bf2 | 4 | * |
Vincent Coubard |
638:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
638:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
Vincent Coubard |
638:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
638:c90ae1400bf2 | 10 | * |
Vincent Coubard |
638:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
638:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
638:c90ae1400bf2 | 14 | * |
Vincent Coubard |
638:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
638:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
638:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
638:c90ae1400bf2 | 18 | * |
Vincent Coubard |
638:c90ae1400bf2 | 19 | * |
Vincent Coubard |
638:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
638:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
638:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
638:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
638:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
638:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
638:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
638:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
638:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
638:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
638:c90ae1400bf2 | 30 | * |
Vincent Coubard |
638:c90ae1400bf2 | 31 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 32 | |
Vincent Coubard |
638:c90ae1400bf2 | 33 | /** @file |
Vincent Coubard |
638:c90ae1400bf2 | 34 | * |
Vincent Coubard |
638:c90ae1400bf2 | 35 | * @defgroup nrf_dfu_app_handler DFU BLE packet handling in application |
Vincent Coubard |
638:c90ae1400bf2 | 36 | * @{ |
Vincent Coubard |
638:c90ae1400bf2 | 37 | * |
Vincent Coubard |
638:c90ae1400bf2 | 38 | * @brief Handling of DFU BLE packets in the application. |
Vincent Coubard |
638:c90ae1400bf2 | 39 | * |
Vincent Coubard |
638:c90ae1400bf2 | 40 | * @details This module implements the handling of DFU packets for switching |
Vincent Coubard |
638:c90ae1400bf2 | 41 | * from an application to the bootloader and start DFU mode. The DFU |
Vincent Coubard |
638:c90ae1400bf2 | 42 | * packets are transmitted over BLE. |
Vincent Coubard |
638:c90ae1400bf2 | 43 | * This module handles only the StartDFU packet, which allows a BLE |
Vincent Coubard |
638:c90ae1400bf2 | 44 | * application to expose support for the DFU Service. |
Vincent Coubard |
638:c90ae1400bf2 | 45 | * The actual DFU Service runs in a dedicated environment after a BLE |
Vincent Coubard |
638:c90ae1400bf2 | 46 | * disconnect and reset of the \nRFXX device. |
Vincent Coubard |
638:c90ae1400bf2 | 47 | * The host must reconnect and continue the update procedure with |
Vincent Coubard |
638:c90ae1400bf2 | 48 | * access to the full DFU Service. |
Vincent Coubard |
638:c90ae1400bf2 | 49 | * |
Vincent Coubard |
638:c90ae1400bf2 | 50 | * @note The application must propagate DFU events to this module by calling |
Vincent Coubard |
638:c90ae1400bf2 | 51 | * @ref dfu_app_on_dfu_evt from the @ref ble_dfu_evt_handler_t callback. |
Vincent Coubard |
638:c90ae1400bf2 | 52 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 53 | |
Vincent Coubard |
638:c90ae1400bf2 | 54 | #ifndef DFU_APP_HANDLER_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 55 | #define DFU_APP_HANDLER_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 56 | |
Vincent Coubard |
638:c90ae1400bf2 | 57 | #include "ble_dfu.h" |
Vincent Coubard |
638:c90ae1400bf2 | 58 | #include "nrf_svc.h" |
Vincent Coubard |
638:c90ae1400bf2 | 59 | #include "bootloader_types.h" |
Vincent Coubard |
638:c90ae1400bf2 | 60 | #include "device_manager.h" |
Vincent Coubard |
638:c90ae1400bf2 | 61 | |
Vincent Coubard |
638:c90ae1400bf2 | 62 | #define DFU_APP_ATT_TABLE_POS 0 /**< Position for the ATT table changed setting. */ |
Vincent Coubard |
638:c90ae1400bf2 | 63 | #define DFU_APP_ATT_TABLE_CHANGED 1 /**< Value indicating that the ATT table might have changed. This value will be set in the application-specific context in Device Manager when entering DFU mode. */ |
Vincent Coubard |
638:c90ae1400bf2 | 64 | |
Vincent Coubard |
638:c90ae1400bf2 | 65 | /**@brief DFU application reset_prepare function. This function is a callback that allows the |
Vincent Coubard |
638:c90ae1400bf2 | 66 | * application to prepare for an upcoming application reset. |
Vincent Coubard |
638:c90ae1400bf2 | 67 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 68 | typedef void (*dfu_app_reset_prepare_t)(void); |
Vincent Coubard |
638:c90ae1400bf2 | 69 | |
Vincent Coubard |
638:c90ae1400bf2 | 70 | /**@brief Function for handling events from the DFU Service. |
Vincent Coubard |
638:c90ae1400bf2 | 71 | * |
Vincent Coubard |
638:c90ae1400bf2 | 72 | * @details The application must inject this function into the DFU Service or propagate DFU events |
Vincent Coubard |
638:c90ae1400bf2 | 73 | * to the dfu_app_handler module by calling this function in the application-specific DFU event |
Vincent Coubard |
638:c90ae1400bf2 | 74 | * handler. |
Vincent Coubard |
638:c90ae1400bf2 | 75 | * |
Vincent Coubard |
638:c90ae1400bf2 | 76 | * @param[in] p_dfu Pointer to the DFU Service structure to which the include event relates. |
Vincent Coubard |
638:c90ae1400bf2 | 77 | * @param[in] p_evt Pointer to the DFU event. |
Vincent Coubard |
638:c90ae1400bf2 | 78 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 79 | void dfu_app_on_dfu_evt(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt); |
Vincent Coubard |
638:c90ae1400bf2 | 80 | |
Vincent Coubard |
638:c90ae1400bf2 | 81 | /**@brief Function for registering a function to prepare a reset. |
Vincent Coubard |
638:c90ae1400bf2 | 82 | * |
Vincent Coubard |
638:c90ae1400bf2 | 83 | * @details The provided function is executed before resetting the system into bootloader/DFU |
Vincent Coubard |
638:c90ae1400bf2 | 84 | * mode. By registering this function, the caller is notified before the reset and can |
Vincent Coubard |
638:c90ae1400bf2 | 85 | * thus prepare the application for reset. For example, the application can gracefully |
Vincent Coubard |
638:c90ae1400bf2 | 86 | * disconnect any peers on BLE, turn of LEDS, ensure that all pending flash operations |
Vincent Coubard |
638:c90ae1400bf2 | 87 | * have completed, and so on. |
Vincent Coubard |
638:c90ae1400bf2 | 88 | * |
Vincent Coubard |
638:c90ae1400bf2 | 89 | * @param[in] reset_prepare_func Function to be executed before a reset. |
Vincent Coubard |
638:c90ae1400bf2 | 90 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 91 | void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func); |
Vincent Coubard |
638:c90ae1400bf2 | 92 | |
Vincent Coubard |
638:c90ae1400bf2 | 93 | /**@brief Function for setting the Device Manager application instance. |
Vincent Coubard |
638:c90ae1400bf2 | 94 | * |
Vincent Coubard |
638:c90ae1400bf2 | 95 | * @details This function allows to set the @ref dm_application_instance_t value that is returned by the |
Vincent Coubard |
638:c90ae1400bf2 | 96 | * Device Manager when the application registers using @ref dm_register. |
Vincent Coubard |
638:c90ae1400bf2 | 97 | * If this function is not called, it is not be possible to share bonding information |
Vincent Coubard |
638:c90ae1400bf2 | 98 | * from the application to the bootloader/DFU when entering DFU mode. |
Vincent Coubard |
638:c90ae1400bf2 | 99 | * |
Vincent Coubard |
638:c90ae1400bf2 | 100 | * @param[in] app_instance Value for the application instance in use. |
Vincent Coubard |
638:c90ae1400bf2 | 101 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 102 | void dfu_app_dm_appl_instance_set(dm_application_instance_t app_instance); |
Vincent Coubard |
638:c90ae1400bf2 | 103 | |
Vincent Coubard |
638:c90ae1400bf2 | 104 | #endif // DFU_APP_HANDLER_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 105 | |
Vincent Coubard |
638:c90ae1400bf2 | 106 | /** @} */ |