diff options
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.h')
-rw-r--r-- | lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.h | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.h b/lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.h new file mode 100644 index 000000000..9ed343e3e --- /dev/null +++ b/lib/chibios-contrib/os/hal/ports/LPC/LPC11Uxx/hal_lld.h | |||
@@ -0,0 +1,161 @@ | |||
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 LPC11Uxx/hal_lld.h | ||
19 | * @brief NXP LPC 11Uxx HAL subsystem low level driver header. | ||
20 | * | ||
21 | * @addtogroup HAL | ||
22 | * @{ | ||
23 | */ | ||
24 | #ifndef HAL_LLD_H | ||
25 | #define HAL_LLD_H | ||
26 | |||
27 | #include "LPC11Uxx.h" | ||
28 | #include "lpc_registry.h" | ||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver constants. */ | ||
32 | /*===========================================================================*/ | ||
33 | |||
34 | /** | ||
35 | * @name Platform identification macros | ||
36 | * @{ | ||
37 | */ | ||
38 | #define PLATFORM_NAME "LPC" | ||
39 | /** @} */ | ||
40 | |||
41 | |||
42 | /** | ||
43 | * @name PLATFORM configuration options | ||
44 | * @{ | ||
45 | */ | ||
46 | #define LPC_IRC_FREQUENCY 12000000UL // 12MHz | ||
47 | /** @} */ | ||
48 | |||
49 | /*===========================================================================*/ | ||
50 | /* Derived constants and error checks. */ | ||
51 | /*===========================================================================*/ | ||
52 | |||
53 | /* | ||
54 | * Configuration-related checks. | ||
55 | */ | ||
56 | #if !defined(LPC11Uxx_MCUCONF) && !defined(LPC11U35_MCUCONF) && \ | ||
57 | !defined(LPC11U35_401_MCUCONF) | ||
58 | #error "Using a wrong mcuconf.h file, LPC11Uxx_MCUCONF not defined" | ||
59 | #endif | ||
60 | |||
61 | #if defined(LPC_USE_SYSOSC) && LPC_USE_SYSOSC != FALSE && !defined(LPC_SYSOSC_FREQUENCY) | ||
62 | #error "LPC_SYSOSC_FREQUENCY must be defined if LPC_USE_SYSOSC" | ||
63 | #endif | ||
64 | |||
65 | // SYSTEMPLL SEL | ||
66 | #if defined(LPC_SYSPLLCLKSEL) && LPC_SYSPLLCLKSEL == SYSCON_SYSPLLCLKSEL_IRC | ||
67 | #define LPC_SYSPLLIN_FREQUENCY (LPC_IRC_FREQUENCY) | ||
68 | #elif defined(LPC_SYSPLLCLKSEL) && LPC_SYSPLLCLKSEL == SYSCON_SYSPLLCLKSEL_SYSOSC | ||
69 | #ifndef LPC_USE_SYSOSC | ||
70 | #error "LPC_USE_SYSOSC must be defined when using SYSOSC" | ||
71 | #endif | ||
72 | #define LPC_SYSPLLIN_FREQUENCY (LPC_SYSOSC_FREQUENCY) | ||
73 | #else | ||
74 | #error "LPC_SYSPLLCLKSEL must be one of SYSCON_SYSPLLCLKSEL_IRC, \ | ||
75 | SYSCON_SYSPLLCLKSEL_SYSOSC" | ||
76 | #endif | ||
77 | |||
78 | #if defined(LPC_MAINCLKSEL) && LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_IRC | ||
79 | // Using Internal OSC | ||
80 | #define LPC_MAINCLK_FREQUENCY (LPC_IRC_FREQUENCY) | ||
81 | |||
82 | #elif defined(LPC_MAINCLKSEL) && LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLIN | ||
83 | #define LPC_MAINCLK_FREQUENCY (LPC_SYSPLLIN_FREQUENCY) | ||
84 | #elif defined(LPC_MAINCLKSEL) && LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_WATCHDOG | ||
85 | |||
86 | #error "Unsupported clock select" | ||
87 | |||
88 | #elif defined(LPC_MAINCLKSEL) && LPC_MAINCLKSEL == SYSCON_MAINCLKSEL_PLLOUT | ||
89 | // PLL OUT | ||
90 | #if defined(LPC_SYSPLL_MULT) && LPC_SYSPLL_MULT > 0 && LPC_SYSPLL_MULT <= 32 \ | ||
91 | && defined(LPC_SYSPLL_PDIV) && (LPC_SYSPLL_PDIV == 2 || LPC_SYSPLL_PDIV == 4 \ | ||
92 | || LPC_SYSPLL_PDIV == 8 || LPC_SYSPLL_PDIV == 16) | ||
93 | |||
94 | #if LPC_SYSPLL_PDIV == 2 | ||
95 | #define LPC_SYSPLL_PSEL_VAL 0x0U | ||
96 | #elif LPC_SYSPLL_PDIV == 4 | ||
97 | #define LPC_SYSPLL_PSEL_VAL 0x1U | ||
98 | #elif LPC_SYSPLL_PDIV == 8 | ||
99 | #define LPC_SYSPLL_PSEL_VAL 0x2U | ||
100 | #elif LPC_SYSPLL_PDIV == 16 | ||
101 | #define LPC_SYSPLL_PSEL_VAL 0x3U | ||
102 | #else | ||
103 | #error "INVALID PDIV VALUE" | ||
104 | #endif //LPC_SYSPLL_PDIV == xx | ||
105 | |||
106 | #if (LPC_SYSPLLIN_FREQUENCY * LPC_SYSPLL_MULT * LPC_SYSPLL_PDIV < 156000000UL) ||\ | ||
107 | (LPC_SYSPLLIN_FREQUENCY * LPC_SYSPLL_MULT * LPC_SYSPLL_PDIV > 320000000UL) | ||
108 | #error "Please check the documentation about how to pick MULT and PDIV. \ | ||
109 | current value gives a out of range CCO frequency" | ||
110 | #endif | ||
111 | |||
112 | #define LPC_MAINCLK_FREQUENCY (LPC_SYSPLLIN_FREQUENCY * LPC_SYSPLL_MULT) | ||
113 | #define LPC_SYSPLL_MSEL_VAL (LPC_SYSPLL_MULT - 1) | ||
114 | |||
115 | #else | ||
116 | #error "LPC_SYSPLL_MULT must be defined and btween 1 and 32, \ | ||
117 | LPC_SYSPLL_PDIV must be one of 2, 4, 8, 16." | ||
118 | #endif | ||
119 | #else | ||
120 | #error "Invalid LPC_MAINCLKSEL. Must be one of SYSCON_MAINCLKSEL_IRC, \ | ||
121 | SYSCON_MAINCLKSEL_PLLIN, SYSCON_MAINCLKSEL_WATCHDOG, SYSCON_MAINCLKSEL_PLLOUT" | ||
122 | #endif | ||
123 | |||
124 | #if !defined(LPC_SYS_DIV) || LPC_SYS_DIV < 1 || LPC_SYS_DIV > 255 | ||
125 | #error "LPC_SYS_DIV must be between 1 and 255" | ||
126 | #else | ||
127 | #define LPC_SYS_FREQUENCY (LPC_MAINCLK_FREQUENCY / LPC_SYS_DIV) | ||
128 | #endif | ||
129 | |||
130 | /*===========================================================================*/ | ||
131 | /* Driver data structures and types. */ | ||
132 | /*===========================================================================*/ | ||
133 | |||
134 | /*===========================================================================*/ | ||
135 | /* Driver macros. */ | ||
136 | /*===========================================================================*/ | ||
137 | |||
138 | /*===========================================================================*/ | ||
139 | /* External declarations. */ | ||
140 | /*===========================================================================*/ | ||
141 | |||
142 | |||
143 | /*===========================================================================*/ | ||
144 | /* External declarations. */ | ||
145 | /*===========================================================================*/ | ||
146 | |||
147 | #include "nvic.h" | ||
148 | |||
149 | #ifdef __cplusplus | ||
150 | extern "C" { | ||
151 | #endif | ||
152 | void hal_lld_init(void); | ||
153 | void lpc_clock_init(void); | ||
154 | #ifdef __cplusplus | ||
155 | } | ||
156 | #endif | ||
157 | |||
158 | #endif /* HAL_LLD_H_ */ | ||
159 | |||
160 | /** @} */ | ||
161 | |||