aboutsummaryrefslogtreecommitdiff
path: root/src/devices/splitter.h
blob: 1d5e730e83d0199afb7c7d9a2eda53975d18d13a (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
87
88
#pragma once

#include <systemc.h>

#include <spx_module.h>
#include <optical_output_port.h>
#include <optical_signal.h>
#include "specs.h"
#include "spx_module.h"

/** A 1x2 waveguide splitter module.
 *
 * This device copies any output to its two output, with power values defines by the
 * split ratio and attenuation.
 * */
class Splitter : public spx_module {
public:
    // Ports
    /** The optical input port. */
    spx::oa_port_in_type p_in;
    /** The first optical output port. */
    spx::oa_port_out_type p_out1;
    /** The second optical output port. */
    spx::oa_port_out_type p_out2;

private:
    // Timed ports writers
    /** Timed writer to the first output port.
     *
     * @sa DelayedWriter
     * */
    OpticalOutputPort m_out1_writer;
    /** Timed writer to the second output port.
     *
     * @sa DelayedWriter
     * */
    OpticalOutputPort m_out2_writer;

public:
    // Member variables
    /** The power transmission from input to branch 1, exclusive of losses
     *
     * The power transmission from input to branch 2 is (1 - m_split_ratio)
     * */
    double m_split_ratio;

    /** The delay for an output to propagate to the outputs in ns.
     *
     * The delay is the same for both outputs.
     * */
    // static double m_delay_ns;
    /** The attenuation of the signal in dB.
     *
     * The attenuation is applied before the split (although it does not really make a
     * difference. */
    double m_attenuation_dB;

    // Processes
    /** Main process of the module.
     *
     * It copies the input to both output, after attenuation and delay.
     *
     *   **SystemC type:** thread
     *
     *   **Sensitivity list:** p_in
     * */
    void on_port_in_changed();

    // Constructor
    /** Constructor for Splitter
     *
     * @param name name of the module
     * @param split_ratio ratio of the light which goes to the first ouptut
     * (pre-attenuation)
     * */
    Splitter(sc_module_name name, double split_ratio = 0.5, double attenuation_dB = 0)
        : spx_module(name)
        , m_out1_writer("out1_delayed_writer", p_out1)
        , m_out2_writer("out2_delayed_writer", p_out2)
        , m_split_ratio(split_ratio)
        , m_attenuation_dB(attenuation_dB)
    {
        SC_HAS_PROCESS(Splitter);

        SC_THREAD(on_port_in_changed);
        sensitive << p_in;
    }
};