Branch data Line data Source code
1 : : /* 2 : : * Copyright (c) 2019 - 2022, Nordic Semiconductor ASA 3 : : * All rights reserved. 4 : : * 5 : : * SPDX-License-Identifier: BSD-3-Clause 6 : : * 7 : : * Redistribution and use in source and binary forms, with or without 8 : : * modification, are permitted provided that the following conditions are met: 9 : : * 10 : : * 1. Redistributions of source code must retain the above copyright notice, this 11 : : * list of conditions and the following disclaimer. 12 : : * 13 : : * 2. Redistributions in binary form must reproduce the above copyright 14 : : * notice, this list of conditions and the following disclaimer in the 15 : : * documentation and/or other materials provided with the distribution. 16 : : * 17 : : * 3. Neither the name of the copyright holder nor the names of its 18 : : * contributors may be used to endorse or promote products derived from this 19 : : * software without specific prior written permission. 20 : : * 21 : : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 : : * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 : : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 : : * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 : : * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 : : * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 : : * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 : : * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 : : * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 : : * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 : : * POSSIBILITY OF SUCH DAMAGE. 32 : : */ 33 : : 34 : : #ifndef NRF_OSCILLATORS_H__ 35 : : #define NRF_OSCILLATORS_H__ 36 : : 37 : : #include <nrfx.h> 38 : : 39 : : #ifdef __cplusplus 40 : : extern "C" { 41 : : #endif 42 : : 43 : : /** 44 : : * @defgroup nrf_oscillators_hal OSCILLATORS HAL 45 : : * @{ 46 : : * @ingroup nrf_clock 47 : : * @brief Hardware access layer for managing the OSCILLATORS peripheral. 48 : : */ 49 : : 50 : : /** @brief Capacitors configuration for LFXO. */ 51 : : typedef enum 52 : : { 53 : : NRF_OSCILLATORS_LFXO_CAP_EXTERNAL = OSCILLATORS_XOSC32KI_INTCAP_INTCAP_External, ///< Use external capacitors. 54 : : NRF_OSCILLATORS_LFXO_CAP_6PF = OSCILLATORS_XOSC32KI_INTCAP_INTCAP_C6PF, ///< Use 6 pF internal capacitors. 55 : : NRF_OSCILLATORS_LFXO_CAP_7PF = OSCILLATORS_XOSC32KI_INTCAP_INTCAP_C7PF, ///< Use 7 pF internal capacitors. 56 : : NRF_OSCILLATORS_LFXO_CAP_9PF = OSCILLATORS_XOSC32KI_INTCAP_INTCAP_C9PF, ///< Use 9 pF internal capacitors. 57 : : } nrf_oscillators_lfxo_cap_t; 58 : : 59 : : /** 60 : : * @brief Function for enabling or disabling the bypass of LFXO with external clock source. 61 : : * 62 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral. 63 : : * @param[in] enable True if bypass is to be enabled (use with rail-to-rail external source). 64 : : * False if bypass is to be disabled (use with xtal or low-swing external source). 65 : : */ 66 : : NRF_STATIC_INLINE void nrf_oscillators_lfxo_bypass_set(NRF_OSCILLATORS_Type * p_reg, bool enable); 67 : : 68 : : /** 69 : : * @brief Function for configuring the internal capacitors of LFXO. 70 : : * 71 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral. 72 : : * @param[in] cap Capacitors configuration. 73 : : */ 74 : : NRF_STATIC_INLINE void nrf_oscillators_lfxo_cap_set(NRF_OSCILLATORS_Type * p_reg, 75 : : nrf_oscillators_lfxo_cap_t cap); 76 : : 77 : : /** 78 : : * @brief Function for configuring the internal capacitors of HXFO. 79 : : * 80 : : * The capacitance of internal capacitors ranges from 7 pF to 20 pF in 0.5 pF steps. 81 : : * To calculate the correct @p cap_value, use the following equation: 82 : : * CAPVALUE = (1+FICR->XOSC32MTRIM.SLOPE/16) * (CAPACITANCE*2-14) + FICR->XOSC32MTRIM.OFFSET 83 : : * 84 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral. 85 : : * @param[in] enable True if internal capacitors are to be enabled, false otherwise. 86 : : * @param[in] cap_value Value representing capacitance, calculated using provided equation. 87 : : * Ignored when internal capacitors are disabled. 88 : : */ 89 : : NRF_STATIC_INLINE void nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS_Type * p_reg, 90 : : bool enable, 91 : : uint32_t cap_value); 92 : : 93 : : #ifndef NRF_DECLARE_ONLY 94 : : NRF_STATIC_INLINE void nrf_oscillators_lfxo_bypass_set(NRF_OSCILLATORS_Type * p_reg, bool enable) 95 : : { 96 : : p_reg->XOSC32KI.BYPASS = (enable ? OSCILLATORS_XOSC32KI_BYPASS_BYPASS_Enabled : 97 : : OSCILLATORS_XOSC32KI_BYPASS_BYPASS_Disabled); 98 : : } 99 : : 100 : 1 : NRF_STATIC_INLINE void nrf_oscillators_lfxo_cap_set(NRF_OSCILLATORS_Type * p_reg, 101 : : nrf_oscillators_lfxo_cap_t cap) 102 : : { 103 : 1 : p_reg->XOSC32KI.INTCAP = (uint32_t)cap; 104 : 1 : } 105 : : 106 : : NRF_STATIC_INLINE void nrf_oscillators_hfxo_cap_set(NRF_OSCILLATORS_Type * p_reg, 107 : : bool enable, 108 : : uint32_t cap_value) 109 : : { 110 : : p_reg->XOSC32MCAPS = 111 : : (enable ? ((OSCILLATORS_XOSC32MCAPS_ENABLE_Enabled << OSCILLATORS_XOSC32MCAPS_ENABLE_Pos) | 112 : : (cap_value << OSCILLATORS_XOSC32MCAPS_CAPVALUE_Pos)) 113 : : : (OSCILLATORS_XOSC32MCAPS_ENABLE_Disabled << OSCILLATORS_XOSC32MCAPS_ENABLE_Pos)); 114 : : } 115 : : #endif // NRF_DECLARE_ONLY 116 : : 117 : : /** @} */ 118 : : 119 : : #ifdef __cplusplus 120 : : } 121 : : #endif 122 : : 123 : : #endif // NRF_OSCILLATORS_H__