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_CLOCK_H__
AnnaBridge 143:86740a56073b 41 #define NRF_CLOCK_H__
AnnaBridge 143:86740a56073b 42
AnnaBridge 143:86740a56073b 43 #include <stddef.h>
AnnaBridge 143:86740a56073b 44 #include <stdbool.h>
AnnaBridge 143:86740a56073b 45
AnnaBridge 143:86740a56073b 46 #include "nrf.h"
AnnaBridge 143:86740a56073b 47
AnnaBridge 143:86740a56073b 48 /**
AnnaBridge 143:86740a56073b 49 * @defgroup nrf_clock_hal Clock HAL
AnnaBridge 143:86740a56073b 50 * @{
AnnaBridge 143:86740a56073b 51 * @ingroup nrf_clock
AnnaBridge 143:86740a56073b 52 * @brief Hardware access layer for managing the low-frequency clock (LFCLK) and the high-frequency clock (HFCLK).
AnnaBridge 143:86740a56073b 53 */
AnnaBridge 143:86740a56073b 54
AnnaBridge 143:86740a56073b 55 #define NRF_CLOCK_TASK_TRIGGER (1UL)
AnnaBridge 143:86740a56073b 56 #define NRF_CLOCK_EVENT_CLEAR (0UL)
AnnaBridge 143:86740a56073b 57
AnnaBridge 143:86740a56073b 58 /**
AnnaBridge 143:86740a56073b 59 * @brief Low-frequency clock sources.
AnnaBridge 143:86740a56073b 60 * @details Used by LFCLKSRC, LFCLKSTAT, and LFCLKSRCCOPY registers.
AnnaBridge 143:86740a56073b 61 */
AnnaBridge 143:86740a56073b 62 typedef enum
AnnaBridge 143:86740a56073b 63 {
AnnaBridge 143:86740a56073b 64 NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_RC, /**< Internal 32 kHz RC oscillator. */
AnnaBridge 143:86740a56073b 65 NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_Xtal, /**< External 32 kHz crystal. */
AnnaBridge 143:86740a56073b 66 NRF_CLOCK_LFCLK_Synth = CLOCK_LFCLKSRC_SRC_Synth /**< Internal 32 kHz synthesizer from HFCLK system clock. */
AnnaBridge 143:86740a56073b 67 } nrf_clock_lfclk_t;
AnnaBridge 143:86740a56073b 68
AnnaBridge 143:86740a56073b 69 /**
AnnaBridge 143:86740a56073b 70 * @brief High-frequency clock sources.
AnnaBridge 143:86740a56073b 71 */
AnnaBridge 143:86740a56073b 72 typedef enum
AnnaBridge 143:86740a56073b 73 {
AnnaBridge 143:86740a56073b 74 NRF_CLOCK_HFCLK_LOW_ACCURACY = CLOCK_HFCLKSTAT_SRC_RC, /**< Internal 16 MHz RC oscillator. */
AnnaBridge 143:86740a56073b 75 NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_Xtal /**< External 16 MHz/32 MHz crystal oscillator. */
AnnaBridge 143:86740a56073b 76 } nrf_clock_hfclk_t;
AnnaBridge 143:86740a56073b 77
AnnaBridge 143:86740a56073b 78 /**
AnnaBridge 143:86740a56073b 79 * @brief Trigger status of task LFCLKSTART/HFCLKSTART.
AnnaBridge 143:86740a56073b 80 * @details Used by LFCLKRUN and HFCLKRUN registers.
AnnaBridge 143:86740a56073b 81 */
AnnaBridge 143:86740a56073b 82 typedef enum
AnnaBridge 143:86740a56073b 83 {
AnnaBridge 143:86740a56073b 84 NRF_CLOCK_START_TASK_NOT_TRIGGERED = CLOCK_LFCLKRUN_STATUS_NotTriggered, /**< Task LFCLKSTART/HFCLKSTART has not been triggered. */
AnnaBridge 143:86740a56073b 85 NRF_CLOCK_START_TASK_TRIGGERED = CLOCK_LFCLKRUN_STATUS_Triggered /**< Task LFCLKSTART/HFCLKSTART has been triggered. */
AnnaBridge 143:86740a56073b 86 } nrf_clock_start_task_status_t;
AnnaBridge 143:86740a56073b 87
AnnaBridge 143:86740a56073b 88 /**
AnnaBridge 143:86740a56073b 89 * @brief Crystal frequency selection.
AnnaBridge 143:86740a56073b 90 */
AnnaBridge 143:86740a56073b 91 typedef enum
AnnaBridge 143:86740a56073b 92 {
AnnaBridge 143:86740a56073b 93 #ifdef NRF51
AnnaBridge 143:86740a56073b 94 NRF_CLOCK_XTALFREQ_Default = CLOCK_XTALFREQ_XTALFREQ_16MHz, /**< Default. 32 MHz. */
AnnaBridge 143:86740a56073b 95 NRF_CLOCK_XTALFREQ_16MHz = CLOCK_XTALFREQ_XTALFREQ_16MHz, /**< 16 MHz crystal. */
AnnaBridge 143:86740a56073b 96 NRF_CLOCK_XTALFREQ_32MHz = CLOCK_XTALFREQ_XTALFREQ_32MHz /**< 32 MHz crystal. */
AnnaBridge 143:86740a56073b 97 #elif defined NRF52
AnnaBridge 143:86740a56073b 98 NRF_CLOCK_XTALFREQ_Default, /**< Default. 64MHz. */
AnnaBridge 143:86740a56073b 99 #endif
AnnaBridge 143:86740a56073b 100 } nrf_clock_xtalfreq_t;
AnnaBridge 143:86740a56073b 101
AnnaBridge 143:86740a56073b 102 /**
AnnaBridge 143:86740a56073b 103 * @brief Interrupts.
AnnaBridge 143:86740a56073b 104 */
AnnaBridge 143:86740a56073b 105 typedef enum
AnnaBridge 143:86740a56073b 106 {
AnnaBridge 143:86740a56073b 107 NRF_CLOCK_INT_HF_STARTED_MASK = CLOCK_INTENSET_HFCLKSTARTED_Msk, /**< Interrupt on HFCLKSTARTED event. */
AnnaBridge 143:86740a56073b 108 NRF_CLOCK_INT_LF_STARTED_MASK = CLOCK_INTENSET_LFCLKSTARTED_Msk, /**< Interrupt on LFCLKSTARTED event. */
AnnaBridge 143:86740a56073b 109 NRF_CLOCK_INT_DONE_MASK = CLOCK_INTENSET_DONE_Msk, /**< Interrupt on DONE event. */
AnnaBridge 143:86740a56073b 110 NRF_CLOCK_INT_CTTO_MASK = CLOCK_INTENSET_CTTO_Msk /**< Interrupt on CTTO event. */
AnnaBridge 143:86740a56073b 111 } nrf_clock_int_mask_t;
AnnaBridge 143:86740a56073b 112
AnnaBridge 143:86740a56073b 113 /**
AnnaBridge 143:86740a56073b 114 * @brief Tasks.
AnnaBridge 143:86740a56073b 115 *
AnnaBridge 143:86740a56073b 116 * @details The NRF_CLOCK_TASK_LFCLKSTOP task cannot be set when the low-frequency clock is not running.
AnnaBridge 143:86740a56073b 117 * The NRF_CLOCK_TASK_HFCLKSTOP task cannot be set when the high-frequency clock is not running.
AnnaBridge 143:86740a56073b 118 */
AnnaBridge 143:86740a56073b 119 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
AnnaBridge 143:86740a56073b 120 {
AnnaBridge 143:86740a56073b 121 NRF_CLOCK_TASK_HFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTART), /**< Start HFCLK clock source.*/
AnnaBridge 143:86740a56073b 122 NRF_CLOCK_TASK_HFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTOP), /**< Stop HFCLK clock source.*/
AnnaBridge 143:86740a56073b 123 NRF_CLOCK_TASK_LFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTART), /**< Start LFCLK clock source.*/
AnnaBridge 143:86740a56073b 124 NRF_CLOCK_TASK_LFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTOP), /**< Stop LFCLK clock source.*/
AnnaBridge 143:86740a56073b 125 NRF_CLOCK_TASK_CAL = offsetof(NRF_CLOCK_Type, TASKS_CAL), /**< Start calibration of LFCLK RC oscillator.*/
AnnaBridge 143:86740a56073b 126 NRF_CLOCK_TASK_CTSTART = offsetof(NRF_CLOCK_Type, TASKS_CTSTART), /**< Start calibration timer.*/
AnnaBridge 143:86740a56073b 127 NRF_CLOCK_TASK_CTSTOP = offsetof(NRF_CLOCK_Type, TASKS_CTSTOP) /**< Stop calibration timer.*/
AnnaBridge 143:86740a56073b 128 } nrf_clock_task_t; /*lint -restore */
AnnaBridge 143:86740a56073b 129
AnnaBridge 143:86740a56073b 130 /**
AnnaBridge 143:86740a56073b 131 * @brief Events.
AnnaBridge 143:86740a56073b 132 */
AnnaBridge 143:86740a56073b 133 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
AnnaBridge 143:86740a56073b 134 {
AnnaBridge 143:86740a56073b 135 NRF_CLOCK_EVENT_HFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLKSTARTED), /**< HFCLK oscillator started.*/
AnnaBridge 143:86740a56073b 136 NRF_CLOCK_EVENT_LFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_LFCLKSTARTED), /**< LFCLK oscillator started.*/
AnnaBridge 143:86740a56073b 137 NRF_CLOCK_EVENT_DONE = offsetof(NRF_CLOCK_Type, EVENTS_DONE), /**< Calibration of LFCLK RC oscillator completed.*/
AnnaBridge 143:86740a56073b 138 NRF_CLOCK_EVENT_CTTO = offsetof(NRF_CLOCK_Type, EVENTS_CTTO) /**< Calibration timer time-out.*/
AnnaBridge 143:86740a56073b 139 } nrf_clock_event_t; /*lint -restore */
AnnaBridge 143:86740a56073b 140
AnnaBridge 143:86740a56073b 141 /**
AnnaBridge 143:86740a56073b 142 * @brief Function for enabling a specific interrupt.
AnnaBridge 143:86740a56073b 143 *
AnnaBridge 143:86740a56073b 144 * @param[in] int_mask Interrupt.
AnnaBridge 143:86740a56073b 145 */
AnnaBridge 143:86740a56073b 146 __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask);
AnnaBridge 143:86740a56073b 147
AnnaBridge 143:86740a56073b 148 /**
AnnaBridge 143:86740a56073b 149 * @brief Function for disabling a specific interrupt.
AnnaBridge 143:86740a56073b 150 *
AnnaBridge 143:86740a56073b 151 * @param[in] int_mask Interrupt.
AnnaBridge 143:86740a56073b 152 */
AnnaBridge 143:86740a56073b 153 __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask);
AnnaBridge 143:86740a56073b 154
AnnaBridge 143:86740a56073b 155 /**
AnnaBridge 143:86740a56073b 156 * @brief Function for retrieving the state of a specific interrupt.
AnnaBridge 143:86740a56073b 157 *
AnnaBridge 143:86740a56073b 158 * @param[in] int_mask Interrupt.
AnnaBridge 143:86740a56073b 159 *
AnnaBridge 143:86740a56073b 160 * @retval true If the interrupt is enabled.
AnnaBridge 143:86740a56073b 161 * @retval false If the interrupt is not enabled.
AnnaBridge 143:86740a56073b 162 */
AnnaBridge 143:86740a56073b 163 __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask);
AnnaBridge 143:86740a56073b 164
AnnaBridge 143:86740a56073b 165 /**
AnnaBridge 143:86740a56073b 166 * @brief Function for retrieving the address of a specific task.
AnnaBridge 143:86740a56073b 167 * @details This function can be used by the PPI module.
AnnaBridge 143:86740a56073b 168 *
AnnaBridge 143:86740a56073b 169 * @param[in] task Task.
AnnaBridge 143:86740a56073b 170 *
AnnaBridge 143:86740a56073b 171 * @return Address of the requested task register.
AnnaBridge 143:86740a56073b 172 */
AnnaBridge 143:86740a56073b 173 __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task);
AnnaBridge 143:86740a56073b 174
AnnaBridge 143:86740a56073b 175 /**
AnnaBridge 143:86740a56073b 176 * @brief Function for setting a specific task.
AnnaBridge 143:86740a56073b 177 *
AnnaBridge 143:86740a56073b 178 * @param[in] task Task.
AnnaBridge 143:86740a56073b 179 */
AnnaBridge 143:86740a56073b 180 __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task);
AnnaBridge 143:86740a56073b 181
AnnaBridge 143:86740a56073b 182 /**
AnnaBridge 143:86740a56073b 183 * @brief Function for retrieving the address of a specific event.
AnnaBridge 143:86740a56073b 184 * @details This function can be used by the PPI module.
AnnaBridge 143:86740a56073b 185 *
AnnaBridge 143:86740a56073b 186 * @param[in] event Event.
AnnaBridge 143:86740a56073b 187 *
AnnaBridge 143:86740a56073b 188 * @return Address of the requested event register.
AnnaBridge 143:86740a56073b 189 */
AnnaBridge 143:86740a56073b 190 __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event);
AnnaBridge 143:86740a56073b 191
AnnaBridge 143:86740a56073b 192 /**
AnnaBridge 143:86740a56073b 193 * @brief Function for clearing a specific event.
AnnaBridge 143:86740a56073b 194 *
AnnaBridge 143:86740a56073b 195 * @param[in] event Event.
AnnaBridge 143:86740a56073b 196 */
AnnaBridge 143:86740a56073b 197 __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event);
AnnaBridge 143:86740a56073b 198
AnnaBridge 143:86740a56073b 199 /**
AnnaBridge 143:86740a56073b 200 * @brief Function for retrieving the state of a specific event.
AnnaBridge 143:86740a56073b 201 *
AnnaBridge 143:86740a56073b 202 * @param[in] event Event.
AnnaBridge 143:86740a56073b 203 *
AnnaBridge 143:86740a56073b 204 * @retval true If the event is set.
AnnaBridge 143:86740a56073b 205 * @retval false If the event is not set.
AnnaBridge 143:86740a56073b 206 */
AnnaBridge 143:86740a56073b 207 __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event);
AnnaBridge 143:86740a56073b 208
AnnaBridge 143:86740a56073b 209 /**
AnnaBridge 143:86740a56073b 210 * @brief Function for changing the low-frequency clock source.
AnnaBridge 143:86740a56073b 211 * @details This function cannot be called when the low-frequency clock is running.
AnnaBridge 143:86740a56073b 212 *
AnnaBridge 143:86740a56073b 213 * @param[in] source New low-frequency clock source.
AnnaBridge 143:86740a56073b 214 *
AnnaBridge 143:86740a56073b 215 */
AnnaBridge 143:86740a56073b 216 __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source);
AnnaBridge 143:86740a56073b 217
AnnaBridge 143:86740a56073b 218 /**
AnnaBridge 143:86740a56073b 219 * @brief Function for retrieving the selected source for the low-frequency clock.
AnnaBridge 143:86740a56073b 220 *
AnnaBridge 143:86740a56073b 221 * @retval NRF_CLOCK_LFCLK_RC If the internal 32 kHz RC oscillator is the selected source for the low-frequency clock.
AnnaBridge 143:86740a56073b 222 * @retval NRF_CLOCK_LFCLK_Xtal If an external 32 kHz crystal oscillator is the selected source for the low-frequency clock.
AnnaBridge 143:86740a56073b 223 * @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from the HFCLK is the selected source for the low-frequency clock.
AnnaBridge 143:86740a56073b 224 */
AnnaBridge 143:86740a56073b 225 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void);
AnnaBridge 143:86740a56073b 226
AnnaBridge 143:86740a56073b 227 /**
AnnaBridge 143:86740a56073b 228 * @brief Function for retrieving the active source of the low-frequency clock.
AnnaBridge 143:86740a56073b 229 *
AnnaBridge 143:86740a56073b 230 * @retval NRF_CLOCK_LFCLK_RC If the internal 32 kHz RC oscillator is the active source of the low-frequency clock.
AnnaBridge 143:86740a56073b 231 * @retval NRF_CLOCK_LFCLK_Xtal If an external 32 kHz crystal oscillator is the active source of the low-frequency clock.
AnnaBridge 143:86740a56073b 232 * @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from the HFCLK is the active source of the low-frequency clock.
AnnaBridge 143:86740a56073b 233 */
AnnaBridge 143:86740a56073b 234 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void);
AnnaBridge 143:86740a56073b 235
AnnaBridge 143:86740a56073b 236 /**
AnnaBridge 143:86740a56073b 237 * @brief Function for retrieving the clock source for the LFCLK clock when the task LKCLKSTART is triggered.
AnnaBridge 143:86740a56073b 238 *
AnnaBridge 143:86740a56073b 239 * @retval NRF_CLOCK_LFCLK_RC If the internal 32 kHz RC oscillator is running and generating the LFCLK clock.
AnnaBridge 143:86740a56073b 240 * @retval NRF_CLOCK_LFCLK_Xtal If an external 32 kHz crystal oscillator is running and generating the LFCLK clock.
AnnaBridge 143:86740a56073b 241 * @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from the HFCLK is running and generating the LFCLK clock.
AnnaBridge 143:86740a56073b 242 */
AnnaBridge 143:86740a56073b 243 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void);
AnnaBridge 143:86740a56073b 244
AnnaBridge 143:86740a56073b 245 /**
AnnaBridge 143:86740a56073b 246 * @brief Function for retrieving the state of the LFCLK clock.
AnnaBridge 143:86740a56073b 247 *
AnnaBridge 143:86740a56073b 248 * @retval false If the LFCLK clock is not running.
AnnaBridge 143:86740a56073b 249 * @retval true If the LFCLK clock is running.
AnnaBridge 143:86740a56073b 250 */
AnnaBridge 143:86740a56073b 251 __STATIC_INLINE bool nrf_clock_lf_is_running(void);
AnnaBridge 143:86740a56073b 252
AnnaBridge 143:86740a56073b 253 /**
AnnaBridge 143:86740a56073b 254 * @brief Function for retrieving the trigger status of the task LFCLKSTART.
AnnaBridge 143:86740a56073b 255 *
AnnaBridge 143:86740a56073b 256 * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED If the task LFCLKSTART has not been triggered.
AnnaBridge 143:86740a56073b 257 * @retval NRF_CLOCK_START_TASK_TRIGGERED If the task LFCLKSTART has been triggered.
AnnaBridge 143:86740a56073b 258 */
AnnaBridge 143:86740a56073b 259 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void);
AnnaBridge 143:86740a56073b 260
AnnaBridge 143:86740a56073b 261 /**
AnnaBridge 143:86740a56073b 262 * @brief Function for retrieving the active source of the high-frequency clock.
AnnaBridge 143:86740a56073b 263 *
AnnaBridge 143:86740a56073b 264 * @retval NRF_CLOCK_HFCLK_LOW_ACCURACY If the internal 16 MHz RC oscillator is the active source of the high-frequency clock.
AnnaBridge 143:86740a56073b 265 * @retval NRF_CLOCK_HFCLK_HIGH_ACCURACY If an external 16 MHz/32 MHz crystal oscillator is the active source of the high-frequency clock.
AnnaBridge 143:86740a56073b 266 */
AnnaBridge 143:86740a56073b 267 __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void);
AnnaBridge 143:86740a56073b 268
AnnaBridge 143:86740a56073b 269 /**
AnnaBridge 143:86740a56073b 270 * @brief Function for retrieving the state of the HFCLK clock.
AnnaBridge 143:86740a56073b 271 *
AnnaBridge 143:86740a56073b 272 * @param[in] clk_src Clock source to be checked.
AnnaBridge 143:86740a56073b 273 *
AnnaBridge 143:86740a56073b 274 * @retval false If the HFCLK clock is not running.
AnnaBridge 143:86740a56073b 275 * @retval true If the HFCLK clock is running.
AnnaBridge 143:86740a56073b 276 */
AnnaBridge 143:86740a56073b 277 __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src);
AnnaBridge 143:86740a56073b 278
AnnaBridge 143:86740a56073b 279 /**
AnnaBridge 143:86740a56073b 280 * @brief Function for retrieving the trigger status of the task HFCLKSTART.
AnnaBridge 143:86740a56073b 281 *
AnnaBridge 143:86740a56073b 282 * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED If the task HFCLKSTART has not been triggered.
AnnaBridge 143:86740a56073b 283 * @retval NRF_CLOCK_START_TASK_TRIGGERED If the task HFCLKSTART has been triggered.
AnnaBridge 143:86740a56073b 284 */
AnnaBridge 143:86740a56073b 285 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void);
AnnaBridge 143:86740a56073b 286
AnnaBridge 143:86740a56073b 287 /**
AnnaBridge 143:86740a56073b 288 * @brief Function for retrieving the frequency selection of the external crystal.
AnnaBridge 143:86740a56073b 289 *
AnnaBridge 143:86740a56073b 290 * @retval NRF_CLOCK_XTALFREQ_16MHz If a 16 MHz crystal is used as source for the HFCLK oscillator.
AnnaBridge 143:86740a56073b 291 * @retval NRF_CLOCK_XTALFREQ_32MHz If a 32 MHz crystal is used as source for the HFCLK oscillator.
AnnaBridge 143:86740a56073b 292 */
AnnaBridge 143:86740a56073b 293 __STATIC_INLINE nrf_clock_xtalfreq_t nrf_clock_xtalfreq_get(void);
AnnaBridge 143:86740a56073b 294
AnnaBridge 143:86740a56073b 295 /**
AnnaBridge 143:86740a56073b 296 * @brief Function for changing the frequency selection of the external crystal.
AnnaBridge 143:86740a56073b 297 *
AnnaBridge 143:86740a56073b 298 * @param[in] xtalfreq New frequency selection for the external crystal.
AnnaBridge 143:86740a56073b 299 */
AnnaBridge 143:86740a56073b 300 __STATIC_INLINE void nrf_clock_xtalfreq_set(nrf_clock_xtalfreq_t xtalfreq);
AnnaBridge 143:86740a56073b 301
AnnaBridge 143:86740a56073b 302 /**
AnnaBridge 143:86740a56073b 303 * @brief Function for changing the calibration timer interval.
AnnaBridge 143:86740a56073b 304 *
AnnaBridge 143:86740a56073b 305 * @param[in] interval New calibration timer interval in 0.25 s resolution (range: 0.25 seconds to 31.75 seconds).
AnnaBridge 143:86740a56073b 306 */
AnnaBridge 143:86740a56073b 307 __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval);
AnnaBridge 143:86740a56073b 308
AnnaBridge 143:86740a56073b 309 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 310
AnnaBridge 143:86740a56073b 311 __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask)
AnnaBridge 143:86740a56073b 312 {
AnnaBridge 143:86740a56073b 313 NRF_CLOCK->INTENSET = int_mask;
AnnaBridge 143:86740a56073b 314 }
AnnaBridge 143:86740a56073b 315
AnnaBridge 143:86740a56073b 316 __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask)
AnnaBridge 143:86740a56073b 317 {
AnnaBridge 143:86740a56073b 318 NRF_CLOCK->INTENCLR = int_mask;
AnnaBridge 143:86740a56073b 319 }
AnnaBridge 143:86740a56073b 320
AnnaBridge 143:86740a56073b 321 __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask)
AnnaBridge 143:86740a56073b 322 {
AnnaBridge 143:86740a56073b 323 return (bool)(NRF_CLOCK->INTENCLR & int_mask);
AnnaBridge 143:86740a56073b 324 }
AnnaBridge 143:86740a56073b 325
AnnaBridge 143:86740a56073b 326 __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task)
AnnaBridge 143:86740a56073b 327 {
AnnaBridge 143:86740a56073b 328 return ((uint32_t )NRF_CLOCK + task);
AnnaBridge 143:86740a56073b 329 }
AnnaBridge 143:86740a56073b 330
AnnaBridge 143:86740a56073b 331 __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task)
AnnaBridge 143:86740a56073b 332 {
AnnaBridge 143:86740a56073b 333 *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + task)) = NRF_CLOCK_TASK_TRIGGER;
AnnaBridge 143:86740a56073b 334 }
AnnaBridge 143:86740a56073b 335
AnnaBridge 143:86740a56073b 336 __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event)
AnnaBridge 143:86740a56073b 337 {
AnnaBridge 143:86740a56073b 338 return ((uint32_t)NRF_CLOCK + event);
AnnaBridge 143:86740a56073b 339 }
AnnaBridge 143:86740a56073b 340
AnnaBridge 143:86740a56073b 341 __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event)
AnnaBridge 143:86740a56073b 342 {
AnnaBridge 143:86740a56073b 343 *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event)) = NRF_CLOCK_EVENT_CLEAR;
AnnaBridge 143:86740a56073b 344 #if __CORTEX_M == 0x04
AnnaBridge 143:86740a56073b 345 volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event));
AnnaBridge 143:86740a56073b 346 (void)dummy;
AnnaBridge 143:86740a56073b 347 #endif
AnnaBridge 143:86740a56073b 348 }
AnnaBridge 143:86740a56073b 349
AnnaBridge 143:86740a56073b 350 __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event)
AnnaBridge 143:86740a56073b 351 {
AnnaBridge 143:86740a56073b 352 return (bool)*((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event));
AnnaBridge 143:86740a56073b 353 }
AnnaBridge 143:86740a56073b 354
AnnaBridge 143:86740a56073b 355 __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source)
AnnaBridge 143:86740a56073b 356 {
AnnaBridge 143:86740a56073b 357 NRF_CLOCK->LFCLKSRC =
AnnaBridge 143:86740a56073b 358 (uint32_t)((source << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
AnnaBridge 143:86740a56073b 359 }
AnnaBridge 143:86740a56073b 360
AnnaBridge 143:86740a56073b 361 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void)
AnnaBridge 143:86740a56073b 362 {
AnnaBridge 143:86740a56073b 363 return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSRC &
AnnaBridge 143:86740a56073b 364 CLOCK_LFCLKSRC_SRC_Msk) >> CLOCK_LFCLKSRC_SRC_Pos);
AnnaBridge 143:86740a56073b 365 }
AnnaBridge 143:86740a56073b 366
AnnaBridge 143:86740a56073b 367 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void)
AnnaBridge 143:86740a56073b 368 {
AnnaBridge 143:86740a56073b 369 return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSTAT &
AnnaBridge 143:86740a56073b 370 CLOCK_LFCLKSTAT_SRC_Msk) >> CLOCK_LFCLKSTAT_SRC_Pos);
AnnaBridge 143:86740a56073b 371 }
AnnaBridge 143:86740a56073b 372
AnnaBridge 143:86740a56073b 373 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void)
AnnaBridge 143:86740a56073b 374 {
AnnaBridge 143:86740a56073b 375 return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSRCCOPY &
AnnaBridge 143:86740a56073b 376 CLOCK_LFCLKSRCCOPY_SRC_Msk) >> CLOCK_LFCLKSRCCOPY_SRC_Pos);
AnnaBridge 143:86740a56073b 377 }
AnnaBridge 143:86740a56073b 378
AnnaBridge 143:86740a56073b 379 __STATIC_INLINE bool nrf_clock_lf_is_running(void)
AnnaBridge 143:86740a56073b 380 {
AnnaBridge 143:86740a56073b 381 return ((NRF_CLOCK->LFCLKSTAT &
AnnaBridge 143:86740a56073b 382 CLOCK_LFCLKSTAT_STATE_Msk) >> CLOCK_LFCLKSTAT_STATE_Pos);
AnnaBridge 143:86740a56073b 383 }
AnnaBridge 143:86740a56073b 384
AnnaBridge 143:86740a56073b 385 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void)
AnnaBridge 143:86740a56073b 386 {
AnnaBridge 143:86740a56073b 387 return (nrf_clock_start_task_status_t)((NRF_CLOCK->LFCLKRUN &
AnnaBridge 143:86740a56073b 388 CLOCK_LFCLKRUN_STATUS_Msk) >>
AnnaBridge 143:86740a56073b 389 CLOCK_LFCLKRUN_STATUS_Pos);
AnnaBridge 143:86740a56073b 390 }
AnnaBridge 143:86740a56073b 391
AnnaBridge 143:86740a56073b 392 __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void)
AnnaBridge 143:86740a56073b 393 {
AnnaBridge 143:86740a56073b 394 return (nrf_clock_hfclk_t)((NRF_CLOCK->HFCLKSTAT &
AnnaBridge 143:86740a56073b 395 CLOCK_HFCLKSTAT_SRC_Msk) >> CLOCK_HFCLKSTAT_SRC_Pos);
AnnaBridge 143:86740a56073b 396 }
AnnaBridge 143:86740a56073b 397
AnnaBridge 143:86740a56073b 398 __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src)
AnnaBridge 143:86740a56073b 399 {
AnnaBridge 143:86740a56073b 400 return (NRF_CLOCK->HFCLKSTAT & (CLOCK_HFCLKSTAT_STATE_Msk | CLOCK_HFCLKSTAT_SRC_Msk)) ==
AnnaBridge 143:86740a56073b 401 (CLOCK_HFCLKSTAT_STATE_Msk | (clk_src << CLOCK_HFCLKSTAT_SRC_Pos));
AnnaBridge 143:86740a56073b 402 }
AnnaBridge 143:86740a56073b 403
AnnaBridge 143:86740a56073b 404 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void)
AnnaBridge 143:86740a56073b 405 {
AnnaBridge 143:86740a56073b 406 return (nrf_clock_start_task_status_t)((NRF_CLOCK->HFCLKRUN &
AnnaBridge 143:86740a56073b 407 CLOCK_HFCLKRUN_STATUS_Msk) >>
AnnaBridge 143:86740a56073b 408 CLOCK_HFCLKRUN_STATUS_Pos);
AnnaBridge 143:86740a56073b 409 }
AnnaBridge 143:86740a56073b 410
AnnaBridge 143:86740a56073b 411 __STATIC_INLINE nrf_clock_xtalfreq_t nrf_clock_xtalfreq_get(void)
AnnaBridge 143:86740a56073b 412 {
AnnaBridge 143:86740a56073b 413 #ifdef NRF51
AnnaBridge 143:86740a56073b 414 return (nrf_clock_xtalfreq_t)((NRF_CLOCK->XTALFREQ &
AnnaBridge 143:86740a56073b 415 CLOCK_XTALFREQ_XTALFREQ_Msk) >> CLOCK_XTALFREQ_XTALFREQ_Pos);
AnnaBridge 143:86740a56073b 416 #elif defined NRF52
AnnaBridge 143:86740a56073b 417 return NRF_CLOCK_XTALFREQ_Default;
AnnaBridge 143:86740a56073b 418 #endif
AnnaBridge 143:86740a56073b 419 }
AnnaBridge 143:86740a56073b 420
AnnaBridge 143:86740a56073b 421 __STATIC_INLINE void nrf_clock_xtalfreq_set(nrf_clock_xtalfreq_t xtalfreq)
AnnaBridge 143:86740a56073b 422 {
AnnaBridge 143:86740a56073b 423 #ifdef NRF51
AnnaBridge 143:86740a56073b 424 NRF_CLOCK->XTALFREQ =
AnnaBridge 143:86740a56073b 425 (uint32_t)((xtalfreq << CLOCK_XTALFREQ_XTALFREQ_Pos) & CLOCK_XTALFREQ_XTALFREQ_Msk);
AnnaBridge 143:86740a56073b 426 #elif defined NRF52
AnnaBridge 143:86740a56073b 427 return;
AnnaBridge 143:86740a56073b 428 #endif
AnnaBridge 143:86740a56073b 429 }
AnnaBridge 143:86740a56073b 430
AnnaBridge 143:86740a56073b 431 __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval)
AnnaBridge 143:86740a56073b 432 {
AnnaBridge 143:86740a56073b 433 NRF_CLOCK->CTIV = ((interval << CLOCK_CTIV_CTIV_Pos) & CLOCK_CTIV_CTIV_Msk);
AnnaBridge 143:86740a56073b 434 }
AnnaBridge 143:86740a56073b 435
AnnaBridge 143:86740a56073b 436 #endif // SUPPRESS_INLINE_IMPLEMENTATION
AnnaBridge 143:86740a56073b 437
AnnaBridge 143:86740a56073b 438 /**
AnnaBridge 143:86740a56073b 439 *@}
AnnaBridge 143:86740a56073b 440 **/
AnnaBridge 143:86740a56073b 441 #endif // NRF_CLOCK_H__