【问题标题】:Setting the vector length in SystemC with a received parameter使用接收到的参数在 SystemC 中设置向量长度
【发布时间】:2018-04-16 03:13:59
【问题描述】:

我在 SystemC 中通过四个 NAND 门的绑定制作了一个异或门。我希望模块接收 N 位向量,其中 N 作为参数传递。我应该能够执行 &not 位运算(对于 NAND 门)。

最好的解决方案可能是使用sc_bv_base 类型,但我不知道如何在构造函数中对其进行初始化。

如何使用自定义长度创建位向量?

【问题讨论】:

    标签: systemc


    【解决方案1】:

    参数化模块的一种方法是为模块创建一个新的 C++ 模板。

    在这个例子中,输入向量的宽度可以设置在这个模块的实例化级别

    #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_ */
    

    请注意,struct my_xor: sc_module 使用 i.s.o。 SC_MODULE 宏。 (参见第 40 页,5.2.5 SC_MODULEIEEE Std 1666-2011)。

    您可以使用以下测试平台对此进行测试:

    //------------------------------------------------------------------
    // Simple Testbench for 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 a 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 to ns
        sc_trace(fp, clk, "clk");             // Add signals to 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;
    }
    

    请注意,我使用的是struct,而不是classclass 也是可能的。

    class my_xor: public sc_module{
    public:
    

    这段代码中的异或就是xor_reduce。您可以在第 197 页的IEEE Std 1666-2011 中找到更多信息(7.2.8 归约运算符)。但我认为这不是您想要的解决方案。

    【讨论】:

      猜你喜欢
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      相关资源
      最近更新 更多