Commit b3eec517 authored by Irina LEE's avatar Irina LEE

add forth test for code generation (eln)

parent 7a6b44d6
# Compiler and linker flags
CXXFLAGS = -g -Wall -I. $(SYSTEMC_INCLUDE_DIRS)
LDFLAGS = $(SYSTEMC_LIBRARY_DIRS)
# List of all ecutables to be compiled
EXECUTABLES = cluster_tb
# .PHONY targets don't generate files
.PHONY: all clean
# Default targets
all: $(EXECUTABLES)
cluster_tb: cluster_tb.cpp phone.h transmission_line.h protection_circuit.h slic.h
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< -lsystemc-ams -lsystemc | c++filt
# Clean rule to delete temporary and generated files
clean:
rm -rf *~ *.o *.dat *.vcd *.dSYM $(EXECUTABLES)
#include <systemc-ams>
#include "phone.h"
#include "transmission_line.h"
#include "protection_circuit.h"
#include "slic.h"
int sc_main(int argc, char *argv[])
{
sc_core::sc_signal<bool> s_hook;
sca_tdf::sca_signal<double> s_voice;
sca_eln::sca_node n_ring_b1;
sca_eln::sca_node n_tip_a1;
sca_tdf::sca_signal<double> s_v2w;
sca_tdf::sca_signal<double> s_i_trans;
sca_eln::sca_node n_tip_slic_tip;
sca_eln::sca_node n_b2_ring;
sca_eln::sca_node n_a2_tip;
sca_eln::sca_node n_ring_slic_ring;
phone i_phone("i_phone");
i_phone.ring(n_ring_b1);
i_phone.tip(n_tip_a1);
i_phone.voice(s_voice);
i_phone.hook(s_hook);
transmission_line i_transmission_line("i_transmission_line");
i_transmission_line.a1(n_tip_a1);
i_transmission_line.b1(n_ring_b1);
i_transmission_line.a2(n_a2_tip);
i_transmission_line.b2(n_b2_ring);
protection_circuit i_protection_circuit("i_protection_circuit");
i_protection_circuit.tip(n_a2_tip);
i_protection_circuit.ring(n_b2_ring);
i_protection_circuit.tip_slic(n_tip_slic_tip);
i_protection_circuit.ring_slic(n_ring_slic_ring);
slic i_slic("i_slic");
i_slic.tip(n_tip_slic_tip);
i_slic.ring(n_ring_slic_ring);
i_slic.i_trans(s_i_trans);
i_slic.v2w(s_v2w);
sca_util::sca_trace_file* tfp = sca_util::sca_create_tabular_trace_file("cluster_tb");
sca_util::sca_trace(tfp, s_hook, "s_hook");
sca_util::sca_trace(tfp, s_voice, "s_voice");
sca_util::sca_trace(tfp, n_ring_b1, "n_ring_b1");
sca_util::sca_trace(tfp, n_tip_a1, "n_tip_a1");
sca_util::sca_trace(tfp, s_v2w, "s_v2w");
sca_util::sca_trace(tfp, s_i_trans, "s_i_trans");
sca_util::sca_trace(tfp, n_tip_slic_tip, "n_tip_slic_tip");
sca_util::sca_trace(tfp, n_b2_ring, "n_b2_ring");
sca_util::sca_trace(tfp, n_a2_tip, "n_a2_tip");
sca_util::sca_trace(tfp, n_ring_slic_ring, "n_ring_slic_ring");
sc_start(100.0, sc_core::SC_MS);
sca_util::sca_close_tabular_trace_file(tfp);
sc_core::sc_stop();
return 0;
}
#ifndef PHONE_H
#define PHONE_H
#include <cmath>
#include <iostream>
#include <systemc-ams>
SC_MODULE(phone)
{
sca_eln::sca_terminal ring;
sca_eln::sca_terminal tip;
sc_core::sc_in<bool> hook;
sca_tdf::sca_in<double> voice;
sca_eln::sca_c cr;
sca_eln::sca_c cp;
sca_eln::sca_r rr;
sca_eln::sca_r rs;
sca_eln::sca_r rp;
sca_eln::sca_de_vsource sw1;
sca_eln::sca_de_vsource sw2;
sca_eln::sca_tdf_vsource mic;
SC_CTOR(phone)
: ring("ring")
, tip("tip")
, hook("hook")
, voice("voice")
, cr("cr", 1.0e-6, 0.0)
, cp("cp", 115.0e-9, 0.0)
, rr("rr", 1.0e3)
, rs("rs", 220.0)
, rp("rp", 820.0)
, sw1("sw1", 1.0)
, sw2("sw2", 1.0)
, mic("mic", 1.0)
, wring("wring")
, w1("w1")
, w_onhook("w_onhook")
, w2("w2")
, w_offhook("w_offhook")
{
cr.p(wring);
cr.n(w_onhook);
cp.p(w1);
cp.n(w_offhook);
rr.p(wring);
rr.n(ring);
rs.p(w1);
rs.n(w2);
rp.p(w_offhook);
rp.n(w1);
sw1.p(tip);
sw1.n(w_onhook);
sw1.inp(hook);
sw2.p(tip);
sw2.n(w_offhook);
sw2.inp(hook);
mic.p(w2);
mic.n(ring);
mic.inp(voice);
}
private:
sca_eln::sca_node wring;
sca_eln::sca_node w1;
sca_eln::sca_node w_onhook;
sca_eln::sca_node w2;
sca_eln::sca_node w_offhook;
};
#endif // PHONE_H
\ No newline at end of file
#ifndef PROTECTION_CIRCUIT_H
#define PROTECTION_CIRCUIT_H
#include <cmath>
#include <iostream>
#include <systemc-ams>
SC_MODULE(protection_circuit)
{
sca_eln::sca_terminal tip;
sca_eln::sca_terminal ring;
sca_eln::sca_terminal tip_slic;
sca_eln::sca_terminal ring_slic;
sca_eln::sca_c cprot1;
sca_eln::sca_c cprot2;
sca_eln::sca_r rprot1;
sca_eln::sca_r rprot2;
sca_eln::sca_r rprot3;
sca_eln::sca_r rprot4;
SC_CTOR(protection_circuit)
: tip("tip")
, ring("ring")
, tip_slic("tip_slic")
, ring_slic("ring_slic")
, cprot1("cprot1", 18.0e-9, 0.0)
, cprot2("cprot2", 18.0e-9, 0.0)
, rprot1("rprot1", 20.0)
, rprot2("rprot2", 20.0)
, rprot3("rprot3", 20.0)
, rprot4("rprot4", 20.0)
, n_ring("n_ring")
, n_tip("n_tip")
, gnd("gnd")
{
cprot1.p(n_tip);
cprot1.n(gnd);
cprot2.p(n_ring);
cprot2.n(gnd);
rprot1.p(tip);
rprot1.n(n_tip);
rprot2.p(tip_slic);
rprot2.n(n_tip);
rprot3.p(ring);
rprot3.n(n_ring);
rprot4.p(ring_slic);
rprot4.n(n_ring);
}
private:
sca_eln::sca_node n_ring;
sca_eln::sca_node n_tip;
sca_eln::sca_node_ref gnd;
};
#endif // PROTECTION_CIRCUIT_H
\ No newline at end of file
#ifndef SLIC_H
#define SLIC_H
#include <cmath>
#include <iostream>
#include <systemc-ams>
SC_MODULE(slic)
{
sca_eln::sca_terminal tip;
sca_eln::sca_terminal ring;
sca_tdf::sca_out<double> i_trans;
sca_tdf::sca_in<double> v2w;
sca_eln::sca_r rtr;
sca_eln::sca_vccs mirror2;
sca_eln::sca_vccs mirror1;
sca_eln::sca_tdf_vsink itr_meas;
sca_eln::sca_tdf_vsource driver1;
sca_eln::sca_tdf_vsource driver2;
SC_CTOR(slic)
: tip("tip")
, ring("ring")
, i_trans("i_trans")
, v2w("v2w")
, rtr("rtr", 1.0)
, mirror2("mirror2", -0.5)
, mirror1("mirror1", 0.5)
, itr_meas("itr_meas", 1.0)
, driver1("driver1", 0.5)
, driver2("driver2", 0.5)
, n_tri_i("n_tri_i")
, n_ring_gnd("n_ring_gnd")
, n_tip_gnd("n_tip_gnd")
, gnd("gnd")
{
rtr.p(n_tri_i);
rtr.n(gnd);
mirror2.ncp(n_ring_gnd);
mirror2.np(n_tri_i);
mirror2.ncn(gnd);
mirror2.nn(gnd);
mirror1.ncp(n_tip_gnd);
mirror1.np(n_tri_i);
mirror1.ncn(gnd);
mirror1.nn(gnd);
itr_meas.p(n_tri_i);
itr_meas.n(gnd);
itr_meas.outp(i_trans);
driver1.p(tip);
driver1.n(n_tip_gnd);
driver1.inp(v2w);
driver2.p(ring);
driver2.n(n_ring_gnd);
driver2.inp(v2w);
}
private:
sca_eln::sca_node n_tri_i;
sca_eln::sca_node n_ring_gnd;
sca_eln::sca_node n_tip_gnd;
sca_eln::sca_node_ref gnd;
};
#endif // SLIC_H
\ No newline at end of file
#ifndef TRANSMISSION_LINE_H
#define TRANSMISSION_LINE_H
#include <cmath>
#include <iostream>
#include <systemc-ams>
SC_MODULE(transmission_line)
{
sca_eln::sca_terminal a1;
sca_eln::sca_terminal b1;
sca_eln::sca_terminal a2;
sca_eln::sca_terminal b2;
sca_eln::sca_transmission_line tl0;
SC_CTOR(transmission_line)
: a1("a1")
, b1("b1")
, a2("a2")
, b2("b2")
, tl0("tl0", 50.0, sc_core::SC_ZERO_TIME, 0.0)
{
tl0.a1(a1);
tl0.a2(a2);
tl0.b1(b1);
tl0.b2(b2);
}
private:
};
#endif // TRANSMISSION_LINE_H
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment