Setting the vector length in systemc with a received parameter -


im making xor gate in systemc, binding of 4 nand gates. want module receive vector of n bits, n passed parameter. should able perform & , not bitwise operations (for nand gate).

the best solution may using sc_bv_base type, don't know how initialize in constructor.

i appreciate solve issue.

a way parameterise module create new c++ template module. in example, width of input vector can set @ level of instantiation of module

#ifndef my_xor_h_ #define my_xor_h_  #include <systemc.h>         template<int depth> struct my_xor: sc_module {     sc_in<bool > clk;     sc_in<sc_uint<depth> > din;     sc_out<bool > dout;      void p1() {                                                                    dout.write(xor_reduce(din.read()));     }      sc_ctor(my_xor) {         sc_method(p1);         sensitive << clk.pos();     }  }; #endif /* my_xor_h_ */ 

note 'struct my_xor: sc_module' used i.s.o. 'sc_module' macro. (see page 40 , 5.2.5 sc_module of ieee std 1666-2011).

you can test following testbench:

//------------------------------------------------------------------ // simple testbench xor file //------------------------------------------------------------------  #include <systemc.h> #include "my_xor.h"  int sc_main(int argc, char* argv[]) {      const int width = 8;      sc_signal<sc_uint<width> > din;     sc_signal<bool> dout;      sc_clock clk("clk", 10, sc_ns, 0.5);   // create clock signal      my_xor<width> dut("my_xor");           // instantiate device under test      dut.din(din);                          // connect ports     dut.dout(dout);     dut.clk(clk);      sc_trace_file *fp;                  // create vcd file     fp = sc_create_vcd_trace_file("wave");     // open(fp), create wave.vcd file     fp->set_time_unit(100, sc_ps);      // set tracing resolution ns     sc_trace(fp, clk, "clk");             // add signals trace file     sc_trace(fp, din, "din");     sc_trace(fp, dout, "dout");      sc_start(31, sc_ns);                // run simulation     din = 0x00;     sc_start(31, sc_ns);                // run simulation     din = 0x01;     sc_start(31, sc_ns);                // run simulation     din = 0xff;     sc_start(31, sc_ns);                // run simulation      sc_close_vcd_trace_file(fp);        // close(fp)      return 0; } 

note i'm using 'struct' , not class. 'class' possible.

class my_xor: public sc_module{ public: 

the xor in code 'xor_reduce'. can find more in ieee std 1666-2011. @ page 197 (7.2.8 reduction operators). assume not solution wanted have.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -