diff options
Diffstat (limited to 'lib/chibios/os/hal/ports/LPC/LPC214x/hal_lld.c')
-rw-r--r-- | lib/chibios/os/hal/ports/LPC/LPC214x/hal_lld.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/LPC/LPC214x/hal_lld.c b/lib/chibios/os/hal/ports/LPC/LPC214x/hal_lld.c new file mode 100644 index 000000000..937003889 --- /dev/null +++ b/lib/chibios/os/hal/ports/LPC/LPC214x/hal_lld.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
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 LPC214x/hal_lld.c | ||
19 | * @brief LPC214x HAL subsystem low level driver source. | ||
20 | * | ||
21 | * @addtogroup HAL | ||
22 | * @{ | ||
23 | */ | ||
24 | |||
25 | #include "hal.h" | ||
26 | |||
27 | /*===========================================================================*/ | ||
28 | /* Driver exported variables. */ | ||
29 | /*===========================================================================*/ | ||
30 | |||
31 | /*===========================================================================*/ | ||
32 | /* Driver local variables and types. */ | ||
33 | /*===========================================================================*/ | ||
34 | |||
35 | /*===========================================================================*/ | ||
36 | /* Driver local functions. */ | ||
37 | /*===========================================================================*/ | ||
38 | |||
39 | /*===========================================================================*/ | ||
40 | /* Driver interrupt handlers. */ | ||
41 | /*===========================================================================*/ | ||
42 | |||
43 | /* | ||
44 | * Non-vectored IRQs handler, the default action can be overridden by | ||
45 | * redefining the @p LPC214x_NON_VECTORED_IRQ_HOOK() hook macro. | ||
46 | */ | ||
47 | static CH_IRQ_HANDLER(irq_handler) { | ||
48 | |||
49 | CH_IRQ_PROLOGUE(); | ||
50 | |||
51 | LPC214x_NON_VECTORED_IRQ_HOOK(); | ||
52 | |||
53 | VICVectAddr = 0; | ||
54 | CH_IRQ_EPILOGUE(); | ||
55 | } | ||
56 | |||
57 | /*===========================================================================*/ | ||
58 | /* Driver exported functions. */ | ||
59 | /*===========================================================================*/ | ||
60 | |||
61 | /** | ||
62 | * @brief Low level HAL driver initialization. | ||
63 | * | ||
64 | * @notapi | ||
65 | */ | ||
66 | void hal_lld_init(void) { | ||
67 | |||
68 | vic_init(); | ||
69 | VICDefVectAddr = (IOREG32)irq_handler; | ||
70 | |||
71 | } | ||
72 | |||
73 | /** | ||
74 | * @brief LPC214x clocks and PLL initialization. | ||
75 | * @note All the involved constants come from the file @p board.h. | ||
76 | * @note This function must be invoked only after the system reset. | ||
77 | * | ||
78 | * @special | ||
79 | */ | ||
80 | void lpc214x_clock_init(void) { | ||
81 | |||
82 | /* | ||
83 | * All peripherals clock disabled by default in order to save power. | ||
84 | */ | ||
85 | PCONP = PCRTC | PCTIM0; | ||
86 | |||
87 | /* | ||
88 | * MAM setup. | ||
89 | */ | ||
90 | MAMTIM = 0x3; /* 3 cycles for flash accesses. */ | ||
91 | MAMCR = 0x2; /* MAM fully enabled. */ | ||
92 | |||
93 | /* | ||
94 | * PLL setup for Fosc=12MHz and CCLK=48MHz. | ||
95 | * P=2 M=3. | ||
96 | */ | ||
97 | PLL *pll = PLL0Base; | ||
98 | pll->PLL_CFG = 0x23; /* P and M values. */ | ||
99 | pll->PLL_CON = 0x1; /* Enables the PLL 0. */ | ||
100 | pll->PLL_FEED = 0xAA; | ||
101 | pll->PLL_FEED = 0x55; | ||
102 | while (!(pll->PLL_STAT & 0x400)) | ||
103 | ; /* Wait for PLL lock. */ | ||
104 | |||
105 | pll->PLL_CON = 0x3; /* Connects the PLL. */ | ||
106 | pll->PLL_FEED = 0xAA; | ||
107 | pll->PLL_FEED = 0x55; | ||
108 | |||
109 | /* | ||
110 | * VPB setup. | ||
111 | * PCLK = CCLK / 4. | ||
112 | */ | ||
113 | VPBDIV = VPD_D4; | ||
114 | } | ||
115 | |||
116 | /** @} */ | ||