//----------------------------------------------------
/**
	\file		cortex-m4/inc/ctktypes.h
	\ingroup	general
	\ingroup	cortex-m4

	\brief		definice obecne uzitecnych datovych typu
				<<< CORTEX M4 >>>

	\author		ConTeK s.r.o., Petr Cernin, Pavel Bazika
	\version	01.02
	\date		15.01.2007
*/
//----------------------------------------------------


#ifndef _CTK_TYPES_H_
#define _CTK_TYPES_H_

#include <libsets.h>

#include <stdint.h>
#include <stdlib.h>

//----------------------------------------------------
/**
	\name	Definice typu bool_t a konstant TRUE, FALSE, true a false
*/
//----------------------------------------------------
//@{
#ifndef FALSE
#define FALSE	0
#endif

#ifndef TRUE
#define TRUE	(!FALSE)
#endif

#ifndef true
#define true	TRUE
#endif

#ifndef false
#define false	FALSE
#endif
//@}

//----------------------------------------------------
//!	Definice NULL

#ifndef NULL
	#define NULL	0
#endif	// NULL


//----------------------------------------------------
//!	\brief	Definice zakladni sirky dat

#define ATOM_BYTES		4				//!< \note atomicka sirka slova v bytech


//----------------------------------------------------
/**
	\name	Typy pouzivame v prenositelne casti kodu

	\brief	Tyto typy maji na vsech platformach dany minimalni rozsah
			dany nazvem typu (tj. 8/16/32bit signed/unsigned)
			Mohou byt vsak implementovany typy s vetsim rozsahem
			(tj. napr na 32-bitech muze byt i mint8_t, muint8_t, mint16_t a muint16_t
			implementovan pomoci 32bitoveho typu - signed/unsigned se vsak dodrzuje)
*/
//----------------------------------------------------
//@{
typedef int_least8_t	mint8_t;		//!< 8bit signed
typedef uint_least8_t	muint8_t;		//!< 8bit unsigned

typedef int_least16_t	mint16_t;		//!< 16bit signed
typedef uint_least16_t	muint16_t;		//!< 16bit unsigned

typedef int_least32_t	mint32_t;		//!< 32bit signed
typedef uint_least32_t	muint32_t;		//!< 32bit unsigned

typedef int_least64_t 	mint64_t;		//!< 64bit signed
typedef uint_least64_t	muint64_t;		//!< 64bit unsigned

typedef int				bool_t;			//!< boolean

typedef float			float_t;		//!< float
typedef double			double_t;		//!< double

typedef uint32_t		ptr_t;			//!< ukazatel

typedef int8_t			enum8_t;		//!< vyctovy typ
typedef int16_t			enum16_t;

typedef uint8_t			setenum8_t;		//!< mnozina vyctovy typu 8bit, <0,7>
typedef uint16_t		setenum16_t;	//!< mnozina vyctovy typu 16bit, <0,15>
typedef uint32_t		setenum32_t;	//!< mnozina vyctovy typu 32bit, <0,31>
typedef uint64_t		setenum64_t;	//!< mnozina vyctovy typu 64bit, <0,63>

typedef char			char_t;			//!< znak
typedef char			char8_t;		//!< znak
typedef wchar_t			char16_t;		//!< znak

#ifdef DTDEF_SUPPORT_SSTRING
typedef char_t			sstring_t[DTDEF_SSTRING_BUFF_SIZE];		//!< String jako small string vyjadreni hodnoty
typedef char8_t			sstring8_t[DTDEF_SSTRING_BUFF_SIZE];
#endif // DTDEF_SUPPORT_SSTRING

#ifdef DTDEF_SUPPORT_LSTRING
typedef char_t			lstring_t[DTDEF_LSTRING_BUFF_SIZE];		//!< String jako large string vyjadreni hodnoty
typedef char8_t			lstring8_t[DTDEF_LSTRING_BUFF_SIZE];		//!< String jako large string vyjadreni hodnoty
#endif // DTDEF_SUPPORT_LSTRING

//@}


//----------------------------------------------------
//!	\name	Spolecny datovy typ pro prevody formatu
//@{
typedef union _CONVTYPE
{
	uint8_t		u8[8];
	int8_t		i8[8];
	uint16_t	u16[4];
	int16_t		i16[4];
	uint32_t	u32[2];
	int32_t		i32[2];
	float_t		flt32[2];
	double_t	dbl64;

} CONVTYPE;

//@}


//----------------------------------------------------
//!	\name	Makra pro praci s 64 bitovymi cisly
//@{

#define HIGH_DWORD( u64 )  	((uint32_t) (u64 >> 32))		//!< Vyssich 32-bitu z u64, AVR
#define LOW_DWORD( u64 )	((uint32_t) (u64 & 0xFFFFFFFF))	//!< Nizsich 32-bitu z u64, AVR
//@}

//----------------------------------------------------
//!	\name	definice maximalnich rozsahu init cisel
//@{

#ifndef UINT8_MAX
	#define UINT8_MAX	 255L									//!< Maximalni hodnota uint8_t
#endif // UINT8_MAX

#ifndef UINT16_MAX
	#define UINT16_MAX	 65535UL								//!< Maximalni hodnota uint16_t
#endif // UINT16_MAX

#ifndef UINT32_MAX
	#define UINT32_MAX	 4294967295UL							//!< Maximalni hodnota uint32_t
#endif // UINT32_MAX

#ifndef UINT64_MAX
	#define UINT64_MAX	 18446744073709551615UL					//!< Maximalni hodnota uint64_t
#endif // UINT64_MAX
//@}

//----------------------------------------------------
//!	\name	Typy pro praci v programove pameti (AVR,..)
//@{

typedef const void		pconst_void;		//!< Konstanta void v programove pameti
typedef const char_t	pconst_char;		//!< Konstanta char_t v programove pameti
typedef const int8_t	pconst_int8_t;		//!< Konstanta int8_t v programove pameti
typedef const uint8_t	pconst_uint8_t;		//!< Konstanta uint8_t v programove pameti
typedef const int16_t	pconst_int16_t;		//!< Konstanta int16_t v programove pameti
typedef const uint16_t	pconst_uint16_t;	//!< Konstanta uint16_t v programove pameti
typedef const int32_t	pconst_int32_t;		//!< Konstanta int32_t v programove pameti
typedef const uint32_t	pconst_uint32_t;	//!< Konstanta uint32_t v programove pameti
typedef const int64_t	pconst_int64_t;		//!< Konstanta int64_t v programove pameti
typedef const uint64_t	pconst_uint64_t;	//!< Konstanta uint64_t v programove pameti

typedef void * const	pconst_voidptr_t;	//!< Ukazatel na RAM v programove pameti
typedef const uint32_t 	pconst_ptr_t;		//!< Adresa programove pameti v programove pameti
typedef const void * 	pvoidptr_t;			//!< Obecny ukazatel na programovou pamet v RAM
typedef uint32_t		pptr_t;				//!< Adresa programove pameti v RAM
typedef const void * const	pconst_pvoidptr_t;	//!< Ukazatel do programove pameti v programove pameti
typedef const uint32_t	pconst_pptr_t;		//!< Adresa programove pameti ulozena v programove pameti

typedef const char_t *	pcharptr_t;			//!< Ukazatel na retezec v programove pameti ulozeny v RAM
typedef const char_t * const pconst_pcharptr_t;//!< Ukazatel na retezec v programove pameti ulozeny v programove pameti

#define PCONST								//!< Definice konstanty v programove pameti, const uint8_t PCONST myname
//@}


//----------------------------------------------------
//!	Typ zamku nv pameti

typedef bool_t		nvmemlock_t;


//----------------------------------------------------
/**
	\brief	Funkce pro Inicializaci
*/
//----------------------------------------------------
static inline void CtktypesInitialize(void)
{}

//----------------------------------------------------
/**
	\brief	Funkce pro ukonceni
*/
//----------------------------------------------------
static inline void CtktypesFinalize(void)
{}

#endif
