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

#include <systemc-ams>

#include "singlediode_mixer.h"

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_eln::sca_node v1M, v1k, if_s, lo_s, rf_s, inner, vi;
  sca_eln::sca_node_ref gnd;

  sca_eln::sca_vsource LO1M("LO1M");
  LO1M.p.bind(v1M);
  LO1M.n.bind(gnd);
  LO1M.amplitude=1.0;
  LO1M.frequency=1.0e6;
  LO1M.set_timestep(100.0,sc_core::SC_NS);

  sca_eln::sca_r Rlo("Rlo");
  Rlo.p.bind(v1M);
  Rlo.n.bind(lo_s);
  Rlo.value=50.0;

  sca_eln::sca_vsource IF1K("IF1K");
  IF1K.p.bind(v1k);
  IF1K.n.bind(gnd);
  IF1K.amplitude=0.1;
  IF1K.frequency=5.0e3;
  IF1K.offset=0.2;

  sca_eln::sca_r Rif("Rif");
  Rif.p.bind(v1k);
  Rif.n.bind(if_s);
  Rif.value=1.0;

  singlediode_mixer DUT("DUT");
  DUT.lo_i.bind(lo_s);
  DUT.if_i.bind(if_s);
  DUT.rf_o.bind(rf_s);

  sca_eln::sca_r Rrf("Rrf");
  Rrf.p.bind(rf_s);
  Rrf.n.bind(gnd);
  Rrf.value=50.0;

  // tracing
  sca_util::sca_trace_file* atf = sca_util::sca_create_tabular_trace_file( "singlemix_tran.tab" );
  sca_util::sca_trace( atf, lo_s, "lo_s" );		// 1
  sca_util::sca_trace( atf, if_s, "if_s" );		// 2
  sca_util::sca_trace( atf, rf_s, "rf_s" );		// 3
  sca_util::sca_trace( atf, DUT.inner, "inner" );	// 4
  sca_util::sca_trace( atf, v1M, "v1M" );		// 5
  sca_util::sca_trace( atf, v1k, "v1k" );		// 6

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

  sc_core::sc_start(10.0, sc_core::SC_MS);

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

  sca_util::sca_close_tabular_trace_file( atf );

  return 0;
}
