Contiki-Inga 3.x
xmega_clock.c
1 #include "xmega_clock.h"
2 
3 void xmega_clock_output(void)
4 {
5  //Enable output of clock on PortC Pin 7 (p.161)
6  PORTC.DIR = 0x80; // set PortC.7 as output pin
7  PORTCFG.CLKEVOUT = 0x1; // set clock to be on portc.7
8 }
9 
10 /**
11  * We will use the 2 MHz internal oscillator by default as the source for the PLL
12  *
13  * The PLL accepts a factor (1 - 31) that can be used to multiply the PLL Source clock.
14  * This way we can generate multiplies of a 2 MHz clock
15  */
16 
17 void xmega_clock_init(void)
18 {
19  // 2MHz internal oscillator is selected by default for the PLL (00 in the MSB)
20  // The Constant will be taken from the clock.h
21  OSC.PLLCTRL = 0 | XMEGA_CLOCK_CONF_PLL_FACTOR;
22  // Enable PLL
23  OSC.CTRL |= OSC_PLLEN_bm;
24  // Wait for it to stablize
25  while ( !(OSC.STATUS & OSC_PLLEN_bm) ) ;
26  // Set main system clock to PLL internal clock
27  CCP = CCP_IOREG_gc; // Secret handshake so we can change clock
28  CLK.CTRL = (CLK.CTRL & ~CLK_SCLKSEL_gm ) | CLK_SCLKSEL_PLL_gc;
29 }