The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015 Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 3 * All rights reserved.
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 143:86740a56073b 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 143:86740a56073b 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 143:86740a56073b 15 *
AnnaBridge 143:86740a56073b 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 143:86740a56073b 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 143:86740a56073b 18 * written permission.
AnnaBridge 143:86740a56073b 19 *
AnnaBridge 143:86740a56073b 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 143:86740a56073b 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 143:86740a56073b 22 *
AnnaBridge 143:86740a56073b 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 143:86740a56073b 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 143:86740a56073b 25 *
AnnaBridge 143:86740a56073b 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 36 *
AnnaBridge 143:86740a56073b 37 */
AnnaBridge 143:86740a56073b 38
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40 #ifndef NRF_DRV_CLOCK_H__
AnnaBridge 143:86740a56073b 41 #define NRF_DRV_CLOCK_H__
AnnaBridge 143:86740a56073b 42
AnnaBridge 143:86740a56073b 43 #include <stdbool.h>
AnnaBridge 143:86740a56073b 44 #include <stdint.h>
AnnaBridge 143:86740a56073b 45 #include "sdk_errors.h"
AnnaBridge 143:86740a56073b 46 #include "nrf_assert.h"
AnnaBridge 143:86740a56073b 47 #include "nrf_clock.h"
AnnaBridge 143:86740a56073b 48 #include "nrf_drv_config.h"
AnnaBridge 143:86740a56073b 49 #include "nrf_drv_common.h"
AnnaBridge 143:86740a56073b 50
AnnaBridge 143:86740a56073b 51 /**
AnnaBridge 143:86740a56073b 52 *
AnnaBridge 143:86740a56073b 53 * @addtogroup nrf_clock Clock HAL and driver
AnnaBridge 143:86740a56073b 54 * @ingroup nrf_drivers
AnnaBridge 143:86740a56073b 55 * @brief Clock APIs.
AnnaBridge 143:86740a56073b 56 * @details The clock HAL provides basic APIs for accessing the registers of the clock.
AnnaBridge 143:86740a56073b 57 * The clock driver provides APIs on a higher level.
AnnaBridge 143:86740a56073b 58 *
AnnaBridge 143:86740a56073b 59 * @defgroup nrf_clock_drv Clock driver
AnnaBridge 143:86740a56073b 60 * @{
AnnaBridge 143:86740a56073b 61 * @ingroup nrf_clock
AnnaBridge 143:86740a56073b 62 * @brief Driver for managing the low-frequency clock (LFCLK) and the high-frequency clock (HFCLK).
AnnaBridge 143:86740a56073b 63 */
AnnaBridge 143:86740a56073b 64
AnnaBridge 143:86740a56073b 65 /**
AnnaBridge 143:86740a56073b 66 * @brief Clock events.
AnnaBridge 143:86740a56073b 67 */
AnnaBridge 143:86740a56073b 68 typedef enum
AnnaBridge 143:86740a56073b 69 {
AnnaBridge 143:86740a56073b 70 NRF_DRV_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
AnnaBridge 143:86740a56073b 71 NRF_DRV_CLOCK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
AnnaBridge 143:86740a56073b 72 NRF_DRV_CLOCK_EVT_CAL_DONE, ///< Calibration is done.
AnnaBridge 143:86740a56073b 73 NRF_DRV_CLOCK_EVT_CAL_ABORTED, ///< Calibration has been aborted.
AnnaBridge 143:86740a56073b 74 } nrf_drv_clock_evt_type_t;
AnnaBridge 143:86740a56073b 75
AnnaBridge 143:86740a56073b 76 /**
AnnaBridge 143:86740a56073b 77 * @brief Clock event handler.
AnnaBridge 143:86740a56073b 78 *
AnnaBridge 143:86740a56073b 79 * @param[in] event Event.
AnnaBridge 143:86740a56073b 80 */
AnnaBridge 143:86740a56073b 81 typedef void (*nrf_drv_clock_event_handler_t)(nrf_drv_clock_evt_type_t event);
AnnaBridge 143:86740a56073b 82
AnnaBridge 143:86740a56073b 83 // Forward declaration of the nrf_drv_clock_handler_item_t type.
AnnaBridge 143:86740a56073b 84 typedef struct nrf_drv_clock_handler_item_s nrf_drv_clock_handler_item_t;
AnnaBridge 143:86740a56073b 85
AnnaBridge 143:86740a56073b 86 struct nrf_drv_clock_handler_item_s
AnnaBridge 143:86740a56073b 87 {
AnnaBridge 143:86740a56073b 88 nrf_drv_clock_handler_item_t * p_next; ///< A pointer to the next handler that should be called when the clock is started.
AnnaBridge 143:86740a56073b 89 nrf_drv_clock_event_handler_t event_handler; ///< Function to be called when the clock is started.
AnnaBridge 143:86740a56073b 90 };
AnnaBridge 143:86740a56073b 91
AnnaBridge 143:86740a56073b 92 /**
AnnaBridge 143:86740a56073b 93 * @brief Function for initializing the nrf_drv_clock module.
AnnaBridge 143:86740a56073b 94 *
AnnaBridge 143:86740a56073b 95 * After initialization, the module is in power off state (clocks are not requested).
AnnaBridge 143:86740a56073b 96 *
AnnaBridge 143:86740a56073b 97 * @retval NRF_SUCCESS If the procedure was successful.
AnnaBridge 143:86740a56073b 98 * @retval MODULE_ALREADY_INITIALIZED If the driver was already initialized.
AnnaBridge 143:86740a56073b 99 * @retval NRF_ERROR_SOFTDEVICE_NOT_ENABLED If the SoftDevice was not enabled.
AnnaBridge 143:86740a56073b 100 */
AnnaBridge 143:86740a56073b 101 ret_code_t nrf_drv_clock_init(void);
AnnaBridge 143:86740a56073b 102
AnnaBridge 143:86740a56073b 103 /**
AnnaBridge 143:86740a56073b 104 * @brief Function for uninitializing the clock module.
AnnaBridge 143:86740a56073b 105 *
AnnaBridge 143:86740a56073b 106 */
AnnaBridge 143:86740a56073b 107 void nrf_drv_clock_uninit(void);
AnnaBridge 143:86740a56073b 108
AnnaBridge 143:86740a56073b 109 /**
AnnaBridge 143:86740a56073b 110 * @brief Function for requesting the LFCLK.
AnnaBridge 143:86740a56073b 111 *
AnnaBridge 143:86740a56073b 112 * The low-frequency clock can be requested by different modules
AnnaBridge 143:86740a56073b 113 * or contexts. The driver ensures that the clock will be started only when it is requested
AnnaBridge 143:86740a56073b 114 * the first time. If the clock is not ready but it was already started, the handler item that is
AnnaBridge 143:86740a56073b 115 * provided as an input parameter is added to the list of handlers that will be notified
AnnaBridge 143:86740a56073b 116 * when the clock is started. If the clock is already enabled, user callback is called from the
AnnaBridge 143:86740a56073b 117 * current context.
AnnaBridge 143:86740a56073b 118 *
AnnaBridge 143:86740a56073b 119 * The first request will start the selected LFCLK source. If an event handler is
AnnaBridge 143:86740a56073b 120 * provided, it will be called once the LFCLK is started. If the LFCLK was already started at this
AnnaBridge 143:86740a56073b 121 * time, the event handler will be called from the context of this function. Additionally,
AnnaBridge 143:86740a56073b 122 * the @ref nrf_drv_clock_lfclk_is_running function can be polled to check if the clock has started.
AnnaBridge 143:86740a56073b 123 *
AnnaBridge 143:86740a56073b 124 * @note When a SoftDevice is enabled, the LFCLK is always running and the driver cannot control it.
AnnaBridge 143:86740a56073b 125 *
AnnaBridge 143:86740a56073b 126 * @note The handler item provided by the user cannot be an automatic variable.
AnnaBridge 143:86740a56073b 127 *
AnnaBridge 143:86740a56073b 128 * @param[in] p_handler_item A pointer to the event handler structure.
AnnaBridge 143:86740a56073b 129 */
AnnaBridge 143:86740a56073b 130 void nrf_drv_clock_lfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
AnnaBridge 143:86740a56073b 131
AnnaBridge 143:86740a56073b 132 /**
AnnaBridge 143:86740a56073b 133 * @brief Function for releasing the LFCLK.
AnnaBridge 143:86740a56073b 134 *
AnnaBridge 143:86740a56073b 135 * If there are no more requests, the LFCLK source will be stopped.
AnnaBridge 143:86740a56073b 136 *
AnnaBridge 143:86740a56073b 137 * @note When a SoftDevice is enabled, the LFCLK is always running.
AnnaBridge 143:86740a56073b 138 */
AnnaBridge 143:86740a56073b 139 void nrf_drv_clock_lfclk_release(void);
AnnaBridge 143:86740a56073b 140
AnnaBridge 143:86740a56073b 141 /**
AnnaBridge 143:86740a56073b 142 * @brief Function for checking the LFCLK state.
AnnaBridge 143:86740a56073b 143 *
AnnaBridge 143:86740a56073b 144 * @retval true If the LFCLK is running.
AnnaBridge 143:86740a56073b 145 * @retval false If the LFCLK is not running.
AnnaBridge 143:86740a56073b 146 */
AnnaBridge 143:86740a56073b 147 bool nrf_drv_clock_lfclk_is_running(void);
AnnaBridge 143:86740a56073b 148
AnnaBridge 143:86740a56073b 149 /**
AnnaBridge 143:86740a56073b 150 * @brief Function for requesting the high-accuracy source HFCLK.
AnnaBridge 143:86740a56073b 151 *
AnnaBridge 143:86740a56073b 152 * The high-accuracy source
AnnaBridge 143:86740a56073b 153 * can be requested by different modules or contexts. The driver ensures that the high-accuracy
AnnaBridge 143:86740a56073b 154 * clock will be started only when it is requested the first time. If the clock is not ready
AnnaBridge 143:86740a56073b 155 * but it was already started, the handler item that is provided as an input parameter is added
AnnaBridge 143:86740a56073b 156 * to the list of handlers that will be notified when the clock is started.
AnnaBridge 143:86740a56073b 157 *
AnnaBridge 143:86740a56073b 158 * If an event handler is provided, it will be called once the clock is started. If the clock was already
AnnaBridge 143:86740a56073b 159 * started at this time, the event handler will be called from the context of this function. Additionally,
AnnaBridge 143:86740a56073b 160 * the @ref nrf_drv_clock_hfclk_is_running function can be polled to check if the clock has started.
AnnaBridge 143:86740a56073b 161 *
AnnaBridge 143:86740a56073b 162 * @note If a SoftDevice is running, the clock is managed by the SoftDevice and all requests are handled by
AnnaBridge 143:86740a56073b 163 * the SoftDevice. This function cannot be called from all interrupt priority levels in that case.
AnnaBridge 143:86740a56073b 164 * @note The handler item provided by the user cannot be an automatic variable.
AnnaBridge 143:86740a56073b 165 *
AnnaBridge 143:86740a56073b 166 * @param[in] p_handler_item A pointer to the event handler structure.
AnnaBridge 143:86740a56073b 167 */
AnnaBridge 143:86740a56073b 168 void nrf_drv_clock_hfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
AnnaBridge 143:86740a56073b 169
AnnaBridge 143:86740a56073b 170 /**
AnnaBridge 143:86740a56073b 171 * @brief Function for releasing the high-accuracy source HFCLK.
AnnaBridge 143:86740a56073b 172 *
AnnaBridge 143:86740a56073b 173 * If there are no more requests, the high-accuracy source will be released.
AnnaBridge 143:86740a56073b 174 */
AnnaBridge 143:86740a56073b 175 void nrf_drv_clock_hfclk_release(void);
AnnaBridge 143:86740a56073b 176
AnnaBridge 143:86740a56073b 177 /**
AnnaBridge 143:86740a56073b 178 * @brief Function for checking the HFCLK state.
AnnaBridge 143:86740a56073b 179 *
AnnaBridge 143:86740a56073b 180 * @retval true If the HFCLK is running (for \nRFXX XTAL source).
AnnaBridge 143:86740a56073b 181 * @retval false If the HFCLK is not running.
AnnaBridge 143:86740a56073b 182 */
AnnaBridge 143:86740a56073b 183 bool nrf_drv_clock_hfclk_is_running(void);
AnnaBridge 143:86740a56073b 184
AnnaBridge 143:86740a56073b 185 /**
AnnaBridge 143:86740a56073b 186 * @brief Function for starting a single calibration process.
AnnaBridge 143:86740a56073b 187 *
AnnaBridge 143:86740a56073b 188 * This function can also delay the start of calibration by a user-specified value. The delay will use
AnnaBridge 143:86740a56073b 189 * a low-power timer that is part of the CLOCK module. @ref nrf_drv_clock_is_calibrating can be called to
AnnaBridge 143:86740a56073b 190 * check if calibration is still in progress. If a handler is provided, the user can be notified when
AnnaBridge 143:86740a56073b 191 * calibration is completed. The ext calibration can be started from the handler context.
AnnaBridge 143:86740a56073b 192 *
AnnaBridge 143:86740a56073b 193 * The calibration process consists of three phases:
AnnaBridge 143:86740a56073b 194 * - Delay (optional)
AnnaBridge 143:86740a56073b 195 * - Requesting the high-accuracy HFCLK
AnnaBridge 143:86740a56073b 196 * - Hardware-supported calibration
AnnaBridge 143:86740a56073b 197 *
AnnaBridge 143:86740a56073b 198 * @param[in] delay Time after which the calibration will be started (in 0.25 s units).
AnnaBridge 143:86740a56073b 199 * @param[in] handler NULL or user function to be called when calibration is completed or aborted.
AnnaBridge 143:86740a56073b 200 *
AnnaBridge 143:86740a56073b 201 * @retval NRF_SUCCESS If the procedure was successful.
AnnaBridge 143:86740a56073b 202 * @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
AnnaBridge 143:86740a56073b 203 * @retval NRF_ERROR_INVALID_STATE If the low-frequency clock is off.
AnnaBridge 143:86740a56073b 204 * @retval NRF_ERROR_BUSY If calibration is in progress.
AnnaBridge 143:86740a56073b 205 */
AnnaBridge 143:86740a56073b 206 ret_code_t nrf_drv_clock_calibration_start(uint8_t delay, nrf_drv_clock_event_handler_t handler);
AnnaBridge 143:86740a56073b 207
AnnaBridge 143:86740a56073b 208 /**
AnnaBridge 143:86740a56073b 209 * @brief Function for aborting calibration.
AnnaBridge 143:86740a56073b 210 *
AnnaBridge 143:86740a56073b 211 * This function aborts on-going calibration. If calibration was started, it cannot be stopped. If a handler
AnnaBridge 143:86740a56073b 212 * was provided by @ref nrf_drv_clock_calibration_start, this handler will be called once
AnnaBridge 143:86740a56073b 213 * aborted calibration is completed. @ref nrf_drv_clock_is_calibrating can also be used to check
AnnaBridge 143:86740a56073b 214 * if the system is calibrating.
AnnaBridge 143:86740a56073b 215 *
AnnaBridge 143:86740a56073b 216 * @retval NRF_SUCCESS If the procedure was successful.
AnnaBridge 143:86740a56073b 217 * @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
AnnaBridge 143:86740a56073b 218 */
AnnaBridge 143:86740a56073b 219 ret_code_t nrf_drv_clock_calibration_abort(void);
AnnaBridge 143:86740a56073b 220
AnnaBridge 143:86740a56073b 221 /**
AnnaBridge 143:86740a56073b 222 * @brief Function for checking if calibration is in progress.
AnnaBridge 143:86740a56073b 223 *
AnnaBridge 143:86740a56073b 224 * This function indicates that the system is
AnnaBridge 143:86740a56073b 225 * in calibration if it is in any of the calibration process phases (see @ref nrf_drv_clock_calibration_start).
AnnaBridge 143:86740a56073b 226 *
AnnaBridge 143:86740a56073b 227 * @param[out] p_is_calibrating True if calibration is in progress, false if not.
AnnaBridge 143:86740a56073b 228 *
AnnaBridge 143:86740a56073b 229 * @retval NRF_SUCCESS If the procedure was successful.
AnnaBridge 143:86740a56073b 230 * @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
AnnaBridge 143:86740a56073b 231 */
AnnaBridge 143:86740a56073b 232 ret_code_t nrf_drv_clock_is_calibrating(bool * p_is_calibrating);
AnnaBridge 143:86740a56073b 233
AnnaBridge 143:86740a56073b 234 /**@brief Function for returning a requested task address for the clock driver module.
AnnaBridge 143:86740a56073b 235 *
AnnaBridge 143:86740a56073b 236 * @param[in] task One of the peripheral tasks.
AnnaBridge 143:86740a56073b 237 *
AnnaBridge 143:86740a56073b 238 * @return Task address.
AnnaBridge 143:86740a56073b 239 */
AnnaBridge 143:86740a56073b 240 __STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task);
AnnaBridge 143:86740a56073b 241
AnnaBridge 143:86740a56073b 242 /**@brief Function for returning a requested event address for the clock driver module.
AnnaBridge 143:86740a56073b 243 *
AnnaBridge 143:86740a56073b 244 * @param[in] event One of the peripheral events.
AnnaBridge 143:86740a56073b 245 *
AnnaBridge 143:86740a56073b 246 * @return Event address.
AnnaBridge 143:86740a56073b 247 */
AnnaBridge 143:86740a56073b 248 __STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event);
AnnaBridge 143:86740a56073b 249
AnnaBridge 143:86740a56073b 250 /**
AnnaBridge 143:86740a56073b 251 * @brief Function called by the SoftDevice handler if an @ref nrf_soc event is received from the SoftDevice.
AnnaBridge 143:86740a56073b 252 */
AnnaBridge 143:86740a56073b 253 #ifdef SOFTDEVICE_PRESENT
AnnaBridge 143:86740a56073b 254 void nrf_drv_clock_on_soc_event(uint32_t evt_id);
AnnaBridge 143:86740a56073b 255 #endif
AnnaBridge 143:86740a56073b 256 /**
AnnaBridge 143:86740a56073b 257 *@}
AnnaBridge 143:86740a56073b 258 **/
AnnaBridge 143:86740a56073b 259
AnnaBridge 143:86740a56073b 260 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 261 __STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task)
AnnaBridge 143:86740a56073b 262 {
AnnaBridge 143:86740a56073b 263 return nrf_clock_task_address_get(task);
AnnaBridge 143:86740a56073b 264 }
AnnaBridge 143:86740a56073b 265
AnnaBridge 143:86740a56073b 266 __STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event)
AnnaBridge 143:86740a56073b 267 {
AnnaBridge 143:86740a56073b 268 return nrf_clock_event_address_get(event);
AnnaBridge 143:86740a56073b 269 }
AnnaBridge 143:86740a56073b 270 #endif //SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 271
AnnaBridge 143:86740a56073b 272 /*lint --flb "Leave library region" */
AnnaBridge 143:86740a56073b 273 #endif // NRF_CLOCK_H__