aboutsummaryrefslogtreecommitdiff
path: root/src/devices/cw_source.h
blob: 487177cff7fa3c582c6890822d3a8482b595570c (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
#pragma once

#include <systemc.h>
#include <fstream>

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

class CWSource : public spx_module {
public:
    // Ports
    spx::oa_port_out_type p_out;

    // Timed ports writers
    OpticalOutputPort m_out_writer;

    // Signal characteristic
    spx::oa_value_type m_signal_on;
    double m_source_wavelength;

    // Source emission control
    spx::ed_signal_type enable;
    spx::ed_signal_type reset;

    // Processes
    void runner();

    inline void setWavelength(const double &wl)
    {
        m_source_wavelength = wl;
        m_signal_on.m_wavelength_id = m_signal_on.getIDFromWavelength(wl);
    }
    inline void setFrequency(const double &f)
    {
        setWavelength(299792458.0 / f);
    }
    inline void setAmplitudePhase (const double &amplitude, const double &phase)
    {
        m_signal_on.m_field = polar(amplitude, phase);
    }
    inline void setPhase (const double &phase)
    {
        if (m_signal_on.modulus() == 0)
            cerr << "Warning: setting phase has no effect on 0" << endl;
        m_signal_on.m_field = polar(m_signal_on.modulus(), phase);
    }
    inline void setPower (const double &power)
    {
        m_signal_on.m_field = polar(sqrt(power), m_signal_on.phase());
    }
    inline void setPower(const double &power, double phase)
    {
        setAmplitudePhase(sqrt(power), phase);
    }

    // Constructor
    CWSource(sc_module_name name)
        : spx_module(name)
        , m_out_writer("out_delayed_writer", p_out)
    {
        SC_HAS_PROCESS(CWSource);

        SC_THREAD(runner);

        enable = sc_logic(0);
        reset = sc_logic(0);
    }

    CWSource(sc_module_name name, const OpticalSignal& signal_on)
        : CWSource(name)
    {
        m_signal_on = signal_on;
    }
};