#ifndef __DEFINES_EDK_H
#define __DEFINES_EDK_H


/*******************************************************************************/
// definice masky vstupu ve strukture EDK.input
/*******************************************************************************/
#define EDK_IN_INPUT1			(1<<0)		// vstup 1
#define EDK_IN_INPUT2			(1<<1)		// vstup 2 
#define EDK_IN_BUZZER			(1<<2)		// pipak aktivni a/n
#define EDK_IN_RELE_INV			(1<<3)		// inverzni rele n/a
#define EDK_IN_EHS				(1<<4)		// sporic n/a
#define EDK_IN_READER2			(1<<5)		// ctecka c.2 n/a
#define EDK_IN_TAMPER			(1<<6)		// optozavora
#define EDK_IN_WGOUT			(1<<7)		// vystup WIEGAND/ACS a/n
#define EDK_IN_W32BIT			(1<<8)		// format W26/W42 n/a
#define EDK_IN_CONFIG			(1<<9)		// konfiguracni propojka
#define EDK_IN_WAIT_RXD_BUSY 	(1<<10)		// propojka JP4 - blokovat TXD pokud jsou data na RXD

/*******************************************************************************/
// definice masky v strukture EDK.output
/*******************************************************************************/
#define EDK_OUT_RELAY			(1<<0)		// rele
#define EDK_OUT_BUZZER			(1<<1)		// pipak
#define EDK_OUT_LED_RED			(1<<2)		// LED RED
#define EDK_OUT_LED_GRN			(1<<3)		// LED GREEN

/*******************************************************************************/
// definice pro nacitani vstupu do promene EDK.input
/*******************************************************************************/
#define EDK_PIN_INPUT1			(p2_0)? 0:1
#define EDK_PIN_INPUT2			(p3_3)? 0:1


/*******************************************************************************/
// pokud je osazen DIP prepinac - definice funkce prepinacu, cislovani LSB=DIP8														   
/*******************************************************************************/
#define EDK_PIN_DIP1			!(p1_3)	
#define EDK_PIN_DIP2			!(p0_0)
#define EDK_PIN_DIP3			!(p0_4)
#define EDK_PIN_DIP4			!(p0_5)
#define EDK_PIN_DIP5			!(p0_6)
#define EDK_PIN_DIP6			!(p2_0)
#define EDK_PIN_DIP7			!(p3_3)
#define EDK_PIN_DIP8			!(p0_1)


#define EDK_DIP_ADR_MASK		0x1f	// maska pro adresu zarizeni DIP1-DIP4


/*******************************************************************************/
// definice pro optozavoru
/*******************************************************************************/
#define OPTO_UNDEFINED			0x00		// stav optozavory zatim neznamy
#define OPTO_OPEN				0x01		// optozavora detekuje otevreni
#define OPTO_CLOSED				0x02		// optozavora detekuje klidovy stav


/*******************************************************************************/
// definice synchronizace v rezimu EDK
/*******************************************************************************/
#define SYNC_READER_1			1		// nabezna hrana SYNC=READER1
#define SYNC_READER_2			0		// sestupna hrana SYNC=READER2

#define READER1_WAIT_SYNC		100		// pausa pred odeslanim paketu po detekci sync READER1
#define READER2_WAIT_SYNC		1		// pausa pred odeslanim paketu po detekci sync READER2



/// poznamka k flagum - jelikoz je procesor 16-bit tak je vhodne nepresahnout INT - bitove operace

//------------------------------------------------------------------------
// stavove flagy EDK.sys_flag - vse ostatni ktere nesouvisi s IO
//------------------------------------------------------------------------
#define FLAG_READ_CARD				0x0001	// cti kartu
#define FLAG_SEND_EDK_PACKET		0x0002	// pozadavek na odeslani paketu do terminalu - synchronizovano se SYNC signalem
#define FLAG_EDK_PACKET_SENDED		0x0004	// paket odeslan 
#define FLAG_RD3_PACKET_SENDED		0x0008	// paket odeslan 
#define FLAG_OFFLINE_MODE			0x0010	// pokud vypadne komunikace s terminalem prechazi ctecka do OFFLINE rezimu
#define FLAG_OFFLINE_LED			0x0020	// indikovat ledkama OFFLINE rezim
#define FLAG_ACK_BUS_QUIET			0x0040	// BUS_QUIET je potreba potvrdit paketem ACK, pomocny flag nez se nastavi BUS_QUIET
#define FLAG_ACK_DEVICE_RESET		0x0080	// pokud je potreba potvrdit prikaz RESET
#define FLAG_ACK_DEVICE_BOOT		0x0100	// pro potvrzeni restartu do BOOTLOADERU
#define FLAG_PROCESS_STV_CMD		0x0200	// probiha zpracovani prikazu STV na sbernici, nacitani linky, je nutne blokovat provoz na sbernici
#define FLAG_BLOCK_MEASURE_PACKET	0x0400	// blokujici flag odesilani paketu MEASURE po startu, obdobne jako u FLAG_PROCESS_STV_CMD
#define FLAG_BLOCK_LED_TIMER		0x0800	// blokujici flag LED timeru
#define FLAG_BLOCK_BUZZER_TIMER		0x1000	// blokujici flag BUZZER timeru
#define FLAG_AIO_FIRST_SEND			0x2000	// odeslani stavu sensoru po zapnuti, i kdyz nevyhovuji nastavenym limitam

//------------------------------------------------------------------------
// stavove flagy EDK.io_flag
//------------------------------------------------------------------------
#define FLAG_SYNC_IN				0x0001	// flag synchronizace vstupem SYN - v rezimu EDK
#define FLAG_SYNC_OUT				0x0002  // flag synchronizace vstupem IN1->IN2

#define FLAG_OPTO_UPDOWN			0x0004	// up/down counter pro detekci optozavory (SET=UP, CLEAR=DOWN)
#define FLAG_INPUT1_UPDOWN			0x0008	// up/down counter pro detekci vstupu IN1 (SET=UP, CLEAR=DOWN)
#define FLAG_INPUT2_UPDOWN			0x0010	// up/down counter pro detekci vstupu IN2 (SET=UP, CLEAR=DOWN)

#define FLAG_RED_PULSE_MODE			0x0020	// blikej LED RED
#define FLAG_GRN_PULSE_MODE			0x0040	// blikej LED GRN  
#define FLAG_BUZZER_PULSE_MODE  	0x0080	// buzzer pipa po nastavenou dobu VALUE_BEEP
#define FLAG_RED_FOLLOW_MODE		0x0100	// RED kopiruje stav rele
#define FLAG_GRN_FOLLOW_MODE    	0x0200	// GRN kopiruje stav rele
#define FLAG_BUZZ_FOLLOW_MODE		0x0400	// BUZZER kopiruje stav rele
#define FLAG_LED_TIMEOUT	    	0x0800	// citac pro LED docasoval - bud cas nebo pocet bliknuti
#define FLAG_BUZZER_TIMEOUT			0x1000	// citac pro BUZZER docasoval - bud cas nebo pocet bliknuti
#define FLAG_REZERVA				0x2000	// rezerva
#define FLAG_EHS_CARD_PRESENCE		0x4000	// detekce vlozene karty u odkladacky, aby to nekdo neosulil treba vizitkou
#define FLAG_EHS_CARD_REMOVED		0x8000	// pomocny flip-flop pro odkladacku

//------------------------------------------------------------------------
// GR_EXT8
//------------------------------------------------------------------------
#define FLAG_INPUT3_UPDOWN			0x0001	// up/down counter pro detekci vstupu IN3 (SET=UP, CLEAR=DOWN)
#define FLAG_INPUT4_UPDOWN			0x0002	// up/down counter pro detekci vstupu IN4 (SET=UP, CLEAR=DOWN)
#define FLAG_INPUT5_UPDOWN			0x0004	// up/down counter pro detekci vstupu IN5 (SET=UP, CLEAR=DOWN)
#define FLAG_INPUT6_UPDOWN			0x0008	// up/down counter pro detekci vstupu IN6 (SET=UP, CLEAR=DOWN)
#define FLAG_INPUT7_UPDOWN			0x0010	// up/down counter pro detekci vstupu IN7 (SET=UP, CLEAR=DOWN)
#define FLAG_INPUT8_UPDOWN			0x0020	// up/down counter pro detekci vstupu IN8 (SET=UP, CLEAR=DOWN)



//------------------------------------------------------------------------
// stavove bity MASKA_LED pro dekodovani prikazu GUI
//------------------------------------------------------------------------	
#define GUI_RED_OFF				0x00	// bity pro RED LED nenastaveny
#define GUI_GRN_OFF				0x00	// bity pro GRN LED nenastaveny

#define GUI_BUZZ_NO_ACTION		0x00	// piskac neni ovlivnen
#define GUI_RED_STATIC_MODE		0x01	// LED sviti/nesviti staticky rezim
#define GUI_RED_PULSE_MODE		0x02	// LED blika
#define GUI_RED_FOLLOW_MODE		0x03	// LED kopiruje stav rele

#define GUI_GRN_STATIC_MODE		0x04	// LED sviti/nesviti staticky rezim
#define GUI_GRN_PULSE_MODE		0x08	// LED blika
#define GUI_GRN_FOLLOW_MODE		0x0C	// LED kopiruje stav rele

#define GUI_BUZZ_STATIC_MODE	0x01	// piskac buzen ve statickem rezimu 
#define GUI_BUZZ_PULSE_MODE		0x02	// piskac pipa
#define GUI_BUZZ_FOLLOW_MODE	0x03	// piskac sleduje stav rele

#define GUI_RED_MASK			0x03	// maska pro bity RED
#define GUI_GRN_MASK			0x0C	// maska pro bity GRN
#define GUI_BUZZ_MASK			0x03	// maska pro bity BUZZ


/*******************************************************************************/
// prednastaveni casovacu EDK
/*******************************************************************************/
 #define EDK_PRESET_LED_TIME				5		// doba svitu LED po nacteni karty, [x100ms] - pro RS varianty a ACS
 #define EDK_PRESET_LED_TIME_RD3			10		// doba svitu LED po nacteni karty, [x100ms] - pro RD3
 #define EDK_PRESET_BUZZER_TIME				5		// doba pipnuti x100ms
 
 #define EDK_PRESET_RELAY_TIME				30		// doba sepnuti rele x100ms - pouze v offline rezimu
 
 #define EDK_PRESET_OPTOCOUPLER_TIME 		2		// potrebna doba aktivace optozavory [x100ms]
 #define EDK_TEMPERATURE_CHECK_TIME			5		// perioda osahavani teploty [s]


// nastaveni pro rezim EDK-RS a nebo variantu GR_EXT8
#if defined INTERFACE_RS || defined INTERFACE_RSN
 #ifndef GR_EXT8
   #define EDK_PRESET_INPUT1_TIME 			5		// potrebna doba aktivace vstupu IN1-odchodove tlac.[x10ms]
   #define EDK_PRESET_INPUT2_TIME 			5		// potrebna doba aktivace vstupu IN2-dverni kontakt [x10ms]
 #else
   #define EDK_PRESET_INPUT1_TIME 			5		// potrebna doba aktivace vstupu IN1
   #define EDK_PRESET_INPUT2_TIME 			5		// potrebna doba aktivace vstupu IN2
   #define EDK_PRESET_INPUT3_TIME 			5		// potrebna doba aktivace vstupu IN3
   #define EDK_PRESET_INPUT4_TIME 			5		// potrebna doba aktivace vstupu IN4
   #define EDK_PRESET_MUX_INPUT_TIME		5		// potrebna doba aktivace multiplexovanych externich vstupu IN5-IN8
 #endif
#endif

// nastaveni pro rezim EDK-ACS
#ifdef INTERFACE_EDK
 #define EDK_PRESET_INPUT1_TIME 			2		// potrebna doba aktivace vstupu IN1-BUZZER [x10ms]
 #define EDK_PRESET_INPUT2_TIME 			2		// potrebna doba aktivace vstupu IN2-LED [x10ms]
 #define EDK_PRESET_D1_PULSE_TIME			3		// delka pulsu na DATA1 - indikace nacteni karty [x10ms]
#endif



#endif