From ff9b8bb838ecdfbfc1dc81038fcf3b2a87636982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Zrounba?= <6691770+clement-z@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:06:01 +0200 Subject: Initial release --- src/devices/crossing.h | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/devices/crossing.h (limited to 'src/devices/crossing.h') diff --git a/src/devices/crossing.h b/src/devices/crossing.h new file mode 100644 index 0000000..8631ba4 --- /dev/null +++ b/src/devices/crossing.h @@ -0,0 +1,113 @@ +#pragma once + +#include + +#include + +#include +#include + + +/* A waveguide crossing that accounts for */ +/* loss and interchannel crosstalk */ +/* */ +/* (2)p_in2 */ +/* | */ +/* (1)p_in1----+---->p_out1(3) */ +/* | */ +/* v */ +/* p_out2(4) */ +/* */ +/* ---------------------------------------*/ +class CrossingBase : public spx_module { +public: + // Member variables + double m_attenuation_power_dB; + double m_crosstalk_power_dB; + + // Constructor with crosstalk + // Attenuation relates to out1/in1 when there's nothing in in2 + // Crosstalk relates to out2/in1 when there's nothing in in1 + CrossingBase(sc_module_name name, + double attenuation_power_dB = 0, + double crosstalk_power_dB = NAN) + : spx_module(name) + , m_attenuation_power_dB(attenuation_power_dB) + , m_crosstalk_power_dB(crosstalk_power_dB) + { + } +}; + +class CrossingUni : public CrossingBase { +public: + // Ports + spx::oa_port_in_type p_in1; + spx::oa_port_in_type p_in2; + spx::oa_port_out_type p_out1; + spx::oa_port_out_type p_out2; + + // Timed ports writers + OpticalOutputPort m_out1_writer; + OpticalOutputPort m_out2_writer; + + // Processes + void on_input_changed(); + + // Constructor with crosstalk + // Attenuation relates to out1/in1 when there's nothing in in2 + // Crosstalk relates to out2/in1 when there's nothing in in1 + CrossingUni(sc_module_name name, + double attenuation_power_dB = 0, + double crosstalk_power_dB = NAN) + : CrossingBase(name, attenuation_power_dB, crosstalk_power_dB) + , m_out1_writer("out1_delayed_writer", p_out1) + , m_out2_writer("out2_delayed_writer", p_out2) + { + SC_HAS_PROCESS(CrossingUni); + + SC_THREAD(on_input_changed); + sensitive << p_in1 << p_in2; + } +}; + +typedef CrossingUni Crossing; + +class CrossingBi : public CrossingBase { +public: + // Ports + spx::oa_port_in_type p0_in; + spx::oa_port_in_type p1_in; + spx::oa_port_in_type p2_in; + spx::oa_port_in_type p3_in; + spx::oa_port_out_type p0_out; + spx::oa_port_out_type p1_out; + spx::oa_port_out_type p2_out; + spx::oa_port_out_type p3_out; + + // Timed ports writers + OpticalOutputPort m_p0_out_writer; + OpticalOutputPort m_p1_out_writer; + OpticalOutputPort m_p2_out_writer; + OpticalOutputPort m_p3_out_writer; + + // Processes + void on_input_changed(); + + // Constructor with crosstalk + // Attenuation relates to out1/in1 when there's nothing in in2 + // Crosstalk relates to out2/in1 when there's nothing in in1 + CrossingBi(sc_module_name name, + double attenuation_power_dB = 0, + double crosstalk_power_dB = NAN) + : CrossingBase(name, attenuation_power_dB, crosstalk_power_dB) + , m_p0_out_writer("p0_out_delayed_writer", p0_out) + , m_p1_out_writer("p1_out_delayed_writer", p1_out) + , m_p2_out_writer("p2_out_delayed_writer", p2_out) + , m_p3_out_writer("p3_out_delayed_writer", p3_out) + { + SC_HAS_PROCESS(CrossingBi); + + SC_THREAD(on_input_changed); + sensitive << p0_in << p1_in << p2_in << p3_in; + } +}; \ No newline at end of file -- cgit v1.2.3