diff options
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.c')
-rw-r--r-- | lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.c b/lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.c new file mode 100644 index 000000000..f3e35d485 --- /dev/null +++ b/lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.c | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2020 Yaotian Feng / Codetector | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | /** | ||
18 | * @file hal_lld.c | ||
19 | * @brief PLATFORM HAL subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup HAL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | |||
28 | /*===========================================================================*/ | ||
29 | /* Driver local definitions. */ | ||
30 | /*===========================================================================*/ | ||
31 | |||
32 | /*===========================================================================*/ | ||
33 | /* Driver exported variables. */ | ||
34 | /*===========================================================================*/ | ||
35 | |||
36 | /*===========================================================================*/ | ||
37 | /* Driver local variables and types. */ | ||
38 | /*===========================================================================*/ | ||
39 | |||
40 | /*===========================================================================*/ | ||
41 | /* Driver local functions. */ | ||
42 | /*===========================================================================*/ | ||
43 | |||
44 | /*===========================================================================*/ | ||
45 | /* Driver interrupt handlers. */ | ||
46 | /*===========================================================================*/ | ||
47 | |||
48 | /*===========================================================================*/ | ||
49 | /* Driver exported functions. */ | ||
50 | /*===========================================================================*/ | ||
51 | |||
52 | void lpc_clock_init(void) { | ||
53 | |||
54 | #if defined(LPC_USE_SYSOSC) && LPC_USE_SYSOSC != FALSE | ||
55 | |||
56 | LPC_SYSCON->PDRUNCFG &= ~SYSCON_PDRUNCFG_SYSSOC_PD; | ||
57 | LPC_SYSCON->SYSOSCCTRL = 0; | ||
58 | |||
59 | #endif | ||
60 | |||
61 | #if LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLOUT ||\ | ||
62 | LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLIN | ||
63 | // 1. Config PLL input clock | ||
64 | LPC_SYSCON->SYSPLLCLKSEL = LPC_SYSPLLCLKSEL; | ||
65 | // Switch Clock | ||
66 | LPC_SYSCON->SYSPLLCLKUEN = 0; | ||
67 | LPC_SYSCON->SYSPLLCLKUEN = SYSCON_SYSPLLCLKUEN_ENA; | ||
68 | |||
69 | #if LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLOUT | ||
70 | |||
71 | // 2. Config PLL | ||
72 | // Enable PLL power | ||
73 | LPC_SYSCON->PDRUNCFG &= (~SYSCON_PDRUNCFG_SYSPLL_PD); | ||
74 | // Apply PLL Config | ||
75 | LPC_SYSCON->SYSPLLCTRL = (LPC_SYSPLL_PSEL_VAL << SYSCON_SYSPLLCTRL_PSEL_POS) | ||
76 | | (LPC_SYSPLL_MSEL_VAL << SYSCON_SYSPLLCTRL_MSEL_POS); | ||
77 | // Wait for PLLLock | ||
78 | while(!(LPC_SYSCON->SYSPLLSTAT & SYSCON_SYSPLLSTAT_LOCK)){} | ||
79 | #endif // LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLOUT | ||
80 | |||
81 | #endif /* LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLOUT || | ||
82 | LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLIN */ | ||
83 | |||
84 | // Config SYSDIV | ||
85 | LPC_SYSCON->SYSAHBCLKDIV = LPC_SYS_DIV & 0xFF; | ||
86 | |||
87 | // Select Main Clock | ||
88 | LPC_SYSCON->MAINCLKSEL = LPC_MAINCLKSEL; | ||
89 | LPC_SYSCON->MAINCLKUEN = 0; | ||
90 | LPC_SYSCON->MAINCLKUEN = SYSCON_MAINCLKUEN_ENA; | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * @brief Low level HAL driver initialization. | ||
95 | * | ||
96 | * @notapi | ||
97 | */ | ||
98 | void hal_lld_init(void) { | ||
99 | lpc_clock_init(); | ||
100 | } | ||
101 | |||
102 | /** @} */ | ||