/** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) { #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) /* Start the master external oscillator which will be used as the main clock reference */ AVR32CLK_StartExternalOscillator(0, EXOSC_MODE_8MHZ_OR_MORE, EXOSC_START_0CLK); /* Start the PLL for the CPU clock, switch CPU to it */ AVR32CLK_StartPLL(0, CLOCK_SRC_OSC0, 12000000, F_CPU); AVR32CLK_SetCPUClockSource(CLOCK_SRC_PLL0, F_CPU); /* Start the PLL for the USB Generic Clock module */ AVR32CLK_StartPLL(1, CLOCK_SRC_OSC0, 12000000, F_USB); /* Initialize interrupt subsystem */ INTC_Init(); INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_GEN_vect); #endif /* Hardware Initialization */ LEDs_Init(); USB_Init(); }
//Initialize the clock void clock_init(void) { GlobalInterruptDisable(); INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_TC_IRQ0), AVR32_INTC_INT0, tc_irq); GlobalInterruptEnable(); // Initialize the timer/counter. tc_init_waveform(tc, &WAVEFORM_OPT); // Initialize the timer/counter waveform. // Set the compare triggers. // Remember TC counter is 16-bits, so counting second is not possible with fPBA = 12 MHz. // We configure it to count ms. // We want: (1/(fPBA/8)) * RC = 0.001 s, hence RC = (fPBA/8) / 1000 = 1500 to get an interrupt every 1 ms. tc_write_rc(tc, TC_CHANNEL, (F_PBA_SPEED / 8) / 1000); // Set RC value. //tc_write_ra(tc, TC_CHANNEL, 0); // Set RA value. //tc_write_rb(tc, TC_CHANNEL, 1900); // Set RB value. //gpio_enable_module_pin(AVR32_TC_A0_0_1_PIN, AVR32_TC_A0_0_1_FUNCTION); //gpio_enable_module_pin(AVR32_TC_B0_0_1_PIN, AVR32_TC_B0_0_1_FUNCTION); tc_configure_interrupts(tc, TC_CHANNEL, &TC_INTERRUPT); // Start the timer/counter. tc_start(tc, TC_CHANNEL); // And start the timer/counter. }