2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "fsl_osc_hal.h"
33 /*******************************************************************************
35 ******************************************************************************/
37 /*******************************************************************************
39 ******************************************************************************/
41 /*FUNCTION**********************************************************************
43 * Function Name : OSC_HAL_SetExternalRefClkCmd
44 * Description : Enable/disable the external reference clock
45 * This function will enable/disable the external reference clock output
46 * for oscillator - that is the OSCERCLK. This clock will be used by many
47 * peripherals. It should be enabled at early system init stage to ensure the
48 * peripherals could select it and use it.
50 *END**************************************************************************/
51 void OSC_HAL_SetExternalRefClkCmd(uint32_t baseAddr, bool enable)
53 BW_OSC_CR_ERCLKEN(baseAddr, enable);
56 /*FUNCTION**********************************************************************
58 * Function Name : OSC_HAL_GetExternalRefClkCmd
59 * Description : Get the external reference clock enable setting for osc
60 * This function will get the external reference clock output enable setting
61 * for oscillator - that is the OSCERCLK. This clock will be used by many
62 * peripherals. It should be enabled at early system init stage to ensure the
63 * peripherals could select it and use it.
65 *END**************************************************************************/
66 bool OSC_HAL_GetExternalRefClkCmd(uint32_t baseAddr)
68 return (bool)BR_OSC_CR_ERCLKEN(baseAddr);
71 /*FUNCTION**********************************************************************
73 * Function Name : OSC_HAL_SetExternalRefClkInStopModeCmd
74 * Description : Enable/disable the external ref clock in stop mode
75 * This function will enable/disable the external reference clock (OSCERCLK)
76 * when MCU enters Stop mode.
78 *END**************************************************************************/
79 void OSC_HAL_SetExternalRefClkInStopModeCmd(uint32_t baseAddr, bool enable)
81 BW_OSC_CR_EREFSTEN(baseAddr, enable);
84 /*FUNCTION**********************************************************************
86 * Function Name : OSC_HAL_GetExternalRefClkInStopModeCmd
87 * Description : Get the external ref clock enable setting for osc in stop mode
88 * This function will get the external reference clock (OSCERCLK) setting when
89 * MCU enters Stop mode.
91 *END**************************************************************************/
92 bool OSC_HAL_GetExternalRefClkInStopModeCmd(uint32_t baseAddr)
94 return (bool)BR_OSC_CR_EREFSTEN(baseAddr);
97 /*FUNCTION**********************************************************************
99 * Function Name : OSC_HAL_SetCapacitorCmd
100 * Description : Enable/disable the capacitor configuration for oscillator
101 * This function will enable/disable the specified capacitors configuration for
102 * oscillator. This should be done in early system level init function call
103 * based on system configuration.
105 *END**************************************************************************/
106 void OSC_HAL_SetCapacitorCmd(uint32_t baseAddr,
107 osc_capacitor_config_t capacitorConfig,
110 if (capacitorConfig == kOscCapacitor2p)
112 BW_OSC_CR_SC2P(baseAddr, enable);
114 else if (capacitorConfig == kOscCapacitor4p)
116 BW_OSC_CR_SC4P(baseAddr, enable);
118 else if (capacitorConfig == kOscCapacitor8p)
120 BW_OSC_CR_SC8P(baseAddr, enable);
122 else if (capacitorConfig == kOscCapacitor16p)
124 BW_OSC_CR_SC16P(baseAddr, enable);
128 /*FUNCTION**********************************************************************
130 * Function Name : OSC_HAL_GetCapacitorCmd
131 * Description : Get the capacitor configuration for specific oscillator
132 * This function will get the specified capacitors configuration for the
135 *END**************************************************************************/
136 bool OSC_HAL_GetCapacitorCmd(uint32_t baseAddr,
137 osc_capacitor_config_t capacitorConfig)
139 if (capacitorConfig == kOscCapacitor2p)
141 return (bool)BR_OSC_CR_SC2P(baseAddr);
143 else if (capacitorConfig == kOscCapacitor4p)
145 return (bool)BR_OSC_CR_SC4P(baseAddr);
147 else if (capacitorConfig == kOscCapacitor8p)
149 return (bool)BR_OSC_CR_SC8P(baseAddr);
151 else if (capacitorConfig == kOscCapacitor16p)
153 return (bool)BR_OSC_CR_SC16P(baseAddr);
159 #if FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER
160 /*FUNCTION**********************************************************************
162 * Function Name : OSC_HAL_SetExternalRefClkDivCmd
163 * Description : Set the external reference clock divider setting for osc
164 * This function will get the external reference clock divider setting
165 * for oscillator - that is the OSCERCLK. This clock will be used by many
168 *END**************************************************************************/
169 void OSC_HAL_SetExternalRefClkDivCmd(uint32_t baseAddr, uint32_t divider)
171 BW_OSC_DIV_ERPS(baseAddr, divider);
174 /*FUNCTION**********************************************************************
176 * Function Name : OSC_HAL_GetExternalRefClkDivCmd
177 * Description : Get the external reference clock divider setting for osc
178 * This function will get the external reference clock divider setting
179 * for oscillator - that is the OSCERCLK. This clock will be used by many
182 *END**************************************************************************/
183 uint32_t OSC_HAL_GetExternalRefClkDivCmd(uint32_t baseAddr)
185 return BR_OSC_DIV_ERPS(baseAddr);
189 /*******************************************************************************
191 ******************************************************************************/