Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:49 2016 +0100
Revision:
24:2aea0c1c57ee
Parent:
22:67a8d2c0bbbf
Child:
27:0fe148f1bca3
Synchronized with git rev 709d3cdb
Author: Liyou Zhou
Change version number in README

Who changed what in which revision?

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