CMSIS2000  0.0.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc2xxx_pllclk.h
Go to the documentation of this file.
1 /*
2  * CMSIS2000
3  * CMSIS-like sources for LPC2xxx series MCUs
4  *
5  * (C) Copyright 2011-2012, Dmitriy Cherepanov, All Rights Reserved
6  *
7  * Version: 0.0.7
8  * Date of the Last Update: 2013-03-04
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to
12  * deal in the Software without restriction, including without limitation the
13  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14  * sell copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  * IN THE SOFTWARE.
27  *
28  * Do not be lasy! For the latest version see http://irtos.sourceforge.net .
29  *
30  *
31 #*/
32 
33 #ifndef _PORT_LPC2XXX_PLLCLK_H_
34 #define _PORT_LPC2XXX_PLLCLK_H_ 1
35 /*-----------Документация Doxygen -- Doxygen documentation -----------------*/
36 /** \file
37  *\if russian_lng
38  * Определения для схемы PLL NXP LPC2xxx
39  *\else
40  * Definitions for NXP LPC2xxx PLL module
41  *\endif
42  * \ingroup LPC2xxx_System_periphiral
43  * \addtogroup LPC2xxx_System_periphiral
44  * @{
45  */
46 #if _HASBSPBRD > 0
47 #include "bsp_board_def.h"/* board /definitions if you do not have this file then create it with '#include "mcu_id.h"' line*/
48 #else
49  #include "mcu_id.h"
50 #endif
51 /*--------- Define clock sourses ---------------------------------------------*/
52 #ifndef IRC_OSC_HZ
53  #define IRC_OSC_HZ (4000000UL)/* Internal RC oscillator frequency*/
54 #endif
55 #ifndef RTC_CLK_HZ
56  #define RTC_CLK_HZ (32768U)/* external RTC oscillator frequency*/
57 #endif
58 #define CLKSRCSEL_IRC 0 /**< 00 Selects the Internal RC oscillator as the PLL clock source (default).*/
59 #define CLKSRCSEL_XTAL 1/**< 01 Selects the main oscillator as the PLL clock source.*/
60 #define CLKSRCSEL_RTC 2/**< 10 Selects the RTC oscillator as the PLL clock source.*/
61 
62 #ifndef CLKSRCSEL_Val
63  #define CLKSRCSEL_Val CLKSRCSEL_XTAL /* by default enablin external OSC*/
64  #warning "by default internal oscillator is used IRC please define CLKSRCSEL_Val"
65 #endif
66 
67 #define CLKSRCSEL_Val_0 IRC_OSC_HZ
68 #define CLKSRCSEL_Val_1 XTAL_HZ
69 #define CLKSRCSEL_Val_2 RTC_CLK_HZ
70 
71 #define CLKSRCSEL_concat2(a,b) a##b
72 #define CLKSRCSEL_concat(a,b) CLKSRCSEL_concat2(CLKSRCSEL_Val_,b)
73  /**\def F_OSC_HZ
74  there is three clock soursec in lpc2xxx
75  and table here describe sourses and frequency constants.
76  CLKSRCSEL_IRC 0 IRC_OSC_HZ will be select as osc source
77  CLKSRCSEL_XTAL 1 XTAL_HZ will be select as osc source
78  CLKSRCSEL_RTC 2 RTC_CLK_HZ will be select as osc source
79 
80  \code
81  use on of the folowing definitions
82 
83  #define CLKSRCSEL_Val CLKSRCSEL_IRC
84  #define CLKSRCSEL_Val CLKSRCSEL_XTAL
85  #define CLKSRCSEL_Val CLKSRCSEL_RTC
86  \endcode
87  */
88 #define F_OSC_HZ CLKSRCSEL_concat(,CLKSRCSEL_Val)
89 /*----- PLL_MValue PLL_PValue PLL_NValue F_OSC_HZ must defined before -------*/
90 #ifndef F_OSC_HZ
91  #error "please define source of frequency (F_OSC_HZ) by CLKSRCSEL_Val!!! may be you should do it in bsp_board_def.h or -DCLKSRCSEL_Val=IRC_OSC_HZ"
92 #endif
93 #ifndef PLL_MValue
94  #error "please define PLL_MValue -- value to PLLCFG!!!"
95 #endif
96 /*------ МАКРОСЫ И ОПРЕДЕЛЕНИЯ - MACROSES ------------------------------------*/
97 /** \brief Defenitions for Phased Lock Loop (PLL)
98 
99 - FOR LPC 23xx 24xx
100  - FOSC(FIN) is in the range of 32 kHz to 50 MHz.
101  - FCCO is in the range of 275 MHz to 550 MHz.
102 - FOR LPC 21xx 22xx
103  - FOSC is in the range of 10 MHz to 25 MHz.
104  - CCLK is in the range of 10 MHz to Fmax (the maximum allowed frequency for the
105 microcontroller - determined by the system microcontroller is embedded in).
106  - FCCO is in the range of 156 MHz to 320 MHz.
107 */
108 #ifdef PLL_NValue
109  #define F_CCO_HZ (2 * (PLL_MValue + 1) * F_OSC_HZ)/(PLL_NValue + 1)
110  #define F_CCLK_HZ (F_CCO_HZ/(CCLKCFG_Val + 1))
111  #define F_USBCLK_HZ (F_CCO_HZ/(USBCLKCFG_Val + 1))
112 
113  #if (F_CCO_HZ > 550000000UL)
114  #error "F_CCO_HZ is to hight"
115  #endif
116  #if (F_CCO_HZ < 275000000UL)
117  /*#error "F_CCO_HZ is to low"
118  #error F_CCO_HZ*/
119  #endif
120 
121 #else
122  #define F_CCLK_HZ ((PLL_MValue + 1) * F_OSC_HZ)
123  #define F_CCO_HZ (2 * (1 << PLL_PValue) * F_CCLK_HZ)
124 
125  #if (F_CCO_HZ > 320000000UL)
126  #error "F_CCO_HZ is to hight"
127  #endif
128  #if (F_CCO_HZ < 156000000UL)
129  #error "F_CCO_HZ is to low"
130  #endif
131 #endif
132 #ifdef USBCLKCFG_Val
133  #if ((F_USBCLK_HZ % 48000000) != 0)
134  #warning F_USBCLK_HZ is not devided by 48000000
135  #endif
136 #endif
137 
138 /** @} end of group LPC2xxx_System_periphiral */
139 #endif /* _PORT_LPC2XXX_PLLCLK_H_ */