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