Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

UserRevisionLine numberNew 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 NRF52
sahilmgandhi 18:6a4db94011d3 55 #error "This header file shall only be included for nRF52 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 MBR_PAGE_SIZE_IN_WORDS (1024)
sahilmgandhi 18:6a4db94011d3 70
sahilmgandhi 18:6a4db94011d3 71 /** @brief The size that must be reserved for the MBR when a softdevice is written to flash.
sahilmgandhi 18:6a4db94011d3 72 This is the offset where the first byte of the softdevice hex file is written.*/
sahilmgandhi 18:6a4db94011d3 73 #define MBR_SIZE (0x1000)
sahilmgandhi 18:6a4db94011d3 74
sahilmgandhi 18:6a4db94011d3 75 /** @} */
sahilmgandhi 18:6a4db94011d3 76
sahilmgandhi 18:6a4db94011d3 77 /** @addtogroup NRF_MBR_ENUMS Enumerations
sahilmgandhi 18:6a4db94011d3 78 * @{ */
sahilmgandhi 18:6a4db94011d3 79
sahilmgandhi 18:6a4db94011d3 80 /**@brief nRF Master Boot Record API SVC numbers. */
sahilmgandhi 18:6a4db94011d3 81 enum NRF_MBR_SVCS
sahilmgandhi 18:6a4db94011d3 82 {
sahilmgandhi 18:6a4db94011d3 83 SD_MBR_COMMAND = MBR_SVC_BASE, /**< ::sd_mbr_command */
sahilmgandhi 18:6a4db94011d3 84 };
sahilmgandhi 18:6a4db94011d3 85
sahilmgandhi 18:6a4db94011d3 86 /**@brief Possible values for ::sd_mbr_command_t.command */
sahilmgandhi 18:6a4db94011d3 87 enum NRF_MBR_COMMANDS
sahilmgandhi 18:6a4db94011d3 88 {
sahilmgandhi 18:6a4db94011d3 89 SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see sd_mbr_command_copy_bl_t */
sahilmgandhi 18:6a4db94011d3 90 SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
sahilmgandhi 18:6a4db94011d3 91 SD_MBR_COMMAND_INIT_SD, /**< Init forwarding interrupts to SD, and run reset function in SD*/
sahilmgandhi 18:6a4db94011d3 92 SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
sahilmgandhi 18:6a4db94011d3 93 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 94 };
sahilmgandhi 18:6a4db94011d3 95
sahilmgandhi 18:6a4db94011d3 96 /** @} */
sahilmgandhi 18:6a4db94011d3 97
sahilmgandhi 18:6a4db94011d3 98 /** @addtogroup NRF_MBR_TYPES Types
sahilmgandhi 18:6a4db94011d3 99 * @{ */
sahilmgandhi 18:6a4db94011d3 100
sahilmgandhi 18:6a4db94011d3 101 /**@brief This command copies part of a new SoftDevice
sahilmgandhi 18:6a4db94011d3 102 * The destination area is erased before copying.
sahilmgandhi 18:6a4db94011d3 103 * If dst is in the middle of a flash page, that whole flash page will be erased.
sahilmgandhi 18:6a4db94011d3 104 * If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
sahilmgandhi 18:6a4db94011d3 105 *
sahilmgandhi 18:6a4db94011d3 106 * The user of this function is responsible for setting the BPROT registers.
sahilmgandhi 18:6a4db94011d3 107 *
sahilmgandhi 18:6a4db94011d3 108 * @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
sahilmgandhi 18:6a4db94011d3 109 * @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
sahilmgandhi 18:6a4db94011d3 110 */
sahilmgandhi 18:6a4db94011d3 111 typedef struct
sahilmgandhi 18:6a4db94011d3 112 {
sahilmgandhi 18:6a4db94011d3 113 uint32_t *src; /**< Pointer to the source of data to be copied.*/
sahilmgandhi 18:6a4db94011d3 114 uint32_t *dst; /**< Pointer to the destination where the content is to be copied.*/
sahilmgandhi 18:6a4db94011d3 115 uint32_t len; /**< Number of 32 bit words to copy. Must be a multiple of @ref MBR_PAGE_SIZE_IN_WORDS words.*/
sahilmgandhi 18:6a4db94011d3 116 } sd_mbr_command_copy_sd_t;
sahilmgandhi 18:6a4db94011d3 117
sahilmgandhi 18:6a4db94011d3 118
sahilmgandhi 18:6a4db94011d3 119 /**@brief This command works like memcmp, but takes the length in words.
sahilmgandhi 18:6a4db94011d3 120 *
sahilmgandhi 18:6a4db94011d3 121 * @retval ::NRF_SUCCESS indicates that the contents of both memory blocks are equal.
sahilmgandhi 18:6a4db94011d3 122 * @retval ::NRF_ERROR_NULL indicates that the contents of the memory blocks are not equal.
sahilmgandhi 18:6a4db94011d3 123 */
sahilmgandhi 18:6a4db94011d3 124 typedef struct
sahilmgandhi 18:6a4db94011d3 125 {
sahilmgandhi 18:6a4db94011d3 126 uint32_t *ptr1; /**< Pointer to block of memory. */
sahilmgandhi 18:6a4db94011d3 127 uint32_t *ptr2; /**< Pointer to block of memory. */
sahilmgandhi 18:6a4db94011d3 128 uint32_t len; /**< Number of 32 bit words to compare.*/
sahilmgandhi 18:6a4db94011d3 129 } sd_mbr_command_compare_t;
sahilmgandhi 18:6a4db94011d3 130
sahilmgandhi 18:6a4db94011d3 131
sahilmgandhi 18:6a4db94011d3 132 /**@brief This command copies a new BootLoader.
sahilmgandhi 18:6a4db94011d3 133 * With this command, destination of BootLoader is always the address written in NRF_UICR->BOOTADDR.
sahilmgandhi 18:6a4db94011d3 134 *
sahilmgandhi 18:6a4db94011d3 135 * Destination is erased by this function.
sahilmgandhi 18:6a4db94011d3 136 * If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
sahilmgandhi 18:6a4db94011d3 137 *
sahilmgandhi 18:6a4db94011d3 138 * This function will use PROTENSET to protect the flash that is not intended to be written.
sahilmgandhi 18:6a4db94011d3 139 *
sahilmgandhi 18:6a4db94011d3 140 * On Success, this function will not return. It will start the new BootLoader from reset-vector as normal.
sahilmgandhi 18:6a4db94011d3 141 *
sahilmgandhi 18:6a4db94011d3 142 * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
sahilmgandhi 18:6a4db94011d3 143 * @retval ::NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set.
sahilmgandhi 18:6a4db94011d3 144 * @retval ::NRF_ERROR_INVALID_LENGTH if parameters attempts to read or write outside flash area.
sahilmgandhi 18:6a4db94011d3 145 * @retval ::NRF_ERROR_NO_MEM if no parameter page is provided (see sds for more info)
sahilmgandhi 18:6a4db94011d3 146 */
sahilmgandhi 18:6a4db94011d3 147 typedef struct
sahilmgandhi 18:6a4db94011d3 148 {
sahilmgandhi 18:6a4db94011d3 149 uint32_t *bl_src; /**< Pointer to the source of the Bootloader to be be copied.*/
sahilmgandhi 18:6a4db94011d3 150 uint32_t bl_len; /**< Number of 32 bit words to copy for BootLoader. */
sahilmgandhi 18:6a4db94011d3 151 } sd_mbr_command_copy_bl_t;
sahilmgandhi 18:6a4db94011d3 152
sahilmgandhi 18:6a4db94011d3 153 /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
sahilmgandhi 18:6a4db94011d3 154 *
sahilmgandhi 18:6a4db94011d3 155 * Once this function has been called, this address is where the MBR will start to forward interrupts to after a reset.
sahilmgandhi 18:6a4db94011d3 156 *
sahilmgandhi 18:6a4db94011d3 157 * To restore default forwarding this function should be called with @param address set to 0.
sahilmgandhi 18:6a4db94011d3 158 * 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 159 *
sahilmgandhi 18:6a4db94011d3 160 * On Success, this function will not return. It will reset the device.
sahilmgandhi 18:6a4db94011d3 161 *
sahilmgandhi 18:6a4db94011d3 162 * @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
sahilmgandhi 18:6a4db94011d3 163 * @retval ::NRF_ERROR_INVALID_ADDR if parameter address is outside of the flash size.
sahilmgandhi 18:6a4db94011d3 164 * @retval ::NRF_ERROR_NO_MEM if no parameter page is provided (see sds for more info)
sahilmgandhi 18:6a4db94011d3 165 */
sahilmgandhi 18:6a4db94011d3 166 typedef struct
sahilmgandhi 18:6a4db94011d3 167 {
sahilmgandhi 18:6a4db94011d3 168 uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
sahilmgandhi 18:6a4db94011d3 169 } sd_mbr_command_vector_table_base_set_t;
sahilmgandhi 18:6a4db94011d3 170
sahilmgandhi 18:6a4db94011d3 171
sahilmgandhi 18:6a4db94011d3 172 typedef struct
sahilmgandhi 18:6a4db94011d3 173 {
sahilmgandhi 18:6a4db94011d3 174 uint32_t command; /**< type of command to be issued see @ref NRF_MBR_COMMANDS. */
sahilmgandhi 18:6a4db94011d3 175 union
sahilmgandhi 18:6a4db94011d3 176 {
sahilmgandhi 18:6a4db94011d3 177 sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/
sahilmgandhi 18:6a4db94011d3 178 sd_mbr_command_compare_t compare; /**< Parameters for verify.*/
sahilmgandhi 18:6a4db94011d3 179 sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy BootLoader. Requires parameter page. */
sahilmgandhi 18:6a4db94011d3 180 sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set. Requires parameter page.*/
sahilmgandhi 18:6a4db94011d3 181 } params;
sahilmgandhi 18:6a4db94011d3 182 } sd_mbr_command_t;
sahilmgandhi 18:6a4db94011d3 183
sahilmgandhi 18:6a4db94011d3 184 /** @} */
sahilmgandhi 18:6a4db94011d3 185
sahilmgandhi 18:6a4db94011d3 186 /** @addtogroup NRF_MBR_FUNCTIONS Functions
sahilmgandhi 18:6a4db94011d3 187 * @{ */
sahilmgandhi 18:6a4db94011d3 188
sahilmgandhi 18:6a4db94011d3 189 /**@brief Issue Master Boot Record commands
sahilmgandhi 18:6a4db94011d3 190 *
sahilmgandhi 18:6a4db94011d3 191 * Commands used when updating a SoftDevice and bootloader.
sahilmgandhi 18:6a4db94011d3 192 *
sahilmgandhi 18:6a4db94011d3 193 * The SD_MBR_COMMAND_COPY_BL and SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET requires parameters to be
sahilmgandhi 18:6a4db94011d3 194 * retained by the MBR when resetting the IC. This is done in a separate flash page
sahilmgandhi 18:6a4db94011d3 195 * provided by the application. The uicr register UICR.NRFFW[1] must be set
sahilmgandhi 18:6a4db94011d3 196 * to an address corresponding to a page in the application flash space. This page will be cleared
sahilmgandhi 18:6a4db94011d3 197 * by the MBR and used to store the command before reset. When the UICR.NRFFW[1] field is set
sahilmgandhi 18:6a4db94011d3 198 * the page it refers to must not be used by the application. If the UICR.NRFFW[1] is set to
sahilmgandhi 18:6a4db94011d3 199 * 0xFFFFFFFF (the default) MBR commands which use flash will be unavailable and return
sahilmgandhi 18:6a4db94011d3 200 * NRF_ERROR_NO_MEM.
sahilmgandhi 18:6a4db94011d3 201 *
sahilmgandhi 18:6a4db94011d3 202 * @param[in] param Pointer to a struct describing the command.
sahilmgandhi 18:6a4db94011d3 203 *
sahilmgandhi 18:6a4db94011d3 204 * @note for retvals see ::sd_mbr_command_copy_sd_t ::sd_mbr_command_copy_bl_t ::sd_mbr_command_compare_t ::sd_mbr_command_vector_table_base_set_t
sahilmgandhi 18:6a4db94011d3 205 *
sahilmgandhi 18:6a4db94011d3 206 * @retval NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
sahilmgandhi 18:6a4db94011d3 207 * @retval NRF_ERROR_INVALID_PARAM if an invalid command is given.
sahilmgandhi 18:6a4db94011d3 208 */
sahilmgandhi 18:6a4db94011d3 209 SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));
sahilmgandhi 18:6a4db94011d3 210
sahilmgandhi 18:6a4db94011d3 211 /** @} */
sahilmgandhi 18:6a4db94011d3 212
sahilmgandhi 18:6a4db94011d3 213 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 214 }
sahilmgandhi 18:6a4db94011d3 215 #endif
sahilmgandhi 18:6a4db94011d3 216 #endif // NRF_MBR_H__
sahilmgandhi 18:6a4db94011d3 217
sahilmgandhi 18:6a4db94011d3 218 /**
sahilmgandhi 18:6a4db94011d3 219 @}
sahilmgandhi 18:6a4db94011d3 220 */