![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
n
Fork of LG by
system_LPC17xx.c@12:74bd0ecf7f83, 2016-02-02 (annotated)
- Committer:
- igor_v
- Date:
- Tue Feb 02 14:42:57 2016 +0000
- Revision:
- 12:74bd0ecf7f83
- Parent:
- 2:2d0b80ed9216
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 2:2d0b80ed9216 | 1 | /**************************************************************************//** |
igor_v | 2:2d0b80ed9216 | 2 | * @file system_LPC17xx.c |
igor_v | 2:2d0b80ed9216 | 3 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer Source File |
igor_v | 2:2d0b80ed9216 | 4 | * for the NXP LPC17xx Device Series |
igor_v | 2:2d0b80ed9216 | 5 | * @version V1.03 |
igor_v | 2:2d0b80ed9216 | 6 | * @date 07. October 2009 |
igor_v | 2:2d0b80ed9216 | 7 | * |
igor_v | 2:2d0b80ed9216 | 8 | * @note |
igor_v | 2:2d0b80ed9216 | 9 | * Copyright (C) 2009 ARM Limited. All rights reserved. |
igor_v | 2:2d0b80ed9216 | 10 | * |
igor_v | 2:2d0b80ed9216 | 11 | * @par |
igor_v | 2:2d0b80ed9216 | 12 | * ARM Limited (ARM) is supplying this software for use with Cortex-M |
igor_v | 2:2d0b80ed9216 | 13 | * processor based microcontrollers. This file can be freely distributed |
igor_v | 2:2d0b80ed9216 | 14 | * within development tools that are supporting such ARM based processors. |
igor_v | 2:2d0b80ed9216 | 15 | * |
igor_v | 2:2d0b80ed9216 | 16 | * @par |
igor_v | 2:2d0b80ed9216 | 17 | * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED |
igor_v | 2:2d0b80ed9216 | 18 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
igor_v | 2:2d0b80ed9216 | 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. |
igor_v | 2:2d0b80ed9216 | 20 | * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR |
igor_v | 2:2d0b80ed9216 | 21 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
igor_v | 2:2d0b80ed9216 | 22 | * |
igor_v | 2:2d0b80ed9216 | 23 | ******************************************************************************/ |
igor_v | 2:2d0b80ed9216 | 24 | |
igor_v | 2:2d0b80ed9216 | 25 | |
igor_v | 2:2d0b80ed9216 | 26 | #include <stdint.h> |
igor_v | 2:2d0b80ed9216 | 27 | #include "LPC17xx.h" |
igor_v | 2:2d0b80ed9216 | 28 | |
igor_v | 2:2d0b80ed9216 | 29 | /* |
igor_v | 2:2d0b80ed9216 | 30 | //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------ |
igor_v | 2:2d0b80ed9216 | 31 | */ |
igor_v | 2:2d0b80ed9216 | 32 | |
igor_v | 2:2d0b80ed9216 | 33 | /*--------------------- Clock Configuration ---------------------------------- |
igor_v | 2:2d0b80ed9216 | 34 | // |
igor_v | 2:2d0b80ed9216 | 35 | // <e> Clock Configuration |
igor_v | 2:2d0b80ed9216 | 36 | // <h> System Controls and Status Register (SCS) |
igor_v | 2:2d0b80ed9216 | 37 | // <o1.4> OSCRANGE: Main Oscillator Range Select |
igor_v | 2:2d0b80ed9216 | 38 | // <0=> 1 MHz to 20 MHz |
igor_v | 2:2d0b80ed9216 | 39 | // <1=> 15 MHz to 24 MHz |
igor_v | 2:2d0b80ed9216 | 40 | // <e1.5> OSCEN: Main Oscillator Enable |
igor_v | 2:2d0b80ed9216 | 41 | // </e> |
igor_v | 2:2d0b80ed9216 | 42 | // </h> |
igor_v | 2:2d0b80ed9216 | 43 | // |
igor_v | 2:2d0b80ed9216 | 44 | // <h> Clock Source Select Register (CLKSRCSEL) |
igor_v | 2:2d0b80ed9216 | 45 | // <o2.0..1> CLKSRC: PLL Clock Source Selection |
igor_v | 2:2d0b80ed9216 | 46 | // <0=> Internal RC oscillator |
igor_v | 2:2d0b80ed9216 | 47 | // <1=> Main oscillator |
igor_v | 2:2d0b80ed9216 | 48 | // <2=> RTC oscillator |
igor_v | 2:2d0b80ed9216 | 49 | // </h> |
igor_v | 2:2d0b80ed9216 | 50 | // |
igor_v | 2:2d0b80ed9216 | 51 | // <e3> PLL0 Configuration (Main PLL) |
igor_v | 2:2d0b80ed9216 | 52 | // <h> PLL0 Configuration Register (PLL0CFG) |
igor_v | 2:2d0b80ed9216 | 53 | // <i> F_cco0 = (2 * M * F_in) / N |
igor_v | 2:2d0b80ed9216 | 54 | // <i> F_in must be in the range of 32 kHz to 50 MHz |
igor_v | 2:2d0b80ed9216 | 55 | // <i> F_cco0 must be in the range of 275 MHz to 550 MHz |
igor_v | 2:2d0b80ed9216 | 56 | // <o4.0..14> MSEL: PLL Multiplier Selection |
igor_v | 2:2d0b80ed9216 | 57 | // <6-32768><#-1> |
igor_v | 2:2d0b80ed9216 | 58 | // <i> M Value |
igor_v | 2:2d0b80ed9216 | 59 | // <o4.16..23> NSEL: PLL Divider Selection |
igor_v | 2:2d0b80ed9216 | 60 | // <1-256><#-1> |
igor_v | 2:2d0b80ed9216 | 61 | // <i> N Value |
igor_v | 2:2d0b80ed9216 | 62 | // </h> |
igor_v | 2:2d0b80ed9216 | 63 | // </e> |
igor_v | 2:2d0b80ed9216 | 64 | // |
igor_v | 2:2d0b80ed9216 | 65 | // <e5> PLL1 Configuration (USB PLL) |
igor_v | 2:2d0b80ed9216 | 66 | // <h> PLL1 Configuration Register (PLL1CFG) |
igor_v | 2:2d0b80ed9216 | 67 | // <i> F_usb = M * F_osc or F_usb = F_cco1 / (2 * P) |
igor_v | 2:2d0b80ed9216 | 68 | // <i> F_cco1 = F_osc * M * 2 * P |
igor_v | 2:2d0b80ed9216 | 69 | // <i> F_cco1 must be in the range of 156 MHz to 320 MHz |
igor_v | 2:2d0b80ed9216 | 70 | // <o6.0..4> MSEL: PLL Multiplier Selection |
igor_v | 2:2d0b80ed9216 | 71 | // <1-32><#-1> |
igor_v | 2:2d0b80ed9216 | 72 | // <i> M Value (for USB maximum value is 4) |
igor_v | 2:2d0b80ed9216 | 73 | // <o6.5..6> PSEL: PLL Divider Selection |
igor_v | 2:2d0b80ed9216 | 74 | // <0=> 1 |
igor_v | 2:2d0b80ed9216 | 75 | // <1=> 2 |
igor_v | 2:2d0b80ed9216 | 76 | // <2=> 4 |
igor_v | 2:2d0b80ed9216 | 77 | // <3=> 8 |
igor_v | 2:2d0b80ed9216 | 78 | // <i> P Value |
igor_v | 2:2d0b80ed9216 | 79 | // </h> |
igor_v | 2:2d0b80ed9216 | 80 | // </e> |
igor_v | 2:2d0b80ed9216 | 81 | // |
igor_v | 2:2d0b80ed9216 | 82 | // <h> CPU Clock Configuration Register (CCLKCFG) |
igor_v | 2:2d0b80ed9216 | 83 | // <o7.0..7> CCLKSEL: Divide Value for CPU Clock from PLL0 |
igor_v | 2:2d0b80ed9216 | 84 | // <3-256><#-1> |
igor_v | 2:2d0b80ed9216 | 85 | // </h> |
igor_v | 2:2d0b80ed9216 | 86 | // |
igor_v | 2:2d0b80ed9216 | 87 | // <h> USB Clock Configuration Register (USBCLKCFG) |
igor_v | 2:2d0b80ed9216 | 88 | // <o8.0..3> USBSEL: Divide Value for USB Clock from PLL0 |
igor_v | 2:2d0b80ed9216 | 89 | // <0-15> |
igor_v | 2:2d0b80ed9216 | 90 | // <i> Divide is USBSEL + 1 |
igor_v | 2:2d0b80ed9216 | 91 | // </h> |
igor_v | 2:2d0b80ed9216 | 92 | // |
igor_v | 2:2d0b80ed9216 | 93 | // <h> Peripheral Clock Selection Register 0 (PCLKSEL0) |
igor_v | 2:2d0b80ed9216 | 94 | // <o9.0..1> PCLK_WDT: Peripheral Clock Selection for WDT |
igor_v | 2:2d0b80ed9216 | 95 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 96 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 97 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 98 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 99 | // <o9.2..3> PCLK_TIMER0: Peripheral Clock Selection for TIMER0 |
igor_v | 2:2d0b80ed9216 | 100 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 101 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 102 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 103 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 104 | // <o9.4..5> PCLK_TIMER1: Peripheral Clock Selection for TIMER1 |
igor_v | 2:2d0b80ed9216 | 105 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 106 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 107 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 108 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 109 | // <o9.6..7> PCLK_UART0: Peripheral Clock Selection for UART0 |
igor_v | 2:2d0b80ed9216 | 110 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 111 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 112 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 113 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 114 | // <o9.8..9> PCLK_UART1: Peripheral Clock Selection for UART1 |
igor_v | 2:2d0b80ed9216 | 115 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 116 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 117 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 118 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 119 | // <o9.12..13> PCLK_PWM1: Peripheral Clock Selection for PWM1 |
igor_v | 2:2d0b80ed9216 | 120 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 121 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 122 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 123 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 124 | // <o9.14..15> PCLK_I2C0: Peripheral Clock Selection for I2C0 |
igor_v | 2:2d0b80ed9216 | 125 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 126 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 127 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 128 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 129 | // <o9.16..17> PCLK_SPI: Peripheral Clock Selection for SPI |
igor_v | 2:2d0b80ed9216 | 130 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 131 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 132 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 133 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 134 | // <o9.20..21> PCLK_SSP1: Peripheral Clock Selection for SSP1 |
igor_v | 2:2d0b80ed9216 | 135 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 136 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 137 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 138 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 139 | // <o9.22..23> PCLK_DAC: Peripheral Clock Selection for DAC |
igor_v | 2:2d0b80ed9216 | 140 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 141 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 142 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 143 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 144 | // <o9.24..25> PCLK_ADC: Peripheral Clock Selection for ADC |
igor_v | 2:2d0b80ed9216 | 145 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 146 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 147 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 148 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 149 | // <o9.26..27> PCLK_CAN1: Peripheral Clock Selection for CAN1 |
igor_v | 2:2d0b80ed9216 | 150 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 151 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 152 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 153 | // <3=> Pclk = Hclk / 6 |
igor_v | 2:2d0b80ed9216 | 154 | // <o9.28..29> PCLK_CAN2: Peripheral Clock Selection for CAN2 |
igor_v | 2:2d0b80ed9216 | 155 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 156 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 157 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 158 | // <3=> Pclk = Hclk / 6 |
igor_v | 2:2d0b80ed9216 | 159 | // <o9.30..31> PCLK_ACF: Peripheral Clock Selection for ACF |
igor_v | 2:2d0b80ed9216 | 160 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 161 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 162 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 163 | // <3=> Pclk = Hclk / 6 |
igor_v | 2:2d0b80ed9216 | 164 | // </h> |
igor_v | 2:2d0b80ed9216 | 165 | // |
igor_v | 2:2d0b80ed9216 | 166 | // <h> Peripheral Clock Selection Register 1 (PCLKSEL1) |
igor_v | 2:2d0b80ed9216 | 167 | // <o10.0..1> PCLK_QEI: Peripheral Clock Selection for the Quadrature Encoder Interface |
igor_v | 2:2d0b80ed9216 | 168 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 169 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 170 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 171 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 172 | // <o10.2..3> PCLK_GPIO: Peripheral Clock Selection for GPIOs |
igor_v | 2:2d0b80ed9216 | 173 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 174 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 175 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 176 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 177 | // <o10.4..5> PCLK_PCB: Peripheral Clock Selection for the Pin Connect Block |
igor_v | 2:2d0b80ed9216 | 178 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 179 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 180 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 181 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 182 | // <o10.6..7> PCLK_I2C1: Peripheral Clock Selection for I2C1 |
igor_v | 2:2d0b80ed9216 | 183 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 184 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 185 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 186 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 187 | // <o10.10..11> PCLK_SSP0: Peripheral Clock Selection for SSP0 |
igor_v | 2:2d0b80ed9216 | 188 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 189 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 190 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 191 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 192 | // <o10.12..13> PCLK_TIMER2: Peripheral Clock Selection for TIMER2 |
igor_v | 2:2d0b80ed9216 | 193 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 194 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 195 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 196 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 197 | // <o10.14..15> PCLK_TIMER3: Peripheral Clock Selection for TIMER3 |
igor_v | 2:2d0b80ed9216 | 198 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 199 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 200 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 201 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 202 | // <o10.16..17> PCLK_UART2: Peripheral Clock Selection for UART2 |
igor_v | 2:2d0b80ed9216 | 203 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 204 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 205 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 206 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 207 | // <o10.18..19> PCLK_UART3: Peripheral Clock Selection for UART3 |
igor_v | 2:2d0b80ed9216 | 208 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 209 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 210 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 211 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 212 | // <o10.20..21> PCLK_I2C2: Peripheral Clock Selection for I2C2 |
igor_v | 2:2d0b80ed9216 | 213 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 214 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 215 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 216 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 217 | // <o10.22..23> PCLK_I2S: Peripheral Clock Selection for I2S |
igor_v | 2:2d0b80ed9216 | 218 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 219 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 220 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 221 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 222 | // <o10.26..27> PCLK_RIT: Peripheral Clock Selection for the Repetitive Interrupt Timer |
igor_v | 2:2d0b80ed9216 | 223 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 224 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 225 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 226 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 227 | // <o10.28..29> PCLK_SYSCON: Peripheral Clock Selection for the System Control Block |
igor_v | 2:2d0b80ed9216 | 228 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 229 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 230 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 231 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 232 | // <o10.30..31> PCLK_MC: Peripheral Clock Selection for the Motor Control PWM |
igor_v | 2:2d0b80ed9216 | 233 | // <0=> Pclk = Cclk / 4 |
igor_v | 2:2d0b80ed9216 | 234 | // <1=> Pclk = Cclk |
igor_v | 2:2d0b80ed9216 | 235 | // <2=> Pclk = Cclk / 2 |
igor_v | 2:2d0b80ed9216 | 236 | // <3=> Pclk = Hclk / 8 |
igor_v | 2:2d0b80ed9216 | 237 | // </h> |
igor_v | 2:2d0b80ed9216 | 238 | // |
igor_v | 2:2d0b80ed9216 | 239 | // <h> Power Control for Peripherals Register (PCONP) |
igor_v | 2:2d0b80ed9216 | 240 | // <o11.1> PCTIM0: Timer/Counter 0 power/clock enable |
igor_v | 2:2d0b80ed9216 | 241 | // <o11.2> PCTIM1: Timer/Counter 1 power/clock enable |
igor_v | 2:2d0b80ed9216 | 242 | // <o11.3> PCUART0: UART 0 power/clock enable |
igor_v | 2:2d0b80ed9216 | 243 | // <o11.4> PCUART1: UART 1 power/clock enable |
igor_v | 2:2d0b80ed9216 | 244 | // <o11.6> PCPWM1: PWM 1 power/clock enable |
igor_v | 2:2d0b80ed9216 | 245 | // <o11.7> PCI2C0: I2C interface 0 power/clock enable |
igor_v | 2:2d0b80ed9216 | 246 | // <o11.8> PCSPI: SPI interface power/clock enable |
igor_v | 2:2d0b80ed9216 | 247 | // <o11.9> PCRTC: RTC power/clock enable |
igor_v | 2:2d0b80ed9216 | 248 | // <o11.10> PCSSP1: SSP interface 1 power/clock enable |
igor_v | 2:2d0b80ed9216 | 249 | // <o11.12> PCAD: A/D converter power/clock enable |
igor_v | 2:2d0b80ed9216 | 250 | // <o11.13> PCCAN1: CAN controller 1 power/clock enable |
igor_v | 2:2d0b80ed9216 | 251 | // <o11.14> PCCAN2: CAN controller 2 power/clock enable |
igor_v | 2:2d0b80ed9216 | 252 | // <o11.15> PCGPIO: GPIOs power/clock enable |
igor_v | 2:2d0b80ed9216 | 253 | // <o11.16> PCRIT: Repetitive interrupt timer power/clock enable |
igor_v | 2:2d0b80ed9216 | 254 | // <o11.17> PCMC: Motor control PWM power/clock enable |
igor_v | 2:2d0b80ed9216 | 255 | // <o11.18> PCQEI: Quadrature encoder interface power/clock enable |
igor_v | 2:2d0b80ed9216 | 256 | // <o11.19> PCI2C1: I2C interface 1 power/clock enable |
igor_v | 2:2d0b80ed9216 | 257 | // <o11.21> PCSSP0: SSP interface 0 power/clock enable |
igor_v | 2:2d0b80ed9216 | 258 | // <o11.22> PCTIM2: Timer 2 power/clock enable |
igor_v | 2:2d0b80ed9216 | 259 | // <o11.23> PCTIM3: Timer 3 power/clock enable |
igor_v | 2:2d0b80ed9216 | 260 | // <o11.24> PCUART2: UART 2 power/clock enable |
igor_v | 2:2d0b80ed9216 | 261 | // <o11.25> PCUART3: UART 3 power/clock enable |
igor_v | 2:2d0b80ed9216 | 262 | // <o11.26> PCI2C2: I2C interface 2 power/clock enable |
igor_v | 2:2d0b80ed9216 | 263 | // <o11.27> PCI2S: I2S interface power/clock enable |
igor_v | 2:2d0b80ed9216 | 264 | // <o11.29> PCGPDMA: GP DMA function power/clock enable |
igor_v | 2:2d0b80ed9216 | 265 | // <o11.30> PCENET: Ethernet block power/clock enable |
igor_v | 2:2d0b80ed9216 | 266 | // <o11.31> PCUSB: USB interface power/clock enable |
igor_v | 2:2d0b80ed9216 | 267 | // </h> |
igor_v | 2:2d0b80ed9216 | 268 | // |
igor_v | 2:2d0b80ed9216 | 269 | // <h> Clock Output Configuration Register (CLKOUTCFG) |
igor_v | 2:2d0b80ed9216 | 270 | // <o12.0..3> CLKOUTSEL: Selects clock source for CLKOUT |
igor_v | 2:2d0b80ed9216 | 271 | // <0=> CPU clock |
igor_v | 2:2d0b80ed9216 | 272 | // <1=> Main oscillator |
igor_v | 2:2d0b80ed9216 | 273 | // <2=> Internal RC oscillator |
igor_v | 2:2d0b80ed9216 | 274 | // <3=> USB clock |
igor_v | 2:2d0b80ed9216 | 275 | // <4=> RTC oscillator |
igor_v | 2:2d0b80ed9216 | 276 | // <o12.4..7> CLKOUTDIV: Selects clock divider for CLKOUT |
igor_v | 2:2d0b80ed9216 | 277 | // <1-16><#-1> |
igor_v | 2:2d0b80ed9216 | 278 | // <o12.8> CLKOUT_EN: CLKOUT enable control |
igor_v | 2:2d0b80ed9216 | 279 | // </h> |
igor_v | 2:2d0b80ed9216 | 280 | // |
igor_v | 2:2d0b80ed9216 | 281 | // </e> |
igor_v | 2:2d0b80ed9216 | 282 | */ |
igor_v | 2:2d0b80ed9216 | 283 | #define CLOCK_SETUP 1 |
igor_v | 2:2d0b80ed9216 | 284 | #define SCS_Val 0x00000020 |
igor_v | 2:2d0b80ed9216 | 285 | #define CLKSRCSEL_Val 0x00000001 |
igor_v | 2:2d0b80ed9216 | 286 | #define PLL0_SETUP 1 |
igor_v | 2:2d0b80ed9216 | 287 | #define PLL0CFG_Val 0x00050063 |
igor_v | 2:2d0b80ed9216 | 288 | #define PLL1_SETUP 1 |
igor_v | 2:2d0b80ed9216 | 289 | #define PLL1CFG_Val 0x00000023 |
igor_v | 2:2d0b80ed9216 | 290 | #define CCLKCFG_Val 0x00000003 |
igor_v | 2:2d0b80ed9216 | 291 | #define USBCLKCFG_Val 0x00000000 |
igor_v | 2:2d0b80ed9216 | 292 | #define PCLKSEL0_Val 0x00000010 |
igor_v | 2:2d0b80ed9216 | 293 | #define PCLKSEL1_Val 0x00000000 |
igor_v | 2:2d0b80ed9216 | 294 | #define PCONP_Val 0x046887DE |
igor_v | 2:2d0b80ed9216 | 295 | #define CLKOUTCFG_Val 0x00000000 |
igor_v | 2:2d0b80ed9216 | 296 | |
igor_v | 2:2d0b80ed9216 | 297 | |
igor_v | 2:2d0b80ed9216 | 298 | /*--------------------- Flash Accelerator Configuration ---------------------- |
igor_v | 2:2d0b80ed9216 | 299 | // |
igor_v | 2:2d0b80ed9216 | 300 | // <e> Flash Accelerator Configuration |
igor_v | 2:2d0b80ed9216 | 301 | // <o1.0..1> FETCHCFG: Fetch Configuration |
igor_v | 2:2d0b80ed9216 | 302 | // <0=> Instruction fetches from flash are not buffered |
igor_v | 2:2d0b80ed9216 | 303 | // <1=> One buffer is used for all instruction fetch buffering |
igor_v | 2:2d0b80ed9216 | 304 | // <2=> All buffers may be used for instruction fetch buffering |
igor_v | 2:2d0b80ed9216 | 305 | // <3=> Reserved (do not use this setting) |
igor_v | 2:2d0b80ed9216 | 306 | // <o1.2..3> DATACFG: Data Configuration |
igor_v | 2:2d0b80ed9216 | 307 | // <0=> Data accesses from flash are not buffered |
igor_v | 2:2d0b80ed9216 | 308 | // <1=> One buffer is used for all data access buffering |
igor_v | 2:2d0b80ed9216 | 309 | // <2=> All buffers may be used for data access buffering |
igor_v | 2:2d0b80ed9216 | 310 | // <3=> Reserved (do not use this setting) |
igor_v | 2:2d0b80ed9216 | 311 | // <o1.4> ACCEL: Acceleration Enable |
igor_v | 2:2d0b80ed9216 | 312 | // <o1.5> PREFEN: Prefetch Enable |
igor_v | 2:2d0b80ed9216 | 313 | // <o1.6> PREFOVR: Prefetch Override |
igor_v | 2:2d0b80ed9216 | 314 | // <o1.12..15> FLASHTIM: Flash Access Time |
igor_v | 2:2d0b80ed9216 | 315 | // <0=> 1 CPU clock (for CPU clock up to 20 MHz) |
igor_v | 2:2d0b80ed9216 | 316 | // <1=> 2 CPU clocks (for CPU clock up to 40 MHz) |
igor_v | 2:2d0b80ed9216 | 317 | // <2=> 3 CPU clocks (for CPU clock up to 60 MHz) |
igor_v | 2:2d0b80ed9216 | 318 | // <3=> 4 CPU clocks (for CPU clock up to 80 MHz) |
igor_v | 2:2d0b80ed9216 | 319 | // <4=> 5 CPU clocks (for CPU clock up to 100 MHz) |
igor_v | 2:2d0b80ed9216 | 320 | // <5=> 6 CPU clocks (for any CPU clock) |
igor_v | 2:2d0b80ed9216 | 321 | // </e> |
igor_v | 2:2d0b80ed9216 | 322 | */ |
igor_v | 2:2d0b80ed9216 | 323 | #define FLASH_SETUP 1 |
igor_v | 2:2d0b80ed9216 | 324 | #define FLASHCFG_Val 0x0000303A |
igor_v | 2:2d0b80ed9216 | 325 | |
igor_v | 2:2d0b80ed9216 | 326 | /* |
igor_v | 2:2d0b80ed9216 | 327 | //-------- <<< end of configuration section >>> ------------------------------ |
igor_v | 2:2d0b80ed9216 | 328 | */ |
igor_v | 2:2d0b80ed9216 | 329 | |
igor_v | 2:2d0b80ed9216 | 330 | /*---------------------------------------------------------------------------- |
igor_v | 2:2d0b80ed9216 | 331 | Check the register settings |
igor_v | 2:2d0b80ed9216 | 332 | *----------------------------------------------------------------------------*/ |
igor_v | 2:2d0b80ed9216 | 333 | #define CHECK_RANGE(val, min, max) ((val < min) || (val > max)) |
igor_v | 2:2d0b80ed9216 | 334 | #define CHECK_RSVD(val, mask) (val & mask) |
igor_v | 2:2d0b80ed9216 | 335 | |
igor_v | 2:2d0b80ed9216 | 336 | /* Clock Configuration -------------------------------------------------------*/ |
igor_v | 2:2d0b80ed9216 | 337 | #if (CHECK_RSVD((SCS_Val), ~0x00000030)) |
igor_v | 2:2d0b80ed9216 | 338 | #error "SCS: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 339 | #endif |
igor_v | 2:2d0b80ed9216 | 340 | |
igor_v | 2:2d0b80ed9216 | 341 | #if (CHECK_RANGE((CLKSRCSEL_Val), 0, 2)) |
igor_v | 2:2d0b80ed9216 | 342 | #error "CLKSRCSEL: Value out of range!" |
igor_v | 2:2d0b80ed9216 | 343 | #endif |
igor_v | 2:2d0b80ed9216 | 344 | |
igor_v | 2:2d0b80ed9216 | 345 | #if (CHECK_RSVD((PLL0CFG_Val), ~0x00FF7FFF)) |
igor_v | 2:2d0b80ed9216 | 346 | #error "PLL0CFG: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 347 | #endif |
igor_v | 2:2d0b80ed9216 | 348 | |
igor_v | 2:2d0b80ed9216 | 349 | #if (CHECK_RSVD((PLL1CFG_Val), ~0x0000007F)) |
igor_v | 2:2d0b80ed9216 | 350 | #error "PLL1CFG: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 351 | #endif |
igor_v | 2:2d0b80ed9216 | 352 | |
igor_v | 2:2d0b80ed9216 | 353 | #if ((CCLKCFG_Val != 0) && (((CCLKCFG_Val - 1) % 2))) |
igor_v | 2:2d0b80ed9216 | 354 | #error "CCLKCFG: CCLKSEL field does not contain only odd values or 0!" |
igor_v | 2:2d0b80ed9216 | 355 | #endif |
igor_v | 2:2d0b80ed9216 | 356 | |
igor_v | 2:2d0b80ed9216 | 357 | #if (CHECK_RSVD((USBCLKCFG_Val), ~0x0000000F)) |
igor_v | 2:2d0b80ed9216 | 358 | #error "USBCLKCFG: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 359 | #endif |
igor_v | 2:2d0b80ed9216 | 360 | |
igor_v | 2:2d0b80ed9216 | 361 | #if (CHECK_RSVD((PCLKSEL0_Val), 0x000C0C00)) |
igor_v | 2:2d0b80ed9216 | 362 | #error "PCLKSEL0: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 363 | #endif |
igor_v | 2:2d0b80ed9216 | 364 | |
igor_v | 2:2d0b80ed9216 | 365 | #if (CHECK_RSVD((PCLKSEL1_Val), 0x03000300)) |
igor_v | 2:2d0b80ed9216 | 366 | #error "PCLKSEL1: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 367 | #endif |
igor_v | 2:2d0b80ed9216 | 368 | |
igor_v | 2:2d0b80ed9216 | 369 | #if (CHECK_RSVD((PCONP_Val), 0x10100821)) |
igor_v | 2:2d0b80ed9216 | 370 | #error "PCONP: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 371 | #endif |
igor_v | 2:2d0b80ed9216 | 372 | |
igor_v | 2:2d0b80ed9216 | 373 | #if (CHECK_RSVD((CLKOUTCFG_Val), ~0x000001FF)) |
igor_v | 2:2d0b80ed9216 | 374 | #error "CLKOUTCFG: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 375 | #endif |
igor_v | 2:2d0b80ed9216 | 376 | |
igor_v | 2:2d0b80ed9216 | 377 | /* Flash Accelerator Configuration -------------------------------------------*/ |
igor_v | 2:2d0b80ed9216 | 378 | #if (CHECK_RSVD((FLASHCFG_Val), ~0x0000F07F)) |
igor_v | 2:2d0b80ed9216 | 379 | #error "FLASHCFG: Invalid values of reserved bits!" |
igor_v | 2:2d0b80ed9216 | 380 | #endif |
igor_v | 2:2d0b80ed9216 | 381 | |
igor_v | 2:2d0b80ed9216 | 382 | |
igor_v | 2:2d0b80ed9216 | 383 | /*---------------------------------------------------------------------------- |
igor_v | 2:2d0b80ed9216 | 384 | DEFINES |
igor_v | 2:2d0b80ed9216 | 385 | *----------------------------------------------------------------------------*/ |
igor_v | 2:2d0b80ed9216 | 386 | |
igor_v | 2:2d0b80ed9216 | 387 | /*---------------------------------------------------------------------------- |
igor_v | 2:2d0b80ed9216 | 388 | Define clocks |
igor_v | 2:2d0b80ed9216 | 389 | *----------------------------------------------------------------------------*/ |
igor_v | 2:2d0b80ed9216 | 390 | #define XTAL (12000000UL) /* Oscillator frequency */ |
igor_v | 2:2d0b80ed9216 | 391 | #define OSC_CLK ( XTAL) /* Main oscillator frequency */ |
igor_v | 2:2d0b80ed9216 | 392 | #define RTC_CLK ( 32000UL) /* RTC oscillator frequency */ |
igor_v | 2:2d0b80ed9216 | 393 | #define IRC_OSC ( 4000000UL) /* Internal RC oscillator frequency */ |
igor_v | 2:2d0b80ed9216 | 394 | |
igor_v | 2:2d0b80ed9216 | 395 | |
igor_v | 2:2d0b80ed9216 | 396 | /* F_cco0 = (2 * M * F_in) / N */ |
igor_v | 2:2d0b80ed9216 | 397 | #define __M (((PLL0CFG_Val ) & 0x7FFF) + 1) |
igor_v | 2:2d0b80ed9216 | 398 | #define __N (((PLL0CFG_Val >> 16) & 0x00FF) + 1) |
igor_v | 2:2d0b80ed9216 | 399 | #define __FCCO(__F_IN) ((2 * __M * __F_IN) / __N) |
igor_v | 2:2d0b80ed9216 | 400 | #define __CCLK_DIV (((CCLKCFG_Val ) & 0x00FF) + 1) |
igor_v | 2:2d0b80ed9216 | 401 | |
igor_v | 2:2d0b80ed9216 | 402 | /* Determine core clock frequency according to settings */ |
igor_v | 2:2d0b80ed9216 | 403 | #if (PLL0_SETUP) |
igor_v | 2:2d0b80ed9216 | 404 | #if ((CLKSRCSEL_Val & 0x03) == 1) |
igor_v | 2:2d0b80ed9216 | 405 | #define __CORE_CLK (__FCCO(OSC_CLK) / __CCLK_DIV) |
igor_v | 2:2d0b80ed9216 | 406 | #elif ((CLKSRCSEL_Val & 0x03) == 2) |
igor_v | 2:2d0b80ed9216 | 407 | #define __CORE_CLK (__FCCO(RTC_CLK) / __CCLK_DIV) |
igor_v | 2:2d0b80ed9216 | 408 | #else |
igor_v | 2:2d0b80ed9216 | 409 | #define __CORE_CLK (__FCCO(IRC_OSC) / __CCLK_DIV) |
igor_v | 2:2d0b80ed9216 | 410 | #endif |
igor_v | 2:2d0b80ed9216 | 411 | #else |
igor_v | 2:2d0b80ed9216 | 412 | #if ((CLKSRCSEL_Val & 0x03) == 1) |
igor_v | 2:2d0b80ed9216 | 413 | #define __CORE_CLK (OSC_CLK / __CCLK_DIV) |
igor_v | 2:2d0b80ed9216 | 414 | #elif ((CLKSRCSEL_Val & 0x03) == 2) |
igor_v | 2:2d0b80ed9216 | 415 | #define __CORE_CLK (RTC_CLK / __CCLK_DIV) |
igor_v | 2:2d0b80ed9216 | 416 | #else |
igor_v | 2:2d0b80ed9216 | 417 | #define __CORE_CLK (IRC_OSC / __CCLK_DIV) |
igor_v | 2:2d0b80ed9216 | 418 | #endif |
igor_v | 2:2d0b80ed9216 | 419 | #endif |
igor_v | 2:2d0b80ed9216 | 420 | |
igor_v | 2:2d0b80ed9216 | 421 | |
igor_v | 2:2d0b80ed9216 | 422 | /*---------------------------------------------------------------------------- |
igor_v | 2:2d0b80ed9216 | 423 | Clock Variable definitions |
igor_v | 2:2d0b80ed9216 | 424 | *----------------------------------------------------------------------------*/ |
igor_v | 12:74bd0ecf7f83 | 425 | uint32_t SystemCoreClock1 = __CORE_CLK;/*!< System Clock Frequency (Core Clock)*/ |
igor_v | 2:2d0b80ed9216 | 426 | |
igor_v | 2:2d0b80ed9216 | 427 | |
igor_v | 2:2d0b80ed9216 | 428 | /*---------------------------------------------------------------------------- |
igor_v | 2:2d0b80ed9216 | 429 | Clock functions |
igor_v | 2:2d0b80ed9216 | 430 | *----------------------------------------------------------------------------*/ |
igor_v | 12:74bd0ecf7f83 | 431 | void SystemCoreClockUpdate1 (void) /* Get Core Clock Frequency */ |
igor_v | 2:2d0b80ed9216 | 432 | { |
igor_v | 2:2d0b80ed9216 | 433 | /* Determine clock frequency according to clock register values */ |
igor_v | 2:2d0b80ed9216 | 434 | if (((LPC_SC->PLL0STAT >> 24) & 3) == 3) { /* If PLL0 enabled and connected */ |
igor_v | 2:2d0b80ed9216 | 435 | switch (LPC_SC->CLKSRCSEL & 0x03) { |
igor_v | 2:2d0b80ed9216 | 436 | case 0: /* Int. RC oscillator => PLL0 */ |
igor_v | 2:2d0b80ed9216 | 437 | case 3: /* Reserved, default to Int. RC */ |
igor_v | 12:74bd0ecf7f83 | 438 | SystemCoreClock1 = (IRC_OSC * |
igor_v | 2:2d0b80ed9216 | 439 | ((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) / |
igor_v | 2:2d0b80ed9216 | 440 | (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) / |
igor_v | 2:2d0b80ed9216 | 441 | ((LPC_SC->CCLKCFG & 0xFF)+ 1)); |
igor_v | 2:2d0b80ed9216 | 442 | break; |
igor_v | 2:2d0b80ed9216 | 443 | case 1: /* Main oscillator => PLL0 */ |
igor_v | 12:74bd0ecf7f83 | 444 | SystemCoreClock1 = (OSC_CLK * //it is our case osc_clk = 12 MHz |
igor_v | 2:2d0b80ed9216 | 445 | ((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) / //PLL0 multiplier value |
igor_v | 2:2d0b80ed9216 | 446 | (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) / //PLL0 pre-divider |
igor_v | 2:2d0b80ed9216 | 447 | ((LPC_SC->CCLKCFG & 0xFF)+ 1)); //divider for CCLK (SystemCoreClock) |
igor_v | 2:2d0b80ed9216 | 448 | break; |
igor_v | 2:2d0b80ed9216 | 449 | case 2: /* RTC oscillator => PLL0 */ |
igor_v | 12:74bd0ecf7f83 | 450 | SystemCoreClock1 = (RTC_CLK * |
igor_v | 2:2d0b80ed9216 | 451 | ((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) / |
igor_v | 2:2d0b80ed9216 | 452 | (((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1) / |
igor_v | 2:2d0b80ed9216 | 453 | ((LPC_SC->CCLKCFG & 0xFF)+ 1)); |
igor_v | 2:2d0b80ed9216 | 454 | break; |
igor_v | 2:2d0b80ed9216 | 455 | } |
igor_v | 2:2d0b80ed9216 | 456 | } else { |
igor_v | 2:2d0b80ed9216 | 457 | switch (LPC_SC->CLKSRCSEL & 0x03) { |
igor_v | 2:2d0b80ed9216 | 458 | case 0: /* Int. RC oscillator => PLL0 */ |
igor_v | 2:2d0b80ed9216 | 459 | case 3: /* Reserved, default to Int. RC */ |
igor_v | 12:74bd0ecf7f83 | 460 | SystemCoreClock1 = IRC_OSC / ((LPC_SC->CCLKCFG & 0xFF)+ 1); |
igor_v | 2:2d0b80ed9216 | 461 | break; |
igor_v | 2:2d0b80ed9216 | 462 | case 1: /* Main oscillator => PLL0 */ |
igor_v | 12:74bd0ecf7f83 | 463 | SystemCoreClock1 = OSC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1); |
igor_v | 2:2d0b80ed9216 | 464 | break; |
igor_v | 2:2d0b80ed9216 | 465 | case 2: /* RTC oscillator => PLL0 */ |
igor_v | 12:74bd0ecf7f83 | 466 | SystemCoreClock1 = RTC_CLK / ((LPC_SC->CCLKCFG & 0xFF)+ 1); |
igor_v | 2:2d0b80ed9216 | 467 | break; |
igor_v | 2:2d0b80ed9216 | 468 | } |
igor_v | 2:2d0b80ed9216 | 469 | } |
igor_v | 2:2d0b80ed9216 | 470 | |
igor_v | 2:2d0b80ed9216 | 471 | } |
igor_v | 2:2d0b80ed9216 | 472 | |
igor_v | 2:2d0b80ed9216 | 473 | /** |
igor_v | 2:2d0b80ed9216 | 474 | * Initialize the system |
igor_v | 2:2d0b80ed9216 | 475 | * |
igor_v | 2:2d0b80ed9216 | 476 | * @param none |
igor_v | 2:2d0b80ed9216 | 477 | * @return none |
igor_v | 2:2d0b80ed9216 | 478 | * |
igor_v | 2:2d0b80ed9216 | 479 | * @brief Setup the microcontroller system. |
igor_v | 2:2d0b80ed9216 | 480 | * Initialize the System. |
igor_v | 2:2d0b80ed9216 | 481 | */ |
igor_v | 12:74bd0ecf7f83 | 482 | void SystemInit1 (void) |
igor_v | 2:2d0b80ed9216 | 483 | { |
igor_v | 2:2d0b80ed9216 | 484 | #if (CLOCK_SETUP) /* Clock Setup */ |
igor_v | 2:2d0b80ed9216 | 485 | LPC_SC->SCS = SCS_Val; |
igor_v | 2:2d0b80ed9216 | 486 | if (SCS_Val & (1 << 5)) { /* If Main Oscillator is enabled */ |
igor_v | 2:2d0b80ed9216 | 487 | while ((LPC_SC->SCS & (1<<6)) == 0);/* Wait for Oscillator to be ready */ |
igor_v | 2:2d0b80ed9216 | 488 | } |
igor_v | 2:2d0b80ed9216 | 489 | |
igor_v | 2:2d0b80ed9216 | 490 | LPC_SC->CCLKCFG = CCLKCFG_Val; /* Setup Clock Divider */ |
igor_v | 2:2d0b80ed9216 | 491 | |
igor_v | 2:2d0b80ed9216 | 492 | #if (PLL0_SETUP) |
igor_v | 2:2d0b80ed9216 | 493 | LPC_SC->CLKSRCSEL = CLKSRCSEL_Val; /* Select Clock Source for PLL0 */ |
igor_v | 2:2d0b80ed9216 | 494 | |
igor_v | 2:2d0b80ed9216 | 495 | LPC_SC->PLL0CFG = PLL0CFG_Val; /* configure PLL0 */ |
igor_v | 2:2d0b80ed9216 | 496 | LPC_SC->PLL0FEED = 0xAA; |
igor_v | 2:2d0b80ed9216 | 497 | LPC_SC->PLL0FEED = 0x55; |
igor_v | 2:2d0b80ed9216 | 498 | |
igor_v | 2:2d0b80ed9216 | 499 | LPC_SC->PLL0CON = 0x01; /* PLL0 Enable */ |
igor_v | 2:2d0b80ed9216 | 500 | LPC_SC->PLL0FEED = 0xAA; |
igor_v | 2:2d0b80ed9216 | 501 | LPC_SC->PLL0FEED = 0x55; |
igor_v | 2:2d0b80ed9216 | 502 | while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0 */ |
igor_v | 2:2d0b80ed9216 | 503 | |
igor_v | 2:2d0b80ed9216 | 504 | LPC_SC->PLL0CON = 0x03; /* PLL0 Enable & Connect */ |
igor_v | 2:2d0b80ed9216 | 505 | LPC_SC->PLL0FEED = 0xAA; |
igor_v | 2:2d0b80ed9216 | 506 | LPC_SC->PLL0FEED = 0x55; |
igor_v | 2:2d0b80ed9216 | 507 | while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */ |
igor_v | 2:2d0b80ed9216 | 508 | #endif |
igor_v | 2:2d0b80ed9216 | 509 | |
igor_v | 2:2d0b80ed9216 | 510 | #if (PLL1_SETUP) |
igor_v | 2:2d0b80ed9216 | 511 | LPC_SC->PLL1CFG = PLL1CFG_Val; |
igor_v | 2:2d0b80ed9216 | 512 | LPC_SC->PLL1FEED = 0xAA; |
igor_v | 2:2d0b80ed9216 | 513 | LPC_SC->PLL1FEED = 0x55; |
igor_v | 2:2d0b80ed9216 | 514 | |
igor_v | 2:2d0b80ed9216 | 515 | LPC_SC->PLL1CON = 0x01; /* PLL1 Enable */ |
igor_v | 2:2d0b80ed9216 | 516 | LPC_SC->PLL1FEED = 0xAA; |
igor_v | 2:2d0b80ed9216 | 517 | LPC_SC->PLL1FEED = 0x55; |
igor_v | 2:2d0b80ed9216 | 518 | while (!(LPC_SC->PLL1STAT & (1<<10)));/* Wait for PLOCK1 */ |
igor_v | 2:2d0b80ed9216 | 519 | |
igor_v | 2:2d0b80ed9216 | 520 | LPC_SC->PLL1CON = 0x03; /* PLL1 Enable & Connect */ |
igor_v | 2:2d0b80ed9216 | 521 | LPC_SC->PLL1FEED = 0xAA; |
igor_v | 2:2d0b80ed9216 | 522 | LPC_SC->PLL1FEED = 0x55; |
igor_v | 2:2d0b80ed9216 | 523 | while (!(LPC_SC->PLL1STAT & ((1<< 9) | (1<< 8))));/* Wait for PLLC1_STAT & PLLE1_STAT */ |
igor_v | 2:2d0b80ed9216 | 524 | #else |
igor_v | 2:2d0b80ed9216 | 525 | LPC_SC->USBCLKCFG = USBCLKCFG_Val; /* Setup USB Clock Divider */ |
igor_v | 2:2d0b80ed9216 | 526 | #endif |
igor_v | 2:2d0b80ed9216 | 527 | |
igor_v | 2:2d0b80ed9216 | 528 | LPC_SC->PCLKSEL0 = PCLKSEL0_Val; /* Peripheral Clock Selection */ |
igor_v | 2:2d0b80ed9216 | 529 | LPC_SC->PCLKSEL1 = PCLKSEL1_Val; |
igor_v | 2:2d0b80ed9216 | 530 | |
igor_v | 2:2d0b80ed9216 | 531 | LPC_SC->PCONP = PCONP_Val; /* Power Control for Peripherals */ |
igor_v | 2:2d0b80ed9216 | 532 | |
igor_v | 2:2d0b80ed9216 | 533 | LPC_SC->CLKOUTCFG = CLKOUTCFG_Val; /* Clock Output Configuration */ |
igor_v | 2:2d0b80ed9216 | 534 | #endif |
igor_v | 2:2d0b80ed9216 | 535 | |
igor_v | 2:2d0b80ed9216 | 536 | #if (FLASH_SETUP == 1) /* Flash Accelerator Setup */ |
igor_v | 2:2d0b80ed9216 | 537 | LPC_SC->FLASHCFG = FLASHCFG_Val; |
igor_v | 2:2d0b80ed9216 | 538 | #endif |
igor_v | 2:2d0b80ed9216 | 539 | } |
igor_v | 2:2d0b80ed9216 | 540 |