From 7e00e4960af68e6c26104cca26cdf47f4f4095a7 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Mon, 3 Dec 2018 00:28:25 +0000 Subject: Added initial CPU SR-latch --- cpu8/cpu_srlatch/Makefile | 12 +++++ cpu8/cpu_srlatch/cpu_srlatch.cpp | 98 ++++++++++++++++++++++++++++++++++++++++ cpu8/cpu_srlatch/cpu_srlatch.hpp | 55 ++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 cpu8/cpu_srlatch/Makefile create mode 100644 cpu8/cpu_srlatch/cpu_srlatch.cpp create mode 100644 cpu8/cpu_srlatch/cpu_srlatch.hpp diff --git a/cpu8/cpu_srlatch/Makefile b/cpu8/cpu_srlatch/Makefile new file mode 100644 index 0000000..acccab7 --- /dev/null +++ b/cpu8/cpu_srlatch/Makefile @@ -0,0 +1,12 @@ +SYSTEMC_PATH=/home/fam/downloads/source/systemc/systemc-2.3.2 +SYSTEMC_INC=$(SYSTEMC_PATH)/src +SYSTEMC_LIB=$(SYSTEMC_PATH)/src/.libs + +PROJECT=cpu_srlatch + +make: + g++ $(PROJECT).cpp -I$(SYSTEMC_INC) -L$(SYSTEMC_LIB) -Wl,-rpath=$(SYSTEMC_LIB)\ + -o $(PROJECT) -lsystemc -lm + + + diff --git a/cpu8/cpu_srlatch/cpu_srlatch.cpp b/cpu8/cpu_srlatch/cpu_srlatch.cpp new file mode 100644 index 0000000..07efe5e --- /dev/null +++ b/cpu8/cpu_srlatch/cpu_srlatch.cpp @@ -0,0 +1,98 @@ +#include +#include + +#include "systemc.h" +#include "systemc" +#include +#include + +#include "cpu_srlatch.hpp" + +SC_MODULE(test_cpu_srlatch) +{ + sc_out s,r; + sc_in clk; + + + void test_cpu_srlatch_stim() + { + wait(); + s.write(0); + r.write(1); + + wait(); + s.write(1); + r.write(0); + + wait(); + s.write(1); + r.write(1); + + wait(); + s.write(1); + r.write(0); + + wait(); + s.write(0); + r.write(0); + + + wait(); + s.write(0); + r.write(0); + + wait(); + s.write(0); + r.write(1); + + wait(); + s.write(0); + r.write(0); + + wait(); + s.write(0); + r.write(0); + + + wait(); + + sc_stop(); + } + + SC_CTOR(test_cpu_srlatch) + { + SC_THREAD(test_cpu_srlatch_stim); + sensitive << clk.pos(); + + } +}; + + +int sc_main(int argc, char **argv) { + sc_signal sig_in_r, sig_in_s, sig_out_q, sig_out_nq; + sc_clock TestClk("TestClk", 10, SC_NS, 0.5, 1, SC_NS); + + test_cpu_srlatch Stim1("Stimulus"); + Stim1.r(sig_in_r); + Stim1.s(sig_in_s); + Stim1.clk(TestClk); + + cpu_srlatch DUT("cpu_srlatch"); + DUT.in_r(sig_in_r); + DUT.in_s(sig_in_s); + DUT.out_q(sig_out_q); + DUT.out_nq(sig_out_nq); + + sc_trace_file *Tf; + + Tf = sc_create_vcd_trace_file("trace_cpu_srlatch.dat"); + sc_trace(Tf, sig_in_r, "IN_R"); + sc_trace(Tf, sig_in_s, "IN_S"); + sc_trace(Tf, sig_out_q, "OUT_Q"); + sc_trace(Tf, sig_out_nq, "OUT_NQ"); + + sc_start(); + sc_close_vcd_trace_file(Tf); + + return(0); +} \ No newline at end of file diff --git a/cpu8/cpu_srlatch/cpu_srlatch.hpp b/cpu8/cpu_srlatch/cpu_srlatch.hpp new file mode 100644 index 0000000..f495e70 --- /dev/null +++ b/cpu8/cpu_srlatch/cpu_srlatch.hpp @@ -0,0 +1,55 @@ +#ifndef __SYSC_CPU_SRLATCH_HPP +#define __SYSC_CPU_SRLATCH_HPP + +#include "systemc.h" +#include "../cpu_or/cpu_or.hpp" +#include "../cpu_not/cpu_not.hpp" + +SC_MODULE (cpu_srlatch) +{ + //Inputs + sc_in in_r; + sc_in in_s; + sc_out out_q,out_nq; + + cpu_or *or1,*or2; + cpu_not *not1, *not2; + + sc_signal sig_or1not1, sig_or2not2; + sc_signal sig_outq_ins, sig_outnq_inr; + + void do_srlatch() + { + + } + + SC_CTOR(cpu_srlatch) + { + or1 = new cpu_or("OR1"); + or2 = new cpu_or("OR2"); + not1 = new cpu_not("NOT1"); + not2 = new cpu_not("NOT2"); + + or1->in_a(in_r); + or1->in_b(sig_outnq_inr); + or1->out_c(sig_or1not1); + + or2->in_a(sig_outq_ins); + or2->in_b(in_s); + or2->out_c(sig_or2not2); + + not1->in_a(sig_or1not1); + not1->out_b(out_q); + not1->out_b(sig_outq_ins); + + not2->in_a(sig_or2not2); + not2->out_b(out_nq); + not2->out_b(sig_outnq_inr); + + //SC_METHOD(do_srlatch); + //sensitive << in_r << in_s; + } + +}; + +#endif \ No newline at end of file -- cgit v1.2.3