aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/hal/ports/ADUCM/ADUCM41x/hal_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/hal/ports/ADUCM/ADUCM41x/hal_lld.c')
-rw-r--r--lib/chibios/os/hal/ports/ADUCM/ADUCM41x/hal_lld.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/ADUCM/ADUCM41x/hal_lld.c b/lib/chibios/os/hal/ports/ADUCM/ADUCM41x/hal_lld.c
new file mode 100644
index 000000000..a3fec54ec
--- /dev/null
+++ b/lib/chibios/os/hal/ports/ADUCM/ADUCM41x/hal_lld.c
@@ -0,0 +1,133 @@
1/*
2 ChibiOS - Copyright (C) 2019 Rocco Marco Guglielmi
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 ADUCM41x/hal_lld.c
19 * @brief ADUCM41x HAL subsystem low level driver source.
20 *
21 * @addtogroup HAL
22 * @{
23 */
24
25#include "hal.h"
26
27/*===========================================================================*/
28/* Driver local definitions. */
29/*===========================================================================*/
30
31/**
32 * @brief Reset value of the CLKCON0 register.
33 */
34#define ADUCM_CLKCON0_RESET 0x043CU
35
36/**
37 * @brief Reset value of the CLKCON0 register.
38 */
39#define ADUCM_CLKCON1_RESET 0x0048U
40
41/*===========================================================================*/
42/* Driver exported variables. */
43/*===========================================================================*/
44
45/**
46 * @brief CMSIS system core clock variable.
47 * @note It is declared in system_ADuCM41x.h.
48 */
49uint32_t SystemCoreClock = ADUCM_HCLK;
50
51/*===========================================================================*/
52/* Driver local variables and types. */
53/*===========================================================================*/
54
55/*===========================================================================*/
56/* Driver local functions. */
57/*===========================================================================*/
58
59/*===========================================================================*/
60/* Driver interrupt handlers. */
61/*===========================================================================*/
62
63/*===========================================================================*/
64/* Driver exported functions. */
65/*===========================================================================*/
66
67/**
68 * @brief Low level HAL driver initialization.
69 *
70 * @notapi
71 */
72void hal_lld_init(void) {
73
74 /* DMA subsystems initialization.*/
75#if defined(ADUCM_DMA_REQUIRED)
76 dmaInit();
77#endif
78
79 /* IRQ subsystem initialization.*/
80 irqInit();
81
82 /* Disabling Watchdog timer which is enabled by default. */
83#if HAL_CFG_DISABLE_WDG
84 pADI_WDT->CON = 0;
85#endif
86}
87
88/**
89 * @brief ADUCM clocks and PLL initialization.
90 * @note All the involved constants come from the file @p board.h.
91 * @note This function should be invoked just after the system reset.
92 *
93 * @special
94 */
95void aducm_clock_init(void) {
96
97#if !ADUCM_NO_INIT
98
99 /* Switching the clock source to the internal oscillator. */
100 pADI_CLK->CLKCON0 = ADUCM_CLKMUX_HFOSC;
101
102 /* Configuring the clock sources. */
103 pADI_CLK->CLKCON0 |= ADUCM_CLKOUT | ADUCM_AMUX | ADUCM_ANAROOT;
104
105 /* Managing the clock dividers. */
106 pADI_CLK->CLKCON1 = ADUCM_CDHCLK_DIV | ADUCM_CDPCLK0_DIV |
107 ADUCM_CDPCLK1_DIV | ADUCM_CDANACLK_DIV;
108
109#if((ADUCM_CLKMUX == ADUCM_CLKMUX_SPLL) || \
110 (ADUCM_CLKOUT == ADUCM_CLKOUT_SPLL) || \
111 (ADUCM_ANAROOT == ADUCM_ANAROOT_SPLL))
112
113 /* Enabling PLL auto-gate.*/
114 pADI_PLL->PLLPDCTRL |= BITM_PLL_MMRS_PLLPDCTRL_TOTPDB;
115#endif
116
117 /* Changing the clock source. Note that the field is already zeroed by the
118 previous configuration. */
119 pADI_CLK->CLKCON0 |= ADUCM_CLKMUX;
120
121#if((ADUCM_CLKMUX == ADUCM_CLKMUX_SPLL) || \
122 (ADUCM_CLKOUT == ADUCM_CLKOUT_SPLL) || \
123 (ADUCM_ANAROOT == ADUCM_ANAROOT_SPLL))
124
125 /* Waits until the SPLL is stable */
126 while ((pADI_CLK->CLKSTAT0 & ADUCM_SPLL_STA_MASK) == ADUCM_SPLL_STA_UNLOCKED)
127 ;
128#endif
129
130
131#endif /* !ADUCM_NO_INIT */
132}
133/** @} */