/*
 * init.h
 *
 * Created: 5/5/2016 5:05:38 PM
 *  Author: e813622
 */ 


#ifndef INIT_H_
#define INIT_H_

//#define IMU_SIMULATOR		1
//#define OLDBOARD			1


#include <asf.h>

//********************* User defined HW and SW WDT settings ***********

// HW WDT

// WDT timeout period
#define WDT_PERIOD_MS   (10000)

// WDT flags
//  - WDT disabled in debug mode
//  - WDT disabled in idle state
//  - WDT triggers all resets
#define WDT_MODE    \
        (WDT_MR_WDIDLEHLT | WDT_MR_WDDBGHLT | WDT_MR_WDRSTEN)

// SW WDT
// Number of missed scheduler loops during
// active sampling, which leads to force reset
// of the device
#define SAFETY_CHKPT_NON_PASSED_TICKS   (4)

//********************* User defined WDT settings end ******************

// Slow clock is generated either by internal 22-42kHz oscillator
// or 32kHz crystal oscillator (requires 32.768kHz external XTAL).
// Nominal frequency assumed 32768Hz for both variants
#define SCLK_FREQ_HZ    (32768)
// WDT timer is clocked by SCLK / 128
#define WDT_CLK (SCLK_FREQ_HZ / 128)
// Calculated value of WDT counter based on user defined WDT period
#define WDT_CNTR_VALUE  ( (WDT_PERIOD_MS * WDT_CLK ) / 1000 )
// Window feature of WDT is currently not used so the delta value is
// the same as counter value. This way WDT can be refreshed any time
// during predefined period.
#define WDT_DELTA_VALUE (WDT_CNTR_VALUE)

void board_init(void);

void resetTick(void);
uint64_t getTick(void);
uint32_t getMinor(void);
double getTimeSince(void);
void VBUS_Handler(void);


void initalizeTimers(uint32_t frequency);



#endif /* INIT_H_ */