4 #if CONF_CORE_CLK_XOSC0_FREQUENCY > 24000000
5 #define CONF_CORE_CLK_XOSC0_IPTAT (3)
6 #define CONF_CORE_CLK_XOSC0_IMULT (6)
7 #define CONF_CORE_CLK_XOSC0_CFDPRESC (0x0)
8 #elif CONF_CORE_CLK_XOSC0_FREQUENCY > 16000000
9 #define CONF_CORE_CLK_XOSC0_IPTAT (3)
10 #define CONF_CORE_CLK_XOSC0_IMULT (5)
11 #define CONF_CORE_CLK_XOSC0_CFDPRESC (0x1)
12 #elif CONF_CORE_CLK_XOSC0_FREQUENCY > 8000000
13 #define CONF_CORE_CLK_XOSC0_IPTAT (3)
14 #define CONF_CORE_CLK_XOSC0_IMULT (4)
15 #define CONF_CORE_CLK_XOSC0_CFDPRESC (0x2)
17 #define CONF_CORE_CLK_XOSC0_IPTAT (2)
18 #define CONF_CORE_CLK_XOSC0_IMULT (3)
19 #define CONF_CORE_CLK_XOSC0_CFDPRESC (0x3)
22 #if CONF_CORE_CLK_XOSC1_FREQUENCY > 24000000
23 #define CONF_CORE_CLK_XOSC1_IPTAT (3)
24 #define CONF_CORE_CLK_XOSC1_IMULT (6)
25 #define CONF_CORE_CLK_XOSC1_CFDPRESC (0x0)
26 #elif CONF_CORE_CLK_XOSC1_FREQUENCY > 16000000
27 #define CONF_CORE_CLK_XOSC1_IPTAT (3)
28 #define CONF_CORE_CLK_XOSC1_IMULT (5)
29 #define CONF_CORE_CLK_XOSC1_CFDPRESC (0x1)
30 #elif CONF_CORE_CLK_XOSC1_FREQUENCY > 8000000
31 #define CONF_CORE_CLK_XOSC1_IPTAT (3)
32 #define CONF_CORE_CLK_XOSC1_IMULT (4)
33 #define CONF_CORE_CLK_XOSC1_CFDPRESC (0x2)
35 #define CONF_CORE_CLK_XOSC1_IPTAT (2)
36 #define CONF_CORE_CLK_XOSC1_IMULT (3)
37 #define CONF_CORE_CLK_XOSC1_CFDPRESC (0x3)
40 void clock_osc32k_init(
void)
42 #if CONF_CORE_CLK_XOSC32K_ENABLE == 1
43 OSC32KCTRL->XOSC32K.bit.CGM = CONF_CORE_CLK_XOSC32K_CGM;
44 OSC32KCTRL->XOSC32K.bit.WRTLOCK = CONF_CORE_CLK_XOSC32K_WRTLOCK;
45 OSC32KCTRL->XOSC32K.bit.STARTUP = CONF_CORE_CLK_XOSC32K_STARTUP_TIME;
46 OSC32KCTRL->XOSC32K.bit.RUNSTDBY = CONF_CORE_CLK_XOSC32K_RUNSTDBY;
47 OSC32KCTRL->XOSC32K.bit.ONDEMAND = CONF_CORE_CLK_XOSC32K_ONDEMAND;
48 OSC32KCTRL->XOSC32K.bit.EN1K = CONF_CORE_CLK_XOSC32K_EN1K;
49 OSC32KCTRL->XOSC32K.bit.EN32K = CONF_CORE_CLK_XOSC32K_EN32K;
50 OSC32KCTRL->XOSC32K.bit.XTALEN = CONF_CORE_CLK_XOSC32K_XTALEN;
51 OSC32KCTRL->CFDCTRL.bit.CFDPRESC = CONF_CORE_CLK_XOSC32K_CFDPRESC;
52 OSC32KCTRL->CFDCTRL.bit.SWBACK = CONF_CORE_CLK_XOSC32K_SWBACK;
53 OSC32KCTRL->CFDCTRL.bit.CFDEN = CONF_CORE_CLK_XOSC32K_CFDEN;
55 #if CONF_CORE_CLK_XOSC32K_ENABLE == 1 && CONF_CORE_CLK_XOSC32K_ONDEMAND == 0
61 void clock_osc_init(
void)
63 #if CONF_CORE_CLK_XOSC0_ENABLE == 1
64 CRITICAL_SECTION_ENTER();
65 OSCCTRL->XOSCCTRL[0].bit.XTALEN = CONF_CORE_CLK_XOSC0_XTALEN;
66 OSCCTRL->XOSCCTRL[0].bit.RUNSTDBY = CONF_CORE_CLK_XOSC0_RUNSTDBY;
67 OSCCTRL->XOSCCTRL[0].bit.ONDEMAND = CONF_CORE_CLK_XOSC0_ONDEMAND;
68 OSCCTRL->XOSCCTRL[0].bit.LOWBUFGAIN = CONF_CORE_CLK_XOSC0_LOWBUFGAIN;
69 OSCCTRL->XOSCCTRL[0].bit.IPTAT = CONF_CORE_CLK_XOSC0_IPTAT;
70 OSCCTRL->XOSCCTRL[0].bit.IMULT = CONF_CORE_CLK_XOSC0_IMULT;
71 OSCCTRL->XOSCCTRL[0].bit.ENALC = CONF_CORE_CLK_XOSC0_ENALC;
72 OSCCTRL->XOSCCTRL[0].bit.CFDEN = CONF_CORE_CLK_XOSC0_CFDEN;
73 OSCCTRL->XOSCCTRL[0].bit.CFDPRESC = CONF_CORE_CLK_XOSC0_CFDPRESC;
74 OSCCTRL->XOSCCTRL[0].bit.SWBEN = CONF_CORE_CLK_XOSC0_SWBEN;
75 OSCCTRL->XOSCCTRL[0].bit.STARTUP = CONF_CORE_CLK_XOSC0_STARTUP_TIME;
76 OSCCTRL->XOSCCTRL[0].bit.ENABLE = CONF_CORE_CLK_XOSC0_ENABLE;
77 CRITICAL_SECTION_LEAVE();
78 while(0 ==
OSCCTRL->STATUS.bit.XOSCRDY0);
81 #if CONF_CORE_CLK_XOSC1_ENABLE == 1
82 CRITICAL_SECTION_ENTER();
83 OSCCTRL->XOSCCTRL[1].bit.XTALEN = CONF_CORE_CLK_XOSC1_XTALEN;
84 OSCCTRL->XOSCCTRL[1].bit.RUNSTDBY = CONF_CORE_CLK_XOSC1_RUNSTDBY;
85 OSCCTRL->XOSCCTRL[1].bit.LOWBUFGAIN = CONF_CORE_CLK_XOSC1_LOWBUFGAIN;
86 OSCCTRL->XOSCCTRL[1].bit.IPTAT = CONF_CORE_CLK_XOSC1_IPTAT;
87 OSCCTRL->XOSCCTRL[1].bit.IMULT = CONF_CORE_CLK_XOSC1_IMULT;
88 OSCCTRL->XOSCCTRL[1].bit.CFDEN = CONF_CORE_CLK_XOSC1_CFDEN;
89 OSCCTRL->XOSCCTRL[1].bit.CFDPRESC = CONF_CORE_CLK_XOSC1_CFDPRESC;
90 OSCCTRL->XOSCCTRL[1].bit.SWBEN = CONF_CORE_CLK_XOSC1_SWBEN;
91 OSCCTRL->XOSCCTRL[1].bit.STARTUP = CONF_CORE_CLK_XOSC1_STARTUP_TIME;
92 OSCCTRL->XOSCCTRL[1].bit.ENABLE = CONF_CORE_CLK_XOSC1_ENABLE;
93 CRITICAL_SECTION_LEAVE();
94 while(0 ==
OSCCTRL->STATUS.bit.XOSCRDY1);
97 #if CONF_CORE_CLK_XOSC0_ENABLE == 1
98 CRITICAL_SECTION_ENTER();
99 #if CONF_CORE_CLK_XOSC0_ENALC == 1
100 OSCCTRL->XOSCCTRL[0].bit.ENALC = CONF_CORE_CLK_XOSC0_ENALC;
103 #if CONF_CORE_CLK_XOSC0_ONDEMAND == 1
104 OSCCTRL->XOSCCTRL[0].bit.ONDEMAND = CONF_CORE_CLK_XOSC0_ONDEMAND;
106 CRITICAL_SECTION_LEAVE();
109 #if CONF_CORE_CLK_XOSC1_ENABLE == 1
110 CRITICAL_SECTION_ENTER();
111 #if CONF_CORE_CLK_XOSC1_ENALC == 1
112 OSCCTRL->XOSCCTRL[1].bit.ENALC = CONF_CORE_CLK_XOSC1_ENALC;
115 #if CONF_CORE_CLK_XOSC1_ONDEMAND == 1
116 OSCCTRL->XOSCCTRL[1].bit.ONDEMAND = CONF_CORE_CLK_XOSC1_ONDEMAND;
118 CRITICAL_SECTION_LEAVE();
122 void clock_mclk_init(
void)
124 CRITICAL_SECTION_ENTER();
126 CRITICAL_SECTION_LEAVE();
129 void clock_gclk_init(
void)
131 #if CONF_CORE_GCLK_0_ENABLE == 1
132 CRITICAL_SECTION_ENTER();
133 GCLK->GENCTRL[0].bit.DIV = CONF_CORE_GCLK_0_DIV_VAL;
134 GCLK->GENCTRL[0].bit.DIVSEL = CONF_CORE_GCLK_0_DIVSEL;
135 GCLK->GENCTRL[0].bit.RUNSTDBY = CONF_CORE_GCLK_0_RUN_IN_STANDBY;
136 GCLK->GENCTRL[0].bit.OE = CONF_CORE_GCLK_0_OUTPUT_ENABLE;
137 GCLK->GENCTRL[0].bit.OOV = CONF_CORE_GCLK_0_DIVSEL;
138 GCLK->GENCTRL[0].bit.IDC = CONF_CORE_GCLK_0_IDC;
139 GCLK->GENCTRL[0].bit.GENEN = CONF_CORE_GCLK_0_ENABLE;
140 GCLK->GENCTRL[0].bit.SRC = CONF_CORE_GCLK_0_CLOCK_SOURCE;
141 CRITICAL_SECTION_LEAVE();
143 #if CONF_CORE_GCLK_1_ENABLE == 1
144 CRITICAL_SECTION_ENTER();
145 GCLK->GENCTRL[1].bit.DIV = CONF_CORE_GCLK_1_DIV_VAL;
146 GCLK->GENCTRL[1].bit.DIVSEL = CONF_CORE_GCLK_1_DIVSEL;
147 GCLK->GENCTRL[1].bit.RUNSTDBY = CONF_CORE_GCLK_1_RUN_IN_STANDBY;
148 GCLK->GENCTRL[1].bit.OE = CONF_CORE_GCLK_1_OUTPUT_ENABLE;
149 GCLK->GENCTRL[1].bit.OOV = CONF_CORE_GCLK_1_DIVSEL;
150 GCLK->GENCTRL[1].bit.IDC = CONF_CORE_GCLK_1_IDC;
151 GCLK->GENCTRL[1].bit.GENEN = CONF_CORE_GCLK_1_ENABLE;
152 GCLK->GENCTRL[1].bit.SRC = CONF_CORE_GCLK_1_CLOCK_SOURCE;
153 CRITICAL_SECTION_LEAVE();
155 #if CONF_CORE_GCLK_2_ENABLE == 1
156 CRITICAL_SECTION_ENTER();
157 GCLK->GENCTRL[2].bit.DIV = CONF_CORE_GCLK_2_DIV_VAL;
158 GCLK->GENCTRL[2].bit.DIVSEL = CONF_CORE_GCLK_2_DIVSEL;
159 GCLK->GENCTRL[2].bit.RUNSTDBY = CONF_CORE_GCLK_2_RUN_IN_STANDBY;
160 GCLK->GENCTRL[2].bit.OE = CONF_CORE_GCLK_2_OUTPUT_ENABLE;
161 GCLK->GENCTRL[2].bit.OOV = CONF_CORE_GCLK_2_DIVSEL;
162 GCLK->GENCTRL[2].bit.IDC = CONF_CORE_GCLK_2_IDC;
163 GCLK->GENCTRL[2].bit.GENEN = CONF_CORE_GCLK_2_ENABLE;
164 GCLK->GENCTRL[2].bit.SRC = CONF_CORE_GCLK_2_CLOCK_SOURCE;
165 CRITICAL_SECTION_LEAVE();
167 #if CONF_CORE_GCLK_3_ENABLE == 1
168 CRITICAL_SECTION_ENTER();
169 GCLK->GENCTRL[3].bit.DIV = CONF_CORE_GCLK_3_DIV_VAL;
170 GCLK->GENCTRL[3].bit.DIVSEL = CONF_CORE_GCLK_3_DIVSEL;
171 GCLK->GENCTRL[3].bit.RUNSTDBY = CONF_CORE_GCLK_3_RUN_IN_STANDBY;
172 GCLK->GENCTRL[3].bit.OE = CONF_CORE_GCLK_3_OUTPUT_ENABLE;
173 GCLK->GENCTRL[3].bit.OOV = CONF_CORE_GCLK_3_DIVSEL;
174 GCLK->GENCTRL[3].bit.IDC = CONF_CORE_GCLK_3_IDC;
175 GCLK->GENCTRL[3].bit.GENEN = CONF_CORE_GCLK_3_ENABLE;
176 GCLK->GENCTRL[3].bit.SRC = CONF_CORE_GCLK_3_CLOCK_SOURCE;
177 CRITICAL_SECTION_LEAVE();
179 #if CONF_CORE_GCLK_4_ENABLE == 1
180 CRITICAL_SECTION_ENTER();
181 GCLK->GENCTRL[4].bit.DIV = CONF_CORE_GCLK_4_DIV_VAL;
182 GCLK->GENCTRL[4].bit.DIVSEL = CONF_CORE_GCLK_4_DIVSEL;
183 GCLK->GENCTRL[4].bit.RUNSTDBY = CONF_CORE_GCLK_4_RUN_IN_STANDBY;
184 GCLK->GENCTRL[4].bit.OE = CONF_CORE_GCLK_4_OUTPUT_ENABLE;
185 GCLK->GENCTRL[4].bit.OOV = CONF_CORE_GCLK_4_DIVSEL;
186 GCLK->GENCTRL[4].bit.IDC = CONF_CORE_GCLK_4_IDC;
187 GCLK->GENCTRL[4].bit.GENEN = CONF_CORE_GCLK_4_ENABLE;
188 GCLK->GENCTRL[4].bit.SRC = CONF_CORE_GCLK_4_CLOCK_SOURCE;
189 CRITICAL_SECTION_LEAVE();
191 #if CONF_CORE_GCLK_5_ENABLE == 1
192 CRITICAL_SECTION_ENTER();
193 GCLK->GENCTRL[5].bit.DIV = CONF_CORE_GCLK_5_DIV_VAL;
194 GCLK->GENCTRL[5].bit.DIVSEL = CONF_CORE_GCLK_5_DIVSEL;
195 GCLK->GENCTRL[5].bit.RUNSTDBY = CONF_CORE_GCLK_5_RUN_IN_STANDBY;
196 GCLK->GENCTRL[5].bit.OE = CONF_CORE_GCLK_5_OUTPUT_ENABLE;
197 GCLK->GENCTRL[5].bit.OOV = CONF_CORE_GCLK_5_DIVSEL;
198 GCLK->GENCTRL[5].bit.IDC = CONF_CORE_GCLK_5_IDC;
199 GCLK->GENCTRL[5].bit.GENEN = CONF_CORE_GCLK_5_ENABLE;
200 GCLK->GENCTRL[5].bit.SRC = CONF_CORE_GCLK_5_CLOCK_SOURCE;
201 CRITICAL_SECTION_LEAVE();
203 #if CONF_CORE_GCLK_6_ENABLE == 1
204 CRITICAL_SECTION_ENTER();
205 GCLK->GENCTRL[6].bit.DIV = CONF_CORE_GCLK_6_DIV_VAL;
206 GCLK->GENCTRL[6].bit.DIVSEL = CONF_CORE_GCLK_6_DIVSEL;
207 GCLK->GENCTRL[6].bit.RUNSTDBY = CONF_CORE_GCLK_6_RUN_IN_STANDBY;
208 GCLK->GENCTRL[6].bit.OE = CONF_CORE_GCLK_6_OUTPUT_ENABLE;
209 GCLK->GENCTRL[6].bit.OOV = CONF_CORE_GCLK_6_DIVSEL;
210 GCLK->GENCTRL[6].bit.IDC = CONF_CORE_GCLK_6_IDC;
211 GCLK->GENCTRL[6].bit.GENEN = CONF_CORE_GCLK_6_ENABLE;
212 GCLK->GENCTRL[6].bit.SRC = CONF_CORE_GCLK_6_CLOCK_SOURCE;
213 CRITICAL_SECTION_LEAVE();
215 #if CONF_CORE_GCLK_7_ENABLE == 1
216 CRITICAL_SECTION_ENTER();
217 GCLK->GENCTRL[7].bit.DIV = CONF_CORE_GCLK_7_DIV_VAL;
218 GCLK->GENCTRL[7].bit.DIVSEL = CONF_CORE_GCLK_7_DIVSEL;
219 GCLK->GENCTRL[7].bit.RUNSTDBY = CONF_CORE_GCLK_7_RUN_IN_STANDBY;
220 GCLK->GENCTRL[7].bit.OE = CONF_CORE_GCLK_7_OUTPUT_ENABLE;
221 GCLK->GENCTRL[7].bit.OOV = CONF_CORE_GCLK_7_DIVSEL;
222 GCLK->GENCTRL[7].bit.IDC = CONF_CORE_GCLK_7_IDC;
223 GCLK->GENCTRL[7].bit.GENEN = CONF_CORE_GCLK_7_ENABLE;
224 GCLK->GENCTRL[7].bit.SRC = CONF_CORE_GCLK_7_CLOCK_SOURCE;
225 CRITICAL_SECTION_LEAVE();
227 #if CONF_CORE_GCLK_8_ENABLE == 1
228 CRITICAL_SECTION_ENTER();
229 GCLK->GENCTRL[8].bit.DIV = CONF_CORE_GCLK_8_DIV_VAL;
230 GCLK->GENCTRL[8].bit.DIVSEL = CONF_CORE_GCLK_8_DIVSEL;
231 GCLK->GENCTRL[8].bit.RUNSTDBY = CONF_CORE_GCLK_8_RUN_IN_STANDBY;
232 GCLK->GENCTRL[8].bit.OE = CONF_CORE_GCLK_8_OUTPUT_ENABLE;
233 GCLK->GENCTRL[8].bit.OOV = CONF_CORE_GCLK_8_DIVSEL;
234 GCLK->GENCTRL[8].bit.IDC = CONF_CORE_GCLK_8_IDC;
235 GCLK->GENCTRL[8].bit.GENEN = CONF_CORE_GCLK_8_ENABLE;
236 GCLK->GENCTRL[8].bit.SRC = CONF_CORE_GCLK_8_CLOCK_SOURCE;
237 CRITICAL_SECTION_LEAVE();
239 #if CONF_CORE_GCLK_9_ENABLE == 1
240 CRITICAL_SECTION_ENTER();
241 GCLK->GENCTRL[9].bit.DIV = CONF_CORE_GCLK_9_DIV_VAL;
242 GCLK->GENCTRL[9].bit.DIVSEL = CONF_CORE_GCLK_9_DIVSEL;
243 GCLK->GENCTRL[9].bit.RUNSTDBY = CONF_CORE_GCLK_9_RUN_IN_STANDBY;
244 GCLK->GENCTRL[9].bit.OE = CONF_CORE_GCLK_9_OUTPUT_ENABLE;
245 GCLK->GENCTRL[9].bit.OOV = CONF_CORE_GCLK_9_DIVSEL;
246 GCLK->GENCTRL[9].bit.IDC = CONF_CORE_GCLK_9_IDC;
247 GCLK->GENCTRL[9].bit.GENEN = CONF_CORE_GCLK_9_ENABLE;
248 GCLK->GENCTRL[9].bit.SRC = CONF_CORE_GCLK_9_CLOCK_SOURCE;
249 CRITICAL_SECTION_LEAVE();
251 #if CONF_CORE_GCLK_10_ENABLE == 1
252 CRITICAL_SECTION_ENTER();
253 GCLK->GENCTRL[10].bit.DIV = CONF_CORE_GCLK_10_DIV_VAL;
254 GCLK->GENCTRL[10].bit.DIVSEL = CONF_CORE_GCLK_10_DIVSEL;
255 GCLK->GENCTRL[10].bit.RUNSTDBY = CONF_CORE_GCLK_10_RUN_IN_STANDBY;
256 GCLK->GENCTRL[10].bit.OE = CONF_CORE_GCLK_10_OUTPUT_ENABLE;
257 GCLK->GENCTRL[10].bit.OOV = CONF_CORE_GCLK_10_DIVSEL;
258 GCLK->GENCTRL[10].bit.IDC = CONF_CORE_GCLK_10_IDC;
259 GCLK->GENCTRL[10].bit.GENEN = CONF_CORE_GCLK_10_ENABLE;
260 GCLK->GENCTRL[10].bit.SRC = CONF_CORE_GCLK_10_CLOCK_SOURCE;
261 CRITICAL_SECTION_LEAVE();
263 #if CONF_CORE_GCLK_11_ENABLE == 1
264 CRITICAL_SECTION_ENTER();
265 GCLK->GENCTRL[11].bit.DIV = CONF_CORE_GCLK_11_DIV_VAL;
266 GCLK->GENCTRL[11].bit.DIVSEL = CONF_CORE_GCLK_11_DIVSEL;
267 GCLK->GENCTRL[11].bit.RUNSTDBY = CONF_CORE_GCLK_11_RUN_IN_STANDBY;
268 GCLK->GENCTRL[11].bit.OE = CONF_CORE_GCLK_11_OUTPUT_ENABLE;
269 GCLK->GENCTRL[11].bit.OOV = CONF_CORE_GCLK_11_DIVSEL;
270 GCLK->GENCTRL[11].bit.IDC = CONF_CORE_GCLK_11_IDC;
271 GCLK->GENCTRL[11].bit.GENEN = CONF_CORE_GCLK_11_ENABLE;
272 GCLK->GENCTRL[11].bit.SRC = CONF_CORE_GCLK_11_CLOCK_SOURCE;
273 CRITICAL_SECTION_LEAVE();
277 void clock_dpll_init(
void)
279 #if CONF_CORE_CLK_DPLL0_ENABLE == 1
280 #if CONF_CORE_CLK_DPLL0_REFCLK == 0
281 CRITICAL_SECTION_ENTER();
282 GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL0].bit.GEN =
283 GCLK_PCHCTRL_GEN(CONF_CORE_CLK_DPLL0_GCLK_SRC);
284 GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL0].bit.CHEN =
285 CONF_CORE_CLK_DPLL0_ENABLE;
286 CRITICAL_SECTION_LEAVE();
289 CRITICAL_SECTION_ENTER();
291 OSCCTRL->Dpll[0].DPLLRATIO.bit.LDRFRAC = CONF_CORE_CLK_DPLL0_LDRFRAC_VAL;
292 OSCCTRL->Dpll[0].DPLLRATIO.bit.LDR = CONF_CORE_CLK_DPLL0_LDR_VAL;
295 OSCCTRL->Dpll[0].DPLLCTRLB.bit.DIV = CONF_CORE_CLK_DPLL0_DIV_VAL;
296 OSCCTRL->Dpll[0].DPLLCTRLB.bit.DCOEN = CONF_CORE_CLK_DPLL0_DCOEN;
297 OSCCTRL->Dpll[0].DPLLCTRLB.bit.DCOFILTER = CONF_CORE_CLK_DPLL0_DCOFILTER;
298 OSCCTRL->Dpll[0].DPLLCTRLB.bit.LBYPASS = CONF_CORE_CLK_DPLL0_LBYPASS;
299 OSCCTRL->Dpll[0].DPLLCTRLB.bit.LTIME = CONF_CORE_CLK_DPLL0_LTIME;
300 OSCCTRL->Dpll[0].DPLLCTRLB.bit.REFCLK = CONF_CORE_CLK_DPLL0_REFCLK;
301 OSCCTRL->Dpll[0].DPLLCTRLB.bit.WUF = CONF_CORE_CLK_DPLL0_WUF;
303 CRITICAL_SECTION_LEAVE();
305 CRITICAL_SECTION_ENTER();
306 OSCCTRL->Dpll[0].DPLLCTRLA.reg = 0;
307 OSCCTRL->Dpll[0].DPLLCTRLA.bit.RUNSTDBY = CONF_CORE_CLK_DPLL0_RUNSTDBY;
308 OSCCTRL->Dpll[0].DPLLCTRLA.bit.ENABLE = CONF_CORE_CLK_DPLL0_ENABLE;
309 CRITICAL_SECTION_LEAVE();
312 #if CONF_CORE_CLK_DPLL1_ENABLE == 1
313 #if CONF_CORE_CLK_DPLL0_REFCLK == 0
314 CRITICAL_SECTION_ENTER();
315 GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL1].bit.GEN =
316 GCLK_PCHCTRL_GEN(CONF_CORE_CLK_DPLL1_GCLK_SRC);
317 GCLK->PCHCTRL[OSCCTRL_GCLK_ID_FDPLL1].bit.CHEN =
318 CONF_CORE_CLK_DPLL1_ENABLE;
319 CRITICAL_SECTION_LEAVE();
322 CRITICAL_SECTION_ENTER();
324 OSCCTRL->Dpll[1].DPLLRATIO.bit.LDRFRAC = CONF_CORE_CLK_DPLL1_LDRFRAC_VAL;
325 OSCCTRL->Dpll[1].DPLLRATIO.bit.LDR = CONF_CORE_CLK_DPLL1_LDR_VAL;
327 OSCCTRL->Dpll[1].DPLLCTRLB.bit.DIV = CONF_CORE_CLK_DPLL1_DIV_VAL;
328 OSCCTRL->Dpll[1].DPLLCTRLB.bit.DCOEN = CONF_CORE_CLK_DPLL1_DCOEN;
329 OSCCTRL->Dpll[1].DPLLCTRLB.bit.DCOFILTER = CONF_CORE_CLK_DPLL1_DCOFILTER;
330 OSCCTRL->Dpll[1].DPLLCTRLB.bit.LBYPASS = CONF_CORE_CLK_DPLL1_LBYPASS;
331 OSCCTRL->Dpll[1].DPLLCTRLB.bit.LTIME = CONF_CORE_CLK_DPLL1_LTIME;
332 OSCCTRL->Dpll[1].DPLLCTRLB.bit.REFCLK = CONF_CORE_CLK_DPLL1_REFCLK;
333 OSCCTRL->Dpll[1].DPLLCTRLB.bit.WUF = CONF_CORE_CLK_DPLL1_WUF;
335 CRITICAL_SECTION_LEAVE();
337 CRITICAL_SECTION_ENTER();
338 OSCCTRL->Dpll[1].DPLLCTRLA.reg = 0;
339 OSCCTRL->Dpll[1].DPLLCTRLA.bit.RUNSTDBY = CONF_CORE_CLK_DPLL1_RUNSTDBY;
340 OSCCTRL->Dpll[1].DPLLCTRLA.bit.ENABLE = CONF_CORE_CLK_DPLL1_ENABLE;
341 CRITICAL_SECTION_LEAVE();
344 #if CONF_CORE_CLK_DPLL0_ENABLE == 1
345 while(!(
OSCCTRL->Dpll[0].DPLLSTATUS.bit.LOCK ||
OSCCTRL->Dpll[0].DPLLSTATUS.bit.CLKRDY));
346 CRITICAL_SECTION_ENTER();
347 #if CONF_CORE_CLK_DPLL0_ONDEMAND == 1
348 OSCCTRL->Dpll[0].DPLLCTRLA.bit.ONDEMAND = CONF_CORE_CLK_DPLL0_ONDEMAND;
350 CRITICAL_SECTION_LEAVE();
353 #if CONF_CORE_CLK_DPLL1_ENABLE == 1
354 while(!(
OSCCTRL->Dpll[1].DPLLSTATUS.bit.LOCK ||
OSCCTRL->Dpll[1].DPLLSTATUS.bit.CLKRDY));
355 CRITICAL_SECTION_ENTER();
356 #if CONF_CORE_CLK_DPLL1_ONDEMAND == 1
357 OSCCTRL->Dpll[1].DPLLCTRLA.bit.ONDEMAND = CONF_CORE_CLK_DPLL1_ONDEMAND;
359 CRITICAL_SECTION_LEAVE();
363 void clock_dfll_init(
void)
365 #if CONF_CORE_CLK_DFLL_ENABLE
366 CRITICAL_SECTION_ENTER();
367 GCLK->GENCTRL[0].bit.SRC = GCLK_GENCTRL_SRC_OSCULP32K;
368 CRITICAL_SECTION_LEAVE();
369 while(
GCLK->SYNCBUSY.bit.GENCTRL0);
371 CRITICAL_SECTION_ENTER();
374 CRITICAL_SECTION_LEAVE();
375 #if CONF_CORE_CLK_DFLL_USBCRM != 1 && CONF_CORE_CLK_DFLL_MODE != 0
376 CRITICAL_SECTION_ENTER();
378 GCLK->PCHCTRL[OSCCTRL_GCLK_ID_DFLL48].bit.GEN =
381 CRITICAL_SECTION_LEAVE();
384 CRITICAL_SECTION_ENTER();
386 OSCCTRL->DFLLMUL.bit.MUL = CONF_CORE_CLK_DFLL_MUL_VAL;
387 OSCCTRL->DFLLMUL.bit.CSTEP = CONF_CORE_CLK_DFLL_CSTEP_VAL;
388 OSCCTRL->DFLLMUL.bit.FSTEP = CONF_CORE_CLK_DFLL_FSTEP_VAL;
389 CRITICAL_SECTION_LEAVE();
390 while(
OSCCTRL->DFLLSYNC.bit.DFLLMUL);
392 CRITICAL_SECTION_ENTER();
395 CRITICAL_SECTION_LEAVE();
397 while(
OSCCTRL->DFLLSYNC.bit.DFLLCTRLB);
399 CRITICAL_SECTION_ENTER();
402 CRITICAL_SECTION_LEAVE();
403 while(
OSCCTRL->DFLLSYNC.bit.ENABLE);
404 #if CONF_CORE_CLK_DFLL_OVERWRITE_CAL == 1
405 CRITICAL_SECTION_ENTER();
407 OSCCTRL->DFLLVAL.bit.COARSE = CONF_CORE_CLK_DFLL_COARSE_VAL;
408 OSCCTRL->DFLLVAL.bit.FINE = CONF_CORE_CLK_DFLL_FINE_VAL;
409 OSCCTRL->DFLLVAL.bit.DIFF = CONF_CORE_CLK_DFLL_DIFF_VAL;
410 CRITICAL_SECTION_LEAVE();
413 CRITICAL_SECTION_ENTER();
417 CRITICAL_SECTION_LEAVE();
419 while(
OSCCTRL->DFLLSYNC.bit.DFLLVAL);
421 CRITICAL_SECTION_ENTER();
424 OSCCTRL->DFLLCTRLB.bit.BPLCKC = CONF_CORE_CLK_DFLL_BPLKC;
425 OSCCTRL->DFLLCTRLB.bit.QLDIS = CONF_CORE_CLK_DFLL_QLDIS;
426 OSCCTRL->DFLLCTRLB.bit.CCDIS = CONF_CORE_CLK_DFLL_CCDIS;
427 OSCCTRL->DFLLCTRLB.bit.USBCRM = CONF_CORE_CLK_DFLL_USBCRM;
428 OSCCTRL->DFLLCTRLB.bit.LLAW = CONF_CORE_CLK_DFLL_LLAW;
429 OSCCTRL->DFLLCTRLB.bit.STABLE = CONF_CORE_CLK_DFLL_STABLE_FCALIB;
430 OSCCTRL->DFLLCTRLB.bit.MODE = CONF_CORE_CLK_DFLL_MODE;
431 CRITICAL_SECTION_LEAVE();
432 while(
OSCCTRL->DFLLSYNC.bit.DFLLCTRLB);
434 if (
OSCCTRL->DFLLCTRLB.bit.MODE)
436 volatile uint32_t status_mask = OSCCTRL_STATUS_DFLLRDY | OSCCTRL_STATUS_DFLLLCKC;
437 while((
OSCCTRL->STATUS.reg & status_mask) != status_mask);
441 while(!
OSCCTRL->STATUS.bit.DFLLRDY);
444 #if CONF_CORE_CLK_DFLL_ONDEMAND == 1
445 CRITICAL_SECTION_ENTER();
447 CRITICAL_SECTION_LEAVE();
450 while(
GCLK->SYNCBUSY.reg);
451 CRITICAL_SECTION_ENTER();
453 GCLK->GENCTRL[0].bit.SRC = CONF_CORE_GCLK_0_CLOCK_SOURCE;
454 CRITICAL_SECTION_LEAVE();