song zhao / nRF51822

Dependencies:   nrf51-sdk

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:19:02 2016 +0000
Revision:
542:884f95bf5351
Parent:
388:b13ab9a7ddb9
Synchronized with git rev 60a7c0c0
Author: Rohit Grover
bring in the latest changes for BLE::init() where we allow <object, member> tuples for init callback.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 542:884f95bf5351 1 /*
vcoubard 542:884f95bf5351 2 * Copyright (c) Nordic Semiconductor ASA
vcoubard 542:884f95bf5351 3 * All rights reserved.
vcoubard 542:884f95bf5351 4 *
vcoubard 542:884f95bf5351 5 * Redistribution and use in source and binary forms, with or without modification,
vcoubard 542:884f95bf5351 6 * are permitted provided that the following conditions are met:
vcoubard 542:884f95bf5351 7 *
vcoubard 542:884f95bf5351 8 * 1. Redistributions of source code must retain the above copyright notice, this
vcoubard 542:884f95bf5351 9 * list of conditions and the following disclaimer.
vcoubard 542:884f95bf5351 10 *
vcoubard 542:884f95bf5351 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
vcoubard 542:884f95bf5351 12 * list of conditions and the following disclaimer in the documentation and/or
vcoubard 542:884f95bf5351 13 * other materials provided with the distribution.
vcoubard 542:884f95bf5351 14 *
vcoubard 542:884f95bf5351 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
vcoubard 542:884f95bf5351 16 * contributors to this software may be used to endorse or promote products
vcoubard 542:884f95bf5351 17 * derived from this software without specific prior written permission.
vcoubard 542:884f95bf5351 18 *
vcoubard 542:884f95bf5351 19 *
vcoubard 542:884f95bf5351 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
vcoubard 542:884f95bf5351 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
vcoubard 542:884f95bf5351 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vcoubard 542:884f95bf5351 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
vcoubard 542:884f95bf5351 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
vcoubard 542:884f95bf5351 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
vcoubard 542:884f95bf5351 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
vcoubard 542:884f95bf5351 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
vcoubard 542:884f95bf5351 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
vcoubard 542:884f95bf5351 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vcoubard 542:884f95bf5351 30 *
vcoubard 542:884f95bf5351 31 */
vcoubard 542:884f95bf5351 32
vcoubard 542:884f95bf5351 33 /**@file
vcoubard 542:884f95bf5351 34 *
vcoubard 542:884f95bf5351 35 * @defgroup nrf_dfu_types Types and definitions.
vcoubard 542:884f95bf5351 36 * @{
vcoubard 542:884f95bf5351 37 *
vcoubard 542:884f95bf5351 38 * @ingroup nrf_dfu
vcoubard 542:884f95bf5351 39 *
vcoubard 542:884f95bf5351 40 * @brief Device Firmware Update module type and definitions.
vcoubard 542:884f95bf5351 41 */
vcoubard 542:884f95bf5351 42
vcoubard 542:884f95bf5351 43 #ifndef DFU_TYPES_H__
vcoubard 542:884f95bf5351 44 #define DFU_TYPES_H__
vcoubard 542:884f95bf5351 45
vcoubard 542:884f95bf5351 46 #include <stdint.h>
vcoubard 542:884f95bf5351 47 #include "nrf51.h"
vcoubard 542:884f95bf5351 48 #include "app_util.h"
vcoubard 542:884f95bf5351 49
vcoubard 542:884f95bf5351 50 /**@brief Structure holding SoftDevice information to be used by the Bootloader/DFU.
vcoubard 542:884f95bf5351 51 * Only size field is used.
vcoubard 542:884f95bf5351 52 */
vcoubard 542:884f95bf5351 53 typedef struct
vcoubard 542:884f95bf5351 54 {
vcoubard 542:884f95bf5351 55 uint8_t info_size; /**< Not used. */
vcoubard 542:884f95bf5351 56 uint8_t reserved1[3]; /**< Not used. */
vcoubard 542:884f95bf5351 57 uint32_t magic_number; /**< Not used. */
vcoubard 542:884f95bf5351 58 uint32_t softdevice_size; /**< Size field containing the size of installed SoftDevice. */
vcoubard 542:884f95bf5351 59 uint16_t firmware_id; /**< Firmware id. */
vcoubard 542:884f95bf5351 60 uint8_t reserved2[2]; /**< Not used. */
vcoubard 542:884f95bf5351 61 } SOFTDEVICE_INFORMATION_Type;
vcoubard 542:884f95bf5351 62
vcoubard 542:884f95bf5351 63 #define SOFTDEVICE_INFORMATION_BASE 0x0003000 /**< Location in the SoftDevice image which holds the SoftDevice informations. */
vcoubard 542:884f95bf5351 64 #define SOFTDEVICE_INFORMATION ((SOFTDEVICE_INFORMATION_Type *) SOFTDEVICE_INFORMATION_BASE) /**< Make SoftDevice information accessible through the structure. */
vcoubard 542:884f95bf5351 65
vcoubard 542:884f95bf5351 66 #define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */
vcoubard 542:884f95bf5351 67
vcoubard 542:884f95bf5351 68 #define CODE_REGION_1_START SOFTDEVICE_INFORMATION->softdevice_size /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
vcoubard 542:884f95bf5351 69
vcoubard 542:884f95bf5351 70 #define SOFTDEVICE_REGION_START 0x00001000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
vcoubard 542:884f95bf5351 71 #define BOOTLOADER_REGION_START 0x0003C000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
vcoubard 542:884f95bf5351 72 #define BOOTLOADER_SETTINGS_ADDRESS 0x0003FC00 /**< The field specifies the page location of the bootloader settings address. */
vcoubard 542:884f95bf5351 73
vcoubard 542:884f95bf5351 74 #define DFU_REGION_TOTAL_SIZE (BOOTLOADER_REGION_START - CODE_REGION_1_START) /**< Total size of the region between SD and Bootloader. */
vcoubard 542:884f95bf5351 75
vcoubard 542:884f95bf5351 76 #define DFU_APP_DATA_RESERVED 0x0000 /**< Size of Application Data that must be preserved between application updates. This value must be a multiple of page size. Page size is 0x400 (1024d) bytes, thus this value must be 0x0000, 0x0400, 0x0800, 0x0C00, 0x1000, etc. */
vcoubard 542:884f95bf5351 77 #define DFU_BANK_PADDING (DFU_APP_DATA_RESERVED % (2 * CODE_PAGE_SIZE)) /**< Padding to ensure that image size banked is always page sized. */
vcoubard 542:884f95bf5351 78 #define DFU_IMAGE_MAX_SIZE_FULL (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED) /**< Maximum size of an application, excluding save data from the application. */
vcoubard 542:884f95bf5351 79 #define DFU_IMAGE_MAX_SIZE_BANKED ((DFU_REGION_TOTAL_SIZE - \
vcoubard 542:884f95bf5351 80 DFU_APP_DATA_RESERVED - \
vcoubard 542:884f95bf5351 81 DFU_BANK_PADDING) / 2) /**< Maximum size of an application, excluding save data from the application. */
vcoubard 542:884f95bf5351 82
vcoubard 542:884f95bf5351 83 #define DFU_BL_IMAGE_MAX_SIZE (BOOTLOADER_SETTINGS_ADDRESS - BOOTLOADER_REGION_START) /**< Maximum size of a bootloader, excluding save data from the current bootloader. */
vcoubard 542:884f95bf5351 84
vcoubard 542:884f95bf5351 85 #define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */
vcoubard 542:884f95bf5351 86 #define DFU_BANK_1_REGION_START (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED) /**< Bank 1 region start. */
vcoubard 542:884f95bf5351 87
vcoubard 542:884f95bf5351 88 #define CODE_PAGE_SIZE 0x0400 /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */
vcoubard 542:884f95bf5351 89 #define EMPTY_FLASH_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
vcoubard 542:884f95bf5351 90
vcoubard 542:884f95bf5351 91 #define INVALID_PACKET 0x00 /**< Invalid packet identifies. */
vcoubard 542:884f95bf5351 92 #define INIT_PACKET 0x01 /**< Packet identifies for initialization packet. */
vcoubard 542:884f95bf5351 93 #define STOP_INIT_PACKET 0x02 /**< Packet identifies for stop initialization packet. Used when complete init packet has been received so that the init packet can be used for pre validaiton. */
vcoubard 542:884f95bf5351 94 #define START_PACKET 0x03 /**< Packet identifies for the Data Start Packet. */
vcoubard 542:884f95bf5351 95 #define DATA_PACKET 0x04 /**< Packet identifies for a Data Packet. */
vcoubard 542:884f95bf5351 96 #define STOP_DATA_PACKET 0x05 /**< Packet identifies for the Data Stop Packet. */
vcoubard 542:884f95bf5351 97
vcoubard 542:884f95bf5351 98 #define DFU_UPDATE_SD 0x01 /**< Bit field indicating update of SoftDevice is ongoing. */
vcoubard 542:884f95bf5351 99 #define DFU_UPDATE_BL 0x02 /**< Bit field indicating update of bootloader is ongoing. */
vcoubard 542:884f95bf5351 100 #define DFU_UPDATE_APP 0x04 /**< Bit field indicating update of application is ongoing. */
vcoubard 542:884f95bf5351 101
vcoubard 542:884f95bf5351 102 #define DFU_INIT_RX 0x00 /**< Op Code identifies for receiving init packet. */
vcoubard 542:884f95bf5351 103 #define DFU_INIT_COMPLETE 0x01 /**< Op Code identifies for transmission complete of init packet. */
vcoubard 542:884f95bf5351 104
vcoubard 542:884f95bf5351 105 // Safe guard to ensure during compile time that the DFU_APP_DATA_RESERVED is a multiple of page size.
vcoubard 542:884f95bf5351 106 STATIC_ASSERT((((DFU_APP_DATA_RESERVED) & (CODE_PAGE_SIZE - 1)) == 0x00));
vcoubard 542:884f95bf5351 107
vcoubard 542:884f95bf5351 108 /**@brief Structure holding a start packet containing update mode and image sizes.
vcoubard 542:884f95bf5351 109 */
vcoubard 542:884f95bf5351 110 typedef struct
vcoubard 542:884f95bf5351 111 {
vcoubard 542:884f95bf5351 112 uint8_t dfu_update_mode; /**< Packet type, used to identify the content of the received packet referenced by data packet. */
vcoubard 542:884f95bf5351 113 uint32_t sd_image_size; /**< Size of the SoftDevice image to be transferred. Zero if no SoftDevice image will be transfered. */
vcoubard 542:884f95bf5351 114 uint32_t bl_image_size; /**< Size of the Bootloader image to be transferred. Zero if no Bootloader image will be transfered. */
vcoubard 542:884f95bf5351 115 uint32_t app_image_size; /**< Size of the application image to be transmitted. Zero if no Bootloader image will be transfered. */
vcoubard 542:884f95bf5351 116 } dfu_start_packet_t;
vcoubard 542:884f95bf5351 117
vcoubard 542:884f95bf5351 118 /**@brief Structure holding a bootloader init/data packet received.
vcoubard 542:884f95bf5351 119 */
vcoubard 542:884f95bf5351 120 typedef struct
vcoubard 542:884f95bf5351 121 {
vcoubard 542:884f95bf5351 122 uint32_t packet_length; /**< Packet length of the data packet. Each data is word size, meaning length of 4 is 4 words, not bytes. */
vcoubard 542:884f95bf5351 123 uint32_t * p_data_packet; /**< Data Packet received. Each data is a word size entry. */
vcoubard 542:884f95bf5351 124 } dfu_data_packet_t;
vcoubard 542:884f95bf5351 125
vcoubard 542:884f95bf5351 126 /**@brief Structure for holding dfu update packet. Packet type indicate the type of packet.
vcoubard 542:884f95bf5351 127 */
vcoubard 542:884f95bf5351 128 typedef struct
vcoubard 542:884f95bf5351 129 {
vcoubard 542:884f95bf5351 130 uint32_t packet_type; /**< Packet type, used to identify the content of the received packet referenced by data packet. */
vcoubard 542:884f95bf5351 131 union
vcoubard 542:884f95bf5351 132 {
vcoubard 542:884f95bf5351 133 dfu_data_packet_t data_packet; /**< Used when packet type is INIT_PACKET or DATA_PACKET. Packet contains data received for init or data. */
vcoubard 542:884f95bf5351 134 dfu_start_packet_t * start_packet; /**< Used when packet type is START_DATA_PACKET. Will contain information on software to be updtaed, i.e. SoftDevice, Bootloader and/or Application along with image sizes. */
vcoubard 542:884f95bf5351 135 } params;
vcoubard 542:884f95bf5351 136 } dfu_update_packet_t;
vcoubard 542:884f95bf5351 137
vcoubard 542:884f95bf5351 138 /**@brief DFU status error codes.
vcoubard 542:884f95bf5351 139 */
vcoubard 542:884f95bf5351 140 typedef enum
vcoubard 542:884f95bf5351 141 {
vcoubard 542:884f95bf5351 142 DFU_UPDATE_APP_COMPLETE, /**< Status update of application complete.*/
vcoubard 542:884f95bf5351 143 DFU_UPDATE_SD_COMPLETE, /**< Status update of SoftDevice update complete. Note that this solely indicates that a new SoftDevice has been received and stored in bank 0 and 1. */
vcoubard 542:884f95bf5351 144 DFU_UPDATE_SD_SWAPPED, /**< Status update of SoftDevice update complete. Note that this solely indicates that a new SoftDevice has been received and stored in bank 0 and 1. */
vcoubard 542:884f95bf5351 145 DFU_UPDATE_BOOT_COMPLETE, /**< Status update complete.*/
vcoubard 542:884f95bf5351 146 DFU_BANK_0_ERASED, /**< Status bank 0 erased.*/
vcoubard 542:884f95bf5351 147 DFU_TIMEOUT, /**< Status timeout.*/
vcoubard 542:884f95bf5351 148 DFU_RESET /**< Status Reset to indicate current update procedure has been aborted and system should reset. */
vcoubard 542:884f95bf5351 149 } dfu_update_status_code_t;
vcoubard 542:884f95bf5351 150
vcoubard 542:884f95bf5351 151 /**@brief Structure holding DFU complete event.
vcoubard 542:884f95bf5351 152 */
vcoubard 542:884f95bf5351 153 typedef struct
vcoubard 542:884f95bf5351 154 {
vcoubard 542:884f95bf5351 155 dfu_update_status_code_t status_code; /**< Device Firmware Update status. */
vcoubard 542:884f95bf5351 156 uint16_t app_crc; /**< CRC of the recieved application. */
vcoubard 542:884f95bf5351 157 uint32_t sd_size; /**< Size of the recieved SoftDevice. */
vcoubard 542:884f95bf5351 158 uint32_t bl_size; /**< Size of the recieved BootLoader. */
vcoubard 542:884f95bf5351 159 uint32_t app_size; /**< Size of the recieved Application. */
vcoubard 542:884f95bf5351 160 uint32_t sd_image_start; /**< Location in flash where the received SoftDevice image is stored. */
vcoubard 542:884f95bf5351 161 } dfu_update_status_t;
vcoubard 542:884f95bf5351 162
vcoubard 542:884f95bf5351 163 /**@brief Update complete handler type. */
vcoubard 542:884f95bf5351 164 typedef void (*dfu_complete_handler_t)(dfu_update_status_t dfu_update_status);
vcoubard 542:884f95bf5351 165
vcoubard 542:884f95bf5351 166 #endif // DFU_TYPES_H__
vcoubard 542:884f95bf5351 167
rgrover1 372:8f7d2137727a 168 /**@} */