LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clock_13xx.h
Go to the documentation of this file.
1 /*
2  * @brief LPC13XX 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_13XX_H_
33 #define __CLOCK_13XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
58 #define SYSCTL_IRC_FREQ (12000000)
59 
67 STATIC INLINE void Chip_Clock_SetupSystemPLL(uint8_t msel, uint8_t psel)
68 {
69  LPC_SYSCTL->SYSPLLCTRL = (msel & 0x1F) | ((psel & 0x3) << 5);
70 }
71 
77 {
78  return (bool) ((LPC_SYSCTL->SYSPLLSTAT & 1) != 0);
79 }
80 
84 typedef enum CHIP_SYSCTL_PLLCLKSRC {
90 
99 
107 STATIC INLINE void Chip_Clock_SetupUSBPLL(uint8_t msel, uint8_t psel)
108 {
109  LPC_SYSCTL->USBPLLCTRL = (msel & 0x1F) | ((psel & 0x3) << 5);
110 }
111 
117 {
118  return (bool) ((LPC_SYSCTL->USBPLLSTAT & 1) != 0);
119 }
120 
129 
139 void Chip_Clock_SetPLLBypass(bool bypass, bool highfr);
140 
144 typedef enum CHIP_WDTLFO_OSC {
162 
171 {
172  LPC_SYSCTL->WDTOSCCTRL = (((uint32_t) wdtclk) << 5) | ((div >> 1) - 1);
173 }
174 
178 typedef enum CHIP_SYSCTL_MAINCLKSRC{
184 
193 
199 {
200  return (CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL);
201 }
202 
211 {
212  LPC_SYSCTL->SYSAHBCLKDIV = div;
213 }
214 
218 typedef enum CHIP_SYSCTL_CLOCK{
238 #if defined(CHIP_LPC1347)
246  SYSCTL_CLOCK_RAM1,
247  SYSCTL_CLOCK_USBRAM,
248 #endif
250 
257 {
258  LPC_SYSCTL->SYSAHBCLKCTRL |= (1 << clk);
259 }
260 
267 {
268  LPC_SYSCTL->SYSAHBCLKCTRL &= ~(1 << clk);
269 }
270 
279 {
280  LPC_SYSCTL->SSP0CLKDIV = div;
281 }
282 
289 {
290  return LPC_SYSCTL->SSP0CLKDIV;
291 }
292 
303 {
304  LPC_SYSCTL->USARTCLKDIV = div;
305 }
306 
313 {
314  return LPC_SYSCTL->USARTCLKDIV;
315 }
316 
325 {
326  LPC_SYSCTL->SSP1CLKDIV = div;
327 }
328 
335 {
336  return LPC_SYSCTL->SSP1CLKDIV;
337 }
338 
347 {
348  LPC_SYSCTL->TRACECLKDIV = div;
349 }
350 
357 {
358  return LPC_SYSCTL->TRACECLKDIV;
359 }
360 
369 {
370  LPC_SYSCTL->SYSTICKCLKDIV = div;
371 }
372 
379 {
380  return LPC_SYSCTL->SYSTICKCLKDIV;
381 }
382 
386 typedef enum CHIP_SYSCTL_USBCLKSRC{
390 
402 
403 #if defined(CHIP_LPC1343)
404 
407 typedef enum CHIP_SYSCTL_WDTCLKSRC{
408  SYSCTL_WDTCLKSRC_IRC = 0,
409  SYSCTL_WDTCLKSRC_MAINSYSCLK,
410  SYSCTL_WDTCLKSRC_WDTOSC,
411 } CHIP_SYSCTL_WDTCLKSRC_T;
412 
423 void Chip_Clock_SetWDTClockSource(CHIP_SYSCTL_WDTCLKSRC_T src, uint32_t div);
424 
425 #endif
426 
430 typedef enum CHIP_SYSCTL_CLKOUTSRC{
436 
448 
454 {
455  return CRYSTAL_MAIN_FREQ_IN;
456 }
457 
463 {
464  return SYSCTL_IRC_FREQ;
465 }
466 
473 
479 
485 
491 
497 
503 
509 
514 #ifdef __cplusplus
515 }
516 #endif
517 
518 #endif /* __CLOCK_13XX_H_ */