]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/osc/fsl_osc_hal.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / hal / osc / fsl_osc_hal.c
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
29  */
30
31 #include "fsl_osc_hal.h"
32
33 /*******************************************************************************
34  * Definitions
35  ******************************************************************************/
36
37 /*******************************************************************************
38  * Code
39  ******************************************************************************/
40
41 /*FUNCTION**********************************************************************
42  *
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.
49  * 
50  *END**************************************************************************/
51 void OSC_HAL_SetExternalRefClkCmd(uint32_t baseAddr, bool enable)
52 {
53     BW_OSC_CR_ERCLKEN(baseAddr, enable);
54 }
55
56 /*FUNCTION**********************************************************************
57  *
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.
64  * 
65  *END**************************************************************************/
66 bool OSC_HAL_GetExternalRefClkCmd(uint32_t baseAddr)
67 {
68     return (bool)BR_OSC_CR_ERCLKEN(baseAddr);
69 }
70
71 /*FUNCTION**********************************************************************
72  *
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. 
77  * 
78  *END**************************************************************************/
79 void OSC_HAL_SetExternalRefClkInStopModeCmd(uint32_t baseAddr, bool enable)
80 {
81     BW_OSC_CR_EREFSTEN(baseAddr, enable);
82 }
83
84 /*FUNCTION**********************************************************************
85  *
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. 
90  * 
91  *END**************************************************************************/
92 bool OSC_HAL_GetExternalRefClkInStopModeCmd(uint32_t baseAddr)
93 {
94     return (bool)BR_OSC_CR_EREFSTEN(baseAddr);
95 }
96
97 /*FUNCTION**********************************************************************
98  *
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.
104  * 
105  *END**************************************************************************/
106 void OSC_HAL_SetCapacitorCmd(uint32_t baseAddr, 
107                              osc_capacitor_config_t capacitorConfig,
108                              bool enable)
109 {
110     if (capacitorConfig == kOscCapacitor2p)
111     {
112         BW_OSC_CR_SC2P(baseAddr, enable);
113     }
114     else if (capacitorConfig == kOscCapacitor4p)
115     {
116         BW_OSC_CR_SC4P(baseAddr, enable);
117     }
118     else if (capacitorConfig == kOscCapacitor8p)
119     {
120         BW_OSC_CR_SC8P(baseAddr, enable);
121     }
122     else if (capacitorConfig == kOscCapacitor16p)
123     {
124         BW_OSC_CR_SC16P(baseAddr, enable);
125     }
126 }
127
128 /*FUNCTION**********************************************************************
129  *
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 
133  * oscillator.
134  * 
135  *END**************************************************************************/
136 bool OSC_HAL_GetCapacitorCmd(uint32_t baseAddr, 
137                              osc_capacitor_config_t capacitorConfig)
138 {
139     if (capacitorConfig == kOscCapacitor2p)
140     {
141         return (bool)BR_OSC_CR_SC2P(baseAddr);
142     }
143     else if (capacitorConfig == kOscCapacitor4p)
144     {
145         return (bool)BR_OSC_CR_SC4P(baseAddr);
146     }
147     else if (capacitorConfig == kOscCapacitor8p)
148     {
149         return (bool)BR_OSC_CR_SC8P(baseAddr);
150     }
151     else if (capacitorConfig == kOscCapacitor16p)
152     {
153         return (bool)BR_OSC_CR_SC16P(baseAddr);
154     }
155
156     return 0;
157 }
158
159 #if FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER
160 /*FUNCTION**********************************************************************
161  *
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 
166  * peripherals. 
167  * 
168  *END**************************************************************************/
169 void OSC_HAL_SetExternalRefClkDivCmd(uint32_t baseAddr, uint32_t divider)
170 {
171     BW_OSC_DIV_ERPS(baseAddr, divider);
172 }
173
174 /*FUNCTION**********************************************************************
175  *
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 
180  * peripherals. 
181  * 
182  *END**************************************************************************/
183 uint32_t OSC_HAL_GetExternalRefClkDivCmd(uint32_t baseAddr)
184 {
185     return BR_OSC_DIV_ERPS(baseAddr);
186 }
187 #endif
188
189 /*******************************************************************************
190  * EOF
191  ******************************************************************************/
192