PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
mbed-pokitto/targets/cmsis/TARGET_NXP/TARGET_LPC11U6X/system_LPC11U6x.c@64:6e6c6c2b664e, 2018-11-18 (annotated)
- Committer:
- spinal
- Date:
- Sun Nov 18 15:47:54 2018 +0000
- Revision:
- 64:6e6c6c2b664e
- Parent:
- 5:ea7377f3d1af
added fix for directrectangle()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 5:ea7377f3d1af | 1 | /**************************************************************************//** |
Pokitto | 5:ea7377f3d1af | 2 | * @file system_LPC11U6x.c |
Pokitto | 5:ea7377f3d1af | 3 | * @brief CMSIS Cortex-M3 Device System Source File for |
Pokitto | 5:ea7377f3d1af | 4 | * NXP LPC11U6x Device Series |
Pokitto | 5:ea7377f3d1af | 5 | * @version V1.00 |
Pokitto | 5:ea7377f3d1af | 6 | * @date 19. July 2013 |
Pokitto | 5:ea7377f3d1af | 7 | * |
Pokitto | 5:ea7377f3d1af | 8 | * @note |
Pokitto | 5:ea7377f3d1af | 9 | * Copyright (C) 2013 ARM Limited. All rights reserved. |
Pokitto | 5:ea7377f3d1af | 10 | * |
Pokitto | 5:ea7377f3d1af | 11 | * @par |
Pokitto | 5:ea7377f3d1af | 12 | * ARM Limited (ARM) is supplying this software for use with Cortex-M |
Pokitto | 5:ea7377f3d1af | 13 | * processor based microcontrollers. This file can be freely distributed |
Pokitto | 5:ea7377f3d1af | 14 | * within development tools that are supporting such ARM based processors. |
Pokitto | 5:ea7377f3d1af | 15 | * |
Pokitto | 5:ea7377f3d1af | 16 | * @par |
Pokitto | 5:ea7377f3d1af | 17 | * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED |
Pokitto | 5:ea7377f3d1af | 18 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
Pokitto | 5:ea7377f3d1af | 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. |
Pokitto | 5:ea7377f3d1af | 20 | * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR |
Pokitto | 5:ea7377f3d1af | 21 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
Pokitto | 5:ea7377f3d1af | 22 | * |
Pokitto | 5:ea7377f3d1af | 23 | ******************************************************************************/ |
Pokitto | 5:ea7377f3d1af | 24 | |
Pokitto | 5:ea7377f3d1af | 25 | |
Pokitto | 5:ea7377f3d1af | 26 | #include <stdint.h> |
Pokitto | 5:ea7377f3d1af | 27 | #include "LPC11U6x.h" |
Pokitto | 5:ea7377f3d1af | 28 | |
Pokitto | 5:ea7377f3d1af | 29 | /* |
Pokitto | 5:ea7377f3d1af | 30 | //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------ |
Pokitto | 5:ea7377f3d1af | 31 | */ |
Pokitto | 5:ea7377f3d1af | 32 | |
Pokitto | 5:ea7377f3d1af | 33 | /*- SystemCoreClock Configuration -------------------------------------------*/ |
Pokitto | 5:ea7377f3d1af | 34 | // <e0> SystemCoreClock Configuration |
Pokitto | 5:ea7377f3d1af | 35 | #define CLOCK_SETUP 1 |
Pokitto | 5:ea7377f3d1af | 36 | // |
Pokitto | 5:ea7377f3d1af | 37 | // <h> System Oscillator Control (SYSOSCCTRL) |
Pokitto | 5:ea7377f3d1af | 38 | // <o.0> BYPASS: System Oscillator Bypass Enable |
Pokitto | 5:ea7377f3d1af | 39 | // <i> If enabled then PLL input (sys_osc_clk) is fed |
Pokitto | 5:ea7377f3d1af | 40 | // <i> directly from XTALIN and XTALOUT pins. |
Pokitto | 5:ea7377f3d1af | 41 | // <o.1> FREQRANGE: System Oscillator Frequency Range |
Pokitto | 5:ea7377f3d1af | 42 | // <i> Determines frequency range for Low-power oscillator. |
Pokitto | 5:ea7377f3d1af | 43 | // <0=> 1 - 20 MHz |
Pokitto | 5:ea7377f3d1af | 44 | // <1=> 15 - 25 MHz |
Pokitto | 5:ea7377f3d1af | 45 | // </h> |
Pokitto | 5:ea7377f3d1af | 46 | #define SYSOSCCTRL_Val 0x00000000 // Reset value: 0x000 |
Pokitto | 5:ea7377f3d1af | 47 | // |
Pokitto | 5:ea7377f3d1af | 48 | // <o.0..1> System PLL Clock Source Select (SYSPLLCLKSEL) |
Pokitto | 5:ea7377f3d1af | 49 | // <0=> IRC Oscillator |
Pokitto | 5:ea7377f3d1af | 50 | // <1=> Crystal Oscillator (SYSOSC) |
Pokitto | 5:ea7377f3d1af | 51 | // <3=> RTC Oscillator (32 kHz) |
Pokitto | 5:ea7377f3d1af | 52 | #define SYSPLLCLKSEL_Val 0x00000001 // Reset value: 0x000 |
Pokitto | 5:ea7377f3d1af | 53 | // |
Pokitto | 5:ea7377f3d1af | 54 | // <e> Clock Configuration (Manual) |
Pokitto | 5:ea7377f3d1af | 55 | #define CLOCK_SETUP_REG 1 |
Pokitto | 5:ea7377f3d1af | 56 | // |
Pokitto | 5:ea7377f3d1af | 57 | // <h> WD Oscillator Setting (WDTOSCCTRL) |
Pokitto | 5:ea7377f3d1af | 58 | // <o.0..4> DIVSEL: Select Divider for Fclkana |
Pokitto | 5:ea7377f3d1af | 59 | // <i> wd_osc_clk = Fclkana / (2 × (1 + DIVSEL)) |
Pokitto | 5:ea7377f3d1af | 60 | // <0-31> |
Pokitto | 5:ea7377f3d1af | 61 | // <o.5..8> FREQSEL: Select WD Oscillator Analog Output Frequency (Fclkana) |
Pokitto | 5:ea7377f3d1af | 62 | // <1=> 0.5 MHz |
Pokitto | 5:ea7377f3d1af | 63 | // <2=> 0.8 MHz |
Pokitto | 5:ea7377f3d1af | 64 | // <3=> 1.1 MHz |
Pokitto | 5:ea7377f3d1af | 65 | // <4=> 1.4 MHz |
Pokitto | 5:ea7377f3d1af | 66 | // <5=> 1.6 MHz |
Pokitto | 5:ea7377f3d1af | 67 | // <6=> 1.8 MHz |
Pokitto | 5:ea7377f3d1af | 68 | // <7=> 2.0 MHz |
Pokitto | 5:ea7377f3d1af | 69 | // <8=> 2.2 MHz |
Pokitto | 5:ea7377f3d1af | 70 | // <9=> 2.4 MHz |
Pokitto | 5:ea7377f3d1af | 71 | // <10=> 2.6 MHz |
Pokitto | 5:ea7377f3d1af | 72 | // <11=> 2.7 MHz |
Pokitto | 5:ea7377f3d1af | 73 | // <12=> 2.9 MHz |
Pokitto | 5:ea7377f3d1af | 74 | // <13=> 3.1 MHz |
Pokitto | 5:ea7377f3d1af | 75 | // <14=> 3.2 MHz |
Pokitto | 5:ea7377f3d1af | 76 | // <15=> 3.4 MHz |
Pokitto | 5:ea7377f3d1af | 77 | // </h> |
Pokitto | 5:ea7377f3d1af | 78 | #define WDTOSCCTRL_Val 0x000000A0 // Reset value: 0x0A0 |
Pokitto | 5:ea7377f3d1af | 79 | // |
Pokitto | 5:ea7377f3d1af | 80 | // <h> System PLL Setting (SYSPLLCTRL) |
Pokitto | 5:ea7377f3d1af | 81 | // <i> F_clkout = M * F_clkin = F_CCO / (2 * P) |
Pokitto | 5:ea7377f3d1af | 82 | // <i> F_clkin must be in the range of 10 MHz to 25 MHz |
Pokitto | 5:ea7377f3d1af | 83 | // <i> F_CCO must be in the range of 156 MHz to 320 MHz |
Pokitto | 5:ea7377f3d1af | 84 | // <o.0..4> MSEL: Feedback Divider Selection |
Pokitto | 5:ea7377f3d1af | 85 | // <i> M = MSEL + 1 |
Pokitto | 5:ea7377f3d1af | 86 | // <0-31> |
Pokitto | 5:ea7377f3d1af | 87 | // <o.5..6> PSEL: Post Divider Selection |
Pokitto | 5:ea7377f3d1af | 88 | // <i> Post divider ratio P. Division ratio is 2 * P |
Pokitto | 5:ea7377f3d1af | 89 | // <0=> P = 1 |
Pokitto | 5:ea7377f3d1af | 90 | // <1=> P = 2 |
Pokitto | 5:ea7377f3d1af | 91 | // <2=> P = 4 |
Pokitto | 5:ea7377f3d1af | 92 | // <3=> P = 8 |
Pokitto | 5:ea7377f3d1af | 93 | // </h> |
Pokitto | 5:ea7377f3d1af | 94 | #define SYSPLLCTRL_Val 0x00000023 // Reset value: 0x000 |
Pokitto | 5:ea7377f3d1af | 95 | // |
Pokitto | 5:ea7377f3d1af | 96 | // <o.0..1> Main Clock Source Select (MAINCLKSEL) |
Pokitto | 5:ea7377f3d1af | 97 | // <0=> IRC Oscillator |
Pokitto | 5:ea7377f3d1af | 98 | // <1=> PLL Input |
Pokitto | 5:ea7377f3d1af | 99 | // <2=> WD Oscillator |
Pokitto | 5:ea7377f3d1af | 100 | // <3=> PLL Output |
Pokitto | 5:ea7377f3d1af | 101 | #define MAINCLKSEL_Val 0x00000003 // Reset value: 0x000 |
Pokitto | 5:ea7377f3d1af | 102 | // |
Pokitto | 5:ea7377f3d1af | 103 | // <o.0..7> System AHB Clock Divider (SYSAHBCLKDIV.DIV) |
Pokitto | 5:ea7377f3d1af | 104 | // <i> Divides main clock to provide system clock to core, memories, and peripherals. |
Pokitto | 5:ea7377f3d1af | 105 | // <i> 0 = is disabled |
Pokitto | 5:ea7377f3d1af | 106 | // <0-255> |
Pokitto | 5:ea7377f3d1af | 107 | #define SYSAHBCLKDIV_Val 0x00000001 // Reset value: 0x001 |
Pokitto | 5:ea7377f3d1af | 108 | // </e> |
Pokitto | 5:ea7377f3d1af | 109 | // |
Pokitto | 5:ea7377f3d1af | 110 | // <e> Clock Configuration (via ROM PLL API) |
Pokitto | 5:ea7377f3d1af | 111 | #define CLOCK_SETUP_API 0 |
Pokitto | 5:ea7377f3d1af | 112 | // |
Pokitto | 5:ea7377f3d1af | 113 | // <o> PLL API Mode Select |
Pokitto | 5:ea7377f3d1af | 114 | // <0=> Exact |
Pokitto | 5:ea7377f3d1af | 115 | // <1=> Less than or equal |
Pokitto | 5:ea7377f3d1af | 116 | // <2=> Greater than or equal |
Pokitto | 5:ea7377f3d1af | 117 | // <3=> As close as possible |
Pokitto | 5:ea7377f3d1af | 118 | #define PLL_API_MODE_Val 0 |
Pokitto | 5:ea7377f3d1af | 119 | // |
Pokitto | 5:ea7377f3d1af | 120 | // <o> CPU Frequency [Hz] <1000000-50000000:1000> |
Pokitto | 5:ea7377f3d1af | 121 | #define PLL_API_FREQ_Val 48000000 |
Pokitto | 5:ea7377f3d1af | 122 | // </e> |
Pokitto | 5:ea7377f3d1af | 123 | // |
Pokitto | 5:ea7377f3d1af | 124 | // <e> USB Clock Configuration |
Pokitto | 5:ea7377f3d1af | 125 | #define USB_CLOCK_SETUP 1 |
Pokitto | 5:ea7377f3d1af | 126 | // <h> USB PLL Control (USBPLLCTRL) |
Pokitto | 5:ea7377f3d1af | 127 | // <i> F_clkout = M * F_clkin = F_CCO / (2 * P) |
Pokitto | 5:ea7377f3d1af | 128 | // <i> F_clkin must be in the range of 10 MHz to 25 MHz |
Pokitto | 5:ea7377f3d1af | 129 | // <i> F_CCO must be in the range of 156 MHz to 320 MHz |
Pokitto | 5:ea7377f3d1af | 130 | // <o.0..4> MSEL: Feedback Divider Selection |
Pokitto | 5:ea7377f3d1af | 131 | // <i> M = MSEL + 1 |
Pokitto | 5:ea7377f3d1af | 132 | // <0-31> |
Pokitto | 5:ea7377f3d1af | 133 | // <o.5..6> PSEL: Post Divider Selection |
Pokitto | 5:ea7377f3d1af | 134 | // <i> Post divider ratio P. Division ratio is 2 * P |
Pokitto | 5:ea7377f3d1af | 135 | // <0=> P = 1 |
Pokitto | 5:ea7377f3d1af | 136 | // <1=> P = 2 |
Pokitto | 5:ea7377f3d1af | 137 | // <2=> P = 4 |
Pokitto | 5:ea7377f3d1af | 138 | // <3=> P = 8 |
Pokitto | 5:ea7377f3d1af | 139 | // </h> |
Pokitto | 5:ea7377f3d1af | 140 | #define USBPLLCTRL_Val 0x00000023 // Reset value: 0x000 |
Pokitto | 5:ea7377f3d1af | 141 | // |
Pokitto | 5:ea7377f3d1af | 142 | // <o.0..1> USB PLL Clock Source Select (USBPLLCLKSEL.SEL) |
Pokitto | 5:ea7377f3d1af | 143 | // <i> USB PLL clock source must be switched to System Oscillator for correct USB operation |
Pokitto | 5:ea7377f3d1af | 144 | // <0=> IRC Oscillator |
Pokitto | 5:ea7377f3d1af | 145 | // <1=> System Oscillator |
Pokitto | 5:ea7377f3d1af | 146 | #define USBPLLCLKSEL_Val 0x00000001 // Reset value: 0x000 |
Pokitto | 5:ea7377f3d1af | 147 | // |
Pokitto | 5:ea7377f3d1af | 148 | // <o.0..1> USB Clock Source Select (USBCLKSEL.SEL) |
Pokitto | 5:ea7377f3d1af | 149 | // <0=> USB PLL out |
Pokitto | 5:ea7377f3d1af | 150 | // <1=> Main clock |
Pokitto | 5:ea7377f3d1af | 151 | #define USBCLKSEL_Val 0x00000000 // Reset value: 0x000 |
Pokitto | 5:ea7377f3d1af | 152 | // |
Pokitto | 5:ea7377f3d1af | 153 | // <o.0..7> USB Clock Divider (USBCLKDIV.DIV) |
Pokitto | 5:ea7377f3d1af | 154 | // <i> Divides USB clock to 48 MHz. |
Pokitto | 5:ea7377f3d1af | 155 | // <i> 0 = is disabled |
Pokitto | 5:ea7377f3d1af | 156 | // <0-255> |
Pokitto | 5:ea7377f3d1af | 157 | #define USBCLKDIV_Val 0x00000001 // Reset Value: 0x001 |
Pokitto | 5:ea7377f3d1af | 158 | // </e> |
Pokitto | 5:ea7377f3d1af | 159 | // |
Pokitto | 5:ea7377f3d1af | 160 | // </e> |
Pokitto | 5:ea7377f3d1af | 161 | // |
Pokitto | 5:ea7377f3d1af | 162 | // <o0>System Oscillator (XTAL) Frequency [Hz] <1000000-25000000> |
Pokitto | 5:ea7377f3d1af | 163 | // <i> XTAL frequency must be in the range of 1 MHz to 25 MHz |
Pokitto | 5:ea7377f3d1af | 164 | // |
Pokitto | 5:ea7377f3d1af | 165 | #define XTAL_CLK_Val 12000000 |
Pokitto | 5:ea7377f3d1af | 166 | |
Pokitto | 5:ea7377f3d1af | 167 | /* |
Pokitto | 5:ea7377f3d1af | 168 | //-------- <<< end of configuration section >>> ------------------------------ |
Pokitto | 5:ea7377f3d1af | 169 | */ |
Pokitto | 5:ea7377f3d1af | 170 | |
Pokitto | 5:ea7377f3d1af | 171 | /*---------------------------------------------------------------------------- |
Pokitto | 5:ea7377f3d1af | 172 | Define clocks |
Pokitto | 5:ea7377f3d1af | 173 | *----------------------------------------------------------------------------*/ |
Pokitto | 5:ea7377f3d1af | 174 | #define __XTAL_CLK ( XTAL_CLK_Val) /* Oscillator freq */ |
Pokitto | 5:ea7377f3d1af | 175 | #define __SYS_OSC_CLK ( __XTAL_CLK) /* System oscillator freq */ |
Pokitto | 5:ea7377f3d1af | 176 | #define __IRC_OSC_CLK ( 12000000UL) /* Internal RC oscillator freq */ |
Pokitto | 5:ea7377f3d1af | 177 | #define __RTC_OSC_CLK ( 32768UL) /* RTC oscillator freq */ |
Pokitto | 5:ea7377f3d1af | 178 | |
Pokitto | 5:ea7377f3d1af | 179 | /*---------------------------------------------------------------------------- |
Pokitto | 5:ea7377f3d1af | 180 | Check the register settings |
Pokitto | 5:ea7377f3d1af | 181 | *----------------------------------------------------------------------------*/ |
Pokitto | 5:ea7377f3d1af | 182 | #define CHECK_RANGE(val, min, max) ((val < min) || (val > max)) |
Pokitto | 5:ea7377f3d1af | 183 | #define CHECK_RSVD(val, mask) (val & mask) |
Pokitto | 5:ea7377f3d1af | 184 | |
Pokitto | 5:ea7377f3d1af | 185 | #if (CHECK_RSVD((SYSOSCCTRL_Val), ~0x00000003)) |
Pokitto | 5:ea7377f3d1af | 186 | #error "SYSOSCCTRL: Invalid values of reserved bits!" |
Pokitto | 5:ea7377f3d1af | 187 | #endif |
Pokitto | 5:ea7377f3d1af | 188 | |
Pokitto | 5:ea7377f3d1af | 189 | #if (CHECK_RSVD((WDTOSCCTRL_Val), ~0x000001FF)) |
Pokitto | 5:ea7377f3d1af | 190 | #error "WDTOSCCTRL: Invalid values of reserved bits!" |
Pokitto | 5:ea7377f3d1af | 191 | #endif |
Pokitto | 5:ea7377f3d1af | 192 | |
Pokitto | 5:ea7377f3d1af | 193 | #if (CHECK_RANGE((SYSPLLCLKSEL_Val), 0, 3)) |
Pokitto | 5:ea7377f3d1af | 194 | #error "SYSPLLCLKSEL: Value out of range!" |
Pokitto | 5:ea7377f3d1af | 195 | #endif |
Pokitto | 5:ea7377f3d1af | 196 | |
Pokitto | 5:ea7377f3d1af | 197 | #if (SYSPLLCLKSEL_Val == 3) // RTC Oscillator used as PLL input |
Pokitto | 5:ea7377f3d1af | 198 | #if (CLOCK_SETUP_API == 1) |
Pokitto | 5:ea7377f3d1af | 199 | #error "SYSPLLCLKSEL: RTC oscillator not allowed as PLL clock source!" |
Pokitto | 5:ea7377f3d1af | 200 | #endif |
Pokitto | 5:ea7377f3d1af | 201 | #if (CLOCK_SETUP_REG == 1) && (MAINCLKSEL_Val == 3) // RTC Oscillator used as PLL input |
Pokitto | 5:ea7377f3d1af | 202 | #error "SYSPLLCLKSEL: RTC oscillator not allowed as PLL clock source!" |
Pokitto | 5:ea7377f3d1af | 203 | #endif |
Pokitto | 5:ea7377f3d1af | 204 | #endif |
Pokitto | 5:ea7377f3d1af | 205 | |
Pokitto | 5:ea7377f3d1af | 206 | #if (CHECK_RSVD((SYSPLLCTRL_Val), ~0x0000007F)) |
Pokitto | 5:ea7377f3d1af | 207 | #error "SYSPLLCTRL: Invalid values of reserved bits!" |
Pokitto | 5:ea7377f3d1af | 208 | #endif |
Pokitto | 5:ea7377f3d1af | 209 | |
Pokitto | 5:ea7377f3d1af | 210 | #if (CHECK_RSVD((MAINCLKSEL_Val), ~0x00000003)) |
Pokitto | 5:ea7377f3d1af | 211 | #error "MAINCLKSEL: Invalid values of reserved bits!" |
Pokitto | 5:ea7377f3d1af | 212 | #endif |
Pokitto | 5:ea7377f3d1af | 213 | |
Pokitto | 5:ea7377f3d1af | 214 | #if (CHECK_RANGE((SYSAHBCLKDIV_Val), 0, 255)) |
Pokitto | 5:ea7377f3d1af | 215 | #error "SYSAHBCLKDIV: Value out of range!" |
Pokitto | 5:ea7377f3d1af | 216 | #endif |
Pokitto | 5:ea7377f3d1af | 217 | |
Pokitto | 5:ea7377f3d1af | 218 | #if ( CLOCK_SETUP_REG == CLOCK_SETUP_API ) |
Pokitto | 5:ea7377f3d1af | 219 | #error "You must select either manual or API based Clock Configuration!" |
Pokitto | 5:ea7377f3d1af | 220 | #endif |
Pokitto | 5:ea7377f3d1af | 221 | |
Pokitto | 5:ea7377f3d1af | 222 | #if (CHECK_RANGE((USBPLLCLKSEL_Val), 0, 1)) |
Pokitto | 5:ea7377f3d1af | 223 | #error "USBPLLCLKSEL: Value out of range!" |
Pokitto | 5:ea7377f3d1af | 224 | #endif |
Pokitto | 5:ea7377f3d1af | 225 | |
Pokitto | 5:ea7377f3d1af | 226 | #if (CHECK_RSVD((USBPLLCTRL_Val), ~0x000007F)) |
Pokitto | 5:ea7377f3d1af | 227 | #error "USBPLLCTRL: Invalid values of reserved bits!" |
Pokitto | 5:ea7377f3d1af | 228 | #endif |
Pokitto | 5:ea7377f3d1af | 229 | |
Pokitto | 5:ea7377f3d1af | 230 | #if (CHECK_RANGE((USBCLKSEL_Val), 0, 1)) |
Pokitto | 5:ea7377f3d1af | 231 | #error "USBCLKSEL: Value out of range!" |
Pokitto | 5:ea7377f3d1af | 232 | #endif |
Pokitto | 5:ea7377f3d1af | 233 | |
Pokitto | 5:ea7377f3d1af | 234 | #if (CHECK_RANGE((USBCLKDIV_Val), 0, 255)) |
Pokitto | 5:ea7377f3d1af | 235 | #error "USBCLKDIV: Value out of range!" |
Pokitto | 5:ea7377f3d1af | 236 | #endif |
Pokitto | 5:ea7377f3d1af | 237 | |
Pokitto | 5:ea7377f3d1af | 238 | #if (CHECK_RANGE(XTAL_CLK_Val, 1000000, 25000000)) |
Pokitto | 5:ea7377f3d1af | 239 | #error "XTAL frequency is out of bounds" |
Pokitto | 5:ea7377f3d1af | 240 | #endif |
Pokitto | 5:ea7377f3d1af | 241 | |
Pokitto | 5:ea7377f3d1af | 242 | #if (CHECK_RANGE(PLL_API_MODE_Val, 0, 3)) |
Pokitto | 5:ea7377f3d1af | 243 | #error "PLL API Mode Select not valid" |
Pokitto | 5:ea7377f3d1af | 244 | #endif |
Pokitto | 5:ea7377f3d1af | 245 | |
Pokitto | 5:ea7377f3d1af | 246 | #if (CHECK_RANGE(PLL_API_FREQ_Val, 1000000, 50000000)) |
Pokitto | 5:ea7377f3d1af | 247 | #error "CPU Frequency (API mode) not valid" |
Pokitto | 5:ea7377f3d1af | 248 | #endif |
Pokitto | 5:ea7377f3d1af | 249 | |
Pokitto | 5:ea7377f3d1af | 250 | |
Pokitto | 5:ea7377f3d1af | 251 | |
Pokitto | 5:ea7377f3d1af | 252 | /*---------------------------------------------------------------------------- |
Pokitto | 5:ea7377f3d1af | 253 | Calculate system core clock |
Pokitto | 5:ea7377f3d1af | 254 | *----------------------------------------------------------------------------*/ |
Pokitto | 5:ea7377f3d1af | 255 | #if (CLOCK_SETUP) /* Clock Setup */ |
Pokitto | 5:ea7377f3d1af | 256 | |
Pokitto | 5:ea7377f3d1af | 257 | /* sys_pllclkin calculation */ |
Pokitto | 5:ea7377f3d1af | 258 | #if ((SYSPLLCLKSEL_Val & 0x03) == 0) |
Pokitto | 5:ea7377f3d1af | 259 | #define __SYS_PLLCLKIN (__IRC_OSC_CLK) |
Pokitto | 5:ea7377f3d1af | 260 | #elif ((SYSPLLCLKSEL_Val & 0x03) == 1) |
Pokitto | 5:ea7377f3d1af | 261 | #define __SYS_PLLCLKIN (__SYS_OSC_CLK) |
Pokitto | 5:ea7377f3d1af | 262 | #elif ((SYSPLLCLKSEL_Val & 0x03) == 3) |
Pokitto | 5:ea7377f3d1af | 263 | #define __SYS_PLLCLKIN (__RTC_OSC_CLK) |
Pokitto | 5:ea7377f3d1af | 264 | #else |
Pokitto | 5:ea7377f3d1af | 265 | #error "Oops" |
Pokitto | 5:ea7377f3d1af | 266 | #endif |
Pokitto | 5:ea7377f3d1af | 267 | |
Pokitto | 5:ea7377f3d1af | 268 | #if (CLOCK_SETUP_REG == 1) /* Clock Setup via Register */ |
Pokitto | 5:ea7377f3d1af | 269 | |
Pokitto | 5:ea7377f3d1af | 270 | #define __FREQSEL ((WDTOSCCTRL_Val >> 5) & 0x0F) |
Pokitto | 5:ea7377f3d1af | 271 | #define __DIVSEL (((WDTOSCCTRL_Val & 0x1F) << 1) + 2) |
Pokitto | 5:ea7377f3d1af | 272 | |
Pokitto | 5:ea7377f3d1af | 273 | #if (__FREQSEL == 0) |
Pokitto | 5:ea7377f3d1af | 274 | #error "WDTOSCCTRL.FREQSEL undefined!" |
Pokitto | 5:ea7377f3d1af | 275 | #elif (__FREQSEL == 1) |
Pokitto | 5:ea7377f3d1af | 276 | #define __OSC_CLK ( 500000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 277 | #elif (__FREQSEL == 2) |
Pokitto | 5:ea7377f3d1af | 278 | #define __OSC_CLK ( 800000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 279 | #elif (__FREQSEL == 3) |
Pokitto | 5:ea7377f3d1af | 280 | #define __OSC_CLK (1100000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 281 | #elif (__FREQSEL == 4) |
Pokitto | 5:ea7377f3d1af | 282 | #define __OSC_CLK (1400000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 283 | #elif (__FREQSEL == 5) |
Pokitto | 5:ea7377f3d1af | 284 | #define __OSC_CLK (1600000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 285 | #elif (__FREQSEL == 6) |
Pokitto | 5:ea7377f3d1af | 286 | #define __OSC_CLK (1800000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 287 | #elif (__FREQSEL == 7) |
Pokitto | 5:ea7377f3d1af | 288 | #define __OSC_CLK (2000000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 289 | #elif (__FREQSEL == 8) |
Pokitto | 5:ea7377f3d1af | 290 | #define __OSC_CLK (2200000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 291 | #elif (__FREQSEL == 9) |
Pokitto | 5:ea7377f3d1af | 292 | #define __OSC_CLK (2400000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 293 | #elif (__FREQSEL == 10) |
Pokitto | 5:ea7377f3d1af | 294 | #define __OSC_CLK (2600000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 295 | #elif (__FREQSEL == 11) |
Pokitto | 5:ea7377f3d1af | 296 | #define __OSC_CLK (2700000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 297 | #elif (__FREQSEL == 12) |
Pokitto | 5:ea7377f3d1af | 298 | #define __OSC_CLK (2900000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 299 | #elif (__FREQSEL == 13) |
Pokitto | 5:ea7377f3d1af | 300 | #define __OSC_CLK (3100000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 301 | #elif (__FREQSEL == 14) |
Pokitto | 5:ea7377f3d1af | 302 | #define __OSC_CLK (3200000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 303 | #else |
Pokitto | 5:ea7377f3d1af | 304 | #define __OSC_CLK (3400000 / __DIVSEL) |
Pokitto | 5:ea7377f3d1af | 305 | #endif |
Pokitto | 5:ea7377f3d1af | 306 | |
Pokitto | 5:ea7377f3d1af | 307 | #define __SYS_PLLCLKOUT (__SYS_PLLCLKIN * ((SYSPLLCTRL_Val & 0x01F) + 1)) |
Pokitto | 5:ea7377f3d1af | 308 | |
Pokitto | 5:ea7377f3d1af | 309 | /* main clock calculation */ |
Pokitto | 5:ea7377f3d1af | 310 | #if ((MAINCLKSEL_Val & 0x03) == 0) |
Pokitto | 5:ea7377f3d1af | 311 | #define __MAIN_CLOCK (__IRC_OSC_CLK) |
Pokitto | 5:ea7377f3d1af | 312 | #elif ((MAINCLKSEL_Val & 0x03) == 1) |
Pokitto | 5:ea7377f3d1af | 313 | #define __MAIN_CLOCK (__SYS_PLLCLKIN) |
Pokitto | 5:ea7377f3d1af | 314 | #elif ((MAINCLKSEL_Val & 0x03) == 2) |
Pokitto | 5:ea7377f3d1af | 315 | #define __MAIN_CLOCK (__OSC_CLK) |
Pokitto | 5:ea7377f3d1af | 316 | #elif ((MAINCLKSEL_Val & 0x03) == 3) |
Pokitto | 5:ea7377f3d1af | 317 | #define __MAIN_CLOCK (__SYS_PLLCLKOUT) |
Pokitto | 5:ea7377f3d1af | 318 | #else |
Pokitto | 5:ea7377f3d1af | 319 | #error "Oops" |
Pokitto | 5:ea7377f3d1af | 320 | #endif |
Pokitto | 5:ea7377f3d1af | 321 | |
Pokitto | 5:ea7377f3d1af | 322 | #define __SYSTEM_CLOCK (__MAIN_CLOCK / SYSAHBCLKDIV_Val) |
Pokitto | 5:ea7377f3d1af | 323 | #endif /* Clock Setup via Register */ |
Pokitto | 5:ea7377f3d1af | 324 | |
Pokitto | 5:ea7377f3d1af | 325 | #if (CLOCK_SETUP_API == 1) /* Clock Setup via ROM API */ |
Pokitto | 5:ea7377f3d1af | 326 | #define __SYSTEM_CLOCK (PLL_API_FREQ_Val) |
Pokitto | 5:ea7377f3d1af | 327 | #endif /* Clock Setup via PLL API */ |
Pokitto | 5:ea7377f3d1af | 328 | |
Pokitto | 5:ea7377f3d1af | 329 | #else |
Pokitto | 5:ea7377f3d1af | 330 | #define __SYSTEM_CLOCK (__IRC_OSC_CLK) |
Pokitto | 5:ea7377f3d1af | 331 | #endif /* CLOCK_SETUP */ |
Pokitto | 5:ea7377f3d1af | 332 | |
Pokitto | 5:ea7377f3d1af | 333 | |
Pokitto | 5:ea7377f3d1af | 334 | |
Pokitto | 5:ea7377f3d1af | 335 | #if ((CLOCK_SETUP == 1) && (CLOCK_SETUP_API == 1)) /* PLL Setup via PLL API */ |
Pokitto | 5:ea7377f3d1af | 336 | #include "power_api.h" |
Pokitto | 5:ea7377f3d1af | 337 | |
Pokitto | 5:ea7377f3d1af | 338 | typedef struct _ROM { |
Pokitto | 5:ea7377f3d1af | 339 | const unsigned p_dev0; |
Pokitto | 5:ea7377f3d1af | 340 | const unsigned p_dev1; |
Pokitto | 5:ea7377f3d1af | 341 | const unsigned p_dev2; |
Pokitto | 5:ea7377f3d1af | 342 | const PWRD * pPWRD; /* ROM Power Management API */ |
Pokitto | 5:ea7377f3d1af | 343 | const unsigned p_dev4; |
Pokitto | 5:ea7377f3d1af | 344 | const unsigned p_dev5; |
Pokitto | 5:ea7377f3d1af | 345 | const unsigned p_dev6; |
Pokitto | 5:ea7377f3d1af | 346 | const unsigned p_dev7; |
Pokitto | 5:ea7377f3d1af | 347 | } ROM; |
Pokitto | 5:ea7377f3d1af | 348 | |
Pokitto | 5:ea7377f3d1af | 349 | /*---------------------------------------------------------------------------- |
Pokitto | 5:ea7377f3d1af | 350 | PLL API Function |
Pokitto | 5:ea7377f3d1af | 351 | *----------------------------------------------------------------------------*/ |
Pokitto | 5:ea7377f3d1af | 352 | static void setPLL(const uint32_t pllMode, const uint32_t pllInFreq, const uint32_t reqCpuFreq) |
Pokitto | 5:ea7377f3d1af | 353 | { |
Pokitto | 5:ea7377f3d1af | 354 | uint32_t cmd[5], res[5]; |
Pokitto | 5:ea7377f3d1af | 355 | ROM ** rom = (ROM **) 0x1FFF1FF8; /* pointer to power API calls */ |
Pokitto | 5:ea7377f3d1af | 356 | |
Pokitto | 5:ea7377f3d1af | 357 | cmd[0] = pllInFreq; /* PLL's input freq in KHz */ |
Pokitto | 5:ea7377f3d1af | 358 | cmd[1] = reqCpuFreq; /* requested CPU freq in KHz */ |
Pokitto | 5:ea7377f3d1af | 359 | cmd[2] = pllMode; |
Pokitto | 5:ea7377f3d1af | 360 | cmd[3] = 0; /* no timeout for PLL to lock */ |
Pokitto | 5:ea7377f3d1af | 361 | |
Pokitto | 5:ea7377f3d1af | 362 | /* Execute API call */ |
Pokitto | 5:ea7377f3d1af | 363 | (*rom)->pPWRD->set_pll(cmd, res); /* call API function */ |
Pokitto | 5:ea7377f3d1af | 364 | if ((res[0] != PLL_CMD_SUCCESS)){ /* in case of an error ... */ |
Pokitto | 5:ea7377f3d1af | 365 | while(1); /* ... stay here */ |
Pokitto | 5:ea7377f3d1af | 366 | } |
Pokitto | 5:ea7377f3d1af | 367 | } |
Pokitto | 5:ea7377f3d1af | 368 | #endif |
Pokitto | 5:ea7377f3d1af | 369 | |
Pokitto | 5:ea7377f3d1af | 370 | |
Pokitto | 5:ea7377f3d1af | 371 | |
Pokitto | 5:ea7377f3d1af | 372 | |
Pokitto | 5:ea7377f3d1af | 373 | /*---------------------------------------------------------------------------- |
Pokitto | 5:ea7377f3d1af | 374 | Clock Variable definitions |
Pokitto | 5:ea7377f3d1af | 375 | *----------------------------------------------------------------------------*/ |
Pokitto | 5:ea7377f3d1af | 376 | uint32_t SystemCoreClock = __SYSTEM_CLOCK; /* System Clock Frequency */ |
Pokitto | 5:ea7377f3d1af | 377 | |
Pokitto | 5:ea7377f3d1af | 378 | |
Pokitto | 5:ea7377f3d1af | 379 | /*---------------------------------------------------------------------------- |
Pokitto | 5:ea7377f3d1af | 380 | Clock functions |
Pokitto | 5:ea7377f3d1af | 381 | *----------------------------------------------------------------------------*/ |
Pokitto | 5:ea7377f3d1af | 382 | void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */ |
Pokitto | 5:ea7377f3d1af | 383 | { |
Pokitto | 5:ea7377f3d1af | 384 | uint32_t oscClk = 0; |
Pokitto | 5:ea7377f3d1af | 385 | |
Pokitto | 5:ea7377f3d1af | 386 | /* Determine clock frequency according to clock register values */ |
Pokitto | 5:ea7377f3d1af | 387 | switch ((LPC_SYSCON->WDTOSCCTRL >> 5) & 0x0F) { |
Pokitto | 5:ea7377f3d1af | 388 | case 0: oscClk = 0; break; |
Pokitto | 5:ea7377f3d1af | 389 | case 1: oscClk = 500000; break; |
Pokitto | 5:ea7377f3d1af | 390 | case 2: oscClk = 800000; break; |
Pokitto | 5:ea7377f3d1af | 391 | case 3: oscClk = 1100000; break; |
Pokitto | 5:ea7377f3d1af | 392 | case 4: oscClk = 1400000; break; |
Pokitto | 5:ea7377f3d1af | 393 | case 5: oscClk = 1600000; break; |
Pokitto | 5:ea7377f3d1af | 394 | case 6: oscClk = 1800000; break; |
Pokitto | 5:ea7377f3d1af | 395 | case 7: oscClk = 2000000; break; |
Pokitto | 5:ea7377f3d1af | 396 | case 8: oscClk = 2200000; break; |
Pokitto | 5:ea7377f3d1af | 397 | case 9: oscClk = 2400000; break; |
Pokitto | 5:ea7377f3d1af | 398 | case 10: oscClk = 2600000; break; |
Pokitto | 5:ea7377f3d1af | 399 | case 11: oscClk = 2700000; break; |
Pokitto | 5:ea7377f3d1af | 400 | case 12: oscClk = 2900000; break; |
Pokitto | 5:ea7377f3d1af | 401 | case 13: oscClk = 3100000; break; |
Pokitto | 5:ea7377f3d1af | 402 | case 14: oscClk = 3200000; break; |
Pokitto | 5:ea7377f3d1af | 403 | case 15: oscClk = 3400000; break; |
Pokitto | 5:ea7377f3d1af | 404 | } |
Pokitto | 5:ea7377f3d1af | 405 | oscClk /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2; |
Pokitto | 5:ea7377f3d1af | 406 | |
Pokitto | 5:ea7377f3d1af | 407 | switch (LPC_SYSCON->MAINCLKSEL & 0x03) { |
Pokitto | 5:ea7377f3d1af | 408 | case 0: /* Internal RC oscillator */ |
Pokitto | 5:ea7377f3d1af | 409 | SystemCoreClock = __IRC_OSC_CLK; |
Pokitto | 5:ea7377f3d1af | 410 | break; |
Pokitto | 5:ea7377f3d1af | 411 | case 1: /* Input Clock to System PLL */ |
Pokitto | 5:ea7377f3d1af | 412 | switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { |
Pokitto | 5:ea7377f3d1af | 413 | case 0: /* Internal RC oscillator */ |
Pokitto | 5:ea7377f3d1af | 414 | SystemCoreClock = __IRC_OSC_CLK; |
Pokitto | 5:ea7377f3d1af | 415 | break; |
Pokitto | 5:ea7377f3d1af | 416 | case 1: /* System oscillator */ |
Pokitto | 5:ea7377f3d1af | 417 | SystemCoreClock = __SYS_OSC_CLK; |
Pokitto | 5:ea7377f3d1af | 418 | break; |
Pokitto | 5:ea7377f3d1af | 419 | case 2: /* Reserved */ |
Pokitto | 5:ea7377f3d1af | 420 | case 3: /* Reserved */ |
Pokitto | 5:ea7377f3d1af | 421 | SystemCoreClock = 0; |
Pokitto | 5:ea7377f3d1af | 422 | break; |
Pokitto | 5:ea7377f3d1af | 423 | } |
Pokitto | 5:ea7377f3d1af | 424 | break; |
Pokitto | 5:ea7377f3d1af | 425 | case 2: /* WDT Oscillator */ |
Pokitto | 5:ea7377f3d1af | 426 | SystemCoreClock = oscClk; |
Pokitto | 5:ea7377f3d1af | 427 | break; |
Pokitto | 5:ea7377f3d1af | 428 | case 3: /* System PLL Clock Out */ |
Pokitto | 5:ea7377f3d1af | 429 | switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { |
Pokitto | 5:ea7377f3d1af | 430 | case 0: /* Internal RC oscillator */ |
Pokitto | 5:ea7377f3d1af | 431 | SystemCoreClock = __IRC_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); |
Pokitto | 5:ea7377f3d1af | 432 | break; |
Pokitto | 5:ea7377f3d1af | 433 | case 1: /* System oscillator */ |
Pokitto | 5:ea7377f3d1af | 434 | SystemCoreClock = __SYS_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); |
Pokitto | 5:ea7377f3d1af | 435 | break; |
Pokitto | 5:ea7377f3d1af | 436 | case 2: /* Reserved */ |
Pokitto | 5:ea7377f3d1af | 437 | case 3: /* Reserved */ |
Pokitto | 5:ea7377f3d1af | 438 | SystemCoreClock = 0; |
Pokitto | 5:ea7377f3d1af | 439 | break; |
Pokitto | 5:ea7377f3d1af | 440 | } |
Pokitto | 5:ea7377f3d1af | 441 | break; |
Pokitto | 5:ea7377f3d1af | 442 | } |
Pokitto | 5:ea7377f3d1af | 443 | |
Pokitto | 5:ea7377f3d1af | 444 | SystemCoreClock /= LPC_SYSCON->SYSAHBCLKDIV; |
Pokitto | 5:ea7377f3d1af | 445 | |
Pokitto | 5:ea7377f3d1af | 446 | } |
Pokitto | 5:ea7377f3d1af | 447 | |
Pokitto | 5:ea7377f3d1af | 448 | #define PDRUN_VALID_BITS 0x000025FFL |
Pokitto | 5:ea7377f3d1af | 449 | #define PDRUN_RESERVED_ONE 0x0000C800L |
Pokitto | 5:ea7377f3d1af | 450 | |
Pokitto | 5:ea7377f3d1af | 451 | static void power_down_config(uint32_t val) |
Pokitto | 5:ea7377f3d1af | 452 | { |
Pokitto | 5:ea7377f3d1af | 453 | volatile uint32_t tmp; |
Pokitto | 5:ea7377f3d1af | 454 | tmp = (LPC_SYSCON->PDRUNCFG & PDRUN_VALID_BITS); |
Pokitto | 5:ea7377f3d1af | 455 | tmp |= (val & PDRUN_VALID_BITS); |
Pokitto | 5:ea7377f3d1af | 456 | LPC_SYSCON->PDRUNCFG = (tmp | PDRUN_RESERVED_ONE); |
Pokitto | 5:ea7377f3d1af | 457 | } |
Pokitto | 5:ea7377f3d1af | 458 | |
Pokitto | 5:ea7377f3d1af | 459 | static void power_up_config(uint32_t val) |
Pokitto | 5:ea7377f3d1af | 460 | { |
Pokitto | 5:ea7377f3d1af | 461 | volatile uint32_t tmp; |
Pokitto | 5:ea7377f3d1af | 462 | tmp = (LPC_SYSCON->PDRUNCFG & PDRUN_VALID_BITS); |
Pokitto | 5:ea7377f3d1af | 463 | tmp &= ~(val & PDRUN_VALID_BITS); |
Pokitto | 5:ea7377f3d1af | 464 | LPC_SYSCON->PDRUNCFG = (tmp | PDRUN_RESERVED_ONE); |
Pokitto | 5:ea7377f3d1af | 465 | } |
Pokitto | 5:ea7377f3d1af | 466 | |
Pokitto | 5:ea7377f3d1af | 467 | /** |
Pokitto | 5:ea7377f3d1af | 468 | * Initialize the system |
Pokitto | 5:ea7377f3d1af | 469 | * |
Pokitto | 5:ea7377f3d1af | 470 | * @param none |
Pokitto | 5:ea7377f3d1af | 471 | * @return none |
Pokitto | 5:ea7377f3d1af | 472 | * |
Pokitto | 5:ea7377f3d1af | 473 | * @brief Setup the microcontroller system. |
Pokitto | 5:ea7377f3d1af | 474 | */ |
Pokitto | 5:ea7377f3d1af | 475 | void SystemInit (void) { |
Pokitto | 5:ea7377f3d1af | 476 | #if (CLOCK_SETUP) |
Pokitto | 5:ea7377f3d1af | 477 | volatile uint32_t i; |
Pokitto | 5:ea7377f3d1af | 478 | #endif |
Pokitto | 5:ea7377f3d1af | 479 | LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); |
Pokitto | 5:ea7377f3d1af | 480 | LPC_SYSCON->SYSPLLCTRL = SYSPLLCTRL_Val; |
Pokitto | 5:ea7377f3d1af | 481 | |
Pokitto | 5:ea7377f3d1af | 482 | #if (CLOCK_SETUP) /* Clock Setup */ |
Pokitto | 5:ea7377f3d1af | 483 | |
Pokitto | 5:ea7377f3d1af | 484 | #if ((SYSPLLCLKSEL_Val & 0x03) == 1) |
Pokitto | 5:ea7377f3d1af | 485 | // Initialize XTALIN/XTALOUT pins |
Pokitto | 5:ea7377f3d1af | 486 | LPC_IOCON->PIO2_0 = 0x01; |
Pokitto | 5:ea7377f3d1af | 487 | LPC_IOCON->PIO2_1 = 0x01; |
Pokitto | 5:ea7377f3d1af | 488 | |
Pokitto | 5:ea7377f3d1af | 489 | LPC_SYSCON->SYSOSCCTRL = SYSOSCCTRL_Val; |
Pokitto | 5:ea7377f3d1af | 490 | power_up_config(1<<5); /* Power-up sysosc */ |
Pokitto | 5:ea7377f3d1af | 491 | for (i = 0; i < 2500; i++) __NOP(); /* Wait for osc to stabilize */ |
Pokitto | 5:ea7377f3d1af | 492 | #endif |
Pokitto | 5:ea7377f3d1af | 493 | |
Pokitto | 5:ea7377f3d1af | 494 | #if ((SYSPLLCLKSEL_Val & 0x03) == 3) |
Pokitto | 5:ea7377f3d1af | 495 | LPC_SYSCON->RTCOSCCTRL = (1 << 0); /* Enable 32 kHz output */ |
Pokitto | 5:ea7377f3d1af | 496 | for (i = 0; i < 200; i++) __NOP(); /* Wait for osc to stabilize */ |
Pokitto | 5:ea7377f3d1af | 497 | #endif |
Pokitto | 5:ea7377f3d1af | 498 | |
Pokitto | 5:ea7377f3d1af | 499 | LPC_SYSCON->SYSPLLCLKSEL = SYSPLLCLKSEL_Val; /* Select PLL Input */ |
Pokitto | 5:ea7377f3d1af | 500 | LPC_SYSCON->SYSPLLCLKUEN = 0x01; /* Update Clock Source */ |
Pokitto | 5:ea7377f3d1af | 501 | LPC_SYSCON->SYSPLLCLKUEN = 0x00; /* Toggle Update Register */ |
Pokitto | 5:ea7377f3d1af | 502 | LPC_SYSCON->SYSPLLCLKUEN = 0x01; |
Pokitto | 5:ea7377f3d1af | 503 | while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); /* Wait Until Updated */ |
Pokitto | 5:ea7377f3d1af | 504 | |
Pokitto | 5:ea7377f3d1af | 505 | #if (CLOCK_SETUP_REG == 1) /* Clock Setup via Register */ |
Pokitto | 5:ea7377f3d1af | 506 | |
Pokitto | 5:ea7377f3d1af | 507 | #if (((MAINCLKSEL_Val & 0x03) == 2) ) |
Pokitto | 5:ea7377f3d1af | 508 | LPC_SYSCON->WDTOSCCTRL = WDTOSCCTRL_Val; |
Pokitto | 5:ea7377f3d1af | 509 | LPC_SYSCON->PDRUNCFG &= ~(1 << 6); /* Power-up WDT Clock */ |
Pokitto | 5:ea7377f3d1af | 510 | for (i = 0; i < 2000; i++) __NOP(); /* Wait for osc to stabilize */ |
Pokitto | 5:ea7377f3d1af | 511 | #endif |
Pokitto | 5:ea7377f3d1af | 512 | |
Pokitto | 5:ea7377f3d1af | 513 | #if ((MAINCLKSEL_Val & 0x03) == 3) /* Main Clock is PLL Out */ |
Pokitto | 5:ea7377f3d1af | 514 | power_down_config(1<<7); /* Power-down SYSPLL */ |
Pokitto | 5:ea7377f3d1af | 515 | LPC_SYSCON->SYSPLLCTRL = SYSPLLCTRL_Val; |
Pokitto | 5:ea7377f3d1af | 516 | power_up_config(1<<7); /* Power-up SYSPLL */ |
Pokitto | 5:ea7377f3d1af | 517 | while (!(LPC_SYSCON->SYSPLLSTAT & 0x01)); /* Wait Until PLL Locked */ |
Pokitto | 5:ea7377f3d1af | 518 | #endif |
Pokitto | 5:ea7377f3d1af | 519 | |
Pokitto | 5:ea7377f3d1af | 520 | LPC_SYSCON->MAINCLKSEL = MAINCLKSEL_Val; /* Select Clock Source */ |
Pokitto | 5:ea7377f3d1af | 521 | LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */ |
Pokitto | 5:ea7377f3d1af | 522 | LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */ |
Pokitto | 5:ea7377f3d1af | 523 | LPC_SYSCON->MAINCLKUEN = 0x01; |
Pokitto | 5:ea7377f3d1af | 524 | while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */ |
Pokitto | 5:ea7377f3d1af | 525 | |
Pokitto | 5:ea7377f3d1af | 526 | LPC_SYSCON->SYSAHBCLKDIV = SYSAHBCLKDIV_Val; |
Pokitto | 5:ea7377f3d1af | 527 | #endif /* Clock Setup via Register */ |
Pokitto | 5:ea7377f3d1af | 528 | |
Pokitto | 5:ea7377f3d1af | 529 | #if (CLOCK_SETUP_API == 1) /* Clock Setup via PLL API */ |
Pokitto | 5:ea7377f3d1af | 530 | // LPC_SYSCON->SYSPLLCLKSEL = 0x00; /* Use IRC */ |
Pokitto | 5:ea7377f3d1af | 531 | // LPC_SYSCON->SYSPLLCLKUEN = 0x01; /* Update Clock Source */ |
Pokitto | 5:ea7377f3d1af | 532 | // LPC_SYSCON->SYSPLLCLKUEN = 0x00; /* Toggle Update Register */ |
Pokitto | 5:ea7377f3d1af | 533 | // LPC_SYSCON->SYSPLLCLKUEN = 0x01; |
Pokitto | 5:ea7377f3d1af | 534 | // while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); /* Wait Until Updated */ |
Pokitto | 5:ea7377f3d1af | 535 | |
Pokitto | 5:ea7377f3d1af | 536 | LPC_SYSCON->MAINCLKSEL = SYSPLLCLKSEL_Val; /* Select same as SYSPLL */ |
Pokitto | 5:ea7377f3d1af | 537 | LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */ |
Pokitto | 5:ea7377f3d1af | 538 | LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */ |
Pokitto | 5:ea7377f3d1af | 539 | LPC_SYSCON->MAINCLKUEN = 0x01; |
Pokitto | 5:ea7377f3d1af | 540 | while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */ |
Pokitto | 5:ea7377f3d1af | 541 | |
Pokitto | 5:ea7377f3d1af | 542 | LPC_SYSCON->SYSAHBCLKDIV = 1; |
Pokitto | 5:ea7377f3d1af | 543 | |
Pokitto | 5:ea7377f3d1af | 544 | setPLL(PLL_API_MODE_Val, __SYS_PLLCLKIN / 1000, PLL_API_FREQ_Val / 1000); |
Pokitto | 5:ea7377f3d1af | 545 | #endif /* Clock Setup via PLL API */ |
Pokitto | 5:ea7377f3d1af | 546 | |
Pokitto | 5:ea7377f3d1af | 547 | #if (USB_CLOCK_SETUP == 1) /* USB clock is used */ |
Pokitto | 5:ea7377f3d1af | 548 | LPC_SYSCON->PDRUNCFG &= ~(1 << 10); /* Power-up USB PHY */ |
Pokitto | 5:ea7377f3d1af | 549 | |
Pokitto | 5:ea7377f3d1af | 550 | #if ((USBCLKSEL_Val & 0x003) == 0) /* USB clock is USB PLL out */ |
Pokitto | 5:ea7377f3d1af | 551 | LPC_SYSCON->PDRUNCFG &= ~(1 << 8); /* Power-up USB PLL */ |
Pokitto | 5:ea7377f3d1af | 552 | LPC_SYSCON->USBPLLCLKSEL = USBPLLCLKSEL_Val; /* Select PLL Input */ |
Pokitto | 5:ea7377f3d1af | 553 | LPC_SYSCON->USBPLLCLKUEN = 0x01; /* Update Clock Source */ |
Pokitto | 5:ea7377f3d1af | 554 | LPC_SYSCON->USBPLLCLKUEN = 0x00; /* Toggle Update Register */ |
Pokitto | 5:ea7377f3d1af | 555 | LPC_SYSCON->USBPLLCLKUEN = 0x01; |
Pokitto | 5:ea7377f3d1af | 556 | while (!(LPC_SYSCON->USBPLLCLKUEN & 0x01)); /* Wait Until Updated */ |
Pokitto | 5:ea7377f3d1af | 557 | |
Pokitto | 5:ea7377f3d1af | 558 | LPC_SYSCON->USBPLLCTRL = USBPLLCTRL_Val; |
Pokitto | 5:ea7377f3d1af | 559 | while (!(LPC_SYSCON->USBPLLSTAT & 0x01)); /* Wait Until PLL Locked */ |
Pokitto | 5:ea7377f3d1af | 560 | |
Pokitto | 5:ea7377f3d1af | 561 | LPC_SYSCON->USBCLKSEL = 0x00; /* Select USB PLL */ |
Pokitto | 5:ea7377f3d1af | 562 | #endif |
Pokitto | 5:ea7377f3d1af | 563 | |
Pokitto | 5:ea7377f3d1af | 564 | LPC_SYSCON->USBCLKSEL = USBCLKSEL_Val; /* Select USB Clock */ |
Pokitto | 5:ea7377f3d1af | 565 | LPC_SYSCON->USBCLKDIV = USBCLKDIV_Val; /* Set USB clock divider */ |
Pokitto | 5:ea7377f3d1af | 566 | |
Pokitto | 5:ea7377f3d1af | 567 | #else /* USB clock is not used */ |
Pokitto | 5:ea7377f3d1af | 568 | LPC_SYSCON->PDRUNCFG |= (1 << 10); /* Power-down USB PHY */ |
Pokitto | 5:ea7377f3d1af | 569 | LPC_SYSCON->PDRUNCFG |= (1 << 8); /* Power-down USB PLL */ |
Pokitto | 5:ea7377f3d1af | 570 | #endif |
Pokitto | 5:ea7377f3d1af | 571 | |
Pokitto | 5:ea7377f3d1af | 572 | #endif /* Clock Setup */ |
Pokitto | 5:ea7377f3d1af | 573 | |
Pokitto | 5:ea7377f3d1af | 574 | } |