Nordic stack and drivers for the mbed BLE API
Dependents: BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate writable_gatt ... more
TARGET_MCU_NRF51822/sdk/source/libraries/bootloader_dfu/dfu_bank_internal.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
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 dfu_bank_internal Device Firmware Update internal header for bank handling in DFU. |
Vincent Coubard |
638:c90ae1400bf2 | 36 | * @{ |
Vincent Coubard |
638:c90ae1400bf2 | 37 | * |
Vincent Coubard |
638:c90ae1400bf2 | 38 | * @brief Device Firmware Update Bank handling module interface. |
Vincent Coubard |
638:c90ae1400bf2 | 39 | * |
Vincent Coubard |
638:c90ae1400bf2 | 40 | * @details This header is intended for shared definition and functions between single and dual bank |
Vincent Coubard |
638:c90ae1400bf2 | 41 | * implementations used for DFU support. It is not supposed to be used for external access |
Vincent Coubard |
638:c90ae1400bf2 | 42 | * to the DFU module. |
Vincent Coubard |
638:c90ae1400bf2 | 43 | * |
Vincent Coubard |
638:c90ae1400bf2 | 44 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 45 | #ifndef DFU_BANK_INTERNAL_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 46 | #define DFU_BANK_INTERNAL_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 47 | |
Vincent Coubard |
638:c90ae1400bf2 | 48 | #include <dfu_types.h> |
Vincent Coubard |
638:c90ae1400bf2 | 49 | |
Vincent Coubard |
638:c90ae1400bf2 | 50 | /**@brief States of the DFU state machine. */ |
Vincent Coubard |
638:c90ae1400bf2 | 51 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 52 | { |
Vincent Coubard |
638:c90ae1400bf2 | 53 | DFU_STATE_INIT_ERROR, /**< State for: dfu_init(...) error. */ |
Vincent Coubard |
638:c90ae1400bf2 | 54 | DFU_STATE_IDLE, /**< State for: idle. */ |
Vincent Coubard |
638:c90ae1400bf2 | 55 | DFU_STATE_PREPARING, /**< State for: preparing, indicates that the flash is being erased and no data packets can be processed. */ |
Vincent Coubard |
638:c90ae1400bf2 | 56 | DFU_STATE_RDY, /**< State for: ready. */ |
Vincent Coubard |
638:c90ae1400bf2 | 57 | DFU_STATE_RX_INIT_PKT, /**< State for: receiving initialization packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 58 | DFU_STATE_RX_DATA_PKT, /**< State for: receiving data packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 59 | DFU_STATE_VALIDATE, /**< State for: validate. */ |
Vincent Coubard |
638:c90ae1400bf2 | 60 | DFU_STATE_WAIT_4_ACTIVATE /**< State for: waiting for dfu_image_activate(). */ |
Vincent Coubard |
638:c90ae1400bf2 | 61 | } dfu_state_t; |
Vincent Coubard |
638:c90ae1400bf2 | 62 | |
Vincent Coubard |
638:c90ae1400bf2 | 63 | #define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */ |
Vincent Coubard |
638:c90ae1400bf2 | 64 | #define DFU_TIMEOUT_INTERVAL APP_TIMER_TICKS(120000, APP_TIMER_PRESCALER) /**< DFU timeout interval in units of timer ticks. */ |
Vincent Coubard |
638:c90ae1400bf2 | 65 | |
Vincent Coubard |
638:c90ae1400bf2 | 66 | #define IS_UPDATING_SD(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_SD) /**< Macro for determining if a SoftDevice update is ongoing. */ |
Vincent Coubard |
638:c90ae1400bf2 | 67 | #define IS_UPDATING_BL(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_BL) /**< Macro for determining if a Bootloader update is ongoing. */ |
Vincent Coubard |
638:c90ae1400bf2 | 68 | #define IS_UPDATING_APP(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_APP) /**< Macro for determining if a Application update is ongoing. */ |
Vincent Coubard |
638:c90ae1400bf2 | 69 | #define IMAGE_WRITE_IN_PROGRESS() (m_data_received > 0) /**< Macro for determining if an image write is in progress. */ |
Vincent Coubard |
638:c90ae1400bf2 | 70 | #define IS_WORD_SIZED(SIZE) ((SIZE & (sizeof(uint32_t) - 1)) == 0) /**< Macro for checking that the provided is word sized. */ |
Vincent Coubard |
638:c90ae1400bf2 | 71 | |
Vincent Coubard |
638:c90ae1400bf2 | 72 | /**@cond NO_DOXYGEN */ |
Vincent Coubard |
638:c90ae1400bf2 | 73 | static uint32_t m_data_received; /**< Amount of received data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 74 | /**@endcond */ |
Vincent Coubard |
638:c90ae1400bf2 | 75 | |
Vincent Coubard |
638:c90ae1400bf2 | 76 | /**@brief Type definition of function used for preparing of the bank before receiving of a |
Vincent Coubard |
638:c90ae1400bf2 | 77 | * software image. |
Vincent Coubard |
638:c90ae1400bf2 | 78 | * |
Vincent Coubard |
638:c90ae1400bf2 | 79 | * @param[in] image_size Size of software image being received. |
Vincent Coubard |
638:c90ae1400bf2 | 80 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 81 | typedef void (*dfu_bank_prepare_t)(uint32_t image_size); |
Vincent Coubard |
638:c90ae1400bf2 | 82 | |
Vincent Coubard |
638:c90ae1400bf2 | 83 | /**@brief Type definition of function used for handling clear complete of the bank before |
Vincent Coubard |
638:c90ae1400bf2 | 84 | * receiving of a software image. |
Vincent Coubard |
638:c90ae1400bf2 | 85 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 86 | typedef void (*dfu_bank_cleared_t)(void); |
Vincent Coubard |
638:c90ae1400bf2 | 87 | |
Vincent Coubard |
638:c90ae1400bf2 | 88 | /**@brief Type definition of function used for activating of the software image received. |
Vincent Coubard |
638:c90ae1400bf2 | 89 | * |
Vincent Coubard |
638:c90ae1400bf2 | 90 | * @return NRF_SUCCESS If the image has been successfully activated any other NRF_ERROR code in |
Vincent Coubard |
638:c90ae1400bf2 | 91 | * case of a failure. |
Vincent Coubard |
638:c90ae1400bf2 | 92 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 93 | typedef uint32_t (*dfu_bank_activate_t)(void); |
Vincent Coubard |
638:c90ae1400bf2 | 94 | |
Vincent Coubard |
638:c90ae1400bf2 | 95 | /**@brief Structure for holding of function pointers for needed prepare and activate procedure for |
Vincent Coubard |
638:c90ae1400bf2 | 96 | * the requested update procedure. |
Vincent Coubard |
638:c90ae1400bf2 | 97 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 98 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 99 | { |
Vincent Coubard |
638:c90ae1400bf2 | 100 | dfu_bank_prepare_t prepare; /**< Function pointer to the prepare function called on start of update procedure. */ |
Vincent Coubard |
638:c90ae1400bf2 | 101 | dfu_bank_cleared_t cleared; /**< Function pointer to the cleared function called after prepare function completes. */ |
Vincent Coubard |
638:c90ae1400bf2 | 102 | dfu_bank_activate_t activate; /**< Function pointer to the activate function called on finalizing the update procedure. */ |
Vincent Coubard |
638:c90ae1400bf2 | 103 | } dfu_bank_func_t; |
Vincent Coubard |
638:c90ae1400bf2 | 104 | |
Vincent Coubard |
638:c90ae1400bf2 | 105 | #endif // DFU_BANK_INTERNAL_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 106 | |
Vincent Coubard |
638:c90ae1400bf2 | 107 | /** @} */ |