/*******************************************************************************
 *
 *  Module:         main.h
 *
 ******************************************************************************/

#ifndef __MAIN_H
#define __MAIN_H 

#include "core_lib.h" 


void (*userApp)(void);


// I N T E R N A L    S O F T W A R E    D E F I N E S
#define EVER					(;;)
#define WAITLOOP				60000

#define INFO_TIMEOUT			2		// timeout pro vyskoceni z info o verzi v sec
#define MENU_TIMEOUT			250		// timeout pro vyskoceni z menu v sekundach


// A P P L I C A T I O N    D E F I N E S
//#define	MAX_REQ					32
#define	MAX_REQ					16		// staci bohate
#define NUM_OF_FUNC				255


extern tsEEPROM	EEPROM;					// pristup a mapovani EEPROM
extern tsOPER	OPER;					// operacni globalni provenne uchovavane v EEPROM
extern tsReq reqBuffer[MAX_REQ+1]; 		// requirements buffer


// R E Q U I R E M E T ( T A S K )   D E F I N E S
// PARTS OF REQUIREMENT(TASK) ITEM
#define PRIORITY_MASK					0xE000		// 1110 0000 0000 0000
#define TASK_MASK						0x00FF		// 0000 0000 1111 1111  / 255 possibility

// PRIORITY DEFINES
#define PRIORITY_TASK_ISR				0x8000		// 1000 0000 0000 0000 - MAXIMUM PRIORITY LEVEL - INTERRUPTS
#define PRIORITY_TASK_HIGH			    0x4000		// 0100 0000 0000 0000 - HIGH PRIORITY LEVEL
#define PRIORITY_TASK_MID				0x2000		// 0010 0000 0000 0000 - MEDIUM PRIORITY
#define PRIORITY_TASK_LOW				0x1000		// 0001 0000 0000 0000 - LOW PRIORITY LEVEL

#define PRIORITY_ACK_MESSAGE			0x4000		// musi mit vzssi prioritu nez ostatni zpravy, aby byl ACK generovan jako prvni
#define PRIORITY_SYS_MESSAGE			0x2000		// 
#define PRIORITY_ERR_MESSAGE			0x1000		// 


// ADD STATUS DEFINES
#define REQUIRE_MASK					0xF0FF		// 1111 0000 1111 1111  
#define ADD_SINGLE						0x0000		
#define ADD_MULTIPLE					0x0800		// 0000 1000 0000 0000 - multiple insertion af task is possibility

// PARAMETERS
#define NO_PARAMETER						0



// REQUIREMENTS AND TASKS
	#define	REQUIREMENT_NO					0
	#define	TASK_NO							0


// seznam podporovanych funci pro zarizeni typu EDK - vsechny ctecky
#if defined CORE_EDK
	
	#if defined INTERFACE_RS
				
	#define	DEVICE_RESET					1
	#define	PROCESS_GPIO					2
	#define	PROCESS_ADC						3
	#define PROCESS_DIP						4	
	#define READ_CARD_ID					5
	#define PROCESS_BUS_TIMER				6		
    #define PROCESS_SYNC_OUTPUT				7		
	#define PROCESS_OPTO_TAMPER				8		
	#define READ_DIP_SWITCH					9
	
// API fuinkce GILD protokolu	
	#define PROCESS_SCI_STATE_ACK			10
	#define PROCESS_EXT_DATA				11
	#define PROCESS_SCI_STATE_STV			12
    #define PROCESS_SCI_STATE_READER		13		
	#define PROCESS_SCI_STATE_CHANGE		14
	#define PROCESS_SCI_STATE_INFO			15
	#define PROCESS_SCI_STATE_ERROR			16
	#define PROCESS_SCI_STATE_MEASURE		17
	#define PROCESS_SCI_MESSAGE_INFO		18
	#define PROCESS_SCI_DLL_DATA			19
	#define PROCESS_SCI_DATA_CFG			20
#endif

	#if defined INTERFACE_EDK
		#define	PROCESS_GPIO					1
		#define READ_CARD_ID					2
		#define PROCESS_WIEGAND					3		
    	#define PROCESS_EDK						4		
         #ifdef INTERFACE_RD3
    	   #define PROCESS_RD3_CARD				5		
		   #define PROCESS_RD3_ID				6	// RD3+RRD3 IDENTIFIKACE
		   #define PROCESS_RD3_INPUT_STATE		7	// RRD3 STAV VSTUPU
		   #define PROCESS_RD3_RELE				8	// RRD3 STAV RELE
		   #define PROCESS_RD3_CTRL				9	// RRD3 - ovladaci prikazy (rele)
    	   #define PROCESS_RD3_IO				10  // RRD3 - kontrola stavu vstupu a rele						
		   #define PROCESS_RD3_MEDIUM_TYPE		11	// RD3 - podrobne informace o mediu - karte
		 #endif 
	#endif

	// varianta NETRONIX - terminal RON_SW
	#if defined INTERFACE_RSN
			// systemove funkce zarizeni
		#define	PROCESS_GPIO					1
		#define PROCESS_DIP						2	
		#define READ_CARD_ID					3
		#define PROCESS_BUS_TIMER				4
    	#define PROCESS_SYNC_OUTPUT				5						
	#endif
#endif


#if defined CORE_POW	
		// systemove funkce zarizeni
		#define	DEVICE_RESET					1
		#define READ_DIP_SWITCH					2
		
		#define	PROCESS_GPIO					3
		#define	PROCESS_ADC						4
		#define PROCESS_DIP						5	
		#define PROCESS_BUS_TIMER				6		
	
		// API fuinkce GILD protokolu	
		#define PROCESS_SCI_STATE_ACK			7
		#define PROCESS_SCI_STATE_STV			8
		#define PROCESS_SCI_STATE_CHANGE		9
		#define PROCESS_SCI_STATE_INFO			10
		#define PROCESS_SCI_STATE_ERROR			11
		#define PROCESS_SCI_DLL_DATA			12
		#define PROCESS_SCI_MESSAGE_INFO		13
#endif


// maskovani pro appCB.mode
#define SYSBUSY_MASK				0x8000		// po dobu nastaveni flagu nejsou zpracovany zadne udalosti
#define UNIT_START_MODE				0x4000		// slouzi k odeslani paketu UNIT_START po nastavene dobe po zapnuti Vcc
#define UNIT_BOOT_MODE				0x2000		// rezim nahravani bootloaderu v rezimu aplikace

// rezimy pro MIFARE
#define MIFARE_RW_MASK				0x00FF
#define CARD_RW_BLOCK				0x0020		// rezim prace s MIFARE kartou - obsluha z PC
#define CARD_WRITE_MODE				0x0010		// rezim zapisu do bloku - bud DATA nebo VALUE
#define CARD_READ_MODE				0x0008		// cteni z bloku - bud DATA nebo VALUE
#define MIFARE_DUMP_MODE			0x0004		// DUMP rezim - vypis cele karty
#define MIFARE_EE_LOAD_KEY			0x0002		// zapis klicu do EEPROM


#define INT_LEVEL_INT3				0x02		// detekce signalu na IN2


// offsety do pole adc[] a adc_buffer[] v navaznosti na aktualni sensory
#define SENSOR_VOLT	 	SENSOR_POS_VOLTAGE-1
#define SENSOR_TEMP		SENSOR_POS_TEMPERATURE-1
#define SENSOR_CURR		SENSOR_POS_CURRENT-1
#define SENSOR_LUX		SENSOR_POS_LUXMETER-1
#define SENSOR_WIND		SENSOR_POS_WIND-1
#define SENSOR_HUM		SENSOR_POS_HUMIDITY-1



#endif

