To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

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