/**********************************************************************
 *****  COMMON FILE FOR EVERY GILD-SYSTEM PROJECTS                *****
 *****  (WARNING: do not change constant names				      *****
 *****                                                            *****
 *****  Name: _core_err.h                                         *****
 *****  Desc: Defines global bus constant                         *****
 *****  Ver.: 1.0                                                 *****
 *****  Date: 01/2011		                                      *****
 *****  Auth: Martin Mechacek		                              *****
 *****  Comp: ESTELAR s.r.o.									  *****
 *****                                                            *****
 *****  Copyright ESTELAR s.r.o. (c) 2010, all rights reserved    *****
 **********************************************************************/ 

#ifndef __CORE_ERR_H
#define __CORE_ERR_H

// I N T E R N A L    S T A T E    C O D E S 
// I N T E R N A L    E R R O R    C O D E S 
#define ERR_NO							0
#define ERR_SUCCESS						0
#define ERR_FATAL						0x80


// navratove kody ukladane do spodniho bajtu STATE pri generovani ACK/NACK
// chyby SCI musi byt < 16 protoze se ukladaji do 4bitu pro vytvoreni ACK paketu
#define ERR_SCI_BUFFER					1
#define ERR_SCI_CRC						2
#define ERR_SCI_PARITY					3
#define ERR_SCI_OVERRUN					4
#define ERR_SCI_BUSY					5
#define ERR_SCI_LONG					6
#define ERR_SCI_FRAMING					7
#define ERR_SCI_UNKNOWN					8
#define ERR_SCI_BADVALUE				9
#define ERR_SCI_RANGE					10
#define ERR_SCI_READONLY				11
#define ERR_SCI_EVEN					12
#define ERR_SCI_ADDR					13
#define ERR_SCI_SEND					14		// nepodarilo se opakovane odeslat paket na sbernici
#define ERR_SCI_WRONLY					15		

// navratove kody pri generovani paketu SYS_MESSAGE_ERROR
#define ERR_SPI_DETECTION				18	
#define ERR_LVD_DETECTION				19		// nepouzito
#define ERR_REQ_LIST_FULL				20 | ERR_FATAL	// 
#define ERR_REQ_REPEAT					21
#define ERR_TASK_NOT_FOUND				22
#define ERR_TASK_MISMATCH				23
#define ERR_PARAM_MISMATCH				24
#define ERR_UNDEFINED					25
#define ERR_UNKNOWN						26
#define ERR_BUTTON						27
#define ERR_CTABLE_FULL					28
#define ERR_MODULE_TYPE					29
#define ERR_IO_UPDATE					30
#define ERR_DATA_SIZE					31
#define ERR_TTABLE_FULL					32
#define ERR_MANY_MODULES				33
#define ERR_NO_MODULES					34
#define ERR_UNKNOWN_MODULE				35			// bude asi nahrazeno autodetekci novych modulu na sbernici
#define ERR_UNKNOWN_REG					36

#define ERR_EEPROM_WRITE				40
#define ERR_EEPROM_READ					41			// generuje i hlavni aplikace CL700 pri spatnem cteni I2C
#define ERR_I2C_WRITE					40			// v projektu GR-U01 nepouzivat
#define ERR_I2C_READ					41			// v projektu GR-U01 nepouzivat
#define ERR_MEM_OVERFLOW				42
#define ERR_I2C_WRITE1					43
#define ERR_SCI_PARSING					44
#define ERR_READER_INTERFACE			45

// chybove stavy zdroje POW, prekroceni napevno nastavenych limit nebo stavu
// pricita se k ERROR_CODE_UNITERR jako interni chyba zarizeni
#define ERR_OVERCURRENT					46		// prekroceni proudu
#define ERR_BAT_LOW						47		// pokles napeti baterie
#define ERR_UNDERVOLTAGE				48		// pokles napajeciho napeti
#define ERR_OVERTEMPERATURE				49		// prekroceni nastavene teploty



#define SCI_PROGRESS					0xff

#define UNIT_NORMAL						0
#define UNIT_START						50
#define UNIT_RESTART					51
#define UNIT_MENU						52
#define UNIT_CLEAR_CTABLE				53
#define UNIT_LOAD_DEF					54
#define UNIT_ERROR						55
#define UNIT_ADDR_CHANGE				56
#define UNIT_MAC_CHANGE					57
#define UNIT_CFG_CHANGE					58		
#define UNIT_INDEX_CTABLE				59
#define UNIT_POWER_LOW					60			// v CL700 pokles napětí pro čtečky pod 10,5 V
#define UNIT_POWER_FAIL					61			// v CL700/AL40E preruseni pojistky pro napajeni ctecek
													// bude použito pro ZDROJ POW12-3 = vypadek sitoveho napajeni
#define UNIT_SENSOR_FAIL				62													
#define UNIT_IO_PRESET					63
#define UNIT_BOOT_DLL					64		// rezim nahravani bootloaderu

// ^^ vsechny chybove kody mohou by generovany do interniho LOGu
// max je 99 protoze na display se to vypisuje dekadicky
///////////////////////////////////////////////////////////////////////////////////////////////


// definice systemovych chyb pro generovani paketu SYS_MESSAGE_ERROR
#define ERROR_CODE_NONE					0x0000		// zadna chyba
#define ERROR_CODE_UNSUPPORTED			0x0100		// nepodporovana funkce
#define ERROR_CODE_UNKNOWNADDR			0x0200		// neexistujici adresa
#define ERROR_CODE_BADVALUE				0x0300		// neplatna hodnota
//#define ERROR_CODE_BADVALUE				0x4000		// provozni chyba
#define ERROR_CODE_SCI					0x4000		// prijat chybny paket
#define ERROR_CODE_UNITERR				0x8000		// interni chyba jednotky (napr.: GR-U01)
													// ve spodnim byte bude kod chyby vygenerovany jednotkou
													// dle: I N T E R N A L    E R R O R    C O D E S  definovanych vyse		


#endif 		// __CORE_ERR_H
