//----------------------------------------------------
/**
	\file		ctk/inc/verinfo.h
	\ingroup	data
	\ingroup	all
	
	\brief		Definice hw a sw verze
				<<< ALL >>>
			
	\author		ConTeK s.r.o., Ing. Vladimir Kastner
	\version	01.01
	\date		12.01.2007
*/
//----------------------------------------------------


#ifndef _VER_INFO_H_
#define _VER_INFO_H_

#include <libsets.h>
#include <ctktypes.h>
#include <hwmodel.h>
#include <ctktime.h>

//----------------------------------------------------
//!	Definice magickeho cisla, pri zasadni zmene zmenit

#define	VERINFO_MAGIC_NUMBER	0xCEF1	//!< Magicke cislo, pri zasadni zmene zmenit

// toto musi byt makro, protoze se pouziva v inicializaci gVersionInfo
#define VerInfoSetRevisionDate(_day, _month, _year) \
	((((((_year) - 2000U) << 4) + (uint16_t)(_month)) << 5)  + (uint16_t)(_day))

#ifdef COMPILED_LIB

//----------------------------------------------------
//! \name	Externi deklarace konstant z modulu version.h a XmlConditions.h
//@{

extern const uint16_t		constVERINFO_MAGIC_NUMBER PCONST;
extern const uint16_t		constVERINFO_PROJECT_IDENT PCONST;
extern const ctkdate16_t	constVERINFO_REVISION_DATE PCONST;
extern const uint8_t		constVERINFO_HW_VERSION	PCONST;
extern const uint8_t		constVERINFO_HW_REVISION PCONST;
extern const uint8_t		constVERINFO_SW_VERSION PCONST;
extern const uint8_t		constVERINFO_SW_REVISION PCONST;
extern const uint8_t		constVERINFO_DATA_VERSION PCONST;
extern const uint8_t		constVERINFO_NVDATA_VERSION PCONST;
extern const uint8_t		constVERINFO_PSTDATA_VERSION PCONST;

//@}


//----------------------------------------------------
//!	\name	Definice funkci pro pristup ke konstantam verinfo
//@{

static inline uint16_t VerInfoGetMagicNumber(void)
{
	return (uint16_t)read_pconst_word(&constVERINFO_MAGIC_NUMBER);
}

static inline uint16_t VerInfoGetProjectIdent(void)
{
	return (uint16_t)read_pconst_word(&constVERINFO_PROJECT_IDENT);
}


static inline ctkdate16_t VerInfoGetRevisionDate(void)
{
	return (uint16_t)read_pconst_word(&constVERINFO_REVISION_DATE);
}

static uint8_t VerInfoGetRevisionDay(const ctkdate16_t _date) _const;
static inline uint8_t VerInfoGetRevisionDay(const uint16_t _date)
{
	return (uint8_t)(_date & 0x001F);
}

static uint8_t VerInfoGetRevisionMonth(const ctkdate16_t _date) _const;
static inline uint8_t VerInfoGetRevisionMonth(const uint16_t _date)
{
	return (uint8_t)((_date >> 5 ) & 0x000F);
}

static uint16_t VerInfoGetRevisionYear(const ctkdate16_t _date) _const;
static inline uint16_t VerInfoGetRevisionYear(const uint16_t _date)
{
	return ((_date >> (4 + 5)) & 0x003F) + 2000U;
}

static inline uint8_t VerInfoGetHWVersion(void)
{
	return (uint8_t)read_pconst_byte(&constVERINFO_HW_VERSION);
}

static inline uint8_t VerInfoGetHWRevision(void)
{
	return (uint8_t)read_pconst_byte(&constVERINFO_HW_REVISION);
}

static inline uint8_t VerInfoGetSWVersion(void)
{
	return (uint8_t)read_pconst_byte(&constVERINFO_SW_VERSION);
}

static inline uint8_t VerInfoGetSWRevision(void)
{
	return (uint8_t)read_pconst_byte(&constVERINFO_SW_REVISION);
}

static inline uint8_t VerInfoGetDataVersion(void)
{
	return (uint8_t)read_pconst_byte(&constVERINFO_DATA_VERSION);
}

static inline uint8_t VerInfoGetNvDataVersion(void)
{
	return (uint8_t)read_pconst_byte(&constVERINFO_NVDATA_VERSION);
}

static inline uint8_t VerInfoGetPstDataVersion(void)
{
	return (uint8_t)read_pconst_byte(&constVERINFO_PSTDATA_VERSION);
}
//@}

#else //COMPILED_LIB

#include "version.h"


//----------------------------------------------------
//!	Definice VERINFO struktury

typedef struct _VERINFO_DESC
{
	uint16_t	MagicNumber;		//!< Magicke cislo
	uint16_t	ProjectIdent;		//!< Identifikace projektu
	ctkdate16_t	RevisionDate;		//!< Datum zmeny
	uint8_t		HWVersion;			//!< Verze hardvare, lze-li definovat, jinak 0
	uint8_t		HWRevision;			//!< Revize hardware, lze-li definovat, jinak 0
	uint8_t		SWVersion;			//!< Verze software
	uint8_t		SWRevision;			//!< Revize software
	uint8_t		DataVersion;		//!< Verze datove struktury
	uint8_t		NvDataVersion;		//!< Verze nevolatilni datove struktury
	uint8_t		PstDataVersion;		//!< Verze priodicky ukladane datove struktury
} VERINFO_DESC;


//----------------------------------------------------
//!	Definice konstanty gVersionInfo

extern const VERINFO_DESC PCONST p_gVERSION_INFO;


//----------------------------------------------------
//!	\name	Definice maker pro pristup k polozkam gVersionInfo
//@{

static inline uint16_t VerInfoGetMagicNumber(void)
{
	return (uint16_t)read_pconst_word(&p_gVERSION_INFO.MagicNumber);
}

static inline uint16_t VerInfoGetProjectIdent(void)
{
	return (uint16_t)read_pconst_word(&p_gVERSION_INFO.ProjectIdent);
}

static inline ctkdate16_t VerInfoGetRevisionDate(void)
{
	return (uint16_t)read_pconst_word(&p_gVERSION_INFO.RevisionDate);
}

static uint8_t VerInfoGetRevisionDay(const ctkdate16_t _date) _const;
static inline uint8_t VerInfoGetRevisionDay(const uint16_t _date)
{
	return (uint8_t)(_date & 0x001F);
}

static uint8_t VerInfoGetRevisionMonth(const ctkdate16_t _date) _const;
static inline uint8_t VerInfoGetRevisionMonth(const uint16_t _date)
{
	return (uint8_t)((_date >> 5 ) & 0x000F);
}

static uint16_t VerInfoGetRevisionYear(const ctkdate16_t _date) _const;
static inline uint16_t VerInfoGetRevisionYear(const uint16_t _date)
{
	return ((_date >> (4 + 5)) & 0x003F) + 2000U;
}

static inline uint8_t VerInfoGetHWVersion(void)
{
	return (uint8_t)read_pconst_byte(&p_gVERSION_INFO.HWVersion);
}

static inline uint8_t VerInfoGetHWRevision(void)
{
	return (uint8_t)read_pconst_byte(&p_gVERSION_INFO.HWRevision);
}

static inline uint8_t VerInfoGetSWVersion(void)
{
	return (uint8_t)read_pconst_byte(&p_gVERSION_INFO.SWVersion);
}

static inline uint8_t VerInfoGetSWRevision(void)
{
	return (uint8_t)read_pconst_byte(&p_gVERSION_INFO.SWRevision);
}

static inline uint8_t VerInfoGetDataVersion(void)
{
	return (uint8_t)read_pconst_byte(&p_gVERSION_INFO.DataVersion);
}

static inline uint8_t VerInfoGetNvDataVersion(void)
{
	return (uint8_t)read_pconst_byte(&p_gVERSION_INFO.NvDataVersion);
}

static inline uint8_t VerInfoGetPstDataVersion(void)
{
	return (uint8_t)read_pconst_byte(&p_gVERSION_INFO.PstDataVersion);
}
//@}

#endif //COMPILED_LIB
#endif // _VER_INFO_H_
