//----------------------------------------------------
/**
	\file	finalize.c

	\brief	Ukonceni vsech zarizeni
			<<< ALL >>>

	\author	ConTeK s.r.o., Vladimir Kastner
	\version	01.01
	\date	10.10.2009
*/
//----------------------------------------------------

#include "finalize.h"
#include <hwsubmdl.h>
#include <hwboard.h>
#include <sync.h>
#include <timeticks.h>

#include "realtick.h"
#include "fasttick.h"
#include "slowtick.h"
#include "maintick.h"
#include "pccomm.h"
#include "appsets.h"
#include "appiodef.h"
#include "gvariables.h"


#ifdef MSVC
//  #include "sim.h"
#endif

#ifdef DBGMONITOR
	#include "appdebug.h"
#endif

//-----------------------------------------------------
/**
	\brief	Funkce inicializujici zarizeni
*/
//-----------------------------------------------------

void Finalize(void)
{
	// Ukonceni komunikace
	PcCommFinalize();

#ifdef DBGMONITOR
	// inicializace ladicich vypisu
	AppDebugFinalize();
#endif

	// Ukoncime periodicke ukladani stavu stroje
	pstStop(&gParCtxCtrl);

	// Zakazeme vystupy
	IODisable();

	// zakaz preruseni
	_FastLock();

	// Ukonceni HW, vystupy do neaktivniho stavu
#if defined(MSVC)
	HWBoardFinalize(&gFram);
#elif defined(SENS)
	HWBoardFinalize(&gFram, &gTwi);
#endif

#ifdef MSVC
	//! finalizace dat simulatoru
//	SimFinalize();
#endif //MSVC

	// Ukonceni TimeTicku
	TimeTicksFinalize();

	// Ukonceni TimeTicku
	TimeTicksHWFinalize();

	// Ukonceni FastLock
	FastLockFinalize();
}
