aboutsummaryrefslogtreecommitdiff
path: root/src/tb/mzi_tb.cpp
blob: 2b9905a73977d2d5964d69a77dc57e29a6a4aea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <ctime>
#include <iomanip>
#include <tb/mzi_tb.h>

#include "general_utils.h"

void mzi_tb::run_1()
{
    IN->write(OpticalSignal(sqrt(1.0), 1550e-9));
    wait(1, SC_NS);
    vtheta.write(M_PI_2);
    wait(1, SC_NS);
    vtheta.write(M_PI);
    wait(1, SC_NS);
    vphi.write(1);
    wait(1, SC_NS);

    while (true) { wait(); }
}

void mzi_tb::monitor()
{
    while(true)
    {
        wait();
        std::cout << sc_time_stamp() << ":" << std::endl
            << "\tIN:  " << IN->read() << std::endl
            << "\tPHI: " << vphi.read() << std::endl
            << "\tTHETA: " << vtheta.read() << std::endl
            << "\tOUT1: " << OUT1->read() << std::endl
            << "\tOUT2: " << OUT2->read() << std::endl;
    }

}

void MZI_tb_run()
{
    // Apply SPECS resolution before creating any device
    specsGlobalConfig.applyEngineResolution();

    spx::oa_signal_type IN1, IN2, OUT1, OUT2;
    spx::ea_signal_type vphi,vtheta;

    MZI mzi1("mzi1",0,0,0,0,0,1);
    mzi1.p_in1(IN1);
    mzi1.p_in2(IN2);
    mzi1.p_out1(OUT1);
    mzi1.p_out2(OUT2);
    mzi1.p_vphi(vphi);
    mzi1.p_vtheta(vtheta);

    mzi_tb tb("tb");
    tb.IN(IN1);
    tb.OUT1(OUT1);
    tb.OUT2(OUT2);
    tb.vphi(vphi);
    tb.vtheta(vtheta);

    // Open Trace file
    std::string trace_filename = "traces/";
    trace_filename += "mzi_tb";
    specsGlobalConfig.trace_filename = trace_filename;

    // Apply SPECS options specific to the testbench
    specsGlobalConfig.simulation_mode = OpticalOutputPortMode::EVENT_DRIVEN;
    specsGlobalConfig.trace_all_optical_nets = 0;


    Probe probe_mzi_1("probe_mzi_1",specsGlobalConfig.default_trace_file);
    probe_mzi_1.p_in(OUT1);
    Probe probe_mzi_2("probe_mzi_2",specsGlobalConfig.default_trace_file);
    probe_mzi_2.p_in(OUT2);
    Probe probe_in("probe_in",specsGlobalConfig.default_trace_file);
    probe_in.p_in(IN1);

    // Run SPECS pre-simulation code
    specsGlobalConfig.prepareSimulation();

    // Start simulation
    sc_start();

    std::cout << std::endl << std::endl;
    std::cout << ".vcd trace file: " << specsGlobalConfig.trace_filename << std::endl;

    sc_close_vcd_trace_file(specsGlobalConfig.default_trace_file);
}