2 * @brief LPC18xx/43xx clock driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licenser disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __CLOCK_18XX_43XX_H_
\r
33 #define __CLOCK_18XX_43XX_H_
\r
39 /** @defgroup CLOCK_18XX_43XX CHIP: LPC18xx/43xx Clock Driver
\r
40 * @ingroup CHIP_18XX_43XX_Drivers
\r
44 /** @defgroup CLOCK_18XX_43XX_OPTIONS CHIP: LPC18xx/43xx Clock Driver driver options
\r
45 * @ingroup CLOCK_18XX_43XX CHIP_18XX_43XX_DRIVER_OPTIONS
\r
46 * The clock driver has options that configure it's operation at build-time.<br>
\r
48 * <b>MAX_CLOCK_FREQ</b><br>
\r
49 * This define, when set, identifies the running CPU clock rate of the system
\r
50 * (change this to alter running CPU speed).<br>
\r
51 * When this is not defined, The maximum clock rate for the CPU is used.<br>
\r
53 * <b>CRYSTAL_MAIN_FREQ_IN</b><br>
\r
54 * This define is the external crystal frequency used for the main oscillator.<br>
\r
56 * <b>EXTCLKIN_FREQ_IN</b><br>
\r
57 * This define is rate of the input clock signal on the CLKIN input of the device
\r
58 * (on some parts only).<br>
\r
66 /* Internal oscillator frequency */
\r
67 #define CGU_IRC_FREQ (12000000)
\r
69 #ifndef MAX_CLOCK_FREQ
\r
70 #if defined(CHIP_LPC43XX)
\r
71 #define MAX_CLOCK_FREQ (204000000)
\r
73 #define MAX_CLOCK_FREQ (180000000)
\r
75 #endif /* MAX_CLOCK_FREQ */
\r
78 * @brief Enables the crystal oscillator
\r
81 void Chip_Clock_EnableCrystal(void);
\r
84 * @brief Disables the crystal oscillator
\r
87 void Chip_Clock_DisableCrystal(void);
\r
90 * @brief Configures the main PLL
\r
91 * @param Input : Which clock input to use as the PLL input
\r
92 * @param MinHz : Minimum allowable PLL output frequency
\r
93 * @param DesiredHz : Desired PLL output frequency
\r
94 * @param MaxHz : Maximum allowable PLL output frequency
\r
95 * @return Frequency of the PLL in Hz
\r
96 * Returns the configured PLL frequency or zero if the PLL can not be configured between MinHz
\r
97 * and MaxHz. This will not wait for PLL lock. Call Chip_Clock_MainPLLLocked() to determine if
\r
98 * the PLL is locked.
\r
100 uint32_t Chip_Clock_SetupMainPLLHz(CHIP_CGU_CLKIN_T Input, uint32_t MinHz, uint32_t DesiredHz, uint32_t MaxHz);
\r
103 * @brief Directly set the PLL multipler
\r
104 * @param Input : Which clock input to use as the PLL input
\r
105 * @param mult : How many times to multiply the input clock
\r
106 * @return Frequency of the PLL in Hz
\r
108 uint32_t Chip_Clock_SetupMainPLLMult(CHIP_CGU_CLKIN_T Input, uint32_t mult);
\r
111 * @brief Returns the frequency of the main PLL
\r
112 * @return Frequency of the PLL in Hz
\r
113 * Returns zero if the main PLL is not running.
\r
115 uint32_t Chip_Clock_GetMainPLLHz(void);
\r
118 * @brief Disables the main PLL
\r
120 * Make sure the main PLL is not needed to clock the part before disabling it.
\r
121 * Saves power if the main PLL is not needed.
\r
123 void Chip_Clock_DisableMainPLL(void);
\r
126 * @brief Enbles the main PLL
\r
128 * Make sure the main PLL is enabled.
\r
130 void Chip_Clock_EnableMainPLL(void);
\r
133 * @brief Returns the lock status of the main PLL
\r
134 * @return true if the PLL is locked, otherwise false
\r
135 * The main PLL should be locked prior to using it as a clock input for a base clock.
\r
137 bool Chip_Clock_MainPLLLocked(void);
\r
140 * @brief Sets up a CGU clock divider and it's input clock
\r
141 * @param Divider : CHIP_CGU_IDIV_T value indicating which divider to configure
\r
142 * @param Input : CHIP_CGU_CLKIN_T value indicating which clock source to use or CLOCKINPUT_PD to power down divider
\r
143 * @param Divisor : value to divide Input clock by
\r
145 * Maximum divider on A = 4, B/C/D = 16, E = 256.
\r
146 * See the user manual for allowable combinations for input clock.
\r
148 void Chip_Clock_SetDivider(CHIP_CGU_IDIV_T Divider, CHIP_CGU_CLKIN_T Input, uint32_t Divisor);
\r
151 * @brief Gets a CGU clock divider source
\r
152 * @param Divider : CHIP_CGU_IDIV_T value indicating which divider to get the source of
\r
153 * @return CHIP_CGU_CLKIN_T indicating which clock source is set or CLOCKINPUT_PD
\r
155 CHIP_CGU_CLKIN_T Chip_Clock_GetDividerSource(CHIP_CGU_IDIV_T Divider);
\r
158 * @brief Gets a CGU clock divider divisor
\r
159 * @param Divider : CHIP_CGU_IDIV_T value indicating which divider to get the source of
\r
160 * @return the divider value for the divider
\r
162 uint32_t Chip_Clock_GetDividerDivisor(CHIP_CGU_IDIV_T Divider);
\r
165 * @brief Returns the frequency of the specified input clock source
\r
166 * @param input : Which clock input to return the frequency of
\r
167 * @return Frequency of input source in Hz
\r
168 * This function returns an ideal frequency and not the actual frequency. Returns
\r
169 * zero if the clock source is disabled.
\r
171 uint32_t Chip_Clock_GetClockInputHz(CHIP_CGU_CLKIN_T input);
\r
174 * @brief Returns the frequency of the specified base clock source
\r
175 * @param clock : which base clock to return the frequency of.
\r
176 * @return Frequency of base source in Hz
\r
177 * This function returns an ideal frequency and not the actual frequency. Returns
\r
178 * zero if the clock source is disabled.
\r
180 uint32_t Chip_Clock_GetBaseClocktHz(CHIP_CGU_BASE_CLK_T clock);
\r
183 * @brief Sets a CGU Base Clock clock source
\r
184 * @param BaseClock : CHIP_CGU_BASE_CLK_T value indicating which base clock to set
\r
185 * @param Input : CHIP_CGU_CLKIN_T value indicating which clock source to use or CLOCKINPUT_PD to power down base clock
\r
186 * @param autoblocken : Enables autoblocking during frequency change if true
\r
187 * @param powerdn : The clock base is setup, but powered down if true
\r
190 void Chip_Clock_SetBaseClock(CHIP_CGU_BASE_CLK_T BaseClock, CHIP_CGU_CLKIN_T Input, bool autoblocken, bool powerdn);
\r
193 * @brief Get CGU Base Clock clock source information
\r
194 * @param BaseClock : CHIP_CGU_BASE_CLK_T value indicating which base clock to get
\r
195 * @param Input : Pointer to CHIP_CGU_CLKIN_T value of the base clock
\r
196 * @param autoblocken : Pointer to autoblocking value of the base clock
\r
197 * @param powerdn : Pointer to power down flag
\r
200 void Chip_Clock_GetBaseClockOpts(CHIP_CGU_BASE_CLK_T BaseClock, CHIP_CGU_CLKIN_T *Input, bool *autoblocken,
\r
204 * @brief Gets a CGU Base Clock clock source
\r
205 * @param BaseClock : CHIP_CGU_BASE_CLK_T value indicating which base clock to get inpuot clock for
\r
206 * @return CHIP_CGU_CLKIN_T indicating which clock source is set or CLOCKINPUT_PD
\r
208 CHIP_CGU_CLKIN_T Chip_Clock_GetBaseClock(CHIP_CGU_BASE_CLK_T BaseClock);
\r
211 * @brief Enables a base clock source
\r
212 * @param BaseClock : CHIP_CGU_BASE_CLK_T value indicating which base clock to enable
\r
215 void Chip_Clock_EnableBaseClock(CHIP_CGU_BASE_CLK_T BaseClock);
\r
218 * @brief Disables a base clock source
\r
219 * @param BaseClock : CHIP_CGU_BASE_CLK_T value indicating which base clock to disable
\r
222 void Chip_Clock_DisableBaseClock(CHIP_CGU_BASE_CLK_T BaseClock);
\r
225 * @brief Returns base clock enable state
\r
226 * @param BaseClock : CHIP_CGU_BASE_CLK_T value indicating which base clock to check
\r
227 * @return true if the base clock is enabled, false if disabled
\r
229 bool Chip_Clock_IsBaseClockEnabled(CHIP_CGU_BASE_CLK_T BaseClock);
\r
232 * @brief Enables a peripheral clock and sets clock states
\r
233 * @param clk : CHIP_CCU_CLK_T value indicating which clock to enable
\r
234 * @param autoen : true to enable autoblocking on a clock rate change, false to disable
\r
235 * @param wakeupen : true to enable wakeup mechanism, false to disable
\r
236 * @param div : Divider for the clock, must be 1 for most clocks, 2 supported on others
\r
239 void Chip_Clock_EnableOpts(CHIP_CCU_CLK_T clk, bool autoen, bool wakeupen, int div);
\r
242 * @brief Enables a peripheral clock
\r
243 * @param clk : CHIP_CCU_CLK_T value indicating which clock to enable
\r
246 void Chip_Clock_Enable(CHIP_CCU_CLK_T clk);
\r
249 * @brief Disables a peripheral clock
\r
250 * @param clk : CHIP_CCU_CLK_T value indicating which clock to disable
\r
253 void Chip_Clock_Disable(CHIP_CCU_CLK_T clk);
\r
256 * @brief Returns a peripheral clock rate
\r
257 * @param clk : CHIP_CCU_CLK_T value indicating which clock to get rate for
\r
258 * @return 0 if the clock is disabled, or the rate of the clock
\r
260 uint32_t Chip_Clock_GetRate(CHIP_CCU_CLK_T clk);
\r
263 * @brief Start the power down sequence by disabling the branch output
\r
264 * clocks with wake up mechanism (Only the clocks which
\r
265 * wake up mechanism bit enabled will be disabled)
\r
268 void Chip_Clock_StartPowerDown(void);
\r
271 * @brief Clear the power down mode bit & proceed normal operation of branch output
\r
272 * clocks (Only the clocks which wake up mechanism bit enabled will be
\r
273 * enabled after the wake up event)
\r
276 void Chip_Clock_ClearPowerDown(void);
\r
279 * Structure for setting up the USB or audio PLL
\r
282 uint32_t ctrl; /* Default control word for PLL */
\r
283 uint32_t mdiv; /* Default M-divider value for PLL */
\r
284 uint32_t ndiv; /* Default NP-divider value for PLL */
\r
285 uint32_t fract; /* Default fractional value for audio PLL only */
\r
286 } CGU_USBAUDIO_PLL_SETUP_T;
\r
289 * @brief Sets up the audio or USB PLL
\r
290 * @param Input : Input clock
\r
291 * @param pllnum : PLL identifier
\r
292 * @param pPLLSetup : Pointer to PLL setup structure
\r
294 * Sets up the PLL with the passed structure values.
\r
296 void Chip_Clock_SetupPLL(CHIP_CGU_CLKIN_T Input, CHIP_CGU_USB_AUDIO_PLL_T pllnum,
\r
297 const CGU_USBAUDIO_PLL_SETUP_T *pPLLSetup);
\r
300 * @brief Enables the audio or USB PLL
\r
301 * @param pllnum : PLL identifier
\r
304 void Chip_Clock_EnablePLL(CHIP_CGU_USB_AUDIO_PLL_T pllnum);
\r
307 * @brief Disables the audio or USB PLL
\r
308 * @param pllnum : PLL identifier
\r
311 void Chip_Clock_DisablePLL(CHIP_CGU_USB_AUDIO_PLL_T pllnum);
\r
313 #define CGU_PLL_LOCKED (1 << 0) /* PLL locked status */
\r
314 #define CGU_PLL_FR (1 << 1) /* PLL free running indicator status */
\r
317 * @brief Returns the PLL status
\r
318 * @param pllnum : PLL identifier
\r
319 * @return An OR'ed value of CGU_PLL_LOCKED or CGU_PLL_FR
\r
321 uint32_t Chip_Clock_GetPLLStatus(CHIP_CGU_USB_AUDIO_PLL_T pllnum);
\r
331 #endif /* __CLOCK_18XX_43XX_H_ */
\r