/*
 * ATtiny817.c
 *
 * Created: 11-Jul-19 12:37:19 PM
 * Author : M19892
 */ 

#include <avr/io.h>
#include <avr/fuse.h>

FUSES = 
{
	.APPEND = 0x00,
	.BODCFG = 0x00,
	.BOOTEND = 0x00,
	.OSCCFG = 0x02,
	.SYSCFG0 = 0xF7,
	.SYSCFG1 = 0x07,
	.TCD0CFG = 0x00,
	.WDTCFG = 0x00,
};

int main(void)
{
	// 8X prescaler to account for speed grade at 1.8V
	_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB,		(CLKCTRL_PDIV_8X_gc | CLKCTRL_PEN_bm));
	// 64K startuptime, enable 32K xtal osc
	_PROTECTED_WRITE(CLKCTRL.XOSC32KCTRLA,	(CLKCTRL_CSUT_64K_gc | CLKCTRL_ENABLE_bm));
	// Enable CLKOUT, set main clock to 32K xtal osc
	_PROTECTED_WRITE(CLKCTRL.MCLKCTRLA,		(CLKCTRL_CLKOUT_bm | CLKCTRL_CLKSEL_XOSC32K_gc));
	// Wait for clock to be switched to 32K xtal
	while(CLKCTRL.MCLKSTATUS & CLKCTRL_SOSC_bm);
	// Turn off prescaler
	_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB,		0x00);
	
    while(1){}
}
