- #if (ARCH == ARCH_AVR8)
- /* Disable watchdog if enabled by bootloader/fuses */
- MCUSR &= ~(1 << WDRF);
- wdt_disable();
-
- /* Disable clock division */
- clock_prescale_set(clock_div_1);
- #elif (ARCH == ARCH_UC3)
- /* Initialize interrupt subsystem */
- INTC_Init();
- INTC_RegisterGroupHandler(AVR32_USBB_IRQ, AVR32_INTC_INT0, USB_GEN_vect);
-
- /* Select slow startup, external high frequency crystal attached to OSC0 */
- AVR32_PM.OSCCTRL0.startup = 6;
- AVR32_PM.OSCCTRL0.mode = 7;
- AVR32_PM.MCCTRL.osc0en = true;
- while (!(AVR32_PM.POSCSR.osc0rdy));
-
- /* Switch CPU core to use OSC0 as the system clock */
- AVR32_PM.MCCTRL.mcsel = 1;
-
- /* Start PLL1 to feed into the USB generic clock module */
- AVR32_PM.PLL[1].pllmul = (F_USB / F_CPU) ? (((F_USB / F_CPU) - 1) / 2) : 0;
- AVR32_PM.PLL[1].plldiv = 0;
- AVR32_PM.PLL[1].pllosc = 0;
- AVR32_PM.PLL[1].pllen = true;
- while (!(AVR32_PM.POSCSR.lock1));
- #endif
-
+#if (ARCH == ARCH_AVR8)
+ /* Disable watchdog if enabled by bootloader/fuses */
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ /* Disable clock division */
+ clock_prescale_set(clock_div_1);
+#elif (ARCH == ARCH_XMEGA)
+ /* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
+ XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
+ XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);
+
+ /* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
+ XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
+ XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
+
+ PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
+#endif
+