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) 2014 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_init Init packet handling in DFU.
yihui 1:fc2f9d636751 16 * @{
yihui 1:fc2f9d636751 17 *
yihui 1:fc2f9d636751 18 * @brief Device Firmware Update module type and function declaration for init packet handling.
yihui 1:fc2f9d636751 19 *
yihui 1:fc2f9d636751 20 * @details This header contains basic functionality for performing safety checks on software
yihui 1:fc2f9d636751 21 * updates for nRF51 based devices. It provides a skeleton for pre-checking an init packet
yihui 1:fc2f9d636751 22 * to ensure the following image is compatible with this device. A safety check should
yihui 1:fc2f9d636751 23 * always be performed to prevent accidental flashing of unsupported applications or a
yihui 1:fc2f9d636751 24 * wrong combination of application and SoftDevice.
yihui 1:fc2f9d636751 25 * The device information contains information such as:
yihui 1:fc2f9d636751 26 * - Device type (2 bytes), for example Heart Rate. The device type is a number defined by
yihui 1:fc2f9d636751 27 * the customer. It can be located in UICR or FICR.
yihui 1:fc2f9d636751 28 * - Device revision (2 bytes), for example major revision 1, minor revision 0. The device
yihui 1:fc2f9d636751 29 * revision is a number defined by the customer. It can be located in UICR or FICR.
yihui 1:fc2f9d636751 30 * - List of SoftDevices supported by this application, for example
yihui 1:fc2f9d636751 31 * 0x0049 = S110v6_0_0
yihui 1:fc2f9d636751 32 * 0xFFFE = S110 development (any SoftDevice accepted),
yihui 1:fc2f9d636751 33 * - CRC or hash of firmware image
yihui 1:fc2f9d636751 34 *
yihui 1:fc2f9d636751 35 * @note This module does not support security features such as image signing, but the corresponding
yihui 1:fc2f9d636751 36 * implementation allows for such extensions.
yihui 1:fc2f9d636751 37 * If the init packet is signed by a trusted source, it must be decrypted before it can be
yihui 1:fc2f9d636751 38 * processed.
yihui 1:fc2f9d636751 39 */
yihui 1:fc2f9d636751 40
yihui 1:fc2f9d636751 41 #ifndef DFU_INIT_H__
yihui 1:fc2f9d636751 42 #define DFU_INIT_H__
yihui 1:fc2f9d636751 43
yihui 1:fc2f9d636751 44 #include <stdint.h>
yihui 1:fc2f9d636751 45 #include "nrf51.h"
yihui 1:fc2f9d636751 46
yihui 1:fc2f9d636751 47 /**@brief Structure contained in an init packet. Contains information on device type, revision, and
yihui 1:fc2f9d636751 48 * supported SoftDevices.
yihui 1:fc2f9d636751 49 */
yihui 1:fc2f9d636751 50 typedef struct
yihui 1:fc2f9d636751 51 {
yihui 1:fc2f9d636751 52 uint16_t device_type; /**< Device type (2 bytes), for example Heart Rate. This number must be defined by the customer before production. It can be located in UICR or FICR. */
yihui 1:fc2f9d636751 53 uint16_t device_rev; /**< Device revision (2 bytes), for example major revision 1, minor revision 0. This number must be defined by the customer before production. It can be located in UICR or FICR. */
yihui 1:fc2f9d636751 54 uint32_t app_version; /**< Application version for the image software. This field allows for additional checking, for example ensuring that a downgrade is not allowed. */
yihui 1:fc2f9d636751 55 uint16_t softdevice_len; /**< Number of different SoftDevice revisions compatible with this application. The list of SoftDevice firmware IDs is defined in @ref softdevice. */
yihui 1:fc2f9d636751 56 uint16_t softdevice[1]; /**< Variable length array of SoftDevices compatible with this application. The length of the array is specified in the length field. SoftDevice firmware id 0xFFFE indicates any SoftDevice. */
yihui 1:fc2f9d636751 57 } dfu_init_packet_t;
yihui 1:fc2f9d636751 58
yihui 1:fc2f9d636751 59 /**@brief Structure holding basic device information settings.
yihui 1:fc2f9d636751 60 */
yihui 1:fc2f9d636751 61 typedef struct
yihui 1:fc2f9d636751 62 {
yihui 1:fc2f9d636751 63 uint16_t device_type; /**< Device type (2 bytes), for example Heart Rate. This number must be defined by the customer before production. It can be located in UICR or FICR. */
yihui 1:fc2f9d636751 64 uint16_t device_rev; /**< Device revision (2 bytes), for example major revision 1, minor revision 0. This number must be defined by the customer before production. It can be located in UICR or FICR. */
yihui 1:fc2f9d636751 65 } dfu_device_info_t;
yihui 1:fc2f9d636751 66
yihui 1:fc2f9d636751 67 /** The device info offset can be modified to place the device info settings at a different location.
yihui 1:fc2f9d636751 68 * If the customer reserved UICR location is used for other application specific data, the offset
yihui 1:fc2f9d636751 69 * must be updated to avoid collision with that data.
yihui 1:fc2f9d636751 70 */
yihui 1:fc2f9d636751 71 /** [DFU UICR DEV offset] */
yihui 1:fc2f9d636751 72 #define UICR_CUSTOMER_DEVICE_INFO_OFFSET 0x0 /**< Device info offset inside the customer UICR reserved area. Customers may change this value to place the device information in a user-preferred location. */
yihui 1:fc2f9d636751 73 /** [DFU UICR DEV offset] */
yihui 1:fc2f9d636751 74
yihui 1:fc2f9d636751 75 #define UICR_CUSTOMER_RESERVED_OFFSET 0x80 /**< Customer reserved area in the UICR. The area from UICR + 0x80 is reserved for customer usage. */
yihui 1:fc2f9d636751 76 #define DFU_DEVICE_INFO_BASE (NRF_UICR_BASE + \
yihui 1:fc2f9d636751 77 UICR_CUSTOMER_RESERVED_OFFSET + \
yihui 1:fc2f9d636751 78 UICR_CUSTOMER_DEVICE_INFO_OFFSET) /**< The device information base address inside of UICR. */
yihui 1:fc2f9d636751 79 #define DFU_DEVICE_INFO ((dfu_device_info_t *)DFU_DEVICE_INFO_BASE) /**< The memory mapped structure for device information data. */
yihui 1:fc2f9d636751 80
yihui 1:fc2f9d636751 81 #define DFU_DEVICE_TYPE_EMPTY ((uint16_t)0xFFFF) /**< Mask indicating no device type is present in UICR. 0xFFFF is default flash pattern when not written with data. */
yihui 1:fc2f9d636751 82 #define DFU_DEVICE_REVISION_EMPTY ((uint16_t)0xFFFF) /**< Mask indicating no device revision is present in UICR. 0xFFFF is default flash pattern when not written with data. */
yihui 1:fc2f9d636751 83 #define DFU_SOFTDEVICE_ANY ((uint16_t)0xFFFE) /**< Mask indicating that any SoftDevice is allowed for updating this application. Allows for easy development. Not to be used in production images. */
yihui 1:fc2f9d636751 84
yihui 1:fc2f9d636751 85
yihui 1:fc2f9d636751 86 /**@brief DFU prevalidate call for pre-checking the received init packet.
yihui 1:fc2f9d636751 87 *
yihui 1:fc2f9d636751 88 * @details Pre-validation will safety check the firmware image to be transfered in second stage.
yihui 1:fc2f9d636751 89 * The function currently checks the device type, device revision, application firmware
yihui 1:fc2f9d636751 90 * version, and supported SoftDevices. More checks should be added according to
yihui 1:fc2f9d636751 91 * customer-specific requirements.
yihui 1:fc2f9d636751 92 *
yihui 1:fc2f9d636751 93 * @param[in] p_init_data Pointer to the init packet. If the init packet is encrypted or signed,
yihui 1:fc2f9d636751 94 * it must first be decrypted before being checked.
yihui 1:fc2f9d636751 95 * @param[in] init_data_len Length of the init data.
yihui 1:fc2f9d636751 96 *
yihui 1:fc2f9d636751 97 * @retval NRF_SUCCESS If the pre-validation succeeded, that means the image is
yihui 1:fc2f9d636751 98 * supported by the device and it is considered to come from a
yihui 1:fc2f9d636751 99 * trusted source (signing).
yihui 1:fc2f9d636751 100 * @retval NRF_ERROR_INVALID_DATA If the pre-validation failed, that means the image is not
yihui 1:fc2f9d636751 101 * supported by the device or comes from an un-trusted source
yihui 1:fc2f9d636751 102 * (signing).
yihui 1:fc2f9d636751 103 * @retval NRF_ERROR_INVALID_LENGTH If the size of the init packet is not within the limits of
yihui 1:fc2f9d636751 104 * the init packet handler.
yihui 1:fc2f9d636751 105 */
yihui 1:fc2f9d636751 106 uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len);
yihui 1:fc2f9d636751 107
yihui 1:fc2f9d636751 108 /**@brief DFU postvalidate call for post-checking the received image using the init packet.
yihui 1:fc2f9d636751 109 *
yihui 1:fc2f9d636751 110 * @details Post-validation can verify the integrity check the firmware image received before
yihui 1:fc2f9d636751 111 * activating the image.
yihui 1:fc2f9d636751 112 * Checks performed can be:
yihui 1:fc2f9d636751 113 * - A simple CRC as shown in the corresponding implementation of this API in the file
yihui 1:fc2f9d636751 114 * dfu_init_template.c
yihui 1:fc2f9d636751 115 * - A hash for better verification of the image.
yihui 1:fc2f9d636751 116 * - A signature to ensure the image originates from a trusted source.
yihui 1:fc2f9d636751 117 * Checks are intended to be expanded for customer-specific requirements.
yihui 1:fc2f9d636751 118 *
yihui 1:fc2f9d636751 119 * @param[in] p_image Pointer to the received image. The init data provided in the call
yihui 1:fc2f9d636751 120 * \ref dfu_init_prevalidate will be used for validating the image.
yihui 1:fc2f9d636751 121 * @param[in] image_len Length of the image data.
yihui 1:fc2f9d636751 122 *
yihui 1:fc2f9d636751 123 * @retval NRF_SUCCESS If the post-validation succeeded, that meant the integrity of the
yihui 1:fc2f9d636751 124 * image has been verified and the image originates from a trusted
yihui 1:fc2f9d636751 125 * source (signing).
yihui 1:fc2f9d636751 126 * @retval NRF_ERROR_INVALID_DATA If the post-validation failed, that meant the post check of the
yihui 1:fc2f9d636751 127 * image failed such as the CRC is not matching the image transfered
yihui 1:fc2f9d636751 128 * or the verification of the image fails (signing).
yihui 1:fc2f9d636751 129 */
yihui 1:fc2f9d636751 130 uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len);
yihui 1:fc2f9d636751 131
yihui 1:fc2f9d636751 132 #endif // DFU_INIT_H__
yihui 1:fc2f9d636751 133
yihui 1:fc2f9d636751 134 /**@} */