
#ifndef __CONFIG_C
#define __CONFIG_C

#include "opora.h"
#include "config.h"

void ClockCfg()
{
	RST_CLK->HS_CONTROL=0x01;				//HSE on, Oscillator mode
	while((RST_CLK->CLOCK_STATUS&0x04)==0);	//wait, until frequency unstable
	RST_CLK->PER_CLOCK|=0x08;				//EEPROM_CTRL Clock enable
	EEPROM->CMD=0;							//Delay = 0
	RST_CLK->PER_CLOCK&=(~0x08);			//EEPROM_CTRL Clock disable
	RST_CLK->CPU_CLOCK=0x00000002;			//CPU_C1 frequency 8MHz
	RST_CLK->PLL_CONTROL=0x0104;			//CPU_PLL On, USB_MUL_MULL=1
	while((RST_CLK->CLOCK_STATUS&0x02)==0);	//wait, until PLL frequency unstable
	RST_CLK->CPU_CLOCK=0x00000106;			//CPU frequency 16MHz
	RST_CLK->PER_CLOCK|=0x01004000;			//PORTD clock enable, Timer1 clock enable
	RST_CLK->TIM_CLOCK=0x01000000;			//Timer_1 clock enable Timer_1_Clock=HCLK=16MHz
}

void PortCfg()
{
//------- PortD for LEDS -------
	PORTD->FUNC=0;							//Port_D - ports
	PORTD->ANALOG=0xFFFF;					//Port_D - digital
	PORTD->RXTX=0;							
	PORTD->OE=0x7F80;						//Port_D[14..7] - outputs
	PORTD->PWR=0x3FFFC000;					//Port_D[14..7] - fast edge
}

void Timer1Cfg()
{
	TIMER1->CNT=0;				 			
	TIMER1->ARR=TICKS;						//Interrupt every TICKS cycles
	TIMER1->IE=0x2;							//Interrupt occure, when CNT==ARR
	TIMER1->CNTRL=0x0001;					//Timer enable
}

#endif	//__CONFIG_C

