diff options
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/TIVA/TM4C123x/hal_lld.c')
-rw-r--r-- | lib/chibios-contrib/os/hal/ports/TIVA/TM4C123x/hal_lld.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/TIVA/TM4C123x/hal_lld.c b/lib/chibios-contrib/os/hal/ports/TIVA/TM4C123x/hal_lld.c new file mode 100644 index 000000000..10cd90333 --- /dev/null +++ b/lib/chibios-contrib/os/hal/ports/TIVA/TM4C123x/hal_lld.c | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | Copyright (C) 2014..2017 Marco Veeneman | ||
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 TIVA/TM4C123x/hal_lld.c | ||
19 | * @brief TM4C123x HAL Driver 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 | /* Driver exported variables. */ | ||
33 | /*===========================================================================*/ | ||
34 | |||
35 | /*===========================================================================*/ | ||
36 | /* Driver local variables and types. */ | ||
37 | /*===========================================================================*/ | ||
38 | |||
39 | /*===========================================================================*/ | ||
40 | /* Driver local functions. */ | ||
41 | /*===========================================================================*/ | ||
42 | |||
43 | /*===========================================================================*/ | ||
44 | /* Driver interrupt handlers. */ | ||
45 | /*===========================================================================*/ | ||
46 | |||
47 | /*===========================================================================*/ | ||
48 | /* Driver exported functions. */ | ||
49 | /*===========================================================================*/ | ||
50 | |||
51 | /** | ||
52 | * @brief Low level HAL driver initialization. | ||
53 | * | ||
54 | * @notapi | ||
55 | */ | ||
56 | void hal_lld_init(void) | ||
57 | { | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * @brief TM4C123x clocks and PLL initialization. | ||
62 | * @note All the involved constants come from the file @p board.h and | ||
63 | * @p mcuconf.h. | ||
64 | * @note This function should be invoked just after the system reset. | ||
65 | * | ||
66 | * @special | ||
67 | */ | ||
68 | void tiva_clock_init(void) | ||
69 | { | ||
70 | uint32_t rcc, rcc2, i; | ||
71 | |||
72 | /* 1. Bypass the PLL and system clock divider by setting the BYPASS bit and | ||
73 | * clearing the USESYSDIV bit in the RCC register, thereby configuring the | ||
74 | * microcontroller to run off a "raw" clock source and allowing for the new | ||
75 | * PLL configuration to be validated before switching the system clock to the | ||
76 | * PLL. */ | ||
77 | /* read */ | ||
78 | |||
79 | rcc = HWREG(SYSCTL_RCC); | ||
80 | rcc2 = HWREG(SYSCTL_RCC2); | ||
81 | |||
82 | /* modify */ | ||
83 | rcc |= SYSCTL_RCC_BYPASS; | ||
84 | rcc &= ~SYSCTL_RCC_USESYSDIV; | ||
85 | rcc2 |= SYSCTL_RCC2_BYPASS2 | SYSCTL_RCC2_USERCC2; | ||
86 | |||
87 | /* write */ | ||
88 | HWREG(SYSCTL_RCC) = rcc; | ||
89 | HWREG(SYSCTL_RCC2) = rcc2; | ||
90 | |||
91 | /* 2 Select the crystal value (XTAL) and oscillator source (OSCSRC), and | ||
92 | * clear the PWRDN bit in RCC and RCC2. Setting the XTAL field automatically | ||
93 | * pulls valid PLL configuration data for the appropriate crystal, and | ||
94 | * clearing the PWRDN bit powers and enables the PLL and its output. */ | ||
95 | /* modify */ | ||
96 | rcc &= ~(SYSCTL_RCC_OSCSRC_M | SYSCTL_RCC_XTAL_M | SYSCTL_RCC_PWRDN | SYSCTL_RCC_MOSCDIS); | ||
97 | rcc |= ((TIVA_XTAL | TIVA_OSCSRC | TIVA_MOSCDIS) & (SYSCTL_RCC_XTAL_M | SYSCTL_RCC_OSCSRC_M | SYSCTL_RCC_MOSCDIS)); | ||
98 | rcc2 &= ~(SYSCTL_RCC2_OSCSRC2_M | SYSCTL_RCC2_PWRDN2); | ||
99 | rcc2 |= ((TIVA_OSCSRC | TIVA_DIV400) & (SYSCTL_RCC2_OSCSRC2_M | SYSCTL_RCC2_DIV400)); | ||
100 | |||
101 | /* write */ | ||
102 | HWREG(SYSCTL_RCC) = rcc; | ||
103 | HWREG(SYSCTL_RCC2) = rcc2; | ||
104 | for(i = 100000; i; i--); | ||
105 | |||
106 | /* 3. Select the desired system divider (SYSDIV) in RCC and RCC2 and set the | ||
107 | * USESYSDIV bit in RCC. The SYSDIV field determines the system frequency for | ||
108 | * the microcontroller. */ | ||
109 | /* modify */ | ||
110 | rcc &= ~SYSCTL_RCC_SYSDIV_M; | ||
111 | rcc |= (TIVA_SYSDIV & SYSCTL_RCC_SYSDIV_M) | SYSCTL_RCC_USESYSDIV; | ||
112 | rcc2 &= ~(SYSCTL_RCC2_SYSDIV2_M | SYSCTL_RCC2_SYSDIV2LSB); | ||
113 | rcc2 |= ((TIVA_SYSDIV2 | TIVA_SYSDIV2LSB) & (SYSCTL_RCC2_SYSDIV2_M | SYSCTL_RCC2_SYSDIV2LSB)); | ||
114 | |||
115 | /* write */ | ||
116 | HWREG(SYSCTL_RCC) = rcc; | ||
117 | HWREG(SYSCTL_RCC2) = rcc2; | ||
118 | |||
119 | /* 4. Wait for the PLL to lock by polling the PLLLRIS bit in the Raw | ||
120 | * Interrupt Status (RIS) register. */ | ||
121 | while ((HWREG(SYSCTL_RIS) & SYSCTL_RIS_PLLLRIS) == 0); | ||
122 | |||
123 | /* 5. Enable use of the PLL by clearing the BYPASS bit in RCC and RCC2. */ | ||
124 | rcc &= ~SYSCTL_RCC_BYPASS; | ||
125 | rcc2 &= ~SYSCTL_RCC2_BYPASS2; | ||
126 | rcc |= (TIVA_BYPASS_VALUE << 11); | ||
127 | rcc2 |= (TIVA_BYPASS_VALUE << 11); | ||
128 | HWREG(SYSCTL_RCC) = rcc; | ||
129 | HWREG(SYSCTL_RCC2) = rcc2; | ||
130 | |||
131 | #if HAL_USE_PWM | ||
132 | HWREG(SYSCTL_RCC) |= TIVA_PWM_FIELDS; | ||
133 | #endif | ||
134 | |||
135 | #if defined(TIVA_UDMA_REQUIRED) | ||
136 | udmaInit(); | ||
137 | #endif | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * @} | ||
142 | */ | ||