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/cw_source.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/devices/cw_source.h (limited to 'src/devices/cw_source.h') diff --git a/src/devices/cw_source.h b/src/devices/cw_source.h new file mode 100644 index 0000000..487177c --- /dev/null +++ b/src/devices/cw_source.h @@ -0,0 +1,76 @@ +#pragma once + +#include +#include + +#include +#include +#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 &litude, 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; + } +}; -- cgit v1.2.3