summaryrefslogtreecommitdiff
path: root/cpu8/cpu_and
diff options
context:
space:
mode:
Diffstat (limited to 'cpu8/cpu_and')
-rw-r--r--cpu8/cpu_and/Makefile9
-rw-r--r--cpu8/cpu_and/cpu_and.cpp63
-rw-r--r--cpu8/cpu_and/cpu_and.hpp25
-rw-r--r--cpu8/cpu_and/notes.txt24
4 files changed, 121 insertions, 0 deletions
diff --git a/cpu8/cpu_and/Makefile b/cpu8/cpu_and/Makefile
new file mode 100644
index 0000000..ef0884a
--- /dev/null
+++ b/cpu8/cpu_and/Makefile
@@ -0,0 +1,9 @@
+SYSTEMC_PATH=/home/fam/downloads/source/systemc/systemc-2.3.2
+SYSTEMC_INC=$(SYSTEMC_PATH)/src
+SYSTEMC_LIB=$(SYSTEMC_PATH)/src/.libs
+
+PROJECT=cpu_and_2
+
+make:
+ g++ $(PROJECT).cpp -I$(SYSTEMC_INC) -L$(SYSTEMC_LIB) -Wl,-rpath=$(SYSTEMC_LIB)\
+ -o $(PROJECT) -lsystemc -lm \ No newline at end of file
diff --git a/cpu8/cpu_and/cpu_and.cpp b/cpu8/cpu_and/cpu_and.cpp
new file mode 100644
index 0000000..17e5f0f
--- /dev/null
+++ b/cpu8/cpu_and/cpu_and.cpp
@@ -0,0 +1,63 @@
+#include <iostream>
+#include <iomanip>
+
+#include "systemc.h"
+
+#include "cpu_and.hpp"
+
+SC_MODULE(test_cpu_and)
+{
+ sc_signal<bool> a,b,c;
+ sc_clock TestClk;
+
+ cpu_and circ_and;
+
+ void apply_test()
+ {
+ a = 0; b = 0;
+ wait();
+ a = 1; b = 0;
+ wait();
+ a = 0; b = 1;
+ wait();
+ a = 1; b = 1;
+ wait();
+ sc_stop();
+ }
+
+ void monitor_signals()
+ {
+ cout << "Time" << endl;
+ while (true)
+ {
+ cout << std::setw(5) << sc_time_stamp() << " ";
+ cout << std::setw(2) << a.read() << " ";
+ cout << std::setw(2) << b.read() << " ";
+ cout << std::setw(2) << c.read() << " ";
+ cout << endl;
+ wait();
+ }
+ }
+
+ SC_CTOR(test_cpu_and):
+ TestClk("TestClk", 10, SC_NS),
+ circ_and("cpu_AND")
+ {
+ circ_and.in_a(a);
+ circ_and.in_b(b);
+ circ_and.out_c(c);
+ SC_THREAD(monitor_signals);
+ sensitive << TestClk;
+ SC_THREAD(apply_test);
+ sensitive << TestClk;
+
+ }
+};
+
+int sc_main(int argc, char **argv) {
+ test_cpu_and test_and("cpu_and_test");
+
+ sc_start();
+
+ return(0);
+} \ No newline at end of file
diff --git a/cpu8/cpu_and/cpu_and.hpp b/cpu8/cpu_and/cpu_and.hpp
new file mode 100644
index 0000000..0c78dc0
--- /dev/null
+++ b/cpu8/cpu_and/cpu_and.hpp
@@ -0,0 +1,25 @@
+#ifndef __SYSC_CPU_ADD_HPP
+#define __SYSC_CPU_ADD_HPP
+
+#include "systemc.h"
+
+SC_MODULE (cpu_and)
+{
+ sc_port<sc_signal_in_if<bool>,0> in_a;
+ sc_port<sc_signal_in_if<bool>,0> in_b;
+ sc_port<sc_signal_out_if<bool>,0> out_c;
+
+ void do_and()
+ {
+ out_c[0]->write( in_a[0]->read() && in_b[0]->read() );
+ }
+
+ SC_CTOR(cpu_and)
+ {
+ SC_METHOD(do_and);
+ sensitive << in_a << in_b;
+ }
+
+};
+
+#endif \ No newline at end of file
diff --git a/cpu8/cpu_and/notes.txt b/cpu8/cpu_and/notes.txt
new file mode 100644
index 0000000..62e8b7e
--- /dev/null
+++ b/cpu8/cpu_and/notes.txt
@@ -0,0 +1,24 @@
+https://www.doulos.com/knowhow/systemc/tutorial/modules_and_processes/
+https://www.doulos.com/knowhow/systemc/tutorial/debugging/
+
+
+
+
+#include "systemc.h"
+SC_MODULE(nand2) // declare nand2 sc_module
+{
+ sc_in<bool> A, B; // input signal ports
+ sc_out<bool> F; // output signal ports
+
+ void do_nand2() // a C++ function
+ {
+ F.write( !(A.read() && B.read()) );
+ }
+
+ SC_CTOR(nand2) // constructor for nand2
+ {
+ SC_METHOD(do_nand2); // register do_nand2 with kernel
+ sensitive << A << B; // sensitivity list
+ }
+};
+