/*2011-01-03T15:22:34-01:00*/

/********************************************************************
 * graf_mdl_verin_bist_cov.c
 * 
 * generated by: plcgen 2.1.201
 ********************************************************************/

#include "cb_comp.h"
#include "cb_covs.h"
#include "iec_1131.h"

#include "graf_mdl_verin_bist.h"


/**************************** Variables *****************************/

CB_Index graf_mdl_verin_bist__num = 0;
CB_Mem_Bool *graf_mdl_verin_bist_DR;
CB_Mem_Bool *graf_mdl_verin_bist_DS;
CB_Mem_Bool *graf_mdl_verin_bist_ACQ;
CB_Mem_Bool *graf_mdl_verin_bist_AU;
CB_Mem_Bool *graf_mdl_verin_bist_CR;
CB_Mem_Bool *graf_mdl_verin_bist_CS;
CB_Mem_Bool *graf_mdl_verin_bist_OrdreR;
CB_Mem_Bool *graf_mdl_verin_bist_OrdreS;
CB_Mem_Bool *graf_mdl_verin_bist_EtatR;
CB_Mem_Bool *graf_mdl_verin_bist_EtatS;
CB_Mem_Bool *graf_mdl_verin_bist_Def_verin;
CB_Mem_Bool *graf_mdl_verin_bist_defaut;
CB_Mem_Int *graf_mdl_verin_bist_TTL;
CB_Mem_Int *graf_mdl_verin_bist_Tinertie;
CB_Mem_Int *graf_mdl_verin_bist_t1;
CB_Mem_Int *graf_mdl_verin_bist_t2;
CB_Mem_Int *graf_mdl_verin_bist_t3;
CB_Mem_Int *graf_mdl_verin_bist_t4;
CB_Mem_Int *graf_mdl_verin_bist_t5;
CB_Mem_Int *graf_mdl_verin_bist_t6;
CB_Mem_Int *graf_mdl_verin_bist_t7;
CB_Mem_Int *graf_mdl_verin_bist_t8;
CB_Mem_Bool *graf_mdl_verin_bist__X_10;
CB_Mem_Bool *graf_mdl_verin_bist__X_11;
CB_Mem_Bool *graf_mdl_verin_bist__X_12;
CB_Mem_Bool *graf_mdl_verin_bist__X_20;
CB_Mem_Bool *graf_mdl_verin_bist__X_21;
CB_Mem_Bool *graf_mdl_verin_bist__X_22;
CB_Mem_Bool *graf_mdl_verin_bist__X_23;
CB_Mem_Bool *graf_mdl_verin_bist__FORCING_G2;
CB_Mem_Bool *graf_mdl_verin_bist__X_20_PREV;
CB_Mem_Bool *graf_mdl_verin_bist__X_21_PREV;
CB_Mem_Bool *graf_mdl_verin_bist__X_22_PREV;
CB_Mem_Bool *graf_mdl_verin_bist__X_23_PREV;

/**************************** Variables *****************************/

#define DR (graf_mdl_verin_bist_DR->CB_current_value)
#define DS (graf_mdl_verin_bist_DS->CB_current_value)
#define ACQ (graf_mdl_verin_bist_ACQ->CB_current_value)
#define AU (graf_mdl_verin_bist_AU->CB_current_value)
#define CR (graf_mdl_verin_bist_CR->CB_current_value)
#define CS (graf_mdl_verin_bist_CS->CB_current_value)
#define OrdreR (graf_mdl_verin_bist_OrdreR->CB_current_value)
#define OrdreS (graf_mdl_verin_bist_OrdreS->CB_current_value)
#define EtatR (graf_mdl_verin_bist_EtatR->CB_current_value)
#define EtatS (graf_mdl_verin_bist_EtatS->CB_current_value)
#define Def_verin (graf_mdl_verin_bist_Def_verin->CB_current_value)
#define defaut(i) (graf_mdl_verin_bist_defaut[i+1].CB_current_value)
#define TTL(i) (graf_mdl_verin_bist_TTL[i+1].CB_current_value)
#define Tinertie(i) (graf_mdl_verin_bist_Tinertie[i+1].CB_current_value)
#define t1(i) (graf_mdl_verin_bist_t1[i+1].CB_current_value)
#define t2 (graf_mdl_verin_bist_t2->CB_current_value)
#define t3(i) (graf_mdl_verin_bist_t3[i+1].CB_current_value)
#define t4 (graf_mdl_verin_bist_t4->CB_current_value)
#define t5(i) (graf_mdl_verin_bist_t5[i+1].CB_current_value)
#define t6 (graf_mdl_verin_bist_t6->CB_current_value)
#define t7(i) (graf_mdl_verin_bist_t7[i+1].CB_current_value)
#define t8 (graf_mdl_verin_bist_t8->CB_current_value)
#define _X_10 (graf_mdl_verin_bist__X_10->CB_current_value)
#define _X_11 (graf_mdl_verin_bist__X_11->CB_current_value)
#define _X_12 (graf_mdl_verin_bist__X_12->CB_current_value)
#define _X_20 (graf_mdl_verin_bist__X_20->CB_current_value)
#define _X_21 (graf_mdl_verin_bist__X_21->CB_current_value)
#define _X_22 (graf_mdl_verin_bist__X_22->CB_current_value)
#define _X_23 (graf_mdl_verin_bist__X_23->CB_current_value)
#define _FORCING_G2 (graf_mdl_verin_bist__FORCING_G2->CB_current_value)
#define _X_20_PREV (graf_mdl_verin_bist__X_20_PREV->CB_current_value)
#define _X_21_PREV (graf_mdl_verin_bist__X_21_PREV->CB_current_value)
#define _X_22_PREV (graf_mdl_verin_bist__X_22_PREV->CB_current_value)
#define _X_23_PREV (graf_mdl_verin_bist__X_23_PREV->CB_current_value)


/************************ Components offsets ************************/


/********************* Initialization function **********************/

int _sfp__graf_mdl_verin_bist_init(void)
{
	(self.Int+0+3)->CB_current_value = 100000; /*TTL[2]*/
	(self.Int+4+3)->CB_current_value = 20000; /*Tinertie[2]*/
	(self.Bool+12)->CB_current_value = 1; /*_X_10*/
	self.Bool+=24;
	self.Int+=28;


	return 0;
}


/************************ Behavior function *************************/

int sfp__graf_mdl_verin_bist(void)
{
	static char *__comp_name = "sfp.graf_mdl_verin_bist";
	if (exec_term_node(self_num)) {

		/*********************** Internals variables ************************/

		graf_mdl_verin_bist_defaut = self.Bool+0;
		graf_mdl_verin_bist_TTL = self.Int+0;
		graf_mdl_verin_bist_Tinertie = self.Int+4;
		graf_mdl_verin_bist_t1 = self.Int+8;
		graf_mdl_verin_bist_t2 = self.Int+12;
		graf_mdl_verin_bist_t3 = self.Int+13;
		graf_mdl_verin_bist_t4 = self.Int+17;
		graf_mdl_verin_bist_t5 = self.Int+18;
		graf_mdl_verin_bist_t6 = self.Int+22;
		graf_mdl_verin_bist_t7 = self.Int+23;
		graf_mdl_verin_bist_t8 = self.Int+27;
		graf_mdl_verin_bist__X_10 = self.Bool+12;
		graf_mdl_verin_bist__X_11 = self.Bool+13;
		graf_mdl_verin_bist__X_12 = self.Bool+14;
		graf_mdl_verin_bist__X_20 = self.Bool+15;
		graf_mdl_verin_bist__X_21 = self.Bool+16;
		graf_mdl_verin_bist__X_22 = self.Bool+17;
		graf_mdl_verin_bist__X_23 = self.Bool+18;
		graf_mdl_verin_bist__FORCING_G2 = self.Bool+19;
		graf_mdl_verin_bist__X_20_PREV = self.Bool+20;
		graf_mdl_verin_bist__X_21_PREV = self.Bool+21;
		graf_mdl_verin_bist__X_22_PREV = self.Bool+22;
		graf_mdl_verin_bist__X_23_PREV = self.Bool+23;

		/********************* Pre-conditions execution *********************/

		/*no Pre-conditions*/

		/************************ Behavior execution ************************/

		{
			unsigned char _Y_6;
			unsigned char _Y_5;
			unsigned char _Y_4;
			unsigned char _Y_7;
			unsigned char _Y_22;
			unsigned char _Y_21;
			unsigned char _Y_20;
			unsigned char _Y_19;
			unsigned char _Y_23;
			unsigned char _Y_24;
			_FORCING_G2 = 0;
			/*pre-SFC*/
			/*transitions G1*/
			_Y_6 = _X_10 && (_X_21 || _X_23);
			_Y_5 = _X_11 && Def_verin;
			_Y_4 = _X_12 && ((ACQ && !Def_verin) && !AU);
			_Y_7 = _X_10 && (!_Y_6 && (Def_verin || AU));
			/*transitions G2*/
			_Y_22 = _X_20 && (!CR && CS);
			_Y_21 = _X_21 && (DR && !DS);
			_Y_20 = _X_22 && (CR && !CS);
			_Y_19 = _X_23 && (!DR && DS);
			_Y_23 = _X_20 && (!_Y_22 && (DR && !DS));
			_Y_24 = _X_22 && (!_Y_20 && (!DR && DS));
			/*evolutions G1*/
			if (_Y_6) {
				_X_10 = 0;
			}
			if (_Y_5) {
				_X_11 = 0;
			}
			if (_Y_4) {
				_X_12 = 0;
			}
			if (_Y_7) {
				_X_10 = 0;
			}
			if (_Y_6) {
				_X_11 = 1;
			}
			if (_Y_5) {
				_X_12 = 1;
			}
			if (_Y_4) {
				_X_10 = 1;
			}
			if (_Y_7) {
				_X_12 = 1;
			}
			/*timers G1*/
			/*actions G1*/
			if (_X_10) {
				if (!CR && CS) {
					_FORCING_G2 = 1;
					_X_20 = 0;
					_X_21 = 1;
					_X_22 = 0;
					_X_23 = 0;
				}
				if (CR && !CS) {
					_FORCING_G2 = 1;
					_X_20 = 0;
					_X_21 = 0;
					_X_22 = 0;
					_X_23 = 1;
				}
			}
			if (_X_12) {
				_FORCING_G2 = 1;
				_X_20 = 0;
				_X_21 = 0;
				_X_22 = 0;
				_X_23 = 0;
			}
			/*evolutions G2*/
			if (!_FORCING_G2) {
				if (_Y_22) {
					_X_20 = 0;
				}
				if (_Y_21) {
					_X_21 = 0;
				}
				if (_Y_20) {
					_X_22 = 0;
				}
				if (_Y_19) {
					_X_23 = 0;
				}
				if (_Y_23) {
					_X_20 = 0;
				}
				if (_Y_24) {
					_X_22 = 0;
				}
				if (_Y_22) {
					_X_21 = 1;
				}
				if (_Y_21) {
					_X_22 = 1;
				}
				if (_Y_20) {
					_X_23 = 1;
				}
				if (_Y_19) {
					_X_20 = 1;
				}
				if (_Y_23) {
					_X_22 = 1;
				}
				if (_Y_24) {
					_X_20 = 1;
				}
			}
			/*timers G2*/
			/*actions G2*/
			if (CB_edge_bool(_X_20, _X_20_PREV) < 0) {
				OrdreS = 0;
			}
			if (CB_edge_bool(_X_21, _X_21_PREV) < 0) {
				EtatS = 0;
			}
			if (CB_edge_bool(_X_22, _X_22_PREV) < 0) {
				OrdreR = 0;
			}
			if (CB_edge_bool(_X_23, _X_23_PREV) < 0) {
				EtatR = 0;
			}
			if (_X_20) {
				OrdreS = 1;
			}
			if (_X_21) {
				EtatS = 1;
			}
			if (_X_22) {
				OrdreR = 1;
			}
			if (_X_23) {
				EtatR = 1;
			}
			/*post-SFC*/
			if (_X_23 && !CR) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 2, IFTHEN);
				defaut(1) = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 2, IFELSE);
			}
			if ((_X_21 && CR) | (CR & ton_Q(_X_20, graf_mdl_verin_bist_Tinertie, graf_mdl_verin_bist_t1, &t2))) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 7, IFTHEN);
				defaut(2) = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 7, IFELSE);
			}
			if (_X_21 && !CS) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 12, IFTHEN);
				defaut(3) = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 12, IFELSE);
			}
			if ((_X_23 && CS) | (CS & ton_Q(_X_22, graf_mdl_verin_bist_Tinertie, graf_mdl_verin_bist_t3, &t4))) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 17, IFTHEN);
				defaut(4) = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 17, IFELSE);
			}
			if (ton_Q(_X_20, graf_mdl_verin_bist_TTL, graf_mdl_verin_bist_t5, &t6)) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 22, IFTHEN);
				defaut(5) = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 22, IFELSE);
			}
			if (ton_Q(_X_22, graf_mdl_verin_bist_TTL, graf_mdl_verin_bist_t7, &t8)) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 27, IFTHEN);
				defaut(6) = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 27, IFELSE);
			}
			if (CR && CS) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 31, IFTHEN);
				defaut(7) = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 31, IFELSE);
			}
			if ((((((defaut(1) || defaut(2)) || defaut(3)) || defaut(4)) || defaut(5)) || defaut(6)) || defaut(7)) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 34, IFTHEN);
				Def_verin = 1;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 34, IFELSE);
			}
			if (ACQ && _X_12) {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 39, IFTHEN);
				defaut(1) = 0;
				defaut(2) = 0;
				defaut(3) = 0;
				defaut(4) = 0;
				defaut(5) = 0;
				defaut(6) = 0;
				defaut(7) = 0;
				Def_verin = 0;
			}
			else {
				cov_control_struct(__comp_name, self_num, INPOSTSFC, 39, IFELSE);
			}
			_X_23_PREV = _X_23;
			_X_22_PREV = _X_22;
			_X_21_PREV = _X_21;
			_X_20_PREV = _X_20;
		}

		if(nb_alloc > 0) {
			free_all_alloc();
		}

		CB_post_bool(graf_mdl_verin_bist_OrdreR);
		CB_post_bool(graf_mdl_verin_bist_OrdreS);
		CB_post_bool(graf_mdl_verin_bist_EtatR);
		CB_post_bool(graf_mdl_verin_bist_EtatS);
		CB_post_bool(graf_mdl_verin_bist_Def_verin);

		/******************** Post-conditions execution *********************/

		/*no Post-conditions*/
	}

	/*************************** self update ****************************/

	self.Bool += 24;
	self.Int += 28;

	return 0;
}

