#ifndef __TIMERS_H
#define __TIMERS_H 


void Init_Timer_Variables(void);
void Init_TimerA(void);
void Start_TimerA(void);
void Stop_TimerA(void);

void wait_us_range(tUInt delay);
void WaitTimeout(unsigned int _time);
void StopTimeoutCounter(void);
void StartTimeoutCounter(void);

//void Init_TimerB(void);
//void Start_TimerB(void);
//void Stop_TimerB(void);


void wait_ms(tUInt _ms);

// nastaveni timeru_A pro ruzne XTAL
// TIME/128/(1/FCLK)=DILKY
#ifdef READER_MIFARE
    #define TIMER_PRESET_1MS		106-1		// 13.56Mhz
#else
    #define TIMER_PRESET_1MS		144-1		// 18.432Mhz
#endif



#define TIMER_5MS_DIVIDER_PRESET			5-1
#define TIMER_10MS_DIVIDER_PRESET			10-1
#define TIMER_20MS_DIVIDER_PRESET			20-1
#define TIMER_100MS_DIVIDER_PRESET			100-1
#define TIMER_200MS_DIVIDER_PRESET			200-1
#define TIMER_250MS_DIVIDER_PRESET			250-1
#define TIMER_500MS_DIVIDER_PRESET			500-1
#define TIMER_1000MS_DIVIDER_PRESET			1000-1

#if defined INTERFACE_RSN
 #define SYNC_OUT_DIVIDER_PRESET			15			// [x10ms] 
#else  
 #define SYNC_OUT_DIVIDER_PRESET			20			// [x10ms] 
#endif



// nastaveni timeru_B pro overflow 1ms
#define TIMER_B_PRE_1MS			64					// prescaler
#define TIMER_B_PRI_1MS			TIMER_PRESET_1MS	// PRESET


// definice nastaveni intervalu casovace TIMER_C
#define TIMER_C_DIV				(1/(f1_CLK_SPEED/1000000/32))

#ifdef READER_MIFARE
// nastaveni timeru_C pro karte casy pro XTAL 13.56Mhz
// vypocet je 1/f/32*COUNT
 #define DELAY_50us				21-1		
 #define DELAY_100us			42-1
 #define DELAY_200us			84-1
 #define DELAY_280us			118-1
 #define DELAY_500us			211-1
 #define DELAY_1000us			423-1 
 #define DELAY_2000us			847-1
#else 
// nastaveni timeru_C pro karte casy pro XTAL 18.432Mhz
 #define DELAY_50us				28-1		
 #define DELAY_100us			57-1
 #define DELAY_200us			115-1
 #define DELAY_280us			161-1
 #define DELAY_500us			288-1
 #define DELAY_1000us			576-1 
 #define DELAY_2000us			1152-1


#endif



#define PRESET_LED_PULSE_LENGTH		2		// delka bliknuti [x100ms]
#define PRESET_BUZZ_PULSE_LENGTH	2		// delka pipnuti [x100ms]



#endif


