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/bitstream_source.h | 105 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/devices/bitstream_source.h (limited to 'src/devices/bitstream_source.h') diff --git a/src/devices/bitstream_source.h b/src/devices/bitstream_source.h new file mode 100644 index 0000000..a7c8715 --- /dev/null +++ b/src/devices/bitstream_source.h @@ -0,0 +1,105 @@ +#pragma once + +#include +#include + +#include +#include + +using namespace std; + +class BitstreamSource : public sc_module { +public: + // Set it as typedef for now (we may very well never need to change it) + typedef unsigned long operand_type; + +public: + // Ports + sc_port> p_enable; + sc_in p_clk; + sc_port> p_out; + + // Timed ports writers + OpticalOutputPort m_out_writer; + + // Member variables + static unsigned int m_bits_per_value; + + vector m_values; + operand_type m_current_value = 0; + + OpticalSignal m_signal_on; + OpticalSignal m_signal_off; + + // Processes + void runner(); + + // + inline void setWavelength(const double &wl) + { + m_signal_on.m_wavelength_id = m_signal_on.getIDFromWavelength(wl); + m_signal_off.m_wavelength_id = m_signal_off.getIDFromWavelength(wl); + } + + // + inline void setPower(const double &on, const double &off = 0.0) + { + m_signal_on.m_field = sqrt(on); + m_signal_off.m_field = sqrt(off); + } + + // Constructor + BitstreamSource(sc_module_name name) + : sc_module(name) + , m_out_writer("out_delayed_writer", p_out) + { + SC_HAS_PROCESS(BitstreamSource); + + SC_THREAD(runner); + sensitive << p_clk.pos() << p_clk.neg(); + } + + BitstreamSource(sc_module_name name, + const vector &values, + const OpticalSignal &signal_on, + const OpticalSignal &signal_off = OpticalSignal(0)) + : sc_module(name) + , m_out_writer("out_delayed_writer", p_out) + , m_values(values) + , m_current_value(values.empty() ? 0 : values[0]) + , m_signal_on(signal_on) + , m_signal_off(signal_off) + { + SC_HAS_PROCESS(BitstreamSource); + + SC_THREAD(runner); + sensitive << p_clk.pos() << p_clk.neg(); + } + + BitstreamSource(sc_module_name name, + const std::string &values_file, + const OpticalSignal &signal_on, + const OpticalSignal &signal_off = OpticalSignal(0)) + : sc_module(name) + , m_out_writer("out_delayed_writer", p_out) + , m_signal_on(signal_on) + , m_signal_off(signal_off) + { + // Read values from file + std::ifstream i(values_file); + + int value; + m_values.clear(); + while ( i.good() ) { + i >> value; + m_values.push_back(value); + } + + m_current_value = (m_values.empty() ? 0 : m_values[0]); + + SC_HAS_PROCESS(BitstreamSource); + + SC_THREAD(runner); + sensitive << p_clk.pos() << p_clk.neg(); + } +}; -- cgit v1.2.3