// ELN - Diode (TB)
// (c) Wolfgang Scherr
// w.scherr <at> cuas.at

#include <systemc-ams>

#include "diode.h"

SCA_TDF_MODULE(ramp_src) {
	sca_tdf::sca_out<double> out; // output port
	SCA_CTOR(ramp_src) : out("out") {}
	void processing()  {
		static double v=-21.0;
		out.write( v );
		v = v + 0.1;
	}
};

int sc_main(int argc, char* argv[])
{
  sc_core::sc_set_time_resolution(1.0, sc_core::SC_FS);
  sca_util::sca_information_off();

  sca_tdf::sca_signal<double> ramp;
  sca_eln::sca_node A;
  sca_eln::sca_node_ref gnd;

  ramp_src RS1("RS1");
  RS1.out(ramp);

  sca_eln::sca_tdf::sca_vsource V1("V1",1.0);
  V1.p(A);
  V1.n(gnd);
  V1.inp(ramp);
  V1.set_timestep(1.0,sc_core::SC_NS);

  diode D("D"); // DUT
    D.anode(A);
    D.cathode(gnd);

  // tracing
  sca_util::sca_trace_file* atf = sca_util::sca_create_tabular_trace_file( "diode_tran.tab" );
  sca_util::sca_trace( atf, A, "Vd" );
  sca_util::sca_trace( atf, V1, "Id" );

  std::cout << "Simulation started..." << std::endl;

  sc_core::sc_start(226, sc_core::SC_NS);

  std::cout << "...simulation finished." << std::endl;

  sca_util::sca_close_tabular_trace_file( atf );

  return 0;
}
