summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/communication/sc_export/test05
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-05-24 01:37:55 -0700
committerGabe Black <gabeblack@google.com>2018-08-08 10:09:54 +0000
commit16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch)
tree7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/communication/sc_export/test05
parent7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff)
downloadgem5-16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f.tar.xz
systemc: Import tests from the Accellera systemc distribution.
Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/systemc/communication/sc_export/test05')
-rw-r--r--src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log51
-rw-r--r--src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp106
2 files changed, 157 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log b/src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log
new file mode 100644
index 000000000..a736ca05c
--- /dev/null
+++ b/src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log
@@ -0,0 +1,51 @@
+SystemC Simulation
+0 s: 0
+1 ns: 0
+2 ns: 0
+3 ns: 0
+4 ns: 1
+5 ns: 2
+6 ns: 3
+7 ns: 4
+8 ns: 5
+9 ns: 6
+10 ns: 7
+11 ns: 8
+12 ns: 9
+13 ns: 10
+14 ns: 11
+15 ns: 12
+16 ns: 13
+17 ns: 14
+18 ns: 15
+19 ns: 16
+20 ns: 17
+21 ns: 18
+22 ns: 19
+23 ns: 20
+24 ns: 21
+25 ns: 22
+26 ns: 23
+27 ns: 24
+28 ns: 25
+29 ns: 26
+30 ns: 27
+31 ns: 28
+32 ns: 29
+33 ns: 30
+34 ns: 31
+35 ns: 32
+36 ns: 33
+37 ns: 34
+38 ns: 35
+39 ns: 36
+40 ns: 37
+41 ns: 38
+42 ns: 39
+43 ns: 40
+44 ns: 41
+45 ns: 42
+46 ns: 43
+47 ns: 44
+48 ns: 45
+49 ns: 46
diff --git a/src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp b/src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp
new file mode 100644
index 000000000..f1e38c862
--- /dev/null
+++ b/src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp
@@ -0,0 +1,106 @@
+#include "systemc.h"
+
+typedef sc_biguint<121> atom; // Value to be pipe delayed.
+
+//==============================================================================
+// esc_dpipe<T,N> - DELAY PIPELINE FOR AN ARBITRARY CLASS:
+//==============================================================================
+template<class T, int N>
+SC_MODULE(esc_dpipe) {
+ public:
+ typedef sc_export<sc_signal_inout_if<T> > in; // To pipe port type.
+ typedef sc_export<sc_signal_in_if<T> > out; // From pipe port type.
+
+ public:
+ SC_CTOR(esc_dpipe)
+ {
+ m_in(m_pipe[0]);
+ m_out(m_pipe[N-1]);
+ SC_METHOD(rachet);
+ sensitive << m_clk.pos();
+ }
+
+ protected:
+ void rachet()
+ {
+ for ( int i = N-1; i > 0; i-- )
+ {
+ m_pipe[i].write(m_pipe[i-1].read());
+ }
+ }
+
+ public:
+ sc_in_clk m_clk; // Pipe synchronization.
+ in m_in; // Input to delay pipe.
+ out m_out; // Output from delay pipe.
+
+ protected:
+ sc_signal<T> m_pipe[N]; // Pipeline stages.
+};
+
+
+// Testbench reader of values from the pipe:
+
+SC_MODULE(Reader)
+{
+ SC_CTOR(Reader)
+ {
+ SC_METHOD(extract)
+ sensitive << m_clk.pos();
+ dont_initialize();
+ }
+
+ void extract()
+ {
+ cout << sc_time_stamp() << ": " << m_from_pipe.read() << endl;
+ }
+
+ sc_in_clk m_clk; // Module synchronization.
+ sc_in<atom > m_from_pipe; // Output from delay pipe.
+};
+
+
+
+// Testbench writer of values to the pipe:
+
+SC_MODULE(Writer)
+{
+ SC_CTOR(Writer)
+ {
+ SC_METHOD(insert)
+ sensitive << m_clk.pos();
+ m_counter = 0;
+ }
+
+ void insert()
+ {
+ m_to_pipe.write(m_counter);
+ m_counter++;
+ }
+
+ sc_in_clk m_clk; // Module synchronization.
+ atom m_counter; // Write value.
+ sc_inout<atom > m_to_pipe; // Input for delay pipe.
+};
+
+// Main program
+
+int sc_main(int argc, char* argv[])
+{
+ sc_clock clock;
+ esc_dpipe<atom,4> delay("pipe");
+ Reader reader("reader");
+ Writer writer("writer");
+
+ delay.m_clk(clock);
+
+ reader.m_clk(clock);
+ reader.m_from_pipe(delay.m_out);
+
+ writer.m_clk(clock);
+ writer.m_to_pipe(delay.m_in);
+
+ sc_start(50, SC_NS);
+
+ return 0;
+}