mbed library
Fork of mbed by
TARGET_NRF51822/nrf_sdm.h@80:8e73be2a2ac1, 2014-02-21 (annotated)
- Committer:
- emilmont
- Date:
- Fri Feb 21 12:21:39 2014 +0000
- Revision:
- 80:8e73be2a2ac1
First alpha release for the NRF51822 target (to be tested in the online IDE)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 80:8e73be2a2ac1 | 1 | /* |
emilmont | 80:8e73be2a2ac1 | 2 | * Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved. |
emilmont | 80:8e73be2a2ac1 | 3 | * |
emilmont | 80:8e73be2a2ac1 | 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, |
emilmont | 80:8e73be2a2ac1 | 5 | * copying, transfer or disclosure of such information is prohibited except by express written |
emilmont | 80:8e73be2a2ac1 | 6 | * agreement with Nordic Semiconductor. |
emilmont | 80:8e73be2a2ac1 | 7 | * |
emilmont | 80:8e73be2a2ac1 | 8 | */ |
emilmont | 80:8e73be2a2ac1 | 9 | /** |
emilmont | 80:8e73be2a2ac1 | 10 | @defgroup nrf_sdm_api SoftDevice Manager API |
emilmont | 80:8e73be2a2ac1 | 11 | @{ |
emilmont | 80:8e73be2a2ac1 | 12 | |
emilmont | 80:8e73be2a2ac1 | 13 | @brief APIs for SoftDevice management. |
emilmont | 80:8e73be2a2ac1 | 14 | |
emilmont | 80:8e73be2a2ac1 | 15 | */ |
emilmont | 80:8e73be2a2ac1 | 16 | |
emilmont | 80:8e73be2a2ac1 | 17 | /* Header guard */ |
emilmont | 80:8e73be2a2ac1 | 18 | #ifndef NRF_SDM_H__ |
emilmont | 80:8e73be2a2ac1 | 19 | #define NRF_SDM_H__ |
emilmont | 80:8e73be2a2ac1 | 20 | |
emilmont | 80:8e73be2a2ac1 | 21 | #include "nrf_svc.h" |
emilmont | 80:8e73be2a2ac1 | 22 | #include "nrf51.h" |
emilmont | 80:8e73be2a2ac1 | 23 | #include "nrf_soc.h" |
emilmont | 80:8e73be2a2ac1 | 24 | #include "nrf_error_sdm.h" |
emilmont | 80:8e73be2a2ac1 | 25 | |
emilmont | 80:8e73be2a2ac1 | 26 | /** @addtogroup NRF_SDM_DEFINES Defines |
emilmont | 80:8e73be2a2ac1 | 27 | * @{ */ |
emilmont | 80:8e73be2a2ac1 | 28 | |
emilmont | 80:8e73be2a2ac1 | 29 | /**@brief SoftDevice Manager SVC Base number. */ |
emilmont | 80:8e73be2a2ac1 | 30 | #define SDM_SVC_BASE 0x10 |
emilmont | 80:8e73be2a2ac1 | 31 | |
emilmont | 80:8e73be2a2ac1 | 32 | /** @} */ |
emilmont | 80:8e73be2a2ac1 | 33 | |
emilmont | 80:8e73be2a2ac1 | 34 | /** @addtogroup NRF_SDM_ENUMS Enumerations |
emilmont | 80:8e73be2a2ac1 | 35 | * @{ */ |
emilmont | 80:8e73be2a2ac1 | 36 | |
emilmont | 80:8e73be2a2ac1 | 37 | /**@brief nRF SoftDevice Manager API SVC numbers. */ |
emilmont | 80:8e73be2a2ac1 | 38 | enum NRF_SD_SVCS |
emilmont | 80:8e73be2a2ac1 | 39 | { |
emilmont | 80:8e73be2a2ac1 | 40 | SD_SOFTDEVICE_ENABLE = SDM_SVC_BASE, /**< ::sd_softdevice_enable */ |
emilmont | 80:8e73be2a2ac1 | 41 | SD_SOFTDEVICE_DISABLE, /**< ::sd_softdevice_disable */ |
emilmont | 80:8e73be2a2ac1 | 42 | SD_SOFTDEVICE_IS_ENABLED, /**< ::sd_softdevice_is_enabled */ |
emilmont | 80:8e73be2a2ac1 | 43 | SD_SOFTDEVICE_FORWARD_TO_APPLICATION,/**< ::sd_softdevice_forward_to_application */ |
emilmont | 80:8e73be2a2ac1 | 44 | SVC_SDM_LAST /**< Placeholder for last SDM SVC */ |
emilmont | 80:8e73be2a2ac1 | 45 | }; |
emilmont | 80:8e73be2a2ac1 | 46 | |
emilmont | 80:8e73be2a2ac1 | 47 | /**@brief Possible lfclk oscillator sources. */ |
emilmont | 80:8e73be2a2ac1 | 48 | enum NRF_CLOCK_LFCLKSRCS |
emilmont | 80:8e73be2a2ac1 | 49 | { |
emilmont | 80:8e73be2a2ac1 | 50 | NRF_CLOCK_LFCLKSRC_SYNTH_250_PPM, /**< LFCLK Synthesized from HFCLK. */ |
emilmont | 80:8e73be2a2ac1 | 51 | NRF_CLOCK_LFCLKSRC_XTAL_500_PPM, /**< LFCLK crystal oscillator 500 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 52 | NRF_CLOCK_LFCLKSRC_XTAL_250_PPM, /**< LFCLK crystal oscillator 250 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 53 | NRF_CLOCK_LFCLKSRC_XTAL_150_PPM, /**< LFCLK crystal oscillator 150 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 54 | NRF_CLOCK_LFCLKSRC_XTAL_100_PPM, /**< LFCLK crystal oscillator 100 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 55 | NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, /**< LFCLK crystal oscillator 75 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 56 | NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, /**< LFCLK crystal oscillator 50 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 57 | NRF_CLOCK_LFCLKSRC_XTAL_30_PPM, /**< LFCLK crystal oscillator 30 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 58 | NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, /**< LFCLK crystal oscillator 20 PPM accuracy. */ |
emilmont | 80:8e73be2a2ac1 | 59 | NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION, /**< LFCLK RC oscillator, 250ms calibration interval.*/ |
emilmont | 80:8e73be2a2ac1 | 60 | NRF_CLOCK_LFCLKSRC_RC_250_PPM_500MS_CALIBRATION, /**< LFCLK RC oscillator, 500ms calibration interval.*/ |
emilmont | 80:8e73be2a2ac1 | 61 | NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION, /**< LFCLK RC oscillator, 1000ms calibration interval.*/ |
emilmont | 80:8e73be2a2ac1 | 62 | NRF_CLOCK_LFCLKSRC_RC_250_PPM_2000MS_CALIBRATION, /**< LFCLK RC oscillator, 2000ms calibration interval.*/ |
emilmont | 80:8e73be2a2ac1 | 63 | NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, /**< LFCLK RC oscillator, 4000ms calibration interval.*/ |
emilmont | 80:8e73be2a2ac1 | 64 | NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION, /**< LFCLK RC oscillator, 8000ms calibration interval.*/ |
emilmont | 80:8e73be2a2ac1 | 65 | }; |
emilmont | 80:8e73be2a2ac1 | 66 | |
emilmont | 80:8e73be2a2ac1 | 67 | /** @} */ |
emilmont | 80:8e73be2a2ac1 | 68 | |
emilmont | 80:8e73be2a2ac1 | 69 | /** @addtogroup NRF_SDM_TYPES Types |
emilmont | 80:8e73be2a2ac1 | 70 | * @{ */ |
emilmont | 80:8e73be2a2ac1 | 71 | |
emilmont | 80:8e73be2a2ac1 | 72 | /**@brief Type representing lfclk oscillator source. */ |
emilmont | 80:8e73be2a2ac1 | 73 | typedef uint32_t nrf_clock_lfclksrc_t; |
emilmont | 80:8e73be2a2ac1 | 74 | |
emilmont | 80:8e73be2a2ac1 | 75 | |
emilmont | 80:8e73be2a2ac1 | 76 | /**@brief SoftDevice Assertion Handler type. |
emilmont | 80:8e73be2a2ac1 | 77 | * |
emilmont | 80:8e73be2a2ac1 | 78 | * When an unexpected error occurs within the SoftDevice it will call the SoftDevice assertion handler callback. |
emilmont | 80:8e73be2a2ac1 | 79 | * The protocol stack will be in an undefined state when this happens and the only way to recover will be to |
emilmont | 80:8e73be2a2ac1 | 80 | * perform a reset, using e.g. CMSIS NVIC_SystemReset(). |
emilmont | 80:8e73be2a2ac1 | 81 | * |
emilmont | 80:8e73be2a2ac1 | 82 | * @note This callback is executed in HardFault context, thus SVC functions cannot be called from the SoftDevice assert callback. |
emilmont | 80:8e73be2a2ac1 | 83 | * |
emilmont | 80:8e73be2a2ac1 | 84 | * @param[in] pc The program counter of the failed assert. |
emilmont | 80:8e73be2a2ac1 | 85 | * @param[in] line_number Line number where the assert failed. |
emilmont | 80:8e73be2a2ac1 | 86 | * @param[in] file_name File name where the assert failed. |
emilmont | 80:8e73be2a2ac1 | 87 | */ |
emilmont | 80:8e73be2a2ac1 | 88 | typedef void (*softdevice_assertion_handler_t)(uint32_t pc, uint16_t line_number, const uint8_t * p_file_name); |
emilmont | 80:8e73be2a2ac1 | 89 | |
emilmont | 80:8e73be2a2ac1 | 90 | /** @} */ |
emilmont | 80:8e73be2a2ac1 | 91 | |
emilmont | 80:8e73be2a2ac1 | 92 | /** @addtogroup NRF_SDM_FUNCTIONS Functions |
emilmont | 80:8e73be2a2ac1 | 93 | * @{ */ |
emilmont | 80:8e73be2a2ac1 | 94 | |
emilmont | 80:8e73be2a2ac1 | 95 | /**@brief Enables the SoftDevice and by extension the protocol stack. |
emilmont | 80:8e73be2a2ac1 | 96 | * |
emilmont | 80:8e73be2a2ac1 | 97 | * Idempotent function to enable the SoftDevice. |
emilmont | 80:8e73be2a2ac1 | 98 | * |
emilmont | 80:8e73be2a2ac1 | 99 | * @note Some care must be taken if a low frequency clock source is already running when calling this function: |
emilmont | 80:8e73be2a2ac1 | 100 | * If the LF clock has a different source then the one currently running, it will be stopped. Then, the new |
emilmont | 80:8e73be2a2ac1 | 101 | * clock source will be started. |
emilmont | 80:8e73be2a2ac1 | 102 | * |
emilmont | 80:8e73be2a2ac1 | 103 | * @note This function has no effect when returning with an error. |
emilmont | 80:8e73be2a2ac1 | 104 | * |
emilmont | 80:8e73be2a2ac1 | 105 | * @post If return code is ::NRF_SUCCESS |
emilmont | 80:8e73be2a2ac1 | 106 | * - SoC library and protocol stack APIs are made available |
emilmont | 80:8e73be2a2ac1 | 107 | * - A portion of RAM will be unavailable (see relevant SDS documentation) |
emilmont | 80:8e73be2a2ac1 | 108 | * - Some peripherals will be unavailable or available only through the SoC API (see relevant SDS documentation) |
emilmont | 80:8e73be2a2ac1 | 109 | * - Interrupts will not arrive from protected peripherals or interrupts |
emilmont | 80:8e73be2a2ac1 | 110 | * - nrf_nvic_ functions must be used instead of CMSIS NVIC_ functions for reliable usage of the softdevice. |
emilmont | 80:8e73be2a2ac1 | 111 | * - Interrupt latency may be affected by the SoftDevice (see relevant SDS documentation) |
emilmont | 80:8e73be2a2ac1 | 112 | * - Chosen low frequency clock source will be running |
emilmont | 80:8e73be2a2ac1 | 113 | * |
emilmont | 80:8e73be2a2ac1 | 114 | * @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). |
emilmont | 80:8e73be2a2ac1 | 115 | * @param assertion_handler Callback for SoftDevice assertions. |
emilmont | 80:8e73be2a2ac1 | 116 | * |
emilmont | 80:8e73be2a2ac1 | 117 | * @retval ::NRF_SUCCESS |
emilmont | 80:8e73be2a2ac1 | 118 | * @retval ::NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION SoftDeviceinterrupt is already enabled, or an enabled interrupt has an illegal priority level |
emilmont | 80:8e73be2a2ac1 | 119 | * @retval ::NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN Unknown low frequency clock source selected |
emilmont | 80:8e73be2a2ac1 | 120 | */ |
emilmont | 80:8e73be2a2ac1 | 121 | SVCALL(SD_SOFTDEVICE_ENABLE, uint32_t, sd_softdevice_enable(nrf_clock_lfclksrc_t clock_source, softdevice_assertion_handler_t assertion_handler)); |
emilmont | 80:8e73be2a2ac1 | 122 | |
emilmont | 80:8e73be2a2ac1 | 123 | /**@brief Disables the SoftDevice and by extension the protocol stack. |
emilmont | 80:8e73be2a2ac1 | 124 | * |
emilmont | 80:8e73be2a2ac1 | 125 | * Idempotent function to disable the SoftDevice. |
emilmont | 80:8e73be2a2ac1 | 126 | * |
emilmont | 80:8e73be2a2ac1 | 127 | * @post SoC library and protocol stack APIs are made unavailable. |
emilmont | 80:8e73be2a2ac1 | 128 | * @post All interrupts that was protected by the SoftDevice will be disabled and initialized to priority 0 (highest). |
emilmont | 80:8e73be2a2ac1 | 129 | * @post All peripherals used by the SoftDevice will be reset to default values. |
emilmont | 80:8e73be2a2ac1 | 130 | * @post All of RAM become available. |
emilmont | 80:8e73be2a2ac1 | 131 | * @post All interrupts are forwarded to the application. |
emilmont | 80:8e73be2a2ac1 | 132 | * @post LFCLK source chosen in ::sd_softdevice_enable will be left running. |
emilmont | 80:8e73be2a2ac1 | 133 | * |
emilmont | 80:8e73be2a2ac1 | 134 | * @retval ::NRF_SUCCESS |
emilmont | 80:8e73be2a2ac1 | 135 | */ |
emilmont | 80:8e73be2a2ac1 | 136 | SVCALL(SD_SOFTDEVICE_DISABLE, uint32_t, sd_softdevice_disable(void)); |
emilmont | 80:8e73be2a2ac1 | 137 | |
emilmont | 80:8e73be2a2ac1 | 138 | /**@brief Check if the SoftDevice is enabled. |
emilmont | 80:8e73be2a2ac1 | 139 | * |
emilmont | 80:8e73be2a2ac1 | 140 | * @param[out] p_softdevice_enabled If the SoftDevice is enabled: 1 else 0. |
emilmont | 80:8e73be2a2ac1 | 141 | * |
emilmont | 80:8e73be2a2ac1 | 142 | * @retval ::NRF_SUCCESS |
emilmont | 80:8e73be2a2ac1 | 143 | */ |
emilmont | 80:8e73be2a2ac1 | 144 | SVCALL(SD_SOFTDEVICE_IS_ENABLED, uint32_t, sd_softdevice_is_enabled(uint8_t * p_softdevice_enabled)); |
emilmont | 80:8e73be2a2ac1 | 145 | |
emilmont | 80:8e73be2a2ac1 | 146 | /**@brief Start forwarding interrupts to application. |
emilmont | 80:8e73be2a2ac1 | 147 | * |
emilmont | 80:8e73be2a2ac1 | 148 | * This function is only intended to be called when a bootloader is enabled is used. |
emilmont | 80:8e73be2a2ac1 | 149 | * The bootloader should call this right before it starts the application. |
emilmont | 80:8e73be2a2ac1 | 150 | * It is recommended that all interrupt sources are off when this is called, |
emilmont | 80:8e73be2a2ac1 | 151 | * or you could end up having interrupts in the application being executed before main() of the application. |
emilmont | 80:8e73be2a2ac1 | 152 | * |
emilmont | 80:8e73be2a2ac1 | 153 | * @retval ::NRF_SUCCESS |
emilmont | 80:8e73be2a2ac1 | 154 | */ |
emilmont | 80:8e73be2a2ac1 | 155 | SVCALL(SD_SOFTDEVICE_FORWARD_TO_APPLICATION, uint32_t, sd_softdevice_forward_to_application(void)); |
emilmont | 80:8e73be2a2ac1 | 156 | |
emilmont | 80:8e73be2a2ac1 | 157 | /** @} */ |
emilmont | 80:8e73be2a2ac1 | 158 | |
emilmont | 80:8e73be2a2ac1 | 159 | #endif // NRF_SDM_H__ |
emilmont | 80:8e73be2a2ac1 | 160 | |
emilmont | 80:8e73be2a2ac1 | 161 | /** |
emilmont | 80:8e73be2a2ac1 | 162 | @} |
emilmont | 80:8e73be2a2ac1 | 163 | */ |