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