/*****************************************************************************
 *
 * Copyright (c) 2018-19, Eduard Gerlits, Paula Herber, Josef Treus
 * Westfälische Wilhelms-Universität Münster, AG Embedded Systems 
 * All rights reserved.
 *
 * This file is part of SysCSec
 *
 * SysCSec is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * SysCSec is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SysCSec.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 *  Please report any problems or bugs to: sysc.sec@uni-muenster.de
 *
 ****************************************************************************/


#include <iostream>
#include <systemc.h>
#include "commons.h"

SC_MODULE(InputXORModule){

	// clock
	sc_port<sc_clock> clk;

	// in
	sc_fifo_in<sc_biguint<160> > data_out;

	// out
	sc_fifo_out<sc_biguint<160> > key_in;
	sc_fifo_out<sc_biguint<160> > data_in;

	void input_test(sc_biguint<160> key_in_param, sc_biguint<160> data_in_param){		
		std::cout << "[" << sc_time_stamp() << "]: " << "Write key_in: " << key_in_param << std::endl;
		key_in->write(key_in_param);
		std::cout << "[" << sc_time_stamp() << "]: " << "Write data_in: " << data_in_param << std::endl;
		data_in->write(data_in_param);
		wait();

		sc_biguint<160> val;

		while(data_out->nb_read(val)==false){
			std::cout << "[" << sc_time_stamp() << "]: " << "Computing ..." << std::endl;
			wait();
		}
		
		std::cout << "[" << sc_time_stamp() << "]: " << "Computed value: " << val << std::endl;
	}

	void exe(){
		wait(100, "SC_MS");
		input_test(5,15);
		wait(100, "SC_MS");
		input_test(5,10);
		sc_stop();
	}

	SC_CTOR(InputXORModule){
		SC_THREAD(exe);
		sensitive << clk;
	}

};
