Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:56 2016 +0100
Revision:
28:041dac1366b2
Parent:
20:a90c48eb1d30
Child:
29:286940b7ee5a
Synchronized with git rev 012b8118
Author: Liyou Zhou
Pull in files from sdk 10.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 28:041dac1366b2 1 /*
vcoubard 28:041dac1366b2 2 * Copyright (c) Nordic Semiconductor ASA
vcoubard 28:041dac1366b2 3 * All rights reserved.
vcoubard 28:041dac1366b2 4 *
vcoubard 28:041dac1366b2 5 * Redistribution and use in source and binary forms, with or without modification,
vcoubard 28:041dac1366b2 6 * are permitted provided that the following conditions are met:
vcoubard 28:041dac1366b2 7 *
vcoubard 28:041dac1366b2 8 * 1. Redistributions of source code must retain the above copyright notice, this
vcoubard 28:041dac1366b2 9 * list of conditions and the following disclaimer.
vcoubard 28:041dac1366b2 10 *
vcoubard 28:041dac1366b2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
vcoubard 28:041dac1366b2 12 * list of conditions and the following disclaimer in the documentation and/or
vcoubard 28:041dac1366b2 13 * other materials provided with the distribution.
vcoubard 28:041dac1366b2 14 *
vcoubard 28:041dac1366b2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
vcoubard 28:041dac1366b2 16 * contributors to this software may be used to endorse or promote products
vcoubard 28:041dac1366b2 17 * derived from this software without specific prior written permission.
vcoubard 28:041dac1366b2 18 *
vcoubard 28:041dac1366b2 19 * 4. This software must only be used in a processor manufactured by Nordic
vcoubard 28:041dac1366b2 20 * Semiconductor ASA, or in a processor manufactured by a third party that
vcoubard 28:041dac1366b2 21 * is used in combination with a processor manufactured by Nordic Semiconductor.
vcoubard 28:041dac1366b2 22 *
vcoubard 28:041dac1366b2 23 *
vcoubard 28:041dac1366b2 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
vcoubard 28:041dac1366b2 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
vcoubard 28:041dac1366b2 26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vcoubard 28:041dac1366b2 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
vcoubard 28:041dac1366b2 28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
vcoubard 28:041dac1366b2 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
vcoubard 28:041dac1366b2 30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
vcoubard 28:041dac1366b2 31 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
vcoubard 28:041dac1366b2 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
vcoubard 28:041dac1366b2 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vcoubard 28:041dac1366b2 34 *
vcoubard 1:ebc0e0ef0a11 35 */
vcoubard 1:ebc0e0ef0a11 36 /**
vcoubard 1:ebc0e0ef0a11 37 @defgroup nrf_sdm_api SoftDevice Manager API
vcoubard 1:ebc0e0ef0a11 38 @{
vcoubard 1:ebc0e0ef0a11 39
vcoubard 1:ebc0e0ef0a11 40 @brief APIs for SoftDevice management.
vcoubard 1:ebc0e0ef0a11 41
vcoubard 1:ebc0e0ef0a11 42 */
vcoubard 1:ebc0e0ef0a11 43
vcoubard 1:ebc0e0ef0a11 44 /* Header guard */
vcoubard 1:ebc0e0ef0a11 45 #ifndef NRF_SDM_H__
vcoubard 1:ebc0e0ef0a11 46 #define NRF_SDM_H__
vcoubard 1:ebc0e0ef0a11 47
vcoubard 1:ebc0e0ef0a11 48 #include "nrf_svc.h"
vcoubard 28:041dac1366b2 49 #include "nrf.h"
vcoubard 1:ebc0e0ef0a11 50 #include "nrf_soc.h"
vcoubard 1:ebc0e0ef0a11 51 #include "nrf_error_sdm.h"
vcoubard 1:ebc0e0ef0a11 52
vcoubard 1:ebc0e0ef0a11 53 /** @addtogroup NRF_SDM_DEFINES Defines
vcoubard 1:ebc0e0ef0a11 54 * @{ */
vcoubard 1:ebc0e0ef0a11 55
vcoubard 1:ebc0e0ef0a11 56 /** @brief SoftDevice Manager SVC Base number. */
vcoubard 1:ebc0e0ef0a11 57 #define SDM_SVC_BASE 0x10
vcoubard 1:ebc0e0ef0a11 58
vcoubard 1:ebc0e0ef0a11 59 /** @} */
vcoubard 1:ebc0e0ef0a11 60
vcoubard 1:ebc0e0ef0a11 61 /** @brief Defines the SoftDevice Information Structure location (address) as an offset from
vcoubard 1:ebc0e0ef0a11 62 the start of the softdevice (without MBR)*/
vcoubard 1:ebc0e0ef0a11 63 #define SOFTDEVICE_INFO_STRUCT_OFFSET (0x2000)
vcoubard 1:ebc0e0ef0a11 64
vcoubard 1:ebc0e0ef0a11 65 /** @brief Defines the usual size reserverd for the MBR when a softdevice is written to flash.
vcoubard 1:ebc0e0ef0a11 66 This is the offset where the first byte of the softdevice hex file is written.*/
vcoubard 1:ebc0e0ef0a11 67 #define MBR_SIZE (0x1000)
vcoubard 1:ebc0e0ef0a11 68
vcoubard 1:ebc0e0ef0a11 69 /** @brief Defines the absolute Softdevice information structure location (address)*/
vcoubard 1:ebc0e0ef0a11 70 #define SOFTDEVICE_INFO_STRUCT_ADDRESS (SOFTDEVICE_INFO_STRUCT_OFFSET + MBR_SIZE)
vcoubard 1:ebc0e0ef0a11 71
vcoubard 1:ebc0e0ef0a11 72 /** @brief Defines the offset for Softdevice size value relative to Softdevice base address*/
vcoubard 1:ebc0e0ef0a11 73 #define SD_SIZE_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x08)
vcoubard 1:ebc0e0ef0a11 74
vcoubard 1:ebc0e0ef0a11 75 /** @brief Defines the offset for FWID value relative to Softdevice base address*/
vcoubard 1:ebc0e0ef0a11 76 #define SD_FWID_OFFSET (SOFTDEVICE_INFO_STRUCT_OFFSET + 0x0C)
vcoubard 1:ebc0e0ef0a11 77
vcoubard 1:ebc0e0ef0a11 78 /** @brief Defines a macro for retreiving the actual Softdevice size value from a given base address
vcoubard 1:ebc0e0ef0a11 79 use @ref MBR_SIZE when Softdevice is installed just above the MBR (the usual case)*/
vcoubard 1:ebc0e0ef0a11 80 #define SD_SIZE_GET(baseaddr) (*((uint32_t *) ((baseaddr) + SD_SIZE_OFFSET)))
vcoubard 1:ebc0e0ef0a11 81
vcoubard 1:ebc0e0ef0a11 82 /** @brief Defines a macro for retreiving the actual FWID value from a given base address
vcoubard 1:ebc0e0ef0a11 83 use @ref MBR_SIZE when Softdevice is installed just above the MBR (the usual case)*/
vcoubard 1:ebc0e0ef0a11 84 #define SD_FWID_GET(baseaddr) ((*((uint32_t *) ((baseaddr) + SD_FWID_OFFSET))) & 0xFFFF)
vcoubard 1:ebc0e0ef0a11 85
vcoubard 1:ebc0e0ef0a11 86
vcoubard 1:ebc0e0ef0a11 87 /** @addtogroup NRF_SDM_ENUMS Enumerations
vcoubard 1:ebc0e0ef0a11 88 * @{ */
vcoubard 1:ebc0e0ef0a11 89
vcoubard 1:ebc0e0ef0a11 90 /**@brief nRF SoftDevice Manager API SVC numbers. */
vcoubard 1:ebc0e0ef0a11 91 enum NRF_SD_SVCS
vcoubard 1:ebc0e0ef0a11 92 {
vcoubard 1:ebc0e0ef0a11 93 SD_SOFTDEVICE_ENABLE = SDM_SVC_BASE, /**< ::sd_softdevice_enable */
vcoubard 1:ebc0e0ef0a11 94 SD_SOFTDEVICE_DISABLE, /**< ::sd_softdevice_disable */
vcoubard 1:ebc0e0ef0a11 95 SD_SOFTDEVICE_IS_ENABLED, /**< ::sd_softdevice_is_enabled */
vcoubard 1:ebc0e0ef0a11 96 SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, /**< ::sd_softdevice_vector_table_base_set */
vcoubard 1:ebc0e0ef0a11 97 SVC_SDM_LAST /**< Placeholder for last SDM SVC */
vcoubard 1:ebc0e0ef0a11 98 };
vcoubard 1:ebc0e0ef0a11 99
vcoubard 1:ebc0e0ef0a11 100 /**@brief Possible lfclk oscillator sources. */
vcoubard 1:ebc0e0ef0a11 101 enum NRF_CLOCK_LFCLKSRCS
vcoubard 1:ebc0e0ef0a11 102 {
vcoubard 1:ebc0e0ef0a11 103 NRF_CLOCK_LFCLKSRC_SYNTH_250_PPM, /**< LFCLK Synthesized from HFCLK. */
vcoubard 1:ebc0e0ef0a11 104 NRF_CLOCK_LFCLKSRC_XTAL_500_PPM, /**< LFCLK crystal oscillator 500 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 105 NRF_CLOCK_LFCLKSRC_XTAL_250_PPM, /**< LFCLK crystal oscillator 250 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 106 NRF_CLOCK_LFCLKSRC_XTAL_150_PPM, /**< LFCLK crystal oscillator 150 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 107 NRF_CLOCK_LFCLKSRC_XTAL_100_PPM, /**< LFCLK crystal oscillator 100 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 108 NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, /**< LFCLK crystal oscillator 75 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 109 NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, /**< LFCLK crystal oscillator 50 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 110 NRF_CLOCK_LFCLKSRC_XTAL_30_PPM, /**< LFCLK crystal oscillator 30 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 111 NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, /**< LFCLK crystal oscillator 20 PPM accuracy. */
vcoubard 1:ebc0e0ef0a11 112 NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION, /**< LFCLK RC oscillator, 250ms calibration interval.*/
vcoubard 1:ebc0e0ef0a11 113 NRF_CLOCK_LFCLKSRC_RC_250_PPM_500MS_CALIBRATION, /**< LFCLK RC oscillator, 500ms calibration interval.*/
vcoubard 1:ebc0e0ef0a11 114 NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION, /**< LFCLK RC oscillator, 1000ms calibration interval.*/
vcoubard 1:ebc0e0ef0a11 115 NRF_CLOCK_LFCLKSRC_RC_250_PPM_2000MS_CALIBRATION, /**< LFCLK RC oscillator, 2000ms calibration interval.*/
vcoubard 1:ebc0e0ef0a11 116 NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, /**< LFCLK RC oscillator, 4000ms calibration interval.*/
vcoubard 1:ebc0e0ef0a11 117 NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION, /**< LFCLK RC oscillator, 8000ms calibration interval.*/
vcoubard 1:ebc0e0ef0a11 118 NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_1000MS_CALIBRATION, /**< LFCLK RC oscillator. Temperature checked every 1000ms, if changed above a threshold, a calibration is done.*/
vcoubard 1:ebc0e0ef0a11 119 NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_2000MS_CALIBRATION, /**< LFCLK RC oscillator. Temperature checked every 2000ms, if changed above a threshold, a calibration is done.*/
vcoubard 1:ebc0e0ef0a11 120 NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_4000MS_CALIBRATION, /**< LFCLK RC oscillator. Temperature checked every 4000ms, if changed above a threshold, a calibration is done.*/
vcoubard 1:ebc0e0ef0a11 121 NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_8000MS_CALIBRATION, /**< LFCLK RC oscillator. Temperature checked every 8000ms, if changed above a threshold, a calibration is done.*/
vcoubard 1:ebc0e0ef0a11 122 NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_16000MS_CALIBRATION, /**< LFCLK RC oscillator. Temperature checked every 16000ms, if changed above a threshold, a calibration is done.*/
vcoubard 1:ebc0e0ef0a11 123 };
vcoubard 1:ebc0e0ef0a11 124
vcoubard 1:ebc0e0ef0a11 125 /** @} */
vcoubard 1:ebc0e0ef0a11 126
vcoubard 1:ebc0e0ef0a11 127 /** @addtogroup NRF_SDM_TYPES Types
vcoubard 1:ebc0e0ef0a11 128 * @{ */
vcoubard 1:ebc0e0ef0a11 129
vcoubard 1:ebc0e0ef0a11 130 /**@brief Type representing lfclk oscillator source. */
vcoubard 1:ebc0e0ef0a11 131 typedef uint32_t nrf_clock_lfclksrc_t;
vcoubard 1:ebc0e0ef0a11 132
vcoubard 1:ebc0e0ef0a11 133
vcoubard 1:ebc0e0ef0a11 134 /**@brief SoftDevice Assertion Handler type.
vcoubard 1:ebc0e0ef0a11 135 *
vcoubard 1:ebc0e0ef0a11 136 * When an unexpected error occurs within the SoftDevice it will call the SoftDevice assertion handler callback.
vcoubard 1:ebc0e0ef0a11 137 * The protocol stack will be in an undefined state when this happens and the only way to recover will be to
vcoubard 1:ebc0e0ef0a11 138 * perform a reset, using e.g. CMSIS NVIC_SystemReset().
vcoubard 1:ebc0e0ef0a11 139 *
vcoubard 1:ebc0e0ef0a11 140 * @note This callback is executed in HardFault context, thus SVC functions cannot be called from the SoftDevice assert callback.
vcoubard 1:ebc0e0ef0a11 141 *
vcoubard 1:ebc0e0ef0a11 142 * @param[in] pc The program counter of the failed assert.
vcoubard 1:ebc0e0ef0a11 143 * @param[in] line_number Line number where the assert failed.
vcoubard 1:ebc0e0ef0a11 144 * @param[in] file_name File name where the assert failed.
vcoubard 1:ebc0e0ef0a11 145 */
vcoubard 1:ebc0e0ef0a11 146 typedef void (*softdevice_assertion_handler_t)(uint32_t pc, uint16_t line_number, const uint8_t * p_file_name);
vcoubard 1:ebc0e0ef0a11 147
vcoubard 1:ebc0e0ef0a11 148 /** @} */
vcoubard 1:ebc0e0ef0a11 149
vcoubard 1:ebc0e0ef0a11 150 /** @addtogroup NRF_SDM_FUNCTIONS Functions
vcoubard 1:ebc0e0ef0a11 151 * @{ */
vcoubard 1:ebc0e0ef0a11 152
vcoubard 1:ebc0e0ef0a11 153 /**@brief Enables the SoftDevice and by extension the protocol stack.
vcoubard 1:ebc0e0ef0a11 154 *
vcoubard 1:ebc0e0ef0a11 155 * Idempotent function to enable the SoftDevice.
vcoubard 1:ebc0e0ef0a11 156 *
vcoubard 1:ebc0e0ef0a11 157 * @note Some care must be taken if a low frequency clock source is already running when calling this function:
vcoubard 1:ebc0e0ef0a11 158 * If the LF clock has a different source then the one currently running, it will be stopped. Then, the new
vcoubard 1:ebc0e0ef0a11 159 * clock source will be started.
vcoubard 1:ebc0e0ef0a11 160 *
vcoubard 1:ebc0e0ef0a11 161 * @note This function has no effect when returning with an error.
vcoubard 1:ebc0e0ef0a11 162 *
vcoubard 1:ebc0e0ef0a11 163 * @post If return code is ::NRF_SUCCESS
vcoubard 1:ebc0e0ef0a11 164 * - SoC library and protocol stack APIs are made available.
vcoubard 1:ebc0e0ef0a11 165 * - A portion of RAM will be unavailable (see relevant SDS documentation).
vcoubard 1:ebc0e0ef0a11 166 * - Some peripherals will be unavailable or available only through the SoC API (see relevant SDS documentation).
vcoubard 1:ebc0e0ef0a11 167 * - Interrupts will not arrive from protected peripherals or interrupts.
vcoubard 1:ebc0e0ef0a11 168 * - nrf_nvic_ functions must be used instead of CMSIS NVIC_ functions for reliable usage of the softdevice.
vcoubard 1:ebc0e0ef0a11 169 * - Interrupt latency may be affected by the SoftDevice (see relevant SDS documentation).
vcoubard 1:ebc0e0ef0a11 170 * - Chosen low frequency clock source will be running.
vcoubard 1:ebc0e0ef0a11 171 *
vcoubard 1:ebc0e0ef0a11 172 * @param clock_source Low frequency clock source and accuracy. (Note: In the case of XTAL source, the PPM accuracy of the chosen clock source must be greater than or equal to the actual characteristics of your XTAL clock).
vcoubard 1:ebc0e0ef0a11 173 * @param assertion_handler Callback for SoftDevice assertions.
vcoubard 1:ebc0e0ef0a11 174 *
vcoubard 1:ebc0e0ef0a11 175 * @retval ::NRF_SUCCESS
vcoubard 1:ebc0e0ef0a11 176 * @retval ::NRF_ERROR_INVALID_STATE SoftDevice is already enabled, and the clock source and assertion handler cannot be updated.
vcoubard 1:ebc0e0ef0a11 177 * @retval ::NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION SoftDeviceinterrupt is already enabled, or an enabled interrupt has an illegal priority level.
vcoubard 1:ebc0e0ef0a11 178 * @retval ::NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN Unknown low frequency clock source selected.
vcoubard 1:ebc0e0ef0a11 179 */
vcoubard 1:ebc0e0ef0a11 180 SVCALL(SD_SOFTDEVICE_ENABLE, uint32_t, sd_softdevice_enable(nrf_clock_lfclksrc_t clock_source, softdevice_assertion_handler_t assertion_handler));
vcoubard 1:ebc0e0ef0a11 181
vcoubard 1:ebc0e0ef0a11 182 /**@brief Disables the SoftDevice and by extension the protocol stack.
vcoubard 1:ebc0e0ef0a11 183 *
vcoubard 1:ebc0e0ef0a11 184 * Idempotent function to disable the SoftDevice.
vcoubard 1:ebc0e0ef0a11 185 *
vcoubard 1:ebc0e0ef0a11 186 * @post SoC library and protocol stack APIs are made unavailable.
vcoubard 1:ebc0e0ef0a11 187 * @post All interrupts that was protected by the SoftDevice will be disabled and initialized to priority 0 (highest).
vcoubard 1:ebc0e0ef0a11 188 * @post All peripherals used by the SoftDevice will be reset to default values.
vcoubard 1:ebc0e0ef0a11 189 * @post All of RAM become available.
vcoubard 1:ebc0e0ef0a11 190 * @post All interrupts are forwarded to the application.
vcoubard 1:ebc0e0ef0a11 191 * @post LFCLK source chosen in ::sd_softdevice_enable will be left running.
vcoubard 1:ebc0e0ef0a11 192 *
vcoubard 1:ebc0e0ef0a11 193 * @retval ::NRF_SUCCESS
vcoubard 1:ebc0e0ef0a11 194 */
vcoubard 1:ebc0e0ef0a11 195 SVCALL(SD_SOFTDEVICE_DISABLE, uint32_t, sd_softdevice_disable(void));
vcoubard 1:ebc0e0ef0a11 196
vcoubard 1:ebc0e0ef0a11 197 /**@brief Check if the SoftDevice is enabled.
vcoubard 1:ebc0e0ef0a11 198 *
vcoubard 1:ebc0e0ef0a11 199 * @param[out] p_softdevice_enabled If the SoftDevice is enabled: 1 else 0.
vcoubard 1:ebc0e0ef0a11 200 *
vcoubard 1:ebc0e0ef0a11 201 * @retval ::NRF_SUCCESS
vcoubard 1:ebc0e0ef0a11 202 */
vcoubard 1:ebc0e0ef0a11 203 SVCALL(SD_SOFTDEVICE_IS_ENABLED, uint32_t, sd_softdevice_is_enabled(uint8_t * p_softdevice_enabled));
vcoubard 1:ebc0e0ef0a11 204
vcoubard 1:ebc0e0ef0a11 205 /**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the SoftDevice
vcoubard 1:ebc0e0ef0a11 206 *
vcoubard 1:ebc0e0ef0a11 207 * This function is only intended to be called when a bootloader is enabled.
vcoubard 1:ebc0e0ef0a11 208 *
vcoubard 1:ebc0e0ef0a11 209 * @param[in] address The base address of the interrupt vector table for forwarded interrupts.
vcoubard 1:ebc0e0ef0a11 210
vcoubard 1:ebc0e0ef0a11 211 * @retval ::NRF_SUCCESS
vcoubard 1:ebc0e0ef0a11 212 */
vcoubard 1:ebc0e0ef0a11 213 SVCALL(SD_SOFTDEVICE_VECTOR_TABLE_BASE_SET, uint32_t, sd_softdevice_vector_table_base_set(uint32_t address));
vcoubard 1:ebc0e0ef0a11 214
vcoubard 1:ebc0e0ef0a11 215 /** @} */
vcoubard 1:ebc0e0ef0a11 216
vcoubard 1:ebc0e0ef0a11 217 #endif // NRF_SDM_H__
vcoubard 1:ebc0e0ef0a11 218
vcoubard 1:ebc0e0ef0a11 219 /**
vcoubard 1:ebc0e0ef0a11 220 @}
vcoubard 1:ebc0e0ef0a11 221 */