summaryrefslogtreecommitdiff
path: root/tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/osc/fsl_osc_hal.h
blob: cab94a167c4118a3919402aac93177449a8e2021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#if !defined(__FSL_OSC_HAL_H__)
#define __FSL_OSC_HAL_H__

#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include "fsl_device_registers.h"
#include "fsl_osc_features.h"

/*! @addtogroup osc_hal*/
/*! @{*/

/*! @file fsl_osc_hal.h */

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*! @brief Oscillator capacitor load configurations.*/
typedef enum _osc_capacitor_config {
    kOscCapacitor2p = OSC_CR_SC2P_MASK,     /*!< 2 pF capacitor load */
    kOscCapacitor4p = OSC_CR_SC4P_MASK,     /*!< 4 pF capacitor load */
    kOscCapacitor8p = OSC_CR_SC8P_MASK,     /*!< 8 pF capacitor load */
    kOscCapacitor16p = OSC_CR_SC16P_MASK    /*!< 16 pF capacitor load */
} osc_capacitor_config_t;

/*******************************************************************************
 * API
 ******************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus*/

/*! @name oscillator control APIs*/
/*@{*/


/*!
 * @brief Enables the external reference clock for the oscillator.
 *
 * This function  enables the external reference clock output 
 * for the oscillator, OSCERCLK. This clock is used
 * by many peripherals. It should be enabled at an early system initialization
 * stage to ensure the peripherals can select and use it.
 *
 * @param baseAddr Oscillator register base address
 * @param enable   enable/disable the clock
 */
void OSC_HAL_SetExternalRefClkCmd(uint32_t baseAddr, bool enable);

/*!
 * @brief Gets the external reference clock enable setting for the oscillator.
 *
 * This function gets the external reference clock output enable setting
 * for the oscillator , OSCERCLK. This clock  is used
 * by many peripherals. It should be enabled at an early system initialization
 * stage to ensure the peripherals could select and use it.
 * 
 * @param baseAddr Oscillator register base address
 * @return enable  clock enable/disable setting
 */
bool OSC_HAL_GetExternalRefClkCmd(uint32_t baseAddr);

/*!
 * @brief Enables/disables the external reference clock in stop mode.
 *
 * This function  enables/disables the external reference clock (OSCERCLK) when an
 * MCU enters the stop mode. 
 *
 * @param baseAddr Oscillator register base address
 * @param enable   enable/disable setting
 */
void OSC_HAL_SetExternalRefClkInStopModeCmd(uint32_t baseAddr, bool enable);

/*!
 * @brief Gets the external reference clock enable setting in stop mode.
 *
 * This function gets the external reference clock (OSCERCLK) enable setting when an
 * MCU enters stop mode. 
 *
 * @param baseAddr Oscillator register base address
 */
bool OSC_HAL_GetExternalRefClkInStopModeCmd(uint32_t baseAddr);

/*!
 * @brief Enables the capacitor configuration for the oscillator.
 *
 * This function  enables the specified capacitors configuration for the 
 * oscillator. This should be done in the early system level initialization function call
 * based on the system configuration.
 *
 * @param baseAddr Oscillator register base address
 * @param capacitorConfig Capacitor configuration. (2p, 4p, 8p, 16p)
 * @param enable          enable/disable the Capacitor configuration 
 */
void OSC_HAL_SetCapacitorCmd(uint32_t baseAddr, 
                             osc_capacitor_config_t capacitorConfig,
                             bool enable);

/*!
 * @brief Gets the capacitor configuration for a specific oscillator.
 *
 * This function gets the specified capacitors configuration for an 
 * oscillator.
 *
 * @param baseAddr Oscillator register base address
 * @param capacitorConfig Capacitor configuration. 
 * @return enable         enable/disable setting
 */
bool OSC_HAL_GetCapacitorCmd(uint32_t baseAddr, 
                             osc_capacitor_config_t capacitorConfig);

#if FSL_FEATURE_OSC_HAS_EXT_REF_CLOCK_DIVIDER
/*!
 * @brief Sets the external reference clock divider.
 *
 * This function sets the divider for the external reference clock.
 *
 * @param baseAddr Oscillator register base address
 * @param divider   divider settings
 */
void OSC_HAL_SetExternalRefClkDivCmd(uint32_t baseAddr, uint32_t divider);

/*!
 * @brief Gets the external reference clock divider.
 *
 * This function gets the divider for the external reference clock.
 *
 * @param baseAddr Oscillator register base address
 * @return divider   divider settings
 */
uint32_t OSC_HAL_GetExternalRefClkDivCmd(uint32_t baseAddr);
#endif

/*@}*/

#if defined(__cplusplus)
}
#endif /* __cplusplus*/

/*! @}*/

#endif /* __FSL_OSC_HAL_H__*/
/*******************************************************************************
 * EOF
 ******************************************************************************/