#ifndef _OSC_SEM_CPP_
#define _OSC_SEM_CPP_

#include <systemc.h>
#include "Precision.h"
#include "sc_float.h"
#include "Osc_SEM.h"


void Osc_SEM::oscFUNC()
{
//Definovanie vnútorných premenných
sc_float<E, M> coef[2];
sc_float<E, M> value_Q;
sc_float<E, M> value_D;

//oscilator
bool direction;
bool tmp_dir;
sc_float<E, M> komp;
sc_float<E, M> U;

sc_float<E, M> pos, neg, tmp_U;

//Reset obvodu
sc_float<E, M> tmp_r;
tmp_r = 0.0;
	coef[0] = (0.0);
	coef[1] = (0.0);
	value_Q = (0.0);
		inp_rdy.write(false);
		outp_vld.write(false);
	outp.write(tmp_r);
	//oscil

	pos = (0.0);
	neg = (0.0);
direction = false;
tmp_dir = false;
tmp_U = false;
komp = (0.0);
U = (0.0);
//Ukončenie resetu
wait();

cout << value_Q << endl;

//Vnútorná "nekonečná" slučka - ukončiteľná len resetom obvodu
while (true)
{
	//"handshaking" vstupných dát
	inp_rdy.write(true);
	do {
		wait();
	} while (!inp_vld.read());
coef[0] = coef0_sc_fl.read();
coef[1] = coef1_sc_fl.read();
U = Uz_sc_fl.read();
pos = komp_value.read();
neg = komp_value.read();
	inp_rdy.write(false);



	if (en.read())
	{
		pos.write_sign(0);
		neg.write_sign(1);
		direction = tmp_dir;
		if (direction)
		{
			if (value_Q >= pos) //pretečenie NAD hranicu
			{
				tmp_U = U;
				tmp_U.write_sign(1);
				tmp_dir = false;
			}
			else
			{
				tmp_U = U;
				tmp_U.write_sign(0);
				tmp_dir = true;
			}
		}

		else //direction = false
		{
			if (value_Q <= neg) //pretečenie POD hranicu
			{
				tmp_U = U;
				tmp_U.write_sign(0);
				tmp_dir = true;
			}
			else
			{
				tmp_U = U;
				tmp_U.write_sign(1);
				tmp_dir = false;
			}
		}
	}
	else
	{
		tmp_U.write_sign(0);
		tmp_U.write_exp(0);
		tmp_U.write_man(0);
		tmp_dir = false;
	}


	sc_exp_SEM(coef, &value_D, &value_Q, tmp_U, en.read());

	

//"handshaking" výstupných dát
		outp_vld.write(true);
		do {
			wait();
		} while (!outp_rdy.read());
outp.write(value_Q);
		outp_vld.write(false);
} //Ukončenie while cyklu
} //Ukončenie deklarácie modulu
		
#endif
