//----------------------------------------------------
/**
	\file		ctk/inc/uclp1d.h
	\ingroup	serial
	\ingroup	all

	\brief		Funkce pro seriovou komunikaci protokol CLP - Lecom A/B
				<<< ALL >>>
			
	\author		ConTeK s.r.o., Ing. Vladimir Kastner
	\version	01.01
	\date		27.03.2011
*/
//----------------------------------------------------


#ifndef _UCLP1D_H_
#define _UCLP1D_H_

#include <ctktypes.h>
#include <comm.h>
#include <ulecom.h>
#include <uxor8.h>

//----------------------------------------------------
/**
	\brief	Definice CLP - Lecom A/B protokolu viz ulecom.h
*/
//----------------------------------------------------


//----------------------------------------------------
/**
	\brief	Popisovac automatu
*/
//----------------------------------------------------

//! Master
typedef struct _MCL1DDESC
{
	volatile uint8_t	State;			//!< Stav automatu
	xor8_t				Bcc;			//!< Kontrolni soucet
	ldiv_t				FData;			//!< Docasna hodnota celeho a desetineho cisla
	char8_t				SData[LCM_MAX_FIXED];	//!< String hodnota
	int8_t				SInd;			//!< Index do stringu
	bool_t				Minus;			//!< Znamenko minus
	int16_t				Order;			//!< Desetine poradi
} MCL1DDESC;

//! Slave
typedef struct SCL1DDESC
{
	volatile uint8_t	State;			//!< Stav automatu
	xor8_t				Bcc;			//!< Kontrolni soucet
	ldiv_t				FData;			//!< Docasna hodnota celeho a desetineho cisla
	char8_t				SData[LCM_MAX_FIXED];	//!< String hodnota
	int8_t				SInd;			//!< Index do stringu
	bool_t				Minus;			//!< Znamenko minus
	int16_t				Order;			//!< Desetine poradi
} SCL1DDESC;

//----------------------------------------------------
//! Struktura kontextu automatu vysilace a prijimace

//! Master
typedef struct _MCLP1DDESC
{
	COMMDESC *			Cmm;			//!< ukazatel na komunikaci nizsi vrstvy

	MCL1DDESC			Snd;			//!< stav vysilace
	MCL1DDESC			Rcv;			//!< stav prijimace

} MCLP1DDESC;

//! Slave
typedef struct SCLP1DDESC 
{
	COMMDESC *			Cmm;			//!< ukazatel na komunikaci nizsi vrstvy

	lcaddr_t			Addr;			//!< Adresa zarizeni
	SCL1DDESC			Snd;			//!< stav vysilace
	SCL1DDESC			Rcv;			//!< stav prijimace

} SCLP1DDESC;


//----------------------------------------------------
/**
	\brief	Funkce pro inicializaci komunikacniho automatu

	\param	_clp		Struktura kontextu automatu
	\param	_cmm		Adresa knihovny fyzicke vrstvy
*/
//----------------------------------------------------

//! Master
bool_t Clp1DMInitialize(MCLP1DDESC * const _clp, COMMDESC * const _cmm);

//! Slave
bool_t Clp1DSInitialize(SCLP1DDESC * const _clp, COMMDESC * const _cmm, lcaddr_t _addr);

//----------------------------------------------------
/**
	\brief	Funkce pro ukonceni komunikacniho automatu Master

	\param	_clp		Struktura kontextu automatu
*/
//----------------------------------------------------

//! Master
void Clp1DMFinalize(const MCLP1DDESC * const _clp);

//! Slave
void Clp1DSFinalize(const SCLP1DDESC * const _clp);

#endif // _UCLP1D_H_
