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

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:40 2016 +0100
Revision:
19:47192cb9def7
Parent:
10:233fefd8162b
Child:
20:a90c48eb1d30
Synchronized with git rev 9251259f
Author: Liyou Zhou
Copy over coresponding files from nordic-sdk 9.0.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 19:47192cb9def7 1 /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
vcoubard 19:47192cb9def7 2 *
vcoubard 19:47192cb9def7 3 * The information contained herein is property of Nordic Semiconductor ASA.
vcoubard 19:47192cb9def7 4 * Terms and conditions of usage are described in detail in NORDIC
vcoubard 19:47192cb9def7 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
vcoubard 19:47192cb9def7 6 *
vcoubard 19:47192cb9def7 7 * Licensees are granted free, non-transferable use of the information. NO
vcoubard 19:47192cb9def7 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
vcoubard 19:47192cb9def7 9 * the file.
vcoubard 19:47192cb9def7 10 *
Vincent Coubard 0:f2542974c862 11 */
Vincent Coubard 0:f2542974c862 12
Vincent Coubard 0:f2542974c862 13 /**@file
Vincent Coubard 0:f2542974c862 14 *
Vincent Coubard 0:f2542974c862 15 * @defgroup nrf_dfu_types Types and definitions.
Vincent Coubard 0:f2542974c862 16 * @{
Vincent Coubard 0:f2542974c862 17 *
Vincent Coubard 0:f2542974c862 18 * @ingroup nrf_dfu
Vincent Coubard 0:f2542974c862 19 *
Vincent Coubard 0:f2542974c862 20 * @brief Device Firmware Update module type and definitions.
Vincent Coubard 0:f2542974c862 21 */
Vincent Coubard 0:f2542974c862 22
Vincent Coubard 0:f2542974c862 23 #ifndef DFU_TYPES_H__
Vincent Coubard 0:f2542974c862 24 #define DFU_TYPES_H__
Vincent Coubard 0:f2542974c862 25
Vincent Coubard 0:f2542974c862 26 #include <stdint.h>
vcoubard 19:47192cb9def7 27 #include "nrf_sdm.h"
vcoubard 19:47192cb9def7 28 #include "nrf.h"
Vincent Coubard 0:f2542974c862 29 #include "app_util.h"
Vincent Coubard 0:f2542974c862 30
Vincent Coubard 0:f2542974c862 31 #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 32
vcoubard 19:47192cb9def7 33 #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 19:47192cb9def7 34 #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 35
vcoubard 19:47192cb9def7 36 #ifdef NRF51
vcoubard 19:47192cb9def7 37 #ifdef SIGNING
vcoubard 19:47192cb9def7 38 #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 19:47192cb9def7 39 #define BOOTLOADER_SETTINGS_ADDRESS 0x0003D800 /**< The field specifies the page location of the bootloader settings address. */
vcoubard 19:47192cb9def7 40 #else
Vincent Coubard 0:f2542974c862 41 #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 42 #define BOOTLOADER_SETTINGS_ADDRESS 0x0003FC00 /**< The field specifies the page location of the bootloader settings address. */
vcoubard 19:47192cb9def7 43 #endif
vcoubard 19:47192cb9def7 44
vcoubard 19:47192cb9def7 45 #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 19:47192cb9def7 46 #elif NRF52
vcoubard 19:47192cb9def7 47 #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 19:47192cb9def7 48 #define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */
vcoubard 19:47192cb9def7 49 #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 19:47192cb9def7 50 #else
vcoubard 19:47192cb9def7 51 #error No target defined
vcoubard 19:47192cb9def7 52 #endif
Vincent Coubard 0:f2542974c862 53
Vincent Coubard 0:f2542974c862 54 #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 55
Vincent Coubard 0:f2542974c862 56 #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 57 #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 58 #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 59 #define DFU_IMAGE_MAX_SIZE_BANKED ((DFU_REGION_TOTAL_SIZE - \
Vincent Coubard 0:f2542974c862 60 DFU_APP_DATA_RESERVED - \
Vincent Coubard 0:f2542974c862 61 DFU_BANK_PADDING) / 2) /**< Maximum size of an application, excluding save data from the application. */
Vincent Coubard 0:f2542974c862 62
Vincent Coubard 0:f2542974c862 63 #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 64
Vincent Coubard 0:f2542974c862 65 #define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */
Vincent Coubard 0:f2542974c862 66 #define DFU_BANK_1_REGION_START (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED) /**< Bank 1 region start. */
Vincent Coubard 0:f2542974c862 67
Vincent Coubard 0:f2542974c862 68 #define EMPTY_FLASH_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
Vincent Coubard 0:f2542974c862 69
Vincent Coubard 0:f2542974c862 70 #define INVALID_PACKET 0x00 /**< Invalid packet identifies. */
Vincent Coubard 0:f2542974c862 71 #define INIT_PACKET 0x01 /**< Packet identifies for initialization packet. */
Vincent Coubard 0:f2542974c862 72 #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 73 #define START_PACKET 0x03 /**< Packet identifies for the Data Start Packet. */
Vincent Coubard 0:f2542974c862 74 #define DATA_PACKET 0x04 /**< Packet identifies for a Data Packet. */
Vincent Coubard 0:f2542974c862 75 #define STOP_DATA_PACKET 0x05 /**< Packet identifies for the Data Stop Packet. */
Vincent Coubard 0:f2542974c862 76
Vincent Coubard 0:f2542974c862 77 #define DFU_UPDATE_SD 0x01 /**< Bit field indicating update of SoftDevice is ongoing. */
Vincent Coubard 0:f2542974c862 78 #define DFU_UPDATE_BL 0x02 /**< Bit field indicating update of bootloader is ongoing. */
Vincent Coubard 0:f2542974c862 79 #define DFU_UPDATE_APP 0x04 /**< Bit field indicating update of application is ongoing. */
Vincent Coubard 0:f2542974c862 80
Vincent Coubard 0:f2542974c862 81 #define DFU_INIT_RX 0x00 /**< Op Code identifies for receiving init packet. */
Vincent Coubard 0:f2542974c862 82 #define DFU_INIT_COMPLETE 0x01 /**< Op Code identifies for transmission complete of init packet. */
Vincent Coubard 0:f2542974c862 83
Vincent Coubard 0:f2542974c862 84 // Safe guard to ensure during compile time that the DFU_APP_DATA_RESERVED is a multiple of page size.
Vincent Coubard 0:f2542974c862 85 STATIC_ASSERT((((DFU_APP_DATA_RESERVED) & (CODE_PAGE_SIZE - 1)) == 0x00));
Vincent Coubard 0:f2542974c862 86
Vincent Coubard 0:f2542974c862 87 /**@brief Structure holding a start packet containing update mode and image sizes.
Vincent Coubard 0:f2542974c862 88 */
Vincent Coubard 0:f2542974c862 89 typedef struct
Vincent Coubard 0:f2542974c862 90 {
Vincent Coubard 0:f2542974c862 91 uint8_t dfu_update_mode; /**< Packet type, used to identify the content of the received packet referenced by data packet. */
Vincent Coubard 0:f2542974c862 92 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 93 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 94 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 95 } dfu_start_packet_t;
Vincent Coubard 0:f2542974c862 96
Vincent Coubard 0:f2542974c862 97 /**@brief Structure holding a bootloader init/data packet received.
Vincent Coubard 0:f2542974c862 98 */
Vincent Coubard 0:f2542974c862 99 typedef struct
Vincent Coubard 0:f2542974c862 100 {
Vincent Coubard 0:f2542974c862 101 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 102 uint32_t * p_data_packet; /**< Data Packet received. Each data is a word size entry. */
Vincent Coubard 0:f2542974c862 103 } dfu_data_packet_t;
Vincent Coubard 0:f2542974c862 104
Vincent Coubard 0:f2542974c862 105 /**@brief Structure for holding dfu update packet. Packet type indicate the type of packet.
Vincent Coubard 0:f2542974c862 106 */
Vincent Coubard 0:f2542974c862 107 typedef struct
Vincent Coubard 0:f2542974c862 108 {
Vincent Coubard 0:f2542974c862 109 uint32_t packet_type; /**< Packet type, used to identify the content of the received packet referenced by data packet. */
Vincent Coubard 0:f2542974c862 110 union
Vincent Coubard 0:f2542974c862 111 {
Vincent Coubard 0:f2542974c862 112 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 113 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 114 } params;
Vincent Coubard 0:f2542974c862 115 } dfu_update_packet_t;
Vincent Coubard 0:f2542974c862 116
Vincent Coubard 0:f2542974c862 117 /**@brief DFU status error codes.
Vincent Coubard 0:f2542974c862 118 */
Vincent Coubard 0:f2542974c862 119 typedef enum
Vincent Coubard 0:f2542974c862 120 {
Vincent Coubard 0:f2542974c862 121 DFU_UPDATE_APP_COMPLETE, /**< Status update of application complete.*/
Vincent Coubard 0:f2542974c862 122 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 123 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 124 DFU_UPDATE_BOOT_COMPLETE, /**< Status update complete.*/
Vincent Coubard 0:f2542974c862 125 DFU_BANK_0_ERASED, /**< Status bank 0 erased.*/
Vincent Coubard 0:f2542974c862 126 DFU_TIMEOUT, /**< Status timeout.*/
Vincent Coubard 0:f2542974c862 127 DFU_RESET /**< Status Reset to indicate current update procedure has been aborted and system should reset. */
Vincent Coubard 0:f2542974c862 128 } dfu_update_status_code_t;
Vincent Coubard 0:f2542974c862 129
Vincent Coubard 0:f2542974c862 130 /**@brief Structure holding DFU complete event.
Vincent Coubard 0:f2542974c862 131 */
Vincent Coubard 0:f2542974c862 132 typedef struct
Vincent Coubard 0:f2542974c862 133 {
Vincent Coubard 0:f2542974c862 134 dfu_update_status_code_t status_code; /**< Device Firmware Update status. */
Vincent Coubard 0:f2542974c862 135 uint16_t app_crc; /**< CRC of the recieved application. */
Vincent Coubard 0:f2542974c862 136 uint32_t sd_size; /**< Size of the recieved SoftDevice. */
Vincent Coubard 0:f2542974c862 137 uint32_t bl_size; /**< Size of the recieved BootLoader. */
Vincent Coubard 0:f2542974c862 138 uint32_t app_size; /**< Size of the recieved Application. */
Vincent Coubard 0:f2542974c862 139 uint32_t sd_image_start; /**< Location in flash where the received SoftDevice image is stored. */
Vincent Coubard 0:f2542974c862 140 } dfu_update_status_t;
Vincent Coubard 0:f2542974c862 141
Vincent Coubard 0:f2542974c862 142 /**@brief Update complete handler type. */
Vincent Coubard 0:f2542974c862 143 typedef void (*dfu_complete_handler_t)(dfu_update_status_t dfu_update_status);
Vincent Coubard 0:f2542974c862 144
Vincent Coubard 0:f2542974c862 145 #endif // DFU_TYPES_H__
Vincent Coubard 0:f2542974c862 146
vcoubard 1:ebc0e0ef0a11 147 /**@} */