LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clock_11xx.h
Go to the documentation of this file.
1 /*
2  * @brief LPC11XX Clock control functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __CLOCK_11XX_H_
33 #define __CLOCK_11XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
62 #define SYSCTL_IRC_FREQ (12000000)
63 
71 STATIC INLINE void Chip_Clock_SetupSystemPLL(uint8_t msel, uint8_t psel)
72 {
73  LPC_SYSCTL->SYSPLLCTRL = (msel & 0x1F) | ((psel & 0x3) << 5);
74 }
75 
81 {
82  return (bool) ((LPC_SYSCTL->SYSPLLSTAT & 1) != 0);
83 }
84 
88 typedef enum CHIP_SYSCTL_PLLCLKSRC {
91 #if defined(CHIP_LPC11AXX)
93 #else
95 #endif
98 
107 
108 #if defined(CHIP_LPC11UXX)
109 
116 STATIC INLINE void Chip_Clock_SetupUSBPLL(uint8_t msel, uint8_t psel)
117 {
118  LPC_SYSCTL->USBPLLCTRL = (msel & 0x1F) | ((psel & 0x3) << 5);
119 }
120 
126 {
127  return (bool) ((LPC_SYSCTL->USBPLLSTAT & 1) != 0);
128 }
129 
138 
139 #endif /*defined(CHIP_LPC11UXX)*/
140 
150 void Chip_Clock_SetPLLBypass(bool bypass, bool highfr);
151 
155 typedef enum CHIP_WDTLFO_OSC {
173 
182 {
183  LPC_SYSCTL->WDTOSCCTRL = (((uint32_t) wdtclk) << 5) | ((div >> 1) - 1);
184 }
185 
186 #if defined(CHIP_LPC11AXX)
187 
194 STATIC INLINE void Chip_Clock_SetLFOSC(CHIP_WDTLFO_OSC_T lfoclk, uint8_t div)
195 {
196  LPC_SYSCTL->LFOSCCTRL = (((uint32_t) lfoclk) << 5) | ((div >> 1) - 1);
197 }
198 
199 #endif /*CHIP_LPC11AXX*/
200 
204 typedef enum CHIP_SYSCTL_MAINCLKSRC {
211 
220 
226 {
227  return (CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL);
228 }
229 
238 {
239  LPC_SYSCTL->SYSAHBCLKDIV = div;
240 }
241 
245 typedef enum CHIP_SYSCTL_CLOCK {
251 #if defined(CHIP_LPC110X)
252  SYSCTL_CLOCK_RESERVED5,
253 #else
255 #endif
264 #if defined(CHIP_LPC11UXX)
266 #else
268 #endif
271 #if defined(CHIP_LPC11CXX)
272  SYSCTL_CLOCK_CAN,
273 #else
275 #endif
276 #if !(defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV))
278 #if !defined(CHIP_LPC11CXX)
280 #if defined(CHIP_LPC11AXX)
282  SYSCTL_CLOCK_DAC,
283 #else
286 #endif
293 #if defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX)
294  SYSCTL_CLOCK_RAM1,
295 #else
297 #endif
298 #if defined(CHIP_LPC11UXX)
299  SYSCTL_CLOCK_USBRAM,
300 #else
302 #endif
303 #endif /* !defined(CHIP_LPC11CXX) */
304 #endif /* !(defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV)) */
306 
313 {
314  LPC_SYSCTL->SYSAHBCLKCTRL |= (1 << clk);
315 }
316 
323 {
324  LPC_SYSCTL->SYSAHBCLKCTRL &= ~(1 << clk);
325 }
326 
335 {
336  LPC_SYSCTL->SSP0CLKDIV = div;
337 }
338 
345 {
346  return LPC_SYSCTL->SSP0CLKDIV;
347 }
348 
357 {
358  LPC_SYSCTL->USARTCLKDIV = div;
359 }
360 
367 {
368  return LPC_SYSCTL->USARTCLKDIV;
369 }
370 
371 #if defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) || defined(CHIP_LPC11UXX)
372 
380 {
381  LPC_SYSCTL->SSP1CLKDIV = div;
382 }
383 
390 {
391  return LPC_SYSCTL->SSP1CLKDIV;
392 }
393 
394 #endif /*defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) || defined(CHIP_LPC11UXX)*/
395 
396 #if defined(CHIP_LPC11UXX)
397 
400 typedef enum CHIP_SYSCTL_USBCLKSRC{
404 
416 
417 #endif /*CHIP_LPC11UXX*/
418 
419 #if defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX)
420 
423 typedef enum CHIP_SYSCTL_WDTCLKSRC{
424  SYSCTL_WDTCLKSRC_IRC = 0,
425  SYSCTL_WDTCLKSRC_MAINSYSCLK,
426  SYSCTL_WDTCLKSRC_WDTOSC,
427 } CHIP_SYSCTL_WDTCLKSRC_T;
428 
439 void Chip_Clock_SetWDTClockSource(CHIP_SYSCTL_WDTCLKSRC_T src, uint32_t div);
440 
441 #endif
442 
443 #if !defined(CHIP_LPC110X)
444 
447 typedef enum CHIP_SYSCTL_CLKOUTSRC{
454 
466 
467 #endif
468 
474 {
475  return CRYSTAL_MAIN_FREQ_IN;
476 }
477 
483 {
484  return SYSCTL_IRC_FREQ;
485 }
486 
487 #if defined(CHIP_LPC11AXX)
488 
494 {
495  return EXTCLKIN_FREQ_IN;
496 }
497 
498 #endif
499 
506 
507 #if defined(CHIP_LPC11AXX)
508 
513 uint32_t Chip_Clock_GetLFOOSCRate(void);
514 
515 #endif
516 
522 
528 
529 #if defined(CHIP_LPC11UXX)
530 
535 
541 
542 #endif
543 
549 
555 
560 #ifdef __cplusplus
561 }
562 #endif
563 
564 #endif /* __CLOCK_11XX_H_ */