aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/hal/ports/KINETIS/KL2x/hal_lld.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/KINETIS/KL2x/hal_lld.h')
-rw-r--r--lib/chibios-contrib/os/hal/ports/KINETIS/KL2x/hal_lld.h316
1 files changed, 316 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/KINETIS/KL2x/hal_lld.h b/lib/chibios-contrib/os/hal/ports/KINETIS/KL2x/hal_lld.h
new file mode 100644
index 000000000..388d204c2
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/ports/KINETIS/KL2x/hal_lld.h
@@ -0,0 +1,316 @@
1/*
2 ChibiOS - Copyright (C) 2013-2015 Fabio Utzig
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 KL2x/hal_lld.h
19 * @brief Kinetis KL2x HAL subsystem low level driver header.
20 *
21 * @addtogroup HAL
22 * @{
23 */
24
25#ifndef HAL_LLD_H_
26#define HAL_LLD_H_
27
28#include "kl2xz.h"
29#include "kinetis_registry.h"
30
31/*===========================================================================*/
32/* Driver constants. */
33/*===========================================================================*/
34
35/**
36 * @brief Defines the support for realtime counters in the HAL.
37 */
38#define HAL_IMPLEMENTS_COUNTERS FALSE
39
40/**
41 * @name Platform identification
42 * @{
43 */
44#define PLATFORM_NAME "Kinetis"
45/** @} */
46
47#if KINETIS_HAS_MCG_LITE
48/* MCU only has MCG_Lite */
49
50/**
51 * @name Internal clock sources
52 * @{
53 */
54#define KINETIS_HIRC 48000000 /**< High-frequency internal reference clock (USB recovery). */
55#define KINETIS_LIRC_8 8000000 /**< Low-frequency internal reference clock (faster). */
56#define KINETIS_LIRC_2 2000000 /**< Low-frequency internal reference clock (slower). */
57/** @} */
58
59/**
60 * @name MCG modes of operation
61 * @{
62 */
63#define KINETIS_MCGLITE_MODE_LIRC8M 1 /**< Low frequency internal reference mode (8MHz). */
64#define KINETIS_MCGLITE_MODE_LIRC2M 2 /**< Low frequency internal reference mode (2MHz). */
65#define KINETIS_MCGLITE_MODE_HIRC 3 /**< High frequency internal reference mode (with optional USB recovery). */
66#define KINETIS_MCGLITE_MODE_EXT 4 /**< External reference mode. */
67/** @} */
68
69#else /* KINETIS_HAS_MCG_LITE */
70/* MCU has full blown MCG */
71
72/**
73 * @name Internal clock sources
74 * @{
75 */
76#define KINETIS_IRCLK_F 4000000 /**< Fast internal reference clock, factory trimmed. */
77#define KINETIS_IRCLK_S 32768 /**< Slow internal reference clock, factory trimmed. */
78/** @} */
79
80/**
81 * @name MCG modes of operation
82 * @{
83 */
84#define KINETIS_MCG_MODE_FEI 1 /**< FLL Engaged Internal. */
85#define KINETIS_MCG_MODE_FEE 2 /**< FLL Engaged External. */
86#define KINETIS_MCG_MODE_FBI 3 /**< FLL Bypassed Internal. */
87#define KINETIS_MCG_MODE_FBE 4 /**< FLL Bypassed External. */
88#define KINETIS_MCG_MODE_PEE 5 /**< PLL Engaged External. */
89#define KINETIS_MCG_MODE_PBE 6 /**< PLL Bypassed External. */
90#define KINETIS_MCG_MODE_BLPI 7 /**< Bypassed Low Power Internal. */
91#define KINETIS_MCG_MODE_BLPE 8 /**< Bypassed Low Power External. */
92/** @} */
93
94#endif /* KINETIS_HAS_MCG_LITE */
95
96/*===========================================================================*/
97/* Driver pre-compile time settings. */
98/*===========================================================================*/
99
100/**
101 * @name Configuration options
102 * @{
103 */
104/**
105 * @brief Disables the MCG/system clock initialization in the HAL.
106 */
107#if !defined(KINETIS_NO_INIT) || defined(__DOXYGEN__)
108#define KINETIS_NO_INIT FALSE
109#endif
110
111/**
112 * @brief MCG mode selection.
113 */
114#if !defined(KINETIS_MCG_MODE) || defined(__DOXYGEN__)
115#define KINETIS_MCG_MODE KINETIS_MCG_MODE_PEE
116#endif
117
118#if !defined(KINETIS_MCGLITE_MODE) || defined(__DOXYGEN__)
119#define KINETIS_MCGLITE_MODE KINETIS_MCGLITE_MODE_HIRC
120#endif
121
122/**
123 * @brief MCU PLL clock frequency.
124 */
125#if !defined(KINETIS_PLLCLK_FREQUENCY) || defined(__DOXYGEN__)
126#define KINETIS_PLLCLK_FREQUENCY 96000000UL
127#endif
128
129/**
130 * @brief Clock divider for core/system and bus/flash clocks (OUTDIV1).
131 * @note The allowed range is 1...16.
132 * @note The default value is calculated for a 48 MHz system clock
133 * from a 96 MHz PLL output.
134 */
135#if !defined(KINETIS_CLKDIV1_OUTDIV1) || defined(__DOXYGEN__)
136 #if defined(KINETIS_SYSCLK_FREQUENCY) && KINETIS_SYSCLK_FREQUENCY > 0
137 #define KINETIS_CLKDIV1_OUTDIV1 (KINETIS_PLLCLK_FREQUENCY/KINETIS_SYSCLK_FREQUENCY)
138 #else
139 #define KINETIS_CLKDIV1_OUTDIV1 2
140 #endif
141#endif
142
143/**
144 * @brief Additional clock divider bus/flash clocks (OUTDIV4).
145 * @note The allowed range is 1...8.
146 * @note This divider is on top of the OUTDIV1 divider.
147 * @note The default value is calculated for 24 MHz bus/flash clocks
148 * from a 96 MHz PLL output and 48 MHz core/system clock.
149 */
150#if !defined(KINETIS_CLKDIV1_OUTDIV4) || defined(__DOXYGEN__)
151 #if defined(KINETIS_BUSCLK_FREQUENCY) && KINETIS_BUSCLK_FREQUENCY > 0
152 #define KINETIS_CLKDIV1_OUTDIV4 ((KINETIS_PLLCLK_FREQUENCY/KINETIS_CLKDIV1_OUTDIV1)/KINETIS_BUSCLK_FREQUENCY)
153 #else
154 #define KINETIS_CLKDIV1_OUTDIV4 2
155 #endif
156#endif
157
158/**
159 * @brief FLL DCO tuning enable for 32.768 kHz reference.
160 * @note Set to 1 for fine-tuning DCO for maximum frequency with
161 * a 32.768 kHz reference.
162 * @note The default value is for a 32.768 kHz external crystal.
163 */
164#if !defined(KINETIS_MCG_FLL_DMX32) || defined(__DOXYGEN__)
165#define KINETIS_MCG_FLL_DMX32 1
166#endif
167
168/**
169 * @brief FLL DCO range selection.
170 * @note The allowed range is 0...3.
171 * @note The default value is calculated for 48 MHz FLL output
172 * from a 32.768 kHz external crystal.
173 * (DMX32 && DRST_DRS=1 => F=1464; 32.768 kHz * F ~= 48 MHz.)
174 *
175 */
176#if !defined(KINETIS_MCG_FLL_DRS) || defined(__DOXYGEN__)
177#define KINETIS_MCG_FLL_DRS 2
178#endif
179
180/**
181 * @brief MCU system/core clock frequency.
182 */
183#if !defined(KINETIS_SYSCLK_FREQUENCY) || defined(__DOXYGEN__)
184#define KINETIS_SYSCLK_FREQUENCY (KINETIS_PLLCLK_FREQUENCY / KINETIS_CLKDIV1_OUTDIV1)
185#endif
186
187/**
188 * @brief MCU bus/flash clock frequency.
189 */
190#if !defined(KINETIS_BUSCLK_FREQUENCY) || defined(__DOXYGEN__)
191#define KINETIS_BUSCLK_FREQUENCY (KINETIS_SYSCLK_FREQUENCY / KINETIS_CLKDIV1_OUTDIV4)
192#endif
193
194/**
195 * @brief UART0 clock frequency.
196 * @note The default value is based on 96 MHz PLL/2 source.
197 * If you use a different source, such as the FLL,
198 * you must set this properly.
199 */
200#if !defined(KINETIS_UART0_CLOCK_FREQ) || defined(__DOXYGEN__)
201#define KINETIS_UART0_CLOCK_FREQ KINETIS_SYSCLK_FREQUENCY
202#endif
203
204/**
205 * @brief UART0 clock source.
206 * @note The default value is to use PLL/2 or FLL source.
207 */
208#if !defined(KINETIS_UART0_CLOCK_SRC) || defined(__DOXYGEN__)
209#define KINETIS_UART0_CLOCK_SRC 1
210#endif
211
212/** @} */
213
214/*===========================================================================*/
215/* Derived constants and error checks. */
216/*===========================================================================*/
217
218#if !defined(KINETIS_SYSCLK_FREQUENCY)
219#error KINETIS_SYSCLK_FREQUENCY must be defined
220#endif
221
222#if KINETIS_SYSCLK_FREQUENCY <= 0 || KINETIS_SYSCLK_FREQUENCY > KINETIS_SYSCLK_MAX
223#error KINETIS_SYSCLK_FREQUENCY out of range
224#endif
225
226#if !defined(KINETIS_BUSCLK_FREQUENCY)
227#error KINETIS_BUSCLK_FREQUENCY must be defined
228#endif
229
230#if KINETIS_BUSCLK_FREQUENCY <= 0 || KINETIS_BUSCLK_FREQUENCY > KINETIS_BUSCLK_MAX
231#error KINETIS_BUSCLK_FREQUENCY out of range
232#endif
233
234#if KINETIS_BUSCLK_FREQUENCY > KINETIS_SYSCLK_FREQUENCY
235 #error KINETIS_BUSCLK_FREQUENCY must be an integer divide of\
236 KINETIS_SYSCLK_FREQUENCY
237#endif
238
239
240#if !(defined(KINETIS_CLKDIV1_OUTDIV1) && \
241 KINETIS_CLKDIV1_OUTDIV1 >= 1 && KINETIS_CLKDIV1_OUTDIV1 <= 16)
242 #error KINETIS_CLKDIV1_OUTDIV1 must be 1 through 16
243#endif
244
245#if !(defined(KINETIS_CLKDIV1_OUTDIV4) && \
246 KINETIS_CLKDIV1_OUTDIV4 >= 1 && KINETIS_CLKDIV1_OUTDIV4 <= 16)
247#error KINETIS_CLKDIV1_OUTDIV4 must be 1 through 16
248#endif
249
250#if !(KINETIS_MCG_FLL_DMX32 == 0 || KINETIS_MCG_FLL_DMX32 == 1)
251#error Invalid KINETIS_MCG_FLL_DMX32 value, must be 0 or 1
252#endif
253
254#if !(0 <= KINETIS_MCG_FLL_DRS && KINETIS_MCG_FLL_DRS <= 3)
255#error Invalid KINETIS_MCG_FLL_DRS value, must be 0...3
256#endif
257
258/*===========================================================================*/
259/* Driver data structures and types. */
260/*===========================================================================*/
261
262/**
263 * @brief Type representing a system clock frequency.
264 */
265typedef uint32_t halclock_t;
266
267/**
268 * @brief Type of the realtime free counter value.
269 */
270typedef uint32_t halrtcnt_t;
271
272/*===========================================================================*/
273/* Driver macros. */
274/*===========================================================================*/
275
276/**
277 * @brief Returns the current value of the system free running counter.
278 * @note This service is implemented by returning the content of the
279 * DWT_CYCCNT register.
280 *
281 * @return The value of the system free running counter of
282 * type halrtcnt_t.
283 *
284 * @notapi
285 */
286#define hal_lld_get_counter_value() 0
287
288/**
289 * @brief Realtime counter frequency.
290 * @note The DWT_CYCCNT register is incremented directly by the system
291 * clock so this function returns STM32_HCLK.
292 *
293 * @return The realtime counter frequency of type halclock_t.
294 *
295 * @notapi
296 */
297#define hal_lld_get_counter_frequency() 0
298
299/*===========================================================================*/
300/* External declarations. */
301/*===========================================================================*/
302
303#include "nvic.h"
304
305#ifdef __cplusplus
306extern "C" {
307#endif
308 void hal_lld_init(void);
309 void kl2x_clock_init(void);
310#ifdef __cplusplus
311}
312#endif
313
314#endif /* HAL_LLD_H_ */
315
316/** @} */