Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
640:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 640:c90ae1400bf2 1 /*
Vincent Coubard 640:c90ae1400bf2 2 * Copyright (c) Nordic Semiconductor ASA
Vincent Coubard 640:c90ae1400bf2 3 * All rights reserved.
Vincent Coubard 640:c90ae1400bf2 4 *
Vincent Coubard 640:c90ae1400bf2 5 * Redistribution and use in source and binary forms, with or without modification,
Vincent Coubard 640:c90ae1400bf2 6 * are permitted provided that the following conditions are met:
Vincent Coubard 640:c90ae1400bf2 7 *
Vincent Coubard 640:c90ae1400bf2 8 * 1. Redistributions of source code must retain the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 9 * list of conditions and the following disclaimer.
Vincent Coubard 640:c90ae1400bf2 10 *
Vincent Coubard 640:c90ae1400bf2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 12 * list of conditions and the following disclaimer in the documentation and/or
Vincent Coubard 640:c90ae1400bf2 13 * other materials provided with the distribution.
Vincent Coubard 640:c90ae1400bf2 14 *
Vincent Coubard 640:c90ae1400bf2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Vincent Coubard 640:c90ae1400bf2 16 * contributors to this software may be used to endorse or promote products
Vincent Coubard 640:c90ae1400bf2 17 * derived from this software without specific prior written permission.
Vincent Coubard 640:c90ae1400bf2 18 *
Vincent Coubard 640:c90ae1400bf2 19 *
Vincent Coubard 640:c90ae1400bf2 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Vincent Coubard 640:c90ae1400bf2 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 640:c90ae1400bf2 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 640:c90ae1400bf2 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Vincent Coubard 640:c90ae1400bf2 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 640:c90ae1400bf2 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 640:c90ae1400bf2 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Vincent Coubard 640:c90ae1400bf2 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 640:c90ae1400bf2 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 640:c90ae1400bf2 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 640:c90ae1400bf2 30 *
Vincent Coubard 640:c90ae1400bf2 31 */
Vincent Coubard 640:c90ae1400bf2 32 /**
Vincent Coubard 640:c90ae1400bf2 33 @defgroup nrf_mbr_api Master Boot Record API
Vincent Coubard 640:c90ae1400bf2 34 @{
Vincent Coubard 640:c90ae1400bf2 35
Vincent Coubard 640:c90ae1400bf2 36 @brief APIs for updating SoftDevice and BootLoader
Vincent Coubard 640:c90ae1400bf2 37
Vincent Coubard 640:c90ae1400bf2 38 */
Vincent Coubard 640:c90ae1400bf2 39
Vincent Coubard 640:c90ae1400bf2 40 /* Header guard */
Vincent Coubard 640:c90ae1400bf2 41 #ifndef NRF_MBR_H__
Vincent Coubard 640:c90ae1400bf2 42 #define NRF_MBR_H__
Vincent Coubard 640:c90ae1400bf2 43
Vincent Coubard 640:c90ae1400bf2 44 #include "nrf_svc.h"
Vincent Coubard 640:c90ae1400bf2 45 #include <stdint.h>
Vincent Coubard 640:c90ae1400bf2 46
Vincent Coubard 640:c90ae1400bf2 47
Vincent Coubard 640:c90ae1400bf2 48 /** @addtogroup NRF_MBR_DEFINES Defines
Vincent Coubard 640:c90ae1400bf2 49 * @{ */
Vincent Coubard 640:c90ae1400bf2 50
Vincent Coubard 640:c90ae1400bf2 51 /**@brief MBR SVC Base number. */
Vincent Coubard 640:c90ae1400bf2 52 #define MBR_SVC_BASE (0x18)
Vincent Coubard 640:c90ae1400bf2 53
Vincent Coubard 640:c90ae1400bf2 54 /**@brief Page size in words. */
Vincent Coubard 640:c90ae1400bf2 55 #define PAGE_SIZE_IN_WORDS 256
Vincent Coubard 640:c90ae1400bf2 56 /** @} */
Vincent Coubard 640:c90ae1400bf2 57
Vincent Coubard 640:c90ae1400bf2 58 /** @addtogroup NRF_MBR_ENUMS Enumerations
Vincent Coubard 640:c90ae1400bf2 59 * @{ */
Vincent Coubard 640:c90ae1400bf2 60
Vincent Coubard 640:c90ae1400bf2 61 /**@brief nRF Master Boot Record API SVC numbers. */
Vincent Coubard 640:c90ae1400bf2 62 enum NRF_MBR_SVCS
Vincent Coubard 640:c90ae1400bf2 63 {
Vincent Coubard 640:c90ae1400bf2 64 SD_MBR_COMMAND = MBR_SVC_BASE, /**< ::sd_mbr_command */
Vincent Coubard 640:c90ae1400bf2 65 };
Vincent Coubard 640:c90ae1400bf2 66
Vincent Coubard 640:c90ae1400bf2 67 /**@brief Possible values for ::sd_mbr_command_t.command */
Vincent Coubard 640:c90ae1400bf2 68 enum NRF_MBR_COMMANDS
Vincent Coubard 640:c90ae1400bf2 69 {
Vincent Coubard 640:c90ae1400bf2 70 SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see sd_mbr_command_copy_bl_t */
Vincent Coubard 640:c90ae1400bf2 71 SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
Vincent Coubard 640:c90ae1400bf2 72 SD_MBR_COMMAND_INIT_SD, /**< Init forwarding interrupts to SD, and run reset function in SD*/
Vincent Coubard 640:c90ae1400bf2 73 SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
Vincent Coubard 640:c90ae1400bf2 74 SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Start forwarding all exception to this address @see ::sd_mbr_command_vector_table_base_set_t*/
Vincent Coubard 640:c90ae1400bf2 75 };
Vincent Coubard 640:c90ae1400bf2 76
Vincent Coubard 640:c90ae1400bf2 77 /** @} */
Vincent Coubard 640:c90ae1400bf2 78
Vincent Coubard 640:c90ae1400bf2 79 /** @addtogroup NRF_MBR_TYPES Types
Vincent Coubard 640:c90ae1400bf2 80 * @{ */
Vincent Coubard 640:c90ae1400bf2 81
Vincent Coubard 640:c90ae1400bf2 82 /**@brief This command copies part of a new SoftDevice
Vincent Coubard 640:c90ae1400bf2 83 * The destination area is erased before copying.
Vincent Coubard 640:c90ae1400bf2 84 * If dst is in the middle of a flash page, that whole flash page will be erased.
Vincent Coubard 640:c90ae1400bf2 85 * If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
Vincent Coubard 640:c90ae1400bf2 86 *
Vincent Coubard 640:c90ae1400bf2 87 * The user of this function is responsible for setting the PROTENSET registers.
Vincent Coubard 640:c90ae1400bf2 88 *
Vincent Coubard 640:c90ae1400bf2 89 * @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
Vincent Coubard 640:c90ae1400bf2 90 * @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
Vincent Coubard 640:c90ae1400bf2 91 */
Vincent Coubard 640:c90ae1400bf2 92 typedef struct
Vincent Coubard 640:c90ae1400bf2 93 {
Vincent Coubard 640:c90ae1400bf2 94 uint32_t *src; /**< Pointer to the source of data to be copied.*/
Vincent Coubard 640:c90ae1400bf2 95 uint32_t *dst; /**< Pointer to the destination where the content is to be copied.*/
Vincent Coubard 640:c90ae1400bf2 96 uint32_t len; /**< Number of 32 bit words to copy. Must be a multiple of @ref PAGE_SIZE_IN_WORDS words.*/
Vincent Coubard 640:c90ae1400bf2 97 } sd_mbr_command_copy_sd_t;
Vincent Coubard 640:c90ae1400bf2 98
Vincent Coubard 640:c90ae1400bf2 99
Vincent Coubard 640:c90ae1400bf2 100 /**@brief This command works like memcmp, but takes the length in words.
Vincent Coubard 640:c90ae1400bf2 101 *
Vincent Coubard 640:c90ae1400bf2 102 * @retval ::NRF_SUCCESS indicates that the contents of both memory blocks are equal.
Vincent Coubard 640:c90ae1400bf2 103 * @retval ::NRF_ERROR_NULL indicates that the contents of the memory blocks are not equal.
Vincent Coubard 640:c90ae1400bf2 104 */
Vincent Coubard 640:c90ae1400bf2 105 typedef struct
Vincent Coubard 640:c90ae1400bf2 106 {
Vincent Coubard 640:c90ae1400bf2 107 uint32_t *ptr1; /**< Pointer to block of memory. */
Vincent Coubard 640:c90ae1400bf2 108 uint32_t *ptr2; /**< Pointer to block of memory. */
Vincent Coubard 640:c90ae1400bf2 109 uint32_t len; /**< Number of 32 bit words to compare.*/
Vincent Coubard 640:c90ae1400bf2 110 } sd_mbr_command_compare_t;
Vincent Coubard 640:c90ae1400bf2 111
Vincent Coubard 640:c90ae1400bf2 112
Vincent Coubard 640:c90ae1400bf2 113 /**@brief This command copies a new BootLoader.
Vincent Coubard 640:c90ae1400bf2 114 * With this command, destination of BootLoader is always the address written in NRF_UICR->BOOTADDR.
Vincent Coubard 640:c90ae1400bf2 115 *
Vincent Coubard 640:c90ae1400bf2 116 * Destination is erased by this function.
Vincent Coubard 640:c90ae1400bf2 117 * If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
Vincent Coubard 640:c90ae1400bf2 118 *
Vincent Coubard 640:c90ae1400bf2 119 * This function will use PROTENSET to protect the flash that is not intended to be written.
Vincent Coubard 640:c90ae1400bf2 120 *
Vincent Coubard 640:c90ae1400bf2 121 * On Success, this function will not return. It will start the new BootLoader from reset-vector as normal.
Vincent Coubard 640:c90ae1400bf2 122 *
Vincent Coubard 640:c90ae1400bf2 123 * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
Vincent Coubard 640:c90ae1400bf2 124 * @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set.
Vincent Coubard 640:c90ae1400bf2 125 * @retval ::NRF_ERROR_INVALID_LENGTH if parameters attempts to read or write outside flash area.
Vincent Coubard 640:c90ae1400bf2 126 */
Vincent Coubard 640:c90ae1400bf2 127 typedef struct
Vincent Coubard 640:c90ae1400bf2 128 {
Vincent Coubard 640:c90ae1400bf2 129 uint32_t *bl_src; /**< Pointer to the source of the Bootloader to be be copied.*/
Vincent Coubard 640:c90ae1400bf2 130 uint32_t bl_len; /**< Number of 32 bit words to copy for BootLoader. */
Vincent Coubard 640:c90ae1400bf2 131 } sd_mbr_command_copy_bl_t;
Vincent Coubard 640:c90ae1400bf2 132
Vincent Coubard 640:c90ae1400bf2 133 /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
Vincent Coubard 640:c90ae1400bf2 134 *
Vincent Coubard 640:c90ae1400bf2 135 * Once this function has been called, this address is where the MBR will start to forward interrupts to after a reset.
Vincent Coubard 640:c90ae1400bf2 136 *
Vincent Coubard 640:c90ae1400bf2 137 * To restore default forwarding this function should be called with @param address set to 0.
Vincent Coubard 640:c90ae1400bf2 138 * The MBR will then start forwarding to interrupts to the address in NFR_UICR->BOOTADDR or to the SoftDevice if the BOOTADDR is not set.
Vincent Coubard 640:c90ae1400bf2 139 *
Vincent Coubard 640:c90ae1400bf2 140 * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
Vincent Coubard 640:c90ae1400bf2 141 * @retval ::NRF_ERROR_INVALID_ADDR if parameter address is outside of the flash size.
Vincent Coubard 640:c90ae1400bf2 142 */
Vincent Coubard 640:c90ae1400bf2 143 typedef struct
Vincent Coubard 640:c90ae1400bf2 144 {
Vincent Coubard 640:c90ae1400bf2 145 uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
Vincent Coubard 640:c90ae1400bf2 146 } sd_mbr_command_vector_table_base_set_t;
Vincent Coubard 640:c90ae1400bf2 147
Vincent Coubard 640:c90ae1400bf2 148 typedef struct
Vincent Coubard 640:c90ae1400bf2 149 {
Vincent Coubard 640:c90ae1400bf2 150 uint32_t command; /**< type of command to be issued see @ref NRF_MBR_COMMANDS. */
Vincent Coubard 640:c90ae1400bf2 151 union
Vincent Coubard 640:c90ae1400bf2 152 {
Vincent Coubard 640:c90ae1400bf2 153 sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/
Vincent Coubard 640:c90ae1400bf2 154 sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy BootLoader.*/
Vincent Coubard 640:c90ae1400bf2 155 sd_mbr_command_compare_t compare; /**< Parameters for verify.*/
Vincent Coubard 640:c90ae1400bf2 156 sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set.*/
Vincent Coubard 640:c90ae1400bf2 157 } params;
Vincent Coubard 640:c90ae1400bf2 158 } sd_mbr_command_t;
Vincent Coubard 640:c90ae1400bf2 159
Vincent Coubard 640:c90ae1400bf2 160 /** @} */
Vincent Coubard 640:c90ae1400bf2 161
Vincent Coubard 640:c90ae1400bf2 162 /** @addtogroup NRF_MBR_FUNCTIONS Functions
Vincent Coubard 640:c90ae1400bf2 163 * @{ */
Vincent Coubard 640:c90ae1400bf2 164
Vincent Coubard 640:c90ae1400bf2 165 /**@brief Issue Master Boot Record commands
Vincent Coubard 640:c90ae1400bf2 166 *
Vincent Coubard 640:c90ae1400bf2 167 * Commands used when updating a SoftDevice and bootloader.
Vincent Coubard 640:c90ae1400bf2 168 *
Vincent Coubard 640:c90ae1400bf2 169 * @param[in] param Pointer to a struct describing the command.
Vincent Coubard 640:c90ae1400bf2 170 *
Vincent Coubard 640:c90ae1400bf2 171 *@note for retvals see ::sd_mbr_command_copy_sd_t ::sd_mbr_command_copy_bl_t ::sd_mbr_command_compare_t
Vincent Coubard 640:c90ae1400bf2 172
Vincent Coubard 640:c90ae1400bf2 173 */
Vincent Coubard 640:c90ae1400bf2 174 SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));
Vincent Coubard 640:c90ae1400bf2 175
Vincent Coubard 640:c90ae1400bf2 176 /** @} */
Vincent Coubard 640:c90ae1400bf2 177 #endif // NRF_MBR_H__
Vincent Coubard 640:c90ae1400bf2 178
Vincent Coubard 640:c90ae1400bf2 179 /**
Vincent Coubard 640:c90ae1400bf2 180 @}
Vincent Coubard 640:c90ae1400bf2 181 */